@e-n-v/env 0.0.1 → 0.0.4
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/README.md +43 -24
- package/dist/BooleanMap-B2eIP3tZ.d.cts +32 -0
- package/dist/BooleanMap-DmFnCA-O.d.ts +32 -0
- package/dist/EnvChannel-LMIRYvT1.d.cts +16 -0
- package/dist/EnvChannel-w27PEm7x.d.ts +16 -0
- package/dist/EnvChannelOptions-BPkWDrmr.d.cts +108 -0
- package/dist/EnvChannelOptions-CRwDLWjd.d.ts +108 -0
- package/dist/EnvModel-CrGclUpJ.d.cts +134 -0
- package/dist/EnvModel-D8rt0EJ6.d.ts +134 -0
- package/dist/EnvSource-BVnmdHku.cjs +420 -0
- package/dist/EnvSource-DA3ZGlES.js +400 -0
- package/dist/ProcessEnvChannel-D465c-dp.d.cts +97 -0
- package/dist/ProcessEnvChannel-Do4-yiLI.d.ts +97 -0
- package/dist/StringEnvVarSchema-B8MT7htU.d.ts +64 -0
- package/dist/StringEnvVarSchema-BF6C0nyT.d.cts +64 -0
- package/dist/channels.cjs +8 -0
- package/dist/channels.d.cts +20 -0
- package/dist/channels.d.ts +20 -0
- package/dist/channels.js +4 -0
- package/dist/chunk-pbleEpgJ.cjs +44 -0
- package/dist/cli.cjs +16 -10
- package/dist/cli.js +7 -2
- package/dist/coerce-DNIuYAx4.js +11028 -0
- package/dist/coerce-b7UVodS9.cjs +12365 -0
- package/dist/core.cjs +68 -0
- package/dist/core.d.cts +6 -0
- package/dist/core.d.ts +6 -0
- package/dist/core.js +40 -0
- package/dist/custom-Bt_wnxIu.js +114 -0
- package/dist/custom-D_Rqjm09.cjs +168 -0
- package/dist/files.cjs +18 -0
- package/dist/files.d.cts +38 -0
- package/dist/files.d.ts +38 -0
- package/dist/files.js +13 -0
- package/dist/index-D8pslhp4.d.cts +170 -0
- package/dist/index-Dq_0aeAL.d.ts +170 -0
- package/dist/model-Dic8IJsf.d.ts +29 -0
- package/dist/model-ft0WhSSS.d.cts +29 -0
- package/dist/model.cjs +14 -0
- package/dist/model.d.cts +35 -0
- package/dist/model.d.ts +35 -0
- package/dist/model.js +9 -0
- package/dist/parse-BT1QSa5e.d.cts +28 -0
- package/dist/parse-DwtLpVhC.d.ts +28 -0
- package/dist/parse.cjs +17 -0
- package/dist/parse.d.cts +52 -0
- package/dist/parse.d.ts +52 -0
- package/dist/parse.js +10 -0
- package/dist/prompt-C5WudV9x.d.cts +74 -0
- package/dist/prompt-yKdccbtZ.d.ts +74 -0
- package/dist/prompt.cjs +24 -0
- package/dist/prompt.d.cts +17 -0
- package/dist/prompt.d.ts +17 -0
- package/dist/prompt.js +12 -0
- package/dist/redis-CJOpRPjc.js +395 -0
- package/dist/redis-EcC7TX3K.cjs +611 -0
- package/dist/resolveChannel-CjAuxy3p.cjs +257 -0
- package/dist/resolveChannel-v9BDsw-M.js +224 -0
- package/dist/root.cjs +36 -0
- package/dist/root.d.cts +21 -0
- package/dist/root.d.ts +21 -0
- package/dist/root.js +21 -0
- package/dist/schema-DH4GiW9A.d.cts +18 -0
- package/dist/schema-jN4EtvEP.d.ts +18 -0
- package/dist/schemas/zod.cjs +629 -0
- package/dist/schemas/zod.d.cts +239 -0
- package/dist/schemas/zod.d.ts +239 -0
- package/dist/schemas/zod.js +550 -0
- package/dist/schemas.cjs +133 -0
- package/dist/schemas.d.cts +3 -0
- package/dist/schemas.d.ts +3 -0
- package/dist/schemas.js +6 -0
- package/dist/src-B7FG1rak.js +638 -0
- package/dist/src-BBwjK5SK.js +127 -0
- package/dist/src-CLTURaoo.js +311 -0
- package/dist/src-CVdUqK3q.js +850 -0
- package/dist/src-Cjo2XA4n.cjs +138 -0
- package/dist/{src-oetJm-nZ.cjs → src-DWYoqPX1.cjs} +31 -1964
- package/dist/src-DZmpNGrQ.cjs +1411 -0
- package/dist/{src-RlCvrI0s.js → src-Dtv7TlJx.js} +14 -1726
- package/dist/src-XjL5cyPG.cjs +873 -0
- package/dist/src-meUnCASg.cjs +413 -0
- package/dist/validate-BxA3a-ns.d.cts +203 -0
- package/dist/validate-CyxrRacF.d.ts +203 -0
- package/dist/vars-BNVI6k89.d.ts +21 -0
- package/dist/vars-CYOaskkK.cjs +27 -0
- package/dist/vars-CptZRPX5.d.cts +21 -0
- package/dist/vars-DOW0LiiN.js +22 -0
- package/dist/vars.cjs +138 -0
- package/dist/vars.d.cts +7 -0
- package/dist/vars.d.ts +7 -0
- package/dist/vars.js +9 -0
- package/package.json +59 -9
- package/assets/demo.gif +0 -0
- package/assets/env-logo.png +0 -0
- package/dist/bundle.cjs +0 -1290
- package/dist/bundle.d.cts +0 -1057
- package/dist/bundle.d.ts +0 -1055
- package/dist/bundle.js +0 -1244
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { r as resolvePreprocessor } from "./src-CLTURaoo.js";
|
|
2
|
+
import { i as resolveSchemas, n as EnvModel } from "./src-CVdUqK3q.js";
|
|
3
|
+
|
|
4
|
+
//#region ../parse/src/errors/EnvParseError.ts
|
|
5
|
+
/**
|
|
6
|
+
* Error thrown when parsing environment variables fails.
|
|
7
|
+
* Collects all issues so callers can inspect them without relying on subclasses.
|
|
8
|
+
*/
|
|
9
|
+
var EnvParseError = class EnvParseError extends Error {
|
|
10
|
+
issues;
|
|
11
|
+
partial;
|
|
12
|
+
constructor(params) {
|
|
13
|
+
const { issues, partial } = params;
|
|
14
|
+
super(EnvParseError.formatMessage(issues));
|
|
15
|
+
this.name = "EnvParseError";
|
|
16
|
+
this.issues = Object.freeze([...issues]);
|
|
17
|
+
this.partial = partial ?? {};
|
|
18
|
+
}
|
|
19
|
+
/** Number of issues encountered while parsing. */
|
|
20
|
+
get issueCount() {
|
|
21
|
+
return this.issues.length;
|
|
22
|
+
}
|
|
23
|
+
/** Keys that were missing but required. */
|
|
24
|
+
get missing() {
|
|
25
|
+
return this.issues.filter((issue) => issue.type === "missing").map((issue) => issue.key);
|
|
26
|
+
}
|
|
27
|
+
/** Keys that were present but invalid. */
|
|
28
|
+
get invalid() {
|
|
29
|
+
return this.issues.filter((issue) => issue.type === "invalid").map((issue) => issue.key);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get all issue messages as a numbered list for easy logging.
|
|
33
|
+
*/
|
|
34
|
+
formatIssues() {
|
|
35
|
+
return this.issues.map((issue, index) => `${index + 1}. ${issue.message}`).join("\n");
|
|
36
|
+
}
|
|
37
|
+
static formatMessage(issues) {
|
|
38
|
+
if (issues.length === 0) return "Environment validation failed with no details.";
|
|
39
|
+
return [`Environment validation failed with ${issues.length} issue${issues.length === 1 ? "" : "s"}:`, ...issues.map((issue) => {
|
|
40
|
+
if (issue.type === "missing") return `- ${issue.key}: ${issue.message}`;
|
|
41
|
+
return `- ${issue.key}: ${issue.message}`;
|
|
42
|
+
})].join("\n");
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region ../parse/src/parse.ts
|
|
48
|
+
/**
|
|
49
|
+
* Parse and validate environment variables from a source object
|
|
50
|
+
* Does NOT mutate process.env
|
|
51
|
+
*/
|
|
52
|
+
function parse(source, modelOrOptions) {
|
|
53
|
+
let resolvedSchemas;
|
|
54
|
+
let preprocessConfig;
|
|
55
|
+
if (modelOrOptions instanceof EnvModel) {
|
|
56
|
+
const model = modelOrOptions;
|
|
57
|
+
resolvedSchemas = model.schemas;
|
|
58
|
+
preprocessConfig = model.preprocess;
|
|
59
|
+
} else {
|
|
60
|
+
const options = modelOrOptions;
|
|
61
|
+
resolvedSchemas = resolveSchemas(options.schemas);
|
|
62
|
+
const config = options.preprocess;
|
|
63
|
+
if (config === false) preprocessConfig = {
|
|
64
|
+
string: false,
|
|
65
|
+
number: false,
|
|
66
|
+
boolean: false,
|
|
67
|
+
enum: false
|
|
68
|
+
};
|
|
69
|
+
else if (config === true || config === void 0) preprocessConfig = {};
|
|
70
|
+
else preprocessConfig = { ...config };
|
|
71
|
+
}
|
|
72
|
+
const result = {};
|
|
73
|
+
const issues = [];
|
|
74
|
+
for (const [key, schema$1] of Object.entries(resolvedSchemas)) {
|
|
75
|
+
const rawValue = source[key];
|
|
76
|
+
if (rawValue === void 0 || rawValue.trim() === "") {
|
|
77
|
+
if (schema$1.default !== void 0) {
|
|
78
|
+
result[key] = schema$1.default;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (schema$1.required) {
|
|
82
|
+
issues.push({
|
|
83
|
+
type: "missing",
|
|
84
|
+
key,
|
|
85
|
+
message: `Required environment variable "${key}" is missing`
|
|
86
|
+
});
|
|
87
|
+
result[key] = void 0;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
result[key] = void 0;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const preprocessor = resolvePreprocessor(schema$1.type, preprocessConfig);
|
|
94
|
+
const preprocessedValue = preprocessor ? preprocessor(rawValue) : rawValue;
|
|
95
|
+
const stringValue = typeof preprocessedValue === "string" ? preprocessedValue : String(preprocessedValue);
|
|
96
|
+
try {
|
|
97
|
+
const processedValue = schema$1.process(stringValue);
|
|
98
|
+
if (processedValue === void 0) if (schema$1.default !== void 0) result[key] = schema$1.default;
|
|
99
|
+
else if (schema$1.required) {
|
|
100
|
+
issues.push({
|
|
101
|
+
type: "missing",
|
|
102
|
+
key,
|
|
103
|
+
message: `Required environment variable "${key}" is missing`
|
|
104
|
+
});
|
|
105
|
+
result[key] = void 0;
|
|
106
|
+
} else result[key] = void 0;
|
|
107
|
+
else result[key] = processedValue;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
const message = `Environment variable "${key}" validation failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
110
|
+
issues.push({
|
|
111
|
+
type: "invalid",
|
|
112
|
+
key,
|
|
113
|
+
value: rawValue,
|
|
114
|
+
message
|
|
115
|
+
});
|
|
116
|
+
result[key] = void 0;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (issues.length > 0) throw new EnvParseError({
|
|
120
|
+
issues,
|
|
121
|
+
partial: { ...result }
|
|
122
|
+
});
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
export { EnvParseError as n, parse as t };
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
//#region ../core/src/schemas/EnvVarSchemaBase.ts
|
|
2
|
+
var EnvVarSchemaBase = class {
|
|
3
|
+
required;
|
|
4
|
+
default;
|
|
5
|
+
description;
|
|
6
|
+
process;
|
|
7
|
+
constructor(input) {
|
|
8
|
+
this.required = input?.required ?? true;
|
|
9
|
+
this.default = input?.default;
|
|
10
|
+
this.description = input?.description;
|
|
11
|
+
this.process = input.process;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region ../core/src/processing/helpers/toList.ts
|
|
17
|
+
/**
|
|
18
|
+
* Convert array of items to natural language list.
|
|
19
|
+
* Examples:
|
|
20
|
+
* - [] => ""
|
|
21
|
+
* - ["one"] => "one"
|
|
22
|
+
* - ["one", "two"] => "one and two"
|
|
23
|
+
* - ["one", "two", "three"] => "one, two, and three"
|
|
24
|
+
*/
|
|
25
|
+
function toList(items) {
|
|
26
|
+
if (items.length === 0) return "";
|
|
27
|
+
if (items.length === 1) return items[0];
|
|
28
|
+
if (items.length === 2) return `${items[0]} and ${items[1]}`;
|
|
29
|
+
return `${items.slice(0, -1).join(", ")}, and ${items[items.length - 1]}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region ../core/src/processing/helpers/validate.ts
|
|
34
|
+
/**
|
|
35
|
+
* Run checks and aggregate errors.
|
|
36
|
+
* Throws an error with all validation requirements if any check fails.
|
|
37
|
+
*/
|
|
38
|
+
function validate(value, checks) {
|
|
39
|
+
const allRequirements = checks.map((check) => check(value)).flat();
|
|
40
|
+
if (allRequirements.length > 0) {
|
|
41
|
+
const message = toList(allRequirements);
|
|
42
|
+
throw new Error(`Must be ${message}`);
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region ../core/src/processing/processors/typed/string.ts
|
|
49
|
+
/**
|
|
50
|
+
* String processor with optional validation checks.
|
|
51
|
+
* This is the primary string processor - the base stringProcessor() calls this with no checks.
|
|
52
|
+
*/
|
|
53
|
+
function string$1(...checks) {
|
|
54
|
+
return (input) => {
|
|
55
|
+
if (typeof input !== "string") throw new Error("Value must be a string");
|
|
56
|
+
if (input === "") return;
|
|
57
|
+
if (checks.length > 0) return validate(input, checks);
|
|
58
|
+
return input;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region ../core/src/processing/processors/typed/number.ts
|
|
64
|
+
/**
|
|
65
|
+
* Number processor with optional validation checks.
|
|
66
|
+
* This is the primary number processor - the base numberProcessor() calls this with no checks.
|
|
67
|
+
*/
|
|
68
|
+
function number$1(...checks) {
|
|
69
|
+
return (input) => {
|
|
70
|
+
if (typeof input !== "string") throw new Error("Value must be a string");
|
|
71
|
+
const trimmed = input.trim();
|
|
72
|
+
if (trimmed === "") return;
|
|
73
|
+
const parsed = parseFloat(trimmed);
|
|
74
|
+
if (isNaN(parsed)) throw new Error(`"${input}" is not a valid number`);
|
|
75
|
+
if (checks.length > 0) return validate(parsed, checks);
|
|
76
|
+
return parsed;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region ../core/src/processing/constants/FALSE_STRINGS.ts
|
|
82
|
+
const FALSE_STRINGS = [
|
|
83
|
+
"false",
|
|
84
|
+
"0",
|
|
85
|
+
"no",
|
|
86
|
+
"off"
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region ../core/src/processing/constants/TRUE_STRINGS.ts
|
|
91
|
+
const TRUE_STRINGS = [
|
|
92
|
+
"true",
|
|
93
|
+
"1",
|
|
94
|
+
"yes",
|
|
95
|
+
"on"
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region ../core/src/processing/processors/typed/boolean.ts
|
|
100
|
+
/**
|
|
101
|
+
* Boolean processor.
|
|
102
|
+
* This is the primary boolean processor - the base booleanProcessor() calls this.
|
|
103
|
+
*/
|
|
104
|
+
function boolean$1() {
|
|
105
|
+
const trueValues = new Set(TRUE_STRINGS);
|
|
106
|
+
const falseValues = new Set(FALSE_STRINGS);
|
|
107
|
+
return (input) => {
|
|
108
|
+
if (typeof input !== "string") throw new Error("Value must be a string");
|
|
109
|
+
const trimmed = input.trim().toLowerCase();
|
|
110
|
+
if (trimmed === "") return;
|
|
111
|
+
if (trueValues.has(trimmed)) return true;
|
|
112
|
+
if (falseValues.has(trimmed)) return false;
|
|
113
|
+
const trueList = [...TRUE_STRINGS].join("/");
|
|
114
|
+
const falseList = [...FALSE_STRINGS].join("/");
|
|
115
|
+
throw new Error(`"${input}" is not a valid boolean. Use: ${trueList} or ${falseList}`);
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region ../core/src/processing/processors/typed/enumeration.ts
|
|
121
|
+
/**
|
|
122
|
+
* Enum processor with optional validation checks.
|
|
123
|
+
* This is the primary enum processor - the base enumProcessor() calls this with no checks.
|
|
124
|
+
*/
|
|
125
|
+
function enumeration$1(allowedValues, ...checks) {
|
|
126
|
+
return (input) => {
|
|
127
|
+
if (typeof input !== "string") throw new Error("Value must be a string");
|
|
128
|
+
const trimmed = input.trim();
|
|
129
|
+
if (trimmed === "") return;
|
|
130
|
+
if (!allowedValues.includes(trimmed)) throw new Error(`"${input}" is not a valid option. Must be one of: ${allowedValues.join(", ")}`);
|
|
131
|
+
if (checks.length > 0) return validate(trimmed, checks);
|
|
132
|
+
return trimmed;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region ../core/src/processing/processors/processors.ts
|
|
138
|
+
/**
|
|
139
|
+
* Default processors for environment variable types.
|
|
140
|
+
* Each processor factory returns a function that takes a value and returns T | undefined.
|
|
141
|
+
* Returns undefined for empty/null values, throws descriptive errors for invalid values.
|
|
142
|
+
*/
|
|
143
|
+
const processors = {
|
|
144
|
+
boolean: boolean$1,
|
|
145
|
+
enum: enumeration$1,
|
|
146
|
+
number: number$1,
|
|
147
|
+
string: string$1
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region ../core/src/schemas/typed/BooleanEnvVarSchema.ts
|
|
152
|
+
var BooleanEnvVarSchema = class extends EnvVarSchemaBase {
|
|
153
|
+
type = "boolean";
|
|
154
|
+
constructor(input = {}) {
|
|
155
|
+
super({
|
|
156
|
+
...input,
|
|
157
|
+
process: input.process ?? processors.boolean()
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region ../core/src/schemas/typed/EnumEnvVarSchema.ts
|
|
164
|
+
var EnumEnvVarSchema = class extends EnvVarSchemaBase {
|
|
165
|
+
type = "enum";
|
|
166
|
+
values;
|
|
167
|
+
constructor(input) {
|
|
168
|
+
super({
|
|
169
|
+
...input,
|
|
170
|
+
process: input.process ?? processors.enum(input.values)
|
|
171
|
+
});
|
|
172
|
+
this.values = input.values;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region ../core/src/schemas/typed/NumberEnvVarSchema.ts
|
|
178
|
+
var NumberEnvVarSchema = class extends EnvVarSchemaBase {
|
|
179
|
+
type = "number";
|
|
180
|
+
constructor(input = {}) {
|
|
181
|
+
super({
|
|
182
|
+
...input,
|
|
183
|
+
process: input.process ?? processors.number()
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region ../core/src/schemas/typed/StringEnvVarSchema.ts
|
|
190
|
+
var StringEnvVarSchema = class extends EnvVarSchemaBase {
|
|
191
|
+
type = "string";
|
|
192
|
+
secret;
|
|
193
|
+
constructor(input = {}) {
|
|
194
|
+
super({
|
|
195
|
+
...input,
|
|
196
|
+
process: input.process ?? processors.string()
|
|
197
|
+
});
|
|
198
|
+
this.secret = input.secret;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region ../core/src/schemas/EnvVarSchema.ts
|
|
204
|
+
/**
|
|
205
|
+
* Type guard to check if a value is a EnvVarSchema instance
|
|
206
|
+
*/
|
|
207
|
+
function isEnvVarSchema(value) {
|
|
208
|
+
return value instanceof StringEnvVarSchema || value instanceof NumberEnvVarSchema || value instanceof BooleanEnvVarSchema || value instanceof EnumEnvVarSchema;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region ../core/src/processing/preprocessors/typed/number.ts
|
|
213
|
+
/**
|
|
214
|
+
* Create a number preprocessor that strips commas and whitespace
|
|
215
|
+
*/
|
|
216
|
+
const number = () => (value) => {
|
|
217
|
+
try {
|
|
218
|
+
const cleaned = value.replace(/,/g, "").trim();
|
|
219
|
+
if (/^-?\d*\.?\d+$/.test(cleaned)) return cleaned;
|
|
220
|
+
} catch {}
|
|
221
|
+
return value;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region ../core/src/processing/preprocessors/typed/boolean.ts
|
|
226
|
+
const boolean = (options = {
|
|
227
|
+
true: TRUE_STRINGS,
|
|
228
|
+
false: FALSE_STRINGS
|
|
229
|
+
}) => {
|
|
230
|
+
const normalize = (candidate) => candidate.toLowerCase().trim();
|
|
231
|
+
const trueValues = new Set(options.true.map(normalize));
|
|
232
|
+
const falseValues = new Set(options.false.map(normalize));
|
|
233
|
+
for (const candidate of trueValues) if (falseValues.has(candidate)) throw new Error(`Boolean preprocessor option value "${candidate}" cannot map to both true and false`);
|
|
234
|
+
return (value) => {
|
|
235
|
+
try {
|
|
236
|
+
const cleaned = normalize(value);
|
|
237
|
+
if (trueValues.has(cleaned)) return true;
|
|
238
|
+
if (falseValues.has(cleaned)) return false;
|
|
239
|
+
} catch {}
|
|
240
|
+
return value;
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region ../core/src/processing/preprocessors/typed/enumeration.ts
|
|
246
|
+
/**
|
|
247
|
+
* Create an enum preprocessor - pass through unchanged
|
|
248
|
+
*/
|
|
249
|
+
const enumeration = () => (value) => value;
|
|
250
|
+
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region ../core/src/processing/preprocessors/typed/string.ts
|
|
253
|
+
/**
|
|
254
|
+
* Create a string preprocessor - pass through unchanged
|
|
255
|
+
*/
|
|
256
|
+
const string = () => (value) => value;
|
|
257
|
+
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region ../core/src/processing/preprocessors/preprocessors.ts
|
|
260
|
+
/**
|
|
261
|
+
* Default preprocessors map for each environment variable type
|
|
262
|
+
*/
|
|
263
|
+
const preprocessors = {
|
|
264
|
+
boolean,
|
|
265
|
+
enum: enumeration,
|
|
266
|
+
number,
|
|
267
|
+
string
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region ../core/src/processing/preprocessors/resolvePreprocessor.ts
|
|
272
|
+
const defaultFactories = {
|
|
273
|
+
number: preprocessors.number,
|
|
274
|
+
boolean: preprocessors.boolean,
|
|
275
|
+
string: void 0,
|
|
276
|
+
enum: void 0
|
|
277
|
+
};
|
|
278
|
+
const explicitFactories = {
|
|
279
|
+
number: preprocessors.number,
|
|
280
|
+
boolean: preprocessors.boolean,
|
|
281
|
+
string: preprocessors.string,
|
|
282
|
+
enum: preprocessors.enum
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* Resolve the effective preprocessor for a given environment variable type.
|
|
286
|
+
* Respects custom overrides and falls back to built-in defaults (number, boolean).
|
|
287
|
+
*/
|
|
288
|
+
function resolvePreprocessor(envVarType, preprocessorOptions) {
|
|
289
|
+
const override = preprocessorOptions?.[envVarType];
|
|
290
|
+
if (override === void 0) {
|
|
291
|
+
const factory = defaultFactories[envVarType];
|
|
292
|
+
return factory ? factory() : void 0;
|
|
293
|
+
}
|
|
294
|
+
if (override === false) return;
|
|
295
|
+
if (override === true) return explicitFactories[envVarType]();
|
|
296
|
+
if (typeof override === "function") return override;
|
|
297
|
+
return preprocessors.boolean(override);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region ../core/src/schemas/schema.ts
|
|
302
|
+
const schema = {
|
|
303
|
+
string: (input = {}) => new StringEnvVarSchema(input),
|
|
304
|
+
number: (input = {}) => new NumberEnvVarSchema(input),
|
|
305
|
+
boolean: (input = {}) => new BooleanEnvVarSchema(input),
|
|
306
|
+
enum: (input) => new EnumEnvVarSchema(input)
|
|
307
|
+
};
|
|
308
|
+
const s = schema;
|
|
309
|
+
|
|
310
|
+
//#endregion
|
|
311
|
+
export { EnvVarSchemaBase as _, isEnvVarSchema as a, EnumEnvVarSchema as c, enumeration$1 as d, boolean$1 as f, toList as g, validate as h, preprocessors as i, BooleanEnvVarSchema as l, string$1 as m, schema as n, StringEnvVarSchema as o, number$1 as p, resolvePreprocessor as r, NumberEnvVarSchema as s, s as t, processors as u };
|