From b34f4b28667881cd1a5ff191d82d177bdeb5bba9 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 4 Mar 2024 13:33:02 -0400 Subject: validators: isThing --- src/data/validators.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/data/validators.js b/src/data/validators.js index e3e56122..976e6217 100644 --- a/src/data/validators.js +++ b/src/data/validators.js @@ -613,6 +613,17 @@ export function isThingClass(thingClass) { return true; } +export function isThing(thing) { + isObject(thing); + isFunction(thing.constructor); + + if (!Object.hasOwn(thing.constructor, Symbol.for('Thing.referenceType'))) { + throw new TypeError(`Expected a Thing, constructor missing Thing.referenceType`); + } + + return true; +} + export const isContribution = validateProperties({ artist: isArtistRef, annotation: optional(isStringNonEmpty), -- cgit 1.3.0-6-gf8a5