varlock 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -25
  3. package/dist/auto-load.js +7 -8
  4. package/dist/auto-load.js.map +1 -1
  5. package/dist/{chunk-O2QPQ5MG.js → chunk-A4AHZSZB.js} +7 -6
  6. package/dist/chunk-A4AHZSZB.js.map +1 -0
  7. package/dist/{chunk-4WO4BGKU.js → chunk-C273RDM5.js} +15 -8
  8. package/dist/chunk-C273RDM5.js.map +1 -0
  9. package/dist/chunk-CLVBJA4G.js +107 -0
  10. package/dist/chunk-CLVBJA4G.js.map +1 -0
  11. package/dist/chunk-DHFEY3C4.js +141 -0
  12. package/dist/chunk-DHFEY3C4.js.map +1 -0
  13. package/dist/{chunk-Z55UMN2B.js → chunk-DOIKZ3NG.js} +4 -4
  14. package/dist/{chunk-Z55UMN2B.js.map → chunk-DOIKZ3NG.js.map} +1 -1
  15. package/dist/{chunk-G4BD2BPH.js → chunk-DROJWTCD.js} +237 -76
  16. package/dist/chunk-DROJWTCD.js.map +1 -0
  17. package/dist/chunk-FGMXIEFA.js +20 -0
  18. package/dist/chunk-FGMXIEFA.js.map +1 -0
  19. package/dist/{chunk-LQZ6ICSS.js → chunk-GSRDZVQI.js} +8 -3
  20. package/dist/chunk-GSRDZVQI.js.map +1 -0
  21. package/dist/{chunk-RY3YIJFG.js → chunk-H2TT4DP5.js} +16 -13
  22. package/dist/chunk-H2TT4DP5.js.map +1 -0
  23. package/dist/{chunk-XCFZJA7V.js → chunk-NN3XFBPE.js} +3 -3
  24. package/dist/{chunk-XCFZJA7V.js.map → chunk-NN3XFBPE.js.map} +1 -1
  25. package/dist/chunk-RUB5A7IC.js +14 -0
  26. package/dist/chunk-RUB5A7IC.js.map +1 -0
  27. package/dist/chunk-SVDXBE6D.js +93 -0
  28. package/dist/chunk-SVDXBE6D.js.map +1 -0
  29. package/dist/chunk-VN64D2EQ.js +39 -0
  30. package/dist/chunk-VN64D2EQ.js.map +1 -0
  31. package/dist/chunk-XHOJF7U7.js +12 -0
  32. package/dist/chunk-XHOJF7U7.js.map +1 -0
  33. package/dist/chunk-XPHGSDAF.js +45 -0
  34. package/dist/chunk-XPHGSDAF.js.map +1 -0
  35. package/dist/{chunk-CPA2D42B.js → chunk-ZIN4KXR6.js} +3 -3
  36. package/dist/{chunk-CPA2D42B.js.map → chunk-ZIN4KXR6.js.map} +1 -1
  37. package/dist/cli/cli-executable.js +71 -25
  38. package/dist/cli/cli-executable.js.map +1 -1
  39. package/dist/doctor.command-7BQSOQWW.js +6 -0
  40. package/dist/{doctor.command-SHZI7SR3.js.map → doctor.command-7BQSOQWW.js.map} +1 -1
  41. package/dist/dotenv-compat.js +7 -8
  42. package/dist/dotenv-compat.js.map +1 -1
  43. package/dist/index.d.ts +10 -34
  44. package/dist/index.js +36 -5
  45. package/dist/index.js.map +1 -1
  46. package/dist/init.command-CY3ZOIGP.js +11 -0
  47. package/dist/{init.command-ERPGU436.js.map → init.command-CY3ZOIGP.js.map} +1 -1
  48. package/dist/load.command-ZFNTAAJE.js +10 -0
  49. package/dist/{load.command-LQDSWJSK.js.map → load.command-ZFNTAAJE.js.map} +1 -1
  50. package/dist/login.command-KYZ4FXS5.js +7 -0
  51. package/dist/{login.command-22RUZJLR.js.map → login.command-KYZ4FXS5.js.map} +1 -1
  52. package/dist/run.command-VRKI6ZVN.js +10 -0
  53. package/dist/{run.command-OF3UV7AD.js.map → run.command-VRKI6ZVN.js.map} +1 -1
  54. package/dist/runtime/env.d.ts +27 -0
  55. package/dist/runtime/env.js +5 -0
  56. package/dist/runtime/env.js.map +1 -0
  57. package/dist/runtime/patch-console.d.ts +14 -0
  58. package/dist/runtime/patch-console.js +7 -0
  59. package/dist/runtime/patch-console.js.map +1 -0
  60. package/dist/runtime/patch-response.d.ts +3 -0
  61. package/dist/runtime/patch-response.js +7 -0
  62. package/dist/runtime/patch-response.js.map +1 -0
  63. package/dist/runtime/patch-server-response.d.ts +6 -0
  64. package/dist/runtime/patch-server-response.js +7 -0
  65. package/dist/runtime/patch-server-response.js.map +1 -0
  66. package/package.json +53 -8
  67. package/dist/chunk-332HXE6L.js +0 -53
  68. package/dist/chunk-332HXE6L.js.map +0 -1
  69. package/dist/chunk-4WO4BGKU.js.map +0 -1
  70. package/dist/chunk-6YLXKXKR.js +0 -225
  71. package/dist/chunk-6YLXKXKR.js.map +0 -1
  72. package/dist/chunk-G4BD2BPH.js.map +0 -1
  73. package/dist/chunk-LQZ6ICSS.js.map +0 -1
  74. package/dist/chunk-O2QPQ5MG.js.map +0 -1
  75. package/dist/chunk-RY3YIJFG.js.map +0 -1
  76. package/dist/doctor.command-SHZI7SR3.js +0 -6
  77. package/dist/init.command-ERPGU436.js +0 -10
  78. package/dist/load.command-LQDSWJSK.js +0 -9
  79. package/dist/login.command-22RUZJLR.js +0 -7
  80. 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 */
@@ -2125,6 +2237,10 @@ var EnvGraph = class {
2125
2237
  if (source.loadingError) {
2126
2238
  throw source.loadingError;
2127
2239
  }
2240
+ if (source.type === "example") {
2241
+ source.disabled = true;
2242
+ continue;
2243
+ }
2128
2244
  if (source.decorators?.envFlag) {
2129
2245
  if (source.applyForEnv) {
2130
2246
  throw new Error(`@envFlag cannot be set from within an env-specific data source - ${source.label}`);
@@ -2140,36 +2256,51 @@ var EnvGraph = class {
2140
2256
  }
2141
2257
  }
2142
2258
  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
2259
  if (source.applyForEnv && this.envFlagValue !== source.applyForEnv) {
2163
2260
  source.disabled = true;
2164
2261
  continue;
2165
2262
  }
2166
2263
  }
2264
+ if (source.decorators?.disable && source.decorators.disable.simplifiedValue) {
2265
+ source.disabled = true;
2266
+ continue;
2267
+ }
2167
2268
  for (const itemKey in source.configItemDefs) {
2168
2269
  if (source.ignoreNewDefs && !this.configSchema[itemKey]) continue;
2169
2270
  const itemDef = source.configItemDefs[itemKey];
2170
2271
  this.configSchema[itemKey] ??= new ConfigItem(this, itemKey);
2171
2272
  this.configSchema[itemKey].addDef(itemDef, source);
2172
2273
  }
2274
+ if (source.type === "schema" && this.envFlagKey) {
2275
+ if (!this.configSchema[this.envFlagKey]) {
2276
+ throw new Error(`@envFlag key ${this.envFlagKey} not found in schema`);
2277
+ }
2278
+ const envFlagItem = this.configSchema[this.envFlagKey];
2279
+ await envFlagItem.process();
2280
+ for (const depKey of envFlagItem.valueResolver?.deps || []) {
2281
+ const depItem = this.configSchema[depKey];
2282
+ if (!depItem) {
2283
+ throw new Error(`envFlag resolver is using non-existant dependency: ${depKey}`);
2284
+ }
2285
+ await depItem.process();
2286
+ if (depItem.valueResolver?.deps.length) {
2287
+ throw new Error("envFlag cannot follow a chain of dependencies");
2288
+ }
2289
+ await depItem.resolve();
2290
+ }
2291
+ await envFlagItem.resolve();
2292
+ if (!envFlagItem.isValid) {
2293
+ const err = new Error("resolved @envFlag value is not valid");
2294
+ err.cause = envFlagItem.errors[0];
2295
+ throw err;
2296
+ }
2297
+ if (envFlagItem.resolvedValue) {
2298
+ if (!my_dash_default.isString(envFlagItem.resolvedValue)) {
2299
+ throw new Error("expected resolved @envFlag value to be a string");
2300
+ }
2301
+ this.envFlagValue = envFlagItem.resolvedValue;
2302
+ }
2303
+ }
2173
2304
  }
2174
2305
  for (const itemKey in this.configSchema) {
2175
2306
  const item = this.configSchema[itemKey];
@@ -2249,12 +2380,39 @@ var EnvGraph = class {
2249
2380
  }
2250
2381
  return envObject;
2251
2382
  }
2383
+ getSerializedGraph() {
2384
+ const serializedGraph = {
2385
+ sources: [],
2386
+ config: {},
2387
+ settings: {}
2388
+ };
2389
+ for (const source of this.sortedDataSources) {
2390
+ serializedGraph.sources.push({
2391
+ label: source.label,
2392
+ enabled: !source.disabled
2393
+ });
2394
+ }
2395
+ for (const itemKey in this.configSchema) {
2396
+ const item = this.configSchema[itemKey];
2397
+ serializedGraph.config[itemKey] = {
2398
+ value: item.resolvedValue,
2399
+ isSensitive: item.isSensitive
2400
+ };
2401
+ }
2402
+ serializedGraph.settings.redactLogs = this.getRootDecoratorValue("redactLogs") ?? true;
2403
+ serializedGraph.settings.preventLeaks = this.getRootDecoratorValue("preventLeaks") ?? true;
2404
+ return serializedGraph;
2405
+ }
2252
2406
  get isInvalid() {
2253
2407
  return my_dash_default.some(my_dash_default.values(this.configSchema), (i) => !i.isValid);
2254
2408
  }
2255
2409
  async generateTypes(lang, outputPath) {
2256
2410
  await generateTypes(this, lang, outputPath);
2257
2411
  }
2412
+ getRootDecoratorValue(decoratorName) {
2413
+ const dec = this.schemaDataSource?.decorators?.[decoratorName];
2414
+ return dec?.simplifiedValue;
2415
+ }
2258
2416
  };
2259
2417
  var SKIP_FILE_TYPES = [".md", ".d.ts"];
2260
2418
  async function findEnvFiles(opts) {
@@ -2291,6 +2449,9 @@ async function loadEnvGraph(opts) {
2291
2449
  if (opts?.afterInit) {
2292
2450
  await opts.afterInit(graph);
2293
2451
  }
2452
+ if (opts?.currentEnvFallback) {
2453
+ graph.envFlagValue = opts.currentEnvFallback;
2454
+ }
2294
2455
  const envFilePaths = await findEnvFiles({
2295
2456
  cwd: contextPath
2296
2457
  });
@@ -2299,12 +2460,12 @@ async function loadEnvGraph(opts) {
2299
2460
  graph.addDataSource(fileDataSource);
2300
2461
  await fileDataSource.finishInit();
2301
2462
  }
2302
- graph.addDataSource(new ProcessEnvDataSource());
2463
+ graph.finalOverridesDataSource = new ProcessEnvDataSource();
2303
2464
  await graph.finishLoad();
2304
2465
  return graph;
2305
2466
  }
2306
2467
  __name(loadEnvGraph, "loadEnvGraph");
2307
2468
 
2308
2469
  export { DotEnvFileDataSource, EnvSourceParseError, StaticValueResolver, checkIsFileGitIgnored, loadEnvGraph, my_dash_default };
2309
- //# sourceMappingURL=chunk-G4BD2BPH.js.map
2310
- //# sourceMappingURL=chunk-G4BD2BPH.js.map
2470
+ //# sourceMappingURL=chunk-DROJWTCD.js.map
2471
+ //# sourceMappingURL=chunk-DROJWTCD.js.map