varlock 0.0.4 → 0.0.6
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/dist/auto-load.js +5 -6
- package/dist/chunk-33ROL4J5.js.map +1 -1
- package/dist/chunk-3NTATUIY.js +17 -0
- package/dist/chunk-3NTATUIY.js.map +1 -0
- package/dist/{chunk-DHFEY3C4.js → chunk-46HUIBFX.js} +30 -7
- package/dist/chunk-46HUIBFX.js.map +1 -0
- package/dist/{chunk-7UQXFWKN.js → chunk-5URKU5HG.js} +93 -3
- package/dist/chunk-5URKU5HG.js.map +1 -0
- package/dist/{chunk-C273RDM5.js → chunk-656FP6YP.js} +10 -8
- package/dist/chunk-656FP6YP.js.map +1 -0
- package/dist/{chunk-XPHGSDAF.js → chunk-7TXRGZZC.js} +3 -4
- package/dist/chunk-7TXRGZZC.js.map +1 -0
- package/dist/chunk-ANHWU7RB.js +59 -0
- package/dist/chunk-ANHWU7RB.js.map +1 -0
- package/dist/{chunk-VN64D2EQ.js → chunk-ASGIMFTP.js} +3 -4
- package/dist/chunk-ASGIMFTP.js.map +1 -0
- package/dist/{chunk-ZIN4KXR6.js → chunk-BIYA4LBB.js} +10 -9
- package/dist/chunk-BIYA4LBB.js.map +1 -0
- package/dist/chunk-DAZNZPLN.js.map +1 -1
- package/dist/chunk-FGMXIEFA.js.map +1 -1
- package/dist/{chunk-DOIKZ3NG.js → chunk-HBCSJWPN.js} +6 -6
- package/dist/chunk-HBCSJWPN.js.map +1 -0
- package/dist/{chunk-H2TT4DP5.js → chunk-HH7DAS63.js} +17 -161
- package/dist/chunk-HH7DAS63.js.map +1 -0
- package/dist/{chunk-NN3XFBPE.js → chunk-I3J2UCH7.js} +3 -3
- package/dist/chunk-I3J2UCH7.js.map +1 -0
- package/dist/{chunk-DROJWTCD.js → chunk-INMYFAWB.js} +1401 -1434
- package/dist/chunk-INMYFAWB.js.map +1 -0
- package/dist/{chunk-A4AHZSZB.js → chunk-JX4PYL7V.js} +15 -27
- package/dist/chunk-JX4PYL7V.js.map +1 -0
- package/dist/chunk-LHTLO65N.js +99 -0
- package/dist/chunk-LHTLO65N.js.map +1 -0
- package/dist/{chunk-B4UBSMSZ.js → chunk-PUGFIZE3.js} +4 -3
- package/dist/chunk-PUGFIZE3.js.map +1 -0
- package/dist/{chunk-RCHPHIHX.js → chunk-RZT65DRA.js} +2 -2
- package/dist/chunk-RZT65DRA.js.map +1 -0
- package/dist/chunk-USSBWRQF.js +54 -0
- package/dist/chunk-USSBWRQF.js.map +1 -0
- package/dist/chunk-WGUFO7CT.js +193 -0
- package/dist/chunk-WGUFO7CT.js.map +1 -0
- package/dist/{chunk-SVDXBE6D.js → chunk-X3HJMANF.js} +3 -4
- package/dist/chunk-X3HJMANF.js.map +1 -0
- package/dist/chunk-YSPDPNBR.js +14 -0
- package/dist/{chunk-RUB5A7IC.js.map → chunk-YSPDPNBR.js.map} +1 -1
- package/dist/cli/cli-executable.js +702 -158
- package/dist/cli/cli-executable.js.map +1 -1
- package/dist/doctor.command-SBG4H7Z4.js +7 -0
- package/dist/{doctor.command-7BQSOQWW.js.map → doctor.command-SBG4H7Z4.js.map} +1 -1
- package/dist/dotenv-compat.js +5 -6
- package/dist/en-US-TSGNDI2P.js.map +1 -1
- package/dist/encrypt.command-AGHQ4KTI.js +7 -0
- package/dist/{encrypt.command-VGJABHNK.js.map → encrypt.command-AGHQ4KTI.js.map} +1 -1
- package/dist/env-B8lQt2sl.d.ts +42 -0
- package/dist/help.command-B7VWA53B.js +5 -0
- package/dist/{help.command-YZDL2VEQ.js.map → help.command-B7VWA53B.js.map} +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +11 -10
- package/dist/index.js.map +1 -1
- package/dist/init.command-3DHC5DNC.js +13 -0
- package/dist/{init.command-CY3ZOIGP.js.map → init.command-3DHC5DNC.js.map} +1 -1
- package/dist/ja-JP-UBPCQAAD.js.map +1 -1
- package/dist/load.command-CTOV5PYR.js +12 -0
- package/dist/{load.command-ZFNTAAJE.js.map → load.command-CTOV5PYR.js.map} +1 -1
- package/dist/login.command-UZBZIPP3.js +10 -0
- package/dist/{login.command-KYZ4FXS5.js.map → login.command-UZBZIPP3.js.map} +1 -1
- package/dist/run.command-5276KIMX.js +12 -0
- package/dist/{run.command-VRKI6ZVN.js.map → run.command-5276KIMX.js.map} +1 -1
- package/dist/runtime/env.d.ts +1 -27
- package/dist/runtime/env.js +1 -1
- package/dist/runtime/patch-console.js +2 -3
- package/dist/runtime/patch-response.js +2 -3
- package/dist/runtime/patch-server-response.js +2 -3
- package/dist/telemetry.command-UHJTZULL.js +10 -0
- package/dist/telemetry.command-UHJTZULL.js.map +1 -0
- package/package.json +5 -1
- package/dist/chunk-7UQXFWKN.js.map +0 -1
- package/dist/chunk-A4AHZSZB.js.map +0 -1
- package/dist/chunk-B4UBSMSZ.js.map +0 -1
- package/dist/chunk-C273RDM5.js.map +0 -1
- package/dist/chunk-CLVBJA4G.js +0 -107
- package/dist/chunk-CLVBJA4G.js.map +0 -1
- package/dist/chunk-DHFEY3C4.js.map +0 -1
- package/dist/chunk-DOIKZ3NG.js.map +0 -1
- package/dist/chunk-DROJWTCD.js.map +0 -1
- package/dist/chunk-GSRDZVQI.js +0 -26
- package/dist/chunk-GSRDZVQI.js.map +0 -1
- package/dist/chunk-H2TT4DP5.js.map +0 -1
- package/dist/chunk-NN3XFBPE.js.map +0 -1
- package/dist/chunk-QCC3P7BT.js +0 -39
- package/dist/chunk-QCC3P7BT.js.map +0 -1
- package/dist/chunk-RCHPHIHX.js.map +0 -1
- package/dist/chunk-RUB5A7IC.js +0 -14
- package/dist/chunk-SVDXBE6D.js.map +0 -1
- package/dist/chunk-VN64D2EQ.js.map +0 -1
- package/dist/chunk-XHOJF7U7.js +0 -12
- package/dist/chunk-XHOJF7U7.js.map +0 -1
- package/dist/chunk-XPHGSDAF.js.map +0 -1
- package/dist/chunk-ZIN4KXR6.js.map +0 -1
- package/dist/doctor.command-7BQSOQWW.js +0 -6
- package/dist/encrypt.command-VGJABHNK.js +0 -6
- package/dist/help.command-YZDL2VEQ.js +0 -5
- package/dist/init.command-CY3ZOIGP.js +0 -11
- package/dist/load.command-ZFNTAAJE.js +0 -10
- package/dist/login.command-KYZ4FXS5.js +0 -7
- package/dist/opt-out.command-Y4KUQ6PQ.js +0 -5
- package/dist/opt-out.command-Y4KUQ6PQ.js.map +0 -1
- package/dist/run.command-VRKI6ZVN.js +0 -10
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { __name } from './chunk-XN24GZXQ.js';
|
|
2
2
|
import { exec } from 'node:child_process';
|
|
3
3
|
import { promisify } from 'node:util';
|
|
4
|
-
import
|
|
4
|
+
import fs2 from 'node:fs/promises';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { ParsedEnvSpecStaticValue, ParsedEnvSpecFunctionCall, ParsedEnvSpecKeyValuePair, parseEnvSpecDotEnvFile } from '@env-spec/parser';
|
|
7
|
-
import
|
|
7
|
+
import fs from 'node:fs';
|
|
8
8
|
|
|
9
9
|
// ../../node_modules/.pnpm/@sindresorhus+is@7.0.1/node_modules/@sindresorhus/is/distribution/index.js
|
|
10
10
|
var typedArrayTypeNames = [
|
|
@@ -701,7 +701,7 @@ function mapValues(obj, fn) {
|
|
|
701
701
|
}
|
|
702
702
|
__name(mapValues, "mapValues");
|
|
703
703
|
function times(count, fn) {
|
|
704
|
-
return Array.from({ length: count }, (
|
|
704
|
+
return Array.from({ length: count }, (_3, i) => fn(i));
|
|
705
705
|
}
|
|
706
706
|
__name(times, "times");
|
|
707
707
|
function map(array, fn) {
|
|
@@ -747,8 +747,11 @@ async function checkIsFileGitIgnored(path4, warnIfNotGitRepo = false) {
|
|
|
747
747
|
await asyncExec(`git check-ignore ${path4} -q`);
|
|
748
748
|
return true;
|
|
749
749
|
} catch (err) {
|
|
750
|
-
|
|
751
|
-
if (
|
|
750
|
+
const stderr = err.stderr;
|
|
751
|
+
if (stderr.includes("command not found")) return void 0;
|
|
752
|
+
if (err.code === "ENOENT") return void 0;
|
|
753
|
+
if (stderr === "") return false;
|
|
754
|
+
if (stderr.includes("not a git repository")) {
|
|
752
755
|
if (warnIfNotGitRepo) {
|
|
753
756
|
console.log("\u{1F536} Your code is not currently in a git repository - run `git init` to initialize a new repo.");
|
|
754
757
|
}
|
|
@@ -880,1592 +883,1556 @@ var EmptyRequiredValueError = class extends ValidationError {
|
|
|
880
883
|
}
|
|
881
884
|
};
|
|
882
885
|
|
|
883
|
-
// ../env-graph/src/lib/
|
|
884
|
-
var
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
queue = [];
|
|
889
|
-
processing = false;
|
|
890
|
-
/** Add a task to the queue and return a promise that resolves when the task is complete */
|
|
891
|
-
async enqueue(task) {
|
|
892
|
-
return new Promise((resolve, reject) => {
|
|
893
|
-
this.queue.push(async () => {
|
|
894
|
-
try {
|
|
895
|
-
const result = await task();
|
|
896
|
-
resolve(result);
|
|
897
|
-
} catch (err) {
|
|
898
|
-
reject(err);
|
|
899
|
-
}
|
|
900
|
-
});
|
|
901
|
-
this.processQueue();
|
|
902
|
-
});
|
|
903
|
-
}
|
|
904
|
-
async processQueue() {
|
|
905
|
-
if (this.processing || this.queue.length === 0) {
|
|
906
|
-
return;
|
|
907
|
-
}
|
|
908
|
-
this.processing = true;
|
|
909
|
-
const task = this.queue.shift();
|
|
910
|
-
if (task) {
|
|
911
|
-
try {
|
|
912
|
-
await task();
|
|
913
|
-
} finally {
|
|
914
|
-
this.processing = false;
|
|
915
|
-
this.processQueue();
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
};
|
|
920
|
-
|
|
921
|
-
// ../env-graph/src/lib/resolver.ts
|
|
922
|
-
var execAsync = promisify(exec);
|
|
923
|
-
var Resolver = class {
|
|
924
|
-
constructor(fnArgs) {
|
|
925
|
-
this.fnArgs = fnArgs;
|
|
926
|
-
}
|
|
927
|
-
static {
|
|
928
|
-
__name(this, "Resolver");
|
|
929
|
-
}
|
|
930
|
-
static fnName;
|
|
931
|
-
inferredType;
|
|
932
|
-
_schemaErrors = [];
|
|
933
|
-
_depsObj = {};
|
|
934
|
-
get childResolvers() {
|
|
935
|
-
return this.fnArgs.flatMap((r) => my_dash_default.isPlainObject(r) ? my_dash_default.values(r) : r);
|
|
936
|
-
}
|
|
937
|
-
get schemaErrors() {
|
|
938
|
-
return [
|
|
939
|
-
...this._schemaErrors,
|
|
940
|
-
...this.childResolvers.flatMap((r) => r.schemaErrors)
|
|
941
|
-
];
|
|
942
|
-
}
|
|
943
|
-
get depsObj() {
|
|
944
|
-
const mergedDepsObj = { ...this._depsObj };
|
|
945
|
-
this.childResolvers.forEach((r) => Object.assign(mergedDepsObj, r.depsObj));
|
|
946
|
-
return mergedDepsObj;
|
|
947
|
-
}
|
|
948
|
-
get deps() {
|
|
949
|
-
return Object.keys(this.depsObj);
|
|
950
|
-
}
|
|
951
|
-
configItem;
|
|
952
|
-
async process(configItem) {
|
|
953
|
-
this.configItem = configItem;
|
|
954
|
-
try {
|
|
955
|
-
await this._process(configItem);
|
|
956
|
-
} catch (error) {
|
|
957
|
-
if (error instanceof SchemaError) {
|
|
958
|
-
this._schemaErrors.push(error);
|
|
959
|
-
} else if (error instanceof Error) {
|
|
960
|
-
this._schemaErrors.push(new SchemaError(error));
|
|
961
|
-
} else {
|
|
962
|
-
throw new Error(`Non-error thrown while processing resolver - ${error}`);
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
this.childResolvers.forEach((r) => r.process(configItem));
|
|
966
|
-
}
|
|
967
|
-
// meant to be used by subclass _process methods
|
|
968
|
-
addDep(key) {
|
|
969
|
-
this._depsObj[key] = true;
|
|
970
|
-
if (!this.configItem) throw new Error("expected configItem to be set");
|
|
971
|
-
if (!this.configItem.envGraph.configSchema[key]) {
|
|
972
|
-
this._schemaErrors.push(new SchemaError(`Unknown referenced key: ${key}`));
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
async resolve() {
|
|
976
|
-
const resolvedValue = await this._resolve();
|
|
977
|
-
return resolvedValue;
|
|
978
|
-
}
|
|
979
|
-
// meant to be used by subclass _resolve methods
|
|
980
|
-
getDepValue(key) {
|
|
981
|
-
const depItem = this.configItem?.envGraph.configSchema[key];
|
|
982
|
-
if (!depItem) throw new Error(`Expected to find item - ${key}`);
|
|
983
|
-
return depItem.resolvedValue;
|
|
984
|
-
}
|
|
985
|
-
};
|
|
986
|
-
var StaticValueResolver = class extends Resolver {
|
|
987
|
-
constructor(staticValue) {
|
|
988
|
-
super([]);
|
|
989
|
-
this.staticValue = staticValue;
|
|
990
|
-
if (staticValue !== void 0) {
|
|
991
|
-
this.inferredType = typeof staticValue;
|
|
992
|
-
}
|
|
886
|
+
// ../env-graph/src/lib/data-types.ts
|
|
887
|
+
var EnvGraphDataType = class {
|
|
888
|
+
constructor(def, factory) {
|
|
889
|
+
this.def = def;
|
|
890
|
+
this.factory = factory;
|
|
993
891
|
}
|
|
994
892
|
static {
|
|
995
|
-
__name(this, "
|
|
996
|
-
}
|
|
997
|
-
label = "static";
|
|
998
|
-
icon = "bi:dash";
|
|
999
|
-
async _resolve() {
|
|
1000
|
-
return this.staticValue;
|
|
893
|
+
__name(this, "EnvGraphDataType");
|
|
1001
894
|
}
|
|
1002
|
-
|
|
895
|
+
get name() {
|
|
896
|
+
return this.def.name;
|
|
1003
897
|
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
static {
|
|
1007
|
-
__name(this, "ErrorResolver");
|
|
898
|
+
get icon() {
|
|
899
|
+
return this.def.icon;
|
|
1008
900
|
}
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
this.
|
|
901
|
+
/** @internal */
|
|
902
|
+
get _rawDef() {
|
|
903
|
+
return this.def;
|
|
1012
904
|
}
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
async _resolve() {
|
|
1016
|
-
return void 0;
|
|
905
|
+
coerce(val) {
|
|
906
|
+
return this.def.coerce ? this.def.coerce(val) : val;
|
|
1017
907
|
}
|
|
1018
|
-
|
|
908
|
+
validate(val) {
|
|
909
|
+
return this.def.validate ? this.def.validate(val) : true;
|
|
1019
910
|
}
|
|
1020
911
|
};
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
912
|
+
function createEnvGraphDataType(dataTypeDef) {
|
|
913
|
+
const typeFactoryFn = /* @__PURE__ */ __name((...usageOpts) => {
|
|
914
|
+
return new EnvGraphDataType(
|
|
915
|
+
my_dash_default.isFunction(dataTypeDef) ? dataTypeDef(...usageOpts) : dataTypeDef,
|
|
916
|
+
typeFactoryFn
|
|
917
|
+
);
|
|
918
|
+
}, "typeFactoryFn");
|
|
919
|
+
typeFactoryFn._isEnvGraphDataTypeFactory = true;
|
|
920
|
+
const exampleInstance = typeFactoryFn(...[]);
|
|
921
|
+
typeFactoryFn.dataTypeName = exampleInstance.name;
|
|
922
|
+
return typeFactoryFn;
|
|
923
|
+
}
|
|
924
|
+
__name(createEnvGraphDataType, "createEnvGraphDataType");
|
|
925
|
+
function coerceToString(rawVal) {
|
|
926
|
+
if (rawVal === void 0 || rawVal === null) return "";
|
|
927
|
+
return my_dash_default.isString(rawVal) ? rawVal : String(rawVal);
|
|
928
|
+
}
|
|
929
|
+
__name(coerceToString, "coerceToString");
|
|
930
|
+
function coerceToNumber(rawVal) {
|
|
931
|
+
let numVal;
|
|
932
|
+
if (my_dash_default.isString(rawVal)) {
|
|
933
|
+
const parsed = parseFloat(rawVal);
|
|
934
|
+
if (my_dash_default.isNan(parsed) || parsed === Infinity || parsed === -Infinity) {
|
|
935
|
+
throw new CoercionError("Unable to coerce string to number");
|
|
1032
936
|
}
|
|
1033
|
-
|
|
1034
|
-
|
|
937
|
+
numVal = parsed;
|
|
938
|
+
} else if (my_dash_default.isNumber(rawVal)) {
|
|
939
|
+
if (numVal === Infinity || numVal === -Infinity) {
|
|
940
|
+
throw new CoercionError("Inifinity is not a valid number");
|
|
1035
941
|
}
|
|
942
|
+
numVal = rawVal;
|
|
943
|
+
} else {
|
|
944
|
+
throw new CoercionError(`Cannot convert ${rawVal} to number`);
|
|
1036
945
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
946
|
+
return numVal;
|
|
947
|
+
}
|
|
948
|
+
__name(coerceToNumber, "coerceToNumber");
|
|
949
|
+
var StringDataType = createEnvGraphDataType(
|
|
950
|
+
(settings) => ({
|
|
951
|
+
name: "string",
|
|
952
|
+
icon: "carbon:string-text",
|
|
953
|
+
coerce: /* @__PURE__ */ __name((rawVal) => {
|
|
954
|
+
let val = coerceToString(rawVal);
|
|
955
|
+
if (settings?.toUpperCase) val = val.toUpperCase();
|
|
956
|
+
if (settings?.toLowerCase) val = val.toLowerCase();
|
|
957
|
+
return val;
|
|
958
|
+
}, "coerce"),
|
|
959
|
+
validate: /* @__PURE__ */ __name((val) => {
|
|
960
|
+
const errors = [];
|
|
961
|
+
if (settings?.minLength !== void 0 && val.length < settings.minLength) {
|
|
962
|
+
errors.push(new ValidationError(`Length must be more than ${settings.minLength}`));
|
|
1042
963
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
}
|
|
1046
|
-
return resolvedValues.join("");
|
|
1047
|
-
}
|
|
1048
|
-
};
|
|
1049
|
-
var FallbackResolver = class extends Resolver {
|
|
1050
|
-
static {
|
|
1051
|
-
__name(this, "FallbackResolver");
|
|
1052
|
-
}
|
|
1053
|
-
static fnName = "fallback";
|
|
1054
|
-
label = "fallback";
|
|
1055
|
-
icon = "memory:table-top-stairs-up";
|
|
1056
|
-
async _process() {
|
|
1057
|
-
if (this.fnArgs.some((arg) => my_dash_default.isPlainObject(arg))) {
|
|
1058
|
-
throw new SchemaError("fallback() does not support key-value arguments");
|
|
1059
|
-
}
|
|
1060
|
-
if (this.fnArgs.length < 2) {
|
|
1061
|
-
throw new SchemaError("fallback() expects at least two arguments");
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
async _resolve() {
|
|
1065
|
-
for (const arg of this.fnArgs) {
|
|
1066
|
-
if (my_dash_default.isPlainObject(arg)) throw new Error("fallback() does not support key-value arguments");
|
|
1067
|
-
const resolvedChildValue = await arg.resolve();
|
|
1068
|
-
if (resolvedChildValue !== void 0 && resolvedChildValue !== "") {
|
|
1069
|
-
return resolvedChildValue;
|
|
964
|
+
if (settings?.maxLength !== void 0 && val.length > settings.maxLength) {
|
|
965
|
+
errors.push(new ValidationError(`Length must be less than ${settings.maxLength}`));
|
|
1070
966
|
}
|
|
967
|
+
if (settings?.isLength !== void 0 && val.length !== settings.isLength) {
|
|
968
|
+
errors.push(new ValidationError(`Length must be exactly ${settings.isLength}`));
|
|
969
|
+
}
|
|
970
|
+
if (settings?.startsWith && !val.startsWith(settings.startsWith)) {
|
|
971
|
+
errors.push(new ValidationError(`Value must start with "${settings.startsWith}"`));
|
|
972
|
+
}
|
|
973
|
+
if (settings?.endsWith && !val.endsWith(settings.endsWith)) {
|
|
974
|
+
errors.push(new ValidationError(`Value must start with "${settings.endsWith}"`));
|
|
975
|
+
}
|
|
976
|
+
if (settings?.matches) {
|
|
977
|
+
const regex = my_dash_default.isString(settings.matches) ? new RegExp(settings.matches) : settings.matches;
|
|
978
|
+
const matches = val.match(regex);
|
|
979
|
+
if (!matches) {
|
|
980
|
+
errors.push(new ValidationError(`Value must match regex "${settings.matches}"`));
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
return errors.length ? errors : true;
|
|
984
|
+
}, "validate")
|
|
985
|
+
})
|
|
986
|
+
);
|
|
987
|
+
var NumberDataType = createEnvGraphDataType(
|
|
988
|
+
(settings) => ({
|
|
989
|
+
name: "number",
|
|
990
|
+
icon: "carbon:string-integer",
|
|
991
|
+
coerce(rawVal) {
|
|
992
|
+
let numVal = coerceToNumber(rawVal);
|
|
993
|
+
if (settings?.coerceToMinMaxRange) {
|
|
994
|
+
if (settings?.min !== void 0) numVal = Math.max(settings?.min, numVal);
|
|
995
|
+
if (settings?.max !== void 0) numVal = Math.min(settings?.max, numVal);
|
|
996
|
+
}
|
|
997
|
+
if (settings?.isInt === true || settings?.precision === 0) {
|
|
998
|
+
numVal = Math.round(numVal);
|
|
999
|
+
} else if (settings?.precision) {
|
|
1000
|
+
const p = 10 ** settings.precision;
|
|
1001
|
+
numVal = Math.round(numVal * p) / p;
|
|
1002
|
+
}
|
|
1003
|
+
return numVal;
|
|
1004
|
+
},
|
|
1005
|
+
validate(val) {
|
|
1006
|
+
const errors = [];
|
|
1007
|
+
if (settings?.min !== void 0 && val < settings?.min) {
|
|
1008
|
+
errors.push(new ValidationError(`Min value is ${settings?.min}`));
|
|
1009
|
+
}
|
|
1010
|
+
if (settings?.max !== void 0 && val > settings?.max) {
|
|
1011
|
+
errors.push(new ValidationError(`Max value is ${settings?.max}`));
|
|
1012
|
+
}
|
|
1013
|
+
if (settings?.isDivisibleBy !== void 0 && val % settings.isDivisibleBy !== 0) {
|
|
1014
|
+
errors.push(new ValidationError(`Value must be divisible by ${settings?.isDivisibleBy}`));
|
|
1015
|
+
}
|
|
1016
|
+
return errors.length ? errors : true;
|
|
1071
1017
|
}
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
var
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
throw new ResolutionError("exec() expects a string child arg");
|
|
1095
|
-
}
|
|
1096
|
-
try {
|
|
1097
|
-
const { stdout, stderr } = await _ExecResolver.execQueue.enqueue(() => execAsync(commandStr));
|
|
1098
|
-
return stdout.replace(/\n$/, "");
|
|
1099
|
-
} catch (err) {
|
|
1100
|
-
console.log("exec() failed", err);
|
|
1101
|
-
throw new ResolutionError(`exec() command failed: ${commandStr}`);
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
};
|
|
1105
|
-
var RefResolver = class extends Resolver {
|
|
1106
|
-
static {
|
|
1107
|
-
__name(this, "RefResolver");
|
|
1108
|
-
}
|
|
1109
|
-
static fnName = "ref";
|
|
1110
|
-
label = "ref";
|
|
1111
|
-
icon = "mdi-light:content-duplicate";
|
|
1112
|
-
refKey;
|
|
1113
|
-
async _process() {
|
|
1114
|
-
if (this.fnArgs.length !== 1) {
|
|
1115
|
-
throw new SchemaError("ref() expects a single child arg");
|
|
1116
|
-
}
|
|
1117
|
-
if (!(this.fnArgs[0] instanceof StaticValueResolver)) {
|
|
1118
|
-
throw new SchemaError("ref() expects a single static value passed in");
|
|
1119
|
-
}
|
|
1120
|
-
const keyName = this.fnArgs[0].staticValue;
|
|
1121
|
-
if (typeof keyName !== "string") {
|
|
1122
|
-
throw new SchemaError("ref() expects a string keyname passed in");
|
|
1123
|
-
}
|
|
1124
|
-
this.refKey = keyName;
|
|
1125
|
-
this.addDep(keyName);
|
|
1126
|
-
}
|
|
1127
|
-
async _resolve() {
|
|
1128
|
-
if (!this.refKey) throw new Error("expected refKey to be set");
|
|
1129
|
-
return this.getDepValue(this.refKey);
|
|
1130
|
-
}
|
|
1131
|
-
};
|
|
1132
|
-
var RegexResolver = class extends Resolver {
|
|
1133
|
-
static {
|
|
1134
|
-
__name(this, "RegexResolver");
|
|
1135
|
-
}
|
|
1136
|
-
static fnName = "regex";
|
|
1137
|
-
label = "regex";
|
|
1138
|
-
icon = "mdi:regex";
|
|
1139
|
-
regex;
|
|
1140
|
-
async _process() {
|
|
1141
|
-
if (this.fnArgs.length !== 1) {
|
|
1142
|
-
throw new SchemaError("regex() expects a single child arg");
|
|
1143
|
-
}
|
|
1144
|
-
if (!(this.fnArgs[0] instanceof StaticValueResolver)) {
|
|
1145
|
-
throw new SchemaError("regex() expects a single static value passed in");
|
|
1146
|
-
}
|
|
1147
|
-
const regexStr = this.fnArgs[0].staticValue;
|
|
1148
|
-
if (typeof regexStr !== "string") {
|
|
1149
|
-
throw new SchemaError("regex() expects a string");
|
|
1150
|
-
}
|
|
1151
|
-
this.regex = new RegExp(regexStr);
|
|
1152
|
-
}
|
|
1153
|
-
async _resolve() {
|
|
1154
|
-
if (!this.regex) throw new Error("expected regex to be set");
|
|
1155
|
-
return this.regex;
|
|
1156
|
-
}
|
|
1157
|
-
};
|
|
1158
|
-
var RemapResolver = class extends Resolver {
|
|
1159
|
-
static {
|
|
1160
|
-
__name(this, "RemapResolver");
|
|
1161
|
-
}
|
|
1162
|
-
static fnName = "remap";
|
|
1163
|
-
label = "remap";
|
|
1164
|
-
icon = "codicon:replace";
|
|
1165
|
-
remappings;
|
|
1166
|
-
async _process() {
|
|
1167
|
-
if (my_dash_default.isPlainObject(this.fnArgs[0])) {
|
|
1168
|
-
throw new SchemaError("remap() expects the first arg to be the value to remap");
|
|
1169
|
-
}
|
|
1170
|
-
if (!my_dash_default.isPlainObject(this.fnArgs[1])) {
|
|
1171
|
-
throw new SchemaError("remap() expects the all args after the first to be key-value pairs of remappings");
|
|
1172
|
-
}
|
|
1173
|
-
if (this.fnArgs.length !== 2) {
|
|
1174
|
-
throw new SchemaError("remap() should not have any additional non key-value args after remappings");
|
|
1018
|
+
})
|
|
1019
|
+
);
|
|
1020
|
+
var BooleanDataType = createEnvGraphDataType({
|
|
1021
|
+
name: "boolean",
|
|
1022
|
+
icon: "carbon:boolean",
|
|
1023
|
+
// probably want allow some settings
|
|
1024
|
+
// - more strict about coercion or adding additional true/false values
|
|
1025
|
+
// - coercing to other values - like 0,1
|
|
1026
|
+
coerce(val) {
|
|
1027
|
+
if (my_dash_default.isBoolean(val)) {
|
|
1028
|
+
return val;
|
|
1029
|
+
} else if (my_dash_default.isString(val)) {
|
|
1030
|
+
const cleanVal = val.toLowerCase().trim();
|
|
1031
|
+
if (["t", "true", "yes", "on", "1"].includes(cleanVal)) return true;
|
|
1032
|
+
if (["f", "false", "no", "off", "0"].includes(cleanVal)) return false;
|
|
1033
|
+
throw new CoercionError("Unable to coerce string value to boolean");
|
|
1034
|
+
} else if (my_dash_default.isNumber(val)) {
|
|
1035
|
+
if (val === 0) return false;
|
|
1036
|
+
if (val === 1) return true;
|
|
1037
|
+
throw new CoercionError("Unable to coerce number value to boolean (only 0 or 1 is valid)");
|
|
1038
|
+
} else {
|
|
1039
|
+
throw new CoercionError("Unable to coerce value to boolean");
|
|
1175
1040
|
}
|
|
1176
|
-
|
|
1041
|
+
},
|
|
1042
|
+
// TODO: add settings to be more strict, or to allow other values to coerce to true/false
|
|
1043
|
+
validate(val) {
|
|
1044
|
+
if (my_dash_default.isBoolean(val)) return true;
|
|
1045
|
+
return new ValidationError("Value must be `true` or `false`");
|
|
1177
1046
|
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1047
|
+
});
|
|
1048
|
+
var UrlDataType = createEnvGraphDataType(
|
|
1049
|
+
(settings) => ({
|
|
1050
|
+
name: "url",
|
|
1051
|
+
icon: "carbon:url",
|
|
1052
|
+
coerce(rawVal) {
|
|
1053
|
+
const val = coerceToString(rawVal);
|
|
1054
|
+
if (settings?.prependHttps && !val.startsWith("https://")) return `https://${val}`;
|
|
1055
|
+
return val;
|
|
1056
|
+
},
|
|
1057
|
+
validate(val) {
|
|
1058
|
+
const url = new URL(val);
|
|
1059
|
+
if (settings?.allowedDomains && !settings.allowedDomains.includes(url.host.toLowerCase())) {
|
|
1060
|
+
return new ValidationError(`Domain (${url.host}) is not in allowed list: ${settings.allowedDomains.join(",")}`);
|
|
1061
|
+
}
|
|
1062
|
+
return true;
|
|
1184
1063
|
}
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1064
|
+
})
|
|
1065
|
+
);
|
|
1066
|
+
var SimpleObjectDataType = createEnvGraphDataType({
|
|
1067
|
+
name: "simple-object",
|
|
1068
|
+
icon: "tabler:code-dots",
|
|
1069
|
+
// curly brackets with nothing inside
|
|
1070
|
+
coerce(val) {
|
|
1071
|
+
if (my_dash_default.isPlainObject(val)) return val;
|
|
1072
|
+
if (my_dash_default.isString(val)) {
|
|
1073
|
+
try {
|
|
1074
|
+
const parsedObj = JSON.parse(val);
|
|
1075
|
+
if (my_dash_default.isPlainObject(parsedObj)) return parsedObj;
|
|
1076
|
+
return new CoercionError("Unable to coerce JSON parsed string to object");
|
|
1077
|
+
} catch (err) {
|
|
1078
|
+
return new CoercionError("Error parsing JSON string while coercing string to object");
|
|
1193
1079
|
}
|
|
1194
1080
|
}
|
|
1195
|
-
return
|
|
1196
|
-
}
|
|
1197
|
-
};
|
|
1198
|
-
var BaseResolvers = [
|
|
1199
|
-
ConcatResolver,
|
|
1200
|
-
FallbackResolver,
|
|
1201
|
-
RefResolver,
|
|
1202
|
-
ExecResolver,
|
|
1203
|
-
RemapResolver,
|
|
1204
|
-
RegexResolver
|
|
1205
|
-
];
|
|
1206
|
-
|
|
1207
|
-
// ../env-graph/src/lib/data-source.ts
|
|
1208
|
-
var DATA_SOURCE_TYPES = Object.freeze({
|
|
1209
|
-
schema: {
|
|
1210
|
-
fileSuffixes: ["schema"],
|
|
1211
|
-
precedence: 0
|
|
1212
|
-
},
|
|
1213
|
-
example: {
|
|
1214
|
-
fileSuffixes: ["sample", "example"],
|
|
1215
|
-
precedence: 1
|
|
1216
|
-
},
|
|
1217
|
-
defaults: {
|
|
1218
|
-
fileSuffixes: ["default", "defaults"],
|
|
1219
|
-
precedence: 2
|
|
1220
|
-
},
|
|
1221
|
-
values: {
|
|
1222
|
-
fileSuffixes: [],
|
|
1223
|
-
precedence: 3
|
|
1081
|
+
return new CoercionError("Cannot coerce value to object");
|
|
1224
1082
|
},
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1083
|
+
validate(val) {
|
|
1084
|
+
if (my_dash_default.isPlainObject(val)) return true;
|
|
1085
|
+
return new ValidationError("Value must be an object");
|
|
1228
1086
|
}
|
|
1229
1087
|
});
|
|
1230
|
-
var
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
}
|
|
1246
|
-
configItemDefs = {};
|
|
1247
|
-
decorators = {};
|
|
1248
|
-
getStaticValues() {
|
|
1249
|
-
const obj = {};
|
|
1250
|
-
for (const [key, def] of Object.entries(this.configItemDefs)) {
|
|
1251
|
-
if (def.resolver instanceof StaticValueResolver) {
|
|
1252
|
-
obj[key] = String(def.resolver.staticValue ?? "");
|
|
1088
|
+
var EnumDataType = createEnvGraphDataType(
|
|
1089
|
+
(...enumOptions) => ({
|
|
1090
|
+
name: "enum",
|
|
1091
|
+
icon: "material-symbols-light:category",
|
|
1092
|
+
// a few shapes... not sure about this one
|
|
1093
|
+
coerce(val) {
|
|
1094
|
+
if (my_dash_default.isString(val) || my_dash_default.isNumber(val) || my_dash_default.isBoolean(val)) return val;
|
|
1095
|
+
return new CoercionError("Value must be a string, number, or boolean");
|
|
1096
|
+
},
|
|
1097
|
+
validate(val) {
|
|
1098
|
+
const possibleValues = enumOptions || [];
|
|
1099
|
+
if (!possibleValues.includes(val)) {
|
|
1100
|
+
throw new ValidationError("Current value is not in list of possible values", {
|
|
1101
|
+
tip: `Possible values are: "${possibleValues.join('", "')}"`
|
|
1102
|
+
});
|
|
1253
1103
|
}
|
|
1104
|
+
},
|
|
1105
|
+
_rawEnumOptions: enumOptions
|
|
1106
|
+
})
|
|
1107
|
+
);
|
|
1108
|
+
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,}))$/;
|
|
1109
|
+
var EmailDataType = createEnvGraphDataType(
|
|
1110
|
+
(settings) => ({
|
|
1111
|
+
name: "email",
|
|
1112
|
+
icon: "iconoir:at-sign",
|
|
1113
|
+
typeDescription: "standard email address",
|
|
1114
|
+
coerce(rawVal) {
|
|
1115
|
+
let val = coerceToString(rawVal);
|
|
1116
|
+
if (settings?.normalize) val = val.toLowerCase();
|
|
1117
|
+
return val;
|
|
1118
|
+
},
|
|
1119
|
+
validate(val) {
|
|
1120
|
+
const result = EMAIL_REGEX.test(val);
|
|
1121
|
+
if (result) return true;
|
|
1122
|
+
return new ValidationError("Value must be a valid email address");
|
|
1254
1123
|
}
|
|
1255
|
-
|
|
1124
|
+
})
|
|
1125
|
+
);
|
|
1126
|
+
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}$/;
|
|
1127
|
+
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,})?$/;
|
|
1128
|
+
var ipAddressDataType = createEnvGraphDataType(
|
|
1129
|
+
(settings) => ({
|
|
1130
|
+
name: "ip",
|
|
1131
|
+
icon: "iconoir:ip-address-tag",
|
|
1132
|
+
typeDescription: "ip v4 or v6 address",
|
|
1133
|
+
coerce(rawVal) {
|
|
1134
|
+
let val = coerceToString(rawVal);
|
|
1135
|
+
if (settings?.normalize) val = val.toLowerCase();
|
|
1136
|
+
return val;
|
|
1137
|
+
},
|
|
1138
|
+
validate(val) {
|
|
1139
|
+
const regex = settings?.version === 6 ? IP_V6_ADDRESS_REGEX : IP_V4_ADDRESS_REGEX;
|
|
1140
|
+
const result = regex.test(val);
|
|
1141
|
+
if (result) return true;
|
|
1142
|
+
return new ValidationError("Value must be a valid IP address");
|
|
1143
|
+
}
|
|
1144
|
+
})
|
|
1145
|
+
);
|
|
1146
|
+
var PortDataType = createEnvGraphDataType(
|
|
1147
|
+
(settings) => ({
|
|
1148
|
+
name: "port",
|
|
1149
|
+
icon: "material-symbols:captive-portal",
|
|
1150
|
+
//! globe with arrow - not sure about this one
|
|
1151
|
+
typeDescription: "valid port number between 0 and 65535",
|
|
1152
|
+
coerce(rawVal) {
|
|
1153
|
+
if (my_dash_default.isString(rawVal)) {
|
|
1154
|
+
if (rawVal.includes(".")) throw new CoercionError("Port number must be an integer");
|
|
1155
|
+
if (rawVal.includes("e")) throw new CoercionError("Port number should be an integer, not in exponential notation");
|
|
1156
|
+
}
|
|
1157
|
+
return coerceToNumber(rawVal);
|
|
1158
|
+
},
|
|
1159
|
+
validate(val) {
|
|
1160
|
+
if (settings?.min !== void 0 && val < settings?.min) {
|
|
1161
|
+
return new ValidationError(`Min value is ${settings?.min}`);
|
|
1162
|
+
}
|
|
1163
|
+
if (settings?.max !== void 0 && val > settings?.max) {
|
|
1164
|
+
return new ValidationError(`Max value is ${settings?.max}`);
|
|
1165
|
+
}
|
|
1166
|
+
if (val < 0 || val > 65535) {
|
|
1167
|
+
return new ValidationError("Value must be a valid port number (0-65535)");
|
|
1168
|
+
}
|
|
1169
|
+
return true;
|
|
1170
|
+
}
|
|
1171
|
+
})
|
|
1172
|
+
);
|
|
1173
|
+
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-]+)*))?$/;
|
|
1174
|
+
var SemverDataType = createEnvGraphDataType(
|
|
1175
|
+
(settings) => ({
|
|
1176
|
+
name: "semver",
|
|
1177
|
+
icon: "simple-icons:semver",
|
|
1178
|
+
typeDescription: "semantic version string",
|
|
1179
|
+
validate(val) {
|
|
1180
|
+
const result = SEMVER_REGEX.test(val);
|
|
1181
|
+
if (result) return true;
|
|
1182
|
+
return new ValidationError("Value must be a valid semantic version string");
|
|
1183
|
+
}
|
|
1184
|
+
})
|
|
1185
|
+
);
|
|
1186
|
+
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)?)?)?)?$/;
|
|
1187
|
+
var IsoDateDataType = createEnvGraphDataType({
|
|
1188
|
+
name: "isoDate",
|
|
1189
|
+
icon: "formkit:datetime",
|
|
1190
|
+
typeDescription: "ISO 8601 date string with optional time and milliseconds",
|
|
1191
|
+
validate(val) {
|
|
1192
|
+
const result = ISO_DATE_REGEX.test(val);
|
|
1193
|
+
if (result) return true;
|
|
1194
|
+
return new ValidationError("Value must be a valid ISO 8601 date string");
|
|
1195
|
+
}
|
|
1196
|
+
});
|
|
1197
|
+
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;
|
|
1198
|
+
var UuidDataType = createEnvGraphDataType({
|
|
1199
|
+
name: "uuid",
|
|
1200
|
+
icon: "mdi:identifier",
|
|
1201
|
+
typeDescription: "UUID string V1-V5 per RFC4122, including NIL",
|
|
1202
|
+
validate(val) {
|
|
1203
|
+
const result = UUID_REGEX.test(val);
|
|
1204
|
+
if (result) return true;
|
|
1205
|
+
return new ValidationError("Value must be a valid UUID string");
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
1208
|
+
var MD5_REGEX = /^[a-f0-9]{32}$/;
|
|
1209
|
+
var Md5DataType = createEnvGraphDataType({
|
|
1210
|
+
name: "md5",
|
|
1211
|
+
typeDescription: "MD5 hash string",
|
|
1212
|
+
validate(val) {
|
|
1213
|
+
const result = MD5_REGEX.test(val);
|
|
1214
|
+
if (result) return true;
|
|
1215
|
+
return new ValidationError("Value must be a valid MD5 hash string");
|
|
1256
1216
|
}
|
|
1217
|
+
});
|
|
1218
|
+
var BaseDataTypes = {
|
|
1219
|
+
string: StringDataType,
|
|
1220
|
+
number: NumberDataType,
|
|
1221
|
+
boolean: BooleanDataType,
|
|
1222
|
+
simpleObject: SimpleObjectDataType,
|
|
1223
|
+
enum: EnumDataType,
|
|
1224
|
+
email: EmailDataType,
|
|
1225
|
+
url: UrlDataType,
|
|
1226
|
+
ipAddress: ipAddressDataType,
|
|
1227
|
+
port: PortDataType,
|
|
1228
|
+
semver: SemverDataType,
|
|
1229
|
+
isoDate: IsoDateDataType,
|
|
1230
|
+
uuid: UuidDataType,
|
|
1231
|
+
md5: Md5DataType
|
|
1257
1232
|
};
|
|
1258
|
-
|
|
1233
|
+
|
|
1234
|
+
// ../env-graph/src/lib/simple-queue.ts
|
|
1235
|
+
var SimpleQueue = class {
|
|
1259
1236
|
static {
|
|
1260
|
-
__name(this, "
|
|
1237
|
+
__name(this, "SimpleQueue");
|
|
1261
1238
|
}
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1239
|
+
queue = [];
|
|
1240
|
+
processing = false;
|
|
1241
|
+
/** Add a task to the queue and return a promise that resolves when the task is complete */
|
|
1242
|
+
async enqueue(task) {
|
|
1243
|
+
return new Promise((resolve, reject) => {
|
|
1244
|
+
this.queue.push(async () => {
|
|
1245
|
+
try {
|
|
1246
|
+
const result = await task();
|
|
1247
|
+
resolve(result);
|
|
1248
|
+
} catch (err) {
|
|
1249
|
+
reject(err);
|
|
1250
|
+
}
|
|
1251
|
+
});
|
|
1252
|
+
this.processQueue();
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
async processQueue() {
|
|
1256
|
+
if (this.processing || this.queue.length === 0) {
|
|
1257
|
+
return;
|
|
1276
1258
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1259
|
+
this.processing = true;
|
|
1260
|
+
const task = this.queue.shift();
|
|
1261
|
+
if (task) {
|
|
1262
|
+
try {
|
|
1263
|
+
await task();
|
|
1264
|
+
} finally {
|
|
1265
|
+
this.processing = false;
|
|
1266
|
+
this.processQueue();
|
|
1267
|
+
}
|
|
1281
1268
|
}
|
|
1282
1269
|
}
|
|
1283
1270
|
};
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1271
|
+
|
|
1272
|
+
// ../env-graph/src/lib/resolver.ts
|
|
1273
|
+
var execAsync = promisify(exec);
|
|
1274
|
+
var Resolver = class {
|
|
1275
|
+
constructor(fnArgs) {
|
|
1276
|
+
this.fnArgs = fnArgs;
|
|
1288
1277
|
}
|
|
1289
1278
|
static {
|
|
1290
|
-
__name(this, "
|
|
1279
|
+
__name(this, "Resolver");
|
|
1291
1280
|
}
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1281
|
+
static fnName;
|
|
1282
|
+
inferredType;
|
|
1283
|
+
_schemaErrors = [];
|
|
1284
|
+
_depsObj = {};
|
|
1285
|
+
get childResolvers() {
|
|
1286
|
+
return this.fnArgs.flatMap((r) => my_dash_default.isPlainObject(r) ? my_dash_default.values(r) : r);
|
|
1296
1287
|
}
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
return this.constructor.format;
|
|
1288
|
+
get schemaErrors() {
|
|
1289
|
+
return [
|
|
1290
|
+
...this._schemaErrors,
|
|
1291
|
+
...this.childResolvers.flatMap((r) => r.schemaErrors)
|
|
1292
|
+
];
|
|
1303
1293
|
}
|
|
1304
|
-
get
|
|
1305
|
-
|
|
1294
|
+
get depsObj() {
|
|
1295
|
+
const mergedDepsObj = { ...this._depsObj };
|
|
1296
|
+
this.childResolvers.forEach((r) => Object.assign(mergedDepsObj, r.depsObj));
|
|
1297
|
+
return mergedDepsObj;
|
|
1306
1298
|
}
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
static validFileExtensions = [];
|
|
1310
|
-
get validFileExtensions() {
|
|
1311
|
-
return this.constructor.validFileExtensions;
|
|
1299
|
+
get deps() {
|
|
1300
|
+
return Object.keys(this.depsObj);
|
|
1312
1301
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
this.
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
const maybeExtension = fileNameParts[fileNameParts.length - 1];
|
|
1326
|
-
if (this.validFileExtensions.includes(maybeExtension)) {
|
|
1327
|
-
fileNameParts.pop();
|
|
1328
|
-
}
|
|
1329
|
-
const maybeFileType = fileNameParts[fileNameParts.length - 1];
|
|
1330
|
-
for (const [possibleSourceType, possibleSourceSpec] of Object.entries(DATA_SOURCE_TYPES)) {
|
|
1331
|
-
if (possibleSourceSpec.fileSuffixes.includes(maybeFileType)) {
|
|
1332
|
-
this.type = possibleSourceType;
|
|
1333
|
-
break;
|
|
1302
|
+
configItem;
|
|
1303
|
+
async process(configItem) {
|
|
1304
|
+
this.configItem = configItem;
|
|
1305
|
+
try {
|
|
1306
|
+
await this._process(configItem);
|
|
1307
|
+
} catch (error) {
|
|
1308
|
+
if (error instanceof SchemaError) {
|
|
1309
|
+
this._schemaErrors.push(error);
|
|
1310
|
+
} else if (error instanceof Error) {
|
|
1311
|
+
this._schemaErrors.push(new SchemaError(error));
|
|
1312
|
+
} else {
|
|
1313
|
+
throw new Error(`Non-error thrown while processing resolver - ${error}`);
|
|
1334
1314
|
}
|
|
1335
1315
|
}
|
|
1336
|
-
|
|
1337
|
-
if (fileNameParts.length > 2) {
|
|
1338
|
-
throw Error(`Unsure how to interpret filename - ${this.fileName}`);
|
|
1339
|
-
} else if (fileNameParts.length === 2) {
|
|
1340
|
-
this.applyForEnv = fileNameParts[1];
|
|
1341
|
-
if (this.applyForEnv === "dev") this.applyForEnv = "development";
|
|
1342
|
-
if (this.applyForEnv === "stage") this.applyForEnv = "staging";
|
|
1343
|
-
if (this.applyForEnv === "prod") this.applyForEnv = "production";
|
|
1344
|
-
}
|
|
1316
|
+
this.childResolvers.forEach((r) => r.process(configItem));
|
|
1345
1317
|
}
|
|
1346
|
-
//
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1318
|
+
// meant to be used by subclass _process methods
|
|
1319
|
+
addDep(key) {
|
|
1320
|
+
this._depsObj[key] = true;
|
|
1321
|
+
if (!this.configItem) throw new Error("expected configItem to be set");
|
|
1322
|
+
if (!this.configItem.envGraph.configSchema[key]) {
|
|
1323
|
+
this._schemaErrors.push(new SchemaError(`Unknown referenced key: ${key}`));
|
|
1351
1324
|
}
|
|
1352
|
-
|
|
1325
|
+
}
|
|
1326
|
+
async resolve() {
|
|
1327
|
+
const resolvedValue = await this._resolve();
|
|
1328
|
+
return resolvedValue;
|
|
1329
|
+
}
|
|
1330
|
+
// meant to be used by subclass _resolve methods
|
|
1331
|
+
getDepValue(key) {
|
|
1332
|
+
const depItem = this.configItem?.envGraph.configSchema[key];
|
|
1333
|
+
if (!depItem) throw new Error(`Expected to find item - ${key}`);
|
|
1334
|
+
return depItem.resolvedValue;
|
|
1353
1335
|
}
|
|
1354
1336
|
};
|
|
1355
|
-
var
|
|
1337
|
+
var StaticValueResolver = class extends Resolver {
|
|
1338
|
+
constructor(staticValue) {
|
|
1339
|
+
super([]);
|
|
1340
|
+
this.staticValue = staticValue;
|
|
1341
|
+
if (staticValue !== void 0) {
|
|
1342
|
+
this.inferredType = typeof staticValue;
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1356
1345
|
static {
|
|
1357
|
-
__name(this, "
|
|
1346
|
+
__name(this, "StaticValueResolver");
|
|
1358
1347
|
}
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
convertParserValueToResolvers(value) {
|
|
1364
|
-
if (!this.graph) throw new Error("expected graph to be set");
|
|
1365
|
-
if (value === void 0) {
|
|
1366
|
-
return new StaticValueResolver(void 0);
|
|
1367
|
-
} else if (value instanceof ParsedEnvSpecStaticValue) {
|
|
1368
|
-
return new StaticValueResolver(value.unescapedValue);
|
|
1369
|
-
} else if (value instanceof ParsedEnvSpecFunctionCall) {
|
|
1370
|
-
const ResolverFnClass = this.graph.registeredResolverFunctions[value.name];
|
|
1371
|
-
if (!ResolverFnClass) {
|
|
1372
|
-
return new ErrorResolver(new SchemaError(`Unknown resolver function: ${value.name}()`));
|
|
1373
|
-
}
|
|
1374
|
-
const argsFromParser = value.data.args.values;
|
|
1375
|
-
let keyValueArgs;
|
|
1376
|
-
const argsAsResolversArray = [];
|
|
1377
|
-
for (const arg of argsFromParser) {
|
|
1378
|
-
if (arg instanceof ParsedEnvSpecKeyValuePair) {
|
|
1379
|
-
keyValueArgs ??= {};
|
|
1380
|
-
keyValueArgs[arg.key] = this.convertParserValueToResolvers(arg.value);
|
|
1381
|
-
} else {
|
|
1382
|
-
if (keyValueArgs) {
|
|
1383
|
-
return new ErrorResolver(new SchemaError("After switching to key-value function args, cannot switch back"));
|
|
1384
|
-
}
|
|
1385
|
-
argsAsResolversArray.push(this.convertParserValueToResolvers(arg));
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
if (keyValueArgs) argsAsResolversArray.push(keyValueArgs);
|
|
1389
|
-
return new ResolverFnClass(argsAsResolversArray);
|
|
1390
|
-
} else {
|
|
1391
|
-
throw new Error("Unknown value type");
|
|
1392
|
-
}
|
|
1348
|
+
label = "static";
|
|
1349
|
+
icon = "bi:dash";
|
|
1350
|
+
async _resolve() {
|
|
1351
|
+
return this.staticValue;
|
|
1393
1352
|
}
|
|
1394
|
-
async
|
|
1395
|
-
const rawContents = this.rawContents;
|
|
1396
|
-
this.parsedFile = await tryCatch(
|
|
1397
|
-
() => parseEnvSpecDotEnvFile(rawContents),
|
|
1398
|
-
(error) => {
|
|
1399
|
-
this.loadingError = new EnvSourceParseError(error.message, {
|
|
1400
|
-
path: this.fullPath,
|
|
1401
|
-
lineNumber: error.location.start.line,
|
|
1402
|
-
colNumber: error.location.start.column,
|
|
1403
|
-
lineStr: rawContents.split("\n")[error.location.start.line - 1]
|
|
1404
|
-
});
|
|
1405
|
-
this.loadingError.cause = error;
|
|
1406
|
-
}
|
|
1407
|
-
);
|
|
1408
|
-
if (this.loadingError) return;
|
|
1409
|
-
if (!this.parsedFile) throw new Error("Failed to parse .env file");
|
|
1410
|
-
this.decorators = this.parsedFile.decoratorsObject;
|
|
1411
|
-
if (!this.graph) throw new Error("expected graph to be set");
|
|
1412
|
-
for (const item of this.parsedFile.configItems) {
|
|
1413
|
-
item.processExpansion();
|
|
1414
|
-
this.configItemDefs[item.key] = {
|
|
1415
|
-
resolver: this.convertParserValueToResolvers(item.expandedValue),
|
|
1416
|
-
description: item.description,
|
|
1417
|
-
decorators: item.decoratorsObject
|
|
1418
|
-
};
|
|
1419
|
-
}
|
|
1353
|
+
async _process() {
|
|
1420
1354
|
}
|
|
1421
1355
|
};
|
|
1422
|
-
var
|
|
1423
|
-
constructor(envGraph, key) {
|
|
1424
|
-
this.envGraph = envGraph;
|
|
1425
|
-
this.key = key;
|
|
1426
|
-
}
|
|
1356
|
+
var ErrorResolver = class extends Resolver {
|
|
1427
1357
|
static {
|
|
1428
|
-
__name(this, "
|
|
1358
|
+
__name(this, "ErrorResolver");
|
|
1429
1359
|
}
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
this.
|
|
1360
|
+
constructor(err) {
|
|
1361
|
+
super([]);
|
|
1362
|
+
this._schemaErrors.push(err);
|
|
1433
1363
|
}
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1364
|
+
label = "error";
|
|
1365
|
+
icon = "bi:dash";
|
|
1366
|
+
async _resolve() {
|
|
1367
|
+
return void 0;
|
|
1438
1368
|
}
|
|
1439
|
-
|
|
1440
|
-
const explicitIcon = this.getDecoratorValueString("icon");
|
|
1441
|
-
if (explicitIcon) return explicitIcon;
|
|
1442
|
-
return this.dataType?.icon;
|
|
1369
|
+
async _process() {
|
|
1443
1370
|
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
return links;
|
|
1371
|
+
};
|
|
1372
|
+
var ConcatResolver = class extends Resolver {
|
|
1373
|
+
static {
|
|
1374
|
+
__name(this, "ConcatResolver");
|
|
1449
1375
|
}
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1376
|
+
static fnName = "concat";
|
|
1377
|
+
label = "concat";
|
|
1378
|
+
icon = "material-symbols:join";
|
|
1379
|
+
inferredType = "string";
|
|
1380
|
+
async _process() {
|
|
1381
|
+
if (this.fnArgs.some((arg) => my_dash_default.isPlainObject(arg))) {
|
|
1382
|
+
throw new SchemaError("concat() does not support key-value arguments");
|
|
1453
1383
|
}
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
for (const def of this.defs) {
|
|
1457
|
-
const defDecorators = def.itemDef.decorators || {};
|
|
1458
|
-
if (decoratorName in defDecorators) {
|
|
1459
|
-
return defDecorators[decoratorName];
|
|
1460
|
-
}
|
|
1384
|
+
if (this.fnArgs.length < 2) {
|
|
1385
|
+
throw new SchemaError("concat() expects at least two arguments");
|
|
1461
1386
|
}
|
|
1462
1387
|
}
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
if (
|
|
1467
|
-
|
|
1388
|
+
async _resolve() {
|
|
1389
|
+
const resolvedValues = [];
|
|
1390
|
+
for (const arg of this.fnArgs) {
|
|
1391
|
+
if (my_dash_default.isPlainObject(arg)) {
|
|
1392
|
+
throw new Error("concat() does not support key-value arguments");
|
|
1468
1393
|
}
|
|
1394
|
+
const resolvedChildValue = await arg.resolve();
|
|
1395
|
+
resolvedValues.push(String(resolvedChildValue ?? ""));
|
|
1469
1396
|
}
|
|
1397
|
+
return resolvedValues.join("");
|
|
1470
1398
|
}
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
dataType;
|
|
1476
|
-
schemaErrors = [];
|
|
1477
|
-
get resolverSchemaErrors() {
|
|
1478
|
-
return this.valueResolver?.schemaErrors || [];
|
|
1399
|
+
};
|
|
1400
|
+
var FallbackResolver = class extends Resolver {
|
|
1401
|
+
static {
|
|
1402
|
+
__name(this, "FallbackResolver");
|
|
1479
1403
|
}
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
await def.itemDef.resolver?.process(this);
|
|
1404
|
+
static fnName = "fallback";
|
|
1405
|
+
label = "fallback";
|
|
1406
|
+
icon = "memory:table-top-stairs-up";
|
|
1407
|
+
async _process() {
|
|
1408
|
+
if (this.fnArgs.some((arg) => my_dash_default.isPlainObject(arg))) {
|
|
1409
|
+
throw new SchemaError("fallback() does not support key-value arguments");
|
|
1487
1410
|
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
let dataTypeArgs;
|
|
1491
|
-
if (typeDecoratorValue instanceof ParsedEnvSpecStaticValue) {
|
|
1492
|
-
dataTypeName = typeDecoratorValue.value;
|
|
1493
|
-
} else if (typeDecoratorValue instanceof ParsedEnvSpecFunctionCall) {
|
|
1494
|
-
dataTypeName = typeDecoratorValue.name;
|
|
1495
|
-
dataTypeArgs = typeDecoratorValue.simplifiedArgs;
|
|
1411
|
+
if (this.fnArgs.length < 2) {
|
|
1412
|
+
throw new SchemaError("fallback() expects at least two arguments");
|
|
1496
1413
|
}
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1414
|
+
}
|
|
1415
|
+
async _resolve() {
|
|
1416
|
+
for (const arg of this.fnArgs) {
|
|
1417
|
+
if (my_dash_default.isPlainObject(arg)) throw new Error("fallback() does not support key-value arguments");
|
|
1418
|
+
const resolvedChildValue = await arg.resolve();
|
|
1419
|
+
if (resolvedChildValue !== void 0 && resolvedChildValue !== "") {
|
|
1420
|
+
return resolvedChildValue;
|
|
1500
1421
|
}
|
|
1501
1422
|
}
|
|
1502
|
-
dataTypeName ||= "string";
|
|
1503
|
-
dataTypeArgs ||= [];
|
|
1504
|
-
if (!(dataTypeName in this.envGraph.dataTypesRegistry)) {
|
|
1505
|
-
this.schemaErrors.push(new SchemaError(`unknown data type: ${dataTypeName}`));
|
|
1506
|
-
} else {
|
|
1507
|
-
const dataTypeFactory = this.envGraph.dataTypesRegistry[dataTypeName];
|
|
1508
|
-
this.dataType = dataTypeFactory(...my_dash_default.isPlainObject(dataTypeArgs) ? [dataTypeArgs] : dataTypeArgs);
|
|
1509
|
-
}
|
|
1510
1423
|
}
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
const val = defDecorators.required.simplifiedValue;
|
|
1516
|
-
if (typeof val === "boolean") return val;
|
|
1517
|
-
if (typeof val === "string") return val === "true";
|
|
1518
|
-
return Boolean(val);
|
|
1519
|
-
}
|
|
1520
|
-
if ("optional" in defDecorators) {
|
|
1521
|
-
const val = defDecorators.optional.simplifiedValue;
|
|
1522
|
-
if (typeof val === "boolean") return !val;
|
|
1523
|
-
if (typeof val === "string") return val !== "true";
|
|
1524
|
-
return !val;
|
|
1525
|
-
}
|
|
1526
|
-
if ("defaultRequired" in def.source.decorators) {
|
|
1527
|
-
const val = def.source.decorators.defaultRequired.simplifiedValue;
|
|
1528
|
-
if (val === "infer") {
|
|
1529
|
-
if (def.source.type === "schema") {
|
|
1530
|
-
const resolver = def.itemDef.resolver;
|
|
1531
|
-
if (resolver instanceof StaticValueResolver) {
|
|
1532
|
-
return resolver.staticValue !== void 0 && resolver.staticValue !== "";
|
|
1533
|
-
} else {
|
|
1534
|
-
return true;
|
|
1535
|
-
}
|
|
1536
|
-
} else {
|
|
1537
|
-
continue;
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
return val;
|
|
1541
|
-
}
|
|
1542
|
-
}
|
|
1543
|
-
return true;
|
|
1424
|
+
};
|
|
1425
|
+
var ExecResolver = class _ExecResolver extends Resolver {
|
|
1426
|
+
static {
|
|
1427
|
+
__name(this, "ExecResolver");
|
|
1544
1428
|
}
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
const prefix = Array.isArray(args) && args.length > 0 ? args[0] : void 0;
|
|
1555
|
-
if (typeof prefix === "string" && this.key.startsWith(prefix)) {
|
|
1556
|
-
return false;
|
|
1557
|
-
}
|
|
1558
|
-
return true;
|
|
1559
|
-
}
|
|
1560
|
-
return dec.simplifiedValue;
|
|
1561
|
-
}
|
|
1429
|
+
static fnName = "exec";
|
|
1430
|
+
label = "exec";
|
|
1431
|
+
icon = "iconoir:terminal";
|
|
1432
|
+
async _process() {
|
|
1433
|
+
if (this.fnArgs.length !== 1) {
|
|
1434
|
+
throw new SchemaError("exec() expects a single child arg");
|
|
1435
|
+
}
|
|
1436
|
+
if (this.fnArgs.some((arg) => my_dash_default.isPlainObject(arg))) {
|
|
1437
|
+
throw new SchemaError("exec() does not support key-value arguments");
|
|
1562
1438
|
}
|
|
1563
|
-
return true;
|
|
1564
|
-
}
|
|
1565
|
-
get errors() {
|
|
1566
|
-
return my_dash_default.compact([
|
|
1567
|
-
...this.schemaErrors || [],
|
|
1568
|
-
...this.resolverSchemaErrors || [],
|
|
1569
|
-
this.resolutionError,
|
|
1570
|
-
this.coercionError,
|
|
1571
|
-
...this.validationErrors || []
|
|
1572
|
-
]);
|
|
1573
|
-
}
|
|
1574
|
-
get validationState() {
|
|
1575
|
-
const errors = this.errors;
|
|
1576
|
-
if (!errors.length) return "valid";
|
|
1577
|
-
return my_dash_default.some(errors, (e) => !e.isWarning) ? "error" : "warn";
|
|
1578
|
-
}
|
|
1579
|
-
/** resolved value _before coercion_ */
|
|
1580
|
-
resolvedRawValue;
|
|
1581
|
-
isResolved = false;
|
|
1582
|
-
/** resolved value after coercion */
|
|
1583
|
-
resolvedValue;
|
|
1584
|
-
isValidated = false;
|
|
1585
|
-
resolutionError;
|
|
1586
|
-
coercionError;
|
|
1587
|
-
validationErrors;
|
|
1588
|
-
get isCoerced() {
|
|
1589
|
-
return this.resolvedRawValue !== this.resolvedValue;
|
|
1590
1439
|
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
if (this.
|
|
1594
|
-
|
|
1595
|
-
if (
|
|
1596
|
-
|
|
1440
|
+
static execQueue = new SimpleQueue();
|
|
1441
|
+
async _resolve() {
|
|
1442
|
+
if (my_dash_default.isPlainObject(this.fnArgs[0])) throw new Error("exec() does not support key-value arguments");
|
|
1443
|
+
const commandStr = await this.fnArgs[0].resolve();
|
|
1444
|
+
if (typeof commandStr !== "string") {
|
|
1445
|
+
throw new ResolutionError("exec() expects a string child arg");
|
|
1597
1446
|
}
|
|
1598
1447
|
try {
|
|
1599
|
-
|
|
1448
|
+
const { stdout, stderr } = await _ExecResolver.execQueue.enqueue(() => execAsync(commandStr));
|
|
1449
|
+
return stdout.replace(/\n$/, "");
|
|
1600
1450
|
} catch (err) {
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
}
|
|
1604
|
-
if (this.resolvedRawValue instanceof RegExp) {
|
|
1605
|
-
this.resolutionError = new ResolutionError("regex() is meant to be used within function args, not as a final resolved value");
|
|
1451
|
+
console.log("exec() failed", err);
|
|
1452
|
+
throw new ResolutionError(`exec() command failed: ${commandStr}`);
|
|
1606
1453
|
}
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1454
|
+
}
|
|
1455
|
+
};
|
|
1456
|
+
var RefResolver = class extends Resolver {
|
|
1457
|
+
static {
|
|
1458
|
+
__name(this, "RefResolver");
|
|
1459
|
+
}
|
|
1460
|
+
static fnName = "ref";
|
|
1461
|
+
label = "ref";
|
|
1462
|
+
icon = "mdi-light:content-duplicate";
|
|
1463
|
+
refKey;
|
|
1464
|
+
async _process() {
|
|
1465
|
+
if (this.fnArgs.length !== 1) {
|
|
1466
|
+
throw new SchemaError("ref() expects a single child arg");
|
|
1615
1467
|
}
|
|
1616
|
-
if (!this.
|
|
1617
|
-
|
|
1618
|
-
const coerceResult = this.dataType.coerce(this.resolvedRawValue);
|
|
1619
|
-
if (coerceResult instanceof Error) throw coerceResult;
|
|
1620
|
-
this.resolvedValue = coerceResult;
|
|
1621
|
-
} catch (err) {
|
|
1622
|
-
if (err instanceof CoercionError) {
|
|
1623
|
-
this.coercionError = err;
|
|
1624
|
-
return;
|
|
1625
|
-
} else if (err instanceof Error) {
|
|
1626
|
-
this.coercionError = new CoercionError("Unexpected error coercing value");
|
|
1627
|
-
this.coercionError.cause = err;
|
|
1628
|
-
} else {
|
|
1629
|
-
this.coercionError = new CoercionError(`Unexpected non-error throw during coerce - ${err}`);
|
|
1630
|
-
}
|
|
1631
|
-
return;
|
|
1468
|
+
if (!(this.fnArgs[0] instanceof StaticValueResolver)) {
|
|
1469
|
+
throw new SchemaError("ref() expects a single static value passed in");
|
|
1632
1470
|
}
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
if (validateResult === false) {
|
|
1637
|
-
throw new ValidationError("validation failed with `false` return value");
|
|
1638
|
-
}
|
|
1639
|
-
this.isValidated = true;
|
|
1640
|
-
} catch (err) {
|
|
1641
|
-
if (my_dash_default.isArray(err)) {
|
|
1642
|
-
this.validationErrors = err;
|
|
1643
|
-
} else if (err instanceof ValidationError) {
|
|
1644
|
-
this.validationErrors = [err];
|
|
1645
|
-
} else if (err instanceof Error) {
|
|
1646
|
-
const validationError = new ValidationError("Unexpected error during validation");
|
|
1647
|
-
validationError.cause = err;
|
|
1648
|
-
console.log(err);
|
|
1649
|
-
this.validationErrors = [validationError];
|
|
1650
|
-
} else {
|
|
1651
|
-
const validationError = new ValidationError(`Unexpected non-error thrown during validation - ${err}`);
|
|
1652
|
-
validationError.cause = err;
|
|
1653
|
-
this.validationErrors = [validationError];
|
|
1654
|
-
}
|
|
1655
|
-
return;
|
|
1471
|
+
const keyName = this.fnArgs[0].staticValue;
|
|
1472
|
+
if (typeof keyName !== "string") {
|
|
1473
|
+
throw new SchemaError("ref() expects a string keyname passed in");
|
|
1656
1474
|
}
|
|
1475
|
+
this.refKey = keyName;
|
|
1476
|
+
this.addDep(keyName);
|
|
1657
1477
|
}
|
|
1658
|
-
|
|
1659
|
-
|
|
1478
|
+
async _resolve() {
|
|
1479
|
+
if (!this.refKey) throw new Error("expected refKey to be set");
|
|
1480
|
+
return this.getDepValue(this.refKey);
|
|
1660
1481
|
}
|
|
1661
1482
|
};
|
|
1662
|
-
|
|
1663
|
-
// ../env-graph/src/lib/data-types.ts
|
|
1664
|
-
var EnvGraphDataType = class {
|
|
1665
|
-
constructor(def, factory) {
|
|
1666
|
-
this.def = def;
|
|
1667
|
-
this.factory = factory;
|
|
1668
|
-
}
|
|
1483
|
+
var RegexResolver = class extends Resolver {
|
|
1669
1484
|
static {
|
|
1670
|
-
__name(this, "
|
|
1671
|
-
}
|
|
1672
|
-
get name() {
|
|
1673
|
-
return this.def.name;
|
|
1485
|
+
__name(this, "RegexResolver");
|
|
1674
1486
|
}
|
|
1675
|
-
|
|
1676
|
-
|
|
1487
|
+
static fnName = "regex";
|
|
1488
|
+
label = "regex";
|
|
1489
|
+
icon = "mdi:regex";
|
|
1490
|
+
regex;
|
|
1491
|
+
async _process() {
|
|
1492
|
+
if (this.fnArgs.length !== 1) {
|
|
1493
|
+
throw new SchemaError("regex() expects a single child arg");
|
|
1494
|
+
}
|
|
1495
|
+
if (!(this.fnArgs[0] instanceof StaticValueResolver)) {
|
|
1496
|
+
throw new SchemaError("regex() expects a single static value passed in");
|
|
1497
|
+
}
|
|
1498
|
+
const regexStr = this.fnArgs[0].staticValue;
|
|
1499
|
+
if (typeof regexStr !== "string") {
|
|
1500
|
+
throw new SchemaError("regex() expects a string");
|
|
1501
|
+
}
|
|
1502
|
+
this.regex = new RegExp(regexStr);
|
|
1677
1503
|
}
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
return this.
|
|
1504
|
+
async _resolve() {
|
|
1505
|
+
if (!this.regex) throw new Error("expected regex to be set");
|
|
1506
|
+
return this.regex;
|
|
1681
1507
|
}
|
|
1682
|
-
|
|
1683
|
-
|
|
1508
|
+
};
|
|
1509
|
+
var RemapResolver = class extends Resolver {
|
|
1510
|
+
static {
|
|
1511
|
+
__name(this, "RemapResolver");
|
|
1684
1512
|
}
|
|
1685
|
-
|
|
1686
|
-
|
|
1513
|
+
static fnName = "remap";
|
|
1514
|
+
label = "remap";
|
|
1515
|
+
icon = "codicon:replace";
|
|
1516
|
+
remappings;
|
|
1517
|
+
async _process() {
|
|
1518
|
+
if (my_dash_default.isPlainObject(this.fnArgs[0])) {
|
|
1519
|
+
throw new SchemaError("remap() expects the first arg to be the value to remap");
|
|
1520
|
+
}
|
|
1521
|
+
if (!my_dash_default.isPlainObject(this.fnArgs[1])) {
|
|
1522
|
+
throw new SchemaError("remap() expects the all args after the first to be key-value pairs of remappings");
|
|
1523
|
+
}
|
|
1524
|
+
if (this.fnArgs.length !== 2) {
|
|
1525
|
+
throw new SchemaError("remap() should not have any additional non key-value args after remappings");
|
|
1526
|
+
}
|
|
1527
|
+
this.remappings = this.fnArgs[1];
|
|
1687
1528
|
}
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
return new EnvGraphDataType(
|
|
1692
|
-
my_dash_default.isFunction(dataTypeDef) ? dataTypeDef(...usageOpts) : dataTypeDef,
|
|
1693
|
-
typeFactoryFn
|
|
1694
|
-
);
|
|
1695
|
-
}, "typeFactoryFn");
|
|
1696
|
-
typeFactoryFn._isEnvGraphDataTypeFactory = true;
|
|
1697
|
-
const exampleInstance = typeFactoryFn(...[]);
|
|
1698
|
-
typeFactoryFn.dataTypeName = exampleInstance.name;
|
|
1699
|
-
return typeFactoryFn;
|
|
1700
|
-
}
|
|
1701
|
-
__name(createEnvGraphDataType, "createEnvGraphDataType");
|
|
1702
|
-
function coerceToString(rawVal) {
|
|
1703
|
-
if (rawVal === void 0 || rawVal === null) return "";
|
|
1704
|
-
return my_dash_default.isString(rawVal) ? rawVal : String(rawVal);
|
|
1705
|
-
}
|
|
1706
|
-
__name(coerceToString, "coerceToString");
|
|
1707
|
-
function coerceToNumber(rawVal) {
|
|
1708
|
-
let numVal;
|
|
1709
|
-
if (my_dash_default.isString(rawVal)) {
|
|
1710
|
-
const parsed = parseFloat(rawVal);
|
|
1711
|
-
if (my_dash_default.isNan(parsed) || parsed === Infinity || parsed === -Infinity) {
|
|
1712
|
-
throw new CoercionError("Unable to coerce string to number");
|
|
1529
|
+
async _resolve() {
|
|
1530
|
+
if (my_dash_default.isPlainObject(this.fnArgs[0])) {
|
|
1531
|
+
throw new SchemaError("remap() expects the first arg to be the value to remap");
|
|
1713
1532
|
}
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
if (numVal === Infinity || numVal === -Infinity) {
|
|
1717
|
-
throw new CoercionError("Inifinity is not a valid number");
|
|
1533
|
+
if (!my_dash_default.isPlainObject(this.fnArgs[1])) {
|
|
1534
|
+
throw new SchemaError("remap() expects the all args after the first to be key-value pairs of remappings");
|
|
1718
1535
|
}
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
(settings) => ({
|
|
1728
|
-
name: "string",
|
|
1729
|
-
icon: "carbon:string-text",
|
|
1730
|
-
coerce: /* @__PURE__ */ __name((rawVal) => {
|
|
1731
|
-
let val = coerceToString(rawVal);
|
|
1732
|
-
if (settings?.toUpperCase) val = val.toUpperCase();
|
|
1733
|
-
if (settings?.toLowerCase) val = val.toLowerCase();
|
|
1734
|
-
return val;
|
|
1735
|
-
}, "coerce"),
|
|
1736
|
-
validate: /* @__PURE__ */ __name((val) => {
|
|
1737
|
-
const errors = [];
|
|
1738
|
-
if (settings?.minLength !== void 0 && val.length < settings.minLength) {
|
|
1739
|
-
errors.push(new ValidationError(`Length must be more than ${settings.minLength}`));
|
|
1740
|
-
}
|
|
1741
|
-
if (settings?.maxLength !== void 0 && val.length > settings.maxLength) {
|
|
1742
|
-
errors.push(new ValidationError(`Length must be less than ${settings.maxLength}`));
|
|
1743
|
-
}
|
|
1744
|
-
if (settings?.isLength !== void 0 && val.length !== settings.isLength) {
|
|
1745
|
-
errors.push(new ValidationError(`Length must be exactly ${settings.isLength}`));
|
|
1746
|
-
}
|
|
1747
|
-
if (settings?.startsWith && !val.startsWith(settings.startsWith)) {
|
|
1748
|
-
errors.push(new ValidationError(`Value must start with "${settings.startsWith}"`));
|
|
1749
|
-
}
|
|
1750
|
-
if (settings?.endsWith && !val.endsWith(settings.endsWith)) {
|
|
1751
|
-
errors.push(new ValidationError(`Value must start with "${settings.endsWith}"`));
|
|
1752
|
-
}
|
|
1753
|
-
if (settings?.matches) {
|
|
1754
|
-
const regex = my_dash_default.isString(settings.matches) ? new RegExp(settings.matches) : settings.matches;
|
|
1755
|
-
const matches = val.match(regex);
|
|
1756
|
-
if (!matches) {
|
|
1757
|
-
errors.push(new ValidationError(`Value must match regex "${settings.matches}"`));
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
return errors.length ? errors : true;
|
|
1761
|
-
}, "validate")
|
|
1762
|
-
})
|
|
1763
|
-
);
|
|
1764
|
-
var NumberDataType = createEnvGraphDataType(
|
|
1765
|
-
(settings) => ({
|
|
1766
|
-
name: "number",
|
|
1767
|
-
icon: "carbon:string-integer",
|
|
1768
|
-
coerce(rawVal) {
|
|
1769
|
-
let numVal = coerceToNumber(rawVal);
|
|
1770
|
-
if (settings?.coerceToMinMaxRange) {
|
|
1771
|
-
if (settings?.min !== void 0) numVal = Math.max(settings?.min, numVal);
|
|
1772
|
-
if (settings?.max !== void 0) numVal = Math.min(settings?.max, numVal);
|
|
1773
|
-
}
|
|
1774
|
-
if (settings?.isInt === true || settings?.precision === 0) {
|
|
1775
|
-
numVal = Math.round(numVal);
|
|
1776
|
-
} else if (settings?.precision) {
|
|
1777
|
-
const p = 10 ** settings.precision;
|
|
1778
|
-
numVal = Math.round(numVal * p) / p;
|
|
1779
|
-
}
|
|
1780
|
-
return numVal;
|
|
1781
|
-
},
|
|
1782
|
-
validate(val) {
|
|
1783
|
-
const errors = [];
|
|
1784
|
-
if (settings?.min !== void 0 && val < settings?.min) {
|
|
1785
|
-
errors.push(new ValidationError(`Min value is ${settings?.min}`));
|
|
1786
|
-
}
|
|
1787
|
-
if (settings?.max !== void 0 && val > settings?.max) {
|
|
1788
|
-
errors.push(new ValidationError(`Max value is ${settings?.max}`));
|
|
1789
|
-
}
|
|
1790
|
-
if (settings?.isDivisibleBy !== void 0 && val % settings.isDivisibleBy !== 0) {
|
|
1791
|
-
errors.push(new ValidationError(`Value must be divisible by ${settings?.isDivisibleBy}`));
|
|
1536
|
+
const originalValue = await this.fnArgs[0].resolve();
|
|
1537
|
+
if (!this.remappings) throw new Error("expected remappings to be set");
|
|
1538
|
+
for (const [remappedVal, matchValResolver] of Object.entries(this.remappings)) {
|
|
1539
|
+
const matchVal = await matchValResolver.resolve();
|
|
1540
|
+
if (matchVal instanceof RegExp && originalValue !== void 0) {
|
|
1541
|
+
if (matchVal.test(String(originalValue))) return remappedVal;
|
|
1542
|
+
} else {
|
|
1543
|
+
if (matchVal === originalValue) return remappedVal;
|
|
1792
1544
|
}
|
|
1793
|
-
return errors.length ? errors : true;
|
|
1794
1545
|
}
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1546
|
+
return originalValue;
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
var BaseResolvers = [
|
|
1550
|
+
ConcatResolver,
|
|
1551
|
+
FallbackResolver,
|
|
1552
|
+
RefResolver,
|
|
1553
|
+
ExecResolver,
|
|
1554
|
+
RemapResolver,
|
|
1555
|
+
RegexResolver
|
|
1556
|
+
];
|
|
1557
|
+
|
|
1558
|
+
// ../env-graph/src/lib/graph-utils.ts
|
|
1559
|
+
function findGraphCycles(graph) {
|
|
1560
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1561
|
+
const recursionStack = /* @__PURE__ */ new Set();
|
|
1562
|
+
const cycles = [];
|
|
1563
|
+
const currentPath = [];
|
|
1564
|
+
function dfs(node) {
|
|
1565
|
+
if (recursionStack.has(node)) {
|
|
1566
|
+
const cycleStart = currentPath.indexOf(node);
|
|
1567
|
+
const cycle = currentPath.slice(cycleStart);
|
|
1568
|
+
cycles.push(cycle);
|
|
1569
|
+
return;
|
|
1817
1570
|
}
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1571
|
+
if (visited.has(node)) {
|
|
1572
|
+
return;
|
|
1573
|
+
}
|
|
1574
|
+
visited.add(node);
|
|
1575
|
+
recursionStack.add(node);
|
|
1576
|
+
currentPath.push(node);
|
|
1577
|
+
for (const neighbor of graph[node] || []) {
|
|
1578
|
+
dfs(neighbor);
|
|
1579
|
+
}
|
|
1580
|
+
recursionStack.delete(node);
|
|
1581
|
+
currentPath.pop();
|
|
1823
1582
|
}
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
icon: "carbon:url",
|
|
1829
|
-
coerce(rawVal) {
|
|
1830
|
-
const val = coerceToString(rawVal);
|
|
1831
|
-
if (settings?.prependHttps && !val.startsWith("https://")) return `https://${val}`;
|
|
1832
|
-
return val;
|
|
1833
|
-
},
|
|
1834
|
-
validate(val) {
|
|
1835
|
-
const url = new URL(val);
|
|
1836
|
-
if (settings?.allowedDomains && !settings.allowedDomains.includes(url.host.toLowerCase())) {
|
|
1837
|
-
return new ValidationError(`Domain (${url.host}) is not in allowed list: ${settings.allowedDomains.join(",")}`);
|
|
1838
|
-
}
|
|
1839
|
-
return true;
|
|
1583
|
+
__name(dfs, "dfs");
|
|
1584
|
+
for (const node of Object.keys(graph)) {
|
|
1585
|
+
if (!visited.has(node)) {
|
|
1586
|
+
dfs(node);
|
|
1840
1587
|
}
|
|
1841
|
-
}
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1588
|
+
}
|
|
1589
|
+
return cycles;
|
|
1590
|
+
}
|
|
1591
|
+
__name(findGraphCycles, "findGraphCycles");
|
|
1592
|
+
var AUTOGENERATED_FILE_BANNER = `
|
|
1593
|
+
// \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}
|
|
1594
|
+
// \u{1F6D1} THIS IS AN AUTOGENERATED FILE - DO NOT EDIT DIRECTLY \u{1F6D1}
|
|
1595
|
+
// \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}
|
|
1596
|
+
`;
|
|
1597
|
+
var ICON_SIZE = 20;
|
|
1598
|
+
var iconCacheFolderInit = false;
|
|
1599
|
+
var iconInMemoryCache = {};
|
|
1600
|
+
async function fetchIconSvg(iconifyName, color = "808080", iconCacheFolder = "/tmp/varlock-icon-cache") {
|
|
1601
|
+
if (!iconCacheFolderInit) {
|
|
1602
|
+
fs.mkdirSync(iconCacheFolder, { recursive: true });
|
|
1603
|
+
iconCacheFolderInit = true;
|
|
1604
|
+
}
|
|
1605
|
+
const iconPath = `${iconCacheFolder}/${iconifyName}-${ICON_SIZE}.svg`;
|
|
1606
|
+
let svgSrc;
|
|
1607
|
+
if (iconInMemoryCache[iconPath]) {
|
|
1608
|
+
svgSrc = iconInMemoryCache[iconPath];
|
|
1609
|
+
} else if (fs.existsSync(iconPath)) {
|
|
1610
|
+
const svgFileBuffer = await fs.promises.readFile(iconPath, "utf-8");
|
|
1611
|
+
svgSrc = svgFileBuffer.toString();
|
|
1612
|
+
iconInMemoryCache[iconPath] = svgSrc;
|
|
1613
|
+
} else {
|
|
1614
|
+
try {
|
|
1615
|
+
const iconSvg = await fetch(`https://api.iconify.design/${iconifyName.replace(":", "/")}.svg?height=${ICON_SIZE}`);
|
|
1616
|
+
svgSrc = await iconSvg.text();
|
|
1617
|
+
} catch (err) {
|
|
1618
|
+
return;
|
|
1619
|
+
}
|
|
1620
|
+
if (!svgSrc) return;
|
|
1621
|
+
if (svgSrc) {
|
|
1622
|
+
await fs.promises.writeFile(iconPath, svgSrc, "utf-8");
|
|
1623
|
+
iconInMemoryCache[iconPath] = svgSrc;
|
|
1857
1624
|
}
|
|
1858
|
-
return new CoercionError("Cannot coerce value to object");
|
|
1859
|
-
},
|
|
1860
|
-
validate(val) {
|
|
1861
|
-
if (my_dash_default.isPlainObject(val)) return true;
|
|
1862
|
-
return new ValidationError("Value must be an object");
|
|
1863
1625
|
}
|
|
1864
|
-
}
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1626
|
+
const hexColor = color.startsWith("#") ? color : `#${color}`;
|
|
1627
|
+
const colorizedSvg = svgSrc.replaceAll("currentColor", hexColor);
|
|
1628
|
+
return colorizedSvg;
|
|
1629
|
+
}
|
|
1630
|
+
__name(fetchIconSvg, "fetchIconSvg");
|
|
1631
|
+
async function getTsDefinitionForItem(item, indentLevel = 0) {
|
|
1632
|
+
const i = my_dash_default.times(indentLevel, () => " ").join("");
|
|
1633
|
+
const itemSrc = [];
|
|
1634
|
+
const jsDocLines = [];
|
|
1635
|
+
jsDocLines.push(`**${item.key}**${item.isSensitive ? " \u{1F510} _sensitive_" : ""}`);
|
|
1636
|
+
if (item.description) jsDocLines.push(...item.description.split("\n"));
|
|
1637
|
+
const iconName = item.icon;
|
|
1638
|
+
if (iconName) {
|
|
1639
|
+
const iconSvg = await fetchIconSvg(iconName);
|
|
1640
|
+
if (iconSvg) jsDocLines.push(`}) `);
|
|
1641
|
+
}
|
|
1642
|
+
const docsLinks = item.docsLinks;
|
|
1643
|
+
if (docsLinks.length) {
|
|
1644
|
+
jsDocLines.push("");
|
|
1645
|
+
docsLinks.forEach((docsEntry) => {
|
|
1646
|
+
const docsLink = my_dash_default.compact([docsEntry.url, docsEntry.description]).join(" | ");
|
|
1647
|
+
jsDocLines.push(`\u{1F4DA} {@link ${docsLink}}`);
|
|
1648
|
+
});
|
|
1649
|
+
}
|
|
1650
|
+
if (jsDocLines.length === 1) {
|
|
1651
|
+
itemSrc.push(`/** ${jsDocLines[0]} */`);
|
|
1652
|
+
} else if (jsDocLines.length > 1) {
|
|
1653
|
+
itemSrc.push(...[
|
|
1654
|
+
"/**",
|
|
1655
|
+
// extra 2 trailing spaces are needed to make line breaks visible
|
|
1656
|
+
...my_dash_default.flatMap(jsDocLines, (line) => [` * ${line} `]),
|
|
1657
|
+
" */"
|
|
1658
|
+
]);
|
|
1659
|
+
}
|
|
1660
|
+
const dataType = item.dataType;
|
|
1661
|
+
const dataTypeName = dataType?.name;
|
|
1662
|
+
let itemTsType = "string";
|
|
1663
|
+
if (dataType) {
|
|
1664
|
+
if (dataTypeName === "number" || dataTypeName === "port") {
|
|
1665
|
+
itemTsType = "number";
|
|
1666
|
+
} else if (dataTypeName === "boolean") {
|
|
1667
|
+
itemTsType = "boolean";
|
|
1668
|
+
} else if (dataTypeName === "simple-object") {
|
|
1669
|
+
itemTsType = "Record<string, any>";
|
|
1670
|
+
} else if (dataTypeName === "enum") {
|
|
1671
|
+
const rawEnumOptions = dataType._rawDef._rawEnumOptions;
|
|
1672
|
+
let enumOptions = [];
|
|
1673
|
+
enumOptions = rawEnumOptions;
|
|
1674
|
+
if (!enumOptions.length) {
|
|
1675
|
+
itemTsType = "never";
|
|
1676
|
+
} else {
|
|
1677
|
+
itemTsType = my_dash_default.map(enumOptions, JSON.stringify).join(" | ");
|
|
1880
1678
|
}
|
|
1881
|
-
},
|
|
1882
|
-
_rawEnumOptions: enumOptions
|
|
1883
|
-
})
|
|
1884
|
-
);
|
|
1885
|
-
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,}))$/;
|
|
1886
|
-
var EmailDataType = createEnvGraphDataType(
|
|
1887
|
-
(settings) => ({
|
|
1888
|
-
name: "email",
|
|
1889
|
-
icon: "iconoir:at-sign",
|
|
1890
|
-
typeDescription: "standard email address",
|
|
1891
|
-
coerce(rawVal) {
|
|
1892
|
-
let val = coerceToString(rawVal);
|
|
1893
|
-
if (settings?.normalize) val = val.toLowerCase();
|
|
1894
|
-
return val;
|
|
1895
|
-
},
|
|
1896
|
-
validate(val) {
|
|
1897
|
-
const result = EMAIL_REGEX.test(val);
|
|
1898
|
-
if (result) return true;
|
|
1899
|
-
return new ValidationError("Value must be a valid email address");
|
|
1900
1679
|
}
|
|
1901
|
-
}
|
|
1902
|
-
);
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1680
|
+
}
|
|
1681
|
+
itemSrc.push(`readonly ${item.key}${item.isRequired ? "" : "?"}: ${itemTsType};`);
|
|
1682
|
+
itemSrc.push("");
|
|
1683
|
+
return my_dash_default.map(itemSrc, (line) => `${i}${line}`);
|
|
1684
|
+
}
|
|
1685
|
+
__name(getTsDefinitionForItem, "getTsDefinitionForItem");
|
|
1686
|
+
async function generateTsTypesSrc(graph) {
|
|
1687
|
+
const tsSrc = [
|
|
1688
|
+
AUTOGENERATED_FILE_BANNER,
|
|
1689
|
+
// might want to add some options to let users inject this, or somehow detect eslint, but fine for now
|
|
1690
|
+
"/* eslint-disable */",
|
|
1691
|
+
"export type CoercedEnvSchema = {"
|
|
1692
|
+
];
|
|
1693
|
+
const exposedNonSensitiveKeys = [];
|
|
1694
|
+
for (const itemKey in graph.configSchema) {
|
|
1695
|
+
const configItem = graph.configSchema[itemKey];
|
|
1696
|
+
tsSrc.push(...await getTsDefinitionForItem(configItem, 1));
|
|
1697
|
+
if (!configItem.isSensitive) exposedNonSensitiveKeys.push(itemKey);
|
|
1698
|
+
}
|
|
1699
|
+
tsSrc.push("};\n");
|
|
1700
|
+
tsSrc.push(`
|
|
1701
|
+
declare module 'varlock/env' {
|
|
1702
|
+
export interface TypedEnvSchema extends CoercedEnvSchema {}
|
|
1703
|
+
export interface PublicTypedEnvSchema extends Pick<CoercedEnvSchema, '${exposedNonSensitiveKeys.join("' | '")}'> {}
|
|
1704
|
+
}
|
|
1705
|
+
`);
|
|
1706
|
+
tsSrc.push(`
|
|
1707
|
+
export type EnvSchemaAsStrings = {
|
|
1708
|
+
[Property in keyof CoercedEnvSchema]:
|
|
1709
|
+
CoercedEnvSchema[Property] extends string ? CoercedEnvSchema[Property]
|
|
1710
|
+
: (CoercedEnvSchema[Property] extends boolean ? ('true' | 'false') : string)
|
|
1711
|
+
};
|
|
1712
|
+
`);
|
|
1713
|
+
const IMPORT_META_AUGMENTATION = `
|
|
1714
|
+
// add types for global import.meta.env
|
|
1715
|
+
interface ImportMetaEnv extends EnvSchemaAsStrings {}
|
|
1716
|
+
interface ImportMeta {
|
|
1717
|
+
readonly env: ImportMetaEnv;
|
|
1718
|
+
}`;
|
|
1719
|
+
const PROCESS_ENV_AUGMENTATION = `
|
|
1720
|
+
// add types for global process.env
|
|
1721
|
+
namespace NodeJS {
|
|
1722
|
+
interface ProcessEnv extends EnvSchemaAsStrings {}
|
|
1723
|
+
}`;
|
|
1724
|
+
tsSrc.push(...[
|
|
1725
|
+
"declare global {",
|
|
1726
|
+
IMPORT_META_AUGMENTATION,
|
|
1727
|
+
PROCESS_ENV_AUGMENTATION,
|
|
1728
|
+
"}"
|
|
1729
|
+
].filter(Boolean));
|
|
1730
|
+
return tsSrc.join("\n");
|
|
1731
|
+
}
|
|
1732
|
+
__name(generateTsTypesSrc, "generateTsTypesSrc");
|
|
1733
|
+
async function generateTypes(graph, lang, outputPath) {
|
|
1734
|
+
if (lang !== "ts") throw new Error(`Unsupported @generateTypes lang: ${lang}`);
|
|
1735
|
+
const tsSrc = await generateTsTypesSrc(graph);
|
|
1736
|
+
if (!graph.basePath) return;
|
|
1737
|
+
const typesPath = path.join(graph.basePath, outputPath);
|
|
1738
|
+
await fs.promises.writeFile(typesPath, tsSrc, "utf-8");
|
|
1739
|
+
}
|
|
1740
|
+
__name(generateTypes, "generateTypes");
|
|
1741
|
+
|
|
1742
|
+
// ../env-graph/src/lib/env-graph.ts
|
|
1743
|
+
var EnvGraph2 = class {
|
|
1744
|
+
static {
|
|
1745
|
+
__name(this, "EnvGraph");
|
|
1746
|
+
}
|
|
1747
|
+
// TODO: not sure if this should be the graph of _everything_ in a workspace/project
|
|
1748
|
+
// or just the files that are relevant to the current resolution attempt
|
|
1749
|
+
// (which would mean it's always through the lens of the current directory/package)
|
|
1750
|
+
basePath;
|
|
1751
|
+
/** array of data sources */
|
|
1752
|
+
dataSources = [];
|
|
1753
|
+
finalOverridesDataSource;
|
|
1754
|
+
/** config item key of env flag (toggles env-specific data sources enabled) */
|
|
1755
|
+
envFlagKey;
|
|
1756
|
+
/** current value of the environment flag */
|
|
1757
|
+
envFlagValue;
|
|
1758
|
+
configSchema = {};
|
|
1759
|
+
addDataSource(dataSource) {
|
|
1760
|
+
dataSource.graph = this;
|
|
1761
|
+
this.dataSources.push(dataSource);
|
|
1762
|
+
}
|
|
1763
|
+
get schemaDataSource() {
|
|
1764
|
+
const schemas = this.dataSources.filter((f) => f.type === "schema");
|
|
1765
|
+
if (schemas.length > 1) throw new Error("Multiple schema data sources found");
|
|
1766
|
+
if (schemas.length === 0) return void 0;
|
|
1767
|
+
return schemas[0];
|
|
1768
|
+
}
|
|
1769
|
+
get sortedDataSources() {
|
|
1770
|
+
return my_dash_default.sortBy(this.dataSources, (f) => 10 * EnvGraphDataSource.DATA_SOURCE_TYPES[f.type].precedence + (f.applyForEnv ? 1 : 0));
|
|
1771
|
+
}
|
|
1772
|
+
registeredResolverFunctions = {};
|
|
1773
|
+
registerResolver(resolverClass) {
|
|
1774
|
+
const fnName = resolverClass.fnName;
|
|
1775
|
+
if (fnName in this.registeredResolverFunctions) {
|
|
1776
|
+
throw new Error(`Resolver ${fnName} already registered`);
|
|
1920
1777
|
}
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
(
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1778
|
+
this.registeredResolverFunctions[fnName] = resolverClass;
|
|
1779
|
+
}
|
|
1780
|
+
dataTypesRegistry = {};
|
|
1781
|
+
registerDataType(factory) {
|
|
1782
|
+
this.dataTypesRegistry[factory.dataTypeName] = factory;
|
|
1783
|
+
}
|
|
1784
|
+
constructor() {
|
|
1785
|
+
for (const dataType of my_dash_default.values(BaseDataTypes)) {
|
|
1786
|
+
this.registerDataType(dataType);
|
|
1787
|
+
}
|
|
1788
|
+
for (const resolverClass of BaseResolvers) {
|
|
1789
|
+
this.registerResolver(resolverClass);
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
async finishLoad() {
|
|
1793
|
+
const sortedDataSources = this.sortedDataSources;
|
|
1794
|
+
for (const source of sortedDataSources) {
|
|
1795
|
+
if (source.loadingError) {
|
|
1796
|
+
throw source.loadingError;
|
|
1933
1797
|
}
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
if (settings?.min !== void 0 && val < settings?.min) {
|
|
1938
|
-
return new ValidationError(`Min value is ${settings?.min}`);
|
|
1798
|
+
if (source.type === "example") {
|
|
1799
|
+
source.disabled = true;
|
|
1800
|
+
continue;
|
|
1939
1801
|
}
|
|
1940
|
-
if (
|
|
1941
|
-
|
|
1802
|
+
if (source.decorators?.envFlag) {
|
|
1803
|
+
if (source.applyForEnv) {
|
|
1804
|
+
throw new Error(`@envFlag cannot be set from within an env-specific data source - ${source.label}`);
|
|
1805
|
+
} else if (this.envFlagKey) {
|
|
1806
|
+
throw new Error("only a single @envFlag setting is allowed");
|
|
1807
|
+
} else {
|
|
1808
|
+
const envFlagKey = source.decorators.envFlag.simplifiedValue;
|
|
1809
|
+
if (!my_dash_default.isString(envFlagKey)) {
|
|
1810
|
+
throw new Error("@envFlag must be a string");
|
|
1811
|
+
} else {
|
|
1812
|
+
this.envFlagKey = envFlagKey;
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1942
1815
|
}
|
|
1943
|
-
if (
|
|
1944
|
-
|
|
1816
|
+
if (source.applyForEnv) {
|
|
1817
|
+
if (source.applyForEnv && this.envFlagValue !== source.applyForEnv) {
|
|
1818
|
+
source.disabled = true;
|
|
1819
|
+
continue;
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
if (source.decorators?.disable && source.decorators.disable.simplifiedValue) {
|
|
1823
|
+
source.disabled = true;
|
|
1824
|
+
continue;
|
|
1825
|
+
}
|
|
1826
|
+
for (const itemKey in source.configItemDefs) {
|
|
1827
|
+
if (source.ignoreNewDefs && !this.configSchema[itemKey]) continue;
|
|
1828
|
+
const itemDef = source.configItemDefs[itemKey];
|
|
1829
|
+
this.configSchema[itemKey] ??= new ConfigItem3(this, itemKey);
|
|
1830
|
+
this.configSchema[itemKey].addDef(itemDef, source);
|
|
1831
|
+
}
|
|
1832
|
+
if (source.type === "schema" && this.envFlagKey) {
|
|
1833
|
+
if (!this.configSchema[this.envFlagKey]) {
|
|
1834
|
+
throw new Error(`@envFlag key ${this.envFlagKey} not found in schema`);
|
|
1835
|
+
}
|
|
1836
|
+
const envFlagItem = this.configSchema[this.envFlagKey];
|
|
1837
|
+
await envFlagItem.process();
|
|
1838
|
+
for (const depKey of envFlagItem.valueResolver?.deps || []) {
|
|
1839
|
+
const depItem = this.configSchema[depKey];
|
|
1840
|
+
if (!depItem) {
|
|
1841
|
+
throw new Error(`envFlag resolver is using non-existant dependency: ${depKey}`);
|
|
1842
|
+
}
|
|
1843
|
+
await depItem.process();
|
|
1844
|
+
if (depItem.valueResolver?.deps.length) {
|
|
1845
|
+
throw new Error("envFlag cannot follow a chain of dependencies");
|
|
1846
|
+
}
|
|
1847
|
+
await depItem.resolve();
|
|
1848
|
+
}
|
|
1849
|
+
await envFlagItem.resolve();
|
|
1850
|
+
if (!envFlagItem.isValid) {
|
|
1851
|
+
const err = new Error("resolved @envFlag value is not valid");
|
|
1852
|
+
err.cause = envFlagItem.errors[0];
|
|
1853
|
+
throw err;
|
|
1854
|
+
}
|
|
1855
|
+
if (envFlagItem.resolvedValue) {
|
|
1856
|
+
if (!my_dash_default.isString(envFlagItem.resolvedValue)) {
|
|
1857
|
+
throw new Error("expected resolved @envFlag value to be a string");
|
|
1858
|
+
}
|
|
1859
|
+
this.envFlagValue = envFlagItem.resolvedValue;
|
|
1860
|
+
}
|
|
1945
1861
|
}
|
|
1946
|
-
return true;
|
|
1947
1862
|
}
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
var SemverDataType = createEnvGraphDataType(
|
|
1952
|
-
(settings) => ({
|
|
1953
|
-
name: "semver",
|
|
1954
|
-
icon: "simple-icons:semver",
|
|
1955
|
-
typeDescription: "semantic version string",
|
|
1956
|
-
validate(val) {
|
|
1957
|
-
const result = SEMVER_REGEX.test(val);
|
|
1958
|
-
if (result) return true;
|
|
1959
|
-
return new ValidationError("Value must be a valid semantic version string");
|
|
1863
|
+
for (const itemKey in this.configSchema) {
|
|
1864
|
+
const item = this.configSchema[itemKey];
|
|
1865
|
+
await item.process();
|
|
1960
1866
|
}
|
|
1961
|
-
|
|
1962
|
-
)
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
return new ValidationError("Value must be a valid ISO 8601 date string");
|
|
1972
|
-
}
|
|
1973
|
-
});
|
|
1974
|
-
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;
|
|
1975
|
-
var UuidDataType = createEnvGraphDataType({
|
|
1976
|
-
name: "uuid",
|
|
1977
|
-
icon: "mdi:identifier",
|
|
1978
|
-
typeDescription: "UUID string V1-V5 per RFC4122, including NIL",
|
|
1979
|
-
validate(val) {
|
|
1980
|
-
const result = UUID_REGEX.test(val);
|
|
1981
|
-
if (result) return true;
|
|
1982
|
-
return new ValidationError("Value must be a valid UUID string");
|
|
1983
|
-
}
|
|
1984
|
-
});
|
|
1985
|
-
var MD5_REGEX = /^[a-f0-9]{32}$/;
|
|
1986
|
-
var Md5DataType = createEnvGraphDataType({
|
|
1987
|
-
name: "md5",
|
|
1988
|
-
typeDescription: "MD5 hash string",
|
|
1989
|
-
validate(val) {
|
|
1990
|
-
const result = MD5_REGEX.test(val);
|
|
1991
|
-
if (result) return true;
|
|
1992
|
-
return new ValidationError("Value must be a valid MD5 hash string");
|
|
1993
|
-
}
|
|
1994
|
-
});
|
|
1995
|
-
var BaseDataTypes = {
|
|
1996
|
-
string: StringDataType,
|
|
1997
|
-
number: NumberDataType,
|
|
1998
|
-
boolean: BooleanDataType,
|
|
1999
|
-
simpleObject: SimpleObjectDataType,
|
|
2000
|
-
enum: EnumDataType,
|
|
2001
|
-
email: EmailDataType,
|
|
2002
|
-
url: UrlDataType,
|
|
2003
|
-
ipAddress: ipAddressDataType,
|
|
2004
|
-
port: PortDataType,
|
|
2005
|
-
semver: SemverDataType,
|
|
2006
|
-
isoDate: IsoDateDataType,
|
|
2007
|
-
uuid: UuidDataType,
|
|
2008
|
-
md5: Md5DataType
|
|
2009
|
-
};
|
|
2010
|
-
|
|
2011
|
-
// ../env-graph/src/lib/graph-utils.ts
|
|
2012
|
-
function findGraphCycles(graph) {
|
|
2013
|
-
const visited = /* @__PURE__ */ new Set();
|
|
2014
|
-
const recursionStack = /* @__PURE__ */ new Set();
|
|
2015
|
-
const cycles = [];
|
|
2016
|
-
const currentPath = [];
|
|
2017
|
-
function dfs(node) {
|
|
2018
|
-
if (recursionStack.has(node)) {
|
|
2019
|
-
const cycleStart = currentPath.indexOf(node);
|
|
2020
|
-
const cycle = currentPath.slice(cycleStart);
|
|
2021
|
-
cycles.push(cycle);
|
|
2022
|
-
return;
|
|
1867
|
+
const cycles = findGraphCycles(this.graphAdjacencyList);
|
|
1868
|
+
for (const cycleItemKeys of cycles) {
|
|
1869
|
+
for (const itemKey of cycleItemKeys) {
|
|
1870
|
+
const item = this.configSchema[itemKey];
|
|
1871
|
+
item.schemaErrors.push(
|
|
1872
|
+
new SchemaError(
|
|
1873
|
+
cycleItemKeys.length === 1 ? "Item cannot have dependency on itself" : `Dependency cycle detected: (${cycleItemKeys.join(", ")})`
|
|
1874
|
+
)
|
|
1875
|
+
);
|
|
1876
|
+
}
|
|
2023
1877
|
}
|
|
2024
|
-
|
|
2025
|
-
|
|
1878
|
+
}
|
|
1879
|
+
get graphAdjacencyList() {
|
|
1880
|
+
const adjList = {};
|
|
1881
|
+
for (const itemKey in this.configSchema) {
|
|
1882
|
+
const item = this.configSchema[itemKey];
|
|
1883
|
+
adjList[itemKey] = item.valueResolver?.deps || [];
|
|
2026
1884
|
}
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
1885
|
+
return adjList;
|
|
1886
|
+
}
|
|
1887
|
+
async resolveEnvValues() {
|
|
1888
|
+
const adjList = this.graphAdjacencyList;
|
|
1889
|
+
const reverseAdjList = {};
|
|
1890
|
+
for (const itemKey in adjList) {
|
|
1891
|
+
const itemDeps = adjList[itemKey];
|
|
1892
|
+
for (const dep of itemDeps) {
|
|
1893
|
+
reverseAdjList[dep] ??= [];
|
|
1894
|
+
reverseAdjList[dep].push(itemKey);
|
|
1895
|
+
}
|
|
2032
1896
|
}
|
|
2033
|
-
|
|
2034
|
-
|
|
1897
|
+
const itemsToResolveStatus = my_dash_default.mapValues(this.configSchema, () => false);
|
|
1898
|
+
const deferred = new Promise((resolve, reject) => {
|
|
1899
|
+
const markItemCompleted = /* @__PURE__ */ __name((itemKey) => {
|
|
1900
|
+
delete itemsToResolveStatus[itemKey];
|
|
1901
|
+
if (reverseAdjList[itemKey]) {
|
|
1902
|
+
reverseAdjList[itemKey].forEach(resolveItem);
|
|
1903
|
+
}
|
|
1904
|
+
if (my_dash_default.keys(itemsToResolveStatus).length === 0) resolve();
|
|
1905
|
+
}, "markItemCompleted");
|
|
1906
|
+
const resolveItem = /* @__PURE__ */ __name(async (itemKey) => {
|
|
1907
|
+
if (itemsToResolveStatus[itemKey] !== false) return;
|
|
1908
|
+
const item = this.configSchema[itemKey];
|
|
1909
|
+
if (item.errors.length) {
|
|
1910
|
+
markItemCompleted(itemKey);
|
|
1911
|
+
return;
|
|
1912
|
+
}
|
|
1913
|
+
for (const depKey of adjList[itemKey]) {
|
|
1914
|
+
const depItem = this.configSchema[depKey];
|
|
1915
|
+
if (depItem.validationState === "error") {
|
|
1916
|
+
item.resolutionError = new ResolutionError(`Dependency ${depKey} is invalid`);
|
|
1917
|
+
markItemCompleted(itemKey);
|
|
1918
|
+
return;
|
|
1919
|
+
} else if (depKey in itemsToResolveStatus) {
|
|
1920
|
+
return;
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
itemsToResolveStatus[itemKey] = true;
|
|
1924
|
+
await item.resolve();
|
|
1925
|
+
markItemCompleted(itemKey);
|
|
1926
|
+
}, "resolveItem");
|
|
1927
|
+
for (const itemKey in this.configSchema) {
|
|
1928
|
+
resolveItem(itemKey);
|
|
1929
|
+
}
|
|
1930
|
+
});
|
|
1931
|
+
return deferred;
|
|
2035
1932
|
}
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
1933
|
+
getResolvedEnvObject() {
|
|
1934
|
+
const envObject = {};
|
|
1935
|
+
for (const itemKey in this.configSchema) {
|
|
1936
|
+
const item = this.configSchema[itemKey];
|
|
1937
|
+
envObject[itemKey] = item.resolvedValue;
|
|
2040
1938
|
}
|
|
1939
|
+
return envObject;
|
|
2041
1940
|
}
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
fs2.mkdirSync(iconCacheFolder, { recursive: true });
|
|
2056
|
-
iconCacheFolderInit = true;
|
|
2057
|
-
}
|
|
2058
|
-
const iconPath = `${iconCacheFolder}/${iconifyName}-${ICON_SIZE}.svg`;
|
|
2059
|
-
let svgSrc;
|
|
2060
|
-
if (iconInMemoryCache[iconPath]) {
|
|
2061
|
-
svgSrc = iconInMemoryCache[iconPath];
|
|
2062
|
-
} else if (fs2.existsSync(iconPath)) {
|
|
2063
|
-
const svgFileBuffer = await fs2.promises.readFile(iconPath, "utf-8");
|
|
2064
|
-
svgSrc = svgFileBuffer.toString();
|
|
2065
|
-
iconInMemoryCache[iconPath] = svgSrc;
|
|
2066
|
-
} else {
|
|
2067
|
-
try {
|
|
2068
|
-
const iconSvg = await fetch(`https://api.iconify.design/${iconifyName.replace(":", "/")}.svg?height=${ICON_SIZE}`);
|
|
2069
|
-
svgSrc = await iconSvg.text();
|
|
2070
|
-
} catch (err) {
|
|
2071
|
-
return;
|
|
1941
|
+
getSerializedGraph() {
|
|
1942
|
+
const serializedGraph = {
|
|
1943
|
+
basePath: this.basePath,
|
|
1944
|
+
sources: [],
|
|
1945
|
+
config: {},
|
|
1946
|
+
settings: {}
|
|
1947
|
+
};
|
|
1948
|
+
for (const source of this.sortedDataSources) {
|
|
1949
|
+
serializedGraph.sources.push({
|
|
1950
|
+
label: source.label,
|
|
1951
|
+
enabled: !source.disabled,
|
|
1952
|
+
path: source instanceof FileBasedDataSource ? path.relative(this.basePath ?? "", source.fullPath) : void 0
|
|
1953
|
+
});
|
|
2072
1954
|
}
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
1955
|
+
for (const itemKey in this.configSchema) {
|
|
1956
|
+
const item = this.configSchema[itemKey];
|
|
1957
|
+
serializedGraph.config[itemKey] = {
|
|
1958
|
+
value: item.resolvedValue,
|
|
1959
|
+
isSensitive: item.isSensitive
|
|
1960
|
+
};
|
|
2077
1961
|
}
|
|
1962
|
+
serializedGraph.settings.redactLogs = this.getRootDecoratorValue("redactLogs") ?? true;
|
|
1963
|
+
serializedGraph.settings.preventLeaks = this.getRootDecoratorValue("preventLeaks") ?? true;
|
|
1964
|
+
return serializedGraph;
|
|
2078
1965
|
}
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
return colorizedSvg;
|
|
2082
|
-
}
|
|
2083
|
-
__name(fetchIconSvg, "fetchIconSvg");
|
|
2084
|
-
async function getTsDefinitionForItem(item, indentLevel = 0) {
|
|
2085
|
-
const i = my_dash_default.times(indentLevel, () => " ").join("");
|
|
2086
|
-
const itemSrc = [];
|
|
2087
|
-
const jsDocLines = [];
|
|
2088
|
-
jsDocLines.push(`**${item.key}**${item.isSensitive ? " \u{1F510} _sensitive_" : ""}`);
|
|
2089
|
-
if (item.description) jsDocLines.push(...item.description.split("\n"));
|
|
2090
|
-
const iconName = item.icon;
|
|
2091
|
-
if (iconName) {
|
|
2092
|
-
const iconSvg = await fetchIconSvg(iconName);
|
|
2093
|
-
if (iconSvg) jsDocLines.push(`}) `);
|
|
2094
|
-
}
|
|
2095
|
-
const docsLinks = item.docsLinks;
|
|
2096
|
-
if (docsLinks.length) {
|
|
2097
|
-
jsDocLines.push("");
|
|
2098
|
-
docsLinks.forEach((docsEntry) => {
|
|
2099
|
-
const docsLink = my_dash_default.compact([docsEntry.url, docsEntry.description]).join(" | ");
|
|
2100
|
-
jsDocLines.push(`\u{1F4DA} {@link ${docsLink}}`);
|
|
2101
|
-
});
|
|
2102
|
-
}
|
|
2103
|
-
if (jsDocLines.length === 1) {
|
|
2104
|
-
itemSrc.push(`/** ${jsDocLines[0]} */`);
|
|
2105
|
-
} else if (jsDocLines.length > 1) {
|
|
2106
|
-
itemSrc.push(...[
|
|
2107
|
-
"/**",
|
|
2108
|
-
// extra 2 trailing spaces are needed to make line breaks visible
|
|
2109
|
-
...my_dash_default.flatMap(jsDocLines, (line) => [` * ${line} `]),
|
|
2110
|
-
" */"
|
|
2111
|
-
]);
|
|
1966
|
+
get isInvalid() {
|
|
1967
|
+
return my_dash_default.some(my_dash_default.values(this.configSchema), (i) => !i.isValid);
|
|
2112
1968
|
}
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
let itemTsType = "string";
|
|
2116
|
-
if (dataType) {
|
|
2117
|
-
if (dataTypeName === "number" || dataTypeName === "port") {
|
|
2118
|
-
itemTsType = "number";
|
|
2119
|
-
} else if (dataTypeName === "boolean") {
|
|
2120
|
-
itemTsType = "boolean";
|
|
2121
|
-
} else if (dataTypeName === "simple-object") {
|
|
2122
|
-
itemTsType = "Record<string, any>";
|
|
2123
|
-
} else if (dataTypeName === "enum") {
|
|
2124
|
-
const rawEnumOptions = dataType._rawDef._rawEnumOptions;
|
|
2125
|
-
let enumOptions = [];
|
|
2126
|
-
enumOptions = rawEnumOptions;
|
|
2127
|
-
if (!enumOptions.length) {
|
|
2128
|
-
itemTsType = "never";
|
|
2129
|
-
} else {
|
|
2130
|
-
itemTsType = my_dash_default.map(enumOptions, JSON.stringify).join(" | ");
|
|
2131
|
-
}
|
|
2132
|
-
}
|
|
1969
|
+
async generateTypes(lang, outputPath) {
|
|
1970
|
+
await generateTypes(this, lang, outputPath);
|
|
2133
1971
|
}
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
}
|
|
2138
|
-
__name(getTsDefinitionForItem, "getTsDefinitionForItem");
|
|
2139
|
-
async function generateTsTypesSrc(graph) {
|
|
2140
|
-
const tsSrc = [
|
|
2141
|
-
AUTOGENERATED_FILE_BANNER,
|
|
2142
|
-
// might want to add some options to let users inject this, or somehow detect eslint, but fine for now
|
|
2143
|
-
"/* eslint-disable */",
|
|
2144
|
-
"export type CoercedEnvSchema = {"
|
|
2145
|
-
];
|
|
2146
|
-
const exposedNonSensitiveKeys = [];
|
|
2147
|
-
for (const itemKey in graph.configSchema) {
|
|
2148
|
-
const configItem = graph.configSchema[itemKey];
|
|
2149
|
-
tsSrc.push(...await getTsDefinitionForItem(configItem, 1));
|
|
2150
|
-
if (!configItem.isSensitive) exposedNonSensitiveKeys.push(itemKey);
|
|
1972
|
+
getRootDecoratorValue(decoratorName) {
|
|
1973
|
+
const dec = this.schemaDataSource?.decorators?.[decoratorName];
|
|
1974
|
+
return dec?.simplifiedValue;
|
|
2151
1975
|
}
|
|
2152
|
-
tsSrc.push("};\n");
|
|
2153
|
-
tsSrc.push(`
|
|
2154
|
-
declare module 'varlock/env' {
|
|
2155
|
-
export interface TypedEnvSchema extends CoercedEnvSchema {}
|
|
2156
|
-
export interface PublicTypedEnvSchema extends Pick<CoercedEnvSchema, '${exposedNonSensitiveKeys.join("' | '")}'> {}
|
|
2157
|
-
}
|
|
2158
|
-
`);
|
|
2159
|
-
tsSrc.push(`
|
|
2160
|
-
export type EnvSchemaAsStrings = {
|
|
2161
|
-
[Property in keyof CoercedEnvSchema]:
|
|
2162
|
-
CoercedEnvSchema[Property] extends string ? CoercedEnvSchema[Property]
|
|
2163
|
-
: (CoercedEnvSchema[Property] extends boolean ? ('true' | 'false') : string)
|
|
2164
1976
|
};
|
|
2165
|
-
`);
|
|
2166
|
-
tsSrc.push(`
|
|
2167
|
-
declare global {
|
|
2168
|
-
namespace NodeJS {
|
|
2169
|
-
interface ProcessEnv extends EnvSchemaAsStrings {}
|
|
2170
|
-
}
|
|
2171
|
-
}`);
|
|
2172
|
-
return tsSrc.join("\n");
|
|
2173
|
-
}
|
|
2174
|
-
__name(generateTsTypesSrc, "generateTsTypesSrc");
|
|
2175
|
-
async function generateTypes(graph, lang, outputPath) {
|
|
2176
|
-
if (lang !== "ts") throw new Error(`Unsupported @generateTypes lang: ${lang}`);
|
|
2177
|
-
const tsSrc = await generateTsTypesSrc(graph);
|
|
2178
|
-
if (!graph.basePath) return;
|
|
2179
|
-
const typesPath = path.join(graph.basePath, outputPath);
|
|
2180
|
-
await fs2.promises.writeFile(typesPath, tsSrc, "utf-8");
|
|
2181
|
-
}
|
|
2182
|
-
__name(generateTypes, "generateTypes");
|
|
2183
1977
|
|
|
2184
|
-
// ../env-graph/src/lib/
|
|
2185
|
-
var
|
|
1978
|
+
// ../env-graph/src/lib/config-item.ts
|
|
1979
|
+
var ConfigItem3 = class {
|
|
1980
|
+
constructor(envGraph, key) {
|
|
1981
|
+
this.envGraph = envGraph;
|
|
1982
|
+
this.key = key;
|
|
1983
|
+
}
|
|
2186
1984
|
static {
|
|
2187
|
-
__name(this, "
|
|
1985
|
+
__name(this, "ConfigItem");
|
|
2188
1986
|
}
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
basePath;
|
|
2193
|
-
/** array of data sources */
|
|
2194
|
-
dataSources = [];
|
|
2195
|
-
finalOverridesDataSource;
|
|
2196
|
-
/** config item key of env flag (toggles env-specific data sources enabled) */
|
|
2197
|
-
envFlagKey;
|
|
2198
|
-
/** current value of the environment flag */
|
|
2199
|
-
envFlagValue;
|
|
2200
|
-
configSchema = {};
|
|
2201
|
-
addDataSource(dataSource) {
|
|
2202
|
-
dataSource.graph = this;
|
|
2203
|
-
this.dataSources.push(dataSource);
|
|
1987
|
+
defs = [];
|
|
1988
|
+
addDef(itemDef, source) {
|
|
1989
|
+
this.defs.unshift({ itemDef, source });
|
|
2204
1990
|
}
|
|
2205
|
-
get
|
|
2206
|
-
const
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
return schemas[0];
|
|
1991
|
+
get description() {
|
|
1992
|
+
for (const def of this.defs) {
|
|
1993
|
+
if (def.itemDef.description) return def.itemDef.description;
|
|
1994
|
+
}
|
|
2210
1995
|
}
|
|
2211
|
-
get
|
|
2212
|
-
|
|
1996
|
+
get icon() {
|
|
1997
|
+
const explicitIcon = this.getDecoratorValueString("icon");
|
|
1998
|
+
if (explicitIcon) return explicitIcon;
|
|
1999
|
+
return this.dataType?.icon;
|
|
2213
2000
|
}
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
const
|
|
2217
|
-
if (
|
|
2218
|
-
|
|
2001
|
+
get docsLinks() {
|
|
2002
|
+
const links = [];
|
|
2003
|
+
const docsUrl = this.getDecoratorValueString("docsUrl");
|
|
2004
|
+
if (docsUrl) links.push({ url: docsUrl });
|
|
2005
|
+
return links;
|
|
2006
|
+
}
|
|
2007
|
+
get valueResolver() {
|
|
2008
|
+
for (const def of this.defs) {
|
|
2009
|
+
if (def.itemDef.resolver) return def.itemDef.resolver;
|
|
2219
2010
|
}
|
|
2220
|
-
this.registeredResolverFunctions[fnName] = resolverClass;
|
|
2221
2011
|
}
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2012
|
+
getDecorator(decoratorName) {
|
|
2013
|
+
for (const def of this.defs) {
|
|
2014
|
+
const defDecorators = def.itemDef.decorators || {};
|
|
2015
|
+
if (decoratorName in defDecorators) {
|
|
2016
|
+
return defDecorators[decoratorName];
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2225
2019
|
}
|
|
2226
|
-
|
|
2227
|
-
for (const
|
|
2228
|
-
|
|
2020
|
+
getDecoratorValueRaw(decoratorName) {
|
|
2021
|
+
for (const def of this.defs) {
|
|
2022
|
+
const defDecorators = def.itemDef.decorators || {};
|
|
2023
|
+
if (decoratorName in defDecorators) {
|
|
2024
|
+
return defDecorators[decoratorName].value;
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
getDecoratorValueString(decoratorName) {
|
|
2029
|
+
const dec = this.getDecoratorValueRaw(decoratorName);
|
|
2030
|
+
if (dec instanceof ParsedEnvSpecStaticValue) return String(dec.value);
|
|
2031
|
+
}
|
|
2032
|
+
dataType;
|
|
2033
|
+
schemaErrors = [];
|
|
2034
|
+
get resolverSchemaErrors() {
|
|
2035
|
+
return this.valueResolver?.schemaErrors || [];
|
|
2036
|
+
}
|
|
2037
|
+
async process() {
|
|
2038
|
+
const finalOverrideDef = this.envGraph.finalOverridesDataSource?.configItemDefs[this.key];
|
|
2039
|
+
if (finalOverrideDef) {
|
|
2040
|
+
this.defs.unshift({ itemDef: finalOverrideDef, source: this.envGraph.finalOverridesDataSource });
|
|
2041
|
+
}
|
|
2042
|
+
for (const def of this.defs) {
|
|
2043
|
+
await def.itemDef.resolver?.process(this);
|
|
2044
|
+
}
|
|
2045
|
+
const typeDecoratorValue = this.getDecoratorValueRaw("type");
|
|
2046
|
+
let dataTypeName;
|
|
2047
|
+
let dataTypeArgs;
|
|
2048
|
+
if (typeDecoratorValue instanceof ParsedEnvSpecStaticValue) {
|
|
2049
|
+
dataTypeName = typeDecoratorValue.value;
|
|
2050
|
+
} else if (typeDecoratorValue instanceof ParsedEnvSpecFunctionCall) {
|
|
2051
|
+
dataTypeName = typeDecoratorValue.name;
|
|
2052
|
+
dataTypeArgs = typeDecoratorValue.simplifiedArgs;
|
|
2229
2053
|
}
|
|
2230
|
-
|
|
2231
|
-
this.
|
|
2054
|
+
if (!dataTypeName) {
|
|
2055
|
+
if (this.valueResolver?.inferredType) {
|
|
2056
|
+
dataTypeName = this.valueResolver.inferredType;
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
dataTypeName ||= "string";
|
|
2060
|
+
dataTypeArgs ||= [];
|
|
2061
|
+
if (!(dataTypeName in this.envGraph.dataTypesRegistry)) {
|
|
2062
|
+
this.schemaErrors.push(new SchemaError(`unknown data type: ${dataTypeName}`));
|
|
2063
|
+
} else {
|
|
2064
|
+
const dataTypeFactory = this.envGraph.dataTypesRegistry[dataTypeName];
|
|
2065
|
+
this.dataType = dataTypeFactory(...my_dash_default.isPlainObject(dataTypeArgs) ? [dataTypeArgs] : dataTypeArgs);
|
|
2232
2066
|
}
|
|
2233
2067
|
}
|
|
2234
|
-
|
|
2235
|
-
const
|
|
2236
|
-
|
|
2237
|
-
if (
|
|
2238
|
-
|
|
2068
|
+
get isRequired() {
|
|
2069
|
+
for (const def of this.defs) {
|
|
2070
|
+
const defDecorators = def.itemDef.decorators || {};
|
|
2071
|
+
if ("required" in defDecorators) {
|
|
2072
|
+
const val = defDecorators.required.simplifiedValue;
|
|
2073
|
+
if (typeof val === "boolean") return val;
|
|
2074
|
+
if (typeof val === "string") return val === "true";
|
|
2075
|
+
return Boolean(val);
|
|
2239
2076
|
}
|
|
2240
|
-
if (
|
|
2241
|
-
|
|
2242
|
-
|
|
2077
|
+
if ("optional" in defDecorators) {
|
|
2078
|
+
const val = defDecorators.optional.simplifiedValue;
|
|
2079
|
+
if (typeof val === "boolean") return !val;
|
|
2080
|
+
if (typeof val === "string") return val !== "true";
|
|
2081
|
+
return !val;
|
|
2243
2082
|
}
|
|
2244
|
-
if (source.decorators
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2083
|
+
if ("defaultRequired" in def.source.decorators) {
|
|
2084
|
+
const val = def.source.decorators.defaultRequired.simplifiedValue;
|
|
2085
|
+
if (val === "infer") {
|
|
2086
|
+
if (def.source.type === "schema") {
|
|
2087
|
+
const resolver = def.itemDef.resolver;
|
|
2088
|
+
if (resolver instanceof StaticValueResolver) {
|
|
2089
|
+
return resolver.staticValue !== void 0 && resolver.staticValue !== "";
|
|
2090
|
+
} else {
|
|
2091
|
+
return true;
|
|
2092
|
+
}
|
|
2253
2093
|
} else {
|
|
2254
|
-
|
|
2094
|
+
continue;
|
|
2255
2095
|
}
|
|
2256
2096
|
}
|
|
2097
|
+
return val;
|
|
2257
2098
|
}
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2099
|
+
}
|
|
2100
|
+
return true;
|
|
2101
|
+
}
|
|
2102
|
+
get isSensitive() {
|
|
2103
|
+
for (const def of this.defs) {
|
|
2104
|
+
const defDecorators = def.itemDef.decorators || {};
|
|
2105
|
+
if ("sensitive" in defDecorators) {
|
|
2106
|
+
return defDecorators.sensitive.simplifiedValue;
|
|
2107
|
+
} else if ("defaultSensitive" in def.source.decorators) {
|
|
2108
|
+
const dec = def.source.decorators.defaultSensitive;
|
|
2109
|
+
if (dec.value instanceof ParsedEnvSpecFunctionCall && dec.value.name === "inferFromPrefix") {
|
|
2110
|
+
const args = dec.value.simplifiedArgs;
|
|
2111
|
+
const prefix = Array.isArray(args) && args.length > 0 ? args[0] : void 0;
|
|
2112
|
+
if (typeof prefix === "string" && this.key.startsWith(prefix)) {
|
|
2113
|
+
return false;
|
|
2114
|
+
}
|
|
2115
|
+
return true;
|
|
2262
2116
|
}
|
|
2117
|
+
return dec.simplifiedValue;
|
|
2263
2118
|
}
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2119
|
+
}
|
|
2120
|
+
return true;
|
|
2121
|
+
}
|
|
2122
|
+
get errors() {
|
|
2123
|
+
return my_dash_default.compact([
|
|
2124
|
+
...this.schemaErrors || [],
|
|
2125
|
+
...this.resolverSchemaErrors || [],
|
|
2126
|
+
this.resolutionError,
|
|
2127
|
+
this.coercionError,
|
|
2128
|
+
...this.validationErrors || []
|
|
2129
|
+
]);
|
|
2130
|
+
}
|
|
2131
|
+
get validationState() {
|
|
2132
|
+
const errors = this.errors;
|
|
2133
|
+
if (!errors.length) return "valid";
|
|
2134
|
+
return my_dash_default.some(errors, (e) => !e.isWarning) ? "error" : "warn";
|
|
2135
|
+
}
|
|
2136
|
+
/** resolved value _before coercion_ */
|
|
2137
|
+
resolvedRawValue;
|
|
2138
|
+
isResolved = false;
|
|
2139
|
+
/** resolved value after coercion */
|
|
2140
|
+
resolvedValue;
|
|
2141
|
+
isValidated = false;
|
|
2142
|
+
resolutionError;
|
|
2143
|
+
coercionError;
|
|
2144
|
+
validationErrors;
|
|
2145
|
+
get isCoerced() {
|
|
2146
|
+
return this.resolvedRawValue !== this.resolvedValue;
|
|
2147
|
+
}
|
|
2148
|
+
async resolve() {
|
|
2149
|
+
if (this.schemaErrors.length) return;
|
|
2150
|
+
if (this.resolverSchemaErrors.length) return;
|
|
2151
|
+
if (!this.valueResolver) throw new Error("Expected a resolver to be set");
|
|
2152
|
+
if (this.isResolved) {
|
|
2153
|
+
return;
|
|
2154
|
+
}
|
|
2155
|
+
try {
|
|
2156
|
+
this.resolvedRawValue = await this.valueResolver.resolve();
|
|
2157
|
+
} catch (err) {
|
|
2158
|
+
this.resolutionError = new ResolutionError(`error resolving value: ${err}`);
|
|
2159
|
+
this.resolutionError.cause = err;
|
|
2160
|
+
}
|
|
2161
|
+
if (this.resolvedRawValue instanceof RegExp) {
|
|
2162
|
+
this.resolutionError = new ResolutionError("regex() is meant to be used within function args, not as a final resolved value");
|
|
2163
|
+
}
|
|
2164
|
+
if (this.resolutionError) return;
|
|
2165
|
+
this.isResolved = true;
|
|
2166
|
+
if (this.resolvedRawValue === void 0 || this.resolvedRawValue === "") {
|
|
2167
|
+
this.resolvedValue = this.resolvedRawValue;
|
|
2168
|
+
if (this.isRequired) {
|
|
2169
|
+
this.validationErrors = [new EmptyRequiredValueError(void 0)];
|
|
2267
2170
|
}
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2171
|
+
return;
|
|
2172
|
+
}
|
|
2173
|
+
if (!this.dataType) throw new Error("expected dataType to be set");
|
|
2174
|
+
try {
|
|
2175
|
+
const coerceResult = this.dataType.coerce(this.resolvedRawValue);
|
|
2176
|
+
if (coerceResult instanceof Error) throw coerceResult;
|
|
2177
|
+
this.resolvedValue = coerceResult;
|
|
2178
|
+
} catch (err) {
|
|
2179
|
+
if (err instanceof CoercionError) {
|
|
2180
|
+
this.coercionError = err;
|
|
2181
|
+
return;
|
|
2182
|
+
} else if (err instanceof Error) {
|
|
2183
|
+
this.coercionError = new CoercionError("Unexpected error coercing value");
|
|
2184
|
+
this.coercionError.cause = err;
|
|
2185
|
+
} else {
|
|
2186
|
+
this.coercionError = new CoercionError(`Unexpected non-error throw during coerce - ${err}`);
|
|
2273
2187
|
}
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2188
|
+
return;
|
|
2189
|
+
}
|
|
2190
|
+
try {
|
|
2191
|
+
const validateResult = this.dataType.validate(this.resolvedValue);
|
|
2192
|
+
if (validateResult instanceof Error || my_dash_default.isArray(validateResult) && validateResult[0] instanceof Error) throw validateResult;
|
|
2193
|
+
if (validateResult === false) {
|
|
2194
|
+
throw new ValidationError("validation failed with `false` return value");
|
|
2195
|
+
}
|
|
2196
|
+
this.isValidated = true;
|
|
2197
|
+
} catch (err) {
|
|
2198
|
+
if (my_dash_default.isArray(err)) {
|
|
2199
|
+
this.validationErrors = err;
|
|
2200
|
+
} else if (err instanceof ValidationError) {
|
|
2201
|
+
this.validationErrors = [err];
|
|
2202
|
+
} else if (err instanceof Error) {
|
|
2203
|
+
const validationError = new ValidationError("Unexpected error during validation");
|
|
2204
|
+
validationError.cause = err;
|
|
2205
|
+
console.log(err);
|
|
2206
|
+
this.validationErrors = [validationError];
|
|
2207
|
+
} else {
|
|
2208
|
+
const validationError = new ValidationError(`Unexpected non-error thrown during validation - ${err}`);
|
|
2209
|
+
validationError.cause = err;
|
|
2210
|
+
this.validationErrors = [validationError];
|
|
2211
|
+
}
|
|
2212
|
+
return;
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
get isValid() {
|
|
2216
|
+
return this.validationState === "valid";
|
|
2217
|
+
}
|
|
2218
|
+
};
|
|
2219
|
+
|
|
2220
|
+
// ../env-graph/src/lib/data-source.ts
|
|
2221
|
+
var DATA_SOURCE_TYPES = Object.freeze({
|
|
2222
|
+
schema: {
|
|
2223
|
+
fileSuffixes: ["schema"],
|
|
2224
|
+
precedence: 0
|
|
2225
|
+
},
|
|
2226
|
+
example: {
|
|
2227
|
+
fileSuffixes: ["sample", "example"],
|
|
2228
|
+
precedence: 1
|
|
2229
|
+
},
|
|
2230
|
+
defaults: {
|
|
2231
|
+
fileSuffixes: ["default", "defaults"],
|
|
2232
|
+
precedence: 2
|
|
2233
|
+
},
|
|
2234
|
+
values: {
|
|
2235
|
+
fileSuffixes: [],
|
|
2236
|
+
precedence: 3
|
|
2237
|
+
},
|
|
2238
|
+
overrides: {
|
|
2239
|
+
fileSuffixes: ["local", "override"],
|
|
2240
|
+
precedence: 4
|
|
2241
|
+
}
|
|
2242
|
+
});
|
|
2243
|
+
var EnvGraphDataSource = class {
|
|
2244
|
+
static {
|
|
2245
|
+
__name(this, "EnvGraphDataSource");
|
|
2246
|
+
}
|
|
2247
|
+
static DATA_SOURCE_TYPES = DATA_SOURCE_TYPES;
|
|
2248
|
+
// reference back to the graph
|
|
2249
|
+
graph;
|
|
2250
|
+
type = "values";
|
|
2251
|
+
applyForEnv;
|
|
2252
|
+
disabled = false;
|
|
2253
|
+
ignoreNewDefs = false;
|
|
2254
|
+
/** an error encountered while loading/parsing the data source */
|
|
2255
|
+
loadingError;
|
|
2256
|
+
get isValid() {
|
|
2257
|
+
return !this.loadingError;
|
|
2258
|
+
}
|
|
2259
|
+
configItemDefs = {};
|
|
2260
|
+
decorators = {};
|
|
2261
|
+
getStaticValues() {
|
|
2262
|
+
const obj = {};
|
|
2263
|
+
for (const [key, def] of Object.entries(this.configItemDefs)) {
|
|
2264
|
+
if (def.resolver instanceof StaticValueResolver) {
|
|
2265
|
+
obj[key] = String(def.resolver.staticValue ?? "");
|
|
2303
2266
|
}
|
|
2304
2267
|
}
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2268
|
+
return obj;
|
|
2269
|
+
}
|
|
2270
|
+
};
|
|
2271
|
+
var ProcessEnvDataSource2 = class _ProcessEnvDataSource extends EnvGraphDataSource {
|
|
2272
|
+
static {
|
|
2273
|
+
__name(this, "ProcessEnvDataSource");
|
|
2274
|
+
}
|
|
2275
|
+
type = "overrides";
|
|
2276
|
+
typeLabel = "process";
|
|
2277
|
+
label = "process.env";
|
|
2278
|
+
ignoreNewDefs = true;
|
|
2279
|
+
static processEnvValues;
|
|
2280
|
+
// ? do we want to set decorator values from env vars here? -- ex: _ENV_FLAG_KEY
|
|
2281
|
+
// depends if we want those to work only within process.env
|
|
2282
|
+
constructor() {
|
|
2283
|
+
super();
|
|
2284
|
+
if (!_ProcessEnvDataSource.processEnvValues) {
|
|
2285
|
+
_ProcessEnvDataSource.processEnvValues = {};
|
|
2286
|
+
for (const itemKey of Object.keys(process.env)) {
|
|
2287
|
+
_ProcessEnvDataSource.processEnvValues[itemKey] = process.env[itemKey];
|
|
2288
|
+
}
|
|
2308
2289
|
}
|
|
2309
|
-
const
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2290
|
+
for (const itemKey of Object.keys(_ProcessEnvDataSource.processEnvValues)) {
|
|
2291
|
+
this.configItemDefs[itemKey] = {
|
|
2292
|
+
resolver: new StaticValueResolver(_ProcessEnvDataSource.processEnvValues[itemKey])
|
|
2293
|
+
};
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
};
|
|
2297
|
+
var EnvSourceParseError = class extends Error {
|
|
2298
|
+
constructor(message, location) {
|
|
2299
|
+
super(message);
|
|
2300
|
+
this.location = location;
|
|
2301
|
+
}
|
|
2302
|
+
static {
|
|
2303
|
+
__name(this, "EnvSourceParseError");
|
|
2304
|
+
}
|
|
2305
|
+
};
|
|
2306
|
+
var FileBasedDataSource = class extends EnvGraphDataSource {
|
|
2307
|
+
static {
|
|
2308
|
+
__name(this, "FileBasedDataSource");
|
|
2309
|
+
}
|
|
2310
|
+
isGitIgnored;
|
|
2311
|
+
fullPath;
|
|
2312
|
+
fileName;
|
|
2313
|
+
rawContents;
|
|
2314
|
+
get typeLabel() {
|
|
2315
|
+
return this.constructor.format;
|
|
2316
|
+
}
|
|
2317
|
+
get label() {
|
|
2318
|
+
return this.fileName;
|
|
2319
|
+
}
|
|
2320
|
+
static format = "unknown";
|
|
2321
|
+
// no abstract static
|
|
2322
|
+
static validFileExtensions = [];
|
|
2323
|
+
get validFileExtensions() {
|
|
2324
|
+
return this.constructor.validFileExtensions;
|
|
2325
|
+
}
|
|
2326
|
+
constructor(fullPath, opts) {
|
|
2327
|
+
super();
|
|
2328
|
+
this.fullPath = fullPath;
|
|
2329
|
+
this.fileName = path.basename(fullPath);
|
|
2330
|
+
if (opts?.overrideContents) {
|
|
2331
|
+
this.rawContents = opts.overrideContents;
|
|
2332
|
+
this.isGitIgnored = opts.overrideGitIgnored;
|
|
2333
|
+
}
|
|
2334
|
+
if (!this.fileName.startsWith(".env")) {
|
|
2335
|
+
throw new Error('file name must start with ".env"');
|
|
2336
|
+
}
|
|
2337
|
+
const fileNameParts = this.fileName.substring(1).split(".");
|
|
2338
|
+
const maybeExtension = fileNameParts[fileNameParts.length - 1];
|
|
2339
|
+
if (this.validFileExtensions.includes(maybeExtension)) {
|
|
2340
|
+
fileNameParts.pop();
|
|
2341
|
+
}
|
|
2342
|
+
const maybeFileType = fileNameParts[fileNameParts.length - 1];
|
|
2343
|
+
for (const [possibleSourceType, possibleSourceSpec] of Object.entries(DATA_SOURCE_TYPES)) {
|
|
2344
|
+
if (possibleSourceSpec.fileSuffixes.includes(maybeFileType)) {
|
|
2345
|
+
this.type = possibleSourceType;
|
|
2346
|
+
break;
|
|
2318
2347
|
}
|
|
2319
2348
|
}
|
|
2349
|
+
if (this.type !== "values") fileNameParts.pop();
|
|
2350
|
+
if (fileNameParts.length > 2) {
|
|
2351
|
+
throw Error(`Unsure how to interpret filename - ${this.fileName}`);
|
|
2352
|
+
} else if (fileNameParts.length === 2) {
|
|
2353
|
+
this.applyForEnv = fileNameParts[1];
|
|
2354
|
+
if (this.applyForEnv === "dev") this.applyForEnv = "development";
|
|
2355
|
+
if (this.applyForEnv === "stage") this.applyForEnv = "staging";
|
|
2356
|
+
if (this.applyForEnv === "prod") this.applyForEnv = "production";
|
|
2357
|
+
}
|
|
2320
2358
|
}
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2359
|
+
// no async constructors... :(
|
|
2360
|
+
async finishInit() {
|
|
2361
|
+
if (!this.rawContents) {
|
|
2362
|
+
this.isGitIgnored = await checkIsFileGitIgnored(this.fullPath);
|
|
2363
|
+
this.rawContents = await fs2.readFile(this.fullPath, "utf8");
|
|
2326
2364
|
}
|
|
2327
|
-
|
|
2365
|
+
await this._parseContents();
|
|
2328
2366
|
}
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2367
|
+
};
|
|
2368
|
+
var DotEnvFileDataSource = class extends FileBasedDataSource {
|
|
2369
|
+
static {
|
|
2370
|
+
__name(this, "DotEnvFileDataSource");
|
|
2371
|
+
}
|
|
2372
|
+
static format = ".env";
|
|
2373
|
+
static validFileExtensions = [];
|
|
2374
|
+
// no extension for dotenv files!
|
|
2375
|
+
parsedFile;
|
|
2376
|
+
convertParserValueToResolvers(value) {
|
|
2377
|
+
if (!this.graph) throw new Error("expected graph to be set");
|
|
2378
|
+
if (value === void 0) {
|
|
2379
|
+
return new StaticValueResolver(void 0);
|
|
2380
|
+
} else if (value instanceof ParsedEnvSpecStaticValue) {
|
|
2381
|
+
return new StaticValueResolver(value.unescapedValue);
|
|
2382
|
+
} else if (value instanceof ParsedEnvSpecFunctionCall) {
|
|
2383
|
+
const ResolverFnClass = this.graph.registeredResolverFunctions[value.name];
|
|
2384
|
+
if (!ResolverFnClass) {
|
|
2385
|
+
return new ErrorResolver(new SchemaError(`Unknown resolver function: ${value.name}()`));
|
|
2337
2386
|
}
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
const
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
}
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
const resolveItem = /* @__PURE__ */ __name(async (itemKey) => {
|
|
2349
|
-
if (itemsToResolveStatus[itemKey] !== false) return;
|
|
2350
|
-
const item = this.configSchema[itemKey];
|
|
2351
|
-
if (item.errors.length) {
|
|
2352
|
-
markItemCompleted(itemKey);
|
|
2353
|
-
return;
|
|
2354
|
-
}
|
|
2355
|
-
for (const depKey of adjList[itemKey]) {
|
|
2356
|
-
const depItem = this.configSchema[depKey];
|
|
2357
|
-
if (depItem.validationState === "error") {
|
|
2358
|
-
item.resolutionError = new ResolutionError(`Dependency ${depKey} is invalid`);
|
|
2359
|
-
markItemCompleted(itemKey);
|
|
2360
|
-
return;
|
|
2361
|
-
} else if (depKey in itemsToResolveStatus) {
|
|
2362
|
-
return;
|
|
2387
|
+
const argsFromParser = value.data.args.values;
|
|
2388
|
+
let keyValueArgs;
|
|
2389
|
+
const argsAsResolversArray = [];
|
|
2390
|
+
for (const arg of argsFromParser) {
|
|
2391
|
+
if (arg instanceof ParsedEnvSpecKeyValuePair) {
|
|
2392
|
+
keyValueArgs ??= {};
|
|
2393
|
+
keyValueArgs[arg.key] = this.convertParserValueToResolvers(arg.value);
|
|
2394
|
+
} else {
|
|
2395
|
+
if (keyValueArgs) {
|
|
2396
|
+
return new ErrorResolver(new SchemaError("After switching to key-value function args, cannot switch back"));
|
|
2363
2397
|
}
|
|
2398
|
+
argsAsResolversArray.push(this.convertParserValueToResolvers(arg));
|
|
2364
2399
|
}
|
|
2365
|
-
itemsToResolveStatus[itemKey] = true;
|
|
2366
|
-
await item.resolve();
|
|
2367
|
-
markItemCompleted(itemKey);
|
|
2368
|
-
}, "resolveItem");
|
|
2369
|
-
for (const itemKey in this.configSchema) {
|
|
2370
|
-
resolveItem(itemKey);
|
|
2371
2400
|
}
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
const envObject = {};
|
|
2377
|
-
for (const itemKey in this.configSchema) {
|
|
2378
|
-
const item = this.configSchema[itemKey];
|
|
2379
|
-
envObject[itemKey] = item.resolvedValue;
|
|
2401
|
+
if (keyValueArgs) argsAsResolversArray.push(keyValueArgs);
|
|
2402
|
+
return new ResolverFnClass(argsAsResolversArray);
|
|
2403
|
+
} else {
|
|
2404
|
+
throw new Error("Unknown value type");
|
|
2380
2405
|
}
|
|
2381
|
-
return envObject;
|
|
2382
2406
|
}
|
|
2383
|
-
|
|
2384
|
-
const
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2407
|
+
async _parseContents() {
|
|
2408
|
+
const rawContents = this.rawContents;
|
|
2409
|
+
this.parsedFile = await tryCatch(
|
|
2410
|
+
() => parseEnvSpecDotEnvFile(rawContents),
|
|
2411
|
+
(error) => {
|
|
2412
|
+
this.loadingError = new EnvSourceParseError(error.message, {
|
|
2413
|
+
path: this.fullPath,
|
|
2414
|
+
lineNumber: error.location.start.line,
|
|
2415
|
+
colNumber: error.location.start.column,
|
|
2416
|
+
lineStr: rawContents.split("\n")[error.location.start.line - 1]
|
|
2417
|
+
});
|
|
2418
|
+
this.loadingError.cause = error;
|
|
2419
|
+
}
|
|
2420
|
+
);
|
|
2421
|
+
if (this.loadingError) return;
|
|
2422
|
+
if (!this.parsedFile) throw new Error("Failed to parse .env file");
|
|
2423
|
+
this.decorators = this.parsedFile.decoratorsObject;
|
|
2424
|
+
if (!this.graph) throw new Error("expected graph to be set");
|
|
2425
|
+
for (const item of this.parsedFile.configItems) {
|
|
2426
|
+
item.processExpansion();
|
|
2427
|
+
this.configItemDefs[item.key] = {
|
|
2428
|
+
resolver: this.convertParserValueToResolvers(item.expandedValue),
|
|
2429
|
+
description: item.description,
|
|
2430
|
+
decorators: item.decoratorsObject
|
|
2400
2431
|
};
|
|
2401
2432
|
}
|
|
2402
|
-
serializedGraph.settings.redactLogs = this.getRootDecoratorValue("redactLogs") ?? true;
|
|
2403
|
-
serializedGraph.settings.preventLeaks = this.getRootDecoratorValue("preventLeaks") ?? true;
|
|
2404
|
-
return serializedGraph;
|
|
2405
|
-
}
|
|
2406
|
-
get isInvalid() {
|
|
2407
|
-
return my_dash_default.some(my_dash_default.values(this.configSchema), (i) => !i.isValid);
|
|
2408
|
-
}
|
|
2409
|
-
async generateTypes(lang, outputPath) {
|
|
2410
|
-
await generateTypes(this, lang, outputPath);
|
|
2411
|
-
}
|
|
2412
|
-
getRootDecoratorValue(decoratorName) {
|
|
2413
|
-
const dec = this.schemaDataSource?.decorators?.[decoratorName];
|
|
2414
|
-
return dec?.simplifiedValue;
|
|
2415
2433
|
}
|
|
2416
2434
|
};
|
|
2417
|
-
var SKIP_FILE_TYPES = [".md", ".d.ts"];
|
|
2418
|
-
async function findEnvFiles(opts) {
|
|
2419
|
-
const cwd = opts?.cwd || process.cwd();
|
|
2420
|
-
const envFiles = [];
|
|
2421
|
-
const filesWithinDir = await fs.readdir(cwd);
|
|
2422
|
-
for (const fileName of filesWithinDir) {
|
|
2423
|
-
if (fileName.startsWith(".env")) {
|
|
2424
|
-
let skip = false;
|
|
2425
|
-
for (const fileType of SKIP_FILE_TYPES) {
|
|
2426
|
-
if (fileName.endsWith(fileType)) skip = true;
|
|
2427
|
-
}
|
|
2428
|
-
if (skip) continue;
|
|
2429
|
-
envFiles.push(path.join(cwd, fileName));
|
|
2430
|
-
}
|
|
2431
|
-
}
|
|
2432
|
-
return envFiles;
|
|
2433
|
-
}
|
|
2434
|
-
__name(findEnvFiles, "findEnvFiles");
|
|
2435
|
-
|
|
2436
|
-
// ../env-graph/src/lib/loader.ts
|
|
2437
|
-
function autoDetectContextPath() {
|
|
2438
|
-
const PWD = process.env.PWD;
|
|
2439
|
-
if (!PWD) {
|
|
2440
|
-
throw new Error("PWD is not set");
|
|
2441
|
-
}
|
|
2442
|
-
return PWD;
|
|
2443
|
-
}
|
|
2444
|
-
__name(autoDetectContextPath, "autoDetectContextPath");
|
|
2445
|
-
async function loadEnvGraph(opts) {
|
|
2446
|
-
const contextPath = opts?.contextPath ?? autoDetectContextPath();
|
|
2447
|
-
const graph = new EnvGraph();
|
|
2448
|
-
graph.basePath = contextPath;
|
|
2449
|
-
if (opts?.afterInit) {
|
|
2450
|
-
await opts.afterInit(graph);
|
|
2451
|
-
}
|
|
2452
|
-
if (opts?.currentEnvFallback) {
|
|
2453
|
-
graph.envFlagValue = opts.currentEnvFallback;
|
|
2454
|
-
}
|
|
2455
|
-
const envFilePaths = await findEnvFiles({
|
|
2456
|
-
cwd: contextPath
|
|
2457
|
-
});
|
|
2458
|
-
for (const envFilePath of envFilePaths) {
|
|
2459
|
-
const fileDataSource = new DotEnvFileDataSource(envFilePath);
|
|
2460
|
-
graph.addDataSource(fileDataSource);
|
|
2461
|
-
await fileDataSource.finishInit();
|
|
2462
|
-
}
|
|
2463
|
-
graph.finalOverridesDataSource = new ProcessEnvDataSource();
|
|
2464
|
-
await graph.finishLoad();
|
|
2465
|
-
return graph;
|
|
2466
|
-
}
|
|
2467
|
-
__name(loadEnvGraph, "loadEnvGraph");
|
|
2468
2435
|
|
|
2469
|
-
export { DotEnvFileDataSource, EnvSourceParseError, StaticValueResolver, checkIsFileGitIgnored,
|
|
2470
|
-
//# sourceMappingURL=chunk-
|
|
2471
|
-
//# sourceMappingURL=chunk-
|
|
2436
|
+
export { DotEnvFileDataSource, EnvGraph2 as EnvGraph, EnvSourceParseError, ProcessEnvDataSource2 as ProcessEnvDataSource, StaticValueResolver, checkIsFileGitIgnored, my_dash_default };
|
|
2437
|
+
//# sourceMappingURL=chunk-INMYFAWB.js.map
|
|
2438
|
+
//# sourceMappingURL=chunk-INMYFAWB.js.map
|