entity.cjs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var entity_exports = {};
  20. __export(entity_exports, {
  21. entityKind: () => entityKind,
  22. hasOwnEntityKind: () => hasOwnEntityKind,
  23. is: () => is
  24. });
  25. module.exports = __toCommonJS(entity_exports);
  26. const entityKind = Symbol.for("drizzle:entityKind");
  27. const hasOwnEntityKind = Symbol.for("drizzle:hasOwnEntityKind");
  28. function is(value, type) {
  29. if (!value || typeof value !== "object") {
  30. return false;
  31. }
  32. if (value instanceof type) {
  33. return true;
  34. }
  35. if (!Object.prototype.hasOwnProperty.call(type, entityKind)) {
  36. throw new Error(
  37. `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.`
  38. );
  39. }
  40. let cls = Object.getPrototypeOf(value).constructor;
  41. if (cls) {
  42. while (cls) {
  43. if (entityKind in cls && cls[entityKind] === type[entityKind]) {
  44. return true;
  45. }
  46. cls = Object.getPrototypeOf(cls);
  47. }
  48. }
  49. return false;
  50. }
  51. // Annotate the CommonJS export names for ESM import in node:
  52. 0 && (module.exports = {
  53. entityKind,
  54. hasOwnEntityKind,
  55. is
  56. });
  57. //# sourceMappingURL=entity.cjs.map