« get me outta code hell

withResolvedAnnotatedReferenceList.js « wiki-data « composite « data « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/wiki-data/withResolvedAnnotatedReferenceList.js
blob: e2b8a0a1a6dad26d2c3fede921f3422d06b78744 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import {input, templateCompositeFrom} from '#composite';
import {stitchArrays} from '#sugar';
import {isObject, validateArrayItems} from '#validators';

import {withPropertyFromList} from '#composite/data';

import {
  exitWithoutDependency,
  raiseOutputWithoutDependency,
  withAvailabilityFilter,
} from '#composite/control-flow';

import inputNotFoundMode from './inputNotFoundMode.js';
import inputWikiData from './inputWikiData.js';
import raiseResolvedReferenceList from './raiseResolvedReferenceList.js';
import withResolvedReferenceList from './withResolvedReferenceList.js';

export default templateCompositeFrom({
  annotation: `withResolvedAnnotatedReferenceList`,

  inputs: {
    list: input({
      validate: validateArrayItems(isObject),
      acceptsNull: true,
    }),

    reference: input({type: 'string', defaultValue: 'reference'}),
    annotation: input({type: 'string', defaultValue: 'annotation'}),
    thing: input({type: 'string', defaultValue: 'thing'}),

    data: inputWikiData({allowMixedTypes: true}),
    find: input({type: 'function'}),

    notFoundMode: inputNotFoundMode(),
  },

  outputs: ['#resolvedAnnotatedReferenceList'],

  steps: () => [
    exitWithoutDependency({
      dependency: input('data'),
      value: input.value([]),
    }),

    raiseOutputWithoutDependency({
      dependency: input('list'),
      mode: input.value('empty'),
      output: input.value({
        ['#resolvedAnnotatedReferenceList']: [],
      }),
    }),

    withPropertyFromList({
      list: input('list'),
      property: input('reference'),
    }).outputs({
      ['#values']: '#references',
    }),

    withPropertyFromList({
      list: input('list'),
      property: input('annotation'),
    }).outputs({
      ['#values']: '#annotations',
    }),

    withResolvedReferenceList({
      list: '#references',
      data: input('data'),
      find: input('find'),
      notFoundMode: input.value('null'),
    }),

    {
      dependencies: [
        input('thing'),
        input('annotation'),
        '#resolvedReferenceList',
        '#annotations',
      ],

      compute: (continuation, {
        [input('thing')]: thingProperty,
        [input('annotation')]: annotationProperty,
        ['#resolvedReferenceList']: things,
        ['#annotations']: annotations,
      }) => continuation({
        ['#matches']:
          stitchArrays({
            [thingProperty]: things,
            [annotationProperty]: annotations,
          }),
      }),
    },

    withAvailabilityFilter({
      from: '#resolvedReferenceList',
    }),

    raiseResolvedReferenceList({
      notFoundMode: input('notFoundMode'),
      results: '#matches',
      filter: '#availabilityFilter',
      outputs: input.value('#resolvedAnnotatedReferenceList'),
    }),
  ],
})