envapt 7.0.0-next.0 → 7.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/browser/index.mjs.map +1 -1
  3. package/dist/{node → types}/engine/NodeEnvapter.d.mts +0 -2
  4. package/dist/{node → types}/index.d.mts +0 -2
  5. package/dist/{node/sources/NodeEnvSource.d.cts → types/sources/NodeEnvSource.d.mts} +2 -2
  6. package/package.json +23 -19
  7. package/dist/node/config.d.mts +0 -2
  8. package/dist/node/converters/Converters.d.cts +0 -93
  9. package/dist/node/converters/Converters.d.mts +0 -95
  10. package/dist/node/converters/ValueConverter.d.cts +0 -25
  11. package/dist/node/converters/ValueConverter.d.mts +0 -27
  12. package/dist/node/core/AdvancedMethods.d.cts +0 -76
  13. package/dist/node/core/AdvancedMethods.d.mts +0 -78
  14. package/dist/node/core/EnvapterBase.d.cts +0 -75
  15. package/dist/node/core/EnvapterBase.d.mts +0 -77
  16. package/dist/node/core/EnvironmentMethods.d.cts +0 -115
  17. package/dist/node/core/EnvironmentMethods.d.mts +0 -117
  18. package/dist/node/core/PrimitiveMethods.d.cts +0 -70
  19. package/dist/node/core/PrimitiveMethods.d.mts +0 -72
  20. package/dist/node/decorators/legacy/Envapt.d.cts +0 -218
  21. package/dist/node/decorators/legacy/Envapt.d.mts +0 -220
  22. package/dist/node/decorators/legacy/SugarDecorators.d.cts +0 -40
  23. package/dist/node/decorators/legacy/SugarDecorators.d.mts +0 -42
  24. package/dist/node/decorators/modern/Envapt.d.cts +0 -218
  25. package/dist/node/decorators/modern/Envapt.d.mts +0 -220
  26. package/dist/node/decorators/modern/SugarDecorators.d.cts +0 -40
  27. package/dist/node/decorators/modern/SugarDecorators.d.mts +0 -42
  28. package/dist/node/engine/Envapter.d.cts +0 -70
  29. package/dist/node/engine/Envapter.d.mts +0 -72
  30. package/dist/node/engine/NodeEnvapter.d.cts +0 -73
  31. package/dist/node/engine/TemplateResolver.d.cts +0 -17
  32. package/dist/node/engine/TemplateResolver.d.mts +0 -19
  33. package/dist/node/index.d.cts +0 -19
  34. package/dist/node/infra/Debug.d.cts +0 -13
  35. package/dist/node/infra/Debug.d.mts +0 -15
  36. package/dist/node/infra/Dotenv.d.cts +0 -17
  37. package/dist/node/infra/Dotenv.d.mts +0 -19
  38. package/dist/node/infra/Error.d.cts +0 -72
  39. package/dist/node/infra/Error.d.mts +0 -74
  40. package/dist/node/infra/StandardSchema.d.cts +0 -59
  41. package/dist/node/infra/StandardSchema.d.mts +0 -61
  42. package/dist/node/legacy.d.cts +0 -4
  43. package/dist/node/legacy.d.mts +0 -6
  44. package/dist/node/sources/ManualEnvSource.d.cts +0 -19
  45. package/dist/node/sources/ManualEnvSource.d.mts +0 -21
  46. package/dist/node/sources/NodeEnvSource.d.mts +0 -22
  47. package/dist/node/sources/WorkerEnvSource.d.cts +0 -19
  48. package/dist/node/sources/WorkerEnvSource.d.mts +0 -21
  49. package/dist/node/types/Conversion.d.cts +0 -123
  50. package/dist/node/types/Conversion.d.mts +0 -125
  51. package/dist/node/types/Decorator.d.cts +0 -26
  52. package/dist/node/types/Decorator.d.mts +0 -28
  53. package/dist/node/types/Env.d.cts +0 -17
  54. package/dist/node/types/Env.d.mts +0 -19
  55. package/dist/node/types/Options.d.cts +0 -39
  56. package/dist/node/types/Options.d.mts +0 -41
  57. package/dist/node/types/Schema.d.cts +0 -12
  58. package/dist/node/types/Schema.d.mts +0 -14
  59. package/dist/node/types/Source.d.cts +0 -44
  60. package/dist/node/types/Source.d.mts +0 -46
  61. package/dist/workerd/converters/Converters.d.mts +0 -93
  62. package/dist/workerd/converters/ValueConverter.d.mts +0 -25
  63. package/dist/workerd/core/AdvancedMethods.d.mts +0 -76
  64. package/dist/workerd/core/EnvapterBase.d.mts +0 -75
  65. package/dist/workerd/core/EnvironmentMethods.d.mts +0 -115
  66. package/dist/workerd/core/PrimitiveMethods.d.mts +0 -70
  67. package/dist/workerd/decorators/legacy/Envapt.d.mts +0 -218
  68. package/dist/workerd/decorators/legacy/SugarDecorators.d.mts +0 -40
  69. package/dist/workerd/decorators/modern/Envapt.d.mts +0 -218
  70. package/dist/workerd/decorators/modern/SugarDecorators.d.mts +0 -40
  71. package/dist/workerd/engine/Envapter.d.mts +0 -70
  72. package/dist/workerd/engine/TemplateResolver.d.mts +0 -17
  73. package/dist/workerd/index.d.mts +0 -18
  74. package/dist/workerd/infra/Debug.d.mts +0 -13
  75. package/dist/workerd/infra/Dotenv.d.mts +0 -17
  76. package/dist/workerd/infra/Error.d.mts +0 -72
  77. package/dist/workerd/infra/StandardSchema.d.mts +0 -59
  78. package/dist/workerd/legacy.d.mts +0 -4
  79. package/dist/workerd/sources/ManualEnvSource.d.mts +0 -19
  80. package/dist/workerd/sources/WorkerEnvSource.d.mts +0 -19
  81. package/dist/workerd/types/Conversion.d.mts +0 -123
  82. package/dist/workerd/types/Decorator.d.mts +0 -26
  83. package/dist/workerd/types/Env.d.mts +0 -17
  84. package/dist/workerd/types/Options.d.mts +0 -39
  85. package/dist/workerd/types/Schema.d.mts +0 -12
  86. package/dist/workerd/types/Source.d.mts +0 -44
  87. /package/dist/{node/config.d.cts → types/config.d.mts} +0 -0
  88. /package/dist/{browser → types}/converters/Converters.d.mts +0 -0
  89. /package/dist/{browser → types}/converters/ValueConverter.d.mts +0 -0
  90. /package/dist/{browser → types}/core/AdvancedMethods.d.mts +0 -0
  91. /package/dist/{browser → types}/core/EnvapterBase.d.mts +0 -0
  92. /package/dist/{browser → types}/core/EnvironmentMethods.d.mts +0 -0
  93. /package/dist/{browser → types}/core/PrimitiveMethods.d.mts +0 -0
  94. /package/dist/{browser → types}/decorators/legacy/Envapt.d.mts +0 -0
  95. /package/dist/{browser → types}/decorators/legacy/SugarDecorators.d.mts +0 -0
  96. /package/dist/{browser → types}/decorators/modern/Envapt.d.mts +0 -0
  97. /package/dist/{browser → types}/decorators/modern/SugarDecorators.d.mts +0 -0
  98. /package/dist/{browser → types}/engine/Envapter.d.mts +0 -0
  99. /package/dist/{browser → types}/engine/TemplateResolver.d.mts +0 -0
  100. /package/dist/{browser/index.d.mts → types/index.portable.d.mts} +0 -0
  101. /package/dist/{browser → types}/infra/Debug.d.mts +0 -0
  102. /package/dist/{browser → types}/infra/Dotenv.d.mts +0 -0
  103. /package/dist/{browser → types}/infra/Error.d.mts +0 -0
  104. /package/dist/{browser → types}/infra/StandardSchema.d.mts +0 -0
  105. /package/dist/{browser → types}/legacy.d.mts +0 -0
  106. /package/dist/{browser → types}/sources/ManualEnvSource.d.mts +0 -0
  107. /package/dist/{browser → types}/sources/WorkerEnvSource.d.mts +0 -0
  108. /package/dist/{browser → types}/types/Conversion.d.mts +0 -0
  109. /package/dist/{browser → types}/types/Decorator.d.mts +0 -0
  110. /package/dist/{browser → types}/types/Env.d.mts +0 -0
  111. /package/dist/{browser → types}/types/Options.d.mts +0 -0
  112. /package/dist/{browser → types}/types/Schema.d.mts +0 -0
  113. /package/dist/{browser → types}/types/Source.d.mts +0 -0
@@ -1,28 +0,0 @@
1
- import __tsdown_shims_path from 'node:path';
2
- import __tsdown_shims_url from 'node:url';
3
- //#region src/types/Decorator.d.ts
4
- /**
5
- * A legacy (experimentalDecorators) property decorator that also constrains the decorated field's
6
- * declared type. `Output` is the value the decorator produces. The field must be wide enough to hold
7
- * it, so a field narrower than `Output` fails to compile while a wider or nullable field is accepted.
8
- * The tuple wrap stops `Output` from distributing when it is a union.
9
- * @public
10
- */
11
- type EnvaptFieldDecorator<Output> = <Target, Key extends keyof Target>(target: Target, key: [Output] extends [Target[Key]] ? Key : {
12
- '[envapt] field type must hold the converter output': Output;
13
- }) => void;
14
- /**
15
- * A modern (TC39 Stage 3) accessor decorator that also constrains the decorated `accessor`'s
16
- * declared type. `Output` is the value the decorator produces. The accessor must be wide enough to
17
- * hold it, so an accessor narrower than `Output` fails to compile while a wider or nullable one is
18
- * accepted. The tuple wrap stops `Output` from distributing when it is a union.
19
- * @public
20
- */
21
- type EnvaptAccessorDecorator<Output> = <This, Value>(target: ClassAccessorDecoratorTarget<This, [Output] extends [Value] ? Value : {
22
- '[envapt] field type must hold the converter output': Output;
23
- }>, context: ClassAccessorDecoratorContext<This, [Output] extends [Value] ? Value : {
24
- '[envapt] field type must hold the converter output': Output;
25
- }>) => ClassAccessorDecoratorResult<This, Value>;
26
- //#endregion
27
- export { EnvaptAccessorDecorator, EnvaptFieldDecorator };
28
- //# sourceMappingURL=Decorator.d.mts.map
@@ -1,17 +0,0 @@
1
- //#region src/types/Env.d.ts
2
- /**
3
- * Accepted shape for environment variable lookups. Either a single key or an ordered list of keys.
4
- * @public
5
- */
6
- type EnvKeyInput = string | readonly [string, ...string[]];
7
- /**
8
- * @internal
9
- */
10
- interface EnvapterService {
11
- getRaw(key: EnvKeyInput): string | undefined;
12
- get(key: EnvKeyInput, def?: string): string | undefined;
13
- isStrict(): boolean;
14
- }
15
- //#endregion
16
- export type { EnvKeyInput, EnvapterService };
17
- //# sourceMappingURL=Env.d.cts.map
@@ -1,19 +0,0 @@
1
- import __tsdown_shims_path from 'node:path';
2
- import __tsdown_shims_url from 'node:url';
3
- //#region src/types/Env.d.ts
4
- /**
5
- * Accepted shape for environment variable lookups. Either a single key or an ordered list of keys.
6
- * @public
7
- */
8
- type EnvKeyInput = string | readonly [string, ...string[]];
9
- /**
10
- * @internal
11
- */
12
- interface EnvapterService {
13
- getRaw(key: EnvKeyInput): string | undefined;
14
- get(key: EnvKeyInput, def?: string): string | undefined;
15
- isStrict(): boolean;
16
- }
17
- //#endregion
18
- export type { EnvKeyInput, EnvapterService };
19
- //# sourceMappingURL=Env.d.mts.map
@@ -1,39 +0,0 @@
1
- import { EnvaptConverter } from "./Conversion.cjs";
2
- import { Environment } from "../core/EnvironmentMethods.cjs";
3
-
4
- //#region src/types/Options.d.ts
5
- /**
6
- * Options for the \@Envapt decorator (modern API). `required: true` is mutually exclusive
7
- * with `fallback`; see the per-converter overloads in `Envapt.ts` for the type-level mutex.
8
- * @public
9
- */
10
- interface EnvaptOptions<TFallback = string> {
11
- fallback?: TFallback;
12
- converter?: EnvaptConverter<TFallback>;
13
- required?: boolean;
14
- }
15
- /**
16
- * Per-environment profile entry passed to `Envapter.configureProfiles`.
17
- * @public
18
- */
19
- interface EnvProfile {
20
- /** One or more `.env` paths to load for this environment. Order matters: earlier paths take precedence. */
21
- paths: string | string[];
22
- }
23
- /**
24
- * Configuration object for `Envapter.configureProfiles`. Maps each `Environment` to an optional
25
- * profile override. Unspecified environments fall through to the default cascade behavior
26
- * (`.env.${env}.local`, `.env.local`, `.env.${env}`, `.env`).
27
- * @public
28
- */
29
- type ProfilesConfig = Partial<Record<Environment, EnvProfile>> & {
30
- /**
31
- * When `false`, disables the default dotenv-flow cascade entirely. Only the explicitly
32
- * configured paths are loaded. Defaults to `true` (cascade still runs, configured paths
33
- * are layered on top with higher precedence).
34
- */
35
- useDefaults?: boolean;
36
- };
37
- //#endregion
38
- export type { EnvProfile, EnvaptOptions, ProfilesConfig };
39
- //# sourceMappingURL=Options.d.cts.map
@@ -1,41 +0,0 @@
1
- import __tsdown_shims_path from 'node:path';
2
- import __tsdown_shims_url from 'node:url';
3
- import { EnvaptConverter } from "./Conversion.mjs";
4
- import { Environment } from "../core/EnvironmentMethods.mjs";
5
-
6
- //#region src/types/Options.d.ts
7
- /**
8
- * Options for the \@Envapt decorator (modern API). `required: true` is mutually exclusive
9
- * with `fallback`; see the per-converter overloads in `Envapt.ts` for the type-level mutex.
10
- * @public
11
- */
12
- interface EnvaptOptions<TFallback = string> {
13
- fallback?: TFallback;
14
- converter?: EnvaptConverter<TFallback>;
15
- required?: boolean;
16
- }
17
- /**
18
- * Per-environment profile entry passed to `Envapter.configureProfiles`.
19
- * @public
20
- */
21
- interface EnvProfile {
22
- /** One or more `.env` paths to load for this environment. Order matters: earlier paths take precedence. */
23
- paths: string | string[];
24
- }
25
- /**
26
- * Configuration object for `Envapter.configureProfiles`. Maps each `Environment` to an optional
27
- * profile override. Unspecified environments fall through to the default cascade behavior
28
- * (`.env.${env}.local`, `.env.local`, `.env.${env}`, `.env`).
29
- * @public
30
- */
31
- type ProfilesConfig = Partial<Record<Environment, EnvProfile>> & {
32
- /**
33
- * When `false`, disables the default dotenv-flow cascade entirely. Only the explicitly
34
- * configured paths are loaded. Defaults to `true` (cascade still runs, configured paths
35
- * are layered on top with higher precedence).
36
- */
37
- useDefaults?: boolean;
38
- };
39
- //#endregion
40
- export type { EnvProfile, EnvaptOptions, ProfilesConfig };
41
- //# sourceMappingURL=Options.d.mts.map
@@ -1,12 +0,0 @@
1
- import { StandardSchemaV1 } from "../infra/StandardSchema.cjs";
2
-
3
- //#region src/types/Schema.d.ts
4
- declare const _envaptErrBrand: unique symbol;
5
- type Err<Msg extends string> = Msg & {
6
- readonly [_envaptErrBrand]: never;
7
- };
8
- type SchemaMustBeSync = Err<'Schema must be synchronous. envapt is boot-time config loading; async refinements (validate returning `Promise<Result>`) belong outside the env layer.'>;
9
- type SchemaConstraint<Schema extends StandardSchemaV1> = ReturnType<Schema['~standard']['validate']> extends Promise<unknown> ? SchemaMustBeSync : Schema;
10
- //#endregion
11
- export type { Err, SchemaConstraint, SchemaMustBeSync };
12
- //# sourceMappingURL=Schema.d.cts.map
@@ -1,14 +0,0 @@
1
- import __tsdown_shims_path from 'node:path';
2
- import __tsdown_shims_url from 'node:url';
3
- import { StandardSchemaV1 } from "../infra/StandardSchema.mjs";
4
-
5
- //#region src/types/Schema.d.ts
6
- declare const _envaptErrBrand: unique symbol;
7
- type Err<Msg extends string> = Msg & {
8
- readonly [_envaptErrBrand]: never;
9
- };
10
- type SchemaMustBeSync = Err<'Schema must be synchronous. envapt is boot-time config loading; async refinements (validate returning `Promise<Result>`) belong outside the env layer.'>;
11
- type SchemaConstraint<Schema extends StandardSchemaV1> = ReturnType<Schema['~standard']['validate']> extends Promise<unknown> ? SchemaMustBeSync : Schema;
12
- //#endregion
13
- export type { Err, SchemaConstraint, SchemaMustBeSync };
14
- //# sourceMappingURL=Schema.d.mts.map
@@ -1,44 +0,0 @@
1
- //#region src/types/Source.d.ts
2
- /**
3
- * A source with no filesystem: an injected object on the browser, or the Cloudflare `env` binding on
4
- * Workers. The `.env` cascade, profiles, and the `envPaths`/`baseDir`/`configureProfiles` APIs do not
5
- * apply; only `readVars()` populates the cache.
6
- * @public
7
- */
8
- interface BareEnvSource {
9
- /** Return every variable this source provides, as plain strings. */
10
- readVars(): Record<string, string>;
11
- /** Leave unset (or `false`); a bare source has no filesystem. */
12
- readonly supportsFiles?: false;
13
- }
14
- /**
15
- * A filesystem-backed source, like the default {@link NodeEnvSource}. Setting `supportsFiles` to
16
- * `true` requires all four file capabilities, so the engine can load the `.env` cascade, resolve
17
- * `baseDir`, and mirror loaded keys back to the ambient environment.
18
- * @public
19
- */
20
- interface FileEnvSource {
21
- /** Return every variable this source provides, as plain strings. */
22
- readVars(): Record<string, string>;
23
- /** When `true`, the engine loads the `.env` cascade, profiles, and `envPaths` through the methods below. */
24
- readonly supportsFiles: true;
25
- /** Read a file's text, or `undefined` when it is absent or unreadable. Backs the loader and existence checks. */
26
- readFile(path: string, encoding: string): string | undefined;
27
- /** Join a relative `.env` path onto `baseDir`; absolute paths are returned unchanged. */
28
- resolvePath(baseDir: string, candidate: string): string;
29
- /** Normalize a `baseDir` value (a directory path, or a module / `file:` URL) to an absolute directory path. */
30
- normalizeBaseDir(value: string | URL): string;
31
- /** Mirror loaded keys back to the ambient environment (e.g. `process.env`); backs `Envapter.syncProcessEnv`. */
32
- writeVars(vars: Record<string, string>): void;
33
- }
34
- /**
35
- * A pluggable source of environment variables. The default {@link NodeEnvSource} (a
36
- * {@link FileEnvSource}) reads `process.env` plus the `.env` cascade; a {@link BareEnvSource} lets the
37
- * same engine run where there is no ambient environment (an injected object on the browser, the
38
- * Cloudflare `env` binding on Workers). Bind one with `Envapter.useSource`.
39
- * @public
40
- */
41
- type EnvSource = BareEnvSource | FileEnvSource;
42
- //#endregion
43
- export type { BareEnvSource, EnvSource, FileEnvSource };
44
- //# sourceMappingURL=Source.d.cts.map
@@ -1,46 +0,0 @@
1
- import __tsdown_shims_path from 'node:path';
2
- import __tsdown_shims_url from 'node:url';
3
- //#region src/types/Source.d.ts
4
- /**
5
- * A source with no filesystem: an injected object on the browser, or the Cloudflare `env` binding on
6
- * Workers. The `.env` cascade, profiles, and the `envPaths`/`baseDir`/`configureProfiles` APIs do not
7
- * apply; only `readVars()` populates the cache.
8
- * @public
9
- */
10
- interface BareEnvSource {
11
- /** Return every variable this source provides, as plain strings. */
12
- readVars(): Record<string, string>;
13
- /** Leave unset (or `false`); a bare source has no filesystem. */
14
- readonly supportsFiles?: false;
15
- }
16
- /**
17
- * A filesystem-backed source, like the default {@link NodeEnvSource}. Setting `supportsFiles` to
18
- * `true` requires all four file capabilities, so the engine can load the `.env` cascade, resolve
19
- * `baseDir`, and mirror loaded keys back to the ambient environment.
20
- * @public
21
- */
22
- interface FileEnvSource {
23
- /** Return every variable this source provides, as plain strings. */
24
- readVars(): Record<string, string>;
25
- /** When `true`, the engine loads the `.env` cascade, profiles, and `envPaths` through the methods below. */
26
- readonly supportsFiles: true;
27
- /** Read a file's text, or `undefined` when it is absent or unreadable. Backs the loader and existence checks. */
28
- readFile(path: string, encoding: string): string | undefined;
29
- /** Join a relative `.env` path onto `baseDir`; absolute paths are returned unchanged. */
30
- resolvePath(baseDir: string, candidate: string): string;
31
- /** Normalize a `baseDir` value (a directory path, or a module / `file:` URL) to an absolute directory path. */
32
- normalizeBaseDir(value: string | URL): string;
33
- /** Mirror loaded keys back to the ambient environment (e.g. `process.env`); backs `Envapter.syncProcessEnv`. */
34
- writeVars(vars: Record<string, string>): void;
35
- }
36
- /**
37
- * A pluggable source of environment variables. The default {@link NodeEnvSource} (a
38
- * {@link FileEnvSource}) reads `process.env` plus the `.env` cascade; a {@link BareEnvSource} lets the
39
- * same engine run where there is no ambient environment (an injected object on the browser, the
40
- * Cloudflare `env` binding on Workers). Bind one with `Envapter.useSource`.
41
- * @public
42
- */
43
- type EnvSource = BareEnvSource | FileEnvSource;
44
- //#endregion
45
- export type { BareEnvSource, EnvSource, FileEnvSource };
46
- //# sourceMappingURL=Source.d.mts.map
@@ -1,93 +0,0 @@
1
- //#region src/converters/Converters.d.ts
2
- declare const SCALAR: {
3
- readonly String: "string";
4
- readonly Number: "number";
5
- readonly Boolean: "boolean";
6
- readonly Bigint: "bigint";
7
- readonly Symbol: "symbol";
8
- readonly Integer: "integer";
9
- readonly Float: "float";
10
- readonly Json: "json";
11
- readonly Url: "url";
12
- readonly Regexp: "regexp";
13
- readonly Date: "date";
14
- readonly Time: "time";
15
- };
16
- /**
17
- * String tokens for every built-in scalar converter.
18
- * @public
19
- */
20
- type ConverterToken = (typeof SCALAR)[keyof typeof SCALAR];
21
- /**
22
- * Custom element converter for use inside {@link Converters.array}. Receives the trimmed,
23
- * non-empty raw string for one array slot and returns the parsed value.
24
- * @public
25
- */
26
- type CustomElementConverter<TReturn = unknown> = (raw: string) => TReturn;
27
- /**
28
- * Valid element converters for {@link Converters.array}: any scalar token except
29
- * `json` and `regexp` (those don't compose as array elements), or a custom function.
30
- * @public
31
- */
32
- type ArrayElement = Exclude<ConverterToken, 'json' | 'regexp'> | CustomElementConverter;
33
- /**
34
- * Phantom-branded token produced by {@link Converters.array}. The `T` type parameter carries
35
- * the element converter through any variable indirection so inference survives. The
36
- * `__envaptKind` discriminant is present at runtime for dispatch.
37
- * @public
38
- */
39
- interface ArrayOf<TElement extends ArrayElement = ArrayElement> {
40
- readonly __envaptKind: 'array';
41
- readonly of: TElement;
42
- readonly delimiter: string;
43
- }
44
- /**
45
- * Runtime type guard for tokens produced by {@link Converters.array}.
46
- * @internal
47
- */
48
- declare function isArrayOf(value: unknown): value is ArrayOf;
49
- type ArrayScalarElement = Exclude<ConverterToken, 'json' | 'regexp'>;
50
- declare function buildArrayConverter<TReturn>(opts: {
51
- of: CustomElementConverter<TReturn>;
52
- delimiter?: string;
53
- }): ArrayOf<CustomElementConverter<TReturn>>;
54
- declare function buildArrayConverter<TToken extends ArrayScalarElement>(opts: {
55
- of: TToken;
56
- delimiter?: string;
57
- }): ArrayOf<TToken>;
58
- declare function buildArrayConverter(opts?: {
59
- delimiter?: string;
60
- }): ArrayOf<'string'>;
61
- /**
62
- * Built-in converters for environment variables. Use the scalar tokens (e.g. `Converters.Number`)
63
- * for primitive types and the {@link Converters.array} builder for delimited lists.
64
- *
65
- * @example
66
- * ```ts
67
- * \@Envapt('PORT', { converter: Converters.Number, fallback: 3000 })
68
- * static readonly port: number;
69
- *
70
- * \@Envapt('TAGS', { converter: Converters.array({ of: Converters.String, delimiter: ' ' }) })
71
- * static readonly tags: string[];
72
- * ```
73
- *
74
- * @public
75
- */
76
- declare const Converters: {
77
- readonly array: typeof buildArrayConverter;
78
- readonly String: "string";
79
- readonly Number: "number";
80
- readonly Boolean: "boolean";
81
- readonly Bigint: "bigint";
82
- readonly Symbol: "symbol";
83
- readonly Integer: "integer";
84
- readonly Float: "float";
85
- readonly Json: "json";
86
- readonly Url: "url";
87
- readonly Regexp: "regexp";
88
- readonly Date: "date";
89
- readonly Time: "time";
90
- };
91
- //#endregion
92
- export { ArrayElement, ArrayOf, ConverterToken, Converters, CustomElementConverter, isArrayOf };
93
- //# sourceMappingURL=Converters.d.mts.map
@@ -1,25 +0,0 @@
1
- import { EnvaptConverter } from "../types/Conversion.mjs";
2
- import { StandardSchemaV1 } from "../infra/StandardSchema.mjs";
3
- import { EnvKeyInput, EnvapterService } from "../types/Env.mjs";
4
-
5
- //#region src/converters/ValueConverter.d.ts
6
- /**
7
- * Convert a resolved environment value to its declared type via built-in, primitive, array,
8
- * custom, or Standard Schema converters.
9
- * @internal
10
- */
11
- declare class ValueConverter {
12
- private readonly envService;
13
- constructor(envService: EnvapterService);
14
- convertValue<TFallback>(key: EnvKeyInput, fallback: TFallback | undefined, converter: EnvaptConverter<TFallback> | undefined, hasFallback: boolean): TFallback | null | undefined;
15
- private processFallbackForConverter;
16
- private convertPrimitiveToString;
17
- private processBuiltInConverter;
18
- private processArrayConverter;
19
- private processCustomConverter;
20
- private resolveConverter;
21
- convertWithSchema(key: EnvKeyInput, schema: StandardSchemaV1, fallback: unknown, hasFallback: boolean): unknown;
22
- }
23
- //#endregion
24
- export { ValueConverter };
25
- //# sourceMappingURL=ValueConverter.d.mts.map
@@ -1,76 +0,0 @@
1
- import { ArrayOf } from "../converters/Converters.mjs";
2
- import { AdvancedConverterReturn, BuiltInConverter, ConditionalReturn, ConverterFunction, InferConverterReturnType, TimeFallback } from "../types/Conversion.mjs";
3
- import { InferSchemaOutput, StandardSchemaV1 } from "../infra/StandardSchema.mjs";
4
- import { SchemaConstraint } from "../types/Schema.mjs";
5
- import { EnvKeyInput } from "../types/Env.mjs";
6
- import { PrimitiveMethods } from "./PrimitiveMethods.mjs";
7
-
8
- //#region src/core/AdvancedMethods.d.ts
9
- interface GetUsingRequiredOptions<TConverter> {
10
- converter: TConverter;
11
- required: true;
12
- }
13
- interface GetWithRequiredOptions<TReturnType> {
14
- converter: ConverterFunction<TReturnType>;
15
- required: true;
16
- }
17
- /**
18
- * Mixin for advanced methods for environment variable conversion using built-in and custom converters
19
- * @internal
20
- */
21
- declare class AdvancedMethods extends PrimitiveMethods {
22
- /**
23
- * Get an environment variable using a built-in converter.
24
- *
25
- * Supports both scalar tokens (e.g. `Converters.Number`) and `ArrayOf<...>` tokens
26
- * produced by `Converters.array(...)`. The key can be a single name or an ordered list;
27
- * the first defined value wins.
28
- */
29
- static getUsing<TFallback extends TimeFallback | undefined = undefined>(key: EnvKeyInput, converter: 'time', fallback?: TFallback): ConditionalReturn<number, TFallback>;
30
- static getUsing<TConverter extends BuiltInConverter | ArrayOf, TFallback = undefined>(key: EnvKeyInput, converter: TConverter, fallback?: TFallback): AdvancedConverterReturn<TConverter, TFallback>;
31
- static getUsing<TReturn>(key: EnvKeyInput, converter: BuiltInConverter | ArrayOf, fallback?: TReturn): TReturn;
32
- static getUsing(key: EnvKeyInput, options: GetUsingRequiredOptions<'time'>): number;
33
- static getUsing<TConverter extends BuiltInConverter | ArrayOf>(key: EnvKeyInput, options: GetUsingRequiredOptions<TConverter>): InferConverterReturnType<TConverter>;
34
- /**
35
- * @see {@link AdvancedMethods.getUsing}
36
- */
37
- getUsing<TFallback extends TimeFallback | undefined = undefined>(key: EnvKeyInput, converter: 'time', fallback?: TFallback): ConditionalReturn<number, TFallback>;
38
- getUsing<TConverter extends BuiltInConverter | ArrayOf, TFallback = undefined>(key: EnvKeyInput, converter: TConverter, fallback?: TFallback): AdvancedConverterReturn<TConverter, TFallback>;
39
- getUsing<TReturn>(key: EnvKeyInput, converter: BuiltInConverter | ArrayOf, fallback?: TReturn): TReturn;
40
- getUsing(key: EnvKeyInput, options: GetUsingRequiredOptions<'time'>): number;
41
- getUsing<TConverter extends BuiltInConverter | ArrayOf>(key: EnvKeyInput, options: GetUsingRequiredOptions<TConverter>): InferConverterReturnType<TConverter>;
42
- /**
43
- * Get an environment variable using a custom converter function.
44
- * Accepts a single key or an ordered list for automatic fallback.
45
- */
46
- static getWith<TReturnType, TFallback extends TReturnType | undefined = undefined>(key: EnvKeyInput, converter: ConverterFunction<TReturnType>, fallback?: TFallback): ConditionalReturn<TReturnType, TFallback>;
47
- static getWith<TReturnType>(key: EnvKeyInput, options: GetWithRequiredOptions<TReturnType>): TReturnType;
48
- /**
49
- * @see {@link AdvancedMethods.getWith}
50
- */
51
- getWith<TReturnType, TFallback extends TReturnType | undefined = undefined>(key: EnvKeyInput, converter: ConverterFunction<TReturnType>, fallback?: TFallback): ConditionalReturn<TReturnType, TFallback>;
52
- getWith<TReturnType>(key: EnvKeyInput, options: GetWithRequiredOptions<TReturnType>): TReturnType;
53
- /**
54
- * Validate an environment variable through a {@link StandardSchemaV1}-conformant schema
55
- * (zod, valibot, arktype, etc). Throws `MissingEnvValue` if the env value is absent and
56
- * no fallback is provided. The fallback, when provided, is returned as-is on missing;
57
- * it does NOT pass through the schema (mirrors custom-converter behavior).
58
- *
59
- * Synchronous schemas only. A Promise-returning `validate` triggers an
60
- * `InvalidUserDefinedConfig` throw at the call site.
61
- *
62
- * @example
63
- * ```ts
64
- * import { z } from 'zod';
65
- * const port = Envapter.parse('PORT', z.coerce.number().min(1024).max(65535), 3000);
66
- * ```
67
- */
68
- static parse<Schema extends StandardSchemaV1>(key: EnvKeyInput, schema: SchemaConstraint<Schema>, fallback?: InferSchemaOutput<Schema>): InferSchemaOutput<Schema>;
69
- /**
70
- * @see {@link AdvancedMethods.parse}
71
- */
72
- parse<Schema extends StandardSchemaV1>(key: EnvKeyInput, schema: SchemaConstraint<Schema>, fallback?: InferSchemaOutput<Schema>): InferSchemaOutput<Schema>;
73
- }
74
- //#endregion
75
- export { AdvancedMethods };
76
- //# sourceMappingURL=AdvancedMethods.d.mts.map
@@ -1,75 +0,0 @@
1
- import { DebugLevel } from "../infra/Debug.mjs";
2
- import { EnvFileOptions } from "../infra/Dotenv.mjs";
3
- import { EnvKeyInput } from "../types/Env.mjs";
4
- import { EnvSource, FileEnvSource } from "../types/Source.mjs";
5
-
6
- //#region src/core/EnvapterBase.d.ts
7
- /** @internal */
8
- declare abstract class EnvapterBase {
9
- protected static _envPaths: string[];
10
- protected static _envPathsExplicitlySet: boolean;
11
- protected static _baseDir: string | undefined;
12
- protected static _userDefinedEnvFileOptions: EnvFileOptions;
13
- protected static _strict: boolean;
14
- protected static _syncProcessEnv: boolean;
15
- protected static _dotenvAddedKeys: Set<string>;
16
- protected static _source: EnvSource;
17
- /**
18
- * Enable or disable strict mode. Default `false`. Setting refreshes the cache so
19
- * previously-cached converted values get re-evaluated under the new rule.
20
- */
21
- static set strict(value: boolean);
22
- static get strict(): boolean;
23
- /**
24
- * Set the debug log level. Defaults to `silent`. When unset, reads `ENVAPT_DEBUG` from the
25
- * bound source on first access; the setter overrides any env-var value. Output goes to stderr
26
- * on Node (the console elsewhere), prefixed with `[envapt]`.
27
- */
28
- static set debug(level: DebugLevel);
29
- static get debug(): DebugLevel;
30
- /**
31
- * Opt-in mirror of dotenv-loaded keys back to `process.env`. Default `false`.
32
- *
33
- * Only keys the loader actually wrote are mirrored, so collision behavior follows
34
- * `envFileOptions.override`: with the default `false`, pre-existing `process.env` values
35
- * are preserved; with `true`, the file value wins in both the cache and the mirror.
36
- *
37
- * Flipping `false → true` mirrors the existing tracked delta immediately (no cache
38
- * refresh). Flipping `true → false` is one-way: previously mirrored keys remain in
39
- * `process.env` until the process exits.
40
- */
41
- static set syncProcessEnv(value: boolean);
42
- static get syncProcessEnv(): boolean;
43
- protected static treatAsMissing(value: string | undefined): boolean;
44
- protected static resolveAgainstBase(candidate: string): string;
45
- protected static assertFileApiSupported(api: string, source: EnvSource): asserts source is FileEnvSource;
46
- protected static sourceFileExists(path: string): boolean;
47
- protected static refreshCache(): void;
48
- protected static mirrorToProcessEnv(): void;
49
- protected static resolveEffectivePaths(): string[];
50
- protected static resolveKeyInput(keyInput: EnvKeyInput): {
51
- key: string;
52
- value: string | undefined;
53
- };
54
- protected static get config(): Map<string, unknown>;
55
- /**
56
- * Eagerly load the `.env` cascade now instead of lazily on the first read. Idempotent: a no-op
57
- * once the cache is built. Useful before mirroring to `process.env` (see {@link syncProcessEnv}),
58
- * which is what the `envapt/config` side-effect entry does.
59
- */
60
- static load(): void;
61
- /**
62
- * Bind the environment {@link EnvSource}. On Node the entry binds {@link NodeEnvSource} for you
63
- * (a `process.env` snapshot plus the `.env` cascade); on the browser or Workers, pass a
64
- * `ManualEnvSource` / `WorkerEnvSource` (or any `EnvSource`) before reading. Clears and rebuilds
65
- * the cache.
66
- */
67
- static useSource(source: EnvSource): void;
68
- /**
69
- * Read an environment variable as its raw string, skipping parsing and conversion.
70
- */
71
- getRaw(key: EnvKeyInput): string | undefined;
72
- }
73
- //#endregion
74
- export { EnvapterBase };
75
- //# sourceMappingURL=EnvapterBase.d.mts.map
@@ -1,115 +0,0 @@
1
- import { EnvapterBase } from "./EnvapterBase.mjs";
2
- import { ProfilesConfig } from "../types/Options.mjs";
3
-
4
- //#region src/core/EnvironmentMethods.d.ts
5
- /**
6
- * Environment types supported by Envapter
7
- * @public
8
- */
9
- declare enum Environment {
10
- Development = 0,
11
- Staging = 1,
12
- Production = 2,
13
- Test = 3
14
- }
15
- /**
16
- * Mixin for environment detection and checking methods
17
- * @internal
18
- */
19
- declare class EnvironmentMethods extends EnvapterBase {
20
- protected static _environment: Environment | undefined;
21
- protected static _environmentExplicitlySet: boolean;
22
- protected static _profiles: ProfilesConfig | undefined;
23
- protected static determineEnvironment(env?: string | Environment): void;
24
- private static firstEnvKeyValue;
25
- /**
26
- * Get the current application environment
27
- */
28
- static get environment(): Environment;
29
- /**
30
- * Set the application environment. Accepts either Environment enum or string value.
31
- */
32
- static set environment(env: string | Environment);
33
- /**
34
- * @see {@link EnvironmentMethods.environment}
35
- */
36
- get environment(): Environment;
37
- /**
38
- * @see {@link EnvironmentMethods.environment}
39
- */
40
- set environment(env: string | Environment);
41
- /**
42
- * Check if the current environment is production
43
- */
44
- static get isProduction(): boolean;
45
- /**
46
- * @see {@link EnvironmentMethods.isProduction}
47
- */
48
- get isProduction(): boolean;
49
- /**
50
- * Check if the current environment is staging
51
- */
52
- static get isStaging(): boolean;
53
- /**
54
- * @see {@link EnvironmentMethods.isStaging}
55
- */
56
- get isStaging(): boolean;
57
- /**
58
- * Check if the current environment is development
59
- */
60
- static get isDevelopment(): boolean;
61
- /**
62
- * @see {@link EnvironmentMethods.isDevelopment}
63
- */
64
- get isDevelopment(): boolean;
65
- /**
66
- * Check if the current environment is test
67
- */
68
- static get isTest(): boolean;
69
- /**
70
- * @see {@link EnvironmentMethods.isTest}
71
- */
72
- get isTest(): boolean;
73
- protected static refreshCache(): void;
74
- /**
75
- * Reads the source's raw vars (not `this.config`, which would recurse: cascade selection runs
76
- * before the `.env` load). `Envapter.environment` may differ post-load if a file sets `ENVIRONMENT`.
77
- * @internal
78
- */
79
- protected static getCascadeEnvironment(): Environment;
80
- /**
81
- * Build the dotenv-flow cascade for a given environment, in dotenv first-wins precedence
82
- * order (highest precedence first). Missing files are silently filtered.
83
- *
84
- * Precedence is **most-specific-wins** (matches Vite / Astro / Vocs):
85
- * `.env.${env}.local` \> `.env.${env}` \> `.env.local` \> `.env`
86
- *
87
- * This differs from dotenv-flow / Next.js convention which puts `.env.local` above
88
- * `.env.${env}`. We chose the most-specific-wins order so committed env-specific files
89
- * (`.env.production`) are authoritative for that environment regardless of whether a
90
- * stray `.env.local` is present.
91
- * @internal
92
- */
93
- protected static buildCascadePaths(env: Environment): string[];
94
- private static normalizeProfilePaths;
95
- /**
96
- * Override the base implementation to layer the dotenv-flow cascade + any
97
- * `Envapter.configureProfiles` overrides on top of `_envPaths` when the user has NOT
98
- * explicitly set `envPaths`.
99
- *
100
- * Precedence (passed to dotenv with first-wins semantics):
101
- * 1. profile-configured paths for the current env (if any)
102
- * 2. `.env.${env}.local`
103
- * 3. `.env.${env}`
104
- * 4. `.env.local`
105
- * 5. `.env`
106
- *
107
- * If `useDefaults: false` is set on the profiles config, only (1) is loaded, no cascade.
108
- * If `envPaths` was explicitly set, only `envPaths` is loaded (everything else ignored).
109
- * @internal
110
- */
111
- protected static resolveEffectivePaths(): string[];
112
- }
113
- //#endregion
114
- export { Environment, EnvironmentMethods };
115
- //# sourceMappingURL=EnvironmentMethods.d.mts.map