Skip to content
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

Closed
wants to merge 3 commits into from
Closed

Conversation

charlesBochet
Copy link
Member

@charlesBochet charlesBochet commented Jan 23, 2025

Follow up on #9719

@charlesBochet charlesBochet changed the title Test type batch event Improve typing on Database Events Jan 23, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 from ObjectRecordBaseEvent instead of ObjectRecordCreateEvent in /packages/twenty-server/src/engine/core-modules/event-emitter/types/object-record-restore.event.ts
  • Added generic type parameter <T = object> to ObjectRecordNonDestructiveEvent 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 and getLinkedTimelineActivities still use untyped ObjectRecordBaseEvent

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>,
Copy link
Member

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>
Copy link
Member

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> =
Copy link
Member

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> {
Copy link
Member

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

@charlesBochet
Copy link
Member Author

Got all the comments! closing the PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants