« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/data/validators.js11
1 files changed, 11 insertions, 0 deletions
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),