diff options
Diffstat (limited to 'src/thing/thing.js')
-rw-r--r-- | src/thing/thing.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/thing/thing.js b/src/thing/thing.js index 54a278d1..2d6def62 100644 --- a/src/thing/thing.js +++ b/src/thing/thing.js @@ -3,7 +3,12 @@ import CacheableObject from './cacheable-object.js'; +import { + validateArrayItems, +} from './validators.js'; + import { getKebabCase } from '../util/wiki-data.js'; +import find from '../util/find.js'; export default class Thing extends CacheableObject { static referenceType = Symbol('Thing.referenceType'); @@ -20,6 +25,31 @@ export default class Thing extends CacheableObject { } }; + static genContribsExpose(contribsByRefProperty) { + return { + dependencies: ['artistData', contribsByRefProperty], + compute: ({ artistData, [contribsByRefProperty]: contribsByRef }) => ( + (contribsByRef && artistData + ? (contribsByRef + .map(({ who: ref, what }) => ({ + who: find.artist(ref, {wikiData: {artistData}}), + what + })) + .filter(({ who }) => who)) + : []) + ) + }; + } + + static genWikiDataProperty(thingClass) { + return { + flags: {update: true}, + update: { + validate: validateArrayItems(x => x instanceof thingClass) + } + }; + } + static getReference(thing) { if (!thing.constructor[Thing.referenceType]) throw TypeError(`Passed Thing is ${thing.constructor.name}, which provides no [Thing.referenceType]`); |