« get me outta code hell

yaml: subdocument provide - 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:
author(quasar) nebula <qznebula@protonmail.com>2025-03-31 15:03:05 -0300
committer(quasar) nebula <qznebula@protonmail.com>2025-04-10 16:02:35 -0300
commit964273f8cb26c6d9df8ec827126167dc5b58ae27 (patch)
tree104c2693fe9ae04367af6a08eaed554c0c5cfbc2 /src/data
parent02216898a5bf22359219b77eb48ba9928fa7ea94 (diff)
yaml: subdocument provide
Diffstat (limited to 'src/data')
-rw-r--r--src/data/yaml.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 6618fd4c..d7acdbc0 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -214,6 +214,7 @@ function makeProcessDocument(thingConstructor, {
 
       subdoc(documentType, data, {
         bindInto = null,
+        provide = null,
       } = {}) {
         if (!documentType)
           throw new Error(`Expected document type, got ${typeAppearance(documentType)}`);
@@ -223,12 +224,15 @@ function makeProcessDocument(thingConstructor, {
           throw new Error(`Expected data to be an object, got ${typeAppearance(data)}`);
         if (typeof bindInto !== 'string' && bindInto !== null)
           throw new Error(`Expected bindInto to be a string, got ${typeAppearance(bindInto)}`);
+        if (typeof provide !== 'object' && provide !== null)
+          throw new Error(`Expected provide to be an object, got ${typeAppearance(provide)}`);
 
         return {
           [subdocSymbol]: {
             documentType,
             data,
             bindInto,
+            provide,
           },
         };
       },
@@ -295,6 +299,10 @@ function makeProcessDocument(thingConstructor, {
         subthing[setup.bindInto] = thing;
       }
 
+      if (setup.provide) {
+        Object.assign(subthing, setup.provide);
+      }
+
       if (subthing) {
         fieldValues[field] = subthing;
       }