@enerlence/suntropy-cli 0.2.0 → 0.3.0

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.
@@ -2617,6 +2617,50 @@ var EXPAND_SECTIONS = {
2617
2617
  client: ["clientDetails", "clientsDetails"],
2618
2618
  location: ["location", "mapCenter", "geographicalZone", "atrTariff"]
2619
2619
  };
2620
+ var METADATA_ONLY_FIELDS = {
2621
+ peakPower: "metadata",
2622
+ sellingPrice: "metadata",
2623
+ totalCost: "metadata",
2624
+ anualProduction: "metadata",
2625
+ anualConsumption: "metadata",
2626
+ currentState: "metadata",
2627
+ clientName: "metadata",
2628
+ idSolarStudyMetadata: "metadata",
2629
+ solarStudyId: "metadata"
2630
+ };
2631
+ var COMPUTED_OR_UNKNOWN_FIELDS = {
2632
+ completionPercentage: "computed by `studies validate` / `studies save` from stepsProgress",
2633
+ isCompleted: "not a persisted field; derive from solarStudyProgress or completionPercentage",
2634
+ stepsProgress: "computed by `studies validate` / `studies save`"
2635
+ };
2636
+ function explainMissingStudyFields(missing, studyId) {
2637
+ const metadataFields = missing.filter((f) => f in METADATA_ONLY_FIELDS);
2638
+ const computedFields = missing.filter((f) => f in COMPUTED_OR_UNKNOWN_FIELDS);
2639
+ const unknownFields = missing.filter((f) => !(f in METADATA_ONLY_FIELDS) && !(f in COMPUTED_OR_UNKNOWN_FIELDS));
2640
+ const lines = [];
2641
+ lines.push(`warning: ${missing.length} requested field(s) are not present on the study document returned by findById.`);
2642
+ if (metadataFields.length > 0) {
2643
+ lines.push("");
2644
+ lines.push(` These fields live on the STUDY METADATA (MySQL), not on the study document:`);
2645
+ for (const f of metadataFields) lines.push(` - ${f}`);
2646
+ lines.push(` Use: suntropy studies metadata ${studyId} --by-study-id --fields ${metadataFields.join(",")}`);
2647
+ lines.push(` Or: suntropy studies list --client-name <name> (list already projects these fields)`);
2648
+ }
2649
+ if (computedFields.length > 0) {
2650
+ lines.push("");
2651
+ lines.push(` These fields are not persisted on the study:`);
2652
+ for (const f of computedFields) lines.push(` - ${f}: ${COMPUTED_OR_UNKNOWN_FIELDS[f]}`);
2653
+ lines.push(` Use: suntropy studies validate ${studyId} (returns stepsProgress + completionPercentage)`);
2654
+ }
2655
+ if (unknownFields.length > 0) {
2656
+ lines.push("");
2657
+ lines.push(` These fields were not found on the study document:`);
2658
+ for (const f of unknownFields) lines.push(` - ${f}`);
2659
+ lines.push(` If you expected them, try: suntropy studies get ${studyId} --expand all --format json`);
2660
+ lines.push(` and inspect the full payload to locate the correct field path.`);
2661
+ }
2662
+ process.stderr.write(lines.join("\n") + "\n");
2663
+ }
2620
2664
  var CORE_FIELDS = [
2621
2665
  "_id",
2622
2666
  "id",
@@ -2701,14 +2745,22 @@ function registerStudiesCommands(program2) {
2701
2745
  }
2702
2746
  });
2703
2747
  studies.command("get <studyId>").description(
2704
- "Get solar study by MongoDB ID. By default returns summary (no heavy curves).\nExpand sections: surfaces, results, economics, batteries, consumption, equipment, client, location\nExamples:\n suntropy studies get abc123\n suntropy studies get abc123 --expand surfaces,results\n suntropy studies get abc123 --expand all"
2748
+ "Get solar study by MongoDB ID. By default returns summary (no heavy curves).\nExpand sections: surfaces, results, economics, batteries, consumption, equipment, client, location\nExamples:\n suntropy studies get abc123\n suntropy studies get abc123 --expand surfaces,results\n suntropy studies get abc123 --expand all\n suntropy studies get abc123 --fields name,market (bypasses expand filter)"
2705
2749
  ).option("--expand <sections>", 'Comma-separated sections to expand (or "all")').action(async (studyId, opts) => {
2706
2750
  try {
2707
2751
  const global = getGlobalOpts7(studies);
2708
2752
  const client = createServiceClient("solar", global);
2709
2753
  const res = await client.get(`/solar-study/findById/${studyId}`);
2710
2754
  const study = res.data;
2711
- const filtered = filterStudy(study, opts.expand);
2755
+ const filtered = global.fields ? study : filterStudy(study, opts.expand);
2756
+ if (global.fields) {
2757
+ const requested = global.fields.split(",").map((f) => f.trim());
2758
+ const topLevel = requested.map((f) => f.split(".")[0]);
2759
+ const missing = topLevel.filter((f) => !(f in study));
2760
+ if (missing.length > 0) {
2761
+ explainMissingStudyFields(missing, studyId);
2762
+ }
2763
+ }
2712
2764
  output(filtered, global);
2713
2765
  } catch (err) {
2714
2766
  outputError(handleApiError(err));