101 featch available variables from previous steps (#8062)
- add outputSchema in workflow step settings - use outputSchemas to compute step available variables https://github.com/user-attachments/assets/6b851d8e-625c-49ff-b29c-074cd86cbfee
This commit is contained in:
@ -103,4 +103,34 @@ describe('CodeIntrospectionService', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateFakeDataForFunction', () => {
|
||||
it('should generate fake data for function', () => {
|
||||
const fileContent = `
|
||||
const testArrowFunction = (param1: string, param2: number): void => {
|
||||
console.log(param1, param2);
|
||||
};
|
||||
`;
|
||||
|
||||
const result = service.generateInputData(fileContent);
|
||||
|
||||
expect(typeof result['param1']).toEqual('string');
|
||||
expect(typeof result['param2']).toEqual('number');
|
||||
});
|
||||
|
||||
it('should generate fake data for complex function', () => {
|
||||
const fileContent = `
|
||||
const testArrowFunction = (param1: string[], param2: { key: number }): void => {
|
||||
console.log(param1, param2);
|
||||
};
|
||||
`;
|
||||
|
||||
const result = service.generateInputData(fileContent);
|
||||
|
||||
expect(Array.isArray(result['param1'])).toBeTruthy();
|
||||
expect(typeof result['param1'][0]).toEqual('string');
|
||||
expect(typeof result['param2']).toEqual('object');
|
||||
expect(typeof result['param2']['key']).toEqual('number');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -12,6 +12,7 @@ import {
|
||||
CodeIntrospectionException,
|
||||
CodeIntrospectionExceptionCode,
|
||||
} from 'src/modules/code-introspection/code-introspection.exception';
|
||||
import { generateFakeValue } from 'src/engine/utils/generate-fake-value';
|
||||
|
||||
type FunctionParameter = {
|
||||
name: string;
|
||||
@ -89,4 +90,24 @@ export class CodeIntrospectionService {
|
||||
type: parameter.getType().getText(),
|
||||
};
|
||||
}
|
||||
|
||||
public generateInputData(fileContent: string, fileName = 'temp.ts') {
|
||||
const parameters = this.analyze(fileContent, fileName);
|
||||
|
||||
return this.generateFakeDataFromParams(parameters);
|
||||
}
|
||||
|
||||
private generateFakeDataFromParams(
|
||||
params: FunctionParameter[],
|
||||
): Record<string, any> {
|
||||
const data: Record<string, any> = {};
|
||||
|
||||
params.forEach((param) => {
|
||||
const type = param.type;
|
||||
|
||||
data[param.name] = generateFakeValue(type);
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user