Thomas Trompette
2025-09-10 17:25:40 +02:00
committed by GitHub
parent bcf1bba302
commit 3bfb5bbd86
34 changed files with 642 additions and 118 deletions
@@ -10,4 +10,5 @@ export enum ServerlessFunctionExceptionCode {
SERVERLESS_FUNCTION_BUILDING = 'SERVERLESS_FUNCTION_BUILDING',
SERVERLESS_FUNCTION_CODE_UNCHANGED = 'SERVERLESS_FUNCTION_CODE_UNCHANGED',
SERVERLESS_FUNCTION_EXECUTION_LIMIT_REACHED = 'SERVERLESS_FUNCTION_EXECUTION_LIMIT_REACHED',
SERVERLESS_FUNCTION_CREATE_FAILED = 'SERVERLESS_FUNCTION_CREATE_FAILED',
}
@@ -363,7 +363,7 @@ export class ServerlessFunctionService {
});
}
async usePublishedVersionAsDraft({
async createDraftFromPublishedVersion({
id,
version,
workspaceId,
@@ -400,6 +400,57 @@ export class ServerlessFunctionService {
});
}
async duplicateServerlessFunction({
id,
version,
workspaceId,
}: {
id: string;
version: string;
workspaceId: string;
}) {
const serverlessFunctionToDuplicate =
await this.serverlessFunctionRepository.findOneOrFail({
where: {
id,
workspaceId,
},
});
const newServerlessFunction = await this.createOneServerlessFunction(
{
name: serverlessFunctionToDuplicate.name,
description: serverlessFunctionToDuplicate.description,
timeoutSeconds: serverlessFunctionToDuplicate.timeoutSeconds,
},
workspaceId,
);
if (!isDefined(newServerlessFunction)) {
throw new ServerlessFunctionException(
'Failed to create new serverless function',
ServerlessFunctionExceptionCode.SERVERLESS_FUNCTION_CREATE_FAILED,
);
}
await this.fileStorageService.copy({
from: {
folderPath: getServerlessFolder({
serverlessFunction: serverlessFunctionToDuplicate,
version,
}),
},
to: {
folderPath: getServerlessFolder({
serverlessFunction: newServerlessFunction,
version: 'draft',
}),
},
});
return newServerlessFunction;
}
private async throttleExecution(workspaceId: string) {
try {
await this.throttlerService.throttle(
@@ -24,6 +24,7 @@ export const serverlessFunctionGraphQLApiExceptionHandler = (error: any) => {
case ServerlessFunctionExceptionCode.SERVERLESS_FUNCTION_EXECUTION_LIMIT_REACHED:
throw new ForbiddenError(error);
case ServerlessFunctionExceptionCode.SERVERLESS_FUNCTION_CODE_UNCHANGED:
case ServerlessFunctionExceptionCode.SERVERLESS_FUNCTION_CREATE_FAILED:
throw error;
default: {
return assertUnreachable(error.code);