Merge pull request #409 from Hexastack/408-issue-custom-event-names-are-accepting-normalized-event-names
Some checks failed
Build and Push Docker Images / paths-filter (push) Has been cancelled
Build and Push Docker Images / build-and-push (push) Has been cancelled

fix: update eventEmitter to exclude normalized event names from customized events
This commit is contained in:
Med Marrouchi 2024-12-06 15:09:08 +01:00 committed by GitHub
commit 62e59069dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,8 +6,6 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import { type OnEventOptions } from '@nestjs/event-emitter/dist/interfaces';
import type { Listener, OnOptions } from 'eventemitter2';
import type { Document, Query } from 'mongoose'; import type { Document, Query } from 'mongoose';
import { type Socket } from 'socket.io'; import { type Socket } from 'socket.io';
@ -33,9 +31,9 @@ import type {
} from '@/nlp/schemas/nlp-entity.schema'; } from '@/nlp/schemas/nlp-entity.schema';
import { type NlpSampleEntity } from '@/nlp/schemas/nlp-sample-entity.schema'; import { type NlpSampleEntity } from '@/nlp/schemas/nlp-sample-entity.schema';
import { type NlpSample } from '@/nlp/schemas/nlp-sample.schema'; import { type NlpSample } from '@/nlp/schemas/nlp-sample.schema';
import { import type {
NlpValue,
NlpValueDocument, NlpValueDocument,
type NlpValue,
} from '@/nlp/schemas/nlp-value.schema'; } from '@/nlp/schemas/nlp-value.schema';
import { type Setting } from '@/setting/schemas/setting.schema'; import { type Setting } from '@/setting/schemas/setting.schema';
import { type Invitation } from '@/user/schemas/invitation.schema'; import { type Invitation } from '@/user/schemas/invitation.schema';
@ -44,7 +42,10 @@ import { type Permission } from '@/user/schemas/permission.schema';
import { type Role } from '@/user/schemas/role.schema'; import { type Role } from '@/user/schemas/role.schema';
import { type User } from '@/user/schemas/user.schema'; import { type User } from '@/user/schemas/user.schema';
import { EHook, type DeleteResult } from '@/utils/generics/base-repository'; import { EHook, type DeleteResult } from '@/utils/generics/base-repository';
import { TFilterQuery, THydratedDocument } from '@/utils/types/filter.types'; import type {
TFilterQuery,
THydratedDocument,
} from '@/utils/types/filter.types';
import '@nestjs/event-emitter'; import '@nestjs/event-emitter';
/** /**
@ -301,13 +302,17 @@ declare module '@nestjs/event-emitter' {
: false; : false;
type TCustomEvents<G extends keyof IHookEntityOperationMap> = type TCustomEvents<G extends keyof IHookEntityOperationMap> =
keyof IHookEntityOperationMap[G]['operations'] & string; keyof IHookEntityOperationMap[G]['operations'];
type TNormalizedOrCustomized<G> = G extends IHookEntities
? TNormalizedEvents | TCustomEvents<G>
: TCustomEvents<G>;
type customEvent<G extends EventNamespaces | ConstrainedString> = type customEvent<G extends EventNamespaces | ConstrainedString> =
G extends EventNamespaces G extends EventNamespaces
? G extends `hook:${string}` ? G extends `hook:${string}`
? G ? G
: `hook:${G}:${TNormalizedEvents | TCustomEvents<G>}` : `hook:${G}:${TNormalizedOrCustomized<G>}`
: never; : never;
interface ListenerFn<G extends EventNamespaces | ConstrainedString> { interface ListenerFn<G extends EventNamespaces | ConstrainedString> {