« get me outta code hell

data, yaml: mark ignored fields on `fields` - 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>2024-01-22 10:31:58 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-30 07:59:40 -0400
commitb30585187480a270826767eaf97e1acc66126072 (patch)
tree6478ef73dc72b696c032b631c6ea7edc7fa521fa /src/data/yaml.js
parent98c2012c0c6233fe3f70ba215c19f6d39d7e1e34 (diff)
data, yaml: mark ignored fields on `fields`
Diffstat (limited to 'src/data/yaml.js')
-rw-r--r--src/data/yaml.js17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 19f5629..fe8bfdc 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -80,14 +80,12 @@ function makeProcessDocument(thingConstructor, {
   // YAML into some other format before providing setting it on the Thing
   // instance.
   //
-  fields: fieldSpecs = {},
-
-  // Completely ignored fields. These won't throw an unknown field error if
-  // they're present in a document, but they won't be used for Thing property
-  // generation, either. Useful for stuff that's present in data files but not
-  // yet implemented as part of a Thing's data model!
+  // If a field entry has `ignore: true`, it will be completely skipped by the
+  // YAML parser - it won't be validated, read, or loaded into data objects.
+  // This is mainly useful for fields that are purely annotational or are
+  // currently placeholders.
   //
-  ignoredFields = [],
+  fields: fieldSpecs = {},
 
   // List of fields which are invalid when coexisting in a document.
   // Data objects are generally allowing with regards to what properties go
@@ -120,6 +118,11 @@ function makeProcessDocument(thingConstructor, {
 
   const knownFields = Object.keys(fieldSpecs);
 
+  const ignoredFields =
+    Object.entries(fieldSpecs)
+      .filter(([, {ignore}]) => ignore)
+      .map(([field]) => field);
+
   const propertyToField =
     withEntries(fieldSpecs, entries => entries
       .map(([field, {property}]) => [property, field]));