-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve typing on Database Events #9819
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR enhances type safety across the event handling system by introducing generic type parameters and modifying event inheritance structures.
- Changed
ObjectRecordRestoreEvent
to inherit fromObjectRecordBaseEvent
instead ofObjectRecordCreateEvent
in/packages/twenty-server/src/engine/core-modules/event-emitter/types/object-record-restore.event.ts
- Added generic type parameter
<T = object>
toObjectRecordNonDestructiveEvent
in/packages/twenty-server/src/engine/core-modules/event-emitter/types/object-record-non-destructive-event.ts
- Introduced
TimelineActivityWorkspaceEntity
type safety in/packages/twenty-server/src/modules/timeline/jobs/upsert-timeline-activity-from-internal-event.job.ts
- Inconsistent type usage in
TimelineActivityService
methods needs addressing -transformEventToTimelineActivities
andgetLinkedTimelineActivities
still use untypedObjectRecordBaseEvent
4 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile
@@ -7,7 +7,10 @@ import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/work | |||
import { TimelineActivityRepository } from 'src/modules/timeline/repositiories/timeline-activity.repository'; | |||
import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity'; | |||
|
|||
type TimelineActivity = Omit<ObjectRecordNonDestructiveEvent, 'properties'> & { | |||
type TimelineActivity = Omit< | |||
ObjectRecordNonDestructiveEvent<TimelineActivityWorkspaceEntity>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The event itself is not about a timeline activity, there's a confusion
@@ -18,7 +19,9 @@ export class UpsertTimelineActivityFromInternalEvent { | |||
|
|||
@Process(UpsertTimelineActivityFromInternalEvent.name) | |||
async handle( | |||
workspaceEventBatch: WorkspaceEventBatch<ObjectRecordNonDestructiveEvent>, | |||
workspaceEventBatch: WorkspaceEventBatch< | |||
ObjectRecordNonDestructiveEvent<TimelineActivityWorkspaceEntity> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment
| ObjectRecordUpdateEvent | ||
| ObjectRecordDeleteEvent | ||
| ObjectRecordRestoreEvent; | ||
export type ObjectRecordNonDestructiveEvent<T = object> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I didn't add it because it wasn't needed)
|
||
export class ObjectRecordRestoreEvent< | ||
T = object, | ||
> extends ObjectRecordCreateEvent<T> { | ||
> extends ObjectRecordBaseEvent<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was enforced on purpose because from an API perspective I think the RestoreEvent should always have the properties that the create event has, because people don't want to implemented two different hooks with different logics. I think adding it creates a protection and if there's a need to remove it then it will raise the point
Got all the comments! closing the PR :) |
Follow up on #9719