envapt 5.0.2 → 5.1.0
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 -0
- package/dist/Debug.cjs +2 -0
- package/dist/Debug.cjs.map +1 -0
- package/dist/Debug.d.cts +13 -0
- package/dist/Debug.d.cts.map +1 -0
- package/dist/Debug.d.mts +13 -0
- package/dist/Debug.d.mts.map +1 -0
- package/dist/Debug.mjs +2 -0
- package/dist/Debug.mjs.map +1 -0
- package/dist/Dotenv.cjs +3 -0
- package/dist/Dotenv.cjs.map +1 -0
- package/dist/Dotenv.d.cts +17 -0
- package/dist/Dotenv.d.cts.map +1 -0
- package/dist/Dotenv.d.mts +17 -0
- package/dist/Dotenv.d.mts.map +1 -0
- package/dist/Dotenv.mjs +3 -0
- package/dist/Dotenv.mjs.map +1 -0
- package/dist/Envapter.cjs +2 -0
- package/dist/Envapter.cjs.map +1 -0
- package/dist/Envapter.d.cts +70 -0
- package/dist/Envapter.d.cts.map +1 -0
- package/dist/Envapter.d.mts +70 -0
- package/dist/Envapter.d.mts.map +1 -0
- package/dist/Envapter.mjs +2 -0
- package/dist/Envapter.mjs.map +1 -0
- package/dist/Error.cjs +2 -0
- package/dist/Error.cjs.map +1 -0
- package/dist/Error.d.cts +68 -0
- package/dist/Error.d.cts.map +1 -0
- package/dist/Error.d.mts +68 -0
- package/dist/Error.d.mts.map +1 -0
- package/dist/Error.mjs +2 -0
- package/dist/Error.mjs.map +1 -0
- package/dist/StandardSchema.d.cts +59 -0
- package/dist/StandardSchema.d.cts.map +1 -0
- package/dist/StandardSchema.d.mts +59 -0
- package/dist/StandardSchema.d.mts.map +1 -0
- package/dist/TemplateResolver.cjs +2 -0
- package/dist/TemplateResolver.cjs.map +1 -0
- package/dist/TemplateResolver.d.cts +17 -0
- package/dist/TemplateResolver.d.cts.map +1 -0
- package/dist/TemplateResolver.d.mts +17 -0
- package/dist/TemplateResolver.d.mts.map +1 -0
- package/dist/TemplateResolver.mjs +2 -0
- package/dist/TemplateResolver.mjs.map +1 -0
- package/dist/Validators.cjs +2 -0
- package/dist/Validators.cjs.map +1 -0
- package/dist/Validators.mjs +2 -0
- package/dist/Validators.mjs.map +1 -0
- package/dist/_virtual/_rolldown/runtime.cjs +1 -0
- package/dist/config.cjs +1 -1
- package/dist/config.cjs.map +1 -1
- package/dist/config.mjs +1 -1
- package/dist/config.mjs.map +1 -1
- package/dist/converters/BuiltInConverters.cjs +2 -0
- package/dist/converters/BuiltInConverters.cjs.map +1 -0
- package/dist/converters/BuiltInConverters.mjs +2 -0
- package/dist/converters/BuiltInConverters.mjs.map +1 -0
- package/dist/converters/Converters.cjs +2 -0
- package/dist/converters/Converters.cjs.map +1 -0
- package/dist/converters/Converters.d.cts +93 -0
- package/dist/converters/Converters.d.cts.map +1 -0
- package/dist/converters/Converters.d.mts +93 -0
- package/dist/converters/Converters.d.mts.map +1 -0
- package/dist/converters/Converters.mjs +2 -0
- package/dist/converters/Converters.mjs.map +1 -0
- package/dist/converters/ListOfBuiltInConverters.cjs +2 -0
- package/dist/converters/ListOfBuiltInConverters.cjs.map +1 -0
- package/dist/converters/ListOfBuiltInConverters.mjs +2 -0
- package/dist/converters/ListOfBuiltInConverters.mjs.map +1 -0
- package/dist/converters/ValueConverter.cjs +2 -0
- package/dist/converters/ValueConverter.cjs.map +1 -0
- package/dist/converters/ValueConverter.d.cts +25 -0
- package/dist/converters/ValueConverter.d.cts.map +1 -0
- package/dist/converters/ValueConverter.d.mts +25 -0
- package/dist/converters/ValueConverter.d.mts.map +1 -0
- package/dist/converters/ValueConverter.mjs +2 -0
- package/dist/converters/ValueConverter.mjs.map +1 -0
- package/dist/core/AdvancedMethods.cjs +2 -0
- package/dist/core/AdvancedMethods.cjs.map +1 -0
- package/dist/core/AdvancedMethods.d.cts +76 -0
- package/dist/core/AdvancedMethods.d.cts.map +1 -0
- package/dist/core/AdvancedMethods.d.mts +76 -0
- package/dist/core/AdvancedMethods.d.mts.map +1 -0
- package/dist/core/AdvancedMethods.mjs +2 -0
- package/dist/core/AdvancedMethods.mjs.map +1 -0
- package/dist/core/EnvapterBase.cjs +2 -0
- package/dist/core/EnvapterBase.cjs.map +1 -0
- package/dist/core/EnvapterBase.d.cts +105 -0
- package/dist/core/EnvapterBase.d.cts.map +1 -0
- package/dist/core/EnvapterBase.d.mts +105 -0
- package/dist/core/EnvapterBase.d.mts.map +1 -0
- package/dist/core/EnvapterBase.mjs +2 -0
- package/dist/core/EnvapterBase.mjs.map +1 -0
- package/dist/core/EnvironmentMethods.cjs +2 -0
- package/dist/core/EnvironmentMethods.cjs.map +1 -0
- package/dist/core/EnvironmentMethods.d.cts +132 -0
- package/dist/core/EnvironmentMethods.d.cts.map +1 -0
- package/dist/core/EnvironmentMethods.d.mts +132 -0
- package/dist/core/EnvironmentMethods.d.mts.map +1 -0
- package/dist/core/EnvironmentMethods.mjs +2 -0
- package/dist/core/EnvironmentMethods.mjs.map +1 -0
- package/dist/core/PrimitiveMethods.cjs +2 -0
- package/dist/core/PrimitiveMethods.cjs.map +1 -0
- package/dist/core/PrimitiveMethods.d.cts +70 -0
- package/dist/core/PrimitiveMethods.d.cts.map +1 -0
- package/dist/core/PrimitiveMethods.d.mts +70 -0
- package/dist/core/PrimitiveMethods.d.mts.map +1 -0
- package/dist/core/PrimitiveMethods.mjs +2 -0
- package/dist/core/PrimitiveMethods.mjs.map +1 -0
- package/dist/decorators/Envapt.cjs +2 -0
- package/dist/decorators/Envapt.cjs.map +1 -0
- package/dist/decorators/Envapt.d.cts +233 -0
- package/dist/decorators/Envapt.d.cts.map +1 -0
- package/dist/decorators/Envapt.d.mts +233 -0
- package/dist/decorators/Envapt.d.mts.map +1 -0
- package/dist/decorators/Envapt.mjs +2 -0
- package/dist/decorators/Envapt.mjs.map +1 -0
- package/dist/decorators/SugarDecorators.cjs +2 -0
- package/dist/decorators/SugarDecorators.cjs.map +1 -0
- package/dist/decorators/SugarDecorators.d.cts +34 -0
- package/dist/decorators/SugarDecorators.d.cts.map +1 -0
- package/dist/decorators/SugarDecorators.d.mts +34 -0
- package/dist/decorators/SugarDecorators.d.mts.map +1 -0
- package/dist/decorators/SugarDecorators.mjs +2 -0
- package/dist/decorators/SugarDecorators.mjs.map +1 -0
- package/dist/decorators/createPropertyDecorator.cjs +2 -0
- package/dist/decorators/createPropertyDecorator.cjs.map +1 -0
- package/dist/decorators/createPropertyDecorator.mjs +2 -0
- package/dist/decorators/createPropertyDecorator.mjs.map +1 -0
- package/dist/index.cjs +1 -2
- package/dist/index.d.cts +14 -1127
- package/dist/index.d.mts +14 -1127
- package/dist/index.mjs +1 -2
- package/dist/types/Conversion.d.cts +128 -0
- package/dist/types/Conversion.d.cts.map +1 -0
- package/dist/types/Conversion.d.mts +128 -0
- package/dist/types/Conversion.d.mts.map +1 -0
- package/dist/types/Env.d.cts +17 -0
- package/dist/types/Env.d.cts.map +1 -0
- package/dist/types/Env.d.mts +17 -0
- package/dist/types/Env.d.mts.map +1 -0
- package/dist/types/Options.d.cts +39 -0
- package/dist/types/Options.d.cts.map +1 -0
- package/dist/types/Options.d.mts +39 -0
- package/dist/types/Options.d.mts.map +1 -0
- package/dist/types/Schema.d.cts +12 -0
- package/dist/types/Schema.d.cts.map +1 -0
- package/dist/types/Schema.d.mts +12 -0
- package/dist/types/Schema.d.mts.map +1 -0
- package/package.json +2 -2
- package/dist/Envapter-CBSM3v-5.cjs +0 -3
- package/dist/Envapter-CBSM3v-5.cjs.map +0 -1
- package/dist/Envapter-D8FEdzBR.mjs +0 -3
- package/dist/Envapter-D8FEdzBR.mjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# envapt
|
|
2
2
|
|
|
3
|
+
## 5.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Emit one output module per source file (`unbundle`) so bundlers can tree-shake standalone imports: importing only `EnvaptError` or `Converters` now drops roughly 92-98% of gzip size, while the full `Envapter` path is unchanged.
|
|
8
|
+
|
|
9
|
+
## 5.0.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Update homepage in package.json
|
|
14
|
+
|
|
3
15
|
## 5.0.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/Debug.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./_virtual/_rolldown/runtime.cjs"),t=require("./Error.cjs");let n=require("node:process");n=e.__toESM(n,1);const r=new Set([`silent`,`warn`,`verbose`]);let i=`silent`,a=!1;function o(e){return e!==void 0&&r.has(e)}function s(){if(!a){let e=n.default.env.ENVAPT_DEBUG;i=o(e)?e:`silent`,a=!0}return i}function c(e){if(!o(e))throw new t.EnvaptError(302,`Invalid debug level "${String(e)}". Expected 'silent' | 'warn' | 'verbose'.`);i=e,a=!0}function l(){return s()}function u(e){let t=s();(t===`warn`||t===`verbose`)&&n.default.stderr.write(`[envapt] ${e}\n`)}function d(e){s()===`verbose`&&n.default.stderr.write(`[envapt] ${e}\n`)}exports.debugVerbose=d,exports.debugWarn=u,exports.getDebugLevel=l,exports.setDebugLevel=c;
|
|
2
|
+
//# sourceMappingURL=Debug.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Debug.cjs","names":["process","EnvaptError"],"sources":["../src/Debug.ts"],"sourcesContent":["import process from 'node:process';\n\nimport { EnvaptError, EnvaptErrorCodes } from './Error';\n\n/**\n * Debug log levels for {@link Envapter.debug}. `silent` (default) emits nothing.\n * `warn` covers signals that might indicate misconfiguration: failed file reads,\n * unresolved templates (when not strict), fallback values used in place of missing\n * env. `verbose` adds every loaded file, per-file key count, per-key load lines, and\n * effective-paths / cache-rebuild notices.\n * @public\n */\nexport type DebugLevel = 'silent' | 'warn' | 'verbose';\n\nconst VALID_LEVELS: ReadonlySet<string> = new Set<DebugLevel>(['silent', 'warn', 'verbose']);\n\nlet currentLevel: DebugLevel = 'silent';\nlet initialized = false;\n\nfunction isDebugLevel(value: string | undefined): value is DebugLevel {\n return value !== undefined && VALID_LEVELS.has(value);\n}\n\n// Reads `ENVAPT_DEBUG` lazily on first access. Setter wins after that.\nfunction resolveLevel(): DebugLevel {\n if (!initialized) {\n const fromEnv = process.env.ENVAPT_DEBUG;\n currentLevel = isDebugLevel(fromEnv) ? fromEnv : 'silent';\n initialized = true;\n }\n return currentLevel;\n}\n\n/** @internal */\nexport function setDebugLevel(level: DebugLevel): void {\n if (!isDebugLevel(level)) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Invalid debug level \"${String(level)}\". Expected 'silent' | 'warn' | 'verbose'.`\n );\n }\n currentLevel = level;\n initialized = true;\n}\n\n/** @internal */\nexport function getDebugLevel(): DebugLevel {\n return resolveLevel();\n}\n\n/** @internal */\nexport function resetDebugForTesting(): void {\n currentLevel = 'silent';\n initialized = false;\n}\n\n/** @internal */\nexport function debugWarn(message: string): void {\n const level = resolveLevel();\n if (level === 'warn' || level === 'verbose') {\n process.stderr.write(`[envapt] ${message}\\n`);\n }\n}\n\n/** @internal */\nexport function debugVerbose(message: string): void {\n if (resolveLevel() === 'verbose') {\n process.stderr.write(`[envapt] ${message}\\n`);\n }\n}\n"],"mappings":"4HAcA,MAAM,EAAoC,IAAI,IAAgB,CAAC,SAAU,OAAQ,SAAS,CAAC,EAE3F,IAAI,EAA2B,SAC3B,EAAc,GAElB,SAAS,EAAa,EAAgD,CAClE,OAAO,IAAU,IAAA,IAAa,EAAa,IAAI,CAAK,CACxD,CAGA,SAAS,GAA2B,CAChC,GAAI,CAAC,EAAa,CACd,IAAM,EAAUA,EAAAA,QAAQ,IAAI,aAC5B,EAAe,EAAa,CAAO,EAAI,EAAU,SACjD,EAAc,EAClB,CACA,OAAO,CACX,CAGA,SAAgB,EAAc,EAAyB,CACnD,GAAI,CAAC,EAAa,CAAK,EACnB,MAAM,IAAIC,EAAAA,YAAAA,IAEN,wBAAwB,OAAO,CAAK,EAAE,2CAC1C,EAEJ,EAAe,EACf,EAAc,EAClB,CAGA,SAAgB,GAA4B,CACxC,OAAO,EAAa,CACxB,CASA,SAAgB,EAAU,EAAuB,CAC7C,IAAM,EAAQ,EAAa,GACvB,IAAU,QAAU,IAAU,YAC9B,EAAA,QAAQ,OAAO,MAAM,YAAY,EAAQ,GAAG,CAEpD,CAGA,SAAgB,EAAa,EAAuB,CAC5C,EAAa,IAAM,WACnB,EAAA,QAAQ,OAAO,MAAM,YAAY,EAAQ,GAAG,CAEpD"}
|
package/dist/Debug.d.cts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/Debug.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Debug log levels for {@link Envapter.debug}. `silent` (default) emits nothing.
|
|
4
|
+
* `warn` covers signals that might indicate misconfiguration: failed file reads,
|
|
5
|
+
* unresolved templates (when not strict), fallback values used in place of missing
|
|
6
|
+
* env. `verbose` adds every loaded file, per-file key count, per-key load lines, and
|
|
7
|
+
* effective-paths / cache-rebuild notices.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
type DebugLevel = 'silent' | 'warn' | 'verbose';
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DebugLevel };
|
|
13
|
+
//# sourceMappingURL=Debug.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Debug.d.cts","names":[],"sources":["../src/Debug.ts"],"mappings":";;AAYA;;;;AAAsB;;;KAAV,UAAA"}
|
package/dist/Debug.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/Debug.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Debug log levels for {@link Envapter.debug}. `silent` (default) emits nothing.
|
|
4
|
+
* `warn` covers signals that might indicate misconfiguration: failed file reads,
|
|
5
|
+
* unresolved templates (when not strict), fallback values used in place of missing
|
|
6
|
+
* env. `verbose` adds every loaded file, per-file key count, per-key load lines, and
|
|
7
|
+
* effective-paths / cache-rebuild notices.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
type DebugLevel = 'silent' | 'warn' | 'verbose';
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DebugLevel };
|
|
13
|
+
//# sourceMappingURL=Debug.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Debug.d.mts","names":[],"sources":["../src/Debug.ts"],"mappings":";;AAYA;;;;AAAsB;;;KAAV,UAAA"}
|
package/dist/Debug.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{EnvaptError as e}from"./Error.mjs";import t from"node:process";const n=new Set([`silent`,`warn`,`verbose`]);let r=`silent`,i=!1;function a(e){return e!==void 0&&n.has(e)}function o(){if(!i){let e=t.env.ENVAPT_DEBUG;r=a(e)?e:`silent`,i=!0}return r}function s(t){if(!a(t))throw new e(302,`Invalid debug level "${String(t)}". Expected 'silent' | 'warn' | 'verbose'.`);r=t,i=!0}function c(){return o()}function l(e){let n=o();(n===`warn`||n===`verbose`)&&t.stderr.write(`[envapt] ${e}\n`)}function u(e){o()===`verbose`&&t.stderr.write(`[envapt] ${e}\n`)}export{u as debugVerbose,l as debugWarn,c as getDebugLevel,s as setDebugLevel};
|
|
2
|
+
//# sourceMappingURL=Debug.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Debug.mjs","names":[],"sources":["../src/Debug.ts"],"sourcesContent":["import process from 'node:process';\n\nimport { EnvaptError, EnvaptErrorCodes } from './Error';\n\n/**\n * Debug log levels for {@link Envapter.debug}. `silent` (default) emits nothing.\n * `warn` covers signals that might indicate misconfiguration: failed file reads,\n * unresolved templates (when not strict), fallback values used in place of missing\n * env. `verbose` adds every loaded file, per-file key count, per-key load lines, and\n * effective-paths / cache-rebuild notices.\n * @public\n */\nexport type DebugLevel = 'silent' | 'warn' | 'verbose';\n\nconst VALID_LEVELS: ReadonlySet<string> = new Set<DebugLevel>(['silent', 'warn', 'verbose']);\n\nlet currentLevel: DebugLevel = 'silent';\nlet initialized = false;\n\nfunction isDebugLevel(value: string | undefined): value is DebugLevel {\n return value !== undefined && VALID_LEVELS.has(value);\n}\n\n// Reads `ENVAPT_DEBUG` lazily on first access. Setter wins after that.\nfunction resolveLevel(): DebugLevel {\n if (!initialized) {\n const fromEnv = process.env.ENVAPT_DEBUG;\n currentLevel = isDebugLevel(fromEnv) ? fromEnv : 'silent';\n initialized = true;\n }\n return currentLevel;\n}\n\n/** @internal */\nexport function setDebugLevel(level: DebugLevel): void {\n if (!isDebugLevel(level)) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Invalid debug level \"${String(level)}\". Expected 'silent' | 'warn' | 'verbose'.`\n );\n }\n currentLevel = level;\n initialized = true;\n}\n\n/** @internal */\nexport function getDebugLevel(): DebugLevel {\n return resolveLevel();\n}\n\n/** @internal */\nexport function resetDebugForTesting(): void {\n currentLevel = 'silent';\n initialized = false;\n}\n\n/** @internal */\nexport function debugWarn(message: string): void {\n const level = resolveLevel();\n if (level === 'warn' || level === 'verbose') {\n process.stderr.write(`[envapt] ${message}\\n`);\n }\n}\n\n/** @internal */\nexport function debugVerbose(message: string): void {\n if (resolveLevel() === 'verbose') {\n process.stderr.write(`[envapt] ${message}\\n`);\n }\n}\n"],"mappings":"sEAcA,MAAM,EAAoC,IAAI,IAAgB,CAAC,SAAU,OAAQ,SAAS,CAAC,EAE3F,IAAI,EAA2B,SAC3B,EAAc,GAElB,SAAS,EAAa,EAAgD,CAClE,OAAO,IAAU,IAAA,IAAa,EAAa,IAAI,CAAK,CACxD,CAGA,SAAS,GAA2B,CAChC,GAAI,CAAC,EAAa,CACd,IAAM,EAAU,EAAQ,IAAI,aAC5B,EAAe,EAAa,CAAO,EAAI,EAAU,SACjD,EAAc,EAClB,CACA,OAAO,CACX,CAGA,SAAgB,EAAc,EAAyB,CACnD,GAAI,CAAC,EAAa,CAAK,EACnB,MAAM,IAAI,EAAA,IAEN,wBAAwB,OAAO,CAAK,EAAE,2CAC1C,EAEJ,EAAe,EACf,EAAc,EAClB,CAGA,SAAgB,GAA4B,CACxC,OAAO,EAAa,CACxB,CASA,SAAgB,EAAU,EAAuB,CAC7C,IAAM,EAAQ,EAAa,GACvB,IAAU,QAAU,IAAU,YAC9B,EAAQ,OAAO,MAAM,YAAY,EAAQ,GAAG,CAEpD,CAGA,SAAgB,EAAa,EAAuB,CAC5C,EAAa,IAAM,WACnB,EAAQ,OAAO,MAAM,YAAY,EAAQ,GAAG,CAEpD"}
|
package/dist/Dotenv.cjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const e=require("./_virtual/_rolldown/runtime.cjs"),t=require("./Debug.cjs");let n=require("node:fs");n=e.__toESM(n,1);const r=/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$/u;function i(e){let t=new Map,n=e.split(/\r?\n/u);for(let e=0;e<n.length;e++){let r=a(n,e);e=r.endLine,r.entry&&t.set(r.entry.key,r.entry.value)}return t}function a(e,t){let n=e[t]??``,i=n.trim();if(i===``||i.startsWith(`#`))return{entry:void 0,endLine:t};let a=n.match(r);if(!a)return{entry:void 0,endLine:t};let c=a[1],l=(a[2]??``).replace(/^\s+/u,``),u=l[0];if(u===`"`||u===`'`||u==="`"){let n=o(l,e,t,u);return{entry:{key:c,value:n.value},endLine:n.endLine}}return{entry:{key:c,value:s(l)},endLine:t}}function o(e,t,n,r){let i=e,a=n,o=l(i,r);for(;o<0&&a<t.length-1;)a++,i+=`\n${t[a]??``}`,o=l(i,r);let s=o>0?i.slice(1,o):i.slice(1);return{value:r===`"`?u(s):s,endLine:a}}function s(e){let t=c(e);return(t===-1?e:e.slice(0,t)).trimEnd()}function c(e){for(let t=0;t<e.length;t++)if(e[t]===`#`&&(t===0||/\s/u.test(e[t-1])))return t;return-1}function l(e,t){for(let n=e.length-1;n>0;n--)if(e[n]===t){if(t===`"`){let t=0,r=n-1;for(;r>=0&&e[r]===`\\`;)t++,r--;if(t%2==1)continue}return n}return-1}function u(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];if(r!==`\\`||n===e.length-1){t+=r;continue}let i=e[n+1];switch(n++,i){case`n`:t+=`
|
|
2
|
+
`;break;case`r`:t+=`\r`;break;case`t`:t+=` `;break;case`\\`:t+=`\\`;break;case`"`:t+=`"`;break;default:t+=`\\${i??``}`}}return t}function d(e){let r=Array.isArray(e.path)?e.path:[e.path],a=e.encoding??`utf8`,o=e.override??!1,s=new Set;for(let c of r){let r;try{r=n.default.readFileSync(c,a)}catch{t.debugWarn(`could not read ${c}`);continue}let l=i(r);t.debugVerbose(`loaded ${c}: ${l.size} ${l.size===1?`key`:`keys`}`);for(let[n,r]of l)(!Object.prototype.hasOwnProperty.call(e.processEnv,n)||o)&&(e.processEnv[n]=r,s.add(n),t.debugVerbose(`${c} -> ${n}`))}return s}exports.loadDotenv=d;
|
|
3
|
+
//# sourceMappingURL=Dotenv.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dotenv.cjs","names":["fs"],"sources":["../src/Dotenv.ts"],"sourcesContent":["import fs from 'node:fs';\n\nimport { debugVerbose, debugWarn } from './Debug';\n\n/**\n * Public options for the internal `.env` loader. Mirrors the subset of dotenv's\n * `config()` options that envapt actually supports (no DOTENV_KEY, no quiet).\n * For debug output, use `Envapter.debug` (or the `ENVAPT_DEBUG` env var).\n *\n * @public\n */\nexport interface EnvFileOptions {\n /** Encoding for reading .env files. Defaults to 'utf8'. */\n encoding?: BufferEncoding;\n /** When true, later files override earlier ones (and existing processEnv values). Default false (first-wins). */\n override?: boolean;\n}\n\n/**\n * Internal call signature used by `EnvapterBase`. The `path` and `processEnv`\n * fields are managed by envapt and never user-supplied.\n * @internal\n */\nexport interface LoadDotenvInput extends EnvFileOptions {\n path: string | string[];\n processEnv: Record<string, string>;\n}\n\n// Matches: optional `export`, KEY name, optional whitespace, `=`, optional whitespace, value tail.\n// Multi-line quoted values are handled by re-buffering subsequent lines below.\n// Bounded by anchors with linear-time quantifiers; no catastrophic backtracking risk -- justified\n// eslint-disable-next-line security/detect-unsafe-regex\nconst KEY_LINE_RE = /^\\s*(?:export\\s+)?([A-Za-z_][A-Za-z0-9_]*)\\s*=(.*)$/u;\n\n/**\n * Parse a `.env` text blob into a `Map<string, string>`.\n *\n * Supported syntax:\n * - `KEY=value` and `export KEY=value`\n * - blank lines and full-line `# comments`\n * - single-quoted `'literal'` values (no escape interpretation)\n * - double-quoted `\"value\"` values (interprets `\\n`, `\\r`, `\\t`, `\\\\`, `\\\"`)\n * - backtick-quoted values (literal, like single quotes)\n * - quoted values may span multiple lines\n * - inline `# comment` after an unquoted value (requires whitespace before `#`)\n * - empty values resolve to `\"\"`\n *\n * Mirrors dotenv's quirk where unescaped inner quotes inside a quoted value\n * are tolerated by greedy-matching to the rightmost matching quote on the\n * (possibly multi-line) value buffer. This is what lets a value like\n * `JSON=\"{\"name\":\"x\"}\"` round-trip without escaping.\n *\n * Does NOT perform `${VAR}` expansion — envapt's `Parser` handles that downstream.\n * @internal\n */\nexport function parseDotenv(src: string): Map<string, string> {\n const out = new Map<string, string>();\n const lines = src.split(/\\r?\\n/u);\n\n for (let i = 0; i < lines.length; i++) {\n const consumed = parseEntry(lines, i);\n i = consumed.endLine;\n if (consumed.entry) out.set(consumed.entry.key, consumed.entry.value);\n }\n\n return out;\n}\n\ninterface ParsedEntry {\n key: string;\n value: string;\n}\n\nfunction parseEntry(lines: string[], start: number): { entry: ParsedEntry | undefined; endLine: number } {\n /* v8 ignore next -- @preserve caller bounds-checks start so this never falls back */\n const line = lines[start] ?? '';\n const trimmedLine = line.trim();\n if (trimmedLine === '' || trimmedLine.startsWith('#')) return { entry: undefined, endLine: start };\n\n const match = line.match(KEY_LINE_RE);\n if (!match) return { entry: undefined, endLine: start };\n\n const key = match[1] as string;\n // Drop only leading whitespace before the value; trailing whitespace and inline comments\n // are dealt with below depending on whether the value is quoted.\n /* v8 ignore next -- @preserve regex group 2 always matches via `(.*)`, fallback is defensive */\n const rest = (match[2] ?? '').replace(/^\\s+/u, '');\n const firstChar = rest[0];\n\n if (firstChar === '\"' || firstChar === \"'\" || firstChar === '`') {\n const consumed = consumeQuotedValue(rest, lines, start, firstChar);\n return { entry: { key, value: consumed.value }, endLine: consumed.endLine };\n }\n\n return { entry: { key, value: stripInlineComment(rest) }, endLine: start };\n}\n\nfunction consumeQuotedValue(\n firstLineRest: string,\n lines: string[],\n startLine: number,\n quote: string\n): { value: string; endLine: number } {\n let buffer = firstLineRest;\n let cursor = startLine;\n let closeIdx = findLastUnescapedQuote(buffer, quote);\n\n while (closeIdx < 0 && cursor < lines.length - 1) {\n cursor++;\n /* v8 ignore next -- @preserve cursor is bounded by the while condition above */\n buffer += `\\n${lines[cursor] ?? ''}`;\n closeIdx = findLastUnescapedQuote(buffer, quote);\n }\n\n const inner = closeIdx > 0 ? buffer.slice(1, closeIdx) : buffer.slice(1);\n return { value: quote === '\"' ? unescapeDouble(inner) : inner, endLine: cursor };\n}\n\nfunction stripInlineComment(value: string): string {\n const hashIdx = findInlineCommentStart(value);\n const stripped = hashIdx === -1 ? value : value.slice(0, hashIdx);\n return stripped.trimEnd();\n}\n\nfunction findInlineCommentStart(value: string): number {\n for (let i = 0; i < value.length; i++) {\n if (value[i] === '#' && (i === 0 || /\\s/u.test(value[i - 1] as string))) return i;\n }\n return -1;\n}\n\n/**\n * Find the rightmost matching closing quote in `buffer` (skipping index 0 which is the\n * opening quote). For `\"`, a quote preceded by an odd number of backslashes is escaped\n * and ignored. Single and backtick quotes do not unescape.\n */\nfunction findLastUnescapedQuote(buffer: string, quote: string): number {\n for (let i = buffer.length - 1; i > 0; i--) {\n if (buffer[i] !== quote) continue;\n if (quote === '\"') {\n let backslashes = 0;\n let k = i - 1;\n while (k >= 0 && buffer[k] === '\\\\') {\n backslashes++;\n k--;\n }\n if (backslashes % 2 === 1) continue; // escaped\n }\n return i;\n }\n return -1;\n}\n\nfunction unescapeDouble(raw: string): string {\n let out = '';\n for (let i = 0; i < raw.length; i++) {\n const ch = raw[i];\n if (ch !== '\\\\' || i === raw.length - 1) {\n out += ch;\n continue;\n }\n const next = raw[i + 1];\n i++;\n switch (next) {\n case 'n':\n out += '\\n';\n break;\n case 'r':\n out += '\\r';\n break;\n case 't':\n out += '\\t';\n break;\n case '\\\\':\n out += '\\\\';\n break;\n case '\"':\n out += '\"';\n break;\n default:\n /* v8 ignore next -- @preserve `next` is always defined when this branch is reached (guarded above) */\n out += `\\\\${next ?? ''}`;\n }\n }\n return out;\n}\n\n/**\n * Load one or more `.env` files into a target `processEnv` map. Mirrors the\n * subset of dotenv's `config()` semantics that envapt depends on: first-wins\n * across multiple paths by default, optional `override: true`, optional\n * non-UTF8 encoding, missing files are skipped silently.\n *\n * Returns the set of keys actually written into `input.processEnv`. Skipped\n * collisions (under default `override: false`) are NOT included.\n * @internal\n */\nexport function loadDotenv(input: LoadDotenvInput): Set<string> {\n const paths = Array.isArray(input.path) ? input.path : [input.path];\n const encoding: BufferEncoding = input.encoding ?? 'utf8';\n const override = input.override ?? false;\n const written = new Set<string>();\n\n for (const filePath of paths) {\n let src: string;\n try {\n src = fs.readFileSync(filePath, encoding);\n } catch {\n debugWarn(`could not read ${filePath}`);\n continue;\n }\n\n const parsed = parseDotenv(src);\n debugVerbose(`loaded ${filePath}: ${parsed.size} ${parsed.size === 1 ? 'key' : 'keys'}`);\n for (const [key, value] of parsed) {\n const exists = Object.prototype.hasOwnProperty.call(input.processEnv, key);\n if (!exists || override) {\n input.processEnv[key] = value;\n written.add(key);\n debugVerbose(`${filePath} -> ${key}`);\n }\n }\n }\n\n return written;\n}\n"],"mappings":"uHAgCA,MAAM,EAAc,uDAuBpB,SAAgB,EAAY,EAAkC,CAC1D,IAAM,EAAM,IAAI,IACV,EAAQ,EAAI,MAAM,QAAQ,EAEhC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAAK,CACnC,IAAM,EAAW,EAAW,EAAO,CAAC,EACpC,EAAI,EAAS,QACT,EAAS,OAAO,EAAI,IAAI,EAAS,MAAM,IAAK,EAAS,MAAM,KAAK,CACxE,CAEA,OAAO,CACX,CAOA,SAAS,EAAW,EAAiB,EAAoE,CAErG,IAAM,EAAO,EAAM,IAAU,GACvB,EAAc,EAAK,KAAK,EAC9B,GAAI,IAAgB,IAAM,EAAY,WAAW,GAAG,EAAG,MAAO,CAAE,MAAO,IAAA,GAAW,QAAS,CAAM,EAEjG,IAAM,EAAQ,EAAK,MAAM,CAAW,EACpC,GAAI,CAAC,EAAO,MAAO,CAAE,MAAO,IAAA,GAAW,QAAS,CAAM,EAEtD,IAAM,EAAM,EAAM,GAIZ,GAAQ,EAAM,IAAM,IAAI,QAAQ,QAAS,EAAE,EAC3C,EAAY,EAAK,GAEvB,GAAI,IAAc,KAAO,IAAc,KAAO,IAAc,IAAK,CAC7D,IAAM,EAAW,EAAmB,EAAM,EAAO,EAAO,CAAS,EACjE,MAAO,CAAE,MAAO,CAAE,MAAK,MAAO,EAAS,KAAM,EAAG,QAAS,EAAS,OAAQ,CAC9E,CAEA,MAAO,CAAE,MAAO,CAAE,MAAK,MAAO,EAAmB,CAAI,CAAE,EAAG,QAAS,CAAM,CAC7E,CAEA,SAAS,EACL,EACA,EACA,EACA,EACkC,CAClC,IAAI,EAAS,EACT,EAAS,EACT,EAAW,EAAuB,EAAQ,CAAK,EAEnD,KAAO,EAAW,GAAK,EAAS,EAAM,OAAS,GAC3C,IAEA,GAAU,KAAK,EAAM,IAAW,KAChC,EAAW,EAAuB,EAAQ,CAAK,EAGnD,IAAM,EAAQ,EAAW,EAAI,EAAO,MAAM,EAAG,CAAQ,EAAI,EAAO,MAAM,CAAC,EACvE,MAAO,CAAE,MAAO,IAAU,IAAM,EAAe,CAAK,EAAI,EAAO,QAAS,CAAO,CACnF,CAEA,SAAS,EAAmB,EAAuB,CAC/C,IAAM,EAAU,EAAuB,CAAK,EAE5C,OADiB,IAAY,GAAK,EAAQ,EAAM,MAAM,EAAG,CAAO,GAChD,QAAQ,CAC5B,CAEA,SAAS,EAAuB,EAAuB,CACnD,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAC9B,GAAI,EAAM,KAAO,MAAQ,IAAM,GAAK,MAAM,KAAK,EAAM,EAAI,EAAY,GAAI,OAAO,EAEpF,MAAO,EACX,CAOA,SAAS,EAAuB,EAAgB,EAAuB,CACnE,IAAK,IAAI,EAAI,EAAO,OAAS,EAAG,EAAI,EAAG,IAC/B,KAAO,KAAO,EAClB,IAAI,IAAU,IAAK,CACf,IAAI,EAAc,EACd,EAAI,EAAI,EACZ,KAAO,GAAK,GAAK,EAAO,KAAO,MAC3B,IACA,IAEJ,GAAI,EAAc,GAAM,EAAG,QAC/B,CACA,OAAO,CADP,CAGJ,MAAO,EACX,CAEA,SAAS,EAAe,EAAqB,CACzC,IAAI,EAAM,GACV,IAAK,IAAI,EAAI,EAAG,EAAI,EAAI,OAAQ,IAAK,CACjC,IAAM,EAAK,EAAI,GACf,GAAI,IAAO,MAAQ,IAAM,EAAI,OAAS,EAAG,CACrC,GAAO,EACP,QACJ,CACA,IAAM,EAAO,EAAI,EAAI,GAErB,OADA,IACQ,EAAR,CACI,IAAK,IACD,GAAO;EACP,MACJ,IAAK,IACD,GAAO,KACP,MACJ,IAAK,IACD,GAAO,IACP,MACJ,IAAK,KACD,GAAO,KACP,MACJ,IAAK,IACD,GAAO,IACP,MACJ,QAEI,GAAO,KAAK,GAAQ,IAC5B,CACJ,CACA,OAAO,CACX,CAYA,SAAgB,EAAW,EAAqC,CAC5D,IAAM,EAAQ,MAAM,QAAQ,EAAM,IAAI,EAAI,EAAM,KAAO,CAAC,EAAM,IAAI,EAC5D,EAA2B,EAAM,UAAY,OAC7C,EAAW,EAAM,UAAY,GAC7B,EAAU,IAAI,IAEpB,IAAK,IAAM,KAAY,EAAO,CAC1B,IAAI,EACJ,GAAI,CACA,EAAMA,EAAAA,QAAG,aAAa,EAAU,CAAQ,CAC5C,MAAQ,CACJ,EAAA,UAAU,kBAAkB,GAAU,EACtC,QACJ,CAEA,IAAM,EAAS,EAAY,CAAG,EAC9B,EAAA,aAAa,UAAU,EAAS,IAAI,EAAO,KAAK,GAAG,EAAO,OAAS,EAAI,MAAQ,QAAQ,EACvF,IAAK,GAAM,CAAC,EAAK,KAAU,GAEnB,CADW,OAAO,UAAU,eAAe,KAAK,EAAM,WAAY,CAC5D,GAAK,KACX,EAAM,WAAW,GAAO,EACxB,EAAQ,IAAI,CAAG,EACf,EAAA,aAAa,GAAG,EAAS,MAAM,GAAK,EAGhD,CAEA,OAAO,CACX"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/Dotenv.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Public options for the internal `.env` loader. Mirrors the subset of dotenv's
|
|
4
|
+
* `config()` options that envapt actually supports (no DOTENV_KEY, no quiet).
|
|
5
|
+
* For debug output, use `Envapter.debug` (or the `ENVAPT_DEBUG` env var).
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
interface EnvFileOptions {
|
|
10
|
+
/** Encoding for reading .env files. Defaults to 'utf8'. */
|
|
11
|
+
encoding?: BufferEncoding;
|
|
12
|
+
/** When true, later files override earlier ones (and existing processEnv values). Default false (first-wins). */
|
|
13
|
+
override?: boolean;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { EnvFileOptions };
|
|
17
|
+
//# sourceMappingURL=Dotenv.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dotenv.d.cts","names":[],"sources":["../src/Dotenv.ts"],"mappings":";;AAWA;;;;;;UAAiB,cAAA;EAIL;EAFR,QAAA,GAAW,cAAc;;EAEzB,QAAA;AAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/Dotenv.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Public options for the internal `.env` loader. Mirrors the subset of dotenv's
|
|
4
|
+
* `config()` options that envapt actually supports (no DOTENV_KEY, no quiet).
|
|
5
|
+
* For debug output, use `Envapter.debug` (or the `ENVAPT_DEBUG` env var).
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
interface EnvFileOptions {
|
|
10
|
+
/** Encoding for reading .env files. Defaults to 'utf8'. */
|
|
11
|
+
encoding?: BufferEncoding;
|
|
12
|
+
/** When true, later files override earlier ones (and existing processEnv values). Default false (first-wins). */
|
|
13
|
+
override?: boolean;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { EnvFileOptions };
|
|
17
|
+
//# sourceMappingURL=Dotenv.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dotenv.d.mts","names":[],"sources":["../src/Dotenv.ts"],"mappings":";;AAWA;;;;;;UAAiB,cAAA;EAIL;EAFR,QAAA,GAAW,cAAc;;EAEzB,QAAA;AAAA"}
|
package/dist/Dotenv.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{debugVerbose as e,debugWarn as t}from"./Debug.mjs";import n from"node:fs";const r=/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$/u;function i(e){let t=new Map,n=e.split(/\r?\n/u);for(let e=0;e<n.length;e++){let r=a(n,e);e=r.endLine,r.entry&&t.set(r.entry.key,r.entry.value)}return t}function a(e,t){let n=e[t]??``,i=n.trim();if(i===``||i.startsWith(`#`))return{entry:void 0,endLine:t};let a=n.match(r);if(!a)return{entry:void 0,endLine:t};let c=a[1],l=(a[2]??``).replace(/^\s+/u,``),u=l[0];if(u===`"`||u===`'`||u==="`"){let n=o(l,e,t,u);return{entry:{key:c,value:n.value},endLine:n.endLine}}return{entry:{key:c,value:s(l)},endLine:t}}function o(e,t,n,r){let i=e,a=n,o=l(i,r);for(;o<0&&a<t.length-1;)a++,i+=`\n${t[a]??``}`,o=l(i,r);let s=o>0?i.slice(1,o):i.slice(1);return{value:r===`"`?u(s):s,endLine:a}}function s(e){let t=c(e);return(t===-1?e:e.slice(0,t)).trimEnd()}function c(e){for(let t=0;t<e.length;t++)if(e[t]===`#`&&(t===0||/\s/u.test(e[t-1])))return t;return-1}function l(e,t){for(let n=e.length-1;n>0;n--)if(e[n]===t){if(t===`"`){let t=0,r=n-1;for(;r>=0&&e[r]===`\\`;)t++,r--;if(t%2==1)continue}return n}return-1}function u(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];if(r!==`\\`||n===e.length-1){t+=r;continue}let i=e[n+1];switch(n++,i){case`n`:t+=`
|
|
2
|
+
`;break;case`r`:t+=`\r`;break;case`t`:t+=` `;break;case`\\`:t+=`\\`;break;case`"`:t+=`"`;break;default:t+=`\\${i??``}`}}return t}function d(r){let a=Array.isArray(r.path)?r.path:[r.path],o=r.encoding??`utf8`,s=r.override??!1,c=new Set;for(let l of a){let a;try{a=n.readFileSync(l,o)}catch{t(`could not read ${l}`);continue}let u=i(a);e(`loaded ${l}: ${u.size} ${u.size===1?`key`:`keys`}`);for(let[t,n]of u)(!Object.prototype.hasOwnProperty.call(r.processEnv,t)||s)&&(r.processEnv[t]=n,c.add(t),e(`${l} -> ${t}`))}return c}export{d as loadDotenv};
|
|
3
|
+
//# sourceMappingURL=Dotenv.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dotenv.mjs","names":[],"sources":["../src/Dotenv.ts"],"sourcesContent":["import fs from 'node:fs';\n\nimport { debugVerbose, debugWarn } from './Debug';\n\n/**\n * Public options for the internal `.env` loader. Mirrors the subset of dotenv's\n * `config()` options that envapt actually supports (no DOTENV_KEY, no quiet).\n * For debug output, use `Envapter.debug` (or the `ENVAPT_DEBUG` env var).\n *\n * @public\n */\nexport interface EnvFileOptions {\n /** Encoding for reading .env files. Defaults to 'utf8'. */\n encoding?: BufferEncoding;\n /** When true, later files override earlier ones (and existing processEnv values). Default false (first-wins). */\n override?: boolean;\n}\n\n/**\n * Internal call signature used by `EnvapterBase`. The `path` and `processEnv`\n * fields are managed by envapt and never user-supplied.\n * @internal\n */\nexport interface LoadDotenvInput extends EnvFileOptions {\n path: string | string[];\n processEnv: Record<string, string>;\n}\n\n// Matches: optional `export`, KEY name, optional whitespace, `=`, optional whitespace, value tail.\n// Multi-line quoted values are handled by re-buffering subsequent lines below.\n// Bounded by anchors with linear-time quantifiers; no catastrophic backtracking risk -- justified\n// eslint-disable-next-line security/detect-unsafe-regex\nconst KEY_LINE_RE = /^\\s*(?:export\\s+)?([A-Za-z_][A-Za-z0-9_]*)\\s*=(.*)$/u;\n\n/**\n * Parse a `.env` text blob into a `Map<string, string>`.\n *\n * Supported syntax:\n * - `KEY=value` and `export KEY=value`\n * - blank lines and full-line `# comments`\n * - single-quoted `'literal'` values (no escape interpretation)\n * - double-quoted `\"value\"` values (interprets `\\n`, `\\r`, `\\t`, `\\\\`, `\\\"`)\n * - backtick-quoted values (literal, like single quotes)\n * - quoted values may span multiple lines\n * - inline `# comment` after an unquoted value (requires whitespace before `#`)\n * - empty values resolve to `\"\"`\n *\n * Mirrors dotenv's quirk where unescaped inner quotes inside a quoted value\n * are tolerated by greedy-matching to the rightmost matching quote on the\n * (possibly multi-line) value buffer. This is what lets a value like\n * `JSON=\"{\"name\":\"x\"}\"` round-trip without escaping.\n *\n * Does NOT perform `${VAR}` expansion — envapt's `Parser` handles that downstream.\n * @internal\n */\nexport function parseDotenv(src: string): Map<string, string> {\n const out = new Map<string, string>();\n const lines = src.split(/\\r?\\n/u);\n\n for (let i = 0; i < lines.length; i++) {\n const consumed = parseEntry(lines, i);\n i = consumed.endLine;\n if (consumed.entry) out.set(consumed.entry.key, consumed.entry.value);\n }\n\n return out;\n}\n\ninterface ParsedEntry {\n key: string;\n value: string;\n}\n\nfunction parseEntry(lines: string[], start: number): { entry: ParsedEntry | undefined; endLine: number } {\n /* v8 ignore next -- @preserve caller bounds-checks start so this never falls back */\n const line = lines[start] ?? '';\n const trimmedLine = line.trim();\n if (trimmedLine === '' || trimmedLine.startsWith('#')) return { entry: undefined, endLine: start };\n\n const match = line.match(KEY_LINE_RE);\n if (!match) return { entry: undefined, endLine: start };\n\n const key = match[1] as string;\n // Drop only leading whitespace before the value; trailing whitespace and inline comments\n // are dealt with below depending on whether the value is quoted.\n /* v8 ignore next -- @preserve regex group 2 always matches via `(.*)`, fallback is defensive */\n const rest = (match[2] ?? '').replace(/^\\s+/u, '');\n const firstChar = rest[0];\n\n if (firstChar === '\"' || firstChar === \"'\" || firstChar === '`') {\n const consumed = consumeQuotedValue(rest, lines, start, firstChar);\n return { entry: { key, value: consumed.value }, endLine: consumed.endLine };\n }\n\n return { entry: { key, value: stripInlineComment(rest) }, endLine: start };\n}\n\nfunction consumeQuotedValue(\n firstLineRest: string,\n lines: string[],\n startLine: number,\n quote: string\n): { value: string; endLine: number } {\n let buffer = firstLineRest;\n let cursor = startLine;\n let closeIdx = findLastUnescapedQuote(buffer, quote);\n\n while (closeIdx < 0 && cursor < lines.length - 1) {\n cursor++;\n /* v8 ignore next -- @preserve cursor is bounded by the while condition above */\n buffer += `\\n${lines[cursor] ?? ''}`;\n closeIdx = findLastUnescapedQuote(buffer, quote);\n }\n\n const inner = closeIdx > 0 ? buffer.slice(1, closeIdx) : buffer.slice(1);\n return { value: quote === '\"' ? unescapeDouble(inner) : inner, endLine: cursor };\n}\n\nfunction stripInlineComment(value: string): string {\n const hashIdx = findInlineCommentStart(value);\n const stripped = hashIdx === -1 ? value : value.slice(0, hashIdx);\n return stripped.trimEnd();\n}\n\nfunction findInlineCommentStart(value: string): number {\n for (let i = 0; i < value.length; i++) {\n if (value[i] === '#' && (i === 0 || /\\s/u.test(value[i - 1] as string))) return i;\n }\n return -1;\n}\n\n/**\n * Find the rightmost matching closing quote in `buffer` (skipping index 0 which is the\n * opening quote). For `\"`, a quote preceded by an odd number of backslashes is escaped\n * and ignored. Single and backtick quotes do not unescape.\n */\nfunction findLastUnescapedQuote(buffer: string, quote: string): number {\n for (let i = buffer.length - 1; i > 0; i--) {\n if (buffer[i] !== quote) continue;\n if (quote === '\"') {\n let backslashes = 0;\n let k = i - 1;\n while (k >= 0 && buffer[k] === '\\\\') {\n backslashes++;\n k--;\n }\n if (backslashes % 2 === 1) continue; // escaped\n }\n return i;\n }\n return -1;\n}\n\nfunction unescapeDouble(raw: string): string {\n let out = '';\n for (let i = 0; i < raw.length; i++) {\n const ch = raw[i];\n if (ch !== '\\\\' || i === raw.length - 1) {\n out += ch;\n continue;\n }\n const next = raw[i + 1];\n i++;\n switch (next) {\n case 'n':\n out += '\\n';\n break;\n case 'r':\n out += '\\r';\n break;\n case 't':\n out += '\\t';\n break;\n case '\\\\':\n out += '\\\\';\n break;\n case '\"':\n out += '\"';\n break;\n default:\n /* v8 ignore next -- @preserve `next` is always defined when this branch is reached (guarded above) */\n out += `\\\\${next ?? ''}`;\n }\n }\n return out;\n}\n\n/**\n * Load one or more `.env` files into a target `processEnv` map. Mirrors the\n * subset of dotenv's `config()` semantics that envapt depends on: first-wins\n * across multiple paths by default, optional `override: true`, optional\n * non-UTF8 encoding, missing files are skipped silently.\n *\n * Returns the set of keys actually written into `input.processEnv`. Skipped\n * collisions (under default `override: false`) are NOT included.\n * @internal\n */\nexport function loadDotenv(input: LoadDotenvInput): Set<string> {\n const paths = Array.isArray(input.path) ? input.path : [input.path];\n const encoding: BufferEncoding = input.encoding ?? 'utf8';\n const override = input.override ?? false;\n const written = new Set<string>();\n\n for (const filePath of paths) {\n let src: string;\n try {\n src = fs.readFileSync(filePath, encoding);\n } catch {\n debugWarn(`could not read ${filePath}`);\n continue;\n }\n\n const parsed = parseDotenv(src);\n debugVerbose(`loaded ${filePath}: ${parsed.size} ${parsed.size === 1 ? 'key' : 'keys'}`);\n for (const [key, value] of parsed) {\n const exists = Object.prototype.hasOwnProperty.call(input.processEnv, key);\n if (!exists || override) {\n input.processEnv[key] = value;\n written.add(key);\n debugVerbose(`${filePath} -> ${key}`);\n }\n }\n }\n\n return written;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./Error.cjs");require("./core/EnvapterBase.cjs"),require("./core/EnvironmentMethods.cjs");const t=require("./core/AdvancedMethods.cjs");var n=class n extends t.AdvancedMethods{static resolve(t,...r){let i=n.strict;return t.reduce((t,n,a)=>{let o=r[a];if(!o)return t+n;let s=super.get(o,``);if(i&&s.trim()===``)throw new e.EnvaptError(305,`Cannot resolve template variable "\${${o}}": value is missing or empty.`);return t+n+s},``)}resolve(e,...t){return n.resolve(e,...t)}static require(...t){let r=[];for(let e of t)n.resolveAndValidate(e)===void 0&&r.push(e);if(r.length>0)throw new e.EnvaptError(305,`Missing required environment variables: ${r.join(`, `)}.`)}static resolveAndValidate(e){let{value:t}=this.resolveKeyInput(e);if(t===void 0)return;let n=this.templateResolver.resolveTemplate(e,t);if(n.trim()!==``)return n}require(...e){n.require(...e)}};exports.Envapter=n;
|
|
2
|
+
//# sourceMappingURL=Envapter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Envapter.cjs","names":["AdvancedMethods","EnvaptError"],"sources":["../src/Envapter.ts"],"sourcesContent":["import { AdvancedMethods } from './core';\nimport { EnvaptError, EnvaptErrorCodes } from './Error';\n\nexport { EnvaptCache, Environment } from './core';\n\n/**\n * Main configuration class for environment variable management.\n *\n * Provides both static and instance methods for retrieving typed environment variables\n * with support for template resolution, multiple .env files, and environment detection.\n *\n * Extend your own classes from this to define properties with \\@Envapt decorators and get access to environment-variable methods.\n *\n * @example\n * ```ts\n * // Static usage\n * const port = Envapter.getNumber('PORT', 3000);\n * const url = Envapter.get('API_URL', 'http://localhost');\n * const replica = Envapter.get(['READONLY_URL', 'DATABASE_URL'], 'sqlite://memory');\n *\n * // Instance usage\n * const env = new Envapter();\n * const dbUrl = env.get('DATABASE_URL', 'sqlite://memory');\n * const primaryHost = env.get(['PRIMARY_HOST', 'SECONDARY_HOST']);\n * ```\n *\n * @public\n */\nexport class Envapter extends AdvancedMethods {\n /**\n * Tagged template literal for resolving environment variables in template strings.\n *\n * @example\n * ```ts\n * // Given API_HOST=api.example.com and API_PORT=8080 in environment\n * const endpoint = Envapter.resolve`Connecting to ${'API_HOST'}:${'API_PORT'}`;\n * // Returns: \"Connecting to api.example.com:8080\"\n *\n * // Works with template variables in .env too:\n * // API_URL=https://${API_HOST}:${API_PORT}\n * const message = Envapter.resolve`Service endpoint: ${'API_URL'}`;\n * // Returns: \"Service endpoint: https://api.example.com:8080\"\n * ```\n */\n static resolve(strings: TemplateStringsArray, ...keys: string[]): string {\n const strict = Envapter.strict;\n return strings.reduce((result, string, i) => {\n const envKey = keys[i];\n if (!envKey) return result + string;\n const raw = super.get(envKey, '');\n if (strict && raw.trim() === '') {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Cannot resolve template variable \"\\${${envKey}}\": value is missing or empty.`\n );\n }\n return result + string + raw;\n }, '');\n }\n\n /**\n * @see {@link Envapter.resolve}\n */\n resolve(strings: TemplateStringsArray, ...keys: string[]): string {\n return Envapter.resolve(strings, ...keys);\n }\n\n /**\n * Assert that one or more environment variables are present and non-empty (post-trim,\n * after template resolution). Throws `MissingEnvValue` listing every missing key.\n *\n * For typed fail-fast in functional code, use `Envapter.getUsing(key, { converter, required: true })`.\n *\n * @example\n * ```ts\n * Envapter.require('DATABASE_URL');\n * Envapter.require('DATABASE_URL', 'API_KEY', 'SENTRY_DSN');\n * ```\n */\n static require(...keys: [string, ...string[]]): void {\n const missing: string[] = [];\n for (const k of keys) {\n if (Envapter.resolveAndValidate(k) === undefined) missing.push(k);\n }\n\n if (missing.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Missing required environment variables: ${missing.join(', ')}.`\n );\n }\n }\n\n private static resolveAndValidate(key: string): string | undefined {\n const { value } = this.resolveKeyInput(key);\n if (value === undefined) return undefined;\n const resolved = this.templateResolver.resolveTemplate(key, value);\n if (resolved.trim() === '') return undefined;\n return resolved;\n }\n\n /**\n * @see {@link Envapter.require}\n */\n require(...keys: [string, ...string[]]): void {\n Envapter.require(...keys);\n }\n}\n"],"mappings":"yJA4BA,IAAa,EAAb,MAAa,UAAiBA,EAAAA,eAAgB,CAgB1C,OAAO,QAAQ,EAA+B,GAAG,EAAwB,CACrE,IAAM,EAAS,EAAS,OACxB,OAAO,EAAQ,QAAQ,EAAQ,EAAQ,IAAM,CACzC,IAAM,EAAS,EAAK,GACpB,GAAI,CAAC,EAAQ,OAAO,EAAS,EAC7B,IAAM,EAAM,MAAM,IAAI,EAAQ,EAAE,EAChC,GAAI,GAAU,EAAI,KAAK,IAAM,GACzB,MAAM,IAAIC,EAAAA,YAAAA,IAEN,wCAAwC,EAAO,+BACnD,EAEJ,OAAO,EAAS,EAAS,CAC7B,EAAG,EAAE,CACT,CAKA,QAAQ,EAA+B,GAAG,EAAwB,CAC9D,OAAO,EAAS,QAAQ,EAAS,GAAG,CAAI,CAC5C,CAcA,OAAO,QAAQ,GAAG,EAAmC,CACjD,IAAM,EAAoB,CAAC,EAC3B,IAAK,IAAM,KAAK,EACR,EAAS,mBAAmB,CAAC,IAAM,IAAA,IAAW,EAAQ,KAAK,CAAC,EAGpE,GAAI,EAAQ,OAAS,EACjB,MAAM,IAAIA,EAAAA,YAAAA,IAEN,2CAA2C,EAAQ,KAAK,IAAI,EAAE,EAClE,CAER,CAEA,OAAe,mBAAmB,EAAiC,CAC/D,GAAM,CAAE,SAAU,KAAK,gBAAgB,CAAG,EAC1C,GAAI,IAAU,IAAA,GAAW,OACzB,IAAM,EAAW,KAAK,iBAAiB,gBAAgB,EAAK,CAAK,EAC7D,KAAS,KAAK,IAAM,GACxB,OAAO,CACX,CAKA,QAAQ,GAAG,EAAmC,CAC1C,EAAS,QAAQ,GAAG,CAAI,CAC5B,CACJ"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Environment } from "./core/EnvironmentMethods.cjs";
|
|
2
|
+
import { AdvancedMethods } from "./core/AdvancedMethods.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/Envapter.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Main configuration class for environment variable management.
|
|
7
|
+
*
|
|
8
|
+
* Provides both static and instance methods for retrieving typed environment variables
|
|
9
|
+
* with support for template resolution, multiple .env files, and environment detection.
|
|
10
|
+
*
|
|
11
|
+
* Extend your own classes from this to define properties with \@Envapt decorators and get access to environment-variable methods.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // Static usage
|
|
16
|
+
* const port = Envapter.getNumber('PORT', 3000);
|
|
17
|
+
* const url = Envapter.get('API_URL', 'http://localhost');
|
|
18
|
+
* const replica = Envapter.get(['READONLY_URL', 'DATABASE_URL'], 'sqlite://memory');
|
|
19
|
+
*
|
|
20
|
+
* // Instance usage
|
|
21
|
+
* const env = new Envapter();
|
|
22
|
+
* const dbUrl = env.get('DATABASE_URL', 'sqlite://memory');
|
|
23
|
+
* const primaryHost = env.get(['PRIMARY_HOST', 'SECONDARY_HOST']);
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
declare class Envapter extends AdvancedMethods {
|
|
29
|
+
/**
|
|
30
|
+
* Tagged template literal for resolving environment variables in template strings.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* // Given API_HOST=api.example.com and API_PORT=8080 in environment
|
|
35
|
+
* const endpoint = Envapter.resolve`Connecting to ${'API_HOST'}:${'API_PORT'}`;
|
|
36
|
+
* // Returns: "Connecting to api.example.com:8080"
|
|
37
|
+
*
|
|
38
|
+
* // Works with template variables in .env too:
|
|
39
|
+
* // API_URL=https://${API_HOST}:${API_PORT}
|
|
40
|
+
* const message = Envapter.resolve`Service endpoint: ${'API_URL'}`;
|
|
41
|
+
* // Returns: "Service endpoint: https://api.example.com:8080"
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
static resolve(strings: TemplateStringsArray, ...keys: string[]): string;
|
|
45
|
+
/**
|
|
46
|
+
* @see {@link Envapter.resolve}
|
|
47
|
+
*/
|
|
48
|
+
resolve(strings: TemplateStringsArray, ...keys: string[]): string;
|
|
49
|
+
/**
|
|
50
|
+
* Assert that one or more environment variables are present and non-empty (post-trim,
|
|
51
|
+
* after template resolution). Throws `MissingEnvValue` listing every missing key.
|
|
52
|
+
*
|
|
53
|
+
* For typed fail-fast in functional code, use `Envapter.getUsing(key, { converter, required: true })`.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* Envapter.require('DATABASE_URL');
|
|
58
|
+
* Envapter.require('DATABASE_URL', 'API_KEY', 'SENTRY_DSN');
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
static require(...keys: [string, ...string[]]): void;
|
|
62
|
+
private static resolveAndValidate;
|
|
63
|
+
/**
|
|
64
|
+
* @see {@link Envapter.require}
|
|
65
|
+
*/
|
|
66
|
+
require(...keys: [string, ...string[]]): void;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { Envapter };
|
|
70
|
+
//# sourceMappingURL=Envapter.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Envapter.d.cts","names":[],"sources":["../src/Envapter.ts"],"mappings":";;;;;;AA4BA;;;;;;;;;;;;;;;;;;;;;cAAa,QAAA,SAAiB,eAAA;EA4EX;AAAA;;;;;;;;;;;;;;EAAA,OA5DR,OAAA,CAAQ,OAAA,EAAS,oBAAA,KAAyB,IAAA;;;;EAmBjD,OAAA,CAAQ,OAAA,EAAS,oBAAA,KAAyB,IAAA;;;;;;;;;;;;;SAgBnC,OAAA,CAAA,GAAW,IAAA;EAAA,eAcH,kBAAA;;;;EAWf,OAAA,CAAA,GAAW,IAAA;AAAA"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Environment } from "./core/EnvironmentMethods.mjs";
|
|
2
|
+
import { AdvancedMethods } from "./core/AdvancedMethods.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/Envapter.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Main configuration class for environment variable management.
|
|
7
|
+
*
|
|
8
|
+
* Provides both static and instance methods for retrieving typed environment variables
|
|
9
|
+
* with support for template resolution, multiple .env files, and environment detection.
|
|
10
|
+
*
|
|
11
|
+
* Extend your own classes from this to define properties with \@Envapt decorators and get access to environment-variable methods.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // Static usage
|
|
16
|
+
* const port = Envapter.getNumber('PORT', 3000);
|
|
17
|
+
* const url = Envapter.get('API_URL', 'http://localhost');
|
|
18
|
+
* const replica = Envapter.get(['READONLY_URL', 'DATABASE_URL'], 'sqlite://memory');
|
|
19
|
+
*
|
|
20
|
+
* // Instance usage
|
|
21
|
+
* const env = new Envapter();
|
|
22
|
+
* const dbUrl = env.get('DATABASE_URL', 'sqlite://memory');
|
|
23
|
+
* const primaryHost = env.get(['PRIMARY_HOST', 'SECONDARY_HOST']);
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
declare class Envapter extends AdvancedMethods {
|
|
29
|
+
/**
|
|
30
|
+
* Tagged template literal for resolving environment variables in template strings.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* // Given API_HOST=api.example.com and API_PORT=8080 in environment
|
|
35
|
+
* const endpoint = Envapter.resolve`Connecting to ${'API_HOST'}:${'API_PORT'}`;
|
|
36
|
+
* // Returns: "Connecting to api.example.com:8080"
|
|
37
|
+
*
|
|
38
|
+
* // Works with template variables in .env too:
|
|
39
|
+
* // API_URL=https://${API_HOST}:${API_PORT}
|
|
40
|
+
* const message = Envapter.resolve`Service endpoint: ${'API_URL'}`;
|
|
41
|
+
* // Returns: "Service endpoint: https://api.example.com:8080"
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
static resolve(strings: TemplateStringsArray, ...keys: string[]): string;
|
|
45
|
+
/**
|
|
46
|
+
* @see {@link Envapter.resolve}
|
|
47
|
+
*/
|
|
48
|
+
resolve(strings: TemplateStringsArray, ...keys: string[]): string;
|
|
49
|
+
/**
|
|
50
|
+
* Assert that one or more environment variables are present and non-empty (post-trim,
|
|
51
|
+
* after template resolution). Throws `MissingEnvValue` listing every missing key.
|
|
52
|
+
*
|
|
53
|
+
* For typed fail-fast in functional code, use `Envapter.getUsing(key, { converter, required: true })`.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* Envapter.require('DATABASE_URL');
|
|
58
|
+
* Envapter.require('DATABASE_URL', 'API_KEY', 'SENTRY_DSN');
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
static require(...keys: [string, ...string[]]): void;
|
|
62
|
+
private static resolveAndValidate;
|
|
63
|
+
/**
|
|
64
|
+
* @see {@link Envapter.require}
|
|
65
|
+
*/
|
|
66
|
+
require(...keys: [string, ...string[]]): void;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { Envapter };
|
|
70
|
+
//# sourceMappingURL=Envapter.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Envapter.d.mts","names":[],"sources":["../src/Envapter.ts"],"mappings":";;;;;;AA4BA;;;;;;;;;;;;;;;;;;;;;cAAa,QAAA,SAAiB,eAAA;EA4EX;AAAA;;;;;;;;;;;;;;EAAA,OA5DR,OAAA,CAAQ,OAAA,EAAS,oBAAA,KAAyB,IAAA;;;;EAmBjD,OAAA,CAAQ,OAAA,EAAS,oBAAA,KAAyB,IAAA;;;;;;;;;;;;;SAgBnC,OAAA,CAAA,GAAW,IAAA;EAAA,eAcH,kBAAA;;;;EAWf,OAAA,CAAA,GAAW,IAAA;AAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{EnvaptError as e}from"./Error.mjs";import"./core/EnvapterBase.mjs";import"./core/EnvironmentMethods.mjs";import{AdvancedMethods as t}from"./core/AdvancedMethods.mjs";var n=class n extends t{static resolve(t,...r){let i=n.strict;return t.reduce((t,n,a)=>{let o=r[a];if(!o)return t+n;let s=super.get(o,``);if(i&&s.trim()===``)throw new e(305,`Cannot resolve template variable "\${${o}}": value is missing or empty.`);return t+n+s},``)}resolve(e,...t){return n.resolve(e,...t)}static require(...t){let r=[];for(let e of t)n.resolveAndValidate(e)===void 0&&r.push(e);if(r.length>0)throw new e(305,`Missing required environment variables: ${r.join(`, `)}.`)}static resolveAndValidate(e){let{value:t}=this.resolveKeyInput(e);if(t===void 0)return;let n=this.templateResolver.resolveTemplate(e,t);if(n.trim()!==``)return n}require(...e){n.require(...e)}};export{n as Envapter};
|
|
2
|
+
//# sourceMappingURL=Envapter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Envapter.mjs","names":[],"sources":["../src/Envapter.ts"],"sourcesContent":["import { AdvancedMethods } from './core';\nimport { EnvaptError, EnvaptErrorCodes } from './Error';\n\nexport { EnvaptCache, Environment } from './core';\n\n/**\n * Main configuration class for environment variable management.\n *\n * Provides both static and instance methods for retrieving typed environment variables\n * with support for template resolution, multiple .env files, and environment detection.\n *\n * Extend your own classes from this to define properties with \\@Envapt decorators and get access to environment-variable methods.\n *\n * @example\n * ```ts\n * // Static usage\n * const port = Envapter.getNumber('PORT', 3000);\n * const url = Envapter.get('API_URL', 'http://localhost');\n * const replica = Envapter.get(['READONLY_URL', 'DATABASE_URL'], 'sqlite://memory');\n *\n * // Instance usage\n * const env = new Envapter();\n * const dbUrl = env.get('DATABASE_URL', 'sqlite://memory');\n * const primaryHost = env.get(['PRIMARY_HOST', 'SECONDARY_HOST']);\n * ```\n *\n * @public\n */\nexport class Envapter extends AdvancedMethods {\n /**\n * Tagged template literal for resolving environment variables in template strings.\n *\n * @example\n * ```ts\n * // Given API_HOST=api.example.com and API_PORT=8080 in environment\n * const endpoint = Envapter.resolve`Connecting to ${'API_HOST'}:${'API_PORT'}`;\n * // Returns: \"Connecting to api.example.com:8080\"\n *\n * // Works with template variables in .env too:\n * // API_URL=https://${API_HOST}:${API_PORT}\n * const message = Envapter.resolve`Service endpoint: ${'API_URL'}`;\n * // Returns: \"Service endpoint: https://api.example.com:8080\"\n * ```\n */\n static resolve(strings: TemplateStringsArray, ...keys: string[]): string {\n const strict = Envapter.strict;\n return strings.reduce((result, string, i) => {\n const envKey = keys[i];\n if (!envKey) return result + string;\n const raw = super.get(envKey, '');\n if (strict && raw.trim() === '') {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Cannot resolve template variable \"\\${${envKey}}\": value is missing or empty.`\n );\n }\n return result + string + raw;\n }, '');\n }\n\n /**\n * @see {@link Envapter.resolve}\n */\n resolve(strings: TemplateStringsArray, ...keys: string[]): string {\n return Envapter.resolve(strings, ...keys);\n }\n\n /**\n * Assert that one or more environment variables are present and non-empty (post-trim,\n * after template resolution). Throws `MissingEnvValue` listing every missing key.\n *\n * For typed fail-fast in functional code, use `Envapter.getUsing(key, { converter, required: true })`.\n *\n * @example\n * ```ts\n * Envapter.require('DATABASE_URL');\n * Envapter.require('DATABASE_URL', 'API_KEY', 'SENTRY_DSN');\n * ```\n */\n static require(...keys: [string, ...string[]]): void {\n const missing: string[] = [];\n for (const k of keys) {\n if (Envapter.resolveAndValidate(k) === undefined) missing.push(k);\n }\n\n if (missing.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Missing required environment variables: ${missing.join(', ')}.`\n );\n }\n }\n\n private static resolveAndValidate(key: string): string | undefined {\n const { value } = this.resolveKeyInput(key);\n if (value === undefined) return undefined;\n const resolved = this.templateResolver.resolveTemplate(key, value);\n if (resolved.trim() === '') return undefined;\n return resolved;\n }\n\n /**\n * @see {@link Envapter.require}\n */\n require(...keys: [string, ...string[]]): void {\n Envapter.require(...keys);\n }\n}\n"],"mappings":"6KA4BA,IAAa,EAAb,MAAa,UAAiB,CAAgB,CAgB1C,OAAO,QAAQ,EAA+B,GAAG,EAAwB,CACrE,IAAM,EAAS,EAAS,OACxB,OAAO,EAAQ,QAAQ,EAAQ,EAAQ,IAAM,CACzC,IAAM,EAAS,EAAK,GACpB,GAAI,CAAC,EAAQ,OAAO,EAAS,EAC7B,IAAM,EAAM,MAAM,IAAI,EAAQ,EAAE,EAChC,GAAI,GAAU,EAAI,KAAK,IAAM,GACzB,MAAM,IAAI,EAAA,IAEN,wCAAwC,EAAO,+BACnD,EAEJ,OAAO,EAAS,EAAS,CAC7B,EAAG,EAAE,CACT,CAKA,QAAQ,EAA+B,GAAG,EAAwB,CAC9D,OAAO,EAAS,QAAQ,EAAS,GAAG,CAAI,CAC5C,CAcA,OAAO,QAAQ,GAAG,EAAmC,CACjD,IAAM,EAAoB,CAAC,EAC3B,IAAK,IAAM,KAAK,EACR,EAAS,mBAAmB,CAAC,IAAM,IAAA,IAAW,EAAQ,KAAK,CAAC,EAGpE,GAAI,EAAQ,OAAS,EACjB,MAAM,IAAI,EAAA,IAEN,2CAA2C,EAAQ,KAAK,IAAI,EAAE,EAClE,CAER,CAEA,OAAe,mBAAmB,EAAiC,CAC/D,GAAM,CAAE,SAAU,KAAK,gBAAgB,CAAG,EAC1C,GAAI,IAAU,IAAA,GAAW,OACzB,IAAM,EAAW,KAAK,iBAAiB,gBAAgB,EAAK,CAAK,EAC7D,KAAS,KAAK,IAAM,GACxB,OAAO,CACX,CAKA,QAAQ,GAAG,EAAmC,CAC1C,EAAS,QAAQ,GAAG,CAAI,CAC5B,CACJ"}
|
package/dist/Error.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
let e=function(e){return e[e.InvalidFallback=101]=`InvalidFallback`,e[e.InvalidFallbackType=102]=`InvalidFallbackType`,e[e.ArrayFallbackElementTypeMismatch=103]=`ArrayFallbackElementTypeMismatch`,e[e.FallbackConverterTypeMismatch=104]=`FallbackConverterTypeMismatch`,e[e.MalformedTimeFallback=105]=`MalformedTimeFallback`,e[e.InvalidArrayConverterType=201]=`InvalidArrayConverterType`,e[e.InvalidBuiltInConverter=202]=`InvalidBuiltInConverter`,e[e.InvalidCustomConverter=203]=`InvalidCustomConverter`,e[e.InvalidConverterType=204]=`InvalidConverterType`,e[e.PrimitiveCoercionFailed=205]=`PrimitiveCoercionFailed`,e[e.ArrayElementConversionFailed=206]=`ArrayElementConversionFailed`,e[e.EmptyArrayElement=207]=`EmptyArrayElement`,e[e.SchemaValidationFailed=208]=`SchemaValidationFailed`,e[e.SchemaThrew=209]=`SchemaThrew`,e[e.MissingDelimiter=301]=`MissingDelimiter`,e[e.InvalidUserDefinedConfig=302]=`InvalidUserDefinedConfig`,e[e.EnvFilesNotFound=303]=`EnvFilesNotFound`,e[e.InvalidKeyInput=304]=`InvalidKeyInput`,e[e.MissingEnvValue=305]=`MissingEnvValue`,e}({});var t=class extends Error{code;issues;constructor(e,t,n){super(t,n?.cause===void 0?void 0:{cause:n.cause}),this.name=`EnvaptError [${e}]`,this.code=e,this.issues=n?.issues}};exports.EnvaptError=t,exports.EnvaptErrorCodes=e;
|
|
2
|
+
//# sourceMappingURL=Error.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Error.cjs","names":[],"sources":["../src/Error.ts"],"sourcesContent":["/* eslint-disable no-magic-numbers */\nimport type { StandardSchemaV1 } from './StandardSchema';\n\nexport enum EnvaptErrorCodes {\n // Fallback related errors\n /** Thrown when an invalid fallback value is provided */\n InvalidFallback = 101,\n /** Thrown when fallback value type doesn't match expected converter type */\n InvalidFallbackType = 102,\n /** Thrown when array fallback contains elements of wrong type */\n ArrayFallbackElementTypeMismatch = 103,\n /** Thrown when fallback type doesn't match the specified converter */\n FallbackConverterTypeMismatch = 104,\n /** Thrown when a time-string fallback is malformed (does not match the required `<integer><unit>` format) */\n MalformedTimeFallback = 105,\n\n // Converter related errors\n /** Thrown when invalid array converter configuration is provided */\n InvalidArrayConverterType = 201,\n /** Thrown when an invalid built-in converter is specified */\n InvalidBuiltInConverter = 202,\n /** Thrown when a custom converter is not a function */\n InvalidCustomConverter = 203,\n /** Thrown when converter type is not recognized */\n InvalidConverterType = 204,\n /** Thrown when primitive type coercion on fallback value fails */\n PrimitiveCoercionFailed = 205,\n /** Thrown when an array element fails to convert to the configured element type */\n ArrayElementConversionFailed = 206,\n /** Thrown under strict mode when an array element is empty or whitespace only */\n EmptyArrayElement = 207,\n /** Thrown when a Standard Schema returns issues for a non-empty env value */\n SchemaValidationFailed = 208,\n /** Thrown when a Standard Schema's `validate` itself throws (e.g. a refinement that crashes) */\n SchemaThrew = 209,\n\n // Other errors\n /** Thrown when delimiter is missing in array converter configuration */\n // This doesn't happen because 203 is thrown when object without delimiter is passed\n MissingDelimiter = 301,\n /** Thrown when invalid user-defined configuration is provided */\n InvalidUserDefinedConfig = 302,\n /** Thrown when specified environment files don't exist */\n EnvFilesNotFound = 303,\n /** Thrown when no valid environment key is provided */\n InvalidKeyInput = 304,\n /** Thrown when a required environment value is missing or empty (post-trim) */\n MissingEnvValue = 305\n}\n\ninterface EnvaptErrorOptions {\n issues?: readonly StandardSchemaV1.Issue[];\n cause?: unknown;\n}\n\n/**\n * Custom error for better DX and debugging when using Envapt.\n *\n * @example\n * ```ts\n * throw new EnvaptError(EnvaptErrorCodes.InvalidFallback, \"Invalid fallback value provided for environment variable.\");\n * ```\n */\nexport class EnvaptError extends Error {\n public readonly code: EnvaptErrorCodes;\n /**\n * Populated only for {@link EnvaptErrorCodes.SchemaValidationFailed} (208). For every other\n * code this is `undefined`. Lets callers do `if (err.code === 208) err.issues?.forEach(...)`\n * without a type cast.\n */\n public readonly issues: readonly StandardSchemaV1.Issue[] | undefined;\n\n constructor(code: EnvaptErrorCodes, message: string, options?: EnvaptErrorOptions) {\n super(message, options?.cause !== undefined ? { cause: options.cause } : undefined);\n this.name = `EnvaptError [${code}]`;\n this.code = code;\n this.issues = options?.issues;\n }\n}\n"],"mappings":"AAGA,IAAY,EAAL,SAAA,EAAA,OAGH,GAAA,EAAA,gBAAA,KAAA,kBAEA,EAAA,EAAA,oBAAA,KAAA,sBAEA,EAAA,EAAA,iCAAA,KAAA,mCAEA,EAAA,EAAA,8BAAA,KAAA,gCAEA,EAAA,EAAA,sBAAA,KAAA,wBAIA,EAAA,EAAA,0BAAA,KAAA,4BAEA,EAAA,EAAA,wBAAA,KAAA,0BAEA,EAAA,EAAA,uBAAA,KAAA,yBAEA,EAAA,EAAA,qBAAA,KAAA,uBAEA,EAAA,EAAA,wBAAA,KAAA,0BAEA,EAAA,EAAA,6BAAA,KAAA,+BAEA,EAAA,EAAA,kBAAA,KAAA,oBAEA,EAAA,EAAA,uBAAA,KAAA,yBAEA,EAAA,EAAA,YAAA,KAAA,cAKA,EAAA,EAAA,iBAAA,KAAA,mBAEA,EAAA,EAAA,yBAAA,KAAA,2BAEA,EAAA,EAAA,iBAAA,KAAA,mBAEA,EAAA,EAAA,gBAAA,KAAA,kBAEA,EAAA,EAAA,gBAAA,KAAA,mBACJ,EAAA,CAAA,CAAA,EAeA,IAAa,EAAb,cAAiC,KAAM,CACnC,KAMA,OAEA,YAAY,EAAwB,EAAiB,EAA8B,CAC/E,MAAM,EAAS,GAAS,QAAU,IAAA,GAAuC,IAAA,GAA3B,CAAE,MAAO,EAAQ,KAAM,CAAa,EAClF,KAAK,KAAO,gBAAgB,EAAK,GACjC,KAAK,KAAO,EACZ,KAAK,OAAS,GAAS,MAC3B,CACJ"}
|
package/dist/Error.d.cts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "./StandardSchema.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/Error.d.ts
|
|
4
|
+
declare enum EnvaptErrorCodes {
|
|
5
|
+
/** Thrown when an invalid fallback value is provided */
|
|
6
|
+
InvalidFallback = 101,
|
|
7
|
+
/** Thrown when fallback value type doesn't match expected converter type */
|
|
8
|
+
InvalidFallbackType = 102,
|
|
9
|
+
/** Thrown when array fallback contains elements of wrong type */
|
|
10
|
+
ArrayFallbackElementTypeMismatch = 103,
|
|
11
|
+
/** Thrown when fallback type doesn't match the specified converter */
|
|
12
|
+
FallbackConverterTypeMismatch = 104,
|
|
13
|
+
/** Thrown when a time-string fallback is malformed (does not match the required `<integer><unit>` format) */
|
|
14
|
+
MalformedTimeFallback = 105,
|
|
15
|
+
/** Thrown when invalid array converter configuration is provided */
|
|
16
|
+
InvalidArrayConverterType = 201,
|
|
17
|
+
/** Thrown when an invalid built-in converter is specified */
|
|
18
|
+
InvalidBuiltInConverter = 202,
|
|
19
|
+
/** Thrown when a custom converter is not a function */
|
|
20
|
+
InvalidCustomConverter = 203,
|
|
21
|
+
/** Thrown when converter type is not recognized */
|
|
22
|
+
InvalidConverterType = 204,
|
|
23
|
+
/** Thrown when primitive type coercion on fallback value fails */
|
|
24
|
+
PrimitiveCoercionFailed = 205,
|
|
25
|
+
/** Thrown when an array element fails to convert to the configured element type */
|
|
26
|
+
ArrayElementConversionFailed = 206,
|
|
27
|
+
/** Thrown under strict mode when an array element is empty or whitespace only */
|
|
28
|
+
EmptyArrayElement = 207,
|
|
29
|
+
/** Thrown when a Standard Schema returns issues for a non-empty env value */
|
|
30
|
+
SchemaValidationFailed = 208,
|
|
31
|
+
/** Thrown when a Standard Schema's `validate` itself throws (e.g. a refinement that crashes) */
|
|
32
|
+
SchemaThrew = 209,
|
|
33
|
+
/** Thrown when delimiter is missing in array converter configuration */
|
|
34
|
+
MissingDelimiter = 301,
|
|
35
|
+
/** Thrown when invalid user-defined configuration is provided */
|
|
36
|
+
InvalidUserDefinedConfig = 302,
|
|
37
|
+
/** Thrown when specified environment files don't exist */
|
|
38
|
+
EnvFilesNotFound = 303,
|
|
39
|
+
/** Thrown when no valid environment key is provided */
|
|
40
|
+
InvalidKeyInput = 304,
|
|
41
|
+
/** Thrown when a required environment value is missing or empty (post-trim) */
|
|
42
|
+
MissingEnvValue = 305
|
|
43
|
+
}
|
|
44
|
+
interface EnvaptErrorOptions {
|
|
45
|
+
issues?: readonly StandardSchemaV1.Issue[];
|
|
46
|
+
cause?: unknown;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Custom error for better DX and debugging when using Envapt.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* throw new EnvaptError(EnvaptErrorCodes.InvalidFallback, "Invalid fallback value provided for environment variable.");
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare class EnvaptError extends Error {
|
|
57
|
+
readonly code: EnvaptErrorCodes;
|
|
58
|
+
/**
|
|
59
|
+
* Populated only for {@link EnvaptErrorCodes.SchemaValidationFailed} (208). For every other
|
|
60
|
+
* code this is `undefined`. Lets callers do `if (err.code === 208) err.issues?.forEach(...)`
|
|
61
|
+
* without a type cast.
|
|
62
|
+
*/
|
|
63
|
+
readonly issues: readonly StandardSchemaV1.Issue[] | undefined;
|
|
64
|
+
constructor(code: EnvaptErrorCodes, message: string, options?: EnvaptErrorOptions);
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { EnvaptError, EnvaptErrorCodes };
|
|
68
|
+
//# sourceMappingURL=Error.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Error.d.cts","names":[],"sources":["../src/Error.ts"],"mappings":";;;aAGY,gBAAA;;EAGR,eAAA;EAHwB;EAKxB,mBAAA;EALwB;EAOxB,gCAAA;EAFA;EAIA,6BAAA;EAAA;EAEA,qBAAA;EAIA;EAAA,yBAAA;EAIA;EAFA,uBAAA;EAMA;EAJA,sBAAA;EAQA;EANA,oBAAA;EAUA;EARA,uBAAA;EAeA;EAbA,4BAAA;EAiBA;EAfA,iBAAA;EAiBe;EAff,sBAAA;EAkBM;EAhBN,WAAA;;EAKA,gBAAA;EAYA;EAVA,wBAAA;EAUmC;EARnC,gBAAA;EASK;EAPL,eAAA;EAkBS;EAhBT,eAAA;AAAA;AAAA,UAGM,kBAAA;EACN,MAAA,YAAkB,gBAAA,CAAiB,KAAK;EACxC,KAAA;AAAA;;;;;;;;;cAWS,WAAA,SAAoB,KAAA;EAAA,SACb,IAAA,EAAM,gBAAA;EAQJ;;;;;EAAA,SAFF,MAAA,WAAiB,gBAAA,CAAiB,KAAA;cAEtC,IAAA,EAAM,gBAAA,EAAkB,OAAA,UAAiB,OAAA,GAAU,kBAAA;AAAA"}
|
package/dist/Error.d.mts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "./StandardSchema.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/Error.d.ts
|
|
4
|
+
declare enum EnvaptErrorCodes {
|
|
5
|
+
/** Thrown when an invalid fallback value is provided */
|
|
6
|
+
InvalidFallback = 101,
|
|
7
|
+
/** Thrown when fallback value type doesn't match expected converter type */
|
|
8
|
+
InvalidFallbackType = 102,
|
|
9
|
+
/** Thrown when array fallback contains elements of wrong type */
|
|
10
|
+
ArrayFallbackElementTypeMismatch = 103,
|
|
11
|
+
/** Thrown when fallback type doesn't match the specified converter */
|
|
12
|
+
FallbackConverterTypeMismatch = 104,
|
|
13
|
+
/** Thrown when a time-string fallback is malformed (does not match the required `<integer><unit>` format) */
|
|
14
|
+
MalformedTimeFallback = 105,
|
|
15
|
+
/** Thrown when invalid array converter configuration is provided */
|
|
16
|
+
InvalidArrayConverterType = 201,
|
|
17
|
+
/** Thrown when an invalid built-in converter is specified */
|
|
18
|
+
InvalidBuiltInConverter = 202,
|
|
19
|
+
/** Thrown when a custom converter is not a function */
|
|
20
|
+
InvalidCustomConverter = 203,
|
|
21
|
+
/** Thrown when converter type is not recognized */
|
|
22
|
+
InvalidConverterType = 204,
|
|
23
|
+
/** Thrown when primitive type coercion on fallback value fails */
|
|
24
|
+
PrimitiveCoercionFailed = 205,
|
|
25
|
+
/** Thrown when an array element fails to convert to the configured element type */
|
|
26
|
+
ArrayElementConversionFailed = 206,
|
|
27
|
+
/** Thrown under strict mode when an array element is empty or whitespace only */
|
|
28
|
+
EmptyArrayElement = 207,
|
|
29
|
+
/** Thrown when a Standard Schema returns issues for a non-empty env value */
|
|
30
|
+
SchemaValidationFailed = 208,
|
|
31
|
+
/** Thrown when a Standard Schema's `validate` itself throws (e.g. a refinement that crashes) */
|
|
32
|
+
SchemaThrew = 209,
|
|
33
|
+
/** Thrown when delimiter is missing in array converter configuration */
|
|
34
|
+
MissingDelimiter = 301,
|
|
35
|
+
/** Thrown when invalid user-defined configuration is provided */
|
|
36
|
+
InvalidUserDefinedConfig = 302,
|
|
37
|
+
/** Thrown when specified environment files don't exist */
|
|
38
|
+
EnvFilesNotFound = 303,
|
|
39
|
+
/** Thrown when no valid environment key is provided */
|
|
40
|
+
InvalidKeyInput = 304,
|
|
41
|
+
/** Thrown when a required environment value is missing or empty (post-trim) */
|
|
42
|
+
MissingEnvValue = 305
|
|
43
|
+
}
|
|
44
|
+
interface EnvaptErrorOptions {
|
|
45
|
+
issues?: readonly StandardSchemaV1.Issue[];
|
|
46
|
+
cause?: unknown;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Custom error for better DX and debugging when using Envapt.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* throw new EnvaptError(EnvaptErrorCodes.InvalidFallback, "Invalid fallback value provided for environment variable.");
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare class EnvaptError extends Error {
|
|
57
|
+
readonly code: EnvaptErrorCodes;
|
|
58
|
+
/**
|
|
59
|
+
* Populated only for {@link EnvaptErrorCodes.SchemaValidationFailed} (208). For every other
|
|
60
|
+
* code this is `undefined`. Lets callers do `if (err.code === 208) err.issues?.forEach(...)`
|
|
61
|
+
* without a type cast.
|
|
62
|
+
*/
|
|
63
|
+
readonly issues: readonly StandardSchemaV1.Issue[] | undefined;
|
|
64
|
+
constructor(code: EnvaptErrorCodes, message: string, options?: EnvaptErrorOptions);
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { EnvaptError, EnvaptErrorCodes };
|
|
68
|
+
//# sourceMappingURL=Error.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Error.d.mts","names":[],"sources":["../src/Error.ts"],"mappings":";;;aAGY,gBAAA;;EAGR,eAAA;EAHwB;EAKxB,mBAAA;EALwB;EAOxB,gCAAA;EAFA;EAIA,6BAAA;EAAA;EAEA,qBAAA;EAIA;EAAA,yBAAA;EAIA;EAFA,uBAAA;EAMA;EAJA,sBAAA;EAQA;EANA,oBAAA;EAUA;EARA,uBAAA;EAeA;EAbA,4BAAA;EAiBA;EAfA,iBAAA;EAiBe;EAff,sBAAA;EAkBM;EAhBN,WAAA;;EAKA,gBAAA;EAYA;EAVA,wBAAA;EAUmC;EARnC,gBAAA;EASK;EAPL,eAAA;EAkBS;EAhBT,eAAA;AAAA;AAAA,UAGM,kBAAA;EACN,MAAA,YAAkB,gBAAA,CAAiB,KAAK;EACxC,KAAA;AAAA;;;;;;;;;cAWS,WAAA,SAAoB,KAAA;EAAA,SACb,IAAA,EAAM,gBAAA;EAQJ;;;;;EAAA,SAFF,MAAA,WAAiB,gBAAA,CAAiB,KAAA;cAEtC,IAAA,EAAM,gBAAA,EAAkB,OAAA,UAAiB,OAAA,GAAU,kBAAA;AAAA"}
|
package/dist/Error.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
let e=function(e){return e[e.InvalidFallback=101]=`InvalidFallback`,e[e.InvalidFallbackType=102]=`InvalidFallbackType`,e[e.ArrayFallbackElementTypeMismatch=103]=`ArrayFallbackElementTypeMismatch`,e[e.FallbackConverterTypeMismatch=104]=`FallbackConverterTypeMismatch`,e[e.MalformedTimeFallback=105]=`MalformedTimeFallback`,e[e.InvalidArrayConverterType=201]=`InvalidArrayConverterType`,e[e.InvalidBuiltInConverter=202]=`InvalidBuiltInConverter`,e[e.InvalidCustomConverter=203]=`InvalidCustomConverter`,e[e.InvalidConverterType=204]=`InvalidConverterType`,e[e.PrimitiveCoercionFailed=205]=`PrimitiveCoercionFailed`,e[e.ArrayElementConversionFailed=206]=`ArrayElementConversionFailed`,e[e.EmptyArrayElement=207]=`EmptyArrayElement`,e[e.SchemaValidationFailed=208]=`SchemaValidationFailed`,e[e.SchemaThrew=209]=`SchemaThrew`,e[e.MissingDelimiter=301]=`MissingDelimiter`,e[e.InvalidUserDefinedConfig=302]=`InvalidUserDefinedConfig`,e[e.EnvFilesNotFound=303]=`EnvFilesNotFound`,e[e.InvalidKeyInput=304]=`InvalidKeyInput`,e[e.MissingEnvValue=305]=`MissingEnvValue`,e}({});var t=class extends Error{code;issues;constructor(e,t,n){super(t,n?.cause===void 0?void 0:{cause:n.cause}),this.name=`EnvaptError [${e}]`,this.code=e,this.issues=n?.issues}};export{t as EnvaptError,e as EnvaptErrorCodes};
|
|
2
|
+
//# sourceMappingURL=Error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Error.mjs","names":[],"sources":["../src/Error.ts"],"sourcesContent":["/* eslint-disable no-magic-numbers */\nimport type { StandardSchemaV1 } from './StandardSchema';\n\nexport enum EnvaptErrorCodes {\n // Fallback related errors\n /** Thrown when an invalid fallback value is provided */\n InvalidFallback = 101,\n /** Thrown when fallback value type doesn't match expected converter type */\n InvalidFallbackType = 102,\n /** Thrown when array fallback contains elements of wrong type */\n ArrayFallbackElementTypeMismatch = 103,\n /** Thrown when fallback type doesn't match the specified converter */\n FallbackConverterTypeMismatch = 104,\n /** Thrown when a time-string fallback is malformed (does not match the required `<integer><unit>` format) */\n MalformedTimeFallback = 105,\n\n // Converter related errors\n /** Thrown when invalid array converter configuration is provided */\n InvalidArrayConverterType = 201,\n /** Thrown when an invalid built-in converter is specified */\n InvalidBuiltInConverter = 202,\n /** Thrown when a custom converter is not a function */\n InvalidCustomConverter = 203,\n /** Thrown when converter type is not recognized */\n InvalidConverterType = 204,\n /** Thrown when primitive type coercion on fallback value fails */\n PrimitiveCoercionFailed = 205,\n /** Thrown when an array element fails to convert to the configured element type */\n ArrayElementConversionFailed = 206,\n /** Thrown under strict mode when an array element is empty or whitespace only */\n EmptyArrayElement = 207,\n /** Thrown when a Standard Schema returns issues for a non-empty env value */\n SchemaValidationFailed = 208,\n /** Thrown when a Standard Schema's `validate` itself throws (e.g. a refinement that crashes) */\n SchemaThrew = 209,\n\n // Other errors\n /** Thrown when delimiter is missing in array converter configuration */\n // This doesn't happen because 203 is thrown when object without delimiter is passed\n MissingDelimiter = 301,\n /** Thrown when invalid user-defined configuration is provided */\n InvalidUserDefinedConfig = 302,\n /** Thrown when specified environment files don't exist */\n EnvFilesNotFound = 303,\n /** Thrown when no valid environment key is provided */\n InvalidKeyInput = 304,\n /** Thrown when a required environment value is missing or empty (post-trim) */\n MissingEnvValue = 305\n}\n\ninterface EnvaptErrorOptions {\n issues?: readonly StandardSchemaV1.Issue[];\n cause?: unknown;\n}\n\n/**\n * Custom error for better DX and debugging when using Envapt.\n *\n * @example\n * ```ts\n * throw new EnvaptError(EnvaptErrorCodes.InvalidFallback, \"Invalid fallback value provided for environment variable.\");\n * ```\n */\nexport class EnvaptError extends Error {\n public readonly code: EnvaptErrorCodes;\n /**\n * Populated only for {@link EnvaptErrorCodes.SchemaValidationFailed} (208). For every other\n * code this is `undefined`. Lets callers do `if (err.code === 208) err.issues?.forEach(...)`\n * without a type cast.\n */\n public readonly issues: readonly StandardSchemaV1.Issue[] | undefined;\n\n constructor(code: EnvaptErrorCodes, message: string, options?: EnvaptErrorOptions) {\n super(message, options?.cause !== undefined ? { cause: options.cause } : undefined);\n this.name = `EnvaptError [${code}]`;\n this.code = code;\n this.issues = options?.issues;\n }\n}\n"],"mappings":"AAGA,IAAY,EAAL,SAAA,EAAA,OAGH,GAAA,EAAA,gBAAA,KAAA,kBAEA,EAAA,EAAA,oBAAA,KAAA,sBAEA,EAAA,EAAA,iCAAA,KAAA,mCAEA,EAAA,EAAA,8BAAA,KAAA,gCAEA,EAAA,EAAA,sBAAA,KAAA,wBAIA,EAAA,EAAA,0BAAA,KAAA,4BAEA,EAAA,EAAA,wBAAA,KAAA,0BAEA,EAAA,EAAA,uBAAA,KAAA,yBAEA,EAAA,EAAA,qBAAA,KAAA,uBAEA,EAAA,EAAA,wBAAA,KAAA,0BAEA,EAAA,EAAA,6BAAA,KAAA,+BAEA,EAAA,EAAA,kBAAA,KAAA,oBAEA,EAAA,EAAA,uBAAA,KAAA,yBAEA,EAAA,EAAA,YAAA,KAAA,cAKA,EAAA,EAAA,iBAAA,KAAA,mBAEA,EAAA,EAAA,yBAAA,KAAA,2BAEA,EAAA,EAAA,iBAAA,KAAA,mBAEA,EAAA,EAAA,gBAAA,KAAA,kBAEA,EAAA,EAAA,gBAAA,KAAA,mBACJ,EAAA,CAAA,CAAA,EAeA,IAAa,EAAb,cAAiC,KAAM,CACnC,KAMA,OAEA,YAAY,EAAwB,EAAiB,EAA8B,CAC/E,MAAM,EAAS,GAAS,QAAU,IAAA,GAAuC,IAAA,GAA3B,CAAE,MAAO,EAAQ,KAAM,CAAa,EAClF,KAAK,KAAO,gBAAgB,EAAK,GACjC,KAAK,KAAO,EACZ,KAAK,OAAS,GAAS,MAC3B,CACJ"}
|