varlock 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/dist/auto-load.js +7 -8
  3. package/dist/auto-load.js.map +1 -1
  4. package/dist/{chunk-O2QPQ5MG.js → chunk-2CM6PMED.js} +7 -6
  5. package/dist/chunk-2CM6PMED.js.map +1 -0
  6. package/dist/chunk-3EBGAOLH.js +14 -0
  7. package/dist/chunk-3EBGAOLH.js.map +1 -0
  8. package/dist/chunk-3KZR56NU.js +45 -0
  9. package/dist/chunk-3KZR56NU.js.map +1 -0
  10. package/dist/{chunk-RY3YIJFG.js → chunk-5HDQH7UC.js} +5 -5
  11. package/dist/{chunk-RY3YIJFG.js.map → chunk-5HDQH7UC.js.map} +1 -1
  12. package/dist/chunk-7QXRUUDC.js +137 -0
  13. package/dist/chunk-7QXRUUDC.js.map +1 -0
  14. package/dist/chunk-FGMXIEFA.js +20 -0
  15. package/dist/chunk-FGMXIEFA.js.map +1 -0
  16. package/dist/{chunk-4WO4BGKU.js → chunk-NAZPFZOO.js} +15 -8
  17. package/dist/chunk-NAZPFZOO.js.map +1 -0
  18. package/dist/{chunk-Z55UMN2B.js → chunk-OSSLRXKM.js} +4 -4
  19. package/dist/{chunk-Z55UMN2B.js.map → chunk-OSSLRXKM.js.map} +1 -1
  20. package/dist/chunk-OXV76U3Y.js +39 -0
  21. package/dist/chunk-OXV76U3Y.js.map +1 -0
  22. package/dist/chunk-Q5P7F3WA.js +107 -0
  23. package/dist/chunk-Q5P7F3WA.js.map +1 -0
  24. package/dist/chunk-RF3YMFUX.js +93 -0
  25. package/dist/chunk-RF3YMFUX.js.map +1 -0
  26. package/dist/{chunk-XCFZJA7V.js → chunk-RPLDMNWT.js} +3 -3
  27. package/dist/{chunk-XCFZJA7V.js.map → chunk-RPLDMNWT.js.map} +1 -1
  28. package/dist/{chunk-G4BD2BPH.js → chunk-TYL3Q4QG.js} +233 -76
  29. package/dist/chunk-TYL3Q4QG.js.map +1 -0
  30. package/dist/chunk-XHOJF7U7.js +12 -0
  31. package/dist/chunk-XHOJF7U7.js.map +1 -0
  32. package/dist/cli/cli-executable.js +68 -22
  33. package/dist/cli/cli-executable.js.map +1 -1
  34. package/dist/doctor.command-L3P5LBOW.js +6 -0
  35. package/dist/{doctor.command-SHZI7SR3.js.map → doctor.command-L3P5LBOW.js.map} +1 -1
  36. package/dist/dotenv-compat.js +7 -8
  37. package/dist/dotenv-compat.js.map +1 -1
  38. package/dist/index.d.ts +10 -34
  39. package/dist/index.js +36 -5
  40. package/dist/index.js.map +1 -1
  41. package/dist/init.command-Q4YBHAEG.js +11 -0
  42. package/dist/{init.command-ERPGU436.js.map → init.command-Q4YBHAEG.js.map} +1 -1
  43. package/dist/load.command-K22PEH3D.js +10 -0
  44. package/dist/{load.command-LQDSWJSK.js.map → load.command-K22PEH3D.js.map} +1 -1
  45. package/dist/run.command-DUAYGL6F.js +10 -0
  46. package/dist/{run.command-OF3UV7AD.js.map → run.command-DUAYGL6F.js.map} +1 -1
  47. package/dist/runtime/env.d.ts +27 -0
  48. package/dist/runtime/env.js +5 -0
  49. package/dist/runtime/env.js.map +1 -0
  50. package/dist/runtime/patch-console.d.ts +14 -0
  51. package/dist/runtime/patch-console.js +7 -0
  52. package/dist/runtime/patch-console.js.map +1 -0
  53. package/dist/runtime/patch-response.d.ts +3 -0
  54. package/dist/runtime/patch-response.js +7 -0
  55. package/dist/runtime/patch-response.js.map +1 -0
  56. package/dist/runtime/patch-server-response.d.ts +6 -0
  57. package/dist/runtime/patch-server-response.js +7 -0
  58. package/dist/runtime/patch-server-response.js.map +1 -0
  59. package/package.json +55 -10
  60. package/dist/chunk-332HXE6L.js +0 -53
  61. package/dist/chunk-332HXE6L.js.map +0 -1
  62. package/dist/chunk-4WO4BGKU.js.map +0 -1
  63. package/dist/chunk-6YLXKXKR.js +0 -225
  64. package/dist/chunk-6YLXKXKR.js.map +0 -1
  65. package/dist/chunk-G4BD2BPH.js.map +0 -1
  66. package/dist/chunk-O2QPQ5MG.js.map +0 -1
  67. package/dist/doctor.command-SHZI7SR3.js +0 -6
  68. package/dist/init.command-ERPGU436.js +0 -10
  69. package/dist/load.command-LQDSWJSK.js +0 -9
  70. package/dist/run.command-OF3UV7AD.js +0 -9
@@ -779,17 +779,12 @@ __name(tryCatch, "tryCatch");
779
779
  // ../env-graph/src/lib/errors.ts
780
780
  var VarlockError = class extends Error {
781
781
  constructor(errOrMessage, more) {
782
- var __super = (...args) => {
783
- super(...args);
784
- this.more = more;
785
- return this;
786
- };
782
+ super(my_dash_default.isError(errOrMessage) ? errOrMessage.message : errOrMessage);
783
+ this.more = more;
787
784
  if (my_dash_default.isError(errOrMessage)) {
788
- __super(errOrMessage.message);
789
785
  this.originalError = errOrMessage;
790
786
  this.icon = "\u{1F4A5}";
791
787
  } else {
792
- __super(errOrMessage);
793
788
  this.originalError = more?.err;
794
789
  }
795
790
  if (my_dash_default.isArray(more?.tip)) more.tip = more.tip.join("\n");
@@ -937,7 +932,7 @@ var Resolver = class {
937
932
  _schemaErrors = [];
938
933
  _depsObj = {};
939
934
  get childResolvers() {
940
- return my_dash_default.isArray(this.fnArgs) ? this.fnArgs : my_dash_default.values(this.fnArgs);
935
+ return this.fnArgs.flatMap((r) => my_dash_default.isPlainObject(r) ? my_dash_default.values(r) : r);
941
936
  }
942
937
  get schemaErrors() {
943
938
  return [
@@ -1032,19 +1027,19 @@ var ConcatResolver = class extends Resolver {
1032
1027
  icon = "material-symbols:join";
1033
1028
  inferredType = "string";
1034
1029
  async _process() {
1035
- if (!Array.isArray(this.fnArgs)) {
1036
- throw new SchemaError("concat() expects an array of arguments, not a key-value object");
1030
+ if (this.fnArgs.some((arg) => my_dash_default.isPlainObject(arg))) {
1031
+ throw new SchemaError("concat() does not support key-value arguments");
1037
1032
  }
1038
1033
  if (this.fnArgs.length < 2) {
1039
1034
  throw new SchemaError("concat() expects at least two arguments");
1040
1035
  }
1041
1036
  }
1042
1037
  async _resolve() {
1043
- if (!Array.isArray(this.fnArgs)) {
1044
- throw new Error("concat() expects an array of arguments, not a key-value object");
1045
- }
1046
1038
  const resolvedValues = [];
1047
1039
  for (const arg of this.fnArgs) {
1040
+ if (my_dash_default.isPlainObject(arg)) {
1041
+ throw new Error("concat() does not support key-value arguments");
1042
+ }
1048
1043
  const resolvedChildValue = await arg.resolve();
1049
1044
  resolvedValues.push(String(resolvedChildValue ?? ""));
1050
1045
  }
@@ -1059,18 +1054,16 @@ var FallbackResolver = class extends Resolver {
1059
1054
  label = "fallback";
1060
1055
  icon = "memory:table-top-stairs-up";
1061
1056
  async _process() {
1062
- if (!Array.isArray(this.fnArgs)) {
1063
- throw new SchemaError("fallback() expects an array of arguments, not a key-value object");
1057
+ if (this.fnArgs.some((arg) => my_dash_default.isPlainObject(arg))) {
1058
+ throw new SchemaError("fallback() does not support key-value arguments");
1064
1059
  }
1065
1060
  if (this.fnArgs.length < 2) {
1066
1061
  throw new SchemaError("fallback() expects at least two arguments");
1067
1062
  }
1068
1063
  }
1069
1064
  async _resolve() {
1070
- if (!Array.isArray(this.fnArgs)) {
1071
- throw new Error("concat() expects an array of arguments, not a key-value object");
1072
- }
1073
1065
  for (const arg of this.fnArgs) {
1066
+ if (my_dash_default.isPlainObject(arg)) throw new Error("fallback() does not support key-value arguments");
1074
1067
  const resolvedChildValue = await arg.resolve();
1075
1068
  if (resolvedChildValue !== void 0 && resolvedChildValue !== "") {
1076
1069
  return resolvedChildValue;
@@ -1086,18 +1079,16 @@ var ExecResolver = class _ExecResolver extends Resolver {
1086
1079
  label = "exec";
1087
1080
  icon = "iconoir:terminal";
1088
1081
  async _process() {
1089
- if (!Array.isArray(this.fnArgs)) {
1090
- throw new SchemaError("exec() expects a single child arg, not a key-value object");
1091
- }
1092
1082
  if (this.fnArgs.length !== 1) {
1093
1083
  throw new SchemaError("exec() expects a single child arg");
1094
1084
  }
1085
+ if (this.fnArgs.some((arg) => my_dash_default.isPlainObject(arg))) {
1086
+ throw new SchemaError("exec() does not support key-value arguments");
1087
+ }
1095
1088
  }
1096
1089
  static execQueue = new SimpleQueue();
1097
1090
  async _resolve() {
1098
- if (!Array.isArray(this.fnArgs) || this.fnArgs.length !== 1) {
1099
- throw new Error("exec() expects a single child arg");
1100
- }
1091
+ if (my_dash_default.isPlainObject(this.fnArgs[0])) throw new Error("exec() does not support key-value arguments");
1101
1092
  const commandStr = await this.fnArgs[0].resolve();
1102
1093
  if (typeof commandStr !== "string") {
1103
1094
  throw new ResolutionError("exec() expects a string child arg");
@@ -1120,9 +1111,6 @@ var RefResolver = class extends Resolver {
1120
1111
  icon = "mdi-light:content-duplicate";
1121
1112
  refKey;
1122
1113
  async _process() {
1123
- if (!Array.isArray(this.fnArgs)) {
1124
- throw new SchemaError("ref() expects a single child arg, not a key-value object");
1125
- }
1126
1114
  if (this.fnArgs.length !== 1) {
1127
1115
  throw new SchemaError("ref() expects a single child arg");
1128
1116
  }
@@ -1141,11 +1129,79 @@ var RefResolver = class extends Resolver {
1141
1129
  return this.getDepValue(this.refKey);
1142
1130
  }
1143
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");
1175
+ }
1176
+ this.remappings = this.fnArgs[1];
1177
+ }
1178
+ async _resolve() {
1179
+ if (my_dash_default.isPlainObject(this.fnArgs[0])) {
1180
+ throw new SchemaError("remap() expects the first arg to be the value to remap");
1181
+ }
1182
+ if (!my_dash_default.isPlainObject(this.fnArgs[1])) {
1183
+ throw new SchemaError("remap() expects the all args after the first to be key-value pairs of remappings");
1184
+ }
1185
+ const originalValue = await this.fnArgs[0].resolve();
1186
+ if (!this.remappings) throw new Error("expected remappings to be set");
1187
+ for (const [remappedVal, matchValResolver] of Object.entries(this.remappings)) {
1188
+ const matchVal = await matchValResolver.resolve();
1189
+ if (matchVal instanceof RegExp && originalValue !== void 0) {
1190
+ if (matchVal.test(String(originalValue))) return remappedVal;
1191
+ } else {
1192
+ if (matchVal === originalValue) return remappedVal;
1193
+ }
1194
+ }
1195
+ return originalValue;
1196
+ }
1197
+ };
1144
1198
  var BaseResolvers = [
1145
1199
  ConcatResolver,
1146
1200
  FallbackResolver,
1147
1201
  RefResolver,
1148
- ExecResolver
1202
+ ExecResolver,
1203
+ RemapResolver,
1204
+ RegexResolver
1149
1205
  ];
1150
1206
 
1151
1207
  // ../env-graph/src/lib/data-source.ts
@@ -1204,7 +1260,8 @@ var ProcessEnvDataSource = class _ProcessEnvDataSource extends EnvGraphDataSourc
1204
1260
  __name(this, "ProcessEnvDataSource");
1205
1261
  }
1206
1262
  type = "overrides";
1207
- label = "Process Environment Variables";
1263
+ typeLabel = "process";
1264
+ label = "process.env";
1208
1265
  ignoreNewDefs = true;
1209
1266
  static processEnvValues;
1210
1267
  // ? do we want to set decorator values from env vars here? -- ex: _ENV_FLAG_KEY
@@ -1241,10 +1298,14 @@ var FileBasedDataSource = class extends EnvGraphDataSource {
1241
1298
  fullPath;
1242
1299
  fileName;
1243
1300
  rawContents;
1244
- format;
1301
+ get typeLabel() {
1302
+ return this.constructor.format;
1303
+ }
1245
1304
  get label() {
1246
- return `File: ${this.fullPath}`;
1305
+ return this.fileName;
1247
1306
  }
1307
+ static format = "unknown";
1308
+ // no abstract static
1248
1309
  static validFileExtensions = [];
1249
1310
  get validFileExtensions() {
1250
1311
  return this.constructor.validFileExtensions;
@@ -1295,7 +1356,7 @@ var DotEnvFileDataSource = class extends FileBasedDataSource {
1295
1356
  static {
1296
1357
  __name(this, "DotEnvFileDataSource");
1297
1358
  }
1298
- static format = "dotenv";
1359
+ static format = ".env";
1299
1360
  static validFileExtensions = [];
1300
1361
  // no extension for dotenv files!
1301
1362
  parsedFile;
@@ -1311,19 +1372,21 @@ var DotEnvFileDataSource = class extends FileBasedDataSource {
1311
1372
  return new ErrorResolver(new SchemaError(`Unknown resolver function: ${value.name}()`));
1312
1373
  }
1313
1374
  const argsFromParser = value.data.args.values;
1314
- if (argsFromParser.length && argsFromParser.every((arg) => arg instanceof ParsedEnvSpecKeyValuePair)) {
1315
- const argsAsResolversObj = {};
1316
- for (const arg of argsFromParser) {
1317
- argsAsResolversObj[arg.key] = this.convertParserValueToResolvers(arg.value);
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));
1318
1386
  }
1319
- return new ResolverFnClass(argsAsResolversObj);
1320
- } else {
1321
- const argsAsResolversArray = argsFromParser.map((arg) => {
1322
- if (arg instanceof ParsedEnvSpecKeyValuePair) throw new Error("KeyValuePair not supported as a function argument");
1323
- return this.convertParserValueToResolvers(arg);
1324
- });
1325
- return new ResolverFnClass(argsAsResolversArray);
1326
1387
  }
1388
+ if (keyValueArgs) argsAsResolversArray.push(keyValueArgs);
1389
+ return new ResolverFnClass(argsAsResolversArray);
1327
1390
  } else {
1328
1391
  throw new Error("Unknown value type");
1329
1392
  }
@@ -1415,6 +1478,10 @@ var ConfigItem = class {
1415
1478
  return this.valueResolver?.schemaErrors || [];
1416
1479
  }
1417
1480
  async process() {
1481
+ const finalOverrideDef = this.envGraph.finalOverridesDataSource?.configItemDefs[this.key];
1482
+ if (finalOverrideDef) {
1483
+ this.defs.unshift({ itemDef: finalOverrideDef, source: this.envGraph.finalOverridesDataSource });
1484
+ }
1418
1485
  for (const def of this.defs) {
1419
1486
  await def.itemDef.resolver?.process(this);
1420
1487
  }
@@ -1445,11 +1512,32 @@ var ConfigItem = class {
1445
1512
  for (const def of this.defs) {
1446
1513
  const defDecorators = def.itemDef.decorators || {};
1447
1514
  if ("required" in defDecorators) {
1448
- return defDecorators.required.simplifiedValue;
1449
- } else if ("optional" in defDecorators) {
1450
- return !defDecorators.optional.simplifiedValue;
1451
- } else if ("defaultRequired" in def.source.decorators) {
1452
- return def.source.decorators.defaultRequired.simplifiedValue;
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;
1453
1541
  }
1454
1542
  }
1455
1543
  return true;
@@ -1460,7 +1548,16 @@ var ConfigItem = class {
1460
1548
  if ("sensitive" in defDecorators) {
1461
1549
  return defDecorators.sensitive.simplifiedValue;
1462
1550
  } else if ("defaultSensitive" in def.source.decorators) {
1463
- return def.source.decorators.defaultSensitive.simplifiedValue;
1551
+ const dec = def.source.decorators.defaultSensitive;
1552
+ if (dec.value instanceof ParsedEnvSpecFunctionCall && dec.value.name === "inferFromPrefix") {
1553
+ const args = dec.value.simplifiedArgs;
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;
1464
1561
  }
1465
1562
  }
1466
1563
  return true;
@@ -1494,17 +1591,19 @@ var ConfigItem = class {
1494
1591
  async resolve() {
1495
1592
  if (this.schemaErrors.length) return;
1496
1593
  if (this.resolverSchemaErrors.length) return;
1497
- if (!this.valueResolver) {
1498
- this.resolvedRawValue = void 0;
1594
+ if (!this.valueResolver) throw new Error("Expected a resolver to be set");
1595
+ if (this.isResolved) {
1499
1596
  return;
1500
1597
  }
1501
- if (this.isResolved) throw new Error("item already resolved");
1502
1598
  try {
1503
1599
  this.resolvedRawValue = await this.valueResolver.resolve();
1504
1600
  } catch (err) {
1505
1601
  this.resolutionError = new ResolutionError(`error resolving value: ${err}`);
1506
1602
  this.resolutionError.cause = err;
1507
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");
1606
+ }
1508
1607
  if (this.resolutionError) return;
1509
1608
  this.isResolved = true;
1510
1609
  if (this.resolvedRawValue === void 0 || this.resolvedRawValue === "") {
@@ -2052,12 +2151,24 @@ async function generateTsTypesSrc(graph) {
2052
2151
  }
2053
2152
  tsSrc.push("};\n");
2054
2153
  tsSrc.push(`
2055
- declare module 'varlock' {
2154
+ declare module 'varlock/env' {
2056
2155
  export interface TypedEnvSchema extends CoercedEnvSchema {}
2057
-
2058
2156
  export interface PublicTypedEnvSchema extends Pick<CoercedEnvSchema, '${exposedNonSensitiveKeys.join("' | '")}'> {}
2059
2157
  }
2060
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
+ };
2165
+ `);
2166
+ tsSrc.push(`
2167
+ declare global {
2168
+ namespace NodeJS {
2169
+ interface ProcessEnv extends EnvSchemaAsStrings {}
2170
+ }
2171
+ }`);
2061
2172
  return tsSrc.join("\n");
2062
2173
  }
2063
2174
  __name(generateTsTypesSrc, "generateTsTypesSrc");
@@ -2081,6 +2192,7 @@ var EnvGraph = class {
2081
2192
  basePath;
2082
2193
  /** array of data sources */
2083
2194
  dataSources = [];
2195
+ finalOverridesDataSource;
2084
2196
  /** config item key of env flag (toggles env-specific data sources enabled) */
2085
2197
  envFlagKey;
2086
2198
  /** current value of the environment flag */
@@ -2140,36 +2252,51 @@ var EnvGraph = class {
2140
2252
  }
2141
2253
  }
2142
2254
  if (source.applyForEnv) {
2143
- if (!this.envFlagValue) {
2144
- if (!this.envFlagKey) {
2145
- throw new Error("You must specify the @envFlag in your schema to load any env-specific files");
2146
- }
2147
- if (!this.configSchema[this.envFlagKey]) {
2148
- throw new Error(`@envFlag key ${this.envFlagKey} not found in schema`);
2149
- }
2150
- if (process.env[this.envFlagKey]) {
2151
- this.envFlagValue = process.env[this.envFlagKey];
2152
- } else {
2153
- const envFlagResolver = this.configSchema[this.envFlagKey].valueResolver;
2154
- if (envFlagResolver instanceof StaticValueResolver) {
2155
- if (!my_dash_default.isString(envFlagResolver.staticValue)) throw new Error("expected a static string value for envFlag");
2156
- this.envFlagValue = envFlagResolver.staticValue;
2157
- } else {
2158
- throw new Error("envFlag value must be a static string");
2159
- }
2160
- }
2161
- }
2162
2255
  if (source.applyForEnv && this.envFlagValue !== source.applyForEnv) {
2163
2256
  source.disabled = true;
2164
2257
  continue;
2165
2258
  }
2166
2259
  }
2260
+ if (source.decorators?.disable && source.decorators.disable.simplifiedValue) {
2261
+ source.disabled = true;
2262
+ continue;
2263
+ }
2167
2264
  for (const itemKey in source.configItemDefs) {
2168
2265
  if (source.ignoreNewDefs && !this.configSchema[itemKey]) continue;
2169
2266
  const itemDef = source.configItemDefs[itemKey];
2170
2267
  this.configSchema[itemKey] ??= new ConfigItem(this, itemKey);
2171
2268
  this.configSchema[itemKey].addDef(itemDef, source);
2172
2269
  }
2270
+ if (source.type === "schema" && this.envFlagKey) {
2271
+ if (!this.configSchema[this.envFlagKey]) {
2272
+ throw new Error(`@envFlag key ${this.envFlagKey} not found in schema`);
2273
+ }
2274
+ const envFlagItem = this.configSchema[this.envFlagKey];
2275
+ await envFlagItem.process();
2276
+ for (const depKey of envFlagItem.valueResolver?.deps || []) {
2277
+ const depItem = this.configSchema[depKey];
2278
+ if (!depItem) {
2279
+ throw new Error(`envFlag resolver is using non-existant dependency: ${depKey}`);
2280
+ }
2281
+ await depItem.process();
2282
+ if (depItem.valueResolver?.deps.length) {
2283
+ throw new Error("envFlag cannot follow a chain of dependencies");
2284
+ }
2285
+ await depItem.resolve();
2286
+ }
2287
+ await envFlagItem.resolve();
2288
+ if (!envFlagItem.isValid) {
2289
+ const err = new Error("resolved @envFlag value is not valid");
2290
+ err.cause = envFlagItem.errors[0];
2291
+ throw err;
2292
+ }
2293
+ if (envFlagItem.resolvedValue) {
2294
+ if (!my_dash_default.isString(envFlagItem.resolvedValue)) {
2295
+ throw new Error("expected resolved @envFlag value to be a string");
2296
+ }
2297
+ this.envFlagValue = envFlagItem.resolvedValue;
2298
+ }
2299
+ }
2173
2300
  }
2174
2301
  for (const itemKey in this.configSchema) {
2175
2302
  const item = this.configSchema[itemKey];
@@ -2249,12 +2376,39 @@ var EnvGraph = class {
2249
2376
  }
2250
2377
  return envObject;
2251
2378
  }
2379
+ getSerializedGraph() {
2380
+ const serializedGraph = {
2381
+ sources: [],
2382
+ config: {},
2383
+ settings: {}
2384
+ };
2385
+ for (const source of this.sortedDataSources) {
2386
+ serializedGraph.sources.push({
2387
+ label: source.label,
2388
+ enabled: !source.disabled
2389
+ });
2390
+ }
2391
+ for (const itemKey in this.configSchema) {
2392
+ const item = this.configSchema[itemKey];
2393
+ serializedGraph.config[itemKey] = {
2394
+ value: item.resolvedValue,
2395
+ isSensitive: item.isSensitive
2396
+ };
2397
+ }
2398
+ serializedGraph.settings.redactLogs = this.getRootDecoratorValue("redactLogs") ?? true;
2399
+ serializedGraph.settings.preventLeaks = this.getRootDecoratorValue("preventLeaks") ?? true;
2400
+ return serializedGraph;
2401
+ }
2252
2402
  get isInvalid() {
2253
2403
  return my_dash_default.some(my_dash_default.values(this.configSchema), (i) => !i.isValid);
2254
2404
  }
2255
2405
  async generateTypes(lang, outputPath) {
2256
2406
  await generateTypes(this, lang, outputPath);
2257
2407
  }
2408
+ getRootDecoratorValue(decoratorName) {
2409
+ const dec = this.schemaDataSource?.decorators?.[decoratorName];
2410
+ return dec?.simplifiedValue;
2411
+ }
2258
2412
  };
2259
2413
  var SKIP_FILE_TYPES = [".md", ".d.ts"];
2260
2414
  async function findEnvFiles(opts) {
@@ -2291,6 +2445,9 @@ async function loadEnvGraph(opts) {
2291
2445
  if (opts?.afterInit) {
2292
2446
  await opts.afterInit(graph);
2293
2447
  }
2448
+ if (opts?.currentEnvFallback) {
2449
+ graph.envFlagValue = opts.currentEnvFallback;
2450
+ }
2294
2451
  const envFilePaths = await findEnvFiles({
2295
2452
  cwd: contextPath
2296
2453
  });
@@ -2299,12 +2456,12 @@ async function loadEnvGraph(opts) {
2299
2456
  graph.addDataSource(fileDataSource);
2300
2457
  await fileDataSource.finishInit();
2301
2458
  }
2302
- graph.addDataSource(new ProcessEnvDataSource());
2459
+ graph.finalOverridesDataSource = new ProcessEnvDataSource();
2303
2460
  await graph.finishLoad();
2304
2461
  return graph;
2305
2462
  }
2306
2463
  __name(loadEnvGraph, "loadEnvGraph");
2307
2464
 
2308
2465
  export { DotEnvFileDataSource, EnvSourceParseError, StaticValueResolver, checkIsFileGitIgnored, loadEnvGraph, my_dash_default };
2309
- //# sourceMappingURL=chunk-G4BD2BPH.js.map
2310
- //# sourceMappingURL=chunk-G4BD2BPH.js.map
2466
+ //# sourceMappingURL=chunk-TYL3Q4QG.js.map
2467
+ //# sourceMappingURL=chunk-TYL3Q4QG.js.map