Remove versions from logicFunction (#17540)
## Summary - Remove `latestVersion` and `publishedVersions` columns from `LogicFunction` entity - Remove version parameter from logic function execution, build, and source code retrieval - Update all related services, DTOs, utilities, and tests - Add database migration to drop the version columns
This commit is contained in:
-7
@@ -19,11 +19,4 @@ export class ExecuteLogicFunctionInput {
|
||||
})
|
||||
@IsObject()
|
||||
payload: JSON;
|
||||
|
||||
@Field(() => String, {
|
||||
nullable: false,
|
||||
description: 'Version of the logic function to execute',
|
||||
defaultValue: 'latest',
|
||||
})
|
||||
version: string;
|
||||
}
|
||||
|
||||
+1
-8
@@ -1,4 +1,4 @@
|
||||
import { Field, ID, InputType } from '@nestjs/graphql';
|
||||
import { ID, InputType } from '@nestjs/graphql';
|
||||
|
||||
import { IDField } from '@ptc-org/nestjs-query-graphql';
|
||||
|
||||
@@ -6,11 +6,4 @@ import { IDField } from '@ptc-org/nestjs-query-graphql';
|
||||
export class GetLogicFunctionSourceCodeInput {
|
||||
@IDField(() => ID, { description: 'The id of the function.' })
|
||||
id!: string;
|
||||
|
||||
@Field(() => String, {
|
||||
nullable: false,
|
||||
description: 'The version of the function',
|
||||
defaultValue: 'draft',
|
||||
})
|
||||
version: string;
|
||||
}
|
||||
|
||||
-9
@@ -6,7 +6,6 @@ import {
|
||||
QueryOptions,
|
||||
} from '@ptc-org/nestjs-query-graphql';
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
IsDateString,
|
||||
IsNotEmpty,
|
||||
@@ -59,10 +58,6 @@ export class LogicFunctionDTO {
|
||||
@Field()
|
||||
timeoutSeconds: number;
|
||||
|
||||
@IsString()
|
||||
@Field({ nullable: true })
|
||||
latestVersion?: string;
|
||||
|
||||
@IsString()
|
||||
@Field()
|
||||
sourceHandlerPath: string;
|
||||
@@ -75,10 +70,6 @@ export class LogicFunctionDTO {
|
||||
@Field()
|
||||
handlerName: string;
|
||||
|
||||
@IsArray()
|
||||
@Field(() => [String], { nullable: false })
|
||||
publishedVersions: string[];
|
||||
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
@Field(() => graphqlTypeJson, { nullable: true })
|
||||
|
||||
-1
@@ -27,7 +27,6 @@ export class LogicFunctionTriggerJob {
|
||||
id: logicFunctionPayload.logicFunctionId,
|
||||
workspaceId: logicFunctionPayload.workspaceId,
|
||||
payload: logicFunctionPayload.payload || {},
|
||||
version: 'draft',
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
-6
@@ -69,12 +69,6 @@ export class LogicFunctionEntity
|
||||
@Column({ nullable: true, type: 'varchar' })
|
||||
description: string | null;
|
||||
|
||||
@Column({ nullable: true, type: 'varchar' })
|
||||
latestVersion: string | null;
|
||||
|
||||
@Column({ nullable: false, type: 'jsonb', default: [] })
|
||||
publishedVersions: JsonbProperty<string[]>;
|
||||
|
||||
@Column({ nullable: false, default: LogicFunctionRuntime.NODE22 })
|
||||
runtime: LogicFunctionRuntime;
|
||||
|
||||
|
||||
-3
@@ -6,7 +6,6 @@ import { CustomException } from 'src/utils/custom-exception';
|
||||
|
||||
export enum LogicFunctionExceptionCode {
|
||||
LOGIC_FUNCTION_NOT_FOUND = 'LOGIC_FUNCTION_NOT_FOUND',
|
||||
LOGIC_FUNCTION_VERSION_NOT_FOUND = 'LOGIC_FUNCTION_VERSION_NOT_FOUND',
|
||||
LOGIC_FUNCTION_ALREADY_EXIST = 'LOGIC_FUNCTION_ALREADY_EXIST',
|
||||
LOGIC_FUNCTION_NOT_READY = 'LOGIC_FUNCTION_NOT_READY',
|
||||
LOGIC_FUNCTION_BUILDING = 'LOGIC_FUNCTION_BUILDING',
|
||||
@@ -23,8 +22,6 @@ const getLogicFunctionExceptionUserFriendlyMessage = (
|
||||
switch (code) {
|
||||
case LogicFunctionExceptionCode.LOGIC_FUNCTION_NOT_FOUND:
|
||||
return msg`Function not found.`;
|
||||
case LogicFunctionExceptionCode.LOGIC_FUNCTION_VERSION_NOT_FOUND:
|
||||
return msg`Function version not found.`;
|
||||
case LogicFunctionExceptionCode.LOGIC_FUNCTION_ALREADY_EXIST:
|
||||
return msg`A function with this name already exists.`;
|
||||
case LogicFunctionExceptionCode.LOGIC_FUNCTION_NOT_READY:
|
||||
|
||||
+1
-3
@@ -120,7 +120,6 @@ export class LogicFunctionResolver {
|
||||
return await this.logicFunctionService.getLogicFunctionSourceCode(
|
||||
workspaceId,
|
||||
input.id,
|
||||
input.version,
|
||||
);
|
||||
} catch (error) {
|
||||
return logicFunctionGraphQLApiExceptionHandler(error);
|
||||
@@ -199,13 +198,12 @@ export class LogicFunctionResolver {
|
||||
@AuthWorkspace() { id: workspaceId }: WorkspaceEntity,
|
||||
) {
|
||||
try {
|
||||
const { id, payload, version } = input;
|
||||
const { id, payload } = input;
|
||||
|
||||
return await this.logicFunctionService.executeOneLogicFunction({
|
||||
id,
|
||||
workspaceId,
|
||||
payload,
|
||||
version,
|
||||
});
|
||||
} catch (error) {
|
||||
return logicFunctionGraphQLApiExceptionHandler(error);
|
||||
|
||||
+2
-198
@@ -1,14 +1,12 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import deepEqual from 'deep-equal';
|
||||
import {
|
||||
DEFAULT_API_KEY_NAME,
|
||||
DEFAULT_API_URL_NAME,
|
||||
} from 'twenty-shared/application';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { Repository } from 'typeorm';
|
||||
import { FileFolder } from 'twenty-shared/types';
|
||||
|
||||
import { FileStorageExceptionCode } from 'src/engine/core-modules/file-storage/interfaces/file-storage-exception';
|
||||
import { type LogicFunctionExecuteResult } from 'src/engine/core-modules/logic-function-executor/drivers/interfaces/logic-function-executor-driver.interface';
|
||||
@@ -26,7 +24,6 @@ import { ThrottlerService } from 'src/engine/core-modules/throttler/throttler.se
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
import { WorkspaceManyOrAllFlatEntityMapsCacheService } from 'src/engine/metadata-modules/flat-entity/services/workspace-many-or-all-flat-entity-maps-cache.service';
|
||||
import { findFlatEntityByIdInFlatEntityMapsOrThrow } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-id-in-flat-entity-maps-or-throw.util';
|
||||
import { findFlatEntityByIdInFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-id-in-flat-entity-maps.util';
|
||||
import { LogicFunctionLayerService } from 'src/engine/metadata-modules/logic-function-layer/logic-function-layer.service';
|
||||
import { CreateLogicFunctionInput } from 'src/engine/metadata-modules/logic-function/dtos/create-logic-function.input';
|
||||
import { type UpdateLogicFunctionInput } from 'src/engine/metadata-modules/logic-function/dtos/update-logic-function.input';
|
||||
@@ -44,10 +41,6 @@ import { SubscriptionService } from 'src/engine/subscriptions/subscription.servi
|
||||
import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
|
||||
import { WorkspaceMigrationBuilderException } from 'src/engine/workspace-manager/workspace-migration/exceptions/workspace-migration-builder-exception';
|
||||
import { WorkspaceMigrationValidateBuildAndRunService } from 'src/engine/workspace-manager/workspace-migration/services/workspace-migration-validate-build-and-run-service';
|
||||
import {
|
||||
WorkflowVersionStepException,
|
||||
WorkflowVersionStepExceptionCode,
|
||||
} from 'src/modules/workflow/common/exceptions/workflow-version-step.exception';
|
||||
import { cleanServerUrl } from 'src/utils/clean-server-url';
|
||||
import { FunctionBuildService } from 'src/engine/metadata-modules/function-build/function-build.service';
|
||||
|
||||
@@ -74,35 +67,7 @@ export class LogicFunctionService {
|
||||
private readonly secretEncryptionService: SecretEncryptionService,
|
||||
) {}
|
||||
|
||||
async hasLogicFunctionPublishedVersion(
|
||||
logicFunctionId: string,
|
||||
workspaceId: string,
|
||||
) {
|
||||
const { flatLogicFunctionMaps } =
|
||||
await this.flatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps(
|
||||
{
|
||||
workspaceId,
|
||||
flatMapsKeys: ['flatLogicFunctionMaps'],
|
||||
},
|
||||
);
|
||||
|
||||
const flatLogicFunction = findFlatEntityByIdInFlatEntityMaps({
|
||||
flatEntityId: logicFunctionId,
|
||||
flatEntityMaps: flatLogicFunctionMaps,
|
||||
});
|
||||
|
||||
return (
|
||||
isDefined(flatLogicFunction) &&
|
||||
!isDefined(flatLogicFunction.deletedAt) &&
|
||||
isDefined(flatLogicFunction.latestVersion)
|
||||
);
|
||||
}
|
||||
|
||||
async getLogicFunctionSourceCode(
|
||||
workspaceId: string,
|
||||
id: string,
|
||||
version: string,
|
||||
) {
|
||||
async getLogicFunctionSourceCode(workspaceId: string, id: string) {
|
||||
const { flatLogicFunctionMaps } =
|
||||
await this.flatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps(
|
||||
{
|
||||
@@ -119,7 +84,6 @@ export class LogicFunctionService {
|
||||
try {
|
||||
const folderPath = getLogicFunctionFolderOrThrow({
|
||||
flatLogicFunction,
|
||||
version,
|
||||
});
|
||||
|
||||
return await this.fileStorageService.readFolder(folderPath);
|
||||
@@ -135,12 +99,10 @@ export class LogicFunctionService {
|
||||
id,
|
||||
workspaceId,
|
||||
payload,
|
||||
version = 'latest',
|
||||
}: {
|
||||
id: string;
|
||||
workspaceId: string;
|
||||
payload: object;
|
||||
version?: string;
|
||||
}): Promise<LogicFunctionExecuteResult> {
|
||||
await this.throttleExecution(workspaceId);
|
||||
|
||||
@@ -208,12 +170,10 @@ export class LogicFunctionService {
|
||||
if (
|
||||
!(await this.functionBuildService.isBuilt({
|
||||
flatLogicFunction,
|
||||
version,
|
||||
}))
|
||||
) {
|
||||
await this.functionBuildService.buildAndUpload({
|
||||
flatLogicFunction,
|
||||
version,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -223,7 +183,6 @@ export class LogicFunctionService {
|
||||
flatLogicFunction,
|
||||
flatLogicFunctionLayer,
|
||||
payload,
|
||||
version,
|
||||
env: envVariables,
|
||||
}),
|
||||
timeoutMs: flatLogicFunction.timeoutSeconds * 1000,
|
||||
@@ -290,116 +249,7 @@ export class LogicFunctionService {
|
||||
flatLogicFunctionMaps,
|
||||
});
|
||||
|
||||
if (isDefined(existingFlatLogicFunction.latestVersion)) {
|
||||
const latestCode = await this.getLogicFunctionSourceCode(
|
||||
workspaceId,
|
||||
id,
|
||||
'latest',
|
||||
);
|
||||
const draftCode = await this.getLogicFunctionSourceCode(
|
||||
workspaceId,
|
||||
id,
|
||||
'draft',
|
||||
);
|
||||
|
||||
if (deepEqual(latestCode, draftCode)) {
|
||||
return existingFlatLogicFunction;
|
||||
}
|
||||
}
|
||||
|
||||
const newVersion = existingFlatLogicFunction.latestVersion
|
||||
? `${parseInt(existingFlatLogicFunction.latestVersion, 10) + 1}`
|
||||
: '1';
|
||||
|
||||
const draftSourceFolderPath = getLogicFunctionFolderOrThrow({
|
||||
flatLogicFunction: existingFlatLogicFunction,
|
||||
version: 'draft',
|
||||
fileFolder: FileFolder.LogicFunction,
|
||||
});
|
||||
|
||||
const newSourceFolderPath = getLogicFunctionFolderOrThrow({
|
||||
flatLogicFunction: existingFlatLogicFunction,
|
||||
version: newVersion,
|
||||
fileFolder: FileFolder.LogicFunction,
|
||||
});
|
||||
|
||||
await this.fileStorageService.copy({
|
||||
from: { folderPath: draftSourceFolderPath },
|
||||
to: { folderPath: newSourceFolderPath },
|
||||
});
|
||||
|
||||
const draftBuiltFolderPath = getLogicFunctionFolderOrThrow({
|
||||
flatLogicFunction: existingFlatLogicFunction,
|
||||
version: 'draft',
|
||||
fileFolder: FileFolder.BuiltFunction,
|
||||
});
|
||||
|
||||
const newBuiltFolderPath = getLogicFunctionFolderOrThrow({
|
||||
flatLogicFunction: existingFlatLogicFunction,
|
||||
version: newVersion,
|
||||
fileFolder: FileFolder.BuiltFunction,
|
||||
});
|
||||
|
||||
await this.fileStorageService.copy({
|
||||
from: { folderPath: draftBuiltFolderPath },
|
||||
to: { folderPath: newBuiltFolderPath },
|
||||
});
|
||||
|
||||
const newPublishedVersions = [
|
||||
...existingFlatLogicFunction.publishedVersions,
|
||||
newVersion,
|
||||
];
|
||||
|
||||
const updatedFlatLogicFunction: FlatLogicFunction = {
|
||||
...existingFlatLogicFunction,
|
||||
latestVersion: newVersion,
|
||||
publishedVersions: newPublishedVersions,
|
||||
};
|
||||
|
||||
const validateAndBuildResult =
|
||||
await this.workspaceMigrationValidateBuildAndRunService.validateBuildAndRunWorkspaceMigration(
|
||||
{
|
||||
allFlatEntityOperationByMetadataName: {
|
||||
logicFunction: {
|
||||
flatEntityToCreate: [],
|
||||
flatEntityToDelete: [],
|
||||
flatEntityToUpdate: [updatedFlatLogicFunction],
|
||||
},
|
||||
},
|
||||
workspaceId,
|
||||
isSystemBuild: false,
|
||||
},
|
||||
);
|
||||
|
||||
if (isDefined(validateAndBuildResult)) {
|
||||
throw new WorkspaceMigrationBuilderException(
|
||||
validateAndBuildResult,
|
||||
'Multiple validation errors occurred while publishing logic function',
|
||||
);
|
||||
}
|
||||
|
||||
const { flatLogicFunctionMaps: recomputedFlatLogicFunctionMaps } =
|
||||
await this.flatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps(
|
||||
{
|
||||
workspaceId,
|
||||
flatMapsKeys: ['flatLogicFunctionMaps'],
|
||||
},
|
||||
);
|
||||
|
||||
const publishedFlatLogicFunction =
|
||||
findFlatEntityByIdInFlatEntityMapsOrThrow({
|
||||
flatEntityId: id,
|
||||
flatEntityMaps: recomputedFlatLogicFunctionMaps,
|
||||
});
|
||||
|
||||
if (!isDefined(publishedFlatLogicFunction.latestVersion)) {
|
||||
throw new WorkflowVersionStepException(
|
||||
`Fail to publish logicFunction ${publishedFlatLogicFunction.id}.Received latest version ${publishedFlatLogicFunction.latestVersion}`,
|
||||
WorkflowVersionStepExceptionCode.CODE_STEP_FAILURE,
|
||||
);
|
||||
}
|
||||
|
||||
return publishedFlatLogicFunction;
|
||||
return existingFlatLogicFunction;
|
||||
}
|
||||
|
||||
async deleteOneLogicFunction({
|
||||
@@ -700,55 +550,11 @@ export class LogicFunctionService {
|
||||
});
|
||||
}
|
||||
|
||||
async createDraftFromPublishedVersion({
|
||||
id,
|
||||
version,
|
||||
workspaceId,
|
||||
}: {
|
||||
id: string;
|
||||
version: string;
|
||||
workspaceId: string;
|
||||
}) {
|
||||
if (version === 'draft') {
|
||||
return;
|
||||
}
|
||||
|
||||
const { flatLogicFunctionMaps } =
|
||||
await this.flatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps(
|
||||
{
|
||||
workspaceId,
|
||||
flatMapsKeys: ['flatLogicFunctionMaps'],
|
||||
},
|
||||
);
|
||||
|
||||
const flatLogicFunction = findFlatLogicFunctionOrThrow({
|
||||
id,
|
||||
flatLogicFunctionMaps,
|
||||
});
|
||||
|
||||
await this.fileStorageService.copy({
|
||||
from: {
|
||||
folderPath: getLogicFunctionFolderOrThrow({
|
||||
flatLogicFunction,
|
||||
version,
|
||||
}),
|
||||
},
|
||||
to: {
|
||||
folderPath: getLogicFunctionFolderOrThrow({
|
||||
flatLogicFunction,
|
||||
version: 'draft',
|
||||
}),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async duplicateLogicFunction({
|
||||
id,
|
||||
version,
|
||||
workspaceId,
|
||||
}: {
|
||||
id: string;
|
||||
version: string;
|
||||
workspaceId: string;
|
||||
}): Promise<FlatLogicFunction> {
|
||||
const { flatLogicFunctionMaps } =
|
||||
@@ -779,13 +585,11 @@ export class LogicFunctionService {
|
||||
from: {
|
||||
folderPath: getLogicFunctionFolderOrThrow({
|
||||
flatLogicFunction: flatLogicFunctionToDuplicate,
|
||||
version,
|
||||
}),
|
||||
},
|
||||
to: {
|
||||
folderPath: getLogicFunctionFolderOrThrow({
|
||||
flatLogicFunction: newFlatLogicFunction,
|
||||
version: 'draft',
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
-2
@@ -48,8 +48,6 @@ export const fromCreateLogicFunctionInputToFlatLogicFunction = ({
|
||||
createdAt: currentDate.toISOString(),
|
||||
updatedAt: currentDate.toISOString(),
|
||||
deletedAt: null,
|
||||
latestVersion: null,
|
||||
publishedVersions: [],
|
||||
applicationId: workspaceCustomApplicationId,
|
||||
runtime: LogicFunctionRuntime.NODE22,
|
||||
timeoutSeconds: rawCreateLogicFunctionInput.timeoutSeconds ?? 300,
|
||||
|
||||
-2
@@ -12,11 +12,9 @@ export const fromFlatLogicFunctionToLogicFunctionDto = ({
|
||||
description: flatLogicFunction.description ?? undefined,
|
||||
runtime: flatLogicFunction.runtime,
|
||||
timeoutSeconds: flatLogicFunction.timeoutSeconds,
|
||||
latestVersion: flatLogicFunction.latestVersion ?? undefined,
|
||||
sourceHandlerPath: flatLogicFunction.sourceHandlerPath,
|
||||
builtHandlerPath: flatLogicFunction.builtHandlerPath,
|
||||
handlerName: flatLogicFunction.handlerName,
|
||||
publishedVersions: flatLogicFunction.publishedVersions,
|
||||
toolInputSchema: flatLogicFunction.toolInputSchema ?? undefined,
|
||||
isTool: flatLogicFunction.isTool,
|
||||
applicationId: flatLogicFunction.applicationId ?? undefined,
|
||||
|
||||
-1
@@ -16,7 +16,6 @@ export const logicFunctionGraphQLApiExceptionHandler = (error: any) => {
|
||||
if (error instanceof LogicFunctionException) {
|
||||
switch (error.code) {
|
||||
case LogicFunctionExceptionCode.LOGIC_FUNCTION_NOT_FOUND:
|
||||
case LogicFunctionExceptionCode.LOGIC_FUNCTION_VERSION_NOT_FOUND:
|
||||
throw new NotFoundError(error);
|
||||
case LogicFunctionExceptionCode.LOGIC_FUNCTION_ALREADY_EXIST:
|
||||
throw new ConflictError(error);
|
||||
|
||||
Reference in New Issue
Block a user