« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/data/composite/things/content/hasAnnotationPart.js20
-rw-r--r--src/data/composite/things/content/index.js5
-rw-r--r--src/data/composite/things/content/withAnnotationPartNodeLists.js28
-rw-r--r--src/data/composite/things/content/withAnnotationParts.js103
-rw-r--r--src/data/composite/things/content/withHasAnnotationPart.js43
-rw-r--r--src/data/composite/things/content/withSourceText.js53
-rw-r--r--src/data/composite/things/content/withSourceURLs.js62
-rw-r--r--src/data/composite/wiki-data/splitContentNodesAround.js13
-rw-r--r--src/data/things/content.js133
9 files changed, 169 insertions, 291 deletions
diff --git a/src/data/composite/things/content/hasAnnotationPart.js b/src/data/composite/things/content/hasAnnotationPart.js
index 83d175e3..93aaf5e5 100644
--- a/src/data/composite/things/content/hasAnnotationPart.js
+++ b/src/data/composite/things/content/hasAnnotationPart.js
@@ -1,9 +1,5 @@
 import {input, templateCompositeFrom} from '#composite';
 
-import {exposeDependency} from '#composite/control-flow';
-
-import withHasAnnotationPart from './withHasAnnotationPart.js';
-
 export default templateCompositeFrom({
   annotation: `hasAnnotationPart`,
 
@@ -14,12 +10,16 @@ export default templateCompositeFrom({
   },
 
   steps: () => [
-    withHasAnnotationPart({
-      part: input('part'),
-    }),
+    {
+      dependencies: [input('part'), 'annotationParts'],
 
-    exposeDependency({
-      dependency: '#hasAnnotationPart',
-    }),
+      compute: ({
+        [input('part')]: search,
+        ['annotationParts']: parts,
+      }) =>
+          parts.some(part =>
+            part.toLowerCase() ===
+            search.toLowerCase()),
+    },
   ],
 });
diff --git a/src/data/composite/things/content/index.js b/src/data/composite/things/content/index.js
index 4176337d..37d6fdc5 100644
--- a/src/data/composite/things/content/index.js
+++ b/src/data/composite/things/content/index.js
@@ -1,7 +1,4 @@
 export {default as contentArtists} from './contentArtists.js';
 export {default as hasAnnotationPart} from './hasAnnotationPart.js';
-export {default as withAnnotationParts} from './withAnnotationParts.js';
-export {default as withHasAnnotationPart} from './withHasAnnotationPart.js';
-export {default as withSourceText} from './withSourceText.js';
-export {default as withSourceURLs} from './withSourceURLs.js';
+export {default as withAnnotationPartNodeLists} from './withAnnotationPartNodeLists.js';
 export {default as withWebArchiveDate} from './withWebArchiveDate.js';
diff --git a/src/data/composite/things/content/withAnnotationPartNodeLists.js b/src/data/composite/things/content/withAnnotationPartNodeLists.js
new file mode 100644
index 00000000..fc304594
--- /dev/null
+++ b/src/data/composite/things/content/withAnnotationPartNodeLists.js
@@ -0,0 +1,28 @@
+import {input, templateCompositeFrom} from '#composite';
+
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
+import {splitContentNodesAround, withContentNodes} from '#composite/wiki-data';
+
+export default templateCompositeFrom({
+  annotation: `withAnnotationPartNodeLists`,
+
+  outputs: ['#annotationPartNodeLists'],
+
+  steps: () => [
+    raiseOutputWithoutDependency({
+      dependency: 'annotation',
+      output: input.value({'#annotationPartNodeLists': []}),
+    }),
+
+    withContentNodes({
+      from: 'annotation',
+    }),
+
+    splitContentNodesAround({
+      nodes: '#contentNodes',
+      around: input.value(/, */g),
+    }).outputs({
+      '#contentNodeLists': '#annotationPartNodeLists',
+    }),
+  ],
+});
diff --git a/src/data/composite/things/content/withAnnotationParts.js b/src/data/composite/things/content/withAnnotationParts.js
deleted file mode 100644
index 15eb74a5..00000000
--- a/src/data/composite/things/content/withAnnotationParts.js
+++ /dev/null
@@ -1,103 +0,0 @@
-import {input, templateCompositeFrom} from '#composite';
-import {empty, transposeArrays} from '#sugar';
-import {is} from '#validators';
-
-import {raiseOutputWithoutDependency} from '#composite/control-flow';
-import {withPropertyFromList} from '#composite/data';
-import {splitContentNodesAround, withContentNodes} from '#composite/wiki-data';
-
-export default templateCompositeFrom({
-  annotation: `withAnnotationParts`,
-
-  inputs: {
-    mode: input({
-      validate: is('strings', 'nodes'),
-    }),
-  },
-
-  outputs: ['#annotationParts'],
-
-  steps: () => [
-    raiseOutputWithoutDependency({
-      dependency: '_annotation',
-      output: input.value({'#annotationParts': []}),
-    }),
-
-    withContentNodes({
-      from: '_annotation',
-    }),
-
-    splitContentNodesAround({
-      nodes: '#contentNodes',
-      around: input.value(/, */g),
-    }),
-
-    {
-      dependencies: ['#contentNodeLists'],
-      compute: (continuation, {
-        ['#contentNodeLists']: nodeLists,
-      }) => continuation({
-        ['#contentNodeLists']:
-          nodeLists.filter(list => !empty(list)),
-      }),
-    },
-
-    {
-      dependencies: ['#contentNodeLists', input('mode')],
-      compute: (continuation, {
-        ['#contentNodeLists']: nodeLists,
-        [input('mode')]: mode,
-      }) =>
-        (mode === 'nodes'
-          ? continuation.raiseOutput({'#annotationParts': nodeLists})
-          : continuation()),
-    },
-
-    {
-      dependencies: ['#contentNodeLists'],
-
-      compute: (continuation, {
-        ['#contentNodeLists']: nodeLists,
-      }) => continuation({
-        ['#firstNodes']:
-          nodeLists.map(list => list.at(0)),
-
-        ['#lastNodes']:
-          nodeLists.map(list => list.at(-1)),
-      }),
-    },
-
-    withPropertyFromList({
-      list: '#firstNodes',
-      property: input.value('i'),
-    }).outputs({
-      '#firstNodes.i': '#startIndices',
-    }),
-
-    withPropertyFromList({
-      list: '#lastNodes',
-      property: input.value('iEnd'),
-    }).outputs({
-      '#lastNodes.iEnd': '#endIndices',
-    }),
-
-    {
-      dependencies: [
-        'annotation',
-        '#startIndices',
-        '#endIndices',
-      ],
-
-      compute: (continuation, {
-        ['annotation']: annotation,
-        ['#startIndices']: startIndices,
-        ['#endIndices']: endIndices,
-      }) => continuation({
-        ['#annotationParts']:
-          transposeArrays([startIndices, endIndices])
-            .map(([start, end]) =>
-              annotation.slice(start, end)),
-      }),
-    },
-  ],
-});
diff --git a/src/data/composite/things/content/withHasAnnotationPart.js b/src/data/composite/things/content/withHasAnnotationPart.js
deleted file mode 100644
index 4af554f3..00000000
--- a/src/data/composite/things/content/withHasAnnotationPart.js
+++ /dev/null
@@ -1,43 +0,0 @@
-import {input, templateCompositeFrom} from '#composite';
-
-import {raiseOutputWithoutDependency} from '#composite/control-flow';
-
-import withAnnotationParts from './withAnnotationParts.js';
-
-export default templateCompositeFrom({
-  annotation: `withHasAnnotationPart`,
-
-  inputs: {
-    part: input({type: 'string'}),
-  },
-
-  outputs: ['#hasAnnotationPart'],
-
-  steps: () => [
-    withAnnotationParts({
-      mode: input.value('strings'),
-    }),
-
-    raiseOutputWithoutDependency({
-      dependency: '#annotationParts',
-      output: input.value({'#hasAnnotationPart': false}),
-    }),
-
-    {
-      dependencies: [
-        input('part'),
-        '#annotationParts',
-      ],
-
-      compute: (continuation, {
-        [input('part')]: search,
-        ['#annotationParts']: parts,
-      }) => continuation({
-        ['#hasAnnotationPart']:
-          parts.some(part =>
-            part.toLowerCase() ===
-            search.toLowerCase()),
-      }),
-    },
-  ],
-});
diff --git a/src/data/composite/things/content/withSourceText.js b/src/data/composite/things/content/withSourceText.js
deleted file mode 100644
index 292306b7..00000000
--- a/src/data/composite/things/content/withSourceText.js
+++ /dev/null
@@ -1,53 +0,0 @@
-import {input, templateCompositeFrom} from '#composite';
-
-import {raiseOutputWithoutDependency} from '#composite/control-flow';
-
-import withAnnotationParts from './withAnnotationParts.js';
-
-export default templateCompositeFrom({
-  annotation: `withSourceText`,
-
-  outputs: ['#sourceText'],
-
-  steps: () => [
-    withAnnotationParts({
-      mode: input.value('nodes'),
-    }),
-
-    raiseOutputWithoutDependency({
-      dependency: '#annotationParts',
-      output: input.value({'#sourceText': null}),
-    }),
-
-    {
-      dependencies: ['#annotationParts'],
-      compute: (continuation, {
-        ['#annotationParts']: annotationParts,
-      }) => continuation({
-        ['#firstPartWithExternalLink']:
-          annotationParts
-            .find(nodes => nodes
-              .some(node => node.type === 'external-link')) ??
-          null,
-      }),
-    },
-
-    raiseOutputWithoutDependency({
-      dependency: '#firstPartWithExternalLink',
-      output: input.value({'#sourceText': null}),
-    }),
-
-    {
-      dependencies: ['annotation', '#firstPartWithExternalLink'],
-      compute: (continuation, {
-        ['annotation']: annotation,
-        ['#firstPartWithExternalLink']: nodes,
-      }) => continuation({
-        ['#sourceText']:
-          annotation.slice(
-            nodes.at(0).i,
-            nodes.at(-1).iEnd),
-      }),
-    },
-  ],
-});
diff --git a/src/data/composite/things/content/withSourceURLs.js b/src/data/composite/things/content/withSourceURLs.js
deleted file mode 100644
index f85ff9ea..00000000
--- a/src/data/composite/things/content/withSourceURLs.js
+++ /dev/null
@@ -1,62 +0,0 @@
-import {input, templateCompositeFrom} from '#composite';
-
-import {raiseOutputWithoutDependency} from '#composite/control-flow';
-import {withFilteredList, withMappedList} from '#composite/data';
-
-import withAnnotationParts from './withAnnotationParts.js';
-
-export default templateCompositeFrom({
-  annotation: `withSourceURLs`,
-
-  outputs: ['#sourceURLs'],
-
-  steps: () => [
-    withAnnotationParts({
-      mode: input.value('nodes'),
-    }),
-
-    raiseOutputWithoutDependency({
-      dependency: '#annotationParts',
-      output: input.value({'#sourceURLs': []}),
-    }),
-
-    {
-      dependencies: ['#annotationParts'],
-      compute: (continuation, {
-        ['#annotationParts']: annotationParts,
-      }) => continuation({
-        ['#firstPartWithExternalLink']:
-          annotationParts
-            .find(nodes => nodes
-              .some(node => node.type === 'external-link')) ??
-          null,
-      }),
-    },
-
-    raiseOutputWithoutDependency({
-      dependency: '#firstPartWithExternalLink',
-      output: input.value({'#sourceURLs': []}),
-    }),
-
-    withMappedList({
-      list: '#firstPartWithExternalLink',
-      map: input.value(node => node.type === 'external-link'),
-    }).outputs({
-      '#mappedList': '#externalLinkFilter',
-    }),
-
-    withFilteredList({
-      list: '#firstPartWithExternalLink',
-      filter: '#externalLinkFilter',
-    }).outputs({
-      '#filteredList': '#externalLinks',
-    }),
-
-    withMappedList({
-      list: '#externalLinks',
-      map: input.value(node => node.data.href),
-    }).outputs({
-      '#mappedList': '#sourceURLs',
-    }),
-  ],
-});
diff --git a/src/data/composite/wiki-data/splitContentNodesAround.js b/src/data/composite/wiki-data/splitContentNodesAround.js
index 6648d8e1..afdbd3fa 100644
--- a/src/data/composite/wiki-data/splitContentNodesAround.js
+++ b/src/data/composite/wiki-data/splitContentNodesAround.js
@@ -2,6 +2,7 @@ import {input, templateCompositeFrom} from '#composite';
 import {splitContentNodesAround} from '#replacer';
 import {anyOf, isFunction, validateInstanceOf} from '#validators';
 
+import {withAvailabilityFilter} from '#composite/control-flow';
 import {withFilteredList, withMappedList, withUnflattenedList}
   from '#composite/data';
 
@@ -83,5 +84,17 @@ export default templateCompositeFrom({
     }).outputs({
       '#unflattenedList': '#contentNodeLists',
     }),
+
+    withAvailabilityFilter({
+      from: '#contentNodeLists',
+      mode: input.value('empty'),
+    }),
+
+    withFilteredList({
+      list: '#contentNodeLists',
+      filter: '#availabilityFilter',
+    }).outputs({
+      '#filteredList': '#contentNodeLists',
+    }),
   ],
 });
diff --git a/src/data/things/content.js b/src/data/things/content.js
index 21ee88f8..49a9a0d9 100644
--- a/src/data/things/content.js
+++ b/src/data/things/content.js
@@ -1,8 +1,11 @@
 import {input} from '#composite';
+import {transposeArrays} from '#sugar';
 import Thing from '#thing';
 import {is, isDate} from '#validators';
 import {parseDate} from '#yaml';
 
+import {withFilteredList, withMappedList, withPropertyFromList}
+  from '#composite/data';
 import {contentString, simpleDate, soupyFind, thing}
   from '#composite/wiki-properties';
 
@@ -18,10 +21,7 @@ import {
 import {
   contentArtists,
   hasAnnotationPart,
-  withAnnotationParts,
-  withHasAnnotationPart,
-  withSourceText,
-  withSourceURLs,
+  withAnnotationPartNodeLists,
   withWebArchiveDate,
 } from '#composite/things/content';
 
@@ -116,21 +116,126 @@ export class ContentEntry extends Thing {
     ],
 
     annotationParts: [
-      withAnnotationParts({
-        mode: input.value('strings'),
+      withAnnotationPartNodeLists(),
+
+      {
+        dependencies: ['#annotationPartNodeLists'],
+        compute: (continuation, {
+          ['#annotationPartNodeLists']: nodeLists,
+        }) => continuation({
+          ['#firstNodes']:
+            nodeLists.map(list => list.at(0)),
+
+          ['#lastNodes']:
+            nodeLists.map(list => list.at(-1)),
+        }),
+      },
+
+      withPropertyFromList({
+        list: '#firstNodes',
+        property: input.value('i'),
+      }).outputs({
+        '#firstNodes.i': '#startIndices',
       }),
 
-      exposeDependency({dependency: '#annotationParts'}),
+      withPropertyFromList({
+        list: '#lastNodes',
+        property: input.value('iEnd'),
+      }).outputs({
+        '#lastNodes.iEnd': '#endIndices',
+      }),
+
+      {
+        dependencies: [
+          'annotation',
+          '#startIndices',
+          '#endIndices',
+        ],
+
+        compute: ({
+          ['annotation']: annotation,
+          ['#startIndices']: startIndices,
+          ['#endIndices']: endIndices,
+        }) =>
+          transposeArrays([startIndices, endIndices])
+            .map(([start, end]) =>
+              annotation.slice(start, end)),
+      },
     ],
 
     sourceText: [
-      withSourceText(),
-      exposeDependency({dependency: '#sourceText'}),
+      withAnnotationPartNodeLists(),
+
+      {
+        dependencies: ['#annotationPartNodeLists'],
+        compute: (continuation, {
+          ['#annotationPartNodeLists']: nodeLists,
+        }) => continuation({
+          ['#firstPartWithExternalLink']:
+            nodeLists
+              .find(nodes => nodes
+                .some(node => node.type === 'external-link')) ??
+            null,
+        }),
+      },
+
+      exitWithoutDependency({
+        dependency: '#firstPartWithExternalLink',
+      }),
+
+      {
+        dependencies: ['annotation', '#firstPartWithExternalLink'],
+        compute: ({
+          ['annotation']: annotation,
+          ['#firstPartWithExternalLink']: nodes,
+        }) =>
+          annotation.slice(
+            nodes.at(0).i,
+            nodes.at(-1).iEnd),
+      },
     ],
 
     sourceURLs: [
-      withSourceURLs(),
-      exposeDependency({dependency: '#sourceURLs'}),
+      withAnnotationPartNodeLists(),
+
+      {
+        dependencies: ['#annotationPartNodeLists'],
+        compute: (continuation, {
+          ['#annotationPartNodeLists']: nodeLists,
+        }) => continuation({
+          ['#firstPartWithExternalLink']:
+            nodeLists
+              .find(nodes => nodes
+                .some(node => node.type === 'external-link')) ??
+            null,
+        }),
+      },
+
+      exitWithoutDependency({
+        dependency: '#firstPartWithExternalLink',
+        value: input.value([]),
+      }),
+
+      withMappedList({
+        list: '#firstPartWithExternalLink',
+        map: input.value(node => node.type === 'external-link'),
+      }).outputs({
+        '#mappedList': '#externalLinkFilter',
+      }),
+
+      withFilteredList({
+        list: '#firstPartWithExternalLink',
+        filter: '#externalLinkFilter',
+      }),
+
+      withMappedList({
+        list: '#filteredList',
+        map: input.value(node => node.data.href),
+      }),
+
+      exposeDependency({
+        dependency: '#mappedList',
+      }),
     ],
   });
 
@@ -196,12 +301,8 @@ export class LyricsEntry extends ContentEntry {
     }),
 
     hasSquareBracketAnnotations: [
-      withHasAnnotationPart({
-        part: input.value('wiki lyrics'),
-      }),
-
       exitWithoutDependency({
-        dependency: '#hasAnnotationPart',
+        dependency: 'isWikiLyrics',
         mode: input.value('falsy'),
         value: input.value(false),
       }),