8726 workflow add a test button in workflow code step (#9016)
- add test button to workflow code step - add test tab to workflow code step https://github.com/user-attachments/assets/e180a827-7321-49a2-8026-88490c557da2  
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
|
||||
export type InputSchemaPropertyType =
|
||||
| 'string'
|
||||
| 'number'
|
||||
| 'boolean'
|
||||
| 'object'
|
||||
| 'array'
|
||||
| 'unknown'
|
||||
| FieldMetadataType;
|
||||
|
||||
export type InputSchemaProperty = {
|
||||
type: InputSchemaPropertyType;
|
||||
enum?: string[];
|
||||
items?: InputSchemaProperty; // used to describe array type elements
|
||||
properties?: Properties; // used to describe object type elements
|
||||
};
|
||||
|
||||
type Properties = {
|
||||
[name: string]: InputSchemaProperty;
|
||||
};
|
||||
|
||||
export type InputSchema = InputSchemaProperty[];
|
||||
@ -1,9 +1,9 @@
|
||||
import { InputSchemaPropertyType } from 'src/modules/code-introspection/types/input-schema.type';
|
||||
import { InputSchemaPropertyType } from 'src/modules/workflow/workflow-builder/types/input-schema.type';
|
||||
|
||||
export type Leaf = {
|
||||
isLeaf: true;
|
||||
icon?: string;
|
||||
type?: InputSchemaPropertyType;
|
||||
icon?: string;
|
||||
label?: string;
|
||||
value: any;
|
||||
};
|
||||
|
||||
@ -3,14 +3,12 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { ServerlessFunctionModule } from 'src/engine/metadata-modules/serverless-function/serverless-function.module';
|
||||
import { CodeIntrospectionModule } from 'src/modules/code-introspection/code-introspection.module';
|
||||
import { WorkflowBuilderWorkspaceService } from 'src/modules/workflow/workflow-builder/workflow-builder.workspace-service';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([ObjectMetadataEntity], 'metadata'),
|
||||
ServerlessFunctionModule,
|
||||
CodeIntrospectionModule,
|
||||
],
|
||||
providers: [WorkflowBuilderWorkspaceService],
|
||||
exports: [WorkflowBuilderWorkspaceService],
|
||||
|
||||
@ -1,23 +1,14 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { join } from 'path';
|
||||
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
import { checkStringIsDatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/utils/check-string-is-database-event-action';
|
||||
import { INDEX_FILE_NAME } from 'src/engine/core-modules/serverless/drivers/constants/index-file-name';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { ServerlessFunctionService } from 'src/engine/metadata-modules/serverless-function/serverless-function.service';
|
||||
import { generateFakeValue } from 'src/engine/utils/generate-fake-value';
|
||||
import { CodeIntrospectionService } from 'src/modules/code-introspection/code-introspection.service';
|
||||
import { InputSchemaPropertyType } from 'src/modules/code-introspection/types/input-schema.type';
|
||||
import {
|
||||
Leaf,
|
||||
Node,
|
||||
OutputSchema,
|
||||
} from 'src/modules/workflow/workflow-builder/types/output-schema.type';
|
||||
import { OutputSchema } from 'src/modules/workflow/workflow-builder/types/output-schema.type';
|
||||
import { generateFakeObjectRecord } from 'src/modules/workflow/workflow-builder/utils/generate-fake-object-record';
|
||||
import { generateFakeObjectRecordEvent } from 'src/modules/workflow/workflow-builder/utils/generate-fake-object-record-event';
|
||||
import {
|
||||
@ -34,7 +25,6 @@ import { isDefined } from 'src/utils/is-defined';
|
||||
export class WorkflowBuilderWorkspaceService {
|
||||
constructor(
|
||||
private readonly serverlessFunctionService: ServerlessFunctionService,
|
||||
private readonly codeIntrospectionService: CodeIntrospectionService,
|
||||
@InjectRepository(ObjectMetadataEntity, 'metadata')
|
||||
private readonly objectMetadataRepository: Repository<ObjectMetadataEntity>,
|
||||
) {}
|
||||
@ -72,18 +62,6 @@ export class WorkflowBuilderWorkspaceService {
|
||||
case WorkflowActionType.SEND_EMAIL: {
|
||||
return this.computeSendEmailActionOutputSchema();
|
||||
}
|
||||
case WorkflowActionType.CODE: {
|
||||
const { serverlessFunctionId, serverlessFunctionVersion } =
|
||||
step.settings.input;
|
||||
|
||||
return this.computeCodeActionOutputSchema({
|
||||
serverlessFunctionId,
|
||||
serverlessFunctionVersion,
|
||||
workspaceId,
|
||||
serverlessFunctionService: this.serverlessFunctionService,
|
||||
codeIntrospectionService: this.codeIntrospectionService,
|
||||
});
|
||||
}
|
||||
case WorkflowActionType.CREATE_RECORD:
|
||||
case WorkflowActionType.UPDATE_RECORD:
|
||||
case WorkflowActionType.DELETE_RECORD:
|
||||
@ -98,6 +76,7 @@ export class WorkflowBuilderWorkspaceService {
|
||||
workspaceId,
|
||||
objectMetadataRepository: this.objectMetadataRepository,
|
||||
});
|
||||
case WorkflowActionType.CODE: // StepOutput schema is computed on serverlessFunction draft execution
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
@ -194,63 +173,4 @@ export class WorkflowBuilderWorkspaceService {
|
||||
private computeSendEmailActionOutputSchema(): OutputSchema {
|
||||
return { success: { isLeaf: true, type: 'boolean', value: true } };
|
||||
}
|
||||
|
||||
private async computeCodeActionOutputSchema({
|
||||
serverlessFunctionId,
|
||||
serverlessFunctionVersion,
|
||||
workspaceId,
|
||||
serverlessFunctionService,
|
||||
codeIntrospectionService,
|
||||
}: {
|
||||
serverlessFunctionId: string;
|
||||
serverlessFunctionVersion: string;
|
||||
workspaceId: string;
|
||||
serverlessFunctionService: ServerlessFunctionService;
|
||||
codeIntrospectionService: CodeIntrospectionService;
|
||||
}): Promise<OutputSchema> {
|
||||
if (serverlessFunctionId === '') {
|
||||
return {};
|
||||
}
|
||||
|
||||
const sourceCode = (
|
||||
await serverlessFunctionService.getServerlessFunctionSourceCode(
|
||||
workspaceId,
|
||||
serverlessFunctionId,
|
||||
serverlessFunctionVersion,
|
||||
)
|
||||
)?.[join('src', INDEX_FILE_NAME)];
|
||||
|
||||
if (!isDefined(sourceCode)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const inputSchema =
|
||||
codeIntrospectionService.getFunctionInputSchema(sourceCode);
|
||||
|
||||
const fakeFunctionInput =
|
||||
codeIntrospectionService.generateInputData(inputSchema);
|
||||
|
||||
const resultFromFakeInput =
|
||||
await serverlessFunctionService.executeOneServerlessFunction(
|
||||
serverlessFunctionId,
|
||||
workspaceId,
|
||||
Object.values(fakeFunctionInput)?.[0] || {},
|
||||
serverlessFunctionVersion,
|
||||
);
|
||||
|
||||
return resultFromFakeInput.data
|
||||
? Object.entries(resultFromFakeInput.data).reduce(
|
||||
(acc: Record<string, Leaf | Node>, [key, value]) => {
|
||||
acc[key] = {
|
||||
isLeaf: true,
|
||||
value,
|
||||
type: typeof value as InputSchemaPropertyType,
|
||||
};
|
||||
|
||||
return acc;
|
||||
},
|
||||
{},
|
||||
)
|
||||
: {};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user