« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/data')
-rw-r--r--src/data/thing.js4
-rw-r--r--src/data/yaml.js45
2 files changed, 44 insertions, 5 deletions
diff --git a/src/data/thing.js b/src/data/thing.js
index c51c5fe5..90453c15 100644
--- a/src/data/thing.js
+++ b/src/data/thing.js
@@ -21,6 +21,10 @@ export default class Thing extends CacheableObject {
   static yamlDocumentSpec = Symbol.for('Thing.yamlDocumentSpec');
   static getYamlLoadingSpec = Symbol.for('Thing.getYamlLoadingSpec');
 
+  static yamlSourceFilename = Symbol.for('Thing.yamlSourceFilename');
+  static yamlSourceDocument = Symbol.for('Thing.yamlSourceDocument');
+  static yamlSourceDocumentPlacement = Symbol.for('Thing.yamlSourceDocumentPlacement');
+
   static isThingConstructor = Symbol.for('Thing.isThingConstructor');
   static isThing = Symbol.for('Thing.isThing');
 
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});