Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

3.0 KB
Raw Blame
import { PauseType, Project } from '@activepieces/shared'
import { EntitySchema } from 'typeorm'
import { ApIdSchema, BaseColumnSchemaPart } from '../database/database-common'
import { Waitpoint, WaitpointStatus, WaitpointVersionEnum } from './waitpoint-types'

type WaitpointSchema = Waitpoint & {
    project: Project
}

export const WaitpointEntity = new EntitySchema<WaitpointSchema>({
    name: 'waitpoint',
    columns: {
        ...BaseColumnSchemaPart,
        flowRunId: {
            ...ApIdSchema,
            nullable: false,
        },
        projectId: {
            ...ApIdSchema,
            nullable: false,
        },
        type: {
            type: String,
            nullable: false,
            enum: PauseType,
        },
        status: {
            type: String,
            nullable: false,
            enum: WaitpointStatus,
        },
        resumeDateTime: {
            type: 'timestamp with time zone',
            nullable: true,
        },
        responseToSend: {
            type: 'jsonb',
            nullable: true,
        },
        workerHandlerId: {
            type: String,
            nullable: true,
        },
        httpRequestId: {
            type: String,
            nullable: true,
        },
        version: {
            type: String,
            nullable: false,
            default: 'V0',
            enum: WaitpointVersionEnum,
        },
        stepName: {
            type: String,
            nullable: false,
            default: '',
        },
        resumePayload: {
            type: 'jsonb',
            nullable: true,
        },
        sealed: {
            type: Boolean,
            nullable: false,
            default: false,
        },
        policy: {
            type: 'jsonb',
            nullable: true,
        },
        deadLetteredAt: {
            type: 'timestamp with time zone',
            nullable: true,
        },
    },
    indices: [
        {
            name: 'idx_waitpoint_flow_run_id_step_name',
            columns: ['flowRunId', 'stepName'],
            unique: true,
        },
        {
            name: 'idx_waitpoint_project_id',
            columns: ['projectId'],
        },
        {
            name: 'idx_waitpoint_flow_run_id_status_created',
            columns: ['flowRunId', 'status', 'created'],
        },
        {
            name: 'idx_waitpoint_live_deadline',
            columns: ['resumeDateTime', 'id'],
            where: '"status" = \'PENDING\' AND "resumeDateTime" IS NOT NULL AND "deadLetteredAt" IS NULL',
        },
        {
            name: 'idx_waitpoint_undelivered_barrier',
            columns: ['updated', 'id'],
            where: '"type" = \'BARRIER\' AND "status" = \'COMPLETED\'',
        },
    ],
    relations: {
        project: {
            type: 'many-to-one',
            target: 'project',
            cascade: true,
            onDelete: 'CASCADE',
            joinColumn: {
                name: 'projectId',
                foreignKeyConstraintName: 'fk_waitpoint_project_id',
            },
        },
    },
})