Files
twenty/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto.ts
T
Charles Bochet a4499d21bb Migrate cron, databaseEventTrigger, httpRoute triggers to serverless functions (#17488)
## Summary

Migrates trigger entities (`CronTriggerEntity`,
`DatabaseEventTriggerEntity`, `RouteTriggerEntity`) into
`ServerlessFunctionEntity` by storing trigger settings as JSONB columns
directly on the serverless function. This simplifies the architecture
since these relationships were effectively one-to-one.

## Changes

### Schema Changes
- Added three new nullable JSONB columns to `ServerlessFunctionEntity`:
  - `cronTriggerSettings` - stores cron pattern
- `databaseEventTriggerSettings` - stores event name and updated fields
filter
- `httpRouteTriggerSettings` - stores path, HTTP method, auth
requirements, and forwarded headers

### Core Logic Updates
- `CronTriggerCronJob` - now queries `ServerlessFunctionEntity` directly
instead of `CronTriggerEntity`
- `CallDatabaseEventTriggerJobsJob` - now queries
`ServerlessFunctionEntity` directly
- `RouteTriggerService` - now queries `ServerlessFunctionEntity`
directly
- `ApplicationSyncService` - extracts trigger settings from manifest and
writes to serverless function
2026-01-27 20:54:09 +01:00

127 lines
2.4 KiB
TypeScript

import { Field, HideField, ObjectType } from '@nestjs/graphql';
import {
Authorize,
IDField,
QueryOptions,
} from '@ptc-org/nestjs-query-graphql';
import {
IsArray,
IsBoolean,
IsDateString,
IsNotEmpty,
IsNumber,
IsObject,
IsOptional,
IsString,
IsUUID,
} from 'class-validator';
import graphqlTypeJson from 'graphql-type-json';
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
import {
CronTriggerSettings,
DatabaseEventTriggerSettings,
HttpRouteTriggerSettings,
} from 'src/engine/metadata-modules/serverless-function/serverless-function.entity';
@ObjectType('ServerlessFunction')
@Authorize({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
authorize: (context: any) => ({
workspaceId: { eq: context?.req?.workspace?.id },
}),
})
@QueryOptions({
defaultResultSize: 10,
maxResultsSize: 1000,
})
export class ServerlessFunctionDTO {
@IsUUID()
@IsNotEmpty()
@IDField(() => UUIDScalarType)
id: string;
@IsString()
@Field()
name: string;
@IsString()
@Field({ nullable: true })
description?: string;
@IsString()
@IsNotEmpty()
@Field()
runtime: string;
@IsNumber()
@Field()
timeoutSeconds: number;
@IsString()
@Field({ nullable: true })
latestVersion?: string;
@IsString()
@Field()
sourceHandlerPath: string;
@IsString()
@Field()
builtHandlerPath: string;
@IsString()
@Field()
handlerName: string;
@IsArray()
@Field(() => [String], { nullable: false })
publishedVersions: string[];
@IsObject()
@IsOptional()
@Field(() => graphqlTypeJson, { nullable: true })
toolInputSchema?: object;
@IsBoolean()
@Field()
isTool: boolean;
@IsObject()
@IsOptional()
@Field(() => graphqlTypeJson, { nullable: true })
cronTriggerSettings?: CronTriggerSettings;
@IsObject()
@IsOptional()
@Field(() => graphqlTypeJson, { nullable: true })
databaseEventTriggerSettings?: DatabaseEventTriggerSettings;
@IsObject()
@IsOptional()
@Field(() => graphqlTypeJson, { nullable: true })
httpRouteTriggerSettings?: HttpRouteTriggerSettings;
@IsUUID()
@IsOptional()
@Field(() => UUIDScalarType, { nullable: true })
applicationId?: string;
@IsUUID()
@IsOptional()
@Field(() => UUIDScalarType, { nullable: true })
universalIdentifier?: string;
@HideField()
workspaceId: string;
@IsDateString()
@Field()
createdAt: Date;
@IsDateString()
@Field()
updatedAt: Date;
}