diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2022-02-12 15:27:14 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2022-02-12 15:27:14 -0400 |
commit | cfa02cb03a363c46408db7f0ec54bd3a7e4ad018 (patch) | |
tree | 9dbd2f26cc200838717404163037953924f3e194 /src/thing/thing.js | |
parent | f028105cbb268af2c3039215557ed6f531c688d4 (diff) |
brb gonna make these into one file now
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]`); |