utils.cjs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports._RootEventFilter = exports.isRunnableInterface = void 0;
  4. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  5. function isRunnableInterface(thing) {
  6. return thing ? thing.lc_runnable : false;
  7. }
  8. exports.isRunnableInterface = isRunnableInterface;
  9. /**
  10. * Utility to filter the root event in the streamEvents implementation.
  11. * This is simply binding the arguments to the namespace to make save on
  12. * a bit of typing in the streamEvents implementation.
  13. *
  14. * TODO: Refactor and remove.
  15. */
  16. class _RootEventFilter {
  17. constructor(fields) {
  18. Object.defineProperty(this, "includeNames", {
  19. enumerable: true,
  20. configurable: true,
  21. writable: true,
  22. value: void 0
  23. });
  24. Object.defineProperty(this, "includeTypes", {
  25. enumerable: true,
  26. configurable: true,
  27. writable: true,
  28. value: void 0
  29. });
  30. Object.defineProperty(this, "includeTags", {
  31. enumerable: true,
  32. configurable: true,
  33. writable: true,
  34. value: void 0
  35. });
  36. Object.defineProperty(this, "excludeNames", {
  37. enumerable: true,
  38. configurable: true,
  39. writable: true,
  40. value: void 0
  41. });
  42. Object.defineProperty(this, "excludeTypes", {
  43. enumerable: true,
  44. configurable: true,
  45. writable: true,
  46. value: void 0
  47. });
  48. Object.defineProperty(this, "excludeTags", {
  49. enumerable: true,
  50. configurable: true,
  51. writable: true,
  52. value: void 0
  53. });
  54. this.includeNames = fields.includeNames;
  55. this.includeTypes = fields.includeTypes;
  56. this.includeTags = fields.includeTags;
  57. this.excludeNames = fields.excludeNames;
  58. this.excludeTypes = fields.excludeTypes;
  59. this.excludeTags = fields.excludeTags;
  60. }
  61. includeEvent(event, rootType) {
  62. let include = this.includeNames === undefined &&
  63. this.includeTypes === undefined &&
  64. this.includeTags === undefined;
  65. const eventTags = event.tags ?? [];
  66. if (this.includeNames !== undefined) {
  67. include = include || this.includeNames.includes(event.name);
  68. }
  69. if (this.includeTypes !== undefined) {
  70. include = include || this.includeTypes.includes(rootType);
  71. }
  72. if (this.includeTags !== undefined) {
  73. include =
  74. include || eventTags.some((tag) => this.includeTags?.includes(tag));
  75. }
  76. if (this.excludeNames !== undefined) {
  77. include = include && !this.excludeNames.includes(event.name);
  78. }
  79. if (this.excludeTypes !== undefined) {
  80. include = include && !this.excludeTypes.includes(rootType);
  81. }
  82. if (this.excludeTags !== undefined) {
  83. include =
  84. include && eventTags.every((tag) => !this.excludeTags?.includes(tag));
  85. }
  86. return include;
  87. }
  88. }
  89. exports._RootEventFilter = _RootEventFilter;