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
|
// Resolves the contribsByRef contained in the provided dependency,
// providing (named by the second argument) the result. "Resolving"
// means mapping the "who" reference of each contribution to an artist
// object, and filtering out those whose "who" doesn't match any artist.
import {input, templateCompositeFrom} from '#composite';
import find from '#find';
import {stitchArrays} from '#sugar';
import {is, isContributionList} from '#validators';
import {filterMultipleArrays} from '#wiki-data';
import {
raiseOutputWithoutDependency,
} from '#composite/control-flow';
import {
withPropertiesFromList,
} from '#composite/data';
import withResolvedReferenceList from './withResolvedReferenceList.js';
export default templateCompositeFrom({
annotation: `withResolvedContribs`,
inputs: {
from: input({
validate: isContributionList,
acceptsNull: true,
}),
notFoundMode: input({
validate: is('exit', 'filter', 'null'),
defaultValue: 'null',
}),
},
outputs: ['#resolvedContribs'],
steps: () => [
raiseOutputWithoutDependency({
dependency: input('from'),
mode: input.value('empty'),
output: input.value({
['#resolvedContribs']: [],
}),
}),
withPropertiesFromList({
list: input('from'),
properties: input.value(['who', 'what']),
prefix: input.value('#contribs'),
}),
withResolvedReferenceList({
list: '#contribs.who',
data: 'artistData',
find: input.value(find.artist),
notFoundMode: input('notFoundMode'),
}).outputs({
['#resolvedReferenceList']: '#contribs.who',
}),
{
dependencies: ['#contribs.who', '#contribs.what'],
compute(continuation, {
['#contribs.who']: who,
['#contribs.what']: what,
}) {
filterMultipleArrays(who, what, (who, _what) => who);
return continuation({
['#resolvedContribs']: stitchArrays({who, what}),
});
},
},
],
});
|