envapt 8.2.0 → 8.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -15
- package/dist/node/config.cjs.map +1 -1
- package/dist/node/config.mjs.map +1 -1
- package/dist/node/converters/BuiltInConverters.cjs.map +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/ListOfBuiltInConverters.cjs.map +1 -1
- package/dist/node/converters/ListOfBuiltInConverters.mjs.map +1 -1
- package/dist/node/converters/ValueConverter.cjs.map +1 -1
- package/dist/node/converters/ValueConverter.mjs.map +1 -1
- package/dist/node/core/AdvancedMethods.cjs.map +1 -1
- package/dist/node/core/AdvancedMethods.mjs.map +1 -1
- package/dist/node/core/EnvapterBase.cjs.map +1 -1
- package/dist/node/core/EnvapterBase.mjs.map +1 -1
- package/dist/node/core/EnvironmentMethods.cjs.map +1 -1
- package/dist/node/core/EnvironmentMethods.mjs.map +1 -1
- package/dist/node/core/PrimitiveMethods.cjs.map +1 -1
- package/dist/node/core/PrimitiveMethods.mjs.map +1 -1
- package/dist/node/core/engine.cjs.map +1 -1
- package/dist/node/core/engine.mjs.map +1 -1
- package/dist/node/core/missing.cjs.map +1 -1
- package/dist/node/core/missing.mjs.map +1 -1
- package/dist/node/core/paths.cjs.map +1 -1
- package/dist/node/core/paths.mjs.map +1 -1
- package/dist/node/core/state.cjs.map +1 -1
- package/dist/node/core/state.mjs.map +1 -1
- 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/modern/createAccessorDecorator.cjs.map +1 -1
- package/dist/node/decorators/modern/createAccessorDecorator.mjs.map +1 -1
- package/dist/node/decorators/resolveDecoratorValue.cjs.map +1 -1
- package/dist/node/decorators/resolveDecoratorValue.mjs.map +1 -1
- package/dist/node/engine/Envapter.cjs.map +1 -1
- package/dist/node/engine/Envapter.mjs.map +1 -1
- package/dist/node/engine/NodeEnvapter.cjs.map +1 -1
- package/dist/node/engine/NodeEnvapter.mjs.map +1 -1
- package/dist/node/engine/TemplateResolver.cjs.map +1 -1
- package/dist/node/engine/TemplateResolver.mjs.map +1 -1
- package/dist/node/engine/Validators.cjs.map +1 -1
- package/dist/node/engine/Validators.mjs.map +1 -1
- package/dist/node/infra/Debug.cjs.map +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.map +1 -1
- package/dist/node/infra/Error.mjs.map +1 -1
- package/dist/node/infra/recase.cjs.map +1 -1
- package/dist/node/infra/recase.mjs.map +1 -1
- package/dist/node/infra/runtime.cjs.map +1 -1
- package/dist/node/infra/runtime.mjs.map +1 -1
- package/dist/node/sources/FileSource.cjs.map +1 -1
- package/dist/node/sources/FileSource.mjs.map +1 -1
- package/dist/node/sources/PortableSource.cjs.map +1 -1
- package/dist/node/sources/PortableSource.mjs.map +1 -1
- package/dist/node/sources/UnboundSource.cjs.map +1 -1
- package/dist/node/sources/UnboundSource.mjs.map +1 -1
- package/dist/node/sources/coerce.cjs.map +1 -1
- package/dist/node/sources/coerce.mjs.map +1 -1
- package/dist/node/sources/merge.cjs.map +1 -1
- package/dist/node/sources/merge.mjs.map +1 -1
- package/dist/portable/converters/BuiltInConverters.mjs.map +1 -1
- package/dist/portable/converters/Converters.mjs.map +1 -1
- package/dist/portable/converters/ListOfBuiltInConverters.mjs.map +1 -1
- package/dist/portable/converters/ValueConverter.mjs.map +1 -1
- package/dist/portable/core/AdvancedMethods.mjs.map +1 -1
- package/dist/portable/core/EnvapterBase.mjs.map +1 -1
- package/dist/portable/core/EnvironmentMethods.mjs.map +1 -1
- package/dist/portable/core/PrimitiveMethods.mjs.map +1 -1
- package/dist/portable/core/engine.mjs.map +1 -1
- package/dist/portable/core/missing.mjs.map +1 -1
- package/dist/portable/core/paths.mjs.map +1 -1
- package/dist/portable/core/state.mjs.map +1 -1
- package/dist/portable/decorators/legacy/Envapt.mjs.map +1 -1
- package/dist/portable/decorators/legacy/SugarDecorators.mjs.map +1 -1
- package/dist/portable/decorators/modern/Envapt.mjs.map +1 -1
- package/dist/portable/decorators/modern/SugarDecorators.mjs.map +1 -1
- package/dist/portable/decorators/modern/createAccessorDecorator.mjs.map +1 -1
- package/dist/portable/decorators/resolveDecoratorValue.mjs.map +1 -1
- package/dist/portable/engine/Envapter.mjs.map +1 -1
- package/dist/portable/engine/PortableEnvapter.mjs.map +1 -1
- package/dist/portable/engine/TemplateResolver.mjs.map +1 -1
- package/dist/portable/engine/Validators.mjs.map +1 -1
- package/dist/portable/engine/fileApiStub.mjs.map +1 -1
- package/dist/portable/infra/Debug.mjs.map +1 -1
- package/dist/portable/infra/Dotenv.mjs.map +1 -1
- package/dist/portable/infra/Error.mjs.map +1 -1
- package/dist/portable/infra/recase.mjs.map +1 -1
- package/dist/portable/infra/runtime.mjs.map +1 -1
- package/dist/portable/sources/PortableSource.mjs.map +1 -1
- package/dist/portable/sources/UnboundSource.mjs.map +1 -1
- package/dist/portable/sources/coerce.mjs.map +1 -1
- package/dist/portable/sources/merge.mjs.map +1 -1
- package/dist/types/converters/Converters.d.mts +4 -5
- package/dist/types/core/AdvancedMethods.d.mts +6 -12
- package/dist/types/core/EnvapterBase.d.mts +9 -12
- package/dist/types/core/Environment.d.mts +1 -2
- package/dist/types/core/EnvironmentMethods.d.mts +1 -6
- package/dist/types/core/PrimitiveMethods.d.mts +1 -5
- package/dist/types/decorators/legacy/Envapt.d.mts +17 -19
- package/dist/types/decorators/legacy/SugarDecorators.d.mts +12 -13
- package/dist/types/decorators/modern/Envapt.d.mts +17 -19
- package/dist/types/decorators/modern/SugarDecorators.d.mts +12 -13
- package/dist/types/engine/Envapter.d.mts +2 -2
- package/dist/types/engine/NodeEnvapter.d.mts +5 -6
- package/dist/types/engine/PortableEnvapter.d.mts +5 -7
- package/dist/types/infra/Debug.d.mts +3 -5
- package/dist/types/infra/Dotenv.d.mts +2 -4
- package/dist/types/infra/Error.d.mts +4 -5
- package/dist/types/infra/StandardSchema.d.mts +5 -7
- package/dist/types/sources/FileSource.d.mts +1 -2
- package/dist/types/sources/PortableSource.d.mts +7 -8
- package/dist/types/sources/merge.d.mts +1 -2
- package/dist/types/types/Conversion.d.mts +0 -4
- package/dist/types/types/Decorator.d.mts +2 -3
- package/dist/types/types/Options.d.mts +7 -7
- package/dist/types/types/Schema.d.mts +1 -1
- package/package.json +9 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvapterBase.cjs","names":["state","getDebugLevel","cache","normalizeSource","resolveKeyInput"],"sources":["../../../src/core/EnvapterBase.ts"],"sourcesContent":["import { ensureLoaded, mirrorToProcessEnv, refreshCache, resolveKeyInput } from './engine';\nimport { cache, state } from './state';\nimport { Validator } from '../engine/Validators';\nimport { getDebugLevel, setDebugLevel } from '../infra/Debug';\nimport { bindRuntimeFromSource } from '../infra/runtime';\nimport { normalizeSource } from '../sources/normalizeSource';\n\nimport type { DebugLevel } from '../infra/Debug';\nimport type { EnvKeyInput, FileApiMode, Source } from '../types';\n\
|
|
1
|
+
{"version":3,"file":"EnvapterBase.cjs","names":["state","getDebugLevel","cache","normalizeSource","resolveKeyInput"],"sources":["../../../src/core/EnvapterBase.ts"],"sourcesContent":["import { ensureLoaded, mirrorToProcessEnv, refreshCache, resolveKeyInput } from './engine';\nimport { cache, state } from './state';\nimport { Validator } from '../engine/Validators';\nimport { getDebugLevel, setDebugLevel } from '../infra/Debug';\nimport { bindRuntimeFromSource } from '../infra/runtime';\nimport { normalizeSource } from '../sources/normalizeSource';\n\nimport type { DebugLevel } from '../infra/Debug';\nimport type { EnvKeyInput, FileApiMode, Source } from '../types';\n\nexport abstract class EnvapterBase {\n /**\n * Enable or disable strict mode. Default `false`. Setting it clears and rebuilds the cache.\n * @see {@link https://envapt.materwelon.dev/docs/strict-mode#what-strict-mode-changes}\n */\n static set strict(value: boolean) {\n state.strict = value;\n refreshCache();\n }\n\n static get strict(): boolean {\n return state.strict;\n }\n\n /**\n * Set the debug log level. Defaults to `silent`. When unset, reads `ENVAPT_DEBUG` from the\n * bound source on first access. The setter overrides any env-var value. Output goes to stderr\n * on Node (the console elsewhere), prefixed with `[envapt]`.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#debug-logging}\n */\n static set debug(level: DebugLevel) {\n setDebugLevel(level);\n }\n\n static get debug(): DebugLevel {\n return getDebugLevel();\n }\n\n /**\n * Opt-in mirror of dotenv-loaded keys back to `process.env`. Default `false`.\n *\n * `envFileOptions.override` controls collisions because only keys the loader wrote are mirrored.\n * With the default `false`, existing `process.env` values stay. With `true`, the file value\n * wins in both the cache and the mirror.\n *\n * Flipping `false → true` mirrors the loaded keys immediately without a cache refresh.\n * Flipping `true → false` does not remove anything. Mirrored keys stay in `process.env`\n * until the process exits.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#mirroring-to-processenv}\n */\n static set syncProcessEnv(value: boolean) {\n Validator.validateSyncProcessEnv(value);\n const previous = state.syncProcessEnv;\n state.syncProcessEnv = value;\n if (!previous && value && cache.size > 0) mirrorToProcessEnv();\n }\n\n static get syncProcessEnv(): boolean {\n return state.syncProcessEnv;\n }\n\n /**\n * On the portable build, this controls the filesystem-only config APIs (`envPaths`, `baseDir`,\n * `envFileOptions`, `configureProfiles`, `resetProfiles`). `'warn'` (the default) warns once and\n * no-ops. `'throw'` throws {@link EnvaptError} `FileApiUnsupported`. The node build runs these\n * APIs normally and this value has no effect there.\n * @see {@link https://envapt.materwelon.dev/docs/compatibility#binding-by-runtime}\n */\n static set fileApiMode(mode: FileApiMode) {\n Validator.validateFileApiMode(mode);\n // only the portable stubs read this\n state.fileApiMode = mode;\n }\n\n static get fileApiMode(): FileApiMode {\n return state.fileApiMode;\n }\n\n /**\n * Eagerly load the `.env` cascade now instead of lazily on the first read. Idempotent: a no-op\n * once the cache is built. Useful before mirroring to `process.env` (see {@link syncProcessEnv}),\n * which is what the `envapt/config` side-effect entry does.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static load(): void {\n ensureLoaded();\n }\n\n /**\n * Bind the environment {@link Source}. On Node the entry binds {@link FileSource} for you\n * (a `process.env` snapshot plus the `.env` cascade). On the browser or Workers, pass a\n * `PortableSource` (or any `Source`) before reading. Pass a `(key) => string | undefined` reader for\n * a source that reads one key at a time and cannot list its keys. Clears and rebuilds the cache.\n * @see {@link https://envapt.materwelon.dev/docs/sources#the-providers}\n */\n static useSource(source: Source | ((key: string) => string | undefined)): void {\n const resolved = normalizeSource(source);\n state.source = resolved;\n bindRuntimeFromSource(resolved);\n refreshCache();\n }\n\n /**\n * Read an environment variable as its raw string, skipping parsing and conversion.\n * @see {@link https://envapt.materwelon.dev/docs/envapter#raw-values}\n */\n getRaw(key: EnvKeyInput): string | undefined {\n return resolveKeyInput(key).value;\n }\n}\n"],"mappings":"6MAUA,IAAsB,EAAtB,KAAmC,CAK/B,WAAW,OAAO,EAAgB,CAC9B,EAAA,MAAM,OAAS,EACf,EAAA,aAAa,CACjB,CAEA,WAAW,QAAkB,CACzB,OAAOA,EAAAA,MAAM,MACjB,CAQA,WAAW,MAAM,EAAmB,CAChC,EAAA,cAAc,CAAK,CACvB,CAEA,WAAW,OAAoB,CAC3B,OAAOC,EAAAA,cAAc,CACzB,CAcA,WAAW,eAAe,EAAgB,CACtC,EAAA,UAAU,uBAAuB,CAAK,EACtC,IAAM,EAAWD,EAAAA,MAAM,eACvB,EAAA,MAAM,eAAiB,EACnB,CAAC,GAAY,GAASE,EAAAA,MAAM,KAAO,GAAG,EAAA,mBAAmB,CACjE,CAEA,WAAW,gBAA0B,CACjC,OAAOF,EAAAA,MAAM,cACjB,CASA,WAAW,YAAY,EAAmB,CACtC,EAAA,UAAU,oBAAoB,CAAI,EAElC,EAAA,MAAM,YAAc,CACxB,CAEA,WAAW,aAA2B,CAClC,OAAOA,EAAAA,MAAM,WACjB,CAQA,OAAO,MAAa,CAChB,EAAA,aAAa,CACjB,CASA,OAAO,UAAU,EAA8D,CAC3E,IAAM,EAAWG,EAAAA,gBAAgB,CAAM,EACvC,EAAA,MAAM,OAAS,EACf,EAAA,sBAAsB,CAAQ,EAC9B,EAAA,aAAa,CACjB,CAMA,OAAO,EAAsC,CACzC,OAAOC,EAAAA,gBAAgB,CAAG,CAAC,CAAC,KAChC,CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvapterBase.mjs","names":[],"sources":["../../../src/core/EnvapterBase.ts"],"sourcesContent":["import { ensureLoaded, mirrorToProcessEnv, refreshCache, resolveKeyInput } from './engine';\nimport { cache, state } from './state';\nimport { Validator } from '../engine/Validators';\nimport { getDebugLevel, setDebugLevel } from '../infra/Debug';\nimport { bindRuntimeFromSource } from '../infra/runtime';\nimport { normalizeSource } from '../sources/normalizeSource';\n\nimport type { DebugLevel } from '../infra/Debug';\nimport type { EnvKeyInput, FileApiMode, Source } from '../types';\n\
|
|
1
|
+
{"version":3,"file":"EnvapterBase.mjs","names":[],"sources":["../../../src/core/EnvapterBase.ts"],"sourcesContent":["import { ensureLoaded, mirrorToProcessEnv, refreshCache, resolveKeyInput } from './engine';\nimport { cache, state } from './state';\nimport { Validator } from '../engine/Validators';\nimport { getDebugLevel, setDebugLevel } from '../infra/Debug';\nimport { bindRuntimeFromSource } from '../infra/runtime';\nimport { normalizeSource } from '../sources/normalizeSource';\n\nimport type { DebugLevel } from '../infra/Debug';\nimport type { EnvKeyInput, FileApiMode, Source } from '../types';\n\nexport abstract class EnvapterBase {\n /**\n * Enable or disable strict mode. Default `false`. Setting it clears and rebuilds the cache.\n * @see {@link https://envapt.materwelon.dev/docs/strict-mode#what-strict-mode-changes}\n */\n static set strict(value: boolean) {\n state.strict = value;\n refreshCache();\n }\n\n static get strict(): boolean {\n return state.strict;\n }\n\n /**\n * Set the debug log level. Defaults to `silent`. When unset, reads `ENVAPT_DEBUG` from the\n * bound source on first access. The setter overrides any env-var value. Output goes to stderr\n * on Node (the console elsewhere), prefixed with `[envapt]`.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#debug-logging}\n */\n static set debug(level: DebugLevel) {\n setDebugLevel(level);\n }\n\n static get debug(): DebugLevel {\n return getDebugLevel();\n }\n\n /**\n * Opt-in mirror of dotenv-loaded keys back to `process.env`. Default `false`.\n *\n * `envFileOptions.override` controls collisions because only keys the loader wrote are mirrored.\n * With the default `false`, existing `process.env` values stay. With `true`, the file value\n * wins in both the cache and the mirror.\n *\n * Flipping `false → true` mirrors the loaded keys immediately without a cache refresh.\n * Flipping `true → false` does not remove anything. Mirrored keys stay in `process.env`\n * until the process exits.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#mirroring-to-processenv}\n */\n static set syncProcessEnv(value: boolean) {\n Validator.validateSyncProcessEnv(value);\n const previous = state.syncProcessEnv;\n state.syncProcessEnv = value;\n if (!previous && value && cache.size > 0) mirrorToProcessEnv();\n }\n\n static get syncProcessEnv(): boolean {\n return state.syncProcessEnv;\n }\n\n /**\n * On the portable build, this controls the filesystem-only config APIs (`envPaths`, `baseDir`,\n * `envFileOptions`, `configureProfiles`, `resetProfiles`). `'warn'` (the default) warns once and\n * no-ops. `'throw'` throws {@link EnvaptError} `FileApiUnsupported`. The node build runs these\n * APIs normally and this value has no effect there.\n * @see {@link https://envapt.materwelon.dev/docs/compatibility#binding-by-runtime}\n */\n static set fileApiMode(mode: FileApiMode) {\n Validator.validateFileApiMode(mode);\n // only the portable stubs read this\n state.fileApiMode = mode;\n }\n\n static get fileApiMode(): FileApiMode {\n return state.fileApiMode;\n }\n\n /**\n * Eagerly load the `.env` cascade now instead of lazily on the first read. Idempotent: a no-op\n * once the cache is built. Useful before mirroring to `process.env` (see {@link syncProcessEnv}),\n * which is what the `envapt/config` side-effect entry does.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static load(): void {\n ensureLoaded();\n }\n\n /**\n * Bind the environment {@link Source}. On Node the entry binds {@link FileSource} for you\n * (a `process.env` snapshot plus the `.env` cascade). On the browser or Workers, pass a\n * `PortableSource` (or any `Source`) before reading. Pass a `(key) => string | undefined` reader for\n * a source that reads one key at a time and cannot list its keys. Clears and rebuilds the cache.\n * @see {@link https://envapt.materwelon.dev/docs/sources#the-providers}\n */\n static useSource(source: Source | ((key: string) => string | undefined)): void {\n const resolved = normalizeSource(source);\n state.source = resolved;\n bindRuntimeFromSource(resolved);\n refreshCache();\n }\n\n /**\n * Read an environment variable as its raw string, skipping parsing and conversion.\n * @see {@link https://envapt.materwelon.dev/docs/envapter#raw-values}\n */\n getRaw(key: EnvKeyInput): string | undefined {\n return resolveKeyInput(key).value;\n }\n}\n"],"mappings":"mZAUA,IAAsB,EAAtB,KAAmC,CAK/B,WAAW,OAAO,EAAgB,CAC9B,EAAM,OAAS,EACf,EAAa,CACjB,CAEA,WAAW,QAAkB,CACzB,OAAO,EAAM,MACjB,CAQA,WAAW,MAAM,EAAmB,CAChC,EAAc,CAAK,CACvB,CAEA,WAAW,OAAoB,CAC3B,OAAO,EAAc,CACzB,CAcA,WAAW,eAAe,EAAgB,CACtC,EAAU,uBAAuB,CAAK,EACtC,IAAM,EAAW,EAAM,eACvB,EAAM,eAAiB,EACnB,CAAC,GAAY,GAAS,EAAM,KAAO,GAAG,EAAmB,CACjE,CAEA,WAAW,gBAA0B,CACjC,OAAO,EAAM,cACjB,CASA,WAAW,YAAY,EAAmB,CACtC,EAAU,oBAAoB,CAAI,EAElC,EAAM,YAAc,CACxB,CAEA,WAAW,aAA2B,CAClC,OAAO,EAAM,WACjB,CAQA,OAAO,MAAa,CAChB,EAAa,CACjB,CASA,OAAO,UAAU,EAA8D,CAC3E,IAAM,EAAW,EAAgB,CAAM,EACvC,EAAM,OAAS,EACf,EAAsB,CAAQ,EAC9B,EAAa,CACjB,CAMA,OAAO,EAAsC,CACzC,OAAO,EAAgB,CAAG,CAAC,CAAC,KAChC,CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvironmentMethods.cjs","names":["EnvapterBase","state"],"sources":["../../../src/core/EnvironmentMethods.ts"],"sourcesContent":["import { determineEnvironment } from './engine';\nimport { EnvapterBase } from './EnvapterBase';\nimport { Environment } from './Environment';\nimport { state } from './state';\n\
|
|
1
|
+
{"version":3,"file":"EnvironmentMethods.cjs","names":["EnvapterBase","state"],"sources":["../../../src/core/EnvironmentMethods.ts"],"sourcesContent":["import { determineEnvironment } from './engine';\nimport { EnvapterBase } from './EnvapterBase';\nimport { Environment } from './Environment';\nimport { state } from './state';\n\nexport class EnvironmentMethods extends EnvapterBase {\n /**\n * Get the current application environment\n * @see {@link https://envapt.materwelon.dev/docs/environment#detecting-the-environment}\n */\n static get environment(): Environment {\n if (state.environment === undefined) {\n determineEnvironment();\n }\n return state.environment as Environment;\n }\n\n /**\n * Set the application environment. Accepts either Environment enum or string value.\n * @see {@link https://envapt.materwelon.dev/docs/environment#detecting-the-environment}\n */\n static set environment(env: string | Environment) {\n determineEnvironment(env);\n }\n\n /**\n * @see {@link EnvironmentMethods.environment}\n */\n get environment(): Environment {\n return EnvironmentMethods.environment;\n }\n\n /**\n * @see {@link EnvironmentMethods.environment}\n */\n set environment(env: string | Environment) {\n determineEnvironment(env);\n }\n\n /**\n * Check if the current environment is production\n * @see {@link https://envapt.materwelon.dev/docs/environment#branching-on-the-environment}\n */\n static get isProduction(): boolean {\n return this.environment === Environment.Production;\n }\n\n /**\n * @see {@link EnvironmentMethods.isProduction}\n */\n get isProduction(): boolean {\n return EnvironmentMethods.environment === Environment.Production;\n }\n\n /**\n * Check if the current environment is staging\n * @see {@link https://envapt.materwelon.dev/docs/environment#branching-on-the-environment}\n */\n static get isStaging(): boolean {\n return this.environment === Environment.Staging;\n }\n\n /**\n * @see {@link EnvironmentMethods.isStaging}\n */\n get isStaging(): boolean {\n return EnvironmentMethods.environment === Environment.Staging;\n }\n\n /**\n * Check if the current environment is development\n * @see {@link https://envapt.materwelon.dev/docs/environment#branching-on-the-environment}\n */\n static get isDevelopment(): boolean {\n return this.environment === Environment.Development;\n }\n\n /**\n * @see {@link EnvironmentMethods.isDevelopment}\n */\n get isDevelopment(): boolean {\n return EnvironmentMethods.environment === Environment.Development;\n }\n\n /**\n * Check if the current environment is test\n * @see {@link https://envapt.materwelon.dev/docs/environment#branching-on-the-environment}\n */\n static get isTest(): boolean {\n return this.environment === Environment.Test;\n }\n\n /**\n * @see {@link EnvironmentMethods.isTest}\n */\n get isTest(): boolean {\n return EnvironmentMethods.environment === Environment.Test;\n }\n}\n"],"mappings":"4HAKA,IAAa,EAAb,MAAa,UAA2BA,EAAAA,YAAa,CAKjD,WAAW,aAA2B,CAIlC,OAHIC,EAAAA,MAAM,cAAgB,IAAA,IACtB,EAAA,qBAAqB,EAElBA,EAAAA,MAAM,WACjB,CAMA,WAAW,YAAY,EAA2B,CAC9C,EAAA,qBAAqB,CAAG,CAC5B,CAKA,IAAI,aAA2B,CAC3B,OAAO,EAAmB,WAC9B,CAKA,IAAI,YAAY,EAA2B,CACvC,EAAA,qBAAqB,CAAG,CAC5B,CAMA,WAAW,cAAwB,CAC/B,OAAO,KAAK,cAAA,CAChB,CAKA,IAAI,cAAwB,CACxB,OAAO,EAAmB,cAAA,CAC9B,CAMA,WAAW,WAAqB,CAC5B,OAAO,KAAK,cAAA,CAChB,CAKA,IAAI,WAAqB,CACrB,OAAO,EAAmB,cAAA,CAC9B,CAMA,WAAW,eAAyB,CAChC,OAAO,KAAK,cAAA,CAChB,CAKA,IAAI,eAAyB,CACzB,OAAO,EAAmB,cAAA,CAC9B,CAMA,WAAW,QAAkB,CACzB,OAAO,KAAK,cAAA,CAChB,CAKA,IAAI,QAAkB,CAClB,OAAO,EAAmB,cAAA,CAC9B,CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvironmentMethods.mjs","names":[],"sources":["../../../src/core/EnvironmentMethods.ts"],"sourcesContent":["import { determineEnvironment } from './engine';\nimport { EnvapterBase } from './EnvapterBase';\nimport { Environment } from './Environment';\nimport { state } from './state';\n\
|
|
1
|
+
{"version":3,"file":"EnvironmentMethods.mjs","names":[],"sources":["../../../src/core/EnvironmentMethods.ts"],"sourcesContent":["import { determineEnvironment } from './engine';\nimport { EnvapterBase } from './EnvapterBase';\nimport { Environment } from './Environment';\nimport { state } from './state';\n\nexport class EnvironmentMethods extends EnvapterBase {\n /**\n * Get the current application environment\n * @see {@link https://envapt.materwelon.dev/docs/environment#detecting-the-environment}\n */\n static get environment(): Environment {\n if (state.environment === undefined) {\n determineEnvironment();\n }\n return state.environment as Environment;\n }\n\n /**\n * Set the application environment. Accepts either Environment enum or string value.\n * @see {@link https://envapt.materwelon.dev/docs/environment#detecting-the-environment}\n */\n static set environment(env: string | Environment) {\n determineEnvironment(env);\n }\n\n /**\n * @see {@link EnvironmentMethods.environment}\n */\n get environment(): Environment {\n return EnvironmentMethods.environment;\n }\n\n /**\n * @see {@link EnvironmentMethods.environment}\n */\n set environment(env: string | Environment) {\n determineEnvironment(env);\n }\n\n /**\n * Check if the current environment is production\n * @see {@link https://envapt.materwelon.dev/docs/environment#branching-on-the-environment}\n */\n static get isProduction(): boolean {\n return this.environment === Environment.Production;\n }\n\n /**\n * @see {@link EnvironmentMethods.isProduction}\n */\n get isProduction(): boolean {\n return EnvironmentMethods.environment === Environment.Production;\n }\n\n /**\n * Check if the current environment is staging\n * @see {@link https://envapt.materwelon.dev/docs/environment#branching-on-the-environment}\n */\n static get isStaging(): boolean {\n return this.environment === Environment.Staging;\n }\n\n /**\n * @see {@link EnvironmentMethods.isStaging}\n */\n get isStaging(): boolean {\n return EnvironmentMethods.environment === Environment.Staging;\n }\n\n /**\n * Check if the current environment is development\n * @see {@link https://envapt.materwelon.dev/docs/environment#branching-on-the-environment}\n */\n static get isDevelopment(): boolean {\n return this.environment === Environment.Development;\n }\n\n /**\n * @see {@link EnvironmentMethods.isDevelopment}\n */\n get isDevelopment(): boolean {\n return EnvironmentMethods.environment === Environment.Development;\n }\n\n /**\n * Check if the current environment is test\n * @see {@link https://envapt.materwelon.dev/docs/environment#branching-on-the-environment}\n */\n static get isTest(): boolean {\n return this.environment === Environment.Test;\n }\n\n /**\n * @see {@link EnvironmentMethods.isTest}\n */\n get isTest(): boolean {\n return EnvironmentMethods.environment === Environment.Test;\n }\n}\n"],"mappings":"oKAKA,IAAa,EAAb,MAAa,UAA2B,CAAa,CAKjD,WAAW,aAA2B,CAIlC,OAHI,EAAM,cAAgB,IAAA,IACtB,EAAqB,EAElB,EAAM,WACjB,CAMA,WAAW,YAAY,EAA2B,CAC9C,EAAqB,CAAG,CAC5B,CAKA,IAAI,aAA2B,CAC3B,OAAO,EAAmB,WAC9B,CAKA,IAAI,YAAY,EAA2B,CACvC,EAAqB,CAAG,CAC5B,CAMA,WAAW,cAAwB,CAC/B,OAAO,KAAK,cAAA,CAChB,CAKA,IAAI,cAAwB,CACxB,OAAO,EAAmB,cAAA,CAC9B,CAMA,WAAW,WAAqB,CAC5B,OAAO,KAAK,cAAA,CAChB,CAKA,IAAI,WAAqB,CACrB,OAAO,EAAmB,cAAA,CAC9B,CAMA,WAAW,eAAyB,CAChC,OAAO,KAAK,cAAA,CAChB,CAKA,IAAI,eAAyB,CACzB,OAAO,EAAmB,cAAA,CAC9B,CAMA,WAAW,QAAkB,CACzB,OAAO,KAAK,cAAA,CAChB,CAKA,IAAI,QAAkB,CAClB,OAAO,EAAmB,cAAA,CAC9B,CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrimitiveMethods.cjs","names":["EnvironmentMethods","readPrimitive"],"sources":["../../../src/core/PrimitiveMethods.ts"],"sourcesContent":["import { Primitive, readPrimitive } from './engine';\nimport { EnvironmentMethods } from './EnvironmentMethods';\n\nimport type { ConditionalReturn, EnvKeyInput } from '../types';\n\
|
|
1
|
+
{"version":3,"file":"PrimitiveMethods.cjs","names":["EnvironmentMethods","readPrimitive"],"sources":["../../../src/core/PrimitiveMethods.ts"],"sourcesContent":["import { Primitive, readPrimitive } from './engine';\nimport { EnvironmentMethods } from './EnvironmentMethods';\n\nimport type { ConditionalReturn, EnvKeyInput } from '../types';\n\nexport class PrimitiveMethods extends EnvironmentMethods {\n /**\n * Get a string environment variable with optional fallback.\n * Supports template variable resolution using `${VAR}` syntax.\n * Accepts a single key or an ordered array of keys (first match wins).\n * @see {@link https://envapt.materwelon.dev/docs/envapter#primitives}\n */\n static get<Default extends string | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<string, Default> {\n return readPrimitive(key, Primitive.String, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.get}\n */\n get<Default extends string | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<string, Default> {\n return readPrimitive(key, Primitive.String, def);\n }\n\n /**\n * Get a number environment variable with optional fallback.\n * Automatically converts string values to numbers.\n * Accepts a single key or an ordered array of keys (first match wins).\n * @see {@link https://envapt.materwelon.dev/docs/envapter#primitives}\n */\n static getNumber<Default extends number | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<number, Default> {\n return readPrimitive(key, Primitive.Number, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.getNumber}\n */\n getNumber<Default extends number | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<number, Default> {\n return readPrimitive(key, Primitive.Number, def);\n }\n\n /**\n * Get a boolean environment variable with optional fallback.\n * Recognizes: `1`, `yes`, `true`, `on` as **true**; `0`, `no`, `false`, `off` as **false** (case-insensitive).\n * Accepts a single key or an ordered array of keys (first match wins).\n * @see {@link https://envapt.materwelon.dev/docs/envapter#primitives}\n */\n static getBoolean<Default extends boolean | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<boolean, Default> {\n return readPrimitive(key, Primitive.Boolean, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.getBoolean}\n */\n getBoolean<Default extends boolean | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<boolean, Default> {\n return readPrimitive(key, Primitive.Boolean, def);\n }\n\n /**\n * Get a bigint environment variable with optional fallback.\n * Automatically converts string values to bigint.\n * Accepts a single key or an ordered array of keys (first match wins).\n * @see {@link https://envapt.materwelon.dev/docs/envapter#primitives}\n */\n static getBigInt<Default extends bigint | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<bigint, Default> {\n return readPrimitive(key, Primitive.BigInt, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.getBigInt}\n */\n getBigInt<Default extends bigint | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<bigint, Default> {\n return readPrimitive(key, Primitive.BigInt, def);\n }\n\n /**\n * Get a symbol environment variable with optional fallback.\n * Creates a symbol from the string value.\n * Accepts a single key or an ordered array of keys (first match wins).\n * @see {@link https://envapt.materwelon.dev/docs/envapter#primitives}\n */\n static getSymbol<Default extends symbol | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<symbol, Default> {\n return readPrimitive(key, Primitive.Symbol, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.getSymbol}\n */\n getSymbol<Default extends symbol | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<symbol, Default> {\n return readPrimitive(key, Primitive.Symbol, def);\n }\n}\n"],"mappings":"sEAKA,IAAa,EAAb,cAAsCA,EAAAA,kBAAmB,CAOrD,OAAO,IACH,EACA,EACkC,CAClC,OAAOC,EAAAA,cAAc,EAAA,EAAuB,CAAG,CACnD,CAKA,IACI,EACA,EACkC,CAClC,OAAOA,EAAAA,cAAc,EAAA,EAAuB,CAAG,CACnD,CAQA,OAAO,UACH,EACA,EACkC,CAClC,OAAOA,EAAAA,cAAc,EAAA,EAAuB,CAAG,CACnD,CAKA,UACI,EACA,EACkC,CAClC,OAAOA,EAAAA,cAAc,EAAA,EAAuB,CAAG,CACnD,CAQA,OAAO,WACH,EACA,EACmC,CACnC,OAAOA,EAAAA,cAAc,EAAA,EAAwB,CAAG,CACpD,CAKA,WACI,EACA,EACmC,CACnC,OAAOA,EAAAA,cAAc,EAAA,EAAwB,CAAG,CACpD,CAQA,OAAO,UACH,EACA,EACkC,CAClC,OAAOA,EAAAA,cAAc,EAAA,EAAuB,CAAG,CACnD,CAKA,UACI,EACA,EACkC,CAClC,OAAOA,EAAAA,cAAc,EAAA,EAAuB,CAAG,CACnD,CAQA,OAAO,UACH,EACA,EACkC,CAClC,OAAOA,EAAAA,cAAc,EAAA,EAAuB,CAAG,CACnD,CAKA,UACI,EACA,EACkC,CAClC,OAAOA,EAAAA,cAAc,EAAA,EAAuB,CAAG,CACnD,CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrimitiveMethods.mjs","names":[],"sources":["../../../src/core/PrimitiveMethods.ts"],"sourcesContent":["import { Primitive, readPrimitive } from './engine';\nimport { EnvironmentMethods } from './EnvironmentMethods';\n\nimport type { ConditionalReturn, EnvKeyInput } from '../types';\n\
|
|
1
|
+
{"version":3,"file":"PrimitiveMethods.mjs","names":[],"sources":["../../../src/core/PrimitiveMethods.ts"],"sourcesContent":["import { Primitive, readPrimitive } from './engine';\nimport { EnvironmentMethods } from './EnvironmentMethods';\n\nimport type { ConditionalReturn, EnvKeyInput } from '../types';\n\nexport class PrimitiveMethods extends EnvironmentMethods {\n /**\n * Get a string environment variable with optional fallback.\n * Supports template variable resolution using `${VAR}` syntax.\n * Accepts a single key or an ordered array of keys (first match wins).\n * @see {@link https://envapt.materwelon.dev/docs/envapter#primitives}\n */\n static get<Default extends string | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<string, Default> {\n return readPrimitive(key, Primitive.String, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.get}\n */\n get<Default extends string | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<string, Default> {\n return readPrimitive(key, Primitive.String, def);\n }\n\n /**\n * Get a number environment variable with optional fallback.\n * Automatically converts string values to numbers.\n * Accepts a single key or an ordered array of keys (first match wins).\n * @see {@link https://envapt.materwelon.dev/docs/envapter#primitives}\n */\n static getNumber<Default extends number | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<number, Default> {\n return readPrimitive(key, Primitive.Number, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.getNumber}\n */\n getNumber<Default extends number | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<number, Default> {\n return readPrimitive(key, Primitive.Number, def);\n }\n\n /**\n * Get a boolean environment variable with optional fallback.\n * Recognizes: `1`, `yes`, `true`, `on` as **true**; `0`, `no`, `false`, `off` as **false** (case-insensitive).\n * Accepts a single key or an ordered array of keys (first match wins).\n * @see {@link https://envapt.materwelon.dev/docs/envapter#primitives}\n */\n static getBoolean<Default extends boolean | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<boolean, Default> {\n return readPrimitive(key, Primitive.Boolean, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.getBoolean}\n */\n getBoolean<Default extends boolean | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<boolean, Default> {\n return readPrimitive(key, Primitive.Boolean, def);\n }\n\n /**\n * Get a bigint environment variable with optional fallback.\n * Automatically converts string values to bigint.\n * Accepts a single key or an ordered array of keys (first match wins).\n * @see {@link https://envapt.materwelon.dev/docs/envapter#primitives}\n */\n static getBigInt<Default extends bigint | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<bigint, Default> {\n return readPrimitive(key, Primitive.BigInt, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.getBigInt}\n */\n getBigInt<Default extends bigint | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<bigint, Default> {\n return readPrimitive(key, Primitive.BigInt, def);\n }\n\n /**\n * Get a symbol environment variable with optional fallback.\n * Creates a symbol from the string value.\n * Accepts a single key or an ordered array of keys (first match wins).\n * @see {@link https://envapt.materwelon.dev/docs/envapter#primitives}\n */\n static getSymbol<Default extends symbol | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<symbol, Default> {\n return readPrimitive(key, Primitive.Symbol, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.getSymbol}\n */\n getSymbol<Default extends symbol | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<symbol, Default> {\n return readPrimitive(key, Primitive.Symbol, def);\n }\n}\n"],"mappings":"2GAKA,IAAa,EAAb,cAAsC,CAAmB,CAOrD,OAAO,IACH,EACA,EACkC,CAClC,OAAO,EAAc,EAAA,EAAuB,CAAG,CACnD,CAKA,IACI,EACA,EACkC,CAClC,OAAO,EAAc,EAAA,EAAuB,CAAG,CACnD,CAQA,OAAO,UACH,EACA,EACkC,CAClC,OAAO,EAAc,EAAA,EAAuB,CAAG,CACnD,CAKA,UACI,EACA,EACkC,CAClC,OAAO,EAAc,EAAA,EAAuB,CAAG,CACnD,CAQA,OAAO,WACH,EACA,EACmC,CACnC,OAAO,EAAc,EAAA,EAAwB,CAAG,CACpD,CAKA,WACI,EACA,EACmC,CACnC,OAAO,EAAc,EAAA,EAAwB,CAAG,CACpD,CAQA,OAAO,UACH,EACA,EACkC,CAClC,OAAO,EAAc,EAAA,EAAuB,CAAG,CACnD,CAKA,UACI,EACA,EACkC,CAClC,OAAO,EAAc,EAAA,EAAuB,CAAG,CACnD,CAQA,OAAO,UACH,EACA,EACkC,CAClC,OAAO,EAAc,EAAA,EAAuB,CAAG,CACnD,CAKA,UACI,EACA,EACkC,CAClC,OAAO,EAAc,EAAA,EAAuB,CAAG,CACnD,CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.cjs","names":["EnvaptError","isMissing","state","resolveEffectivePaths","loadDotenv","cache","parseEnvironment","firstEnvKeyValue","ENV_KEYS","TemplateResolver","ValueConverter","BuiltInConverters"],"sources":["../../../src/core/engine.ts"],"sourcesContent":["import { BuiltInConverters, ValueConverter } from '../converters';\nimport { ENV_KEYS, Environment, firstEnvKeyValue, parseEnvironment } from './Environment';\nimport { isMissing } from './missing';\nimport { resolveEffectivePaths } from './paths';\nimport { cache, state } from './state';\nimport { TemplateResolver } from '../engine/TemplateResolver';\nimport { debugVerbose, debugWarn } from '../infra/Debug';\nimport { loadDotenv } from '../infra/Dotenv';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { ConditionalReturn, EnvKeyInput } from '../types';\nimport type { EnvapterService } from '../types/Env';\n\nexport function resolveKeyInput(keyInput: EnvKeyInput): { key: string; value: string | undefined } {\n const keys = Array.isArray(keyInput) ? keyInput : [keyInput];\n const normalizedKeys = keys as readonly string[];\n\n if (normalizedKeys.length === 0) {\n throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, 'At least one environment key must be provided.');\n }\n\n if (normalizedKeys.some((k) => typeof k !== 'string')) {\n throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, 'Environment keys must be strings.');\n }\n\n if (normalizedKeys.some((k) => k.trim() === '')) {\n throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, 'Environment keys cannot be empty strings.');\n }\n\n // An ordered read keeps trying so a present-but-empty candidate falls through to the next, matching\n // getRequired and firstEnvKeyValue. A single key or an all-empty list resolves to the first present value.\n let firstPresent: { key: string; value: string } | undefined;\n for (const candidate of normalizedKeys) {\n const value = readCached(candidate);\n if (value === undefined) continue;\n if (!isMissing(value)) return { key: candidate, value };\n firstPresent ??= { key: candidate, value };\n }\n\n return firstPresent ?? { key: normalizedKeys[0] as string, value: undefined };\n}\n\nexport function ensureLoaded(): Map<string, unknown> {\n if (!state.cacheBuilt) {\n const source = state.source;\n // Clone so the loader and downstream reads never mutate the source's backing object.\n const isolatedEnv: Record<string, string> = { ...source.readVars() };\n\n let added = new Set<string>();\n // Sources without a filesystem (injected objects on the browser or Workers) skip the .env\n // cascade, profiles, and envPaths. Only the readVars() snapshot populates the cache.\n if (source.supportsFiles) {\n debugVerbose(`base dir: ${state.baseDir ?? 'working directory'}`);\n // Outside the try below so a missing configured profile path surfaces its EnvaptError. Only dotenv parse errors stay caught.\n const effectivePaths = resolveEffectivePaths();\n debugVerbose(`effective .env paths: ${effectivePaths.length === 0 ? '(none)' : effectivePaths.join(', ')}`);\n try {\n added = loadDotenv({\n ...state.userDefinedEnvFileOptions,\n path: effectivePaths,\n processEnv: isolatedEnv,\n readFile: source.readFile.bind(source)\n });\n } catch (error) {\n debugWarn(`failed to load .env: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n state.dotenvAddedKeys = added;\n for (const [key, value] of Object.entries(isolatedEnv)) cache.set(key, value);\n debugVerbose(`cache populated: ${cache.size} keys total`);\n // set before mirroring, whose template expansion reads the cache and would re-enter this build otherwise\n state.cacheBuilt = true;\n if (state.syncProcessEnv) mirrorToProcessEnv();\n }\n\n return cache;\n}\n\nfunction readCached(key: string): string | undefined {\n const c = ensureLoaded();\n // decorator memoization also stores non-string values in this shared cache\n if (c.has(key)) {\n const cached = c.get(key);\n return typeof cached === 'string' ? cached : undefined;\n }\n const source = state.source;\n if (typeof source.readVar !== 'function') return undefined;\n const value = source.readVar(key);\n // cache a miss too, so a later read of an absent key skips the reader\n c.set(key, value);\n return value;\n}\n\nexport function refreshCache(): void {\n // Reset an inferred environment so re-hydration re-determines it from current state. An explicit\n // Envapter.environment = X is preserved through the refresh and used for cascade selection.\n if (!state.environmentExplicitlySet) state.environment = undefined;\n cache.clear();\n state.cacheBuilt = false;\n state.dotenvAddedKeys = new Set<string>();\n debugVerbose('cache cleared, reloading config');\n ensureLoaded();\n}\n\nexport function mirrorToProcessEnv(): void {\n if (state.dotenvAddedKeys.size === 0) return;\n const source = state.source;\n /* v8 ignore next -- @preserve dotenv keys only accumulate under a file source, so the delta implies supportsFiles here */\n if (!source.supportsFiles) return;\n const mirrored: Record<string, string> = {};\n for (const key of state.dotenvAddedKeys) {\n const value = cache.get(key);\n /* v8 ignore next -- @preserve loader only writes strings, defensive against future cache contents */\n if (typeof value !== 'string') continue;\n mirrored[key] = resolveForMirror(key, value);\n debugVerbose(`mirrored ${key} to the ambient environment`);\n }\n source.writeVars(mirrored);\n debugVerbose(`mirrored ${state.dotenvAddedKeys.size} keys to the ambient environment`);\n}\n\nfunction resolveForMirror(key: string, value: string): string {\n return templateResolver.resolveTemplate(key, value);\n}\n\nexport function determineEnvironment(env?: string | Environment): void {\n if (typeof env === 'number') {\n state.environment = env;\n state.environmentExplicitlySet = true;\n return;\n }\n if (typeof env === 'string') {\n state.environment = parseEnvironment(env) ?? Environment.Development;\n state.environmentExplicitlySet = true;\n return;\n }\n\n const raw = firstEnvKeyValue((key) => readCached(key));\n if (raw === undefined) {\n debugWarn(`no environment set (looked for ${ENV_KEYS.join(', ')}); defaulting to development`);\n state.environment = Environment.Development;\n return;\n }\n const parsed = parseEnvironment(raw);\n if (parsed === undefined) {\n debugWarn(`unrecognized environment \"${raw}\"; defaulting to development`);\n state.environment = Environment.Development;\n return;\n }\n state.environment = parsed;\n}\n\n/**\n * @internal\n */\nexport enum Primitive {\n String,\n Number,\n Boolean,\n BigInt,\n Symbol\n}\n\nconst PRIMITIVE_NAMES: Record<Primitive, string> = {\n [Primitive.String]: 'string',\n [Primitive.Number]: 'number',\n [Primitive.Boolean]: 'boolean',\n [Primitive.BigInt]: 'bigint',\n [Primitive.Symbol]: 'symbol'\n};\n\n// getRaw is the raw string lookup, get is the template-resolved string read. Lazy arrows so the\n// resolver singletons below store envService without calling readPrimitive, which reads\n// templateResolver before it is assigned.\nconst envService: EnvapterService = {\n getRaw: (key) => resolveKeyInput(key).value,\n get: (key, def) => readPrimitive<string, string | undefined>(key, Primitive.String, def)\n};\n\nexport const templateResolver: TemplateResolver = new TemplateResolver(envService);\nexport const valueConverter: ValueConverter = new ValueConverter(envService);\n\nexport function readPrimitive<EnvVarReturnType, DefaultType extends EnvVarReturnType | undefined = undefined>(\n key: EnvKeyInput,\n type: Primitive,\n def?: DefaultType\n): ConditionalReturn<EnvVarReturnType, DefaultType> {\n const { key: resolvedKey, value } = resolveKeyInput(key);\n if (isMissing(value)) {\n if (def !== undefined) debugWarn(`${resolvedKey} is missing or empty, using fallback ${String(def)}`);\n else debugWarn(`${resolvedKey} is missing or empty`);\n return def as ConditionalReturn<EnvVarReturnType, DefaultType>;\n }\n\n const parsed = templateResolver.resolveTemplate(resolvedKey, String(value));\n\n let converted: EnvVarReturnType | undefined;\n if (type === Primitive.Number) converted = BuiltInConverters.number(parsed) as EnvVarReturnType | undefined;\n else if (type === Primitive.Boolean) converted = BuiltInConverters.boolean(parsed) as EnvVarReturnType | undefined;\n else if (type === Primitive.BigInt) converted = BuiltInConverters.bigint(parsed) as EnvVarReturnType | undefined;\n else if (type === Primitive.Symbol) converted = BuiltInConverters.symbol(parsed) as EnvVarReturnType | undefined;\n else converted = BuiltInConverters.string(parsed) as EnvVarReturnType | 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 ${resolvedKey} as ${PRIMITIVE_NAMES[type]}${def !== undefined ? ', using the fallback' : ''}`\n );\n return def as ConditionalReturn<EnvVarReturnType, DefaultType>;\n }\n\n return converted;\n}\n"],"mappings":"8VAaA,SAAgB,EAAgB,EAAmE,CAE/F,IAAM,EADO,MAAM,QAAQ,CAAQ,EAAI,EAAW,CAAC,CAAQ,EAG3D,GAAI,EAAe,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,CAAM,EACjE,IAAA,EAAwCA,EAAAA,kBAAkB,QAAQ,CAAM,EACxE,IAAA,EAAuCA,EAAAA,kBAAkB,OAAO,CAAM,EACtE,IAAA,EAAuCA,EAAAA,kBAAkB,OAAO,CAAM,EAC9DA,EAAAA,kBAAkB,OAAO,CAAM,EAE5C,IAAc,IAAA,IAEd,EAAA,aACI,qBAAqB,EAAY,MAAM,EAAgB,KAAQ,IAAQ,IAAA,GAAqC,GAAzB,wBACvF,EACO,GAGJ,CACX"}
|
|
1
|
+
{"version":3,"file":"engine.cjs","names":["EnvaptError","isMissing","state","resolveEffectivePaths","loadDotenv","cache","parseEnvironment","firstEnvKeyValue","ENV_KEYS","TemplateResolver","ValueConverter","BuiltInConverters"],"sources":["../../../src/core/engine.ts"],"sourcesContent":["import { BuiltInConverters, ValueConverter } from '../converters';\nimport { ENV_KEYS, Environment, firstEnvKeyValue, parseEnvironment } from './Environment';\nimport { isMissing } from './missing';\nimport { resolveEffectivePaths } from './paths';\nimport { cache, state } from './state';\nimport { TemplateResolver } from '../engine/TemplateResolver';\nimport { debugVerbose, debugWarn } from '../infra/Debug';\nimport { loadDotenv } from '../infra/Dotenv';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { ConditionalReturn, EnvKeyInput } from '../types';\nimport type { EnvapterService } from '../types/Env';\n\nexport function resolveKeyInput(keyInput: EnvKeyInput): { key: string; value: string | undefined } {\n const keys = Array.isArray(keyInput) ? keyInput : [keyInput];\n const normalizedKeys = keys as readonly string[];\n\n if (normalizedKeys.length === 0) {\n throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, 'At least one environment key must be provided.');\n }\n\n if (normalizedKeys.some((k) => typeof k !== 'string')) {\n throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, 'Environment keys must be strings.');\n }\n\n if (normalizedKeys.some((k) => k.trim() === '')) {\n throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, 'Environment keys cannot be empty strings.');\n }\n\n // an empty value falls through to the next key and only comes back when every key is empty\n let firstPresent: { key: string; value: string } | undefined;\n for (const candidate of normalizedKeys) {\n const value = readCached(candidate);\n if (value === undefined) continue;\n if (!isMissing(value)) return { key: candidate, value };\n firstPresent ??= { key: candidate, value };\n }\n\n return firstPresent ?? { key: normalizedKeys[0] as string, value: undefined };\n}\n\nexport function ensureLoaded(): Map<string, unknown> {\n if (!state.cacheBuilt) {\n const source = state.source;\n // the loader writes into this object\n const isolatedEnv: Record<string, string> = { ...source.readVars() };\n\n let added = new Set<string>();\n if (source.supportsFiles) {\n debugVerbose(`base dir: ${state.baseDir ?? 'working directory'}`);\n // outside the try because a missing profile path has to throw\n const effectivePaths = resolveEffectivePaths();\n debugVerbose(`effective .env paths: ${effectivePaths.length === 0 ? '(none)' : effectivePaths.join(', ')}`);\n try {\n added = loadDotenv({\n ...state.userDefinedEnvFileOptions,\n path: effectivePaths,\n processEnv: isolatedEnv,\n readFile: source.readFile.bind(source)\n });\n } catch (error) {\n debugWarn(`failed to load .env: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n state.dotenvAddedKeys = added;\n for (const [key, value] of Object.entries(isolatedEnv)) cache.set(key, value);\n debugVerbose(`cache populated: ${cache.size} keys total`);\n // set before mirroring because template expansion reads the cache\n state.cacheBuilt = true;\n if (state.syncProcessEnv) mirrorToProcessEnv();\n }\n\n return cache;\n}\n\nfunction readCached(key: string): string | undefined {\n const c = ensureLoaded();\n // decorator memoization also stores non-string values in this shared cache\n if (c.has(key)) {\n const cached = c.get(key);\n return typeof cached === 'string' ? cached : undefined;\n }\n const source = state.source;\n if (typeof source.readVar !== 'function') return undefined;\n const value = source.readVar(key);\n // caches misses too\n c.set(key, value);\n return value;\n}\n\nexport function refreshCache(): void {\n // an inferred environment can change once the new vars load\n if (!state.environmentExplicitlySet) state.environment = undefined;\n cache.clear();\n state.cacheBuilt = false;\n state.dotenvAddedKeys = new Set<string>();\n debugVerbose('cache cleared, reloading config');\n ensureLoaded();\n}\n\nexport function mirrorToProcessEnv(): void {\n if (state.dotenvAddedKeys.size === 0) return;\n const source = state.source;\n /* v8 ignore next -- @preserve dotenv keys only accumulate under a file source, so the delta implies supportsFiles here */\n if (!source.supportsFiles) return;\n const mirrored: Record<string, string> = {};\n for (const key of state.dotenvAddedKeys) {\n const value = cache.get(key);\n /* v8 ignore next -- @preserve the loader only writes strings */\n if (typeof value !== 'string') continue;\n mirrored[key] = resolveForMirror(key, value);\n debugVerbose(`mirrored ${key} to the ambient environment`);\n }\n source.writeVars(mirrored);\n debugVerbose(`mirrored ${state.dotenvAddedKeys.size} keys to the ambient environment`);\n}\n\nfunction resolveForMirror(key: string, value: string): string {\n return templateResolver.resolveTemplate(key, value);\n}\n\nexport function determineEnvironment(env?: string | Environment): void {\n if (typeof env === 'number') {\n state.environment = env;\n state.environmentExplicitlySet = true;\n return;\n }\n if (typeof env === 'string') {\n state.environment = parseEnvironment(env) ?? Environment.Development;\n state.environmentExplicitlySet = true;\n return;\n }\n\n const raw = firstEnvKeyValue((key) => readCached(key));\n if (raw === undefined) {\n debugWarn(`no environment set (looked for ${ENV_KEYS.join(', ')}); defaulting to development`);\n state.environment = Environment.Development;\n return;\n }\n const parsed = parseEnvironment(raw);\n if (parsed === undefined) {\n debugWarn(`unrecognized environment \"${raw}\"; defaulting to development`);\n state.environment = Environment.Development;\n return;\n }\n state.environment = parsed;\n}\n\nexport enum Primitive {\n String,\n Number,\n Boolean,\n BigInt,\n Symbol\n}\n\nconst PRIMITIVE_NAMES: Record<Primitive, string> = {\n [Primitive.String]: 'string',\n [Primitive.Number]: 'number',\n [Primitive.Boolean]: 'boolean',\n [Primitive.BigInt]: 'bigint',\n [Primitive.Symbol]: 'symbol'\n};\n\n// arrows because readPrimitive reads templateResolver, which is assigned below\nconst envService: EnvapterService = {\n getRaw: (key) => resolveKeyInput(key).value,\n get: (key, def) => readPrimitive<string, string | undefined>(key, Primitive.String, def)\n};\n\nexport const templateResolver: TemplateResolver = new TemplateResolver(envService);\nexport const valueConverter: ValueConverter = new ValueConverter(envService);\n\nexport function readPrimitive<EnvVarReturnType, DefaultType extends EnvVarReturnType | undefined = undefined>(\n key: EnvKeyInput,\n type: Primitive,\n def?: DefaultType\n): ConditionalReturn<EnvVarReturnType, DefaultType> {\n const { key: resolvedKey, value } = resolveKeyInput(key);\n if (isMissing(value)) {\n if (def !== undefined) debugWarn(`${resolvedKey} is missing or empty, using fallback ${String(def)}`);\n else debugWarn(`${resolvedKey} is missing or empty`);\n return def as ConditionalReturn<EnvVarReturnType, DefaultType>;\n }\n\n const parsed = templateResolver.resolveTemplate(resolvedKey, String(value));\n\n let converted: EnvVarReturnType | undefined;\n if (type === Primitive.Number) converted = BuiltInConverters.number(parsed) as EnvVarReturnType | undefined;\n else if (type === Primitive.Boolean) converted = BuiltInConverters.boolean(parsed) as EnvVarReturnType | undefined;\n else if (type === Primitive.BigInt) converted = BuiltInConverters.bigint(parsed) as EnvVarReturnType | undefined;\n else if (type === Primitive.Symbol) converted = BuiltInConverters.symbol(parsed) as EnvVarReturnType | undefined;\n else converted = BuiltInConverters.string(parsed) as EnvVarReturnType | undefined;\n\n if (converted === undefined) {\n // leave the value out because env values can be secrets\n debugVerbose(\n `could not convert ${resolvedKey} as ${PRIMITIVE_NAMES[type]}${def !== undefined ? ', using the fallback' : ''}`\n );\n return def as ConditionalReturn<EnvVarReturnType, DefaultType>;\n }\n\n return converted;\n}\n"],"mappings":"8VAaA,SAAgB,EAAgB,EAAmE,CAE/F,IAAM,EADO,MAAM,QAAQ,CAAQ,EAAI,EAAW,CAAC,CAAQ,EAG3D,GAAI,EAAe,SAAW,EAC1B,MAAM,IAAIA,EAAAA,YAAAA,IAA8C,gDAAgD,EAG5G,GAAI,EAAe,KAAM,GAAM,OAAO,GAAM,QAAQ,EAChD,MAAM,IAAIA,EAAAA,YAAAA,IAA8C,mCAAmC,EAG/F,GAAI,EAAe,KAAM,GAAM,EAAE,KAAK,IAAM,EAAE,EAC1C,MAAM,IAAIA,EAAAA,YA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M,EAAgB,KAAQ,IAAQ,IAAA,GAAqC,GAAzB,wBACvF,EACO,GAGJ,CACX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.mjs","names":[],"sources":["../../../src/core/engine.ts"],"sourcesContent":["import { BuiltInConverters, ValueConverter } from '../converters';\nimport { ENV_KEYS, Environment, firstEnvKeyValue, parseEnvironment } from './Environment';\nimport { isMissing } from './missing';\nimport { resolveEffectivePaths } from './paths';\nimport { cache, state } from './state';\nimport { TemplateResolver } from '../engine/TemplateResolver';\nimport { debugVerbose, debugWarn } from '../infra/Debug';\nimport { loadDotenv } from '../infra/Dotenv';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { ConditionalReturn, EnvKeyInput } from '../types';\nimport type { EnvapterService } from '../types/Env';\n\nexport function resolveKeyInput(keyInput: EnvKeyInput): { key: string; value: string | undefined } {\n const keys = Array.isArray(keyInput) ? keyInput : [keyInput];\n const normalizedKeys = keys as readonly string[];\n\n if (normalizedKeys.length === 0) {\n throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, 'At least one environment key must be provided.');\n }\n\n if (normalizedKeys.some((k) => typeof k !== 'string')) {\n throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, 'Environment keys must be strings.');\n }\n\n if (normalizedKeys.some((k) => k.trim() === '')) {\n throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, 'Environment keys cannot be empty strings.');\n }\n\n // An ordered read keeps trying so a present-but-empty candidate falls through to the next, matching\n // getRequired and firstEnvKeyValue. A single key or an all-empty list resolves to the first present value.\n let firstPresent: { key: string; value: string } | undefined;\n for (const candidate of normalizedKeys) {\n const value = readCached(candidate);\n if (value === undefined) continue;\n if (!isMissing(value)) return { key: candidate, value };\n firstPresent ??= { key: candidate, value };\n }\n\n return firstPresent ?? { key: normalizedKeys[0] as string, value: undefined };\n}\n\nexport function ensureLoaded(): Map<string, unknown> {\n if (!state.cacheBuilt) {\n const source = state.source;\n // Clone so the loader and downstream reads never mutate the source's backing object.\n const isolatedEnv: Record<string, string> = { ...source.readVars() };\n\n let added = new Set<string>();\n // Sources without a filesystem (injected objects on the browser or Workers) skip the .env\n // cascade, profiles, and envPaths. Only the readVars() snapshot populates the cache.\n if (source.supportsFiles) {\n debugVerbose(`base dir: ${state.baseDir ?? 'working directory'}`);\n // Outside the try below so a missing configured profile path surfaces its EnvaptError. Only dotenv parse errors stay caught.\n const effectivePaths = resolveEffectivePaths();\n debugVerbose(`effective .env paths: ${effectivePaths.length === 0 ? '(none)' : effectivePaths.join(', ')}`);\n try {\n added = loadDotenv({\n ...state.userDefinedEnvFileOptions,\n path: effectivePaths,\n processEnv: isolatedEnv,\n readFile: source.readFile.bind(source)\n });\n } catch (error) {\n debugWarn(`failed to load .env: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n state.dotenvAddedKeys = added;\n for (const [key, value] of Object.entries(isolatedEnv)) cache.set(key, value);\n debugVerbose(`cache populated: ${cache.size} keys total`);\n // set before mirroring, whose template expansion reads the cache and would re-enter this build otherwise\n state.cacheBuilt = true;\n if (state.syncProcessEnv) mirrorToProcessEnv();\n }\n\n return cache;\n}\n\nfunction readCached(key: string): string | undefined {\n const c = ensureLoaded();\n // decorator memoization also stores non-string values in this shared cache\n if (c.has(key)) {\n const cached = c.get(key);\n return typeof cached === 'string' ? cached : undefined;\n }\n const source = state.source;\n if (typeof source.readVar !== 'function') return undefined;\n const value = source.readVar(key);\n // cache a miss too, so a later read of an absent key skips the reader\n c.set(key, value);\n return value;\n}\n\nexport function refreshCache(): void {\n // Reset an inferred environment so re-hydration re-determines it from current state. An explicit\n // Envapter.environment = X is preserved through the refresh and used for cascade selection.\n if (!state.environmentExplicitlySet) state.environment = undefined;\n cache.clear();\n state.cacheBuilt = false;\n state.dotenvAddedKeys = new Set<string>();\n debugVerbose('cache cleared, reloading config');\n ensureLoaded();\n}\n\nexport function mirrorToProcessEnv(): void {\n if (state.dotenvAddedKeys.size === 0) return;\n const source = state.source;\n /* v8 ignore next -- @preserve dotenv keys only accumulate under a file source, so the delta implies supportsFiles here */\n if (!source.supportsFiles) return;\n const mirrored: Record<string, string> = {};\n for (const key of state.dotenvAddedKeys) {\n const value = cache.get(key);\n /* v8 ignore next -- @preserve loader only writes strings, defensive against future cache contents */\n if (typeof value !== 'string') continue;\n mirrored[key] = resolveForMirror(key, value);\n debugVerbose(`mirrored ${key} to the ambient environment`);\n }\n source.writeVars(mirrored);\n debugVerbose(`mirrored ${state.dotenvAddedKeys.size} keys to the ambient environment`);\n}\n\nfunction resolveForMirror(key: string, value: string): string {\n return templateResolver.resolveTemplate(key, value);\n}\n\nexport function determineEnvironment(env?: string | Environment): void {\n if (typeof env === 'number') {\n state.environment = env;\n state.environmentExplicitlySet = true;\n return;\n }\n if (typeof env === 'string') {\n state.environment = parseEnvironment(env) ?? Environment.Development;\n state.environmentExplicitlySet = true;\n return;\n }\n\n const raw = firstEnvKeyValue((key) => readCached(key));\n if (raw === undefined) {\n debugWarn(`no environment set (looked for ${ENV_KEYS.join(', ')}); defaulting to development`);\n state.environment = Environment.Development;\n return;\n }\n const parsed = parseEnvironment(raw);\n if (parsed === undefined) {\n debugWarn(`unrecognized environment \"${raw}\"; defaulting to development`);\n state.environment = Environment.Development;\n return;\n }\n state.environment = parsed;\n}\n\n/**\n * @internal\n */\nexport enum Primitive {\n String,\n Number,\n Boolean,\n BigInt,\n Symbol\n}\n\nconst PRIMITIVE_NAMES: Record<Primitive, string> = {\n [Primitive.String]: 'string',\n [Primitive.Number]: 'number',\n [Primitive.Boolean]: 'boolean',\n [Primitive.BigInt]: 'bigint',\n [Primitive.Symbol]: 'symbol'\n};\n\n// getRaw is the raw string lookup, get is the template-resolved string read. Lazy arrows so the\n// resolver singletons below store envService without calling readPrimitive, which reads\n// templateResolver before it is assigned.\nconst envService: EnvapterService = {\n getRaw: (key) => resolveKeyInput(key).value,\n get: (key, def) => readPrimitive<string, string | undefined>(key, Primitive.String, def)\n};\n\nexport const templateResolver: TemplateResolver = new TemplateResolver(envService);\nexport const valueConverter: ValueConverter = new ValueConverter(envService);\n\nexport function readPrimitive<EnvVarReturnType, DefaultType extends EnvVarReturnType | undefined = undefined>(\n key: EnvKeyInput,\n type: Primitive,\n def?: DefaultType\n): ConditionalReturn<EnvVarReturnType, DefaultType> {\n const { key: resolvedKey, value } = resolveKeyInput(key);\n if (isMissing(value)) {\n if (def !== undefined) debugWarn(`${resolvedKey} is missing or empty, using fallback ${String(def)}`);\n else debugWarn(`${resolvedKey} is missing or empty`);\n return def as ConditionalReturn<EnvVarReturnType, DefaultType>;\n }\n\n const parsed = templateResolver.resolveTemplate(resolvedKey, String(value));\n\n let converted: EnvVarReturnType | undefined;\n if (type === Primitive.Number) converted = BuiltInConverters.number(parsed) as EnvVarReturnType | undefined;\n else if (type === Primitive.Boolean) converted = BuiltInConverters.boolean(parsed) as EnvVarReturnType | undefined;\n else if (type === Primitive.BigInt) converted = BuiltInConverters.bigint(parsed) as EnvVarReturnType | undefined;\n else if (type === Primitive.Symbol) converted = BuiltInConverters.symbol(parsed) as EnvVarReturnType | undefined;\n else converted = BuiltInConverters.string(parsed) as EnvVarReturnType | 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 ${resolvedKey} as ${PRIMITIVE_NAMES[type]}${def !== undefined ? ', using the fallback' : ''}`\n );\n return def as ConditionalReturn<EnvVarReturnType, DefaultType>;\n }\n\n return converted;\n}\n"],"mappings":"qlBAaA,SAAgB,EAAgB,EAAmE,CAE/F,IAAM,EADO,MAAM,QAAQ,CAAQ,EAAI,EAAW,CAAC,CAAQ,EAG3D,GAAI,EAAe,SAAW,EAC1B,MAAM,IAAI,EAAA,IAA8C,gDAAgD,EAG5G,GAAI,EAAe,KAAM,GAAM,OAAO,GAAM,QAAQ,EAChD,MAAM,IAAI,EAAA,IAA8C,mCAAmC,EAG/F,GAAI,EAAe,KAAM,GAAM,EAAE,KAAK,IAAM,EAA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EACxE,EAAM,YAAA,EACN,MACJ,CACA,EAAM,YAAc,CACxB,CAaA,MAAM,EAA6C,CAC3B,EAAA,SACA,EAAA,SACC,EAAA,UACD,EAAA,SACA,EAAA,QACxB,EAKM,EAA8B,CAChC,OAAS,GAAQ,EAAgB,CAAG,CAAC,CAAC,MACtC,KAAM,EAAK,IAAQ,EAA0C,EAAA,EAAuB,CAAG,CAC3F,EAEa,EAAqC,IAAI,EAAiB,CAAU,EACpE,EAAiC,IAAI,EAAe,CAAU,EAE3E,SAAgB,EACZ,EACA,EACA,EACgD,CAChD,GAAM,CAAE,IAAK,EAAa,SAAU,EAAgB,CAAG,EACvD,GAAI,EAAU,CAAK,EAGf,OADK,EADD,IAAQ,IAAA,GACG,GAAG,EAAY,sBADG,GAAG,EAAY,uCAAuC,OAAO,CAAG,GAC9C,EAC5C,EAGX,IAAM,EAAS,EAAiB,gBAAgB,EAAa,OAAO,CAAK,CAAC,EAEtE,EAeJ,MAdA,CAIK,EAJD,IAAA,EAAuC,EAAkB,OAAO,CAAM,EACjE,IAAA,EAAwC,EAAkB,QAAQ,CAAM,EACxE,IAAA,EAAuC,EAAkB,OAAO,CAAM,EACtE,IAAA,EAAuC,EAAkB,OAAO,CAAM,EAC9D,EAAkB,OAAO,CAAM,EAE5C,IAAc,IAAA,IAEd,EACI,qBAAqB,EAAY,MAAM,EAAgB,KAAQ,IAAQ,IAAA,GAAqC,GAAzB,wBACvF,EACO,GAGJ,CACX"}
|
|
1
|
+
{"version":3,"file":"engine.mjs","names":[],"sources":["../../../src/core/engine.ts"],"sourcesContent":["import { BuiltInConverters, ValueConverter } from '../converters';\nimport { ENV_KEYS, Environment, firstEnvKeyValue, parseEnvironment } from './Environment';\nimport { isMissing } from './missing';\nimport { resolveEffectivePaths } from './paths';\nimport { cache, state } from './state';\nimport { TemplateResolver } from '../engine/TemplateResolver';\nimport { debugVerbose, debugWarn } from '../infra/Debug';\nimport { loadDotenv } from '../infra/Dotenv';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { ConditionalReturn, EnvKeyInput } from '../types';\nimport type { EnvapterService } from '../types/Env';\n\nexport function resolveKeyInput(keyInput: EnvKeyInput): { key: string; value: string | undefined } {\n const keys = Array.isArray(keyInput) ? keyInput : [keyInput];\n const normalizedKeys = keys as readonly string[];\n\n if (normalizedKeys.length === 0) {\n throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, 'At least one environment key must be provided.');\n }\n\n if (normalizedKeys.some((k) => typeof k !== 'string')) {\n throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, 'Environment keys must be strings.');\n }\n\n if (normalizedKeys.some((k) => k.trim() === '')) {\n throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, 'Environment keys cannot be empty strings.');\n }\n\n // an empty value falls through to the next key and only comes back when every key is empty\n let firstPresent: { key: string; value: string } | undefined;\n for (const candidate of normalizedKeys) {\n const value = readCached(candidate);\n if (value === undefined) continue;\n if (!isMissing(value)) return { key: candidate, value };\n firstPresent ??= { key: candidate, value };\n }\n\n return firstPresent ?? { key: normalizedKeys[0] as string, value: undefined };\n}\n\nexport function ensureLoaded(): Map<string, unknown> {\n if (!state.cacheBuilt) {\n const source = state.source;\n // the loader writes into this object\n const isolatedEnv: Record<string, string> = { ...source.readVars() };\n\n let added = new Set<string>();\n if (source.supportsFiles) {\n debugVerbose(`base dir: ${state.baseDir ?? 'working directory'}`);\n // outside the try because a missing profile path has to throw\n const effectivePaths = resolveEffectivePaths();\n debugVerbose(`effective .env paths: ${effectivePaths.length === 0 ? '(none)' : effectivePaths.join(', ')}`);\n try {\n added = loadDotenv({\n ...state.userDefinedEnvFileOptions,\n path: effectivePaths,\n processEnv: isolatedEnv,\n readFile: source.readFile.bind(source)\n });\n } catch (error) {\n debugWarn(`failed to load .env: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n state.dotenvAddedKeys = added;\n for (const [key, value] of Object.entries(isolatedEnv)) cache.set(key, value);\n debugVerbose(`cache populated: ${cache.size} keys total`);\n // set before mirroring because template expansion reads the cache\n state.cacheBuilt = true;\n if (state.syncProcessEnv) mirrorToProcessEnv();\n }\n\n return cache;\n}\n\nfunction readCached(key: string): string | undefined {\n const c = ensureLoaded();\n // decorator memoization also stores non-string values in this shared cache\n if (c.has(key)) {\n const cached = c.get(key);\n return typeof cached === 'string' ? cached : undefined;\n }\n const source = state.source;\n if (typeof source.readVar !== 'function') return undefined;\n const value = source.readVar(key);\n // caches misses too\n c.set(key, value);\n return value;\n}\n\nexport function refreshCache(): void {\n // an inferred environment can change once the new vars load\n if (!state.environmentExplicitlySet) state.environment = undefined;\n cache.clear();\n state.cacheBuilt = false;\n state.dotenvAddedKeys = new Set<string>();\n debugVerbose('cache cleared, reloading config');\n ensureLoaded();\n}\n\nexport function mirrorToProcessEnv(): void {\n if (state.dotenvAddedKeys.size === 0) return;\n const source = state.source;\n /* v8 ignore next -- @preserve dotenv keys only accumulate under a file source, so the delta implies supportsFiles here */\n if (!source.supportsFiles) return;\n const mirrored: Record<string, string> = {};\n for (const key of state.dotenvAddedKeys) {\n const value = cache.get(key);\n /* v8 ignore next -- @preserve the loader only writes strings */\n if (typeof value !== 'string') continue;\n mirrored[key] = resolveForMirror(key, value);\n debugVerbose(`mirrored ${key} to the ambient environment`);\n }\n source.writeVars(mirrored);\n debugVerbose(`mirrored ${state.dotenvAddedKeys.size} keys to the ambient environment`);\n}\n\nfunction resolveForMirror(key: string, value: string): string {\n return templateResolver.resolveTemplate(key, value);\n}\n\nexport function determineEnvironment(env?: string | Environment): void {\n if (typeof env === 'number') {\n state.environment = env;\n state.environmentExplicitlySet = true;\n return;\n }\n if (typeof env === 'string') {\n state.environment = parseEnvironment(env) ?? Environment.Development;\n state.environmentExplicitlySet = true;\n return;\n }\n\n const raw = firstEnvKeyValue((key) => readCached(key));\n if (raw === undefined) {\n debugWarn(`no environment set (looked for ${ENV_KEYS.join(', ')}); defaulting to development`);\n state.environment = Environment.Development;\n return;\n }\n const parsed = parseEnvironment(raw);\n if (parsed === undefined) {\n debugWarn(`unrecognized environment \"${raw}\"; defaulting to development`);\n state.environment = Environment.Development;\n return;\n }\n state.environment = parsed;\n}\n\nexport enum Primitive {\n String,\n Number,\n Boolean,\n BigInt,\n Symbol\n}\n\nconst PRIMITIVE_NAMES: Record<Primitive, string> = {\n [Primitive.String]: 'string',\n [Primitive.Number]: 'number',\n [Primitive.Boolean]: 'boolean',\n [Primitive.BigInt]: 'bigint',\n [Primitive.Symbol]: 'symbol'\n};\n\n// arrows because readPrimitive reads templateResolver, which is assigned below\nconst envService: EnvapterService = {\n getRaw: (key) => resolveKeyInput(key).value,\n get: (key, def) => readPrimitive<string, string | undefined>(key, Primitive.String, def)\n};\n\nexport const templateResolver: TemplateResolver = new TemplateResolver(envService);\nexport const valueConverter: ValueConverter = new ValueConverter(envService);\n\nexport function readPrimitive<EnvVarReturnType, DefaultType extends EnvVarReturnType | undefined = undefined>(\n key: EnvKeyInput,\n type: Primitive,\n def?: DefaultType\n): ConditionalReturn<EnvVarReturnType, DefaultType> {\n const { key: resolvedKey, value } = resolveKeyInput(key);\n if (isMissing(value)) {\n if (def !== undefined) debugWarn(`${resolvedKey} is missing or empty, using fallback ${String(def)}`);\n else debugWarn(`${resolvedKey} is missing or empty`);\n return def as ConditionalReturn<EnvVarReturnType, DefaultType>;\n }\n\n const parsed = templateResolver.resolveTemplate(resolvedKey, String(value));\n\n let converted: EnvVarReturnType | undefined;\n if (type === Primitive.Number) converted = BuiltInConverters.number(parsed) as EnvVarReturnType | undefined;\n else if (type === Primitive.Boolean) converted = BuiltInConverters.boolean(parsed) as EnvVarReturnType | undefined;\n else if (type === Primitive.BigInt) converted = BuiltInConverters.bigint(parsed) as EnvVarReturnType | undefined;\n else if (type === Primitive.Symbol) converted = BuiltInConverters.symbol(parsed) as EnvVarReturnType | undefined;\n else converted = BuiltInConverters.string(parsed) as EnvVarReturnType | undefined;\n\n if (converted === undefined) {\n // leave the value out because env values can be secrets\n debugVerbose(\n `could not convert ${resolvedKey} as ${PRIMITIVE_NAMES[type]}${def !== undefined ? ', using the fallback' : ''}`\n );\n return def as ConditionalReturn<EnvVarReturnType, DefaultType>;\n }\n\n return converted;\n}\n"],"mappings":"qlBAaA,SAAgB,EAAgB,EAAmE,CAE/F,IAAM,EADO,MAAM,QAAQ,CAAQ,EAAI,EAAW,CAAC,CAAQ,EAG3D,GAAI,EAAe,SAAW,EAC1B,MAAM,IAAI,EAAA,IAA8C,gDAAgD,EAG5G,GAAI,EAAe,KAAM,GAAM,OAAO,GAAM,QAAQ,EAChD,MAAM,IAAI,EAAA,IAA8C,mCAAmC,EAG/F,GAAI,EAAe,KAAM,GAAM,EAAE,KAAK,IAAM,EAAE,EAC1C,MAAM,IAAI,EAAA,IAA8C,2CAA2C,EAIvG,IAAI,EACJ,IAAK,IAAM,KAAa,EAAgB,CACpC,IAAM,EAAQ,EAAW,CAAS,EAC9B,OAAU,IAAA,GACd,IAAI,CAAC,EAAU,CAAK,EAAG,MAAO,CAAE,IAAK,EAAW,OAAM,EACtD,IAAiB,CAAE,IAAK,EAAW,OAAM,CADa,CAE1D,CAEA,OAAO,GAAgB,CAAE,IAAK,EAAe,GAAc,MAAO,IAAA,EAAU,CAChF,CAEA,SAAgB,GAAqC,CACjD,GAAI,CAAC,EAAM,WAAY,CACnB,IAAM,EAAS,EAAM,OAEf,EAAsC,CAAE,GAAG,EAAO,SAAS,CAAE,EAE/D,EAAQ,IAAI,IAChB,GAAI,EAAO,cAAe,CACtB,EAAa,aAAa,EAAM,SAAW,qBAAqB,EAEhE,IAAM,EAAiB,EAAsB,EAC7C,EAAa,yBAAyB,EAAe,SAAW,EAAI,SAAW,EAAe,KAAK,IAAI,GAAG,EAC1G,GAAI,CACA,EAAQ,EAAW,CACf,GAAG,EAAM,0BACT,KAAM,EACN,WAAY,EACZ,SAAU,EAAO,SAAS,KAAK,CAAM,CACzC,CAAC,CACL,OAAS,EAAO,CACZ,EAAU,wBAAwB,aAAiB,MAAQ,EAAM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IAAc,IAAA,IAEd,EACI,qBAAqB,EAAY,MAAM,EAAgB,KAAQ,IAAQ,IAAA,GAAqC,GAAzB,wBACvF,EACO,GAGJ,CACX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"missing.cjs","names":["state"],"sources":["../../../src/core/missing.ts"],"sourcesContent":["import { state } from './state';\n\n//
|
|
1
|
+
{"version":3,"file":"missing.cjs","names":["state"],"sources":["../../../src/core/missing.ts"],"sourcesContent":["import { state } from './state';\n\n// every missing-value check goes through this\nexport function isMissing(value: string | undefined): boolean {\n if (value === undefined || value === '') return true;\n if (state.strict && value.trim() === '') return true;\n return false;\n}\n\nexport function hasFallback(fallback: unknown): boolean {\n return fallback !== undefined;\n}\n"],"mappings":"+BAGA,SAAgB,EAAU,EAAoC,CAG1D,MADA,GADI,IAAU,IAAA,IAAa,IAAU,IACjCA,EAAAA,MAAM,QAAU,EAAM,KAAK,IAAM,GAEzC,CAEA,SAAgB,EAAY,EAA4B,CACpD,OAAO,IAAa,IAAA,EACxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"missing.mjs","names":[],"sources":["../../../src/core/missing.ts"],"sourcesContent":["import { state } from './state';\n\n//
|
|
1
|
+
{"version":3,"file":"missing.mjs","names":[],"sources":["../../../src/core/missing.ts"],"sourcesContent":["import { state } from './state';\n\n// every missing-value check goes through this\nexport function isMissing(value: string | undefined): boolean {\n if (value === undefined || value === '') return true;\n if (state.strict && value.trim() === '') return true;\n return false;\n}\n\nexport function hasFallback(fallback: unknown): boolean {\n return fallback !== undefined;\n}\n"],"mappings":"oCAGA,SAAgB,EAAU,EAAoC,CAG1D,MADA,GADI,IAAU,IAAA,IAAa,IAAU,IACjC,EAAM,QAAU,EAAM,KAAK,IAAM,GAEzC,CAEA,SAAgB,EAAY,EAA4B,CACpD,OAAO,IAAa,IAAA,EACxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.cjs","names":["state","EnvaptError","Environment","firstEnvKeyValue","parseEnvironment"],"sources":["../../../src/core/paths.ts"],"sourcesContent":["import { Environment, firstEnvKeyValue, parseEnvironment } from './Environment';\nimport { state } from './state';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { EnvProfile, FileCapableSource, Source } from '../types';\n\n//
|
|
1
|
+
{"version":3,"file":"paths.cjs","names":["state","EnvaptError","Environment","firstEnvKeyValue","parseEnvironment"],"sources":["../../../src/core/paths.ts"],"sourcesContent":["import { Environment, firstEnvKeyValue, parseEnvironment } from './Environment';\nimport { state } from './state';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { EnvProfile, FileCapableSource, Source } from '../types';\n\n// without a baseDir the source resolves the path against its own default, process.cwd() on Node\nexport function resolveAgainstBase(candidate: string): string {\n const baseDir = state.baseDir;\n if (baseDir === undefined) return candidate;\n const source = state.source;\n /* v8 ignore next -- @preserve callers are all file-gated, so the source is never bare here */\n if (!source.supportsFiles) return candidate;\n return source.resolvePath(baseDir, candidate);\n}\n\nexport function assertFileApiSupported(api: string, source: Source): asserts source is FileCapableSource {\n if (!source.supportsFiles) {\n throw new EnvaptError(\n EnvaptErrorCodes.FileApiUnsupported,\n `${api} requires a filesystem-backed source; the bound source does not support .env files.`\n );\n }\n}\n\nexport function sourceFileExists(path: string): boolean {\n const source = state.source;\n /* v8 ignore next -- @preserve every caller is file-gated, so this never sees a bare source */\n if (!source.supportsFiles) return false;\n return source.readFile(path, 'utf8') !== undefined;\n}\n\n// most specific first, since the loader keeps the first value per key unless override is on\nfunction buildCascadePaths(env: Environment): string[] {\n const envName = Environment[env].toLowerCase();\n return [`.env.${envName}.local`, `.env.${envName}`, '.env.local', '.env']\n .map((name) => resolveAgainstBase(name))\n .filter((p) => sourceFileExists(p));\n}\n\nfunction normalizeProfilePaths(profile: EnvProfile | undefined): string[] {\n if (!profile) return [];\n return Array.isArray(profile.paths) ? profile.paths : [profile.paths];\n}\n\n// reads the source directly because readCached would re-enter the cache build\nfunction getCascadeEnvironment(): Environment {\n if (state.environment !== undefined) return state.environment;\n\n const source = state.source;\n const vars = source.readVars();\n const raw = firstEnvKeyValue((key) => vars[key] ?? source.readVar?.(key));\n return raw === undefined ? Environment.Development : (parseEnvironment(raw) ?? Environment.Development);\n}\n\nexport function resolveEffectivePaths(): string[] {\n if (state.envPathsExplicitlySet) return state.envPaths.map((p) => resolveAgainstBase(p));\n\n const env = getCascadeEnvironment();\n const profileEntry = state.profiles?.[env];\n const profilePaths = normalizeProfilePaths(profileEntry);\n\n if (profilePaths.length > 0) {\n const missing = profilePaths.filter((p) => !sourceFileExists(resolveAgainstBase(p)));\n if (missing.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.EnvFilesNotFound,\n `Environment file not found at path: ${missing.join(', ')}`\n );\n }\n }\n\n const cascade = state.profiles?.useDefaults === false ? [] : buildCascadePaths(env);\n return [...profilePaths.map((p) => resolveAgainstBase(p)), ...cascade];\n}\n"],"mappings":"8FAOA,SAAgB,EAAmB,EAA2B,CAC1D,IAAM,EAAUA,EAAAA,MAAM,QACtB,GAAI,IAAY,IAAA,GAAW,OAAO,EAClC,IAAM,EAASA,EAAAA,MAAM,OAGrB,OADK,EAAO,cACL,EAAO,YAAY,EAAS,CAAS,EADV,CAEtC,CAEA,SAAgB,EAAuB,EAAa,EAAqD,CACrG,GAAI,CAAC,EAAO,cACR,MAAM,IAAIC,EAAAA,YAAAA,IAEN,GAAG,EAAI,oFACX,CAER,CAEA,SAAgB,EAAiB,EAAuB,CACpD,IAAM,EAASD,EAAAA,MAAM,OAGrB,OADK,EAAO,cACL,EAAO,SAAS,EAAM,MAAM,IAAM,IAAA,GADP,EAEtC,CAGA,SAAS,EAAkB,EAA4B,CACnD,IAAM,EAAUE,EAAAA,YAAY,EAAI,CAAC,YAAY,EAC7C,MAAO,CAAC,QAAQ,EAAQ,QAAS,QAAQ,IAAW,aAAc,MAAM,CAAC,CACpE,IAAK,GAAS,EAAmB,CAAI,CAAC,CAAC,CACvC,OAAQ,GAAM,EAAiB,CAAC,CAAC,CAC1C,CAEA,SAAS,EAAsB,EAA2C,CAEtE,OADK,EACE,MAAM,QAAQ,EAAQ,KAAK,EAAI,EAAQ,MAAQ,CAAC,EAAQ,KAAK,EAD/C,CAAC,CAE1B,CAGA,SAAS,GAAqC,CAC1C,GAAIF,EAAAA,MAAM,cAAgB,IAAA,GAAW,OAAOA,EAAAA,MAAM,YAElD,IAAM,EAASA,EAAAA,MAAM,OACf,EAAO,EAAO,SAAS,EACvB,EAAMG,EAAAA,iBAAkB,GAAQ,EAAK,IAAQ,EAAO,UAAU,CAAG,CAAC,EACxE,OAAO,IAAQ,IAAA,GAAA,EAAuCC,EAAAA,iBAAiB,CAAG,GAAA,CAC9E,CAEA,SAAgB,GAAkC,CAC9C,GAAIJ,EAAAA,MAAM,sBAAuB,OAAOA,EAAAA,MAAM,SAAS,IAAK,GAAM,EAAmB,CAAC,CAAC,EAEvF,IAAM,EAAM,EAAsB,EAC5B,EAAeA,EAAAA,MAAM,WAAW,GAChC,EAAe,EAAsB,CAAY,EAEvD,GAAI,EAAa,OAAS,EAAG,CACzB,IAAM,EAAU,EAAa,OAAQ,GAAM,CAAC,EAAiB,EAAmB,CAAC,CAAC,CAAC,EACnF,GAAI,EAAQ,OAAS,EACjB,MAAM,IAAIC,EAAAA,YAAAA,IAEN,uCAAuC,EAAQ,KAAK,IAAI,GAC5D,CAER,CAEA,IAAM,EAAUD,EAAAA,MAAM,UAAU,cAAgB,GAAQ,CAAC,EAAI,EAAkB,CAAG,EAClF,MAAO,CAAC,GAAG,EAAa,IAAK,GAAM,EAAmB,CAAC,CAAC,EAAG,GAAG,CAAO,CACzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.mjs","names":[],"sources":["../../../src/core/paths.ts"],"sourcesContent":["import { Environment, firstEnvKeyValue, parseEnvironment } from './Environment';\nimport { state } from './state';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { EnvProfile, FileCapableSource, Source } from '../types';\n\n//
|
|
1
|
+
{"version":3,"file":"paths.mjs","names":[],"sources":["../../../src/core/paths.ts"],"sourcesContent":["import { Environment, firstEnvKeyValue, parseEnvironment } from './Environment';\nimport { state } from './state';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { EnvProfile, FileCapableSource, Source } from '../types';\n\n// without a baseDir the source resolves the path against its own default, process.cwd() on Node\nexport function resolveAgainstBase(candidate: string): string {\n const baseDir = state.baseDir;\n if (baseDir === undefined) return candidate;\n const source = state.source;\n /* v8 ignore next -- @preserve callers are all file-gated, so the source is never bare here */\n if (!source.supportsFiles) return candidate;\n return source.resolvePath(baseDir, candidate);\n}\n\nexport function assertFileApiSupported(api: string, source: Source): asserts source is FileCapableSource {\n if (!source.supportsFiles) {\n throw new EnvaptError(\n EnvaptErrorCodes.FileApiUnsupported,\n `${api} requires a filesystem-backed source; the bound source does not support .env files.`\n );\n }\n}\n\nexport function sourceFileExists(path: string): boolean {\n const source = state.source;\n /* v8 ignore next -- @preserve every caller is file-gated, so this never sees a bare source */\n if (!source.supportsFiles) return false;\n return source.readFile(path, 'utf8') !== undefined;\n}\n\n// most specific first, since the loader keeps the first value per key unless override is on\nfunction buildCascadePaths(env: Environment): string[] {\n const envName = Environment[env].toLowerCase();\n return [`.env.${envName}.local`, `.env.${envName}`, '.env.local', '.env']\n .map((name) => resolveAgainstBase(name))\n .filter((p) => sourceFileExists(p));\n}\n\nfunction normalizeProfilePaths(profile: EnvProfile | undefined): string[] {\n if (!profile) return [];\n return Array.isArray(profile.paths) ? profile.paths : [profile.paths];\n}\n\n// reads the source directly because readCached would re-enter the cache build\nfunction getCascadeEnvironment(): Environment {\n if (state.environment !== undefined) return state.environment;\n\n const source = state.source;\n const vars = source.readVars();\n const raw = firstEnvKeyValue((key) => vars[key] ?? source.readVar?.(key));\n return raw === undefined ? Environment.Development : (parseEnvironment(raw) ?? Environment.Development);\n}\n\nexport function resolveEffectivePaths(): string[] {\n if (state.envPathsExplicitlySet) return state.envPaths.map((p) => resolveAgainstBase(p));\n\n const env = getCascadeEnvironment();\n const profileEntry = state.profiles?.[env];\n const profilePaths = normalizeProfilePaths(profileEntry);\n\n if (profilePaths.length > 0) {\n const missing = profilePaths.filter((p) => !sourceFileExists(resolveAgainstBase(p)));\n if (missing.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.EnvFilesNotFound,\n `Environment file not found at path: ${missing.join(', ')}`\n );\n }\n }\n\n const cascade = state.profiles?.useDefaults === false ? [] : buildCascadePaths(env);\n return [...profilePaths.map((p) => resolveAgainstBase(p)), ...cascade];\n}\n"],"mappings":"iLAOA,SAAgB,EAAmB,EAA2B,CAC1D,IAAM,EAAU,EAAM,QACtB,GAAI,IAAY,IAAA,GAAW,OAAO,EAClC,IAAM,EAAS,EAAM,OAGrB,OADK,EAAO,cACL,EAAO,YAAY,EAAS,CAAS,EADV,CAEtC,CAEA,SAAgB,EAAuB,EAAa,EAAqD,CACrG,GAAI,CAAC,EAAO,cACR,MAAM,IAAI,EAAA,IAEN,GAAG,EAAI,oFACX,CAER,CAEA,SAAgB,EAAiB,EAAuB,CACpD,IAAM,EAAS,EAAM,OAGrB,OADK,EAAO,cACL,EAAO,SAAS,EAAM,MAAM,IAAM,IAAA,GADP,EAEtC,CAGA,SAAS,EAAkB,EAA4B,CACnD,IAAM,EAAU,EAAY,EAAI,CAAC,YAAY,EAC7C,MAAO,CAAC,QAAQ,EAAQ,QAAS,QAAQ,IAAW,aAAc,MAAM,CAAC,CACpE,IAAK,GAAS,EAAmB,CAAI,CAAC,CAAC,CACvC,OAAQ,GAAM,EAAiB,CAAC,CAAC,CAC1C,CAEA,SAAS,EAAsB,EAA2C,CAEtE,OADK,EACE,MAAM,QAAQ,EAAQ,KAAK,EAAI,EAAQ,MAAQ,CAAC,EAAQ,KAAK,EAD/C,CAAC,CAE1B,CAGA,SAAS,GAAqC,CAC1C,GAAI,EAAM,cAAgB,IAAA,GAAW,OAAO,EAAM,YAElD,IAAM,EAAS,EAAM,OACf,EAAO,EAAO,SAAS,EACvB,EAAM,EAAkB,GAAQ,EAAK,IAAQ,EAAO,UAAU,CAAG,CAAC,EACxE,OAAO,IAAQ,IAAA,GAAA,EAAuC,EAAiB,CAAG,GAAA,CAC9E,CAEA,SAAgB,GAAkC,CAC9C,GAAI,EAAM,sBAAuB,OAAO,EAAM,SAAS,IAAK,GAAM,EAAmB,CAAC,CAAC,EAEvF,IAAM,EAAM,EAAsB,EAC5B,EAAe,EAAM,WAAW,GAChC,EAAe,EAAsB,CAAY,EAEvD,GAAI,EAAa,OAAS,EAAG,CACzB,IAAM,EAAU,EAAa,OAAQ,GAAM,CAAC,EAAiB,EAAmB,CAAC,CAAC,CAAC,EACnF,GAAI,EAAQ,OAAS,EACjB,MAAM,IAAI,EAAA,IAEN,uCAAuC,EAAQ,KAAK,IAAI,GAC5D,CAER,CAEA,IAAM,EAAU,EAAM,UAAU,cAAgB,GAAQ,CAAC,EAAI,EAAkB,CAAG,EAClF,MAAO,CAAC,GAAG,EAAa,IAAK,GAAM,EAAmB,CAAC,CAAC,EAAG,GAAG,CAAO,CACzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.cjs","names":["UnboundSource"],"sources":["../../../src/core/state.ts"],"sourcesContent":["import { UnboundSource } from '../sources/UnboundSource';\n\nimport type { Environment } from './Environment';\nimport type { EnvFileOptions } from '../infra/Dotenv';\nimport type { FileApiMode, ProfilesConfig, Source } from '../types';\n\n//
|
|
1
|
+
{"version":3,"file":"state.cjs","names":["UnboundSource"],"sources":["../../../src/core/state.ts"],"sourcesContent":["import { UnboundSource } from '../sources/UnboundSource';\n\nimport type { Environment } from './Environment';\nimport type { EnvFileOptions } from '../infra/Dotenv';\nimport type { FileApiMode, ProfilesConfig, Source } from '../types';\n\n// keep this out of the package exports map\nexport const state = {\n envPaths: ['.env'] as string[],\n envPathsExplicitlySet: false,\n baseDir: undefined as string | undefined,\n userDefinedEnvFileOptions: {} as EnvFileOptions,\n strict: false,\n syncProcessEnv: false,\n fileApiMode: 'warn' as FileApiMode,\n // loader-written keys only (collisions skipped), refilled on every cache rebuild.\n dotenvAddedKeys: new Set<string>(),\n // cache.size is 0 both before the build and after a build that found no keys\n cacheBuilt: false,\n // unbound by default so non-Node builds throw NoSourceBound on read until useSource() runs.\n source: new UnboundSource() as Source,\n environment: undefined as Environment | undefined,\n environmentExplicitlySet: false,\n profiles: undefined as ProfilesConfig | undefined\n};\n\nexport const cache = new Map<string, unknown>();\n"],"mappings":"gDAOa,EAAQ,CACjB,SAAU,CAAC,MAAM,EACjB,sBAAuB,GACvB,QAAS,IAAA,GACT,0BAA2B,CAAC,EAC5B,OAAQ,GACR,eAAgB,GAChB,YAAa,OAEb,gBAAiB,IAAI,IAErB,WAAY,GAEZ,OAAQ,IAAIA,EAAAA,cACZ,YAAa,IAAA,GACb,yBAA0B,GAC1B,SAAU,IAAA,EACd,EAEa,EAAQ,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.mjs","names":[],"sources":["../../../src/core/state.ts"],"sourcesContent":["import { UnboundSource } from '../sources/UnboundSource';\n\nimport type { Environment } from './Environment';\nimport type { EnvFileOptions } from '../infra/Dotenv';\nimport type { FileApiMode, ProfilesConfig, Source } from '../types';\n\n//
|
|
1
|
+
{"version":3,"file":"state.mjs","names":[],"sources":["../../../src/core/state.ts"],"sourcesContent":["import { UnboundSource } from '../sources/UnboundSource';\n\nimport type { Environment } from './Environment';\nimport type { EnvFileOptions } from '../infra/Dotenv';\nimport type { FileApiMode, ProfilesConfig, Source } from '../types';\n\n// keep this out of the package exports map\nexport const state = {\n envPaths: ['.env'] as string[],\n envPathsExplicitlySet: false,\n baseDir: undefined as string | undefined,\n userDefinedEnvFileOptions: {} as EnvFileOptions,\n strict: false,\n syncProcessEnv: false,\n fileApiMode: 'warn' as FileApiMode,\n // loader-written keys only (collisions skipped), refilled on every cache rebuild.\n dotenvAddedKeys: new Set<string>(),\n // cache.size is 0 both before the build and after a build that found no keys\n cacheBuilt: false,\n // unbound by default so non-Node builds throw NoSourceBound on read until useSource() runs.\n source: new UnboundSource() as Source,\n environment: undefined as Environment | undefined,\n environmentExplicitlySet: false,\n profiles: undefined as ProfilesConfig | undefined\n};\n\nexport const cache = new Map<string, unknown>();\n"],"mappings":"6DAOA,MAAa,EAAQ,CACjB,SAAU,CAAC,MAAM,EACjB,sBAAuB,GACvB,QAAS,IAAA,GACT,0BAA2B,CAAC,EAC5B,OAAQ,GACR,eAAgB,GAChB,YAAa,OAEb,gBAAiB,IAAI,IAErB,WAAY,GAEZ,OAAQ,IAAI,EACZ,YAAa,IAAA,GACb,yBAA0B,GAC1B,SAAU,IAAA,EACd,EAEa,EAAQ,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Envapt.cjs","names":["createPropertyDecorator","parseEnvaptOptions"],"sources":["../../../../src/decorators/legacy/Envapt.ts"],"sourcesContent":["import { createPropertyDecorator } from './createPropertyDecorator';\nimport { parseEnvaptOptions } from '../parseEnvaptOptions';\n\nimport type { ArrayOf } from '../../converters';\nimport type { InferSchemaOutput, StandardSchemaV1 } from '../../infra/StandardSchema';\nimport type {\n BuiltInConverter,\n ConverterFunction,\n EnvaptFieldDecorator,\n EnvKeyInput,\n InferConverterFallbackType,\n InferConverterReturnType,\n InferPrimitiveReturnType,\n PrimitiveConstructor,\n SchemaConstraint\n} from '../../types';\n\n/**\n * A custom converter function with a fallback (both required), or a fallback only.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * \\@Envapt('API_KEY', {\n * fallback: 'default-key',\n * converter(raw, _fallback) {\n * if (!raw || raw.trim() === '') throw new Error('API_KEY required');\n * return raw.trim();\n * }\n * })\n * static readonly apiKey: string;\n *\n * \\@Envapt('LOG_FILE', { fallback: '/var/log/app.log' })\n * static readonly logFile: string;\n *\n * \\@Envapt('RETRY_POLICY', { fallback: { retries: 3, backoff: 'exponential' } })\n * static readonly retryPolicy: unknown;\n * }\n * ```\n */\nexport function Envapt(\n key: EnvKeyInput,\n options?: { fallback: undefined; converter?: undefined }\n): EnvaptFieldDecorator<string | undefined>;\nexport function Envapt<TFallback>(\n key: EnvKeyInput,\n options:\n | { converter: (raw: string | undefined, fallback: TFallback) => TFallback; fallback: TFallback }\n | { fallback: TFallback; converter?: undefined }\n): EnvaptFieldDecorator<TFallback>;\n\n/**\n * A custom converter function without a fallback. Omit `required` to return the converter's\n * output (possibly `undefined`), or pass `required: true` to throw `MissingEnvValue` on\n * missing or empty values.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * \\@Envapt('FEATURE_FLAGS', { converter(raw) {\n * return raw ? raw.split('|').map(s => s.trim()) : [];\n * } })\n * static readonly featureFlags: string[];\n *\n * \\@Envapt('JWT_SECRET', {\n * converter: (raw) => Buffer.from(raw ?? '', 'base64'),\n * required: true\n * })\n * static readonly jwtSecret: Buffer;\n * }\n * ```\n */\nexport function Envapt<TReturnType>(\n key: EnvKeyInput,\n options:\n | { converter: ConverterFunction<TReturnType>; required?: false }\n | { converter: ConverterFunction<TReturnType>; required: true }\n): EnvaptFieldDecorator<TReturnType>;\n\n/**\n * A built-in or array converter with a fallback, or `required: true`. The fallback type tracks\n * the converter, so `Converters.Time` takes a number or time-string and `Converters.Url` takes\n * a `URL` instance.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * import { Converters } from 'envapt';\n *\n * class Config extends Envapter {\n * \\@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })\n * static readonly port: number;\n *\n * // the Url fallback is a URL instance
|
|
1
|
+
{"version":3,"file":"Envapt.cjs","names":["createPropertyDecorator","parseEnvaptOptions"],"sources":["../../../../src/decorators/legacy/Envapt.ts"],"sourcesContent":["import { createPropertyDecorator } from './createPropertyDecorator';\nimport { parseEnvaptOptions } from '../parseEnvaptOptions';\n\nimport type { ArrayOf } from '../../converters';\nimport type { InferSchemaOutput, StandardSchemaV1 } from '../../infra/StandardSchema';\nimport type {\n BuiltInConverter,\n ConverterFunction,\n EnvaptFieldDecorator,\n EnvKeyInput,\n InferConverterFallbackType,\n InferConverterReturnType,\n InferPrimitiveReturnType,\n PrimitiveConstructor,\n SchemaConstraint\n} from '../../types';\n\n/**\n * A custom converter function with a fallback (both required), or a fallback only.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * \\@Envapt('API_KEY', {\n * fallback: 'default-key',\n * converter(raw, _fallback) {\n * if (!raw || raw.trim() === '') throw new Error('API_KEY required');\n * return raw.trim();\n * }\n * })\n * static readonly apiKey: string;\n *\n * \\@Envapt('LOG_FILE', { fallback: '/var/log/app.log' })\n * static readonly logFile: string;\n *\n * \\@Envapt('RETRY_POLICY', { fallback: { retries: 3, backoff: 'exponential' } })\n * static readonly retryPolicy: unknown;\n * }\n * ```\n */\nexport function Envapt(\n key: EnvKeyInput,\n options?: { fallback: undefined; converter?: undefined }\n): EnvaptFieldDecorator<string | undefined>;\nexport function Envapt<TFallback>(\n key: EnvKeyInput,\n options:\n | { converter: (raw: string | undefined, fallback: TFallback) => TFallback; fallback: TFallback }\n | { fallback: TFallback; converter?: undefined }\n): EnvaptFieldDecorator<TFallback>;\n\n/**\n * A custom converter function without a fallback. Omit `required` to return the converter's\n * output (possibly `undefined`), or pass `required: true` to throw `MissingEnvValue` on\n * missing or empty values.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * \\@Envapt('FEATURE_FLAGS', { converter(raw) {\n * return raw ? raw.split('|').map(s => s.trim()) : [];\n * } })\n * static readonly featureFlags: string[];\n *\n * \\@Envapt('JWT_SECRET', {\n * converter: (raw) => Buffer.from(raw ?? '', 'base64'),\n * required: true\n * })\n * static readonly jwtSecret: Buffer;\n * }\n * ```\n */\nexport function Envapt<TReturnType>(\n key: EnvKeyInput,\n options:\n | { converter: ConverterFunction<TReturnType>; required?: false }\n | { converter: ConverterFunction<TReturnType>; required: true }\n): EnvaptFieldDecorator<TReturnType>;\n\n/**\n * A built-in or array converter with a fallback, or `required: true`. The fallback type tracks\n * the converter, so `Converters.Time` takes a number or time-string and `Converters.Url` takes\n * a `URL` instance.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * import { Converters } from 'envapt';\n *\n * class Config extends Envapter {\n * \\@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })\n * static readonly port: number;\n *\n * // the Url fallback is a URL instance\n * \\@Envapt('APP_URL', { converter: Converters.Url, fallback: new URL('http://localhost:3000') })\n * static readonly url: URL;\n *\n * // reads CANARY_URL when present, otherwise APP_URL\n * \\@Envapt(['CANARY_URL', 'APP_URL'], { converter: Converters.Url })\n * static readonly canaryUrl: URL | undefined;\n *\n * // Time takes a number (milliseconds) or a time-string fallback (`<number><unit>`)\n * \\@Envapt('REQUEST_TIMEOUT', { converter: Converters.Time, fallback: '10s' })\n * static readonly requestTimeout: number;\n *\n * \\@Envapt('ALLOWED_ORIGINS', {\n * converter: Converters.array({ of: Converters.String }),\n * fallback: ['https://example.com']\n * })\n * static readonly allowedOrigins: string[];\n *\n * \\@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })\n * static readonly databaseUrl: URL;\n * }\n * ```\n */\nexport function Envapt<TConverter extends BuiltInConverter | ArrayOf>(\n key: EnvKeyInput,\n options:\n | { converter: TConverter; fallback: InferConverterFallbackType<TConverter>; required?: false }\n | { converter: TConverter; required: true }\n): EnvaptFieldDecorator<InferConverterReturnType<TConverter>>;\nexport function Envapt<TConverter extends BuiltInConverter | ArrayOf>(\n key: EnvKeyInput,\n options: { converter: TConverter; fallback?: undefined; required?: false }\n): EnvaptFieldDecorator<InferConverterReturnType<TConverter> | undefined>;\n\n/**\n * A primitive constructor (`Number`, `Boolean`) with an optional fallback.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * \\@Envapt('MAX_CONNECTIONS', { converter: Number, fallback: 100 })\n * static readonly maxConnections: number;\n *\n * \\@Envapt('FEATURE_ENABLED', { converter: Boolean, fallback: false })\n * static readonly featureEnabled: boolean;\n * }\n * ```\n */\nexport function Envapt<TConstructor extends PrimitiveConstructor>(\n key: EnvKeyInput,\n options:\n | { converter: TConstructor; fallback: InferPrimitiveReturnType<TConstructor>; required?: false }\n | { converter: TConstructor; required: true }\n): EnvaptFieldDecorator<InferPrimitiveReturnType<TConstructor>>;\nexport function Envapt<TConstructor extends PrimitiveConstructor>(\n key: EnvKeyInput,\n options: { converter: TConstructor; fallback?: undefined; required?: false }\n): EnvaptFieldDecorator<InferPrimitiveReturnType<TConstructor> | undefined>;\n\n/**\n * Required, no converter (raw string). Throws `MissingEnvValue` on first access when the env\n * value is missing or empty. Pairing `required: true` with `fallback` matches no overload at\n * compile time, and a call that bypasses the types throws `InvalidUserDefinedConfig` at runtime.\n *\n * @param key - Environment variable name(s) to load\n * @param options - `{ required: true }`\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * \\@Envapt('API_KEY', { required: true })\n * static readonly apiKey: string;\n * }\n * ```\n */\nexport function Envapt(key: EnvKeyInput, options: { required: true }): EnvaptFieldDecorator<string>;\n\n/**\n * A Standard Schema v1 adapter (zod, valibot, arktype, hand-rolled). Synchronous schemas only.\n * A `validate` that returns a Promise throws `InvalidUserDefinedConfig` at runtime. Pairing\n * `schema` with `converter` matches no overload at compile time, and a call that bypasses the\n * types throws `InvalidUserDefinedConfig` at runtime.\n * @public\n */\nexport function Envapt<Schema extends StandardSchemaV1>(\n key: EnvKeyInput,\n options:\n | { schema: SchemaConstraint<Schema>; fallback?: InferSchemaOutput<Schema>; required?: false }\n | { schema: SchemaConstraint<Schema>; required: true }\n): EnvaptFieldDecorator<InferSchemaOutput<Schema>>;\n\n/**\n * Instance or static property decorator that loads and converts an environment variable.\n * @see {@link https://envapt.materwelon.dev/docs/decorators#declaring-decorated-fields}\n */\nexport function Envapt<TFallback = unknown>(key: EnvKeyInput, options?: unknown): EnvaptFieldDecorator<unknown> {\n return createPropertyDecorator(key, parseEnvaptOptions<TFallback>(options)) as EnvaptFieldDecorator<unknown>;\n}\n"],"mappings":"wFAuMA,SAAgB,EAA4B,EAAkB,EAAkD,CAC5G,OAAOA,EAAAA,wBAAwB,EAAKC,EAAAA,mBAA8B,CAAO,CAAC,CAC9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Envapt.mjs","names":[],"sources":["../../../../src/decorators/legacy/Envapt.ts"],"sourcesContent":["import { createPropertyDecorator } from './createPropertyDecorator';\nimport { parseEnvaptOptions } from '../parseEnvaptOptions';\n\nimport type { ArrayOf } from '../../converters';\nimport type { InferSchemaOutput, StandardSchemaV1 } from '../../infra/StandardSchema';\nimport type {\n BuiltInConverter,\n ConverterFunction,\n EnvaptFieldDecorator,\n EnvKeyInput,\n InferConverterFallbackType,\n InferConverterReturnType,\n InferPrimitiveReturnType,\n PrimitiveConstructor,\n SchemaConstraint\n} from '../../types';\n\n/**\n * A custom converter function with a fallback (both required), or a fallback only.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * \\@Envapt('API_KEY', {\n * fallback: 'default-key',\n * converter(raw, _fallback) {\n * if (!raw || raw.trim() === '') throw new Error('API_KEY required');\n * return raw.trim();\n * }\n * })\n * static readonly apiKey: string;\n *\n * \\@Envapt('LOG_FILE', { fallback: '/var/log/app.log' })\n * static readonly logFile: string;\n *\n * \\@Envapt('RETRY_POLICY', { fallback: { retries: 3, backoff: 'exponential' } })\n * static readonly retryPolicy: unknown;\n * }\n * ```\n */\nexport function Envapt(\n key: EnvKeyInput,\n options?: { fallback: undefined; converter?: undefined }\n): EnvaptFieldDecorator<string | undefined>;\nexport function Envapt<TFallback>(\n key: EnvKeyInput,\n options:\n | { converter: (raw: string | undefined, fallback: TFallback) => TFallback; fallback: TFallback }\n | { fallback: TFallback; converter?: undefined }\n): EnvaptFieldDecorator<TFallback>;\n\n/**\n * A custom converter function without a fallback. Omit `required` to return the converter's\n * output (possibly `undefined`), or pass `required: true` to throw `MissingEnvValue` on\n * missing or empty values.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * \\@Envapt('FEATURE_FLAGS', { converter(raw) {\n * return raw ? raw.split('|').map(s => s.trim()) : [];\n * } })\n * static readonly featureFlags: string[];\n *\n * \\@Envapt('JWT_SECRET', {\n * converter: (raw) => Buffer.from(raw ?? '', 'base64'),\n * required: true\n * })\n * static readonly jwtSecret: Buffer;\n * }\n * ```\n */\nexport function Envapt<TReturnType>(\n key: EnvKeyInput,\n options:\n | { converter: ConverterFunction<TReturnType>; required?: false }\n | { converter: ConverterFunction<TReturnType>; required: true }\n): EnvaptFieldDecorator<TReturnType>;\n\n/**\n * A built-in or array converter with a fallback, or `required: true`. The fallback type tracks\n * the converter, so `Converters.Time` takes a number or time-string and `Converters.Url` takes\n * a `URL` instance.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * import { Converters } from 'envapt';\n *\n * class Config extends Envapter {\n * \\@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })\n * static readonly port: number;\n *\n * // the Url fallback is a URL instance
|
|
1
|
+
{"version":3,"file":"Envapt.mjs","names":[],"sources":["../../../../src/decorators/legacy/Envapt.ts"],"sourcesContent":["import { createPropertyDecorator } from './createPropertyDecorator';\nimport { parseEnvaptOptions } from '../parseEnvaptOptions';\n\nimport type { ArrayOf } from '../../converters';\nimport type { InferSchemaOutput, StandardSchemaV1 } from '../../infra/StandardSchema';\nimport type {\n BuiltInConverter,\n ConverterFunction,\n EnvaptFieldDecorator,\n EnvKeyInput,\n InferConverterFallbackType,\n InferConverterReturnType,\n InferPrimitiveReturnType,\n PrimitiveConstructor,\n SchemaConstraint\n} from '../../types';\n\n/**\n * A custom converter function with a fallback (both required), or a fallback only.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * \\@Envapt('API_KEY', {\n * fallback: 'default-key',\n * converter(raw, _fallback) {\n * if (!raw || raw.trim() === '') throw new Error('API_KEY required');\n * return raw.trim();\n * }\n * })\n * static readonly apiKey: string;\n *\n * \\@Envapt('LOG_FILE', { fallback: '/var/log/app.log' })\n * static readonly logFile: string;\n *\n * \\@Envapt('RETRY_POLICY', { fallback: { retries: 3, backoff: 'exponential' } })\n * static readonly retryPolicy: unknown;\n * }\n * ```\n */\nexport function Envapt(\n key: EnvKeyInput,\n options?: { fallback: undefined; converter?: undefined }\n): EnvaptFieldDecorator<string | undefined>;\nexport function Envapt<TFallback>(\n key: EnvKeyInput,\n options:\n | { converter: (raw: string | undefined, fallback: TFallback) => TFallback; fallback: TFallback }\n | { fallback: TFallback; converter?: undefined }\n): EnvaptFieldDecorator<TFallback>;\n\n/**\n * A custom converter function without a fallback. Omit `required` to return the converter's\n * output (possibly `undefined`), or pass `required: true` to throw `MissingEnvValue` on\n * missing or empty values.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * \\@Envapt('FEATURE_FLAGS', { converter(raw) {\n * return raw ? raw.split('|').map(s => s.trim()) : [];\n * } })\n * static readonly featureFlags: string[];\n *\n * \\@Envapt('JWT_SECRET', {\n * converter: (raw) => Buffer.from(raw ?? '', 'base64'),\n * required: true\n * })\n * static readonly jwtSecret: Buffer;\n * }\n * ```\n */\nexport function Envapt<TReturnType>(\n key: EnvKeyInput,\n options:\n | { converter: ConverterFunction<TReturnType>; required?: false }\n | { converter: ConverterFunction<TReturnType>; required: true }\n): EnvaptFieldDecorator<TReturnType>;\n\n/**\n * A built-in or array converter with a fallback, or `required: true`. The fallback type tracks\n * the converter, so `Converters.Time` takes a number or time-string and `Converters.Url` takes\n * a `URL` instance.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * import { Converters } from 'envapt';\n *\n * class Config extends Envapter {\n * \\@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })\n * static readonly port: number;\n *\n * // the Url fallback is a URL instance\n * \\@Envapt('APP_URL', { converter: Converters.Url, fallback: new URL('http://localhost:3000') })\n * static readonly url: URL;\n *\n * // reads CANARY_URL when present, otherwise APP_URL\n * \\@Envapt(['CANARY_URL', 'APP_URL'], { converter: Converters.Url })\n * static readonly canaryUrl: URL | undefined;\n *\n * // Time takes a number (milliseconds) or a time-string fallback (`<number><unit>`)\n * \\@Envapt('REQUEST_TIMEOUT', { converter: Converters.Time, fallback: '10s' })\n * static readonly requestTimeout: number;\n *\n * \\@Envapt('ALLOWED_ORIGINS', {\n * converter: Converters.array({ of: Converters.String }),\n * fallback: ['https://example.com']\n * })\n * static readonly allowedOrigins: string[];\n *\n * \\@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })\n * static readonly databaseUrl: URL;\n * }\n * ```\n */\nexport function Envapt<TConverter extends BuiltInConverter | ArrayOf>(\n key: EnvKeyInput,\n options:\n | { converter: TConverter; fallback: InferConverterFallbackType<TConverter>; required?: false }\n | { converter: TConverter; required: true }\n): EnvaptFieldDecorator<InferConverterReturnType<TConverter>>;\nexport function Envapt<TConverter extends BuiltInConverter | ArrayOf>(\n key: EnvKeyInput,\n options: { converter: TConverter; fallback?: undefined; required?: false }\n): EnvaptFieldDecorator<InferConverterReturnType<TConverter> | undefined>;\n\n/**\n * A primitive constructor (`Number`, `Boolean`) with an optional fallback.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * \\@Envapt('MAX_CONNECTIONS', { converter: Number, fallback: 100 })\n * static readonly maxConnections: number;\n *\n * \\@Envapt('FEATURE_ENABLED', { converter: Boolean, fallback: false })\n * static readonly featureEnabled: boolean;\n * }\n * ```\n */\nexport function Envapt<TConstructor extends PrimitiveConstructor>(\n key: EnvKeyInput,\n options:\n | { converter: TConstructor; fallback: InferPrimitiveReturnType<TConstructor>; required?: false }\n | { converter: TConstructor; required: true }\n): EnvaptFieldDecorator<InferPrimitiveReturnType<TConstructor>>;\nexport function Envapt<TConstructor extends PrimitiveConstructor>(\n key: EnvKeyInput,\n options: { converter: TConstructor; fallback?: undefined; required?: false }\n): EnvaptFieldDecorator<InferPrimitiveReturnType<TConstructor> | undefined>;\n\n/**\n * Required, no converter (raw string). Throws `MissingEnvValue` on first access when the env\n * value is missing or empty. Pairing `required: true` with `fallback` matches no overload at\n * compile time, and a call that bypasses the types throws `InvalidUserDefinedConfig` at runtime.\n *\n * @param key - Environment variable name(s) to load\n * @param options - `{ required: true }`\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * \\@Envapt('API_KEY', { required: true })\n * static readonly apiKey: string;\n * }\n * ```\n */\nexport function Envapt(key: EnvKeyInput, options: { required: true }): EnvaptFieldDecorator<string>;\n\n/**\n * A Standard Schema v1 adapter (zod, valibot, arktype, hand-rolled). Synchronous schemas only.\n * A `validate` that returns a Promise throws `InvalidUserDefinedConfig` at runtime. Pairing\n * `schema` with `converter` matches no overload at compile time, and a call that bypasses the\n * types throws `InvalidUserDefinedConfig` at runtime.\n * @public\n */\nexport function Envapt<Schema extends StandardSchemaV1>(\n key: EnvKeyInput,\n options:\n | { schema: SchemaConstraint<Schema>; fallback?: InferSchemaOutput<Schema>; required?: false }\n | { schema: SchemaConstraint<Schema>; required: true }\n): EnvaptFieldDecorator<InferSchemaOutput<Schema>>;\n\n/**\n * Instance or static property decorator that loads and converts an environment variable.\n * @see {@link https://envapt.materwelon.dev/docs/decorators#declaring-decorated-fields}\n */\nexport function Envapt<TFallback = unknown>(key: EnvKeyInput, options?: unknown): EnvaptFieldDecorator<unknown> {\n return createPropertyDecorator(key, parseEnvaptOptions<TFallback>(options)) as EnvaptFieldDecorator<unknown>;\n}\n"],"mappings":"uIAuMA,SAAgB,EAA4B,EAAkB,EAAkD,CAC5G,OAAO,EAAwB,EAAK,EAA8B,CAAO,CAAC,CAC9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SugarDecorators.cjs","names":["createPropertyDecorator","Converters"],"sources":["../../../../src/decorators/legacy/SugarDecorators.ts"],"sourcesContent":["import { createPropertyDecorator } from './createPropertyDecorator';\nimport { Converters } from '../../converters';\n\nimport type { ConverterToken } from '../../converters';\nimport type { EnvaptFieldDecorator, EnvKeyInput, TimeFallback } from '../../types';\n\nfunction sugar<TFallback>(\n converter: ConverterToken,\n key: EnvKeyInput,\n fallback: TFallback | undefined\n): EnvaptFieldDecorator<TFallback> {\n // the
|
|
1
|
+
{"version":3,"file":"SugarDecorators.cjs","names":["createPropertyDecorator","Converters"],"sources":["../../../../src/decorators/legacy/SugarDecorators.ts"],"sourcesContent":["import { createPropertyDecorator } from './createPropertyDecorator';\nimport { Converters } from '../../converters';\n\nimport type { ConverterToken } from '../../converters';\nimport type { EnvaptFieldDecorator, EnvKeyInput, TimeFallback } from '../../types';\n\nfunction sugar<TFallback>(\n converter: ConverterToken,\n key: EnvKeyInput,\n fallback: TFallback | undefined\n): EnvaptFieldDecorator<TFallback> {\n // the cast only adds a compile-time check on the field type\n return createPropertyDecorator<TFallback>(key, {\n converter,\n fallback,\n hasFallback: fallback !== undefined,\n required: false,\n schema: undefined\n }) as EnvaptFieldDecorator<TFallback>;\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Boolean, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvBool(key: EnvKeyInput, fallback: boolean): EnvaptFieldDecorator<boolean>;\nexport function EnvBool(key: EnvKeyInput): EnvaptFieldDecorator<boolean | undefined>;\nexport function EnvBool(key: EnvKeyInput, fallback?: boolean): EnvaptFieldDecorator<boolean | undefined> {\n return sugar(Converters.Boolean, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Number, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvNum(key: EnvKeyInput, fallback: number): EnvaptFieldDecorator<number>;\nexport function EnvNum(key: EnvKeyInput): EnvaptFieldDecorator<number | undefined>;\nexport function EnvNum(key: EnvKeyInput, fallback?: number): EnvaptFieldDecorator<number | undefined> {\n return sugar(Converters.Number, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.String, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvStr(key: EnvKeyInput, fallback: string): EnvaptFieldDecorator<string>;\nexport function EnvStr(key: EnvKeyInput): EnvaptFieldDecorator<string | undefined>;\nexport function EnvStr(key: EnvKeyInput, fallback?: string): EnvaptFieldDecorator<string | undefined> {\n return sugar(Converters.String, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Time, fallback })`. The fallback is a\n * millisecond number or a time string (`'15m'`), and the resolved value is always milliseconds.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvTime(key: EnvKeyInput, fallback: TimeFallback): EnvaptFieldDecorator<number>;\nexport function EnvTime(key: EnvKeyInput): EnvaptFieldDecorator<number | undefined>;\nexport function EnvTime(key: EnvKeyInput, fallback?: TimeFallback): EnvaptFieldDecorator<number | undefined> {\n return sugar(Converters.Time, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Url, fallback })`. The fallback must be a\n * `URL` instance.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvUrl(key: EnvKeyInput, fallback: URL): EnvaptFieldDecorator<URL>;\nexport function EnvUrl(key: EnvKeyInput): EnvaptFieldDecorator<URL | undefined>;\nexport function EnvUrl(key: EnvKeyInput, fallback?: URL): EnvaptFieldDecorator<URL | undefined> {\n return sugar(Converters.Url, key, fallback);\n}\n"],"mappings":"8FAMA,SAAS,EACL,EACA,EACA,EAC+B,CAE/B,OAAOA,EAAAA,wBAAmC,EAAK,CAC3C,YACA,WACA,YAAa,IAAa,IAAA,GAC1B,SAAU,GACV,OAAQ,IAAA,EACZ,CAAC,CACL,CASA,SAAgB,EAAQ,EAAkB,EAA+D,CACrG,OAAO,EAAMC,EAAAA,WAAW,QAAS,EAAK,CAAQ,CAClD,CASA,SAAgB,EAAO,EAAkB,EAA6D,CAClG,OAAO,EAAMA,EAAAA,WAAW,OAAQ,EAAK,CAAQ,CACjD,CASA,SAAgB,EAAO,EAAkB,EAA6D,CAClG,OAAO,EAAMA,EAAAA,WAAW,OAAQ,EAAK,CAAQ,CACjD,CAUA,SAAgB,EAAQ,EAAkB,EAAmE,CACzG,OAAO,EAAMA,EAAAA,WAAW,KAAM,EAAK,CAAQ,CAC/C,CAUA,SAAgB,EAAO,EAAkB,EAAuD,CAC5F,OAAO,EAAMA,EAAAA,WAAW,IAAK,EAAK,CAAQ,CAC9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SugarDecorators.mjs","names":[],"sources":["../../../../src/decorators/legacy/SugarDecorators.ts"],"sourcesContent":["import { createPropertyDecorator } from './createPropertyDecorator';\nimport { Converters } from '../../converters';\n\nimport type { ConverterToken } from '../../converters';\nimport type { EnvaptFieldDecorator, EnvKeyInput, TimeFallback } from '../../types';\n\nfunction sugar<TFallback>(\n converter: ConverterToken,\n key: EnvKeyInput,\n fallback: TFallback | undefined\n): EnvaptFieldDecorator<TFallback> {\n // the
|
|
1
|
+
{"version":3,"file":"SugarDecorators.mjs","names":[],"sources":["../../../../src/decorators/legacy/SugarDecorators.ts"],"sourcesContent":["import { createPropertyDecorator } from './createPropertyDecorator';\nimport { Converters } from '../../converters';\n\nimport type { ConverterToken } from '../../converters';\nimport type { EnvaptFieldDecorator, EnvKeyInput, TimeFallback } from '../../types';\n\nfunction sugar<TFallback>(\n converter: ConverterToken,\n key: EnvKeyInput,\n fallback: TFallback | undefined\n): EnvaptFieldDecorator<TFallback> {\n // the cast only adds a compile-time check on the field type\n return createPropertyDecorator<TFallback>(key, {\n converter,\n fallback,\n hasFallback: fallback !== undefined,\n required: false,\n schema: undefined\n }) as EnvaptFieldDecorator<TFallback>;\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Boolean, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvBool(key: EnvKeyInput, fallback: boolean): EnvaptFieldDecorator<boolean>;\nexport function EnvBool(key: EnvKeyInput): EnvaptFieldDecorator<boolean | undefined>;\nexport function EnvBool(key: EnvKeyInput, fallback?: boolean): EnvaptFieldDecorator<boolean | undefined> {\n return sugar(Converters.Boolean, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Number, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvNum(key: EnvKeyInput, fallback: number): EnvaptFieldDecorator<number>;\nexport function EnvNum(key: EnvKeyInput): EnvaptFieldDecorator<number | undefined>;\nexport function EnvNum(key: EnvKeyInput, fallback?: number): EnvaptFieldDecorator<number | undefined> {\n return sugar(Converters.Number, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.String, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvStr(key: EnvKeyInput, fallback: string): EnvaptFieldDecorator<string>;\nexport function EnvStr(key: EnvKeyInput): EnvaptFieldDecorator<string | undefined>;\nexport function EnvStr(key: EnvKeyInput, fallback?: string): EnvaptFieldDecorator<string | undefined> {\n return sugar(Converters.String, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Time, fallback })`. The fallback is a\n * millisecond number or a time string (`'15m'`), and the resolved value is always milliseconds.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvTime(key: EnvKeyInput, fallback: TimeFallback): EnvaptFieldDecorator<number>;\nexport function EnvTime(key: EnvKeyInput): EnvaptFieldDecorator<number | undefined>;\nexport function EnvTime(key: EnvKeyInput, fallback?: TimeFallback): EnvaptFieldDecorator<number | undefined> {\n return sugar(Converters.Time, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Url, fallback })`. The fallback must be a\n * `URL` instance.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvUrl(key: EnvKeyInput, fallback: URL): EnvaptFieldDecorator<URL>;\nexport function EnvUrl(key: EnvKeyInput): EnvaptFieldDecorator<URL | undefined>;\nexport function EnvUrl(key: EnvKeyInput, fallback?: URL): EnvaptFieldDecorator<URL | undefined> {\n return sugar(Converters.Url, key, fallback);\n}\n"],"mappings":"qIAMA,SAAS,EACL,EACA,EACA,EAC+B,CAE/B,OAAO,EAAmC,EAAK,CAC3C,YACA,WACA,YAAa,IAAa,IAAA,GAC1B,SAAU,GACV,OAAQ,IAAA,EACZ,CAAC,CACL,CASA,SAAgB,EAAQ,EAAkB,EAA+D,CACrG,OAAO,EAAM,EAAW,QAAS,EAAK,CAAQ,CAClD,CASA,SAAgB,EAAO,EAAkB,EAA6D,CAClG,OAAO,EAAM,EAAW,OAAQ,EAAK,CAAQ,CACjD,CASA,SAAgB,EAAO,EAAkB,EAA6D,CAClG,OAAO,EAAM,EAAW,OAAQ,EAAK,CAAQ,CACjD,CAUA,SAAgB,EAAQ,EAAkB,EAAmE,CACzG,OAAO,EAAM,EAAW,KAAM,EAAK,CAAQ,CAC/C,CAUA,SAAgB,EAAO,EAAkB,EAAuD,CAC5F,OAAO,EAAM,EAAW,IAAK,EAAK,CAAQ,CAC9C"}
|