Function trigger updates 2 (#16608)
- Improves route trigger job performances - expose function params types ## Before <img width="938" height="271" alt="image" src="https://github.com/user-attachments/assets/5752ba64-f31d-44ed-974d-536e63458f2c" /> ## After <img width="1000" height="559" alt="image" src="https://github.com/user-attachments/assets/b1f4927a-5f43-49f0-a606-244c72356772" />
This commit is contained in:
+2
-1
@@ -1,9 +1,10 @@
|
||||
import { type ObjectRecordEvent } from 'twenty-shared/database-events';
|
||||
|
||||
import { AuditService } from 'src/engine/core-modules/audit/services/audit.service';
|
||||
import { OBJECT_RECORD_CREATED_EVENT } from 'src/engine/core-modules/audit/utils/events/object-event/object-record-created';
|
||||
import { OBJECT_RECORD_DELETED_EVENT } from 'src/engine/core-modules/audit/utils/events/object-event/object-record-delete';
|
||||
import { OBJECT_RECORD_UPDATED_EVENT } from 'src/engine/core-modules/audit/utils/events/object-event/object-record-updated';
|
||||
import { OBJECT_RECORD_UPSERTED_EVENT } from 'src/engine/core-modules/audit/utils/events/object-event/object-record-upserted';
|
||||
import { type ObjectRecordEvent } from 'src/engine/core-modules/event-emitter/types/object-record-event.event';
|
||||
import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator';
|
||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
|
||||
+2
-1
@@ -2,13 +2,14 @@
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { type ObjectRecordCreateEvent } from 'twenty-shared/database-events';
|
||||
|
||||
import { OnDatabaseBatchEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-batch-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
import {
|
||||
UpdateSubscriptionQuantityJob,
|
||||
type UpdateSubscriptionQuantityJobData,
|
||||
} from 'src/engine/core-modules/billing/jobs/update-subscription-quantity.job';
|
||||
import { type ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/core-modules/event-emitter/types/object-record.base.event';
|
||||
|
||||
export class ObjectRecordCreateEvent<
|
||||
T = object,
|
||||
> extends ObjectRecordBaseEvent<T> {
|
||||
properties: {
|
||||
after: T;
|
||||
};
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/core-modules/event-emitter/types/object-record.base.event';
|
||||
|
||||
export class ObjectRecordDeleteEvent<
|
||||
T = object,
|
||||
> extends ObjectRecordBaseEvent<T> {
|
||||
properties: {
|
||||
before: T;
|
||||
};
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/core-modules/event-emitter/types/object-record.base.event';
|
||||
|
||||
export class ObjectRecordDestroyEvent<
|
||||
T = object,
|
||||
> extends ObjectRecordBaseEvent<T> {
|
||||
properties: {
|
||||
before: T;
|
||||
};
|
||||
}
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
export type ObjectRecordDiff<T> = {
|
||||
[K in keyof T]: { before: T[K]; after: T[K] };
|
||||
};
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
import { type ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { type ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
import { type ObjectRecordDestroyEvent } from 'src/engine/core-modules/event-emitter/types/object-record-destroy.event';
|
||||
import { type ObjectRecordRestoreEvent } from 'src/engine/core-modules/event-emitter/types/object-record-restore.event';
|
||||
import { type ObjectRecordUpdateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-update.event';
|
||||
import { type ObjectRecordUpsertEvent } from 'src/engine/core-modules/event-emitter/types/object-record-upsert.event';
|
||||
|
||||
export type ObjectRecordEvent<T = object> =
|
||||
| ObjectRecordUpdateEvent<T>
|
||||
| ObjectRecordDeleteEvent<T>
|
||||
| ObjectRecordCreateEvent<T>
|
||||
| ObjectRecordDestroyEvent<T>
|
||||
| ObjectRecordRestoreEvent<T>
|
||||
| ObjectRecordUpsertEvent<T>;
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
import { type ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { type ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
import { type ObjectRecordRestoreEvent } from 'src/engine/core-modules/event-emitter/types/object-record-restore.event';
|
||||
import { type ObjectRecordUpdateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-update.event';
|
||||
import { type ObjectRecordUpsertEvent } from 'src/engine/core-modules/event-emitter/types/object-record-upsert.event';
|
||||
|
||||
export type ObjectRecordNonDestructiveEvent =
|
||||
| ObjectRecordCreateEvent
|
||||
| ObjectRecordUpdateEvent
|
||||
| ObjectRecordDeleteEvent
|
||||
| ObjectRecordRestoreEvent
|
||||
| ObjectRecordUpsertEvent;
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
import { ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
|
||||
export class ObjectRecordRestoreEvent<
|
||||
T = object,
|
||||
> extends ObjectRecordCreateEvent<T> {
|
||||
properties: {
|
||||
after: T;
|
||||
};
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
import { type ObjectRecordDiff } from 'src/engine/core-modules/event-emitter/types/object-record-diff';
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/core-modules/event-emitter/types/object-record.base.event';
|
||||
|
||||
export class ObjectRecordUpdateEvent<
|
||||
T = object,
|
||||
> extends ObjectRecordBaseEvent<T> {
|
||||
properties: {
|
||||
updatedFields?: string[];
|
||||
diff?: Partial<ObjectRecordDiff<T>>;
|
||||
before: T;
|
||||
after: T;
|
||||
};
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
import { type ObjectRecordDiff } from 'src/engine/core-modules/event-emitter/types/object-record-diff';
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/core-modules/event-emitter/types/object-record.base.event';
|
||||
|
||||
export class ObjectRecordUpsertEvent<
|
||||
T = object,
|
||||
> extends ObjectRecordBaseEvent<T> {
|
||||
properties: {
|
||||
before?: T;
|
||||
after: T;
|
||||
diff?: Partial<ObjectRecordDiff<T>>;
|
||||
updatedFields?: string[];
|
||||
};
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
import { type ObjectRecordDiff } from 'src/engine/core-modules/event-emitter/types/object-record-diff';
|
||||
|
||||
type Properties<T> = {
|
||||
updatedFields?: string[];
|
||||
before?: T;
|
||||
after?: T;
|
||||
diff?: Partial<ObjectRecordDiff<T>>;
|
||||
};
|
||||
|
||||
export class ObjectRecordBaseEvent<T = object> {
|
||||
recordId: string;
|
||||
userId?: string;
|
||||
workspaceMemberId?: string;
|
||||
properties: Properties<T>;
|
||||
}
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { type ObjectRecordDestroyEvent } from 'twenty-shared/database-events';
|
||||
|
||||
import { OnDatabaseBatchEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-batch-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
import { type ObjectRecordDestroyEvent } from 'src/engine/core-modules/event-emitter/types/object-record-destroy.event';
|
||||
import {
|
||||
FileDeletionJob,
|
||||
type FileDeletionJobData,
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { type ObjectRecordDestroyEvent } from 'twenty-shared/database-events';
|
||||
|
||||
import { OnDatabaseBatchEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-batch-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
import { type ObjectRecordDestroyEvent } from 'src/engine/core-modules/event-emitter/types/object-record-destroy.event';
|
||||
import {
|
||||
FileDeletionJob,
|
||||
type FileDeletionJobData,
|
||||
|
||||
+2
-1
@@ -2,6 +2,8 @@ import { Logger } from '@nestjs/common';
|
||||
|
||||
import chunk from 'lodash.chunk';
|
||||
|
||||
import type { ObjectRecordEvent } from 'twenty-shared/database-events';
|
||||
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator';
|
||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||
@@ -13,7 +15,6 @@ import {
|
||||
} from 'src/engine/core-modules/webhook/jobs/call-webhook.job';
|
||||
import { WebhookService } from 'src/engine/core-modules/webhook/webhook.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import type { ObjectRecordEvent } from 'src/engine/core-modules/event-emitter/types/object-record-event.event';
|
||||
import { transformEventBatchToWebhookEvents } from 'src/engine/core-modules/webhook/utils/transform-event-batch-to-webhook-events';
|
||||
|
||||
const WEBHOOK_JOBS_CHUNK_SIZE = 20;
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
import type { ObjectRecordEvent } from 'twenty-shared/database-events';
|
||||
|
||||
import { type WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import type { ObjectRecordEvent } from 'src/engine/core-modules/event-emitter/types/object-record-event.event';
|
||||
import type { WebhookEntity } from 'src/engine/core-modules/webhook/webhook.entity';
|
||||
import { transformEventBatchToWebhookEvents } from 'src/engine/core-modules/webhook/utils/transform-event-batch-to-webhook-events';
|
||||
import { type FlatObjectMetadata } from 'src/engine/metadata-modules/flat-object-metadata/types/flat-object-metadata.type';
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
import type { ObjectRecordEvent } from 'twenty-shared/database-events';
|
||||
|
||||
import { transformEventToWebhookEvent } from 'src/engine/core-modules/webhook/utils/transform-event-to-webhook-event';
|
||||
import type { ObjectRecordEvent } from 'src/engine/core-modules/event-emitter/types/object-record-event.event';
|
||||
|
||||
describe('transformEventToWebhookEvent', () => {
|
||||
it('should transform event to webhook event', () => {
|
||||
|
||||
+2
-1
@@ -1,7 +1,8 @@
|
||||
import type { ObjectRecordEvent } from 'twenty-shared/database-events';
|
||||
|
||||
import { type WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import { type CallWebhookJobData } from 'src/engine/core-modules/webhook/jobs/call-webhook.job';
|
||||
import { type WebhookEntity } from 'src/engine/core-modules/webhook/webhook.entity';
|
||||
import type { ObjectRecordEvent } from 'src/engine/core-modules/event-emitter/types/object-record-event.event';
|
||||
import { transformEventToWebhookEvent } from 'src/engine/core-modules/webhook/utils/transform-event-to-webhook-event';
|
||||
|
||||
export const transformEventBatchToWebhookEvents = ({
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import type { ObjectRecordEvent } from 'src/engine/core-modules/event-emitter/types/object-record-event.event';
|
||||
import type { ObjectRecordEvent } from 'twenty-shared/database-events';
|
||||
|
||||
import { removeSecretFromWebhookRecord } from 'src/utils/remove-secret-from-webhook-record';
|
||||
|
||||
export const transformEventToWebhookEvent = ({
|
||||
|
||||
Reference in New Issue
Block a user