utils.js 2.9 KB

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