From a245a27b30d537d7705e1754934fa65db4209450 Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Mon, 4 Nov 2024 16:56:35 +0100 Subject: [PATCH] Greptile feedbacks --- .../src/generated-metadata/graphql.ts | 16 ++++++++-------- packages/twenty-front/src/generated/graphql.tsx | 8 +++++++- .../WorkflowEditActionFormServerlessFunction.tsx | 7 +++++-- ...serverless-function-input-schema-input.dto.ts | 16 ---------------- .../dtos/function-parameter.dto.ts | 4 ++++ .../dtos/serverless-function.dto.ts | 4 ++-- .../__tests__/code-introspection.service.spec.ts | 6 +++--- 7 files changed, 29 insertions(+), 32 deletions(-) delete mode 100644 packages/twenty-server/src/engine/core-modules/workflow/dtos/compute-serverless-function-input-schema-input.dto.ts diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts index 12037b45d747..9d9cddd3a05c 100644 --- a/packages/twenty-front/src/generated-metadata/graphql.ts +++ b/packages/twenty-front/src/generated-metadata/graphql.ts @@ -1232,7 +1232,7 @@ export type ServerlessFunction = { createdAt: Scalars['DateTime']['output']; description?: Maybe; id: Scalars['UUID']['output']; - inputSchema: Array; + inputSchema?: Maybe>; latestVersion?: Maybe; name: Scalars['String']['output']; publishedVersions: Array; @@ -1987,21 +1987,21 @@ export type ObjectMetadataItemsQueryVariables = Exact<{ export type ObjectMetadataItemsQuery = { __typename?: 'Query', objects: { __typename?: 'ObjectConnection', edges: Array<{ __typename?: 'objectEdge', node: { __typename?: 'object', id: any, dataSourceId: string, nameSingular: string, namePlural: string, labelSingular: string, labelPlural: string, description?: string | null, icon?: string | null, isCustom: boolean, isRemote: boolean, isActive: boolean, isSystem: boolean, createdAt: any, updatedAt: any, labelIdentifierFieldMetadataId?: string | null, imageIdentifierFieldMetadataId?: string | null, shortcut?: string | null, isLabelSyncedWithName: boolean, indexMetadatas: { __typename?: 'ObjectIndexMetadatasConnection', edges: Array<{ __typename?: 'indexEdge', node: { __typename?: 'index', id: any, createdAt: any, updatedAt: any, name: string, indexWhereClause?: string | null, indexType: IndexType, isUnique: boolean, indexFieldMetadatas: { __typename?: 'IndexIndexFieldMetadatasConnection', edges: Array<{ __typename?: 'indexFieldEdge', node: { __typename?: 'indexField', id: any, createdAt: any, updatedAt: any, order: number, fieldMetadataId: any } }> } } }> }, fields: { __typename?: 'ObjectFieldsConnection', edges: Array<{ __typename?: 'fieldEdge', node: { __typename?: 'field', id: any, type: FieldMetadataType, name: string, label: string, description?: string | null, icon?: string | null, isCustom?: boolean | null, isActive?: boolean | null, isSystem?: boolean | null, isNullable?: boolean | null, isUnique?: boolean | null, createdAt: any, updatedAt: any, defaultValue?: any | null, options?: any | null, settings?: any | null, relationDefinition?: { __typename?: 'RelationDefinition', relationId: any, direction: RelationDefinitionType, sourceObjectMetadata: { __typename?: 'object', id: any, nameSingular: string, namePlural: string }, sourceFieldMetadata: { __typename?: 'field', id: any, name: string }, targetObjectMetadata: { __typename?: 'object', id: any, nameSingular: string, namePlural: string }, targetFieldMetadata: { __typename?: 'field', id: any, name: string } } | null } }>, pageInfo: { __typename?: 'PageInfo', hasNextPage?: boolean | null, hasPreviousPage?: boolean | null, startCursor?: any | null, endCursor?: any | null } } } }>, pageInfo: { __typename?: 'PageInfo', hasNextPage?: boolean | null, hasPreviousPage?: boolean | null, startCursor?: any | null, endCursor?: any | null } } }; -export type ServerlessFunctionFieldsFragment = { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, runtime: string, syncStatus: ServerlessFunctionSyncStatus, latestVersion?: string | null, publishedVersions: Array, createdAt: any, updatedAt: any, inputSchema: Array<{ __typename?: 'FunctionParameter', name: string, type: string }> }; +export type ServerlessFunctionFieldsFragment = { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, runtime: string, syncStatus: ServerlessFunctionSyncStatus, latestVersion?: string | null, publishedVersions: Array, createdAt: any, updatedAt: any, inputSchema?: Array<{ __typename?: 'FunctionParameter', name: string, type: string }> | null }; export type CreateOneServerlessFunctionItemMutationVariables = Exact<{ input: CreateServerlessFunctionInput; }>; -export type CreateOneServerlessFunctionItemMutation = { __typename?: 'Mutation', createOneServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, runtime: string, syncStatus: ServerlessFunctionSyncStatus, latestVersion?: string | null, publishedVersions: Array, createdAt: any, updatedAt: any, inputSchema: Array<{ __typename?: 'FunctionParameter', name: string, type: string }> } }; +export type CreateOneServerlessFunctionItemMutation = { __typename?: 'Mutation', createOneServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, runtime: string, syncStatus: ServerlessFunctionSyncStatus, latestVersion?: string | null, publishedVersions: Array, createdAt: any, updatedAt: any, inputSchema?: Array<{ __typename?: 'FunctionParameter', name: string, type: string }> | null } }; export type DeleteOneServerlessFunctionMutationVariables = Exact<{ input: ServerlessFunctionIdInput; }>; -export type DeleteOneServerlessFunctionMutation = { __typename?: 'Mutation', deleteOneServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, runtime: string, syncStatus: ServerlessFunctionSyncStatus, latestVersion?: string | null, publishedVersions: Array, createdAt: any, updatedAt: any, inputSchema: Array<{ __typename?: 'FunctionParameter', name: string, type: string }> } }; +export type DeleteOneServerlessFunctionMutation = { __typename?: 'Mutation', deleteOneServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, runtime: string, syncStatus: ServerlessFunctionSyncStatus, latestVersion?: string | null, publishedVersions: Array, createdAt: any, updatedAt: any, inputSchema?: Array<{ __typename?: 'FunctionParameter', name: string, type: string }> | null } }; export type ExecuteOneServerlessFunctionMutationVariables = Exact<{ input: ExecuteServerlessFunctionInput; @@ -2015,14 +2015,14 @@ export type PublishOneServerlessFunctionMutationVariables = Exact<{ }>; -export type PublishOneServerlessFunctionMutation = { __typename?: 'Mutation', publishServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, runtime: string, syncStatus: ServerlessFunctionSyncStatus, latestVersion?: string | null, publishedVersions: Array, createdAt: any, updatedAt: any, inputSchema: Array<{ __typename?: 'FunctionParameter', name: string, type: string }> } }; +export type PublishOneServerlessFunctionMutation = { __typename?: 'Mutation', publishServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, runtime: string, syncStatus: ServerlessFunctionSyncStatus, latestVersion?: string | null, publishedVersions: Array, createdAt: any, updatedAt: any, inputSchema?: Array<{ __typename?: 'FunctionParameter', name: string, type: string }> | null } }; export type UpdateOneServerlessFunctionMutationVariables = Exact<{ input: UpdateServerlessFunctionInput; }>; -export type UpdateOneServerlessFunctionMutation = { __typename?: 'Mutation', updateOneServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, runtime: string, syncStatus: ServerlessFunctionSyncStatus, latestVersion?: string | null, publishedVersions: Array, createdAt: any, updatedAt: any, inputSchema: Array<{ __typename?: 'FunctionParameter', name: string, type: string }> } }; +export type UpdateOneServerlessFunctionMutation = { __typename?: 'Mutation', updateOneServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, runtime: string, syncStatus: ServerlessFunctionSyncStatus, latestVersion?: string | null, publishedVersions: Array, createdAt: any, updatedAt: any, inputSchema?: Array<{ __typename?: 'FunctionParameter', name: string, type: string }> | null } }; export type FindManyAvailablePackagesQueryVariables = Exact<{ [key: string]: never; }>; @@ -2032,14 +2032,14 @@ export type FindManyAvailablePackagesQuery = { __typename?: 'Query', getAvailabl export type GetManyServerlessFunctionsQueryVariables = Exact<{ [key: string]: never; }>; -export type GetManyServerlessFunctionsQuery = { __typename?: 'Query', findManyServerlessFunctions: Array<{ __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, runtime: string, syncStatus: ServerlessFunctionSyncStatus, latestVersion?: string | null, publishedVersions: Array, createdAt: any, updatedAt: any, inputSchema: Array<{ __typename?: 'FunctionParameter', name: string, type: string }> }> }; +export type GetManyServerlessFunctionsQuery = { __typename?: 'Query', findManyServerlessFunctions: Array<{ __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, runtime: string, syncStatus: ServerlessFunctionSyncStatus, latestVersion?: string | null, publishedVersions: Array, createdAt: any, updatedAt: any, inputSchema?: Array<{ __typename?: 'FunctionParameter', name: string, type: string }> | null }> }; export type GetOneServerlessFunctionQueryVariables = Exact<{ input: ServerlessFunctionIdInput; }>; -export type GetOneServerlessFunctionQuery = { __typename?: 'Query', findOneServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, runtime: string, syncStatus: ServerlessFunctionSyncStatus, latestVersion?: string | null, publishedVersions: Array, createdAt: any, updatedAt: any, inputSchema: Array<{ __typename?: 'FunctionParameter', name: string, type: string }> } }; +export type GetOneServerlessFunctionQuery = { __typename?: 'Query', findOneServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, runtime: string, syncStatus: ServerlessFunctionSyncStatus, latestVersion?: string | null, publishedVersions: Array, createdAt: any, updatedAt: any, inputSchema?: Array<{ __typename?: 'FunctionParameter', name: string, type: string }> | null } }; export type FindOneServerlessFunctionSourceCodeQueryVariables = Exact<{ input: GetServerlessFunctionSourceCodeInput; diff --git a/packages/twenty-front/src/generated/graphql.tsx b/packages/twenty-front/src/generated/graphql.tsx index 479ab8bd28bc..a37eb180d58c 100644 --- a/packages/twenty-front/src/generated/graphql.tsx +++ b/packages/twenty-front/src/generated/graphql.tsx @@ -321,6 +321,12 @@ export type FullName = { lastName: Scalars['String']; }; +export type FunctionParameter = { + __typename?: 'FunctionParameter'; + name: Scalars['String']; + type: Scalars['String']; +}; + export type GenerateJwt = GenerateJwtOutputWithAuthTokens | GenerateJwtOutputWithSsoauth; export type GenerateJwtOutputWithAuthTokens = { @@ -966,7 +972,7 @@ export type ServerlessFunction = { createdAt: Scalars['DateTime']; description?: Maybe; id: Scalars['UUID']; - inputSchema?: Maybe; + inputSchema?: Maybe>; latestVersion?: Maybe; name: Scalars['String']; publishedVersions: Array; diff --git a/packages/twenty-front/src/modules/workflow/components/WorkflowEditActionFormServerlessFunction.tsx b/packages/twenty-front/src/modules/workflow/components/WorkflowEditActionFormServerlessFunction.tsx index b9ad8b1bc816..e44c24d92064 100644 --- a/packages/twenty-front/src/modules/workflow/components/WorkflowEditActionFormServerlessFunction.tsx +++ b/packages/twenty-front/src/modules/workflow/components/WorkflowEditActionFormServerlessFunction.tsx @@ -116,8 +116,10 @@ export const WorkflowEditActionFormServerlessFunction = ( serverlessFunction?.latestVersion || 'latest'; const defaultFunctionInput = serverlessFunction?.inputSchema - .map((parameter) => parameter.name) - .reduce((acc, name) => ({ ...acc, [name]: null }), {}); + ? serverlessFunction.inputSchema + .map((parameter) => parameter.name) + .reduce((acc, name) => ({ ...acc, [name]: null }), {}) + : {}; form.handleSubmit(async () => { if (props.readonly === true) { @@ -143,6 +145,7 @@ export const WorkflowEditActionFormServerlessFunction = ( {defaultFunctionInput && Object.keys(defaultFunctionInput).map((inputKey) => ( ( diff --git a/packages/twenty-server/src/engine/core-modules/workflow/dtos/compute-serverless-function-input-schema-input.dto.ts b/packages/twenty-server/src/engine/core-modules/workflow/dtos/compute-serverless-function-input-schema-input.dto.ts deleted file mode 100644 index fd87514cffc4..000000000000 --- a/packages/twenty-server/src/engine/core-modules/workflow/dtos/compute-serverless-function-input-schema-input.dto.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Field, ID, InputType } from '@nestjs/graphql'; - -@InputType() -export class ComputeServerlessFunctionInputSchemaInput { - @Field(() => ID, { - description: 'Serverless function ID', - nullable: false, - }) - serverlessFunctionId: string; - - @Field(() => String, { - description: 'Serverless function version', - nullable: false, - }) - serverlessFunctionVersion: string; -} diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/function-parameter.dto.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/function-parameter.dto.ts index 5ea5705a611f..4ad9c925ccb7 100644 --- a/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/function-parameter.dto.ts +++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/function-parameter.dto.ts @@ -1,10 +1,14 @@ import { Field, ObjectType } from '@nestjs/graphql'; +import { IsString } from 'class-validator'; + @ObjectType() export class FunctionParameter { + @IsString() @Field(() => String) name: string; + @IsString() @Field(() => String) type: string; } diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto.ts index 53b155f1ebd1..6af6dfc4cb7d 100644 --- a/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto.ts +++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto.ts @@ -66,8 +66,8 @@ export class ServerlessFunctionDTO { publishedVersions: string[]; @IsArray() - @Field(() => [FunctionParameter]) - inputSchema: FunctionParameter[]; + @Field(() => [FunctionParameter], { nullable: true }) + inputSchema: FunctionParameter[] | null; @IsEnum(ServerlessFunctionSyncStatus) @IsNotEmpty() diff --git a/packages/twenty-server/src/modules/code-introspection/__tests__/code-introspection.service.spec.ts b/packages/twenty-server/src/modules/code-introspection/__tests__/code-introspection.service.spec.ts index 2c32c75e476c..1b1347b8780b 100644 --- a/packages/twenty-server/src/modules/code-introspection/__tests__/code-introspection.service.spec.ts +++ b/packages/twenty-server/src/modules/code-introspection/__tests__/code-introspection.service.spec.ts @@ -19,7 +19,7 @@ describe('CodeIntrospectionService', () => { }); describe('getFunctionInputSchema', () => { - it('should getFunctionInputSchema a function declaration correctly', () => { + it('should analyze a function declaration correctly', () => { const fileContent = ` function testFunction(param1: string, param2: number): void { console.log(param1, param2); @@ -34,7 +34,7 @@ describe('CodeIntrospectionService', () => { ]); }); - it('should getFunctionInputSchema an arrow function correctly', () => { + it('should analyze an arrow function correctly', () => { const fileContent = ` const testArrowFunction = (param1: string, param2: number): void => { console.log(param1, param2); @@ -88,7 +88,7 @@ describe('CodeIntrospectionService', () => { ); }); - it('should correctly getFunctionInputSchema complex types', () => { + it('should correctly analyze complex types', () => { const fileContent = ` function complexFunction(param1: string[], param2: { key: number }): Promise { return Promise.resolve(true);