Migrate output schema to V2 (#14311)

Previous refacto was creating output schema V2 which has more specific
schemas based on the step type. Before we were using one common schema,
which was too complex when searching for variable informations.

This PR migrate the deprecated schemas and remove the old code:
- mark previous `BaseOutputSchema` as deprecated
- remove other previous schemas
- use V2 everywhere
- icon should not be stored in schema. Instead it should be generated
based on the fieldmetadata or the item type
This commit is contained in:
Thomas Trompette
2025-09-09 18:37:00 +02:00
committed by GitHub
parent e787dadde8
commit 2b59198a1b
57 changed files with 589 additions and 1256 deletions
@@ -14,25 +14,23 @@ describe('getFunctionOutputSchema', () => {
isLeaf: true,
type: 'unknown',
value: null,
icon: 'IconVariable',
label: 'a',
},
b: {
isLeaf: true,
type: 'string',
value: 'b',
icon: 'IconVariable',
label: 'b',
},
c: {
isLeaf: false,
icon: 'IconVariable',
type: 'object',
label: 'c',
value: {
cc: {
isLeaf: true,
type: 'number',
value: 1,
icon: 'IconVariable',
label: 'cc',
},
},
@@ -41,14 +39,12 @@ describe('getFunctionOutputSchema', () => {
isLeaf: true,
type: 'boolean',
value: true,
icon: 'IconVariable',
label: 'd',
},
e: {
isLeaf: true,
type: 'array',
value: [1, 2, 3],
icon: 'IconVariable',
label: 'e',
},
};
@@ -1,9 +1,11 @@
import { type InputSchemaPropertyType } from '@/workflow/types/InputSchema';
import { type BaseOutputSchema } from '@/workflow/workflow-variables/types/StepOutputSchema';
import {
type BaseOutputSchemaV2,
type LeafType,
} from '@/workflow/workflow-variables/types/BaseOutputSchemaV2';
import { isObject } from '@sniptt/guards';
import { isDefined } from 'twenty-shared/utils';
const getValueType = (value: any): InputSchemaPropertyType => {
const getValueType = (value: any): LeafType => {
if (!isDefined(value) || value === null) {
return 'unknown';
}
@@ -19,20 +21,18 @@ const getValueType = (value: any): InputSchemaPropertyType => {
if (Array.isArray(value)) {
return 'array';
}
if (isObject(value)) {
return 'object';
}
return 'unknown';
};
export const getFunctionOutputSchema = (testResult: object) => {
return testResult
? Object.entries(testResult).reduce(
(acc: BaseOutputSchema, [key, value]) => {
(acc: BaseOutputSchemaV2, [key, value]) => {
if (isObject(value) && !Array.isArray(value)) {
acc[key] = {
isLeaf: false,
icon: 'IconVariable',
type: 'object',
label: key,
value: getFunctionOutputSchema(value),
};
} else {
@@ -40,7 +40,6 @@ export const getFunctionOutputSchema = (testResult: object) => {
isLeaf: true,
value,
type: getValueType(value),
icon: 'IconVariable',
label: key,
};
}