« 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/composite/things/content
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/composite/things/content')
-rw-r--r--src/data/composite/things/content/contentArtists.js40
-rw-r--r--src/data/composite/things/content/hasAnnotationPart.js20
-rw-r--r--src/data/composite/things/content/index.js7
-rw-r--r--src/data/composite/things/content/withAnnotationPartNodeLists.js28
-rw-r--r--src/data/composite/things/content/withAnnotationParts.js94
-rw-r--r--src/data/composite/things/content/withExpressedOrImplicitArtistReferences.js (renamed from src/data/composite/things/content/helpers/withExpressedOrImplicitArtistReferences.js)1
-rw-r--r--src/data/composite/things/content/withHasAnnotationPart.js43
-rw-r--r--src/data/composite/things/content/withSourceText.js54
-rw-r--r--src/data/composite/things/content/withSourceURLs.js63
9 files changed, 41 insertions, 309 deletions
diff --git a/src/data/composite/things/content/contentArtists.js b/src/data/composite/things/content/contentArtists.js
deleted file mode 100644
index 8d5db5a5..00000000
--- a/src/data/composite/things/content/contentArtists.js
+++ /dev/null
@@ -1,40 +0,0 @@
-import {input, templateCompositeFrom} from '#composite';
-import {validateReferenceList} from '#validators';
-
-import {exitWithoutDependency, exposeDependency}
-  from '#composite/control-flow';
-import {withResolvedReferenceList} from '#composite/wiki-data';
-import {soupyFind} from '#composite/wiki-properties';
-
-import withExpressedOrImplicitArtistReferences
-  from './helpers/withExpressedOrImplicitArtistReferences.js';
-
-export default templateCompositeFrom({
-  annotation: `contentArtists`,
-
-  compose: false,
-
-  update: {
-    validate: validateReferenceList('artist'),
-  },
-
-  steps: () => [
-    withExpressedOrImplicitArtistReferences({
-      from: input.updateValue(),
-    }),
-
-    exitWithoutDependency({
-      dependency: '#artistReferences',
-      value: input.value([]),
-    }),
-
-    withResolvedReferenceList({
-      list: '#artistReferences',
-      find: soupyFind.input('artist'),
-    }),
-
-    exposeDependency({
-      dependency: '#resolvedReferenceList',
-    }),
-  ],
-});
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..27bf7c53 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 withExpressedOrImplicitArtistReferences} from './withExpressedOrImplicitArtistReferences.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 5eb8e3d5..00000000
--- a/src/data/composite/things/content/withAnnotationParts.js
+++ /dev/null
@@ -1,94 +0,0 @@
-import {input, templateCompositeFrom} from '#composite';
-import {parseContentNodes} from '#replacer';
-import {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', 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/helpers/withExpressedOrImplicitArtistReferences.js b/src/data/composite/things/content/withExpressedOrImplicitArtistReferences.js
index 62799d43..69da8c75 100644
--- a/src/data/composite/things/content/helpers/withExpressedOrImplicitArtistReferences.js
+++ b/src/data/composite/things/content/withExpressedOrImplicitArtistReferences.js
@@ -52,6 +52,7 @@ export default templateCompositeFrom({
     withMappedList({
       list: '#artistTags',
       map: input.value(node =>
+        'artist:' +
         node.data.replacerValue[0].data),
     }).outputs({
       '#mappedList': '#artistReferences',
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 d310e8ea..00000000
--- a/src/data/composite/things/content/withSourceText.js
+++ /dev/null
@@ -1,54 +0,0 @@
-import {input, templateCompositeFrom} from '#composite';
-import {parseContentNodes} from '#replacer';
-
-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 f1e8dbc0..00000000
--- a/src/data/composite/things/content/withSourceURLs.js
+++ /dev/null
@@ -1,63 +0,0 @@
-import {input, templateCompositeFrom} from '#composite';
-import {parseContentNodes} from '#replacer';
-
-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',
-    }),
-  ],
-});