varlock 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -0
- package/bin/cli.js +2 -0
- package/dist/auto-load.d.ts +2 -0
- package/dist/auto-load.js +11 -0
- package/dist/auto-load.js.map +1 -0
- package/dist/chunk-33ROL4J5.js +1013 -0
- package/dist/chunk-33ROL4J5.js.map +1 -0
- package/dist/chunk-35HGPX6I.js +98 -0
- package/dist/chunk-35HGPX6I.js.map +1 -0
- package/dist/chunk-7UQXFWKN.js +82 -0
- package/dist/chunk-7UQXFWKN.js.map +1 -0
- package/dist/chunk-B4UBSMSZ.js +142 -0
- package/dist/chunk-B4UBSMSZ.js.map +1 -0
- package/dist/chunk-BRP5MZU6.js +70 -0
- package/dist/chunk-BRP5MZU6.js.map +1 -0
- package/dist/chunk-BS3AGAHF.js +53 -0
- package/dist/chunk-BS3AGAHF.js.map +1 -0
- package/dist/chunk-CPA2D42B.js +146 -0
- package/dist/chunk-CPA2D42B.js.map +1 -0
- package/dist/chunk-DAZNZPLN.js +675 -0
- package/dist/chunk-DAZNZPLN.js.map +1 -0
- package/dist/chunk-EMPXU5TW.js +681 -0
- package/dist/chunk-EMPXU5TW.js.map +1 -0
- package/dist/chunk-HZADDTO5.js +2310 -0
- package/dist/chunk-HZADDTO5.js.map +1 -0
- package/dist/chunk-LQZ6ICSS.js +21 -0
- package/dist/chunk-LQZ6ICSS.js.map +1 -0
- package/dist/chunk-NZDUC7Q3.js +69 -0
- package/dist/chunk-NZDUC7Q3.js.map +1 -0
- package/dist/chunk-QCC3P7BT.js +39 -0
- package/dist/chunk-QCC3P7BT.js.map +1 -0
- package/dist/chunk-QTYVZQSF.js +225 -0
- package/dist/chunk-QTYVZQSF.js.map +1 -0
- package/dist/chunk-R53MTEAM.js +32 -0
- package/dist/chunk-R53MTEAM.js.map +1 -0
- package/dist/chunk-RCHPHIHX.js +15 -0
- package/dist/chunk-RCHPHIHX.js.map +1 -0
- package/dist/chunk-XN24GZXQ.js +35 -0
- package/dist/chunk-XN24GZXQ.js.map +1 -0
- package/dist/cli/cli-executable.d.ts +2 -0
- package/dist/cli/cli-executable.js +206 -0
- package/dist/cli/cli-executable.js.map +1 -0
- package/dist/doctor.command-N5JAIXRM.js +6 -0
- package/dist/doctor.command-N5JAIXRM.js.map +1 -0
- package/dist/dotenv-compat.d.ts +2 -0
- package/dist/dotenv-compat.js +11 -0
- package/dist/dotenv-compat.js.map +1 -0
- package/dist/en-US-TSGNDI2P.js +22 -0
- package/dist/en-US-TSGNDI2P.js.map +1 -0
- package/dist/encrypt.command-VGJABHNK.js +6 -0
- package/dist/encrypt.command-VGJABHNK.js.map +1 -0
- package/dist/help.command-YZDL2VEQ.js +5 -0
- package/dist/help.command-YZDL2VEQ.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/init.command-7BSALNL5.js +10 -0
- package/dist/init.command-7BSALNL5.js.map +1 -0
- package/dist/ja-JP-UBPCQAAD.js +22 -0
- package/dist/ja-JP-UBPCQAAD.js.map +1 -0
- package/dist/load.command-4MJR5J43.js +9 -0
- package/dist/load.command-4MJR5J43.js.map +1 -0
- package/dist/login.command-22RUZJLR.js +7 -0
- package/dist/login.command-22RUZJLR.js.map +1 -0
- package/dist/opt-out.command-Y4KUQ6PQ.js +5 -0
- package/dist/opt-out.command-Y4KUQ6PQ.js.map +1 -0
- package/dist/run.command-ASKXIWBC.js +9 -0
- package/dist/run.command-ASKXIWBC.js.map +1 -0
- package/package.json +50 -3
- package/notes.md +0 -3
|
@@ -0,0 +1,2310 @@
|
|
|
1
|
+
import { __name } from './chunk-XN24GZXQ.js';
|
|
2
|
+
import { exec } from 'node:child_process';
|
|
3
|
+
import { promisify } from 'node:util';
|
|
4
|
+
import fs from 'node:fs/promises';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { ParsedEnvSpecStaticValue, ParsedEnvSpecFunctionCall, ParsedEnvSpecKeyValuePair, parseEnvSpecDotEnvFile } from '@env-spec/parser';
|
|
7
|
+
import fs2 from 'node:fs';
|
|
8
|
+
|
|
9
|
+
// ../../node_modules/.pnpm/@sindresorhus+is@7.0.1/node_modules/@sindresorhus/is/distribution/index.js
|
|
10
|
+
var typedArrayTypeNames = [
|
|
11
|
+
"Int8Array",
|
|
12
|
+
"Uint8Array",
|
|
13
|
+
"Uint8ClampedArray",
|
|
14
|
+
"Int16Array",
|
|
15
|
+
"Uint16Array",
|
|
16
|
+
"Int32Array",
|
|
17
|
+
"Uint32Array",
|
|
18
|
+
"Float32Array",
|
|
19
|
+
"Float64Array",
|
|
20
|
+
"BigInt64Array",
|
|
21
|
+
"BigUint64Array"
|
|
22
|
+
];
|
|
23
|
+
function isTypedArrayName(name) {
|
|
24
|
+
return typedArrayTypeNames.includes(name);
|
|
25
|
+
}
|
|
26
|
+
__name(isTypedArrayName, "isTypedArrayName");
|
|
27
|
+
var objectTypeNames = [
|
|
28
|
+
"Function",
|
|
29
|
+
"Generator",
|
|
30
|
+
"AsyncGenerator",
|
|
31
|
+
"GeneratorFunction",
|
|
32
|
+
"AsyncGeneratorFunction",
|
|
33
|
+
"AsyncFunction",
|
|
34
|
+
"Observable",
|
|
35
|
+
"Array",
|
|
36
|
+
"Buffer",
|
|
37
|
+
"Blob",
|
|
38
|
+
"Object",
|
|
39
|
+
"RegExp",
|
|
40
|
+
"Date",
|
|
41
|
+
"Error",
|
|
42
|
+
"Map",
|
|
43
|
+
"Set",
|
|
44
|
+
"WeakMap",
|
|
45
|
+
"WeakSet",
|
|
46
|
+
"WeakRef",
|
|
47
|
+
"ArrayBuffer",
|
|
48
|
+
"SharedArrayBuffer",
|
|
49
|
+
"DataView",
|
|
50
|
+
"Promise",
|
|
51
|
+
"URL",
|
|
52
|
+
"FormData",
|
|
53
|
+
"URLSearchParams",
|
|
54
|
+
"HTMLElement",
|
|
55
|
+
"NaN",
|
|
56
|
+
...typedArrayTypeNames
|
|
57
|
+
];
|
|
58
|
+
function isObjectTypeName(name) {
|
|
59
|
+
return objectTypeNames.includes(name);
|
|
60
|
+
}
|
|
61
|
+
__name(isObjectTypeName, "isObjectTypeName");
|
|
62
|
+
var primitiveTypeNames = [
|
|
63
|
+
"null",
|
|
64
|
+
"undefined",
|
|
65
|
+
"string",
|
|
66
|
+
"number",
|
|
67
|
+
"bigint",
|
|
68
|
+
"boolean",
|
|
69
|
+
"symbol"
|
|
70
|
+
];
|
|
71
|
+
function isPrimitiveTypeName(name) {
|
|
72
|
+
return primitiveTypeNames.includes(name);
|
|
73
|
+
}
|
|
74
|
+
__name(isPrimitiveTypeName, "isPrimitiveTypeName");
|
|
75
|
+
var getObjectType = /* @__PURE__ */ __name((value) => {
|
|
76
|
+
const objectTypeName = Object.prototype.toString.call(value).slice(8, -1);
|
|
77
|
+
if (/HTML\w+Element/.test(objectTypeName) && isHtmlElement(value)) {
|
|
78
|
+
return "HTMLElement";
|
|
79
|
+
}
|
|
80
|
+
if (isObjectTypeName(objectTypeName)) {
|
|
81
|
+
return objectTypeName;
|
|
82
|
+
}
|
|
83
|
+
return void 0;
|
|
84
|
+
}, "getObjectType");
|
|
85
|
+
function detect(value) {
|
|
86
|
+
if (value === null) {
|
|
87
|
+
return "null";
|
|
88
|
+
}
|
|
89
|
+
switch (typeof value) {
|
|
90
|
+
case "undefined": {
|
|
91
|
+
return "undefined";
|
|
92
|
+
}
|
|
93
|
+
case "string": {
|
|
94
|
+
return "string";
|
|
95
|
+
}
|
|
96
|
+
case "number": {
|
|
97
|
+
return Number.isNaN(value) ? "NaN" : "number";
|
|
98
|
+
}
|
|
99
|
+
case "boolean": {
|
|
100
|
+
return "boolean";
|
|
101
|
+
}
|
|
102
|
+
case "function": {
|
|
103
|
+
return "Function";
|
|
104
|
+
}
|
|
105
|
+
case "bigint": {
|
|
106
|
+
return "bigint";
|
|
107
|
+
}
|
|
108
|
+
case "symbol": {
|
|
109
|
+
return "symbol";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (isObservable(value)) {
|
|
113
|
+
return "Observable";
|
|
114
|
+
}
|
|
115
|
+
if (isArray(value)) {
|
|
116
|
+
return "Array";
|
|
117
|
+
}
|
|
118
|
+
if (isBuffer(value)) {
|
|
119
|
+
return "Buffer";
|
|
120
|
+
}
|
|
121
|
+
const tagType = getObjectType(value);
|
|
122
|
+
if (tagType) {
|
|
123
|
+
return tagType;
|
|
124
|
+
}
|
|
125
|
+
if (value instanceof String || value instanceof Boolean || value instanceof Number) {
|
|
126
|
+
throw new TypeError("Please don't use object wrappers for primitive types");
|
|
127
|
+
}
|
|
128
|
+
return "Object";
|
|
129
|
+
}
|
|
130
|
+
__name(detect, "detect");
|
|
131
|
+
function hasPromiseApi(value) {
|
|
132
|
+
return isFunction(value?.then) && isFunction(value?.catch);
|
|
133
|
+
}
|
|
134
|
+
__name(hasPromiseApi, "hasPromiseApi");
|
|
135
|
+
Object.assign(detect, {
|
|
136
|
+
all: isAll,
|
|
137
|
+
any: isAny,
|
|
138
|
+
array: isArray,
|
|
139
|
+
arrayBuffer: isArrayBuffer,
|
|
140
|
+
arrayLike: isArrayLike,
|
|
141
|
+
asyncFunction: isAsyncFunction,
|
|
142
|
+
asyncGenerator: isAsyncGenerator,
|
|
143
|
+
asyncGeneratorFunction: isAsyncGeneratorFunction,
|
|
144
|
+
asyncIterable: isAsyncIterable,
|
|
145
|
+
bigint: isBigint,
|
|
146
|
+
bigInt64Array: isBigInt64Array,
|
|
147
|
+
bigUint64Array: isBigUint64Array,
|
|
148
|
+
blob: isBlob,
|
|
149
|
+
boolean: isBoolean,
|
|
150
|
+
boundFunction: isBoundFunction,
|
|
151
|
+
buffer: isBuffer,
|
|
152
|
+
class: isClass,
|
|
153
|
+
dataView: isDataView,
|
|
154
|
+
date: isDate,
|
|
155
|
+
detect,
|
|
156
|
+
directInstanceOf: isDirectInstanceOf,
|
|
157
|
+
emptyArray: isEmptyArray,
|
|
158
|
+
emptyMap: isEmptyMap,
|
|
159
|
+
emptyObject: isEmptyObject,
|
|
160
|
+
emptySet: isEmptySet,
|
|
161
|
+
emptyString: isEmptyString,
|
|
162
|
+
emptyStringOrWhitespace: isEmptyStringOrWhitespace,
|
|
163
|
+
enumCase: isEnumCase,
|
|
164
|
+
error: isError,
|
|
165
|
+
evenInteger: isEvenInteger,
|
|
166
|
+
falsy: isFalsy,
|
|
167
|
+
float32Array: isFloat32Array,
|
|
168
|
+
float64Array: isFloat64Array,
|
|
169
|
+
formData: isFormData,
|
|
170
|
+
function: isFunction,
|
|
171
|
+
generator: isGenerator,
|
|
172
|
+
generatorFunction: isGeneratorFunction,
|
|
173
|
+
htmlElement: isHtmlElement,
|
|
174
|
+
infinite: isInfinite,
|
|
175
|
+
inRange: isInRange,
|
|
176
|
+
int16Array: isInt16Array,
|
|
177
|
+
int32Array: isInt32Array,
|
|
178
|
+
int8Array: isInt8Array,
|
|
179
|
+
integer: isInteger,
|
|
180
|
+
iterable: isIterable,
|
|
181
|
+
map: isMap,
|
|
182
|
+
nan: isNan,
|
|
183
|
+
nativePromise: isNativePromise,
|
|
184
|
+
negativeNumber: isNegativeNumber,
|
|
185
|
+
nodeStream: isNodeStream,
|
|
186
|
+
nonEmptyArray: isNonEmptyArray,
|
|
187
|
+
nonEmptyMap: isNonEmptyMap,
|
|
188
|
+
nonEmptyObject: isNonEmptyObject,
|
|
189
|
+
nonEmptySet: isNonEmptySet,
|
|
190
|
+
nonEmptyString: isNonEmptyString,
|
|
191
|
+
nonEmptyStringAndNotWhitespace: isNonEmptyStringAndNotWhitespace,
|
|
192
|
+
null: isNull,
|
|
193
|
+
nullOrUndefined: isNullOrUndefined,
|
|
194
|
+
number: isNumber,
|
|
195
|
+
numericString: isNumericString,
|
|
196
|
+
object: isObject,
|
|
197
|
+
observable: isObservable,
|
|
198
|
+
oddInteger: isOddInteger,
|
|
199
|
+
plainObject: isPlainObject,
|
|
200
|
+
positiveNumber: isPositiveNumber,
|
|
201
|
+
primitive: isPrimitive,
|
|
202
|
+
promise: isPromise,
|
|
203
|
+
propertyKey: isPropertyKey,
|
|
204
|
+
regExp: isRegExp,
|
|
205
|
+
safeInteger: isSafeInteger,
|
|
206
|
+
set: isSet,
|
|
207
|
+
sharedArrayBuffer: isSharedArrayBuffer,
|
|
208
|
+
string: isString,
|
|
209
|
+
symbol: isSymbol,
|
|
210
|
+
truthy: isTruthy,
|
|
211
|
+
tupleLike: isTupleLike,
|
|
212
|
+
typedArray: isTypedArray,
|
|
213
|
+
uint16Array: isUint16Array,
|
|
214
|
+
uint32Array: isUint32Array,
|
|
215
|
+
uint8Array: isUint8Array,
|
|
216
|
+
uint8ClampedArray: isUint8ClampedArray,
|
|
217
|
+
undefined: isUndefined,
|
|
218
|
+
urlInstance: isUrlInstance,
|
|
219
|
+
urlSearchParams: isUrlSearchParams,
|
|
220
|
+
urlString: isUrlString,
|
|
221
|
+
validDate: isValidDate,
|
|
222
|
+
validLength: isValidLength,
|
|
223
|
+
weakMap: isWeakMap,
|
|
224
|
+
weakRef: isWeakRef,
|
|
225
|
+
weakSet: isWeakSet,
|
|
226
|
+
whitespaceString: isWhitespaceString
|
|
227
|
+
});
|
|
228
|
+
function isAbsoluteModule2(remainder) {
|
|
229
|
+
return (value) => isInteger(value) && Math.abs(value % 2) === remainder;
|
|
230
|
+
}
|
|
231
|
+
__name(isAbsoluteModule2, "isAbsoluteModule2");
|
|
232
|
+
function isAll(predicate, ...values) {
|
|
233
|
+
return predicateOnArray(Array.prototype.every, predicate, values);
|
|
234
|
+
}
|
|
235
|
+
__name(isAll, "isAll");
|
|
236
|
+
function isAny(predicate, ...values) {
|
|
237
|
+
const predicates = isArray(predicate) ? predicate : [predicate];
|
|
238
|
+
return predicates.some((singlePredicate) => predicateOnArray(Array.prototype.some, singlePredicate, values));
|
|
239
|
+
}
|
|
240
|
+
__name(isAny, "isAny");
|
|
241
|
+
function isArray(value, assertion) {
|
|
242
|
+
if (!Array.isArray(value)) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
if (!isFunction(assertion)) {
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
return value.every((element) => assertion(element));
|
|
249
|
+
}
|
|
250
|
+
__name(isArray, "isArray");
|
|
251
|
+
function isArrayBuffer(value) {
|
|
252
|
+
return getObjectType(value) === "ArrayBuffer";
|
|
253
|
+
}
|
|
254
|
+
__name(isArrayBuffer, "isArrayBuffer");
|
|
255
|
+
function isArrayLike(value) {
|
|
256
|
+
return !isNullOrUndefined(value) && !isFunction(value) && isValidLength(value.length);
|
|
257
|
+
}
|
|
258
|
+
__name(isArrayLike, "isArrayLike");
|
|
259
|
+
function isAsyncFunction(value) {
|
|
260
|
+
return getObjectType(value) === "AsyncFunction";
|
|
261
|
+
}
|
|
262
|
+
__name(isAsyncFunction, "isAsyncFunction");
|
|
263
|
+
function isAsyncGenerator(value) {
|
|
264
|
+
return isAsyncIterable(value) && isFunction(value.next) && isFunction(value.throw);
|
|
265
|
+
}
|
|
266
|
+
__name(isAsyncGenerator, "isAsyncGenerator");
|
|
267
|
+
function isAsyncGeneratorFunction(value) {
|
|
268
|
+
return getObjectType(value) === "AsyncGeneratorFunction";
|
|
269
|
+
}
|
|
270
|
+
__name(isAsyncGeneratorFunction, "isAsyncGeneratorFunction");
|
|
271
|
+
function isAsyncIterable(value) {
|
|
272
|
+
return isFunction(value?.[Symbol.asyncIterator]);
|
|
273
|
+
}
|
|
274
|
+
__name(isAsyncIterable, "isAsyncIterable");
|
|
275
|
+
function isBigint(value) {
|
|
276
|
+
return typeof value === "bigint";
|
|
277
|
+
}
|
|
278
|
+
__name(isBigint, "isBigint");
|
|
279
|
+
function isBigInt64Array(value) {
|
|
280
|
+
return getObjectType(value) === "BigInt64Array";
|
|
281
|
+
}
|
|
282
|
+
__name(isBigInt64Array, "isBigInt64Array");
|
|
283
|
+
function isBigUint64Array(value) {
|
|
284
|
+
return getObjectType(value) === "BigUint64Array";
|
|
285
|
+
}
|
|
286
|
+
__name(isBigUint64Array, "isBigUint64Array");
|
|
287
|
+
function isBlob(value) {
|
|
288
|
+
return getObjectType(value) === "Blob";
|
|
289
|
+
}
|
|
290
|
+
__name(isBlob, "isBlob");
|
|
291
|
+
function isBoolean(value) {
|
|
292
|
+
return value === true || value === false;
|
|
293
|
+
}
|
|
294
|
+
__name(isBoolean, "isBoolean");
|
|
295
|
+
function isBoundFunction(value) {
|
|
296
|
+
return isFunction(value) && !Object.hasOwn(value, "prototype");
|
|
297
|
+
}
|
|
298
|
+
__name(isBoundFunction, "isBoundFunction");
|
|
299
|
+
function isBuffer(value) {
|
|
300
|
+
return value?.constructor?.isBuffer?.(value) ?? false;
|
|
301
|
+
}
|
|
302
|
+
__name(isBuffer, "isBuffer");
|
|
303
|
+
function isClass(value) {
|
|
304
|
+
return isFunction(value) && value.toString().startsWith("class ");
|
|
305
|
+
}
|
|
306
|
+
__name(isClass, "isClass");
|
|
307
|
+
function isDataView(value) {
|
|
308
|
+
return getObjectType(value) === "DataView";
|
|
309
|
+
}
|
|
310
|
+
__name(isDataView, "isDataView");
|
|
311
|
+
function isDate(value) {
|
|
312
|
+
return getObjectType(value) === "Date";
|
|
313
|
+
}
|
|
314
|
+
__name(isDate, "isDate");
|
|
315
|
+
function isDirectInstanceOf(instance, class_) {
|
|
316
|
+
if (instance === void 0 || instance === null) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
return Object.getPrototypeOf(instance) === class_.prototype;
|
|
320
|
+
}
|
|
321
|
+
__name(isDirectInstanceOf, "isDirectInstanceOf");
|
|
322
|
+
function isEmptyArray(value) {
|
|
323
|
+
return isArray(value) && value.length === 0;
|
|
324
|
+
}
|
|
325
|
+
__name(isEmptyArray, "isEmptyArray");
|
|
326
|
+
function isEmptyMap(value) {
|
|
327
|
+
return isMap(value) && value.size === 0;
|
|
328
|
+
}
|
|
329
|
+
__name(isEmptyMap, "isEmptyMap");
|
|
330
|
+
function isEmptyObject(value) {
|
|
331
|
+
return isObject(value) && !isMap(value) && !isSet(value) && Object.keys(value).length === 0;
|
|
332
|
+
}
|
|
333
|
+
__name(isEmptyObject, "isEmptyObject");
|
|
334
|
+
function isEmptySet(value) {
|
|
335
|
+
return isSet(value) && value.size === 0;
|
|
336
|
+
}
|
|
337
|
+
__name(isEmptySet, "isEmptySet");
|
|
338
|
+
function isEmptyString(value) {
|
|
339
|
+
return isString(value) && value.length === 0;
|
|
340
|
+
}
|
|
341
|
+
__name(isEmptyString, "isEmptyString");
|
|
342
|
+
function isEmptyStringOrWhitespace(value) {
|
|
343
|
+
return isEmptyString(value) || isWhitespaceString(value);
|
|
344
|
+
}
|
|
345
|
+
__name(isEmptyStringOrWhitespace, "isEmptyStringOrWhitespace");
|
|
346
|
+
function isEnumCase(value, targetEnum) {
|
|
347
|
+
return Object.values(targetEnum).includes(value);
|
|
348
|
+
}
|
|
349
|
+
__name(isEnumCase, "isEnumCase");
|
|
350
|
+
function isError(value) {
|
|
351
|
+
return getObjectType(value) === "Error";
|
|
352
|
+
}
|
|
353
|
+
__name(isError, "isError");
|
|
354
|
+
function isEvenInteger(value) {
|
|
355
|
+
return isAbsoluteModule2(0)(value);
|
|
356
|
+
}
|
|
357
|
+
__name(isEvenInteger, "isEvenInteger");
|
|
358
|
+
function isFalsy(value) {
|
|
359
|
+
return !value;
|
|
360
|
+
}
|
|
361
|
+
__name(isFalsy, "isFalsy");
|
|
362
|
+
function isFloat32Array(value) {
|
|
363
|
+
return getObjectType(value) === "Float32Array";
|
|
364
|
+
}
|
|
365
|
+
__name(isFloat32Array, "isFloat32Array");
|
|
366
|
+
function isFloat64Array(value) {
|
|
367
|
+
return getObjectType(value) === "Float64Array";
|
|
368
|
+
}
|
|
369
|
+
__name(isFloat64Array, "isFloat64Array");
|
|
370
|
+
function isFormData(value) {
|
|
371
|
+
return getObjectType(value) === "FormData";
|
|
372
|
+
}
|
|
373
|
+
__name(isFormData, "isFormData");
|
|
374
|
+
function isFunction(value) {
|
|
375
|
+
return typeof value === "function";
|
|
376
|
+
}
|
|
377
|
+
__name(isFunction, "isFunction");
|
|
378
|
+
function isGenerator(value) {
|
|
379
|
+
return isIterable(value) && isFunction(value?.next) && isFunction(value?.throw);
|
|
380
|
+
}
|
|
381
|
+
__name(isGenerator, "isGenerator");
|
|
382
|
+
function isGeneratorFunction(value) {
|
|
383
|
+
return getObjectType(value) === "GeneratorFunction";
|
|
384
|
+
}
|
|
385
|
+
__name(isGeneratorFunction, "isGeneratorFunction");
|
|
386
|
+
var NODE_TYPE_ELEMENT = 1;
|
|
387
|
+
var DOM_PROPERTIES_TO_CHECK = [
|
|
388
|
+
"innerHTML",
|
|
389
|
+
"ownerDocument",
|
|
390
|
+
"style",
|
|
391
|
+
"attributes",
|
|
392
|
+
"nodeValue"
|
|
393
|
+
];
|
|
394
|
+
function isHtmlElement(value) {
|
|
395
|
+
return isObject(value) && value.nodeType === NODE_TYPE_ELEMENT && isString(value.nodeName) && !isPlainObject(value) && DOM_PROPERTIES_TO_CHECK.every((property) => property in value);
|
|
396
|
+
}
|
|
397
|
+
__name(isHtmlElement, "isHtmlElement");
|
|
398
|
+
function isInfinite(value) {
|
|
399
|
+
return value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY;
|
|
400
|
+
}
|
|
401
|
+
__name(isInfinite, "isInfinite");
|
|
402
|
+
function isInRange(value, range) {
|
|
403
|
+
if (isNumber(range)) {
|
|
404
|
+
return value >= Math.min(0, range) && value <= Math.max(range, 0);
|
|
405
|
+
}
|
|
406
|
+
if (isArray(range) && range.length === 2) {
|
|
407
|
+
return value >= Math.min(...range) && value <= Math.max(...range);
|
|
408
|
+
}
|
|
409
|
+
throw new TypeError(`Invalid range: ${JSON.stringify(range)}`);
|
|
410
|
+
}
|
|
411
|
+
__name(isInRange, "isInRange");
|
|
412
|
+
function isInt16Array(value) {
|
|
413
|
+
return getObjectType(value) === "Int16Array";
|
|
414
|
+
}
|
|
415
|
+
__name(isInt16Array, "isInt16Array");
|
|
416
|
+
function isInt32Array(value) {
|
|
417
|
+
return getObjectType(value) === "Int32Array";
|
|
418
|
+
}
|
|
419
|
+
__name(isInt32Array, "isInt32Array");
|
|
420
|
+
function isInt8Array(value) {
|
|
421
|
+
return getObjectType(value) === "Int8Array";
|
|
422
|
+
}
|
|
423
|
+
__name(isInt8Array, "isInt8Array");
|
|
424
|
+
function isInteger(value) {
|
|
425
|
+
return Number.isInteger(value);
|
|
426
|
+
}
|
|
427
|
+
__name(isInteger, "isInteger");
|
|
428
|
+
function isIterable(value) {
|
|
429
|
+
return isFunction(value?.[Symbol.iterator]);
|
|
430
|
+
}
|
|
431
|
+
__name(isIterable, "isIterable");
|
|
432
|
+
function isMap(value) {
|
|
433
|
+
return getObjectType(value) === "Map";
|
|
434
|
+
}
|
|
435
|
+
__name(isMap, "isMap");
|
|
436
|
+
function isNan(value) {
|
|
437
|
+
return Number.isNaN(value);
|
|
438
|
+
}
|
|
439
|
+
__name(isNan, "isNan");
|
|
440
|
+
function isNativePromise(value) {
|
|
441
|
+
return getObjectType(value) === "Promise";
|
|
442
|
+
}
|
|
443
|
+
__name(isNativePromise, "isNativePromise");
|
|
444
|
+
function isNegativeNumber(value) {
|
|
445
|
+
return isNumber(value) && value < 0;
|
|
446
|
+
}
|
|
447
|
+
__name(isNegativeNumber, "isNegativeNumber");
|
|
448
|
+
function isNodeStream(value) {
|
|
449
|
+
return isObject(value) && isFunction(value.pipe) && !isObservable(value);
|
|
450
|
+
}
|
|
451
|
+
__name(isNodeStream, "isNodeStream");
|
|
452
|
+
function isNonEmptyArray(value) {
|
|
453
|
+
return isArray(value) && value.length > 0;
|
|
454
|
+
}
|
|
455
|
+
__name(isNonEmptyArray, "isNonEmptyArray");
|
|
456
|
+
function isNonEmptyMap(value) {
|
|
457
|
+
return isMap(value) && value.size > 0;
|
|
458
|
+
}
|
|
459
|
+
__name(isNonEmptyMap, "isNonEmptyMap");
|
|
460
|
+
function isNonEmptyObject(value) {
|
|
461
|
+
return isObject(value) && !isMap(value) && !isSet(value) && Object.keys(value).length > 0;
|
|
462
|
+
}
|
|
463
|
+
__name(isNonEmptyObject, "isNonEmptyObject");
|
|
464
|
+
function isNonEmptySet(value) {
|
|
465
|
+
return isSet(value) && value.size > 0;
|
|
466
|
+
}
|
|
467
|
+
__name(isNonEmptySet, "isNonEmptySet");
|
|
468
|
+
function isNonEmptyString(value) {
|
|
469
|
+
return isString(value) && value.length > 0;
|
|
470
|
+
}
|
|
471
|
+
__name(isNonEmptyString, "isNonEmptyString");
|
|
472
|
+
function isNonEmptyStringAndNotWhitespace(value) {
|
|
473
|
+
return isString(value) && !isEmptyStringOrWhitespace(value);
|
|
474
|
+
}
|
|
475
|
+
__name(isNonEmptyStringAndNotWhitespace, "isNonEmptyStringAndNotWhitespace");
|
|
476
|
+
function isNull(value) {
|
|
477
|
+
return value === null;
|
|
478
|
+
}
|
|
479
|
+
__name(isNull, "isNull");
|
|
480
|
+
function isNullOrUndefined(value) {
|
|
481
|
+
return isNull(value) || isUndefined(value);
|
|
482
|
+
}
|
|
483
|
+
__name(isNullOrUndefined, "isNullOrUndefined");
|
|
484
|
+
function isNumber(value) {
|
|
485
|
+
return typeof value === "number" && !Number.isNaN(value);
|
|
486
|
+
}
|
|
487
|
+
__name(isNumber, "isNumber");
|
|
488
|
+
function isNumericString(value) {
|
|
489
|
+
return isString(value) && !isEmptyStringOrWhitespace(value) && !Number.isNaN(Number(value));
|
|
490
|
+
}
|
|
491
|
+
__name(isNumericString, "isNumericString");
|
|
492
|
+
function isObject(value) {
|
|
493
|
+
return !isNull(value) && (typeof value === "object" || isFunction(value));
|
|
494
|
+
}
|
|
495
|
+
__name(isObject, "isObject");
|
|
496
|
+
function isObservable(value) {
|
|
497
|
+
if (!value) {
|
|
498
|
+
return false;
|
|
499
|
+
}
|
|
500
|
+
if (value === value[Symbol.observable]?.()) {
|
|
501
|
+
return true;
|
|
502
|
+
}
|
|
503
|
+
if (value === value["@@observable"]?.()) {
|
|
504
|
+
return true;
|
|
505
|
+
}
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
508
|
+
__name(isObservable, "isObservable");
|
|
509
|
+
function isOddInteger(value) {
|
|
510
|
+
return isAbsoluteModule2(1)(value);
|
|
511
|
+
}
|
|
512
|
+
__name(isOddInteger, "isOddInteger");
|
|
513
|
+
function isPlainObject(value) {
|
|
514
|
+
if (typeof value !== "object" || value === null) {
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
const prototype = Object.getPrototypeOf(value);
|
|
518
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
519
|
+
}
|
|
520
|
+
__name(isPlainObject, "isPlainObject");
|
|
521
|
+
function isPositiveNumber(value) {
|
|
522
|
+
return isNumber(value) && value > 0;
|
|
523
|
+
}
|
|
524
|
+
__name(isPositiveNumber, "isPositiveNumber");
|
|
525
|
+
function isPrimitive(value) {
|
|
526
|
+
return isNull(value) || isPrimitiveTypeName(typeof value);
|
|
527
|
+
}
|
|
528
|
+
__name(isPrimitive, "isPrimitive");
|
|
529
|
+
function isPromise(value) {
|
|
530
|
+
return isNativePromise(value) || hasPromiseApi(value);
|
|
531
|
+
}
|
|
532
|
+
__name(isPromise, "isPromise");
|
|
533
|
+
function isPropertyKey(value) {
|
|
534
|
+
return isAny([isString, isNumber, isSymbol], value);
|
|
535
|
+
}
|
|
536
|
+
__name(isPropertyKey, "isPropertyKey");
|
|
537
|
+
function isRegExp(value) {
|
|
538
|
+
return getObjectType(value) === "RegExp";
|
|
539
|
+
}
|
|
540
|
+
__name(isRegExp, "isRegExp");
|
|
541
|
+
function isSafeInteger(value) {
|
|
542
|
+
return Number.isSafeInteger(value);
|
|
543
|
+
}
|
|
544
|
+
__name(isSafeInteger, "isSafeInteger");
|
|
545
|
+
function isSet(value) {
|
|
546
|
+
return getObjectType(value) === "Set";
|
|
547
|
+
}
|
|
548
|
+
__name(isSet, "isSet");
|
|
549
|
+
function isSharedArrayBuffer(value) {
|
|
550
|
+
return getObjectType(value) === "SharedArrayBuffer";
|
|
551
|
+
}
|
|
552
|
+
__name(isSharedArrayBuffer, "isSharedArrayBuffer");
|
|
553
|
+
function isString(value) {
|
|
554
|
+
return typeof value === "string";
|
|
555
|
+
}
|
|
556
|
+
__name(isString, "isString");
|
|
557
|
+
function isSymbol(value) {
|
|
558
|
+
return typeof value === "symbol";
|
|
559
|
+
}
|
|
560
|
+
__name(isSymbol, "isSymbol");
|
|
561
|
+
function isTruthy(value) {
|
|
562
|
+
return Boolean(value);
|
|
563
|
+
}
|
|
564
|
+
__name(isTruthy, "isTruthy");
|
|
565
|
+
function isTupleLike(value, guards) {
|
|
566
|
+
if (isArray(guards) && isArray(value) && guards.length === value.length) {
|
|
567
|
+
return guards.every((guard, index) => guard(value[index]));
|
|
568
|
+
}
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
__name(isTupleLike, "isTupleLike");
|
|
572
|
+
function isTypedArray(value) {
|
|
573
|
+
return isTypedArrayName(getObjectType(value));
|
|
574
|
+
}
|
|
575
|
+
__name(isTypedArray, "isTypedArray");
|
|
576
|
+
function isUint16Array(value) {
|
|
577
|
+
return getObjectType(value) === "Uint16Array";
|
|
578
|
+
}
|
|
579
|
+
__name(isUint16Array, "isUint16Array");
|
|
580
|
+
function isUint32Array(value) {
|
|
581
|
+
return getObjectType(value) === "Uint32Array";
|
|
582
|
+
}
|
|
583
|
+
__name(isUint32Array, "isUint32Array");
|
|
584
|
+
function isUint8Array(value) {
|
|
585
|
+
return getObjectType(value) === "Uint8Array";
|
|
586
|
+
}
|
|
587
|
+
__name(isUint8Array, "isUint8Array");
|
|
588
|
+
function isUint8ClampedArray(value) {
|
|
589
|
+
return getObjectType(value) === "Uint8ClampedArray";
|
|
590
|
+
}
|
|
591
|
+
__name(isUint8ClampedArray, "isUint8ClampedArray");
|
|
592
|
+
function isUndefined(value) {
|
|
593
|
+
return value === void 0;
|
|
594
|
+
}
|
|
595
|
+
__name(isUndefined, "isUndefined");
|
|
596
|
+
function isUrlInstance(value) {
|
|
597
|
+
return getObjectType(value) === "URL";
|
|
598
|
+
}
|
|
599
|
+
__name(isUrlInstance, "isUrlInstance");
|
|
600
|
+
function isUrlSearchParams(value) {
|
|
601
|
+
return getObjectType(value) === "URLSearchParams";
|
|
602
|
+
}
|
|
603
|
+
__name(isUrlSearchParams, "isUrlSearchParams");
|
|
604
|
+
function isUrlString(value) {
|
|
605
|
+
if (!isString(value)) {
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
try {
|
|
609
|
+
new URL(value);
|
|
610
|
+
return true;
|
|
611
|
+
} catch {
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
__name(isUrlString, "isUrlString");
|
|
616
|
+
function isValidDate(value) {
|
|
617
|
+
return isDate(value) && !isNan(Number(value));
|
|
618
|
+
}
|
|
619
|
+
__name(isValidDate, "isValidDate");
|
|
620
|
+
function isValidLength(value) {
|
|
621
|
+
return isSafeInteger(value) && value >= 0;
|
|
622
|
+
}
|
|
623
|
+
__name(isValidLength, "isValidLength");
|
|
624
|
+
function isWeakMap(value) {
|
|
625
|
+
return getObjectType(value) === "WeakMap";
|
|
626
|
+
}
|
|
627
|
+
__name(isWeakMap, "isWeakMap");
|
|
628
|
+
function isWeakRef(value) {
|
|
629
|
+
return getObjectType(value) === "WeakRef";
|
|
630
|
+
}
|
|
631
|
+
__name(isWeakRef, "isWeakRef");
|
|
632
|
+
function isWeakSet(value) {
|
|
633
|
+
return getObjectType(value) === "WeakSet";
|
|
634
|
+
}
|
|
635
|
+
__name(isWeakSet, "isWeakSet");
|
|
636
|
+
function isWhitespaceString(value) {
|
|
637
|
+
return isString(value) && /^\s+$/.test(value);
|
|
638
|
+
}
|
|
639
|
+
__name(isWhitespaceString, "isWhitespaceString");
|
|
640
|
+
function predicateOnArray(method, predicate, values) {
|
|
641
|
+
if (!isFunction(predicate)) {
|
|
642
|
+
throw new TypeError(`Invalid predicate: ${JSON.stringify(predicate)}`);
|
|
643
|
+
}
|
|
644
|
+
if (values.length === 0) {
|
|
645
|
+
throw new TypeError("Invalid number of values");
|
|
646
|
+
}
|
|
647
|
+
return method.call(values, predicate);
|
|
648
|
+
}
|
|
649
|
+
__name(predicateOnArray, "predicateOnArray");
|
|
650
|
+
function keysOf(value) {
|
|
651
|
+
return Object.keys(value);
|
|
652
|
+
}
|
|
653
|
+
__name(keysOf, "keysOf");
|
|
654
|
+
|
|
655
|
+
// ../utils/src/my-dash.ts
|
|
656
|
+
function keyBy(array, key) {
|
|
657
|
+
return (array || []).reduce((r, x) => ({ ...r, [String(x[key])]: x }), {});
|
|
658
|
+
}
|
|
659
|
+
__name(keyBy, "keyBy");
|
|
660
|
+
function sortBy(array, compareBy) {
|
|
661
|
+
if (typeof compareBy === "function") {
|
|
662
|
+
const compareMap = /* @__PURE__ */ new Map();
|
|
663
|
+
array.forEach((item) => {
|
|
664
|
+
compareMap.set(item, compareBy(item));
|
|
665
|
+
});
|
|
666
|
+
return array.concat().sort(
|
|
667
|
+
(a, b) => compareMap.get(a) - compareMap.get(b)
|
|
668
|
+
);
|
|
669
|
+
} else {
|
|
670
|
+
return array.concat().sort(
|
|
671
|
+
(a, b) => {
|
|
672
|
+
if (a[compareBy] > b[compareBy]) return 1;
|
|
673
|
+
return b[compareBy] > a[compareBy] ? -1 : 0;
|
|
674
|
+
}
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
__name(sortBy, "sortBy");
|
|
679
|
+
function compact(array) {
|
|
680
|
+
return array.filter((item) => item !== void 0 && item !== false && item !== null);
|
|
681
|
+
}
|
|
682
|
+
__name(compact, "compact");
|
|
683
|
+
function filter(array, fn) {
|
|
684
|
+
return array.filter(fn);
|
|
685
|
+
}
|
|
686
|
+
__name(filter, "filter");
|
|
687
|
+
function each(array, fn) {
|
|
688
|
+
if (Array.isArray(array)) {
|
|
689
|
+
array.forEach((item, index) => fn(item, String(index)));
|
|
690
|
+
} else {
|
|
691
|
+
Object.entries(array).forEach(([key, value]) => fn(value, key));
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
__name(each, "each");
|
|
695
|
+
function castArray(value) {
|
|
696
|
+
return Array.isArray(value) ? value : [value];
|
|
697
|
+
}
|
|
698
|
+
__name(castArray, "castArray");
|
|
699
|
+
function mapValues(obj, fn) {
|
|
700
|
+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, fn(value)]));
|
|
701
|
+
}
|
|
702
|
+
__name(mapValues, "mapValues");
|
|
703
|
+
function times(count, fn) {
|
|
704
|
+
return Array.from({ length: count }, (_2, i) => fn(i));
|
|
705
|
+
}
|
|
706
|
+
__name(times, "times");
|
|
707
|
+
function map(array, fn) {
|
|
708
|
+
return array.map(fn);
|
|
709
|
+
}
|
|
710
|
+
__name(map, "map");
|
|
711
|
+
function flatMap(array, fn) {
|
|
712
|
+
return array.flatMap(fn);
|
|
713
|
+
}
|
|
714
|
+
__name(flatMap, "flatMap");
|
|
715
|
+
var _ = {
|
|
716
|
+
keyBy,
|
|
717
|
+
sortBy,
|
|
718
|
+
compact,
|
|
719
|
+
keys: Object.keys,
|
|
720
|
+
values: Object.values,
|
|
721
|
+
some: /* @__PURE__ */ __name((a, fn) => a.some(fn), "some"),
|
|
722
|
+
filter,
|
|
723
|
+
each,
|
|
724
|
+
castArray,
|
|
725
|
+
mapValues,
|
|
726
|
+
times,
|
|
727
|
+
map,
|
|
728
|
+
flatMap,
|
|
729
|
+
// type checks
|
|
730
|
+
isString,
|
|
731
|
+
isBoolean,
|
|
732
|
+
isError,
|
|
733
|
+
isPromise,
|
|
734
|
+
isFunction,
|
|
735
|
+
isNan,
|
|
736
|
+
isNumber,
|
|
737
|
+
isPlainObject,
|
|
738
|
+
isArray,
|
|
739
|
+
isInteger
|
|
740
|
+
};
|
|
741
|
+
var my_dash_default = _;
|
|
742
|
+
var asyncExec = promisify(exec);
|
|
743
|
+
|
|
744
|
+
// ../utils/src/git-utils.ts
|
|
745
|
+
async function checkIsFileGitIgnored(path4, warnIfNotGitRepo = false) {
|
|
746
|
+
try {
|
|
747
|
+
await asyncExec(`git check-ignore ${path4} -q`);
|
|
748
|
+
return true;
|
|
749
|
+
} catch (err) {
|
|
750
|
+
if (err.stderr === "") return false;
|
|
751
|
+
if (err.stderr.includes("not a git repository")) {
|
|
752
|
+
if (warnIfNotGitRepo) {
|
|
753
|
+
console.log("\u{1F536} Your code is not currently in a git repository - run `git init` to initialize a new repo.");
|
|
754
|
+
}
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
throw err;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
__name(checkIsFileGitIgnored, "checkIsFileGitIgnored");
|
|
761
|
+
|
|
762
|
+
// ../utils/src/try-catch.ts
|
|
763
|
+
function isPromise2(obj) {
|
|
764
|
+
return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
765
|
+
}
|
|
766
|
+
__name(isPromise2, "isPromise");
|
|
767
|
+
async function tryCatch(tryFn, catchFn) {
|
|
768
|
+
try {
|
|
769
|
+
return await tryFn();
|
|
770
|
+
} catch (err) {
|
|
771
|
+
const catchResult = catchFn(err);
|
|
772
|
+
if (isPromise2(catchResult)) {
|
|
773
|
+
await catchResult;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
__name(tryCatch, "tryCatch");
|
|
778
|
+
|
|
779
|
+
// ../env-graph/src/lib/errors.ts
|
|
780
|
+
var VarlockError = class extends Error {
|
|
781
|
+
constructor(errOrMessage, more) {
|
|
782
|
+
var __super = (...args) => {
|
|
783
|
+
super(...args);
|
|
784
|
+
this.more = more;
|
|
785
|
+
return this;
|
|
786
|
+
};
|
|
787
|
+
if (my_dash_default.isError(errOrMessage)) {
|
|
788
|
+
__super(errOrMessage.message);
|
|
789
|
+
this.originalError = errOrMessage;
|
|
790
|
+
this.icon = "\u{1F4A5}";
|
|
791
|
+
} else {
|
|
792
|
+
__super(errOrMessage);
|
|
793
|
+
this.originalError = more?.err;
|
|
794
|
+
}
|
|
795
|
+
if (my_dash_default.isArray(more?.tip)) more.tip = more.tip.join("\n");
|
|
796
|
+
this.name = this.constructor.name;
|
|
797
|
+
if (more?.isWarning) this.isWarning = true;
|
|
798
|
+
this.icon ||= this.constructor.defaultIcon;
|
|
799
|
+
}
|
|
800
|
+
static {
|
|
801
|
+
__name(this, "VarlockError");
|
|
802
|
+
}
|
|
803
|
+
originalError;
|
|
804
|
+
get isUnexpected() {
|
|
805
|
+
return !!this.originalError;
|
|
806
|
+
}
|
|
807
|
+
get type() {
|
|
808
|
+
return this.name;
|
|
809
|
+
}
|
|
810
|
+
static defaultIcon = "\u274C";
|
|
811
|
+
icon;
|
|
812
|
+
_isWarning = false;
|
|
813
|
+
get tip() {
|
|
814
|
+
if (!this.more?.tip) return void 0;
|
|
815
|
+
if (my_dash_default.isArray(this.more.tip)) return this.more.tip.join("\n");
|
|
816
|
+
return this.more.tip;
|
|
817
|
+
}
|
|
818
|
+
get code() {
|
|
819
|
+
return this.more?.code;
|
|
820
|
+
}
|
|
821
|
+
get extraMetadata() {
|
|
822
|
+
return this.more?.extraMetadata;
|
|
823
|
+
}
|
|
824
|
+
set isWarning(w) {
|
|
825
|
+
this._isWarning = w;
|
|
826
|
+
if (this._isWarning) {
|
|
827
|
+
this.icon = "\u{1F9D0}";
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
get isWarning() {
|
|
831
|
+
return this._isWarning;
|
|
832
|
+
}
|
|
833
|
+
toJSON() {
|
|
834
|
+
return {
|
|
835
|
+
icon: this.icon,
|
|
836
|
+
type: this.type,
|
|
837
|
+
name: this.name,
|
|
838
|
+
message: this.message,
|
|
839
|
+
isUnexpected: this.isUnexpected,
|
|
840
|
+
...this.tip && { tip: this.tip },
|
|
841
|
+
...this.isWarning && { isWarning: this.isWarning }
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
var SchemaError = class extends VarlockError {
|
|
846
|
+
static {
|
|
847
|
+
__name(this, "SchemaError");
|
|
848
|
+
}
|
|
849
|
+
static defaultIcon = "\u{1F9F0}";
|
|
850
|
+
};
|
|
851
|
+
var ValidationError = class extends VarlockError {
|
|
852
|
+
static {
|
|
853
|
+
__name(this, "ValidationError");
|
|
854
|
+
}
|
|
855
|
+
static defaultIcon = "\u274C";
|
|
856
|
+
};
|
|
857
|
+
var CoercionError = class extends VarlockError {
|
|
858
|
+
static {
|
|
859
|
+
__name(this, "CoercionError");
|
|
860
|
+
}
|
|
861
|
+
static defaultIcon = "\u{1F6D1}";
|
|
862
|
+
};
|
|
863
|
+
var ResolutionError = class _ResolutionError extends VarlockError {
|
|
864
|
+
static {
|
|
865
|
+
__name(this, "ResolutionError");
|
|
866
|
+
}
|
|
867
|
+
static defaultIcon = "\u26D4";
|
|
868
|
+
_retryable = false;
|
|
869
|
+
set retryable(val) {
|
|
870
|
+
this._retryable = val;
|
|
871
|
+
}
|
|
872
|
+
get retryable() {
|
|
873
|
+
if (this._retryable) return true;
|
|
874
|
+
if (this.originalError instanceof _ResolutionError) return this.originalError.retryable;
|
|
875
|
+
return false;
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
var EmptyRequiredValueError = class extends ValidationError {
|
|
879
|
+
static {
|
|
880
|
+
__name(this, "EmptyRequiredValueError");
|
|
881
|
+
}
|
|
882
|
+
icon = "\u2753";
|
|
883
|
+
constructor(_val) {
|
|
884
|
+
super("Value is required but is currently empty");
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
// ../env-graph/src/lib/simple-queue.ts
|
|
889
|
+
var SimpleQueue = class {
|
|
890
|
+
static {
|
|
891
|
+
__name(this, "SimpleQueue");
|
|
892
|
+
}
|
|
893
|
+
queue = [];
|
|
894
|
+
processing = false;
|
|
895
|
+
/** Add a task to the queue and return a promise that resolves when the task is complete */
|
|
896
|
+
async enqueue(task) {
|
|
897
|
+
return new Promise((resolve, reject) => {
|
|
898
|
+
this.queue.push(async () => {
|
|
899
|
+
try {
|
|
900
|
+
const result = await task();
|
|
901
|
+
resolve(result);
|
|
902
|
+
} catch (err) {
|
|
903
|
+
reject(err);
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
this.processQueue();
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
async processQueue() {
|
|
910
|
+
if (this.processing || this.queue.length === 0) {
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
this.processing = true;
|
|
914
|
+
const task = this.queue.shift();
|
|
915
|
+
if (task) {
|
|
916
|
+
try {
|
|
917
|
+
await task();
|
|
918
|
+
} finally {
|
|
919
|
+
this.processing = false;
|
|
920
|
+
this.processQueue();
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
|
|
926
|
+
// ../env-graph/src/lib/resolver.ts
|
|
927
|
+
var execAsync = promisify(exec);
|
|
928
|
+
var Resolver = class {
|
|
929
|
+
constructor(fnArgs) {
|
|
930
|
+
this.fnArgs = fnArgs;
|
|
931
|
+
}
|
|
932
|
+
static {
|
|
933
|
+
__name(this, "Resolver");
|
|
934
|
+
}
|
|
935
|
+
static fnName;
|
|
936
|
+
inferredType;
|
|
937
|
+
_schemaErrors = [];
|
|
938
|
+
_depsObj = {};
|
|
939
|
+
get childResolvers() {
|
|
940
|
+
return my_dash_default.isArray(this.fnArgs) ? this.fnArgs : my_dash_default.values(this.fnArgs);
|
|
941
|
+
}
|
|
942
|
+
get schemaErrors() {
|
|
943
|
+
return [
|
|
944
|
+
...this._schemaErrors,
|
|
945
|
+
...this.childResolvers.flatMap((r) => r.schemaErrors)
|
|
946
|
+
];
|
|
947
|
+
}
|
|
948
|
+
get depsObj() {
|
|
949
|
+
const mergedDepsObj = { ...this._depsObj };
|
|
950
|
+
this.childResolvers.forEach((r) => Object.assign(mergedDepsObj, r.depsObj));
|
|
951
|
+
return mergedDepsObj;
|
|
952
|
+
}
|
|
953
|
+
get deps() {
|
|
954
|
+
return Object.keys(this.depsObj);
|
|
955
|
+
}
|
|
956
|
+
configItem;
|
|
957
|
+
async process(configItem) {
|
|
958
|
+
this.configItem = configItem;
|
|
959
|
+
try {
|
|
960
|
+
await this._process(configItem);
|
|
961
|
+
} catch (error) {
|
|
962
|
+
if (error instanceof SchemaError) {
|
|
963
|
+
this._schemaErrors.push(error);
|
|
964
|
+
} else if (error instanceof Error) {
|
|
965
|
+
this._schemaErrors.push(new SchemaError(error));
|
|
966
|
+
} else {
|
|
967
|
+
throw new Error(`Non-error thrown while processing resolver - ${error}`);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
this.childResolvers.forEach((r) => r.process(configItem));
|
|
971
|
+
}
|
|
972
|
+
// meant to be used by subclass _process methods
|
|
973
|
+
addDep(key) {
|
|
974
|
+
this._depsObj[key] = true;
|
|
975
|
+
if (!this.configItem) throw new Error("expected configItem to be set");
|
|
976
|
+
if (!this.configItem.envGraph.configSchema[key]) {
|
|
977
|
+
this._schemaErrors.push(new SchemaError(`Unknown referenced key: ${key}`));
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
async resolve() {
|
|
981
|
+
const resolvedValue = await this._resolve();
|
|
982
|
+
return resolvedValue;
|
|
983
|
+
}
|
|
984
|
+
// meant to be used by subclass _resolve methods
|
|
985
|
+
getDepValue(key) {
|
|
986
|
+
const depItem = this.configItem?.envGraph.configSchema[key];
|
|
987
|
+
if (!depItem) throw new Error(`Expected to find item - ${key}`);
|
|
988
|
+
return depItem.resolvedValue;
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
var StaticValueResolver = class extends Resolver {
|
|
992
|
+
constructor(staticValue) {
|
|
993
|
+
super([]);
|
|
994
|
+
this.staticValue = staticValue;
|
|
995
|
+
if (staticValue !== void 0) {
|
|
996
|
+
this.inferredType = typeof staticValue;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
static {
|
|
1000
|
+
__name(this, "StaticValueResolver");
|
|
1001
|
+
}
|
|
1002
|
+
label = "static";
|
|
1003
|
+
icon = "bi:dash";
|
|
1004
|
+
async _resolve() {
|
|
1005
|
+
return this.staticValue;
|
|
1006
|
+
}
|
|
1007
|
+
async _process() {
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
var ErrorResolver = class extends Resolver {
|
|
1011
|
+
static {
|
|
1012
|
+
__name(this, "ErrorResolver");
|
|
1013
|
+
}
|
|
1014
|
+
constructor(err) {
|
|
1015
|
+
super([]);
|
|
1016
|
+
this._schemaErrors.push(err);
|
|
1017
|
+
}
|
|
1018
|
+
label = "error";
|
|
1019
|
+
icon = "bi:dash";
|
|
1020
|
+
async _resolve() {
|
|
1021
|
+
return void 0;
|
|
1022
|
+
}
|
|
1023
|
+
async _process() {
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
1026
|
+
var ConcatResolver = class extends Resolver {
|
|
1027
|
+
static {
|
|
1028
|
+
__name(this, "ConcatResolver");
|
|
1029
|
+
}
|
|
1030
|
+
static fnName = "concat";
|
|
1031
|
+
label = "concat";
|
|
1032
|
+
icon = "material-symbols:join";
|
|
1033
|
+
inferredType = "string";
|
|
1034
|
+
async _process() {
|
|
1035
|
+
if (!Array.isArray(this.fnArgs)) {
|
|
1036
|
+
throw new SchemaError("concat() expects an array of arguments, not a key-value object");
|
|
1037
|
+
}
|
|
1038
|
+
if (this.fnArgs.length < 2) {
|
|
1039
|
+
throw new SchemaError("concat() expects at least two arguments");
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
async _resolve() {
|
|
1043
|
+
if (!Array.isArray(this.fnArgs)) {
|
|
1044
|
+
throw new Error("concat() expects an array of arguments, not a key-value object");
|
|
1045
|
+
}
|
|
1046
|
+
const resolvedValues = [];
|
|
1047
|
+
for (const arg of this.fnArgs) {
|
|
1048
|
+
const resolvedChildValue = await arg.resolve();
|
|
1049
|
+
resolvedValues.push(String(resolvedChildValue ?? ""));
|
|
1050
|
+
}
|
|
1051
|
+
return resolvedValues.join("");
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
var FallbackResolver = class extends Resolver {
|
|
1055
|
+
static {
|
|
1056
|
+
__name(this, "FallbackResolver");
|
|
1057
|
+
}
|
|
1058
|
+
static fnName = "fallback";
|
|
1059
|
+
label = "fallback";
|
|
1060
|
+
icon = "memory:table-top-stairs-up";
|
|
1061
|
+
async _process() {
|
|
1062
|
+
if (!Array.isArray(this.fnArgs)) {
|
|
1063
|
+
throw new SchemaError("fallback() expects an array of arguments, not a key-value object");
|
|
1064
|
+
}
|
|
1065
|
+
if (this.fnArgs.length < 2) {
|
|
1066
|
+
throw new SchemaError("fallback() expects at least two arguments");
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
async _resolve() {
|
|
1070
|
+
if (!Array.isArray(this.fnArgs)) {
|
|
1071
|
+
throw new Error("concat() expects an array of arguments, not a key-value object");
|
|
1072
|
+
}
|
|
1073
|
+
for (const arg of this.fnArgs) {
|
|
1074
|
+
const resolvedChildValue = await arg.resolve();
|
|
1075
|
+
if (resolvedChildValue !== void 0 && resolvedChildValue !== "") {
|
|
1076
|
+
return resolvedChildValue;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
var ExecResolver = class _ExecResolver extends Resolver {
|
|
1082
|
+
static {
|
|
1083
|
+
__name(this, "ExecResolver");
|
|
1084
|
+
}
|
|
1085
|
+
static fnName = "exec";
|
|
1086
|
+
label = "exec";
|
|
1087
|
+
icon = "iconoir:terminal";
|
|
1088
|
+
async _process() {
|
|
1089
|
+
if (!Array.isArray(this.fnArgs)) {
|
|
1090
|
+
throw new SchemaError("exec() expects a single child arg, not a key-value object");
|
|
1091
|
+
}
|
|
1092
|
+
if (this.fnArgs.length !== 1) {
|
|
1093
|
+
throw new SchemaError("exec() expects a single child arg");
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
static execQueue = new SimpleQueue();
|
|
1097
|
+
async _resolve() {
|
|
1098
|
+
if (!Array.isArray(this.fnArgs) || this.fnArgs.length !== 1) {
|
|
1099
|
+
throw new Error("exec() expects a single child arg");
|
|
1100
|
+
}
|
|
1101
|
+
const commandStr = await this.fnArgs[0].resolve();
|
|
1102
|
+
if (typeof commandStr !== "string") {
|
|
1103
|
+
throw new ResolutionError("exec() expects a string child arg");
|
|
1104
|
+
}
|
|
1105
|
+
try {
|
|
1106
|
+
const { stdout, stderr } = await _ExecResolver.execQueue.enqueue(() => execAsync(commandStr));
|
|
1107
|
+
return stdout.replace(/\n$/, "");
|
|
1108
|
+
} catch (err) {
|
|
1109
|
+
console.log("exec() failed", err);
|
|
1110
|
+
throw new ResolutionError(`exec() command failed: ${commandStr}`);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
var RefResolver = class extends Resolver {
|
|
1115
|
+
static {
|
|
1116
|
+
__name(this, "RefResolver");
|
|
1117
|
+
}
|
|
1118
|
+
static fnName = "ref";
|
|
1119
|
+
label = "ref";
|
|
1120
|
+
icon = "mdi-light:content-duplicate";
|
|
1121
|
+
refKey;
|
|
1122
|
+
async _process() {
|
|
1123
|
+
if (!Array.isArray(this.fnArgs)) {
|
|
1124
|
+
throw new SchemaError("ref() expects a single child arg, not a key-value object");
|
|
1125
|
+
}
|
|
1126
|
+
if (this.fnArgs.length !== 1) {
|
|
1127
|
+
throw new SchemaError("ref() expects a single child arg");
|
|
1128
|
+
}
|
|
1129
|
+
if (!(this.fnArgs[0] instanceof StaticValueResolver)) {
|
|
1130
|
+
throw new SchemaError("ref() expects a single static value passed in");
|
|
1131
|
+
}
|
|
1132
|
+
const keyName = this.fnArgs[0].staticValue;
|
|
1133
|
+
if (typeof keyName !== "string") {
|
|
1134
|
+
throw new SchemaError("ref() expects a string keyname passed in");
|
|
1135
|
+
}
|
|
1136
|
+
this.refKey = keyName;
|
|
1137
|
+
this.addDep(keyName);
|
|
1138
|
+
}
|
|
1139
|
+
async _resolve() {
|
|
1140
|
+
if (!this.refKey) throw new Error("expected refKey to be set");
|
|
1141
|
+
return this.getDepValue(this.refKey);
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
var BaseResolvers = [
|
|
1145
|
+
ConcatResolver,
|
|
1146
|
+
FallbackResolver,
|
|
1147
|
+
RefResolver,
|
|
1148
|
+
ExecResolver
|
|
1149
|
+
];
|
|
1150
|
+
|
|
1151
|
+
// ../env-graph/src/lib/data-source.ts
|
|
1152
|
+
var DATA_SOURCE_TYPES = Object.freeze({
|
|
1153
|
+
schema: {
|
|
1154
|
+
fileSuffixes: ["schema"],
|
|
1155
|
+
precedence: 0
|
|
1156
|
+
},
|
|
1157
|
+
example: {
|
|
1158
|
+
fileSuffixes: ["sample", "example"],
|
|
1159
|
+
precedence: 1
|
|
1160
|
+
},
|
|
1161
|
+
defaults: {
|
|
1162
|
+
fileSuffixes: ["default", "defaults"],
|
|
1163
|
+
precedence: 2
|
|
1164
|
+
},
|
|
1165
|
+
values: {
|
|
1166
|
+
fileSuffixes: [],
|
|
1167
|
+
precedence: 3
|
|
1168
|
+
},
|
|
1169
|
+
overrides: {
|
|
1170
|
+
fileSuffixes: ["local", "override"],
|
|
1171
|
+
precedence: 4
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
1174
|
+
var EnvGraphDataSource = class {
|
|
1175
|
+
static {
|
|
1176
|
+
__name(this, "EnvGraphDataSource");
|
|
1177
|
+
}
|
|
1178
|
+
static DATA_SOURCE_TYPES = DATA_SOURCE_TYPES;
|
|
1179
|
+
// reference back to the graph
|
|
1180
|
+
graph;
|
|
1181
|
+
type = "values";
|
|
1182
|
+
applyForEnv;
|
|
1183
|
+
disabled = false;
|
|
1184
|
+
ignoreNewDefs = false;
|
|
1185
|
+
/** an error encountered while loading/parsing the data source */
|
|
1186
|
+
loadingError;
|
|
1187
|
+
get isValid() {
|
|
1188
|
+
return !this.loadingError;
|
|
1189
|
+
}
|
|
1190
|
+
configItemDefs = {};
|
|
1191
|
+
decorators = {};
|
|
1192
|
+
getStaticValues() {
|
|
1193
|
+
const obj = {};
|
|
1194
|
+
for (const [key, def] of Object.entries(this.configItemDefs)) {
|
|
1195
|
+
if (def.resolver instanceof StaticValueResolver) {
|
|
1196
|
+
obj[key] = String(def.resolver.staticValue ?? "");
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
return obj;
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
var ProcessEnvDataSource = class _ProcessEnvDataSource extends EnvGraphDataSource {
|
|
1203
|
+
static {
|
|
1204
|
+
__name(this, "ProcessEnvDataSource");
|
|
1205
|
+
}
|
|
1206
|
+
type = "overrides";
|
|
1207
|
+
label = "Process Environment Variables";
|
|
1208
|
+
ignoreNewDefs = true;
|
|
1209
|
+
static processEnvValues;
|
|
1210
|
+
// ? do we want to set decorator values from env vars here? -- ex: _ENV_FLAG_KEY
|
|
1211
|
+
// depends if we want those to work only within process.env
|
|
1212
|
+
constructor() {
|
|
1213
|
+
super();
|
|
1214
|
+
if (!_ProcessEnvDataSource.processEnvValues) {
|
|
1215
|
+
_ProcessEnvDataSource.processEnvValues = {};
|
|
1216
|
+
for (const itemKey of Object.keys(process.env)) {
|
|
1217
|
+
_ProcessEnvDataSource.processEnvValues[itemKey] = process.env[itemKey];
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
for (const itemKey of Object.keys(_ProcessEnvDataSource.processEnvValues)) {
|
|
1221
|
+
this.configItemDefs[itemKey] = {
|
|
1222
|
+
resolver: new StaticValueResolver(_ProcessEnvDataSource.processEnvValues[itemKey])
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1227
|
+
var EnvSourceParseError = class extends Error {
|
|
1228
|
+
constructor(message, location) {
|
|
1229
|
+
super(message);
|
|
1230
|
+
this.location = location;
|
|
1231
|
+
}
|
|
1232
|
+
static {
|
|
1233
|
+
__name(this, "EnvSourceParseError");
|
|
1234
|
+
}
|
|
1235
|
+
};
|
|
1236
|
+
var FileBasedDataSource = class extends EnvGraphDataSource {
|
|
1237
|
+
static {
|
|
1238
|
+
__name(this, "FileBasedDataSource");
|
|
1239
|
+
}
|
|
1240
|
+
isGitIgnored;
|
|
1241
|
+
fullPath;
|
|
1242
|
+
fileName;
|
|
1243
|
+
rawContents;
|
|
1244
|
+
format;
|
|
1245
|
+
get label() {
|
|
1246
|
+
return `File: ${this.fullPath}`;
|
|
1247
|
+
}
|
|
1248
|
+
static validFileExtensions = [];
|
|
1249
|
+
get validFileExtensions() {
|
|
1250
|
+
return this.constructor.validFileExtensions;
|
|
1251
|
+
}
|
|
1252
|
+
constructor(fullPath, opts) {
|
|
1253
|
+
super();
|
|
1254
|
+
this.fullPath = fullPath;
|
|
1255
|
+
this.fileName = path.basename(fullPath);
|
|
1256
|
+
if (opts?.overrideContents) {
|
|
1257
|
+
this.rawContents = opts.overrideContents;
|
|
1258
|
+
this.isGitIgnored = opts.overrideGitIgnored;
|
|
1259
|
+
}
|
|
1260
|
+
if (!this.fileName.startsWith(".env")) {
|
|
1261
|
+
throw new Error('file name must start with ".env"');
|
|
1262
|
+
}
|
|
1263
|
+
const fileNameParts = this.fileName.substring(1).split(".");
|
|
1264
|
+
const maybeExtension = fileNameParts[fileNameParts.length - 1];
|
|
1265
|
+
if (this.validFileExtensions.includes(maybeExtension)) {
|
|
1266
|
+
fileNameParts.pop();
|
|
1267
|
+
}
|
|
1268
|
+
const maybeFileType = fileNameParts[fileNameParts.length - 1];
|
|
1269
|
+
for (const [possibleSourceType, possibleSourceSpec] of Object.entries(DATA_SOURCE_TYPES)) {
|
|
1270
|
+
if (possibleSourceSpec.fileSuffixes.includes(maybeFileType)) {
|
|
1271
|
+
this.type = possibleSourceType;
|
|
1272
|
+
break;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
if (this.type !== "values") fileNameParts.pop();
|
|
1276
|
+
if (fileNameParts.length > 2) {
|
|
1277
|
+
throw Error(`Unsure how to interpret filename - ${this.fileName}`);
|
|
1278
|
+
} else if (fileNameParts.length === 2) {
|
|
1279
|
+
this.applyForEnv = fileNameParts[1];
|
|
1280
|
+
if (this.applyForEnv === "dev") this.applyForEnv = "development";
|
|
1281
|
+
if (this.applyForEnv === "stage") this.applyForEnv = "staging";
|
|
1282
|
+
if (this.applyForEnv === "prod") this.applyForEnv = "production";
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
// no async constructors... :(
|
|
1286
|
+
async finishInit() {
|
|
1287
|
+
if (!this.rawContents) {
|
|
1288
|
+
this.isGitIgnored = await checkIsFileGitIgnored(this.fullPath);
|
|
1289
|
+
this.rawContents = await fs.readFile(this.fullPath, "utf8");
|
|
1290
|
+
}
|
|
1291
|
+
await this._parseContents();
|
|
1292
|
+
}
|
|
1293
|
+
};
|
|
1294
|
+
var DotEnvFileDataSource = class extends FileBasedDataSource {
|
|
1295
|
+
static {
|
|
1296
|
+
__name(this, "DotEnvFileDataSource");
|
|
1297
|
+
}
|
|
1298
|
+
static format = "dotenv";
|
|
1299
|
+
static validFileExtensions = [];
|
|
1300
|
+
// no extension for dotenv files!
|
|
1301
|
+
parsedFile;
|
|
1302
|
+
convertParserValueToResolvers(value) {
|
|
1303
|
+
if (!this.graph) throw new Error("expected graph to be set");
|
|
1304
|
+
if (value === void 0) {
|
|
1305
|
+
return new StaticValueResolver(void 0);
|
|
1306
|
+
} else if (value instanceof ParsedEnvSpecStaticValue) {
|
|
1307
|
+
return new StaticValueResolver(value.unescapedValue);
|
|
1308
|
+
} else if (value instanceof ParsedEnvSpecFunctionCall) {
|
|
1309
|
+
const ResolverFnClass = this.graph.registeredResolverFunctions[value.name];
|
|
1310
|
+
if (!ResolverFnClass) {
|
|
1311
|
+
return new ErrorResolver(new SchemaError(`Unknown resolver function: ${value.name}()`));
|
|
1312
|
+
}
|
|
1313
|
+
const argsFromParser = value.data.args.values;
|
|
1314
|
+
if (argsFromParser.length && argsFromParser.every((arg) => arg instanceof ParsedEnvSpecKeyValuePair)) {
|
|
1315
|
+
const argsAsResolversObj = {};
|
|
1316
|
+
for (const arg of argsFromParser) {
|
|
1317
|
+
argsAsResolversObj[arg.key] = this.convertParserValueToResolvers(arg.value);
|
|
1318
|
+
}
|
|
1319
|
+
return new ResolverFnClass(argsAsResolversObj);
|
|
1320
|
+
} else {
|
|
1321
|
+
const argsAsResolversArray = argsFromParser.map((arg) => {
|
|
1322
|
+
if (arg instanceof ParsedEnvSpecKeyValuePair) throw new Error("KeyValuePair not supported as a function argument");
|
|
1323
|
+
return this.convertParserValueToResolvers(arg);
|
|
1324
|
+
});
|
|
1325
|
+
return new ResolverFnClass(argsAsResolversArray);
|
|
1326
|
+
}
|
|
1327
|
+
} else {
|
|
1328
|
+
throw new Error("Unknown value type");
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
async _parseContents() {
|
|
1332
|
+
const rawContents = this.rawContents;
|
|
1333
|
+
this.parsedFile = await tryCatch(
|
|
1334
|
+
() => parseEnvSpecDotEnvFile(rawContents),
|
|
1335
|
+
(error) => {
|
|
1336
|
+
this.loadingError = new EnvSourceParseError(error.message, {
|
|
1337
|
+
path: this.fullPath,
|
|
1338
|
+
lineNumber: error.location.start.line,
|
|
1339
|
+
colNumber: error.location.start.column,
|
|
1340
|
+
lineStr: rawContents.split("\n")[error.location.start.line - 1]
|
|
1341
|
+
});
|
|
1342
|
+
this.loadingError.cause = error;
|
|
1343
|
+
}
|
|
1344
|
+
);
|
|
1345
|
+
if (this.loadingError) return;
|
|
1346
|
+
if (!this.parsedFile) throw new Error("Failed to parse .env file");
|
|
1347
|
+
this.decorators = this.parsedFile.decoratorsObject;
|
|
1348
|
+
if (!this.graph) throw new Error("expected graph to be set");
|
|
1349
|
+
for (const item of this.parsedFile.configItems) {
|
|
1350
|
+
item.processExpansion();
|
|
1351
|
+
this.configItemDefs[item.key] = {
|
|
1352
|
+
resolver: this.convertParserValueToResolvers(item.expandedValue),
|
|
1353
|
+
description: item.description,
|
|
1354
|
+
decorators: item.decoratorsObject
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
};
|
|
1359
|
+
var ConfigItem = class {
|
|
1360
|
+
constructor(envGraph, key) {
|
|
1361
|
+
this.envGraph = envGraph;
|
|
1362
|
+
this.key = key;
|
|
1363
|
+
}
|
|
1364
|
+
static {
|
|
1365
|
+
__name(this, "ConfigItem");
|
|
1366
|
+
}
|
|
1367
|
+
defs = [];
|
|
1368
|
+
addDef(itemDef, source) {
|
|
1369
|
+
this.defs.unshift({ itemDef, source });
|
|
1370
|
+
}
|
|
1371
|
+
get description() {
|
|
1372
|
+
for (const def of this.defs) {
|
|
1373
|
+
if (def.itemDef.description) return def.itemDef.description;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
get icon() {
|
|
1377
|
+
const explicitIcon = this.getDecoratorValueString("icon");
|
|
1378
|
+
if (explicitIcon) return explicitIcon;
|
|
1379
|
+
return this.dataType?.icon;
|
|
1380
|
+
}
|
|
1381
|
+
get docsLinks() {
|
|
1382
|
+
const links = [];
|
|
1383
|
+
const docsUrl = this.getDecoratorValueString("docsUrl");
|
|
1384
|
+
if (docsUrl) links.push({ url: docsUrl });
|
|
1385
|
+
return links;
|
|
1386
|
+
}
|
|
1387
|
+
get valueResolver() {
|
|
1388
|
+
for (const def of this.defs) {
|
|
1389
|
+
if (def.itemDef.resolver) return def.itemDef.resolver;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
getDecorator(decoratorName) {
|
|
1393
|
+
for (const def of this.defs) {
|
|
1394
|
+
const defDecorators = def.itemDef.decorators || {};
|
|
1395
|
+
if (decoratorName in defDecorators) {
|
|
1396
|
+
return defDecorators[decoratorName];
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
getDecoratorValueRaw(decoratorName) {
|
|
1401
|
+
for (const def of this.defs) {
|
|
1402
|
+
const defDecorators = def.itemDef.decorators || {};
|
|
1403
|
+
if (decoratorName in defDecorators) {
|
|
1404
|
+
return defDecorators[decoratorName].value;
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
getDecoratorValueString(decoratorName) {
|
|
1409
|
+
const dec = this.getDecoratorValueRaw(decoratorName);
|
|
1410
|
+
if (dec instanceof ParsedEnvSpecStaticValue) return String(dec.value);
|
|
1411
|
+
}
|
|
1412
|
+
dataType;
|
|
1413
|
+
schemaErrors = [];
|
|
1414
|
+
get resolverSchemaErrors() {
|
|
1415
|
+
return this.valueResolver?.schemaErrors || [];
|
|
1416
|
+
}
|
|
1417
|
+
async process() {
|
|
1418
|
+
for (const def of this.defs) {
|
|
1419
|
+
await def.itemDef.resolver?.process(this);
|
|
1420
|
+
}
|
|
1421
|
+
const typeDecoratorValue = this.getDecoratorValueRaw("type");
|
|
1422
|
+
let dataTypeName;
|
|
1423
|
+
let dataTypeArgs;
|
|
1424
|
+
if (typeDecoratorValue instanceof ParsedEnvSpecStaticValue) {
|
|
1425
|
+
dataTypeName = typeDecoratorValue.value;
|
|
1426
|
+
} else if (typeDecoratorValue instanceof ParsedEnvSpecFunctionCall) {
|
|
1427
|
+
dataTypeName = typeDecoratorValue.name;
|
|
1428
|
+
dataTypeArgs = typeDecoratorValue.simplifiedArgs;
|
|
1429
|
+
}
|
|
1430
|
+
if (!dataTypeName) {
|
|
1431
|
+
if (this.valueResolver?.inferredType) {
|
|
1432
|
+
dataTypeName = this.valueResolver.inferredType;
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
dataTypeName ||= "string";
|
|
1436
|
+
dataTypeArgs ||= [];
|
|
1437
|
+
if (!(dataTypeName in this.envGraph.dataTypesRegistry)) {
|
|
1438
|
+
this.schemaErrors.push(new SchemaError(`unknown data type: ${dataTypeName}`));
|
|
1439
|
+
} else {
|
|
1440
|
+
const dataTypeFactory = this.envGraph.dataTypesRegistry[dataTypeName];
|
|
1441
|
+
this.dataType = dataTypeFactory(...my_dash_default.isPlainObject(dataTypeArgs) ? [dataTypeArgs] : dataTypeArgs);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
get isRequired() {
|
|
1445
|
+
for (const def of this.defs) {
|
|
1446
|
+
const defDecorators = def.itemDef.decorators || {};
|
|
1447
|
+
if ("required" in defDecorators) {
|
|
1448
|
+
return defDecorators.required.simplifiedValue;
|
|
1449
|
+
} else if ("optional" in defDecorators) {
|
|
1450
|
+
return !defDecorators.optional.simplifiedValue;
|
|
1451
|
+
} else if ("defaultRequired" in def.source.decorators) {
|
|
1452
|
+
return def.source.decorators.defaultRequired.simplifiedValue;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
return true;
|
|
1456
|
+
}
|
|
1457
|
+
get isSensitive() {
|
|
1458
|
+
for (const def of this.defs) {
|
|
1459
|
+
const defDecorators = def.itemDef.decorators || {};
|
|
1460
|
+
if ("sensitive" in defDecorators) {
|
|
1461
|
+
return defDecorators.sensitive.simplifiedValue;
|
|
1462
|
+
} else if ("defaultSensitive" in def.source.decorators) {
|
|
1463
|
+
return def.source.decorators.defaultSensitive.simplifiedValue;
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
return true;
|
|
1467
|
+
}
|
|
1468
|
+
get errors() {
|
|
1469
|
+
return my_dash_default.compact([
|
|
1470
|
+
...this.schemaErrors || [],
|
|
1471
|
+
...this.resolverSchemaErrors || [],
|
|
1472
|
+
this.resolutionError,
|
|
1473
|
+
this.coercionError,
|
|
1474
|
+
...this.validationErrors || []
|
|
1475
|
+
]);
|
|
1476
|
+
}
|
|
1477
|
+
get validationState() {
|
|
1478
|
+
const errors = this.errors;
|
|
1479
|
+
if (!errors.length) return "valid";
|
|
1480
|
+
return my_dash_default.some(errors, (e) => !e.isWarning) ? "error" : "warn";
|
|
1481
|
+
}
|
|
1482
|
+
/** resolved value _before coercion_ */
|
|
1483
|
+
resolvedRawValue;
|
|
1484
|
+
isResolved = false;
|
|
1485
|
+
/** resolved value after coercion */
|
|
1486
|
+
resolvedValue;
|
|
1487
|
+
isValidated = false;
|
|
1488
|
+
resolutionError;
|
|
1489
|
+
coercionError;
|
|
1490
|
+
validationErrors;
|
|
1491
|
+
get isCoerced() {
|
|
1492
|
+
return this.resolvedRawValue !== this.resolvedValue;
|
|
1493
|
+
}
|
|
1494
|
+
async resolve() {
|
|
1495
|
+
if (this.schemaErrors.length) return;
|
|
1496
|
+
if (this.resolverSchemaErrors.length) return;
|
|
1497
|
+
if (!this.valueResolver) {
|
|
1498
|
+
this.resolvedRawValue = void 0;
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1501
|
+
if (this.isResolved) throw new Error("item already resolved");
|
|
1502
|
+
try {
|
|
1503
|
+
this.resolvedRawValue = await this.valueResolver.resolve();
|
|
1504
|
+
} catch (err) {
|
|
1505
|
+
this.resolutionError = new ResolutionError(`error resolving value: ${err}`);
|
|
1506
|
+
this.resolutionError.cause = err;
|
|
1507
|
+
}
|
|
1508
|
+
if (this.resolutionError) return;
|
|
1509
|
+
this.isResolved = true;
|
|
1510
|
+
if (this.resolvedRawValue === void 0 || this.resolvedRawValue === "") {
|
|
1511
|
+
this.resolvedValue = this.resolvedRawValue;
|
|
1512
|
+
if (this.isRequired) {
|
|
1513
|
+
this.validationErrors = [new EmptyRequiredValueError(void 0)];
|
|
1514
|
+
}
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
if (!this.dataType) throw new Error("expected dataType to be set");
|
|
1518
|
+
try {
|
|
1519
|
+
const coerceResult = this.dataType.coerce(this.resolvedRawValue);
|
|
1520
|
+
if (coerceResult instanceof Error) throw coerceResult;
|
|
1521
|
+
this.resolvedValue = coerceResult;
|
|
1522
|
+
} catch (err) {
|
|
1523
|
+
if (err instanceof CoercionError) {
|
|
1524
|
+
this.coercionError = err;
|
|
1525
|
+
return;
|
|
1526
|
+
} else if (err instanceof Error) {
|
|
1527
|
+
this.coercionError = new CoercionError("Unexpected error coercing value");
|
|
1528
|
+
this.coercionError.cause = err;
|
|
1529
|
+
} else {
|
|
1530
|
+
this.coercionError = new CoercionError(`Unexpected non-error throw during coerce - ${err}`);
|
|
1531
|
+
}
|
|
1532
|
+
return;
|
|
1533
|
+
}
|
|
1534
|
+
try {
|
|
1535
|
+
const validateResult = this.dataType.validate(this.resolvedValue);
|
|
1536
|
+
if (validateResult instanceof Error || my_dash_default.isArray(validateResult) && validateResult[0] instanceof Error) throw validateResult;
|
|
1537
|
+
if (validateResult === false) {
|
|
1538
|
+
throw new ValidationError("validation failed with `false` return value");
|
|
1539
|
+
}
|
|
1540
|
+
this.isValidated = true;
|
|
1541
|
+
} catch (err) {
|
|
1542
|
+
if (my_dash_default.isArray(err)) {
|
|
1543
|
+
this.validationErrors = err;
|
|
1544
|
+
} else if (err instanceof ValidationError) {
|
|
1545
|
+
this.validationErrors = [err];
|
|
1546
|
+
} else if (err instanceof Error) {
|
|
1547
|
+
const validationError = new ValidationError("Unexpected error during validation");
|
|
1548
|
+
validationError.cause = err;
|
|
1549
|
+
console.log(err);
|
|
1550
|
+
this.validationErrors = [validationError];
|
|
1551
|
+
} else {
|
|
1552
|
+
const validationError = new ValidationError(`Unexpected non-error thrown during validation - ${err}`);
|
|
1553
|
+
validationError.cause = err;
|
|
1554
|
+
this.validationErrors = [validationError];
|
|
1555
|
+
}
|
|
1556
|
+
return;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
get isValid() {
|
|
1560
|
+
return this.validationState === "valid";
|
|
1561
|
+
}
|
|
1562
|
+
};
|
|
1563
|
+
|
|
1564
|
+
// ../env-graph/src/lib/data-types.ts
|
|
1565
|
+
var EnvGraphDataType = class {
|
|
1566
|
+
constructor(def, factory) {
|
|
1567
|
+
this.def = def;
|
|
1568
|
+
this.factory = factory;
|
|
1569
|
+
}
|
|
1570
|
+
static {
|
|
1571
|
+
__name(this, "EnvGraphDataType");
|
|
1572
|
+
}
|
|
1573
|
+
get name() {
|
|
1574
|
+
return this.def.name;
|
|
1575
|
+
}
|
|
1576
|
+
get icon() {
|
|
1577
|
+
return this.def.icon;
|
|
1578
|
+
}
|
|
1579
|
+
/** @internal */
|
|
1580
|
+
get _rawDef() {
|
|
1581
|
+
return this.def;
|
|
1582
|
+
}
|
|
1583
|
+
coerce(val) {
|
|
1584
|
+
return this.def.coerce ? this.def.coerce(val) : val;
|
|
1585
|
+
}
|
|
1586
|
+
validate(val) {
|
|
1587
|
+
return this.def.validate ? this.def.validate(val) : true;
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
function createEnvGraphDataType(dataTypeDef) {
|
|
1591
|
+
const typeFactoryFn = /* @__PURE__ */ __name((...usageOpts) => {
|
|
1592
|
+
return new EnvGraphDataType(
|
|
1593
|
+
my_dash_default.isFunction(dataTypeDef) ? dataTypeDef(...usageOpts) : dataTypeDef,
|
|
1594
|
+
typeFactoryFn
|
|
1595
|
+
);
|
|
1596
|
+
}, "typeFactoryFn");
|
|
1597
|
+
typeFactoryFn._isEnvGraphDataTypeFactory = true;
|
|
1598
|
+
const exampleInstance = typeFactoryFn(...[]);
|
|
1599
|
+
typeFactoryFn.dataTypeName = exampleInstance.name;
|
|
1600
|
+
return typeFactoryFn;
|
|
1601
|
+
}
|
|
1602
|
+
__name(createEnvGraphDataType, "createEnvGraphDataType");
|
|
1603
|
+
function coerceToString(rawVal) {
|
|
1604
|
+
if (rawVal === void 0 || rawVal === null) return "";
|
|
1605
|
+
return my_dash_default.isString(rawVal) ? rawVal : String(rawVal);
|
|
1606
|
+
}
|
|
1607
|
+
__name(coerceToString, "coerceToString");
|
|
1608
|
+
function coerceToNumber(rawVal) {
|
|
1609
|
+
let numVal;
|
|
1610
|
+
if (my_dash_default.isString(rawVal)) {
|
|
1611
|
+
const parsed = parseFloat(rawVal);
|
|
1612
|
+
if (my_dash_default.isNan(parsed) || parsed === Infinity || parsed === -Infinity) {
|
|
1613
|
+
throw new CoercionError("Unable to coerce string to number");
|
|
1614
|
+
}
|
|
1615
|
+
numVal = parsed;
|
|
1616
|
+
} else if (my_dash_default.isNumber(rawVal)) {
|
|
1617
|
+
if (numVal === Infinity || numVal === -Infinity) {
|
|
1618
|
+
throw new CoercionError("Inifinity is not a valid number");
|
|
1619
|
+
}
|
|
1620
|
+
numVal = rawVal;
|
|
1621
|
+
} else {
|
|
1622
|
+
throw new CoercionError(`Cannot convert ${rawVal} to number`);
|
|
1623
|
+
}
|
|
1624
|
+
return numVal;
|
|
1625
|
+
}
|
|
1626
|
+
__name(coerceToNumber, "coerceToNumber");
|
|
1627
|
+
var StringDataType = createEnvGraphDataType(
|
|
1628
|
+
(settings) => ({
|
|
1629
|
+
name: "string",
|
|
1630
|
+
icon: "carbon:string-text",
|
|
1631
|
+
coerce: /* @__PURE__ */ __name((rawVal) => {
|
|
1632
|
+
let val = coerceToString(rawVal);
|
|
1633
|
+
if (settings?.toUpperCase) val = val.toUpperCase();
|
|
1634
|
+
if (settings?.toLowerCase) val = val.toLowerCase();
|
|
1635
|
+
return val;
|
|
1636
|
+
}, "coerce"),
|
|
1637
|
+
validate: /* @__PURE__ */ __name((val) => {
|
|
1638
|
+
const errors = [];
|
|
1639
|
+
if (settings?.minLength !== void 0 && val.length < settings.minLength) {
|
|
1640
|
+
errors.push(new ValidationError(`Length must be more than ${settings.minLength}`));
|
|
1641
|
+
}
|
|
1642
|
+
if (settings?.maxLength !== void 0 && val.length > settings.maxLength) {
|
|
1643
|
+
errors.push(new ValidationError(`Length must be less than ${settings.maxLength}`));
|
|
1644
|
+
}
|
|
1645
|
+
if (settings?.isLength !== void 0 && val.length !== settings.isLength) {
|
|
1646
|
+
errors.push(new ValidationError(`Length must be exactly ${settings.isLength}`));
|
|
1647
|
+
}
|
|
1648
|
+
if (settings?.startsWith && !val.startsWith(settings.startsWith)) {
|
|
1649
|
+
errors.push(new ValidationError(`Value must start with "${settings.startsWith}"`));
|
|
1650
|
+
}
|
|
1651
|
+
if (settings?.endsWith && !val.endsWith(settings.endsWith)) {
|
|
1652
|
+
errors.push(new ValidationError(`Value must start with "${settings.endsWith}"`));
|
|
1653
|
+
}
|
|
1654
|
+
if (settings?.matches) {
|
|
1655
|
+
const regex = my_dash_default.isString(settings.matches) ? new RegExp(settings.matches) : settings.matches;
|
|
1656
|
+
const matches = val.match(regex);
|
|
1657
|
+
if (!matches) {
|
|
1658
|
+
errors.push(new ValidationError(`Value must match regex "${settings.matches}"`));
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
return errors.length ? errors : true;
|
|
1662
|
+
}, "validate")
|
|
1663
|
+
})
|
|
1664
|
+
);
|
|
1665
|
+
var NumberDataType = createEnvGraphDataType(
|
|
1666
|
+
(settings) => ({
|
|
1667
|
+
name: "number",
|
|
1668
|
+
icon: "carbon:string-integer",
|
|
1669
|
+
coerce(rawVal) {
|
|
1670
|
+
let numVal = coerceToNumber(rawVal);
|
|
1671
|
+
if (settings?.coerceToMinMaxRange) {
|
|
1672
|
+
if (settings?.min !== void 0) numVal = Math.max(settings?.min, numVal);
|
|
1673
|
+
if (settings?.max !== void 0) numVal = Math.min(settings?.max, numVal);
|
|
1674
|
+
}
|
|
1675
|
+
if (settings?.isInt === true || settings?.precision === 0) {
|
|
1676
|
+
numVal = Math.round(numVal);
|
|
1677
|
+
} else if (settings?.precision) {
|
|
1678
|
+
const p = 10 ** settings.precision;
|
|
1679
|
+
numVal = Math.round(numVal * p) / p;
|
|
1680
|
+
}
|
|
1681
|
+
return numVal;
|
|
1682
|
+
},
|
|
1683
|
+
validate(val) {
|
|
1684
|
+
const errors = [];
|
|
1685
|
+
if (settings?.min !== void 0 && val < settings?.min) {
|
|
1686
|
+
errors.push(new ValidationError(`Min value is ${settings?.min}`));
|
|
1687
|
+
}
|
|
1688
|
+
if (settings?.max !== void 0 && val > settings?.max) {
|
|
1689
|
+
errors.push(new ValidationError(`Max value is ${settings?.max}`));
|
|
1690
|
+
}
|
|
1691
|
+
if (settings?.isDivisibleBy !== void 0 && val % settings.isDivisibleBy !== 0) {
|
|
1692
|
+
errors.push(new ValidationError(`Value must be divisible by ${settings?.isDivisibleBy}`));
|
|
1693
|
+
}
|
|
1694
|
+
return errors.length ? errors : true;
|
|
1695
|
+
}
|
|
1696
|
+
})
|
|
1697
|
+
);
|
|
1698
|
+
var BooleanDataType = createEnvGraphDataType({
|
|
1699
|
+
name: "boolean",
|
|
1700
|
+
icon: "carbon:boolean",
|
|
1701
|
+
// probably want allow some settings
|
|
1702
|
+
// - more strict about coercion or adding additional true/false values
|
|
1703
|
+
// - coercing to other values - like 0,1
|
|
1704
|
+
coerce(val) {
|
|
1705
|
+
if (my_dash_default.isBoolean(val)) {
|
|
1706
|
+
return val;
|
|
1707
|
+
} else if (my_dash_default.isString(val)) {
|
|
1708
|
+
const cleanVal = val.toLowerCase().trim();
|
|
1709
|
+
if (["t", "true", "yes", "on", "1"].includes(cleanVal)) return true;
|
|
1710
|
+
if (["f", "false", "no", "off", "0"].includes(cleanVal)) return false;
|
|
1711
|
+
throw new CoercionError("Unable to coerce string value to boolean");
|
|
1712
|
+
} else if (my_dash_default.isNumber(val)) {
|
|
1713
|
+
if (val === 0) return false;
|
|
1714
|
+
if (val === 1) return true;
|
|
1715
|
+
throw new CoercionError("Unable to coerce number value to boolean (only 0 or 1 is valid)");
|
|
1716
|
+
} else {
|
|
1717
|
+
throw new CoercionError("Unable to coerce value to boolean");
|
|
1718
|
+
}
|
|
1719
|
+
},
|
|
1720
|
+
// TODO: add settings to be more strict, or to allow other values to coerce to true/false
|
|
1721
|
+
validate(val) {
|
|
1722
|
+
if (my_dash_default.isBoolean(val)) return true;
|
|
1723
|
+
return new ValidationError("Value must be `true` or `false`");
|
|
1724
|
+
}
|
|
1725
|
+
});
|
|
1726
|
+
var UrlDataType = createEnvGraphDataType(
|
|
1727
|
+
(settings) => ({
|
|
1728
|
+
name: "url",
|
|
1729
|
+
icon: "carbon:url",
|
|
1730
|
+
coerce(rawVal) {
|
|
1731
|
+
const val = coerceToString(rawVal);
|
|
1732
|
+
if (settings?.prependHttps && !val.startsWith("https://")) return `https://${val}`;
|
|
1733
|
+
return val;
|
|
1734
|
+
},
|
|
1735
|
+
validate(val) {
|
|
1736
|
+
const url = new URL(val);
|
|
1737
|
+
if (settings?.allowedDomains && !settings.allowedDomains.includes(url.host.toLowerCase())) {
|
|
1738
|
+
return new ValidationError(`Domain (${url.host}) is not in allowed list: ${settings.allowedDomains.join(",")}`);
|
|
1739
|
+
}
|
|
1740
|
+
return true;
|
|
1741
|
+
}
|
|
1742
|
+
})
|
|
1743
|
+
);
|
|
1744
|
+
var SimpleObjectDataType = createEnvGraphDataType({
|
|
1745
|
+
name: "simple-object",
|
|
1746
|
+
icon: "tabler:code-dots",
|
|
1747
|
+
// curly brackets with nothing inside
|
|
1748
|
+
coerce(val) {
|
|
1749
|
+
if (my_dash_default.isPlainObject(val)) return val;
|
|
1750
|
+
if (my_dash_default.isString(val)) {
|
|
1751
|
+
try {
|
|
1752
|
+
const parsedObj = JSON.parse(val);
|
|
1753
|
+
if (my_dash_default.isPlainObject(parsedObj)) return parsedObj;
|
|
1754
|
+
return new CoercionError("Unable to coerce JSON parsed string to object");
|
|
1755
|
+
} catch (err) {
|
|
1756
|
+
return new CoercionError("Error parsing JSON string while coercing string to object");
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
return new CoercionError("Cannot coerce value to object");
|
|
1760
|
+
},
|
|
1761
|
+
validate(val) {
|
|
1762
|
+
if (my_dash_default.isPlainObject(val)) return true;
|
|
1763
|
+
return new ValidationError("Value must be an object");
|
|
1764
|
+
}
|
|
1765
|
+
});
|
|
1766
|
+
var EnumDataType = createEnvGraphDataType(
|
|
1767
|
+
(...enumOptions) => ({
|
|
1768
|
+
name: "enum",
|
|
1769
|
+
icon: "material-symbols-light:category",
|
|
1770
|
+
// a few shapes... not sure about this one
|
|
1771
|
+
coerce(val) {
|
|
1772
|
+
if (my_dash_default.isString(val) || my_dash_default.isNumber(val) || my_dash_default.isBoolean(val)) return val;
|
|
1773
|
+
return new CoercionError("Value must be a string, number, or boolean");
|
|
1774
|
+
},
|
|
1775
|
+
validate(val) {
|
|
1776
|
+
const possibleValues = enumOptions || [];
|
|
1777
|
+
if (!possibleValues.includes(val)) {
|
|
1778
|
+
throw new ValidationError("Current value is not in list of possible values", {
|
|
1779
|
+
tip: `Possible values are: "${possibleValues.join('", "')}"`
|
|
1780
|
+
});
|
|
1781
|
+
}
|
|
1782
|
+
},
|
|
1783
|
+
_rawEnumOptions: enumOptions
|
|
1784
|
+
})
|
|
1785
|
+
);
|
|
1786
|
+
var EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
1787
|
+
var EmailDataType = createEnvGraphDataType(
|
|
1788
|
+
(settings) => ({
|
|
1789
|
+
name: "email",
|
|
1790
|
+
icon: "iconoir:at-sign",
|
|
1791
|
+
typeDescription: "standard email address",
|
|
1792
|
+
coerce(rawVal) {
|
|
1793
|
+
let val = coerceToString(rawVal);
|
|
1794
|
+
if (settings?.normalize) val = val.toLowerCase();
|
|
1795
|
+
return val;
|
|
1796
|
+
},
|
|
1797
|
+
validate(val) {
|
|
1798
|
+
const result = EMAIL_REGEX.test(val);
|
|
1799
|
+
if (result) return true;
|
|
1800
|
+
return new ValidationError("Value must be a valid email address");
|
|
1801
|
+
}
|
|
1802
|
+
})
|
|
1803
|
+
);
|
|
1804
|
+
var IP_V4_ADDRESS_REGEX = /^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/;
|
|
1805
|
+
var IP_V6_ADDRESS_REGEX = /^(?:(?:[a-fA-F\d]{1,4}:){7}(?:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,2}|:)|(?:[a-fA-F\d]{1,4}:){4}(?:(?::[a-fA-F\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,3}|:)|(?:[a-fA-F\d]{1,4}:){3}(?:(?::[a-fA-F\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,4}|:)|(?:[a-fA-F\d]{1,4}:){2}(?:(?::[a-fA-F\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,5}|:)|(?:[a-fA-F\d]{1,4}:){1}(?:(?::[a-fA-F\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,6}|:)|(?::(?:(?::[a-fA-F\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$/;
|
|
1806
|
+
var ipAddressDataType = createEnvGraphDataType(
|
|
1807
|
+
(settings) => ({
|
|
1808
|
+
name: "ip",
|
|
1809
|
+
icon: "iconoir:ip-address-tag",
|
|
1810
|
+
typeDescription: "ip v4 or v6 address",
|
|
1811
|
+
coerce(rawVal) {
|
|
1812
|
+
let val = coerceToString(rawVal);
|
|
1813
|
+
if (settings?.normalize) val = val.toLowerCase();
|
|
1814
|
+
return val;
|
|
1815
|
+
},
|
|
1816
|
+
validate(val) {
|
|
1817
|
+
const regex = settings?.version === 6 ? IP_V6_ADDRESS_REGEX : IP_V4_ADDRESS_REGEX;
|
|
1818
|
+
const result = regex.test(val);
|
|
1819
|
+
if (result) return true;
|
|
1820
|
+
return new ValidationError("Value must be a valid IP address");
|
|
1821
|
+
}
|
|
1822
|
+
})
|
|
1823
|
+
);
|
|
1824
|
+
var PortDataType = createEnvGraphDataType(
|
|
1825
|
+
(settings) => ({
|
|
1826
|
+
name: "port",
|
|
1827
|
+
icon: "material-symbols:captive-portal",
|
|
1828
|
+
//! globe with arrow - not sure about this one
|
|
1829
|
+
typeDescription: "valid port number between 0 and 65535",
|
|
1830
|
+
coerce(rawVal) {
|
|
1831
|
+
if (my_dash_default.isString(rawVal)) {
|
|
1832
|
+
if (rawVal.includes(".")) throw new CoercionError("Port number must be an integer");
|
|
1833
|
+
if (rawVal.includes("e")) throw new CoercionError("Port number should be an integer, not in exponential notation");
|
|
1834
|
+
}
|
|
1835
|
+
return coerceToNumber(rawVal);
|
|
1836
|
+
},
|
|
1837
|
+
validate(val) {
|
|
1838
|
+
if (settings?.min !== void 0 && val < settings?.min) {
|
|
1839
|
+
return new ValidationError(`Min value is ${settings?.min}`);
|
|
1840
|
+
}
|
|
1841
|
+
if (settings?.max !== void 0 && val > settings?.max) {
|
|
1842
|
+
return new ValidationError(`Max value is ${settings?.max}`);
|
|
1843
|
+
}
|
|
1844
|
+
if (val < 0 || val > 65535) {
|
|
1845
|
+
return new ValidationError("Value must be a valid port number (0-65535)");
|
|
1846
|
+
}
|
|
1847
|
+
return true;
|
|
1848
|
+
}
|
|
1849
|
+
})
|
|
1850
|
+
);
|
|
1851
|
+
var SEMVER_REGEX = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
1852
|
+
var SemverDataType = createEnvGraphDataType(
|
|
1853
|
+
(settings) => ({
|
|
1854
|
+
name: "semver",
|
|
1855
|
+
icon: "simple-icons:semver",
|
|
1856
|
+
typeDescription: "semantic version string",
|
|
1857
|
+
validate(val) {
|
|
1858
|
+
const result = SEMVER_REGEX.test(val);
|
|
1859
|
+
if (result) return true;
|
|
1860
|
+
return new ValidationError("Value must be a valid semantic version string");
|
|
1861
|
+
}
|
|
1862
|
+
})
|
|
1863
|
+
);
|
|
1864
|
+
var ISO_DATE_REGEX = /^(?:[+-]?\d{4}(?!\d{2}\b))(?:(-?)(?:(?:0[1-9]|1[0-2])(?:\1(?:[12]\d|0[1-9]|3[01]))?|W(?:[0-4]\d|5[0-2])(?:-?[1-7])?|(?:00[1-9]|0[1-9]\d|[12]\d{2}|3(?:[0-5]\d|6[1-6])))(?:[T\s](?:(?:(?:[01]\d|2[0-3])(?:(:?)[0-5]\d)?|24:?00)(?:[.,]\d+(?!:))?)?(?:\2[0-5]\d(?:[.,]\d+)?)?(?:[zZ]|(?:[+-])(?:[01]\d|2[0-3]):?(?:[0-5]\d)?)?)?)?$/;
|
|
1865
|
+
var IsoDateDataType = createEnvGraphDataType({
|
|
1866
|
+
name: "isoDate",
|
|
1867
|
+
icon: "formkit:datetime",
|
|
1868
|
+
typeDescription: "ISO 8601 date string with optional time and milliseconds",
|
|
1869
|
+
validate(val) {
|
|
1870
|
+
const result = ISO_DATE_REGEX.test(val);
|
|
1871
|
+
if (result) return true;
|
|
1872
|
+
return new ValidationError("Value must be a valid ISO 8601 date string");
|
|
1873
|
+
}
|
|
1874
|
+
});
|
|
1875
|
+
var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
1876
|
+
var UuidDataType = createEnvGraphDataType({
|
|
1877
|
+
name: "uuid",
|
|
1878
|
+
icon: "mdi:identifier",
|
|
1879
|
+
typeDescription: "UUID string V1-V5 per RFC4122, including NIL",
|
|
1880
|
+
validate(val) {
|
|
1881
|
+
const result = UUID_REGEX.test(val);
|
|
1882
|
+
if (result) return true;
|
|
1883
|
+
return new ValidationError("Value must be a valid UUID string");
|
|
1884
|
+
}
|
|
1885
|
+
});
|
|
1886
|
+
var MD5_REGEX = /^[a-f0-9]{32}$/;
|
|
1887
|
+
var Md5DataType = createEnvGraphDataType({
|
|
1888
|
+
name: "md5",
|
|
1889
|
+
typeDescription: "MD5 hash string",
|
|
1890
|
+
validate(val) {
|
|
1891
|
+
const result = MD5_REGEX.test(val);
|
|
1892
|
+
if (result) return true;
|
|
1893
|
+
return new ValidationError("Value must be a valid MD5 hash string");
|
|
1894
|
+
}
|
|
1895
|
+
});
|
|
1896
|
+
var BaseDataTypes = {
|
|
1897
|
+
string: StringDataType,
|
|
1898
|
+
number: NumberDataType,
|
|
1899
|
+
boolean: BooleanDataType,
|
|
1900
|
+
simpleObject: SimpleObjectDataType,
|
|
1901
|
+
enum: EnumDataType,
|
|
1902
|
+
email: EmailDataType,
|
|
1903
|
+
url: UrlDataType,
|
|
1904
|
+
ipAddress: ipAddressDataType,
|
|
1905
|
+
port: PortDataType,
|
|
1906
|
+
semver: SemverDataType,
|
|
1907
|
+
isoDate: IsoDateDataType,
|
|
1908
|
+
uuid: UuidDataType,
|
|
1909
|
+
md5: Md5DataType
|
|
1910
|
+
};
|
|
1911
|
+
|
|
1912
|
+
// ../env-graph/src/lib/graph-utils.ts
|
|
1913
|
+
function findGraphCycles(graph) {
|
|
1914
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1915
|
+
const recursionStack = /* @__PURE__ */ new Set();
|
|
1916
|
+
const cycles = [];
|
|
1917
|
+
const currentPath = [];
|
|
1918
|
+
function dfs(node) {
|
|
1919
|
+
if (recursionStack.has(node)) {
|
|
1920
|
+
const cycleStart = currentPath.indexOf(node);
|
|
1921
|
+
const cycle = currentPath.slice(cycleStart);
|
|
1922
|
+
cycles.push(cycle);
|
|
1923
|
+
return;
|
|
1924
|
+
}
|
|
1925
|
+
if (visited.has(node)) {
|
|
1926
|
+
return;
|
|
1927
|
+
}
|
|
1928
|
+
visited.add(node);
|
|
1929
|
+
recursionStack.add(node);
|
|
1930
|
+
currentPath.push(node);
|
|
1931
|
+
for (const neighbor of graph[node] || []) {
|
|
1932
|
+
dfs(neighbor);
|
|
1933
|
+
}
|
|
1934
|
+
recursionStack.delete(node);
|
|
1935
|
+
currentPath.pop();
|
|
1936
|
+
}
|
|
1937
|
+
__name(dfs, "dfs");
|
|
1938
|
+
for (const node of Object.keys(graph)) {
|
|
1939
|
+
if (!visited.has(node)) {
|
|
1940
|
+
dfs(node);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
return cycles;
|
|
1944
|
+
}
|
|
1945
|
+
__name(findGraphCycles, "findGraphCycles");
|
|
1946
|
+
var AUTOGENERATED_FILE_BANNER = `
|
|
1947
|
+
// \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1}
|
|
1948
|
+
// \u{1F6D1} THIS IS AN AUTOGENERATED FILE - DO NOT EDIT DIRECTLY \u{1F6D1}
|
|
1949
|
+
// \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1} \u{1F6D1}
|
|
1950
|
+
`;
|
|
1951
|
+
var ICON_SIZE = 20;
|
|
1952
|
+
var iconCacheFolderInit = false;
|
|
1953
|
+
var iconInMemoryCache = {};
|
|
1954
|
+
async function fetchIconSvg(iconifyName, color = "808080", iconCacheFolder = "/tmp/varlock-icon-cache") {
|
|
1955
|
+
if (!iconCacheFolderInit) {
|
|
1956
|
+
fs2.mkdirSync(iconCacheFolder, { recursive: true });
|
|
1957
|
+
iconCacheFolderInit = true;
|
|
1958
|
+
}
|
|
1959
|
+
const iconPath = `${iconCacheFolder}/${iconifyName}-${ICON_SIZE}.svg`;
|
|
1960
|
+
let svgSrc;
|
|
1961
|
+
if (iconInMemoryCache[iconPath]) {
|
|
1962
|
+
svgSrc = iconInMemoryCache[iconPath];
|
|
1963
|
+
} else if (fs2.existsSync(iconPath)) {
|
|
1964
|
+
const svgFileBuffer = await fs2.promises.readFile(iconPath, "utf-8");
|
|
1965
|
+
svgSrc = svgFileBuffer.toString();
|
|
1966
|
+
iconInMemoryCache[iconPath] = svgSrc;
|
|
1967
|
+
} else {
|
|
1968
|
+
try {
|
|
1969
|
+
const iconSvg = await fetch(`https://api.iconify.design/${iconifyName.replace(":", "/")}.svg?height=${ICON_SIZE}`);
|
|
1970
|
+
svgSrc = await iconSvg.text();
|
|
1971
|
+
} catch (err) {
|
|
1972
|
+
return;
|
|
1973
|
+
}
|
|
1974
|
+
if (!svgSrc) return;
|
|
1975
|
+
if (svgSrc) {
|
|
1976
|
+
await fs2.promises.writeFile(iconPath, svgSrc, "utf-8");
|
|
1977
|
+
iconInMemoryCache[iconPath] = svgSrc;
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
const hexColor = color.startsWith("#") ? color : `#${color}`;
|
|
1981
|
+
const colorizedSvg = svgSrc.replaceAll("currentColor", hexColor);
|
|
1982
|
+
return colorizedSvg;
|
|
1983
|
+
}
|
|
1984
|
+
__name(fetchIconSvg, "fetchIconSvg");
|
|
1985
|
+
async function getTsDefinitionForItem(item, indentLevel = 0) {
|
|
1986
|
+
const i = my_dash_default.times(indentLevel, () => " ").join("");
|
|
1987
|
+
const itemSrc = [];
|
|
1988
|
+
const jsDocLines = [];
|
|
1989
|
+
jsDocLines.push(`**${item.key}**${item.isSensitive ? " \u{1F510} _sensitive_" : ""}`);
|
|
1990
|
+
if (item.description) jsDocLines.push(...item.description.split("\n"));
|
|
1991
|
+
const iconName = item.icon;
|
|
1992
|
+
if (iconName) {
|
|
1993
|
+
const iconSvg = await fetchIconSvg(iconName);
|
|
1994
|
+
if (iconSvg) jsDocLines.push(`}) `);
|
|
1995
|
+
}
|
|
1996
|
+
const docsLinks = item.docsLinks;
|
|
1997
|
+
if (docsLinks.length) {
|
|
1998
|
+
jsDocLines.push("");
|
|
1999
|
+
docsLinks.forEach((docsEntry) => {
|
|
2000
|
+
const docsLink = my_dash_default.compact([docsEntry.url, docsEntry.description]).join(" | ");
|
|
2001
|
+
jsDocLines.push(`\u{1F4DA} {@link ${docsLink}}`);
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
if (jsDocLines.length === 1) {
|
|
2005
|
+
itemSrc.push(`/** ${jsDocLines[0]} */`);
|
|
2006
|
+
} else if (jsDocLines.length > 1) {
|
|
2007
|
+
itemSrc.push(...[
|
|
2008
|
+
"/**",
|
|
2009
|
+
// extra 2 trailing spaces are needed to make line breaks visible
|
|
2010
|
+
...my_dash_default.flatMap(jsDocLines, (line) => [` * ${line} `]),
|
|
2011
|
+
" */"
|
|
2012
|
+
]);
|
|
2013
|
+
}
|
|
2014
|
+
const dataType = item.dataType;
|
|
2015
|
+
const dataTypeName = dataType?.name;
|
|
2016
|
+
let itemTsType = "string";
|
|
2017
|
+
if (dataType) {
|
|
2018
|
+
if (dataTypeName === "number" || dataTypeName === "port") {
|
|
2019
|
+
itemTsType = "number";
|
|
2020
|
+
} else if (dataTypeName === "boolean") {
|
|
2021
|
+
itemTsType = "boolean";
|
|
2022
|
+
} else if (dataTypeName === "simple-object") {
|
|
2023
|
+
itemTsType = "Record<string, any>";
|
|
2024
|
+
} else if (dataTypeName === "enum") {
|
|
2025
|
+
const rawEnumOptions = dataType._rawDef._rawEnumOptions;
|
|
2026
|
+
let enumOptions = [];
|
|
2027
|
+
enumOptions = rawEnumOptions;
|
|
2028
|
+
if (!enumOptions.length) {
|
|
2029
|
+
itemTsType = "never";
|
|
2030
|
+
} else {
|
|
2031
|
+
itemTsType = my_dash_default.map(enumOptions, JSON.stringify).join(" | ");
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
itemSrc.push(`readonly ${item.key}${item.isRequired ? "" : "?"}: ${itemTsType};`);
|
|
2036
|
+
itemSrc.push("");
|
|
2037
|
+
return my_dash_default.map(itemSrc, (line) => `${i}${line}`);
|
|
2038
|
+
}
|
|
2039
|
+
__name(getTsDefinitionForItem, "getTsDefinitionForItem");
|
|
2040
|
+
async function generateTsTypesSrc(graph) {
|
|
2041
|
+
const tsSrc = [
|
|
2042
|
+
AUTOGENERATED_FILE_BANNER,
|
|
2043
|
+
// might want to add some options to let users inject this, or somehow detect eslint, but fine for now
|
|
2044
|
+
"/* eslint-disable */",
|
|
2045
|
+
"export type CoercedEnvSchema = {"
|
|
2046
|
+
];
|
|
2047
|
+
const exposedNonSensitiveKeys = [];
|
|
2048
|
+
for (const itemKey in graph.configSchema) {
|
|
2049
|
+
const configItem = graph.configSchema[itemKey];
|
|
2050
|
+
tsSrc.push(...await getTsDefinitionForItem(configItem, 1));
|
|
2051
|
+
if (!configItem.isSensitive) exposedNonSensitiveKeys.push(itemKey);
|
|
2052
|
+
}
|
|
2053
|
+
tsSrc.push("};\n");
|
|
2054
|
+
tsSrc.push(`
|
|
2055
|
+
declare module 'varlock' {
|
|
2056
|
+
export interface TypedEnvSchema extends CoercedEnvSchema {}
|
|
2057
|
+
|
|
2058
|
+
export interface PublicTypedEnvSchema extends Pick<CoercedEnvSchema, '${exposedNonSensitiveKeys.join("' | '")}'> {}
|
|
2059
|
+
}
|
|
2060
|
+
`);
|
|
2061
|
+
return tsSrc.join("\n");
|
|
2062
|
+
}
|
|
2063
|
+
__name(generateTsTypesSrc, "generateTsTypesSrc");
|
|
2064
|
+
async function generateTypes(graph, lang, outputPath) {
|
|
2065
|
+
if (lang !== "ts") throw new Error(`Unsupported @generateTypes lang: ${lang}`);
|
|
2066
|
+
const tsSrc = await generateTsTypesSrc(graph);
|
|
2067
|
+
if (!graph.basePath) return;
|
|
2068
|
+
const typesPath = path.join(graph.basePath, outputPath);
|
|
2069
|
+
await fs2.promises.writeFile(typesPath, tsSrc, "utf-8");
|
|
2070
|
+
}
|
|
2071
|
+
__name(generateTypes, "generateTypes");
|
|
2072
|
+
|
|
2073
|
+
// ../env-graph/src/lib/env-graph.ts
|
|
2074
|
+
var EnvGraph = class {
|
|
2075
|
+
static {
|
|
2076
|
+
__name(this, "EnvGraph");
|
|
2077
|
+
}
|
|
2078
|
+
// TODO: not sure if this should be the graph of _everything_ in a workspace/project
|
|
2079
|
+
// or just the files that are relevant to the current resolution attempt
|
|
2080
|
+
// (which would mean it's always through the lens of the current directory/package)
|
|
2081
|
+
basePath;
|
|
2082
|
+
/** array of data sources */
|
|
2083
|
+
dataSources = [];
|
|
2084
|
+
/** config item key of env flag (toggles env-specific data sources enabled) */
|
|
2085
|
+
envFlagKey;
|
|
2086
|
+
/** current value of the environment flag */
|
|
2087
|
+
envFlagValue;
|
|
2088
|
+
configSchema = {};
|
|
2089
|
+
addDataSource(dataSource) {
|
|
2090
|
+
dataSource.graph = this;
|
|
2091
|
+
this.dataSources.push(dataSource);
|
|
2092
|
+
}
|
|
2093
|
+
get schemaDataSource() {
|
|
2094
|
+
const schemas = this.dataSources.filter((f) => f.type === "schema");
|
|
2095
|
+
if (schemas.length > 1) throw new Error("Multiple schema data sources found");
|
|
2096
|
+
if (schemas.length === 0) return void 0;
|
|
2097
|
+
return schemas[0];
|
|
2098
|
+
}
|
|
2099
|
+
get sortedDataSources() {
|
|
2100
|
+
return my_dash_default.sortBy(this.dataSources, (f) => 10 * EnvGraphDataSource.DATA_SOURCE_TYPES[f.type].precedence + (f.applyForEnv ? 1 : 0));
|
|
2101
|
+
}
|
|
2102
|
+
registeredResolverFunctions = {};
|
|
2103
|
+
registerResolver(resolverClass) {
|
|
2104
|
+
const fnName = resolverClass.fnName;
|
|
2105
|
+
if (fnName in this.registeredResolverFunctions) {
|
|
2106
|
+
throw new Error(`Resolver ${fnName} already registered`);
|
|
2107
|
+
}
|
|
2108
|
+
this.registeredResolverFunctions[fnName] = resolverClass;
|
|
2109
|
+
}
|
|
2110
|
+
dataTypesRegistry = {};
|
|
2111
|
+
registerDataType(factory) {
|
|
2112
|
+
this.dataTypesRegistry[factory.dataTypeName] = factory;
|
|
2113
|
+
}
|
|
2114
|
+
constructor() {
|
|
2115
|
+
for (const dataType of my_dash_default.values(BaseDataTypes)) {
|
|
2116
|
+
this.registerDataType(dataType);
|
|
2117
|
+
}
|
|
2118
|
+
for (const resolverClass of BaseResolvers) {
|
|
2119
|
+
this.registerResolver(resolverClass);
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
async finishLoad() {
|
|
2123
|
+
const sortedDataSources = this.sortedDataSources;
|
|
2124
|
+
for (const source of sortedDataSources) {
|
|
2125
|
+
if (source.loadingError) {
|
|
2126
|
+
throw source.loadingError;
|
|
2127
|
+
}
|
|
2128
|
+
if (source.decorators?.envFlag) {
|
|
2129
|
+
if (source.applyForEnv) {
|
|
2130
|
+
throw new Error(`@envFlag cannot be set from within an env-specific data source - ${source.label}`);
|
|
2131
|
+
} else if (this.envFlagKey) {
|
|
2132
|
+
throw new Error("only a single @envFlag setting is allowed");
|
|
2133
|
+
} else {
|
|
2134
|
+
const envFlagKey = source.decorators.envFlag.simplifiedValue;
|
|
2135
|
+
if (!my_dash_default.isString(envFlagKey)) {
|
|
2136
|
+
throw new Error("@envFlag must be a string");
|
|
2137
|
+
} else {
|
|
2138
|
+
this.envFlagKey = envFlagKey;
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
if (source.applyForEnv) {
|
|
2143
|
+
if (!this.envFlagValue) {
|
|
2144
|
+
if (!this.envFlagKey) {
|
|
2145
|
+
throw new Error("You must specify the @envFlag in your schema to load any env-specific files");
|
|
2146
|
+
}
|
|
2147
|
+
if (!this.configSchema[this.envFlagKey]) {
|
|
2148
|
+
throw new Error(`@envFlag key ${this.envFlagKey} not found in schema`);
|
|
2149
|
+
}
|
|
2150
|
+
if (process.env[this.envFlagKey]) {
|
|
2151
|
+
this.envFlagValue = process.env[this.envFlagKey];
|
|
2152
|
+
} else {
|
|
2153
|
+
const envFlagResolver = this.configSchema[this.envFlagKey].valueResolver;
|
|
2154
|
+
if (envFlagResolver instanceof StaticValueResolver) {
|
|
2155
|
+
if (!my_dash_default.isString(envFlagResolver.staticValue)) throw new Error("expected a static string value for envFlag");
|
|
2156
|
+
this.envFlagValue = envFlagResolver.staticValue;
|
|
2157
|
+
} else {
|
|
2158
|
+
throw new Error("envFlag value must be a static string");
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
if (source.applyForEnv && this.envFlagValue !== source.applyForEnv) {
|
|
2163
|
+
source.disabled = true;
|
|
2164
|
+
continue;
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
for (const itemKey in source.configItemDefs) {
|
|
2168
|
+
if (source.ignoreNewDefs && !this.configSchema[itemKey]) continue;
|
|
2169
|
+
const itemDef = source.configItemDefs[itemKey];
|
|
2170
|
+
this.configSchema[itemKey] ??= new ConfigItem(this, itemKey);
|
|
2171
|
+
this.configSchema[itemKey].addDef(itemDef, source);
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
for (const itemKey in this.configSchema) {
|
|
2175
|
+
const item = this.configSchema[itemKey];
|
|
2176
|
+
await item.process();
|
|
2177
|
+
}
|
|
2178
|
+
const cycles = findGraphCycles(this.graphAdjacencyList);
|
|
2179
|
+
for (const cycleItemKeys of cycles) {
|
|
2180
|
+
for (const itemKey of cycleItemKeys) {
|
|
2181
|
+
const item = this.configSchema[itemKey];
|
|
2182
|
+
item.schemaErrors.push(
|
|
2183
|
+
new SchemaError(
|
|
2184
|
+
cycleItemKeys.length === 1 ? "Item cannot have dependency on itself" : `Dependency cycle detected: (${cycleItemKeys.join(", ")})`
|
|
2185
|
+
)
|
|
2186
|
+
);
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
get graphAdjacencyList() {
|
|
2191
|
+
const adjList = {};
|
|
2192
|
+
for (const itemKey in this.configSchema) {
|
|
2193
|
+
const item = this.configSchema[itemKey];
|
|
2194
|
+
adjList[itemKey] = item.valueResolver?.deps || [];
|
|
2195
|
+
}
|
|
2196
|
+
return adjList;
|
|
2197
|
+
}
|
|
2198
|
+
async resolveEnvValues() {
|
|
2199
|
+
const adjList = this.graphAdjacencyList;
|
|
2200
|
+
const reverseAdjList = {};
|
|
2201
|
+
for (const itemKey in adjList) {
|
|
2202
|
+
const itemDeps = adjList[itemKey];
|
|
2203
|
+
for (const dep of itemDeps) {
|
|
2204
|
+
reverseAdjList[dep] ??= [];
|
|
2205
|
+
reverseAdjList[dep].push(itemKey);
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
const itemsToResolveStatus = my_dash_default.mapValues(this.configSchema, () => false);
|
|
2209
|
+
const deferred = new Promise((resolve, reject) => {
|
|
2210
|
+
const markItemCompleted = /* @__PURE__ */ __name((itemKey) => {
|
|
2211
|
+
delete itemsToResolveStatus[itemKey];
|
|
2212
|
+
if (reverseAdjList[itemKey]) {
|
|
2213
|
+
reverseAdjList[itemKey].forEach(resolveItem);
|
|
2214
|
+
}
|
|
2215
|
+
if (my_dash_default.keys(itemsToResolveStatus).length === 0) resolve();
|
|
2216
|
+
}, "markItemCompleted");
|
|
2217
|
+
const resolveItem = /* @__PURE__ */ __name(async (itemKey) => {
|
|
2218
|
+
if (itemsToResolveStatus[itemKey] !== false) return;
|
|
2219
|
+
const item = this.configSchema[itemKey];
|
|
2220
|
+
if (item.errors.length) {
|
|
2221
|
+
markItemCompleted(itemKey);
|
|
2222
|
+
return;
|
|
2223
|
+
}
|
|
2224
|
+
for (const depKey of adjList[itemKey]) {
|
|
2225
|
+
const depItem = this.configSchema[depKey];
|
|
2226
|
+
if (depItem.validationState === "error") {
|
|
2227
|
+
item.resolutionError = new ResolutionError(`Dependency ${depKey} is invalid`);
|
|
2228
|
+
markItemCompleted(itemKey);
|
|
2229
|
+
return;
|
|
2230
|
+
} else if (depKey in itemsToResolveStatus) {
|
|
2231
|
+
return;
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
itemsToResolveStatus[itemKey] = true;
|
|
2235
|
+
await item.resolve();
|
|
2236
|
+
markItemCompleted(itemKey);
|
|
2237
|
+
}, "resolveItem");
|
|
2238
|
+
for (const itemKey in this.configSchema) {
|
|
2239
|
+
resolveItem(itemKey);
|
|
2240
|
+
}
|
|
2241
|
+
});
|
|
2242
|
+
return deferred;
|
|
2243
|
+
}
|
|
2244
|
+
getResolvedEnvObject() {
|
|
2245
|
+
const envObject = {};
|
|
2246
|
+
for (const itemKey in this.configSchema) {
|
|
2247
|
+
const item = this.configSchema[itemKey];
|
|
2248
|
+
envObject[itemKey] = item.resolvedValue;
|
|
2249
|
+
}
|
|
2250
|
+
return envObject;
|
|
2251
|
+
}
|
|
2252
|
+
get isInvalid() {
|
|
2253
|
+
return my_dash_default.some(my_dash_default.values(this.configSchema), (i) => !i.isValid);
|
|
2254
|
+
}
|
|
2255
|
+
async generateTypes(lang, outputPath) {
|
|
2256
|
+
await generateTypes(this, lang, outputPath);
|
|
2257
|
+
}
|
|
2258
|
+
};
|
|
2259
|
+
var SKIP_FILE_TYPES = [".md", ".d.ts"];
|
|
2260
|
+
async function findEnvFiles(opts) {
|
|
2261
|
+
const cwd = opts?.cwd || process.cwd();
|
|
2262
|
+
const envFiles = [];
|
|
2263
|
+
const filesWithinDir = await fs.readdir(cwd);
|
|
2264
|
+
for (const fileName of filesWithinDir) {
|
|
2265
|
+
if (fileName.startsWith(".env")) {
|
|
2266
|
+
let skip = false;
|
|
2267
|
+
for (const fileType of SKIP_FILE_TYPES) {
|
|
2268
|
+
if (fileName.endsWith(fileType)) skip = true;
|
|
2269
|
+
}
|
|
2270
|
+
if (skip) continue;
|
|
2271
|
+
envFiles.push(path.join(cwd, fileName));
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
return envFiles;
|
|
2275
|
+
}
|
|
2276
|
+
__name(findEnvFiles, "findEnvFiles");
|
|
2277
|
+
|
|
2278
|
+
// ../env-graph/src/lib/loader.ts
|
|
2279
|
+
function autoDetectContextPath() {
|
|
2280
|
+
const PWD = process.env.PWD;
|
|
2281
|
+
if (!PWD) {
|
|
2282
|
+
throw new Error("PWD is not set");
|
|
2283
|
+
}
|
|
2284
|
+
return PWD;
|
|
2285
|
+
}
|
|
2286
|
+
__name(autoDetectContextPath, "autoDetectContextPath");
|
|
2287
|
+
async function loadEnvGraph(opts) {
|
|
2288
|
+
const contextPath = opts?.contextPath ?? autoDetectContextPath();
|
|
2289
|
+
const graph = new EnvGraph();
|
|
2290
|
+
graph.basePath = contextPath;
|
|
2291
|
+
if (opts?.afterInit) {
|
|
2292
|
+
await opts.afterInit(graph);
|
|
2293
|
+
}
|
|
2294
|
+
const envFilePaths = await findEnvFiles({
|
|
2295
|
+
cwd: contextPath
|
|
2296
|
+
});
|
|
2297
|
+
for (const envFilePath of envFilePaths) {
|
|
2298
|
+
const fileDataSource = new DotEnvFileDataSource(envFilePath);
|
|
2299
|
+
graph.addDataSource(fileDataSource);
|
|
2300
|
+
await fileDataSource.finishInit();
|
|
2301
|
+
}
|
|
2302
|
+
graph.addDataSource(new ProcessEnvDataSource());
|
|
2303
|
+
await graph.finishLoad();
|
|
2304
|
+
return graph;
|
|
2305
|
+
}
|
|
2306
|
+
__name(loadEnvGraph, "loadEnvGraph");
|
|
2307
|
+
|
|
2308
|
+
export { DotEnvFileDataSource, EnvSourceParseError, StaticValueResolver, checkIsFileGitIgnored, loadEnvGraph, my_dash_default };
|
|
2309
|
+
//# sourceMappingURL=chunk-HZADDTO5.js.map
|
|
2310
|
+
//# sourceMappingURL=chunk-HZADDTO5.js.map
|