« get me outta code hell

withExpressedOrImplicitArtistReferences.js « content « things « composite « data « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/things/content/withExpressedOrImplicitArtistReferences.js
blob: a6200ee83a628797b9181ecbbe7ca99931b36b41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {input, templateCompositeFrom} from '#composite';

import {raiseOutputWithoutDependency} from '#composite/control-flow';
import {withFilteredList, withMappedList} from '#composite/data';
import {withContentNodes} from '#composite/wiki-data';

export default templateCompositeFrom({
  annotation: `withExpressedOrImplicitArtistReferences`,

  inputs: {
    fromExpressed: input({type: 'array', acceptsNull: true}),
    fromContent: input({type: 'string', acceptsNull: true}),

    filterArtistTags: input({type: 'function', defaultValue: () => true}),
  },

  outputs: ['#artistReferences'],

  steps: () => [
    {
      dependencies: [input('fromExpressed')],
      compute: (continuation, {
        [input('fromExpressed')]: expressedArtistReferences,
      }) =>
        (expressedArtistReferences
          ? continuation.raiseOutput({'#artistReferences': expressedArtistReferences})
          : continuation()),
    },

    raiseOutputWithoutDependency({
      dependency: input('fromContent'),
      output: input.value({'#artistReferences': []}),
    }),

    withContentNodes({
      from: input('fromContent'),
    }),

    withMappedList({
      list: '#contentNodes',
      map: input.value(node =>
        node.type === 'tag' &&
        node.data.replacerKey?.data === 'artist'),
    }).outputs({
      '#mappedList': '#artistTagFilter',
    }),

    withFilteredList('#contentNodes', '#artistTagFilter')
      .outputs({'#filteredList': '#artistTags'}),

    withMappedList({
      list: '#artistTags',
      map: input('filterArtistTags'),
    }).outputs({
      '#mappedList': '#customFilter',
    }),

    withFilteredList({list: '#artistTags', filter: '#customFilter'})
      .outputs({'#filteredList': '#artistTags'}),

    withMappedList({
      list: '#artistTags',
      map: input.value(node =>
        'artist:' +
        node.data.replacerValue[0].data),
    }).outputs({
      '#mappedList': '#artistReferences',
    }),
  ],
});