entity.js 867 B

12345678910111213141516171819202122232425262728293031
  1. const entityKind = Symbol.for("drizzle:entityKind");
  2. const hasOwnEntityKind = Symbol.for("drizzle:hasOwnEntityKind");
  3. function is(value, type) {
  4. if (!value || typeof value !== "object") {
  5. return false;
  6. }
  7. if (value instanceof type) {
  8. return true;
  9. }
  10. if (!Object.prototype.hasOwnProperty.call(type, entityKind)) {
  11. throw new Error(
  12. `Class "${type.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`
  13. );
  14. }
  15. let cls = Object.getPrototypeOf(value).constructor;
  16. if (cls) {
  17. while (cls) {
  18. if (entityKind in cls && cls[entityKind] === type[entityKind]) {
  19. return true;
  20. }
  21. cls = Object.getPrototypeOf(cls);
  22. }
  23. }
  24. return false;
  25. }
  26. export {
  27. entityKind,
  28. hasOwnEntityKind,
  29. is
  30. };
  31. //# sourceMappingURL=entity.js.map