« get me outta code hell

yaml: track filenames, document placements & documents - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/yaml.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-02-22 12:07:04 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-02-22 13:16:46 -0400
commite9bfe465e9e5db2f0dd10502a4485768277677dc (patch)
treed62a9c03d75ea14337b3792258b3d72cc3a4194c /src/data/yaml.js
parent929e8500667012b2b2f5506efbfd10a39134a9cd (diff)
yaml: track filenames, document placements & documents
Diffstat (limited to 'src/data/yaml.js')
-rw-r--r--src/data/yaml.js45
1 files changed, 40 insertions, 5 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 69069d66..4548c536 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -913,15 +913,22 @@ export function processThingsFromDataStep(documents, dataStep) {
       const aggregate = openAggregate({message: `Errors processing documents`});
 
       documents.forEach(
-        decorateErrorWithIndex(document => {
+        decorateErrorWithIndex((document, index) => {
           const {thing, aggregate: subAggregate} =
             processDocument(document, dataStep.documentThing);
 
+          thing[Thing.yamlSourceDocument] = document;
+          thing[Thing.yamlSourceDocumentPlacement] = ['all in one', index];
+
           result.push(thing);
           aggregate.call(subAggregate.close);
         }));
 
-      return {aggregate, result};
+      return {
+        aggregate,
+        result,
+        things: result,
+      };
     }
 
     case documentModes.oneDocumentTotal: {
@@ -931,7 +938,14 @@ export function processThingsFromDataStep(documents, dataStep) {
       const {thing, aggregate} =
         processDocument(documents[0], dataStep.documentThing);
 
-      return {aggregate, result: thing};
+      thing[Thing.yamlSourceDocument] = documents[0];
+      thing[Thing.yamlSourceDocumentPlacement] = ['one document total'];
+
+      return {
+        aggregate,
+        result: thing,
+        things: [thing],
+      };
     }
 
     case documentModes.headerAndEntries: {
@@ -946,6 +960,9 @@ export function processThingsFromDataStep(documents, dataStep) {
       const {thing: headerThing, aggregate: headerAggregate} =
         processDocument(headerDocument, dataStep.headerDocumentThing);
 
+      headerThing[Thing.yamlSourceDocument] = headerDocument;
+      headerThing[Thing.yamlSourceDocumentPlacement] = ['header'];
+
       try {
         headerAggregate.close();
       } catch (caughtError) {
@@ -959,6 +976,9 @@ export function processThingsFromDataStep(documents, dataStep) {
         const {thing: entryThing, aggregate: entryAggregate} =
           processDocument(entryDocument, dataStep.entryDocumentThing);
 
+        entryThing[Thing.yamlSourceDocument] = entryDocument;
+        entryThing[Thing.yamlSourceDocumentPlacement] = ['entry under header', index];
+
         entryThings.push(entryThing);
 
         try {
@@ -975,6 +995,7 @@ export function processThingsFromDataStep(documents, dataStep) {
           header: headerThing,
           entries: entryThings,
         },
+        things: [headerThing, ...entryThings],
       };
     }
 
@@ -988,7 +1009,14 @@ export function processThingsFromDataStep(documents, dataStep) {
       const {thing, aggregate} =
         processDocument(documents[0], dataStep.documentThing);
 
-      return {aggregate, result: thing};
+      thing[Thing.yamlSourceDocument] = documents[0];
+      thing[Thing.yamlSourceDocumentPlacement] = ['one per file'];
+
+      return {
+        aggregate,
+        result: thing,
+        things: [thing],
+      };
     }
 
     default:
@@ -1088,9 +1116,16 @@ export async function processThingsFromDataSteps(documentLists, fileLists, dataS
           file: files,
           documents: documentLists,
         }).map(({file, documents}) => {
-            const {result, aggregate} =
+            const {result, aggregate, things} =
               processThingsFromDataStep(documents, dataStep);
 
+            for (const thing of things) {
+              thing[Thing.yamlSourceFilename] =
+                path.relative(dataPath, file)
+                  .split(path.sep)
+                  .join(path.posix.sep);
+            }
+
             const close = decorateErrorWithFileFromDataPath(aggregate.close, {dataPath});
             aggregate.close = () => close({file});