« get me outta code hell

constitutibleArtwork.js « wiki-properties « 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-properties/constitutibleArtwork.js
blob: 9f7ba13e29462297b0629ca44bb8a15d3dbdfd71 (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
// This composition does not actually inspect the values of any properties
// specified, so it's not responsible for determining whether a constituted
// artwork should exist at all.

import {input, templateCompositeFrom} from '#composite';
import {withEntries} from '#sugar';
import Thing from '#thing';
import {validateThing} from '#validators';

import {exposeDependency, exposeUpdateValueOrContinue}
  from '#composite/control-flow';
import {withConstitutedArtwork} from '#composite/wiki-data';

const template = templateCompositeFrom({
  annotation: `constitutibleArtwork`,

  compose: false,

  inputs: {
    dimensionsFromThingProperty: input({type: 'string', acceptsNull: true}),
    fileExtensionFromThingProperty: input({type: 'string', acceptsNull: true}),
    artistContribsFromThingProperty: input({type: 'string', acceptsNull: true}),
    artistContribsArtistProperty: input({type: 'string', acceptsNull: true}),
    dateFromThingProperty: input({type: 'string', acceptsNull: true}),
  },

  steps: () => [
    exposeUpdateValueOrContinue({
      validate: input.value(
        validateThing({
          referenceType: 'artwork',
        })),
    }),

    withConstitutedArtwork({
      dimensionsFromThingProperty: input('dimensionsFromThingProperty'),
      fileExtensionFromThingProperty: input('fileExtensionFromThingProperty'),
      artistContribsFromThingProperty: input('artistContribsFromThingProperty'),
      artistContribsArtistProperty: input('artistContribsArtistProperty'),
      dateFromThingProperty: input('dateFromThingProperty'),
    }),

    exposeDependency({
      dependency: '#constitutedArtwork',
    }),
  ],
});

template.fromYAMLFieldSpec = function(field) {
  const {[Thing.yamlDocumentSpec]: documentSpec} = this;

  const {provide} = documentSpec.fields[field].transform;

  const inputs =
    withEntries(provide, entries =>
      entries.map(([property, value]) => [
        property,
        input.value(value),
      ]));

  return template(inputs);
};

export default template;