Fix initial code step functionInput (#18002)
At code step creation ## before <img width="623" height="816" alt="image" src="https://github.com/user-attachments/assets/0aed5ed8-8d56-4988-9d31-fe80942191bb" /> ## after <img width="627" height="528" alt="image" src="https://github.com/user-attachments/assets/9e2a5cb9-7480-4734-8e41-25b45edcec07" />
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { getInputSchemaFromSourceCode } from '@/logic-function/get-input-schema-from-source-code';
|
||||
import { DEFAULT_TOOL_INPUT_SCHEMA } from '@/logic-function/constants/default-tool-input-schema';
|
||||
import { DEFAULT_TOOL_INPUT_SCHEMA } from '@/logic-function/constants/DefaultToolInputSchema';
|
||||
|
||||
describe('getInputSchemaFromSourceCode', () => {
|
||||
it('should return empty input if not parameter', async () => {
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
* |___/
|
||||
*/
|
||||
|
||||
export { DEFAULT_TOOL_INPUT_SCHEMA } from './constants/default-tool-input-schema';
|
||||
export { SEED_LOGIC_FUNCTION_INPUT_SCHEMA } from './constants/seed-logic-function-input-schema';
|
||||
export { DEFAULT_TOOL_INPUT_SCHEMA } from './constants/DefaultToolInputSchema';
|
||||
export { SEED_LOGIC_FUNCTION_INPUT_SCHEMA } from './constants/SeedLogicFunctionInputSchema';
|
||||
export { getInputSchemaFromSourceCode } from './get-input-schema-from-source-code';
|
||||
export { getOutputSchemaFromValue } from './get-output-schema-from-value';
|
||||
export type { InputJsonSchema } from './input-json-schema.type';
|
||||
|
||||
@@ -44,10 +44,7 @@ describe('turnJSDateToPlainDate', () => {
|
||||
describe('turnPlainDateIntoUserTimeZoneInstantString', () => {
|
||||
it('should convert a PlainDate to an instant string in the given timezone', () => {
|
||||
const plainDate = Temporal.PlainDate.from('2024-03-15');
|
||||
const result = turnPlainDateIntoUserTimeZoneInstantString(
|
||||
plainDate,
|
||||
'UTC',
|
||||
);
|
||||
const result = turnPlainDateIntoUserTimeZoneInstantString(plainDate, 'UTC');
|
||||
|
||||
expect(result).toBe('2024-03-15T00:00:00Z');
|
||||
});
|
||||
|
||||
+1
-3
@@ -3,9 +3,7 @@ import { Temporal } from 'temporal-polyfill';
|
||||
import { addUnitToZonedDateTime } from '@/utils/filter/dates/utils/addUnitToZonedDateTime';
|
||||
|
||||
describe('addUnitToZonedDateTime', () => {
|
||||
const baseZdt = Temporal.ZonedDateTime.from(
|
||||
'2024-03-15T12:00:00[UTC]',
|
||||
);
|
||||
const baseZdt = Temporal.ZonedDateTime.from('2024-03-15T12:00:00[UTC]');
|
||||
|
||||
it('should add days', () => {
|
||||
const result = addUnitToZonedDateTime(baseZdt, 'DAY', 3);
|
||||
|
||||
+4
-2
@@ -14,7 +14,8 @@ describe('relativeDateFilterStringifiedSchema', () => {
|
||||
});
|
||||
|
||||
it('should parse a valid NEXT filter string', () => {
|
||||
const result = relativeDateFilterStringifiedSchema.safeParse('NEXT_30_MINUTE');
|
||||
const result =
|
||||
relativeDateFilterStringifiedSchema.safeParse('NEXT_30_MINUTE');
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
|
||||
@@ -26,7 +27,8 @@ describe('relativeDateFilterStringifiedSchema', () => {
|
||||
});
|
||||
|
||||
it('should parse a THIS filter string', () => {
|
||||
const result = relativeDateFilterStringifiedSchema.safeParse('THIS_1_MONTH');
|
||||
const result =
|
||||
relativeDateFilterStringifiedSchema.safeParse('THIS_1_MONTH');
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
|
||||
|
||||
+1
-3
@@ -3,9 +3,7 @@ import { Temporal } from 'temporal-polyfill';
|
||||
import { resolveRelativeDateFilter } from '@/utils/filter/dates/utils/resolveRelativeDateFilter';
|
||||
|
||||
describe('resolveRelativeDateFilter', () => {
|
||||
const referenceZdt = Temporal.ZonedDateTime.from(
|
||||
'2024-03-15T12:00:00[UTC]',
|
||||
);
|
||||
const referenceZdt = Temporal.ZonedDateTime.from('2024-03-15T12:00:00[UTC]');
|
||||
|
||||
describe('NEXT direction', () => {
|
||||
it('should compute start and end for NEXT 7 DAY', () => {
|
||||
|
||||
+1
-3
@@ -3,9 +3,7 @@ import { Temporal } from 'temporal-polyfill';
|
||||
import { resolveRelativeDateTimeFilter } from '@/utils/filter/dates/utils/resolveRelativeDateTimeFilter';
|
||||
|
||||
describe('resolveRelativeDateTimeFilter', () => {
|
||||
const referenceZdt = Temporal.ZonedDateTime.from(
|
||||
'2024-03-15T12:00:00[UTC]',
|
||||
);
|
||||
const referenceZdt = Temporal.ZonedDateTime.from('2024-03-15T12:00:00[UTC]');
|
||||
|
||||
describe('NEXT direction', () => {
|
||||
it('should compute for sub-day unit (HOUR)', () => {
|
||||
|
||||
+1
-3
@@ -3,9 +3,7 @@ import { Temporal } from 'temporal-polyfill';
|
||||
import { subUnitFromZonedDateTime } from '@/utils/filter/dates/utils/subUnitFromZonedDateTime';
|
||||
|
||||
describe('subUnitFromZonedDateTime', () => {
|
||||
const baseZdt = Temporal.ZonedDateTime.from(
|
||||
'2024-03-15T12:00:00[UTC]',
|
||||
);
|
||||
const baseZdt = Temporal.ZonedDateTime.from('2024-03-15T12:00:00[UTC]');
|
||||
|
||||
it('should subtract days', () => {
|
||||
const result = subUnitFromZonedDateTime(baseZdt, 'DAY', 3);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { FirstDayOfTheWeek as FirstDayOfTheWeekEnum } from '@/types/FirstDayOfTheWeek';
|
||||
import { FirstDayOfTheWeek } from '@/types';
|
||||
import z from 'zod';
|
||||
|
||||
export const firstDayOfWeekSchema = z.enum([
|
||||
FirstDayOfTheWeekEnum.MONDAY,
|
||||
FirstDayOfTheWeekEnum.SATURDAY,
|
||||
FirstDayOfTheWeekEnum.SUNDAY,
|
||||
FirstDayOfTheWeek.MONDAY,
|
||||
FirstDayOfTheWeek.SATURDAY,
|
||||
FirstDayOfTheWeek.SUNDAY,
|
||||
]);
|
||||
|
||||
export type FirstDayOfTheWeek = z.infer<typeof firstDayOfWeekSchema>;
|
||||
export type FirstDayOfTheWeekSchema = z.infer<typeof firstDayOfWeekSchema>;
|
||||
|
||||
+6
-6
@@ -1,16 +1,16 @@
|
||||
import { FirstDayOfTheWeek as FirstDayOfTheWeekEnum } from '@/types/FirstDayOfTheWeek';
|
||||
import { FirstDayOfTheWeek } from '@/types';
|
||||
import { assertUnreachable } from '@/utils/assertUnreachable';
|
||||
import { type FirstDayOfTheWeek } from '@/utils/filter/dates/utils/firstDayOfWeekSchema';
|
||||
import { type FirstDayOfTheWeekSchema } from '@/utils/filter/dates/utils/firstDayOfWeekSchema';
|
||||
|
||||
export const getFirstDayOfTheWeekAsANumberForDateFNS = (
|
||||
firstDayOfTheWeek: FirstDayOfTheWeek,
|
||||
firstDayOfTheWeek: FirstDayOfTheWeekSchema,
|
||||
): 0 | 1 | 6 => {
|
||||
switch (firstDayOfTheWeek) {
|
||||
case FirstDayOfTheWeekEnum.MONDAY:
|
||||
case FirstDayOfTheWeek.MONDAY:
|
||||
return 1;
|
||||
case FirstDayOfTheWeekEnum.SATURDAY:
|
||||
case FirstDayOfTheWeek.SATURDAY:
|
||||
return 6;
|
||||
case FirstDayOfTheWeekEnum.SUNDAY:
|
||||
case FirstDayOfTheWeek.SUNDAY:
|
||||
return 0;
|
||||
default:
|
||||
return assertUnreachable(firstDayOfTheWeek);
|
||||
|
||||
+6
-6
@@ -1,16 +1,16 @@
|
||||
import { FirstDayOfTheWeek as FirstDayOfTheWeekEnum } from '@/types/FirstDayOfTheWeek';
|
||||
import { FirstDayOfTheWeek } from '@/types';
|
||||
import { assertUnreachable } from '@/utils/assertUnreachable';
|
||||
import { type FirstDayOfTheWeek } from '@/utils/filter/dates/utils/firstDayOfWeekSchema';
|
||||
import { type FirstDayOfTheWeekSchema } from '@/utils/filter/dates/utils/firstDayOfWeekSchema';
|
||||
|
||||
export const getFirstDayOfTheWeekAsISONumber = (
|
||||
firstDayOfTheWeek: FirstDayOfTheWeek,
|
||||
firstDayOfTheWeek: FirstDayOfTheWeekSchema,
|
||||
): 1 | 6 | 7 => {
|
||||
switch (firstDayOfTheWeek) {
|
||||
case FirstDayOfTheWeekEnum.MONDAY:
|
||||
case FirstDayOfTheWeek.MONDAY:
|
||||
return 1;
|
||||
case FirstDayOfTheWeekEnum.SATURDAY:
|
||||
case FirstDayOfTheWeek.SATURDAY:
|
||||
return 6;
|
||||
case FirstDayOfTheWeekEnum.SUNDAY:
|
||||
case FirstDayOfTheWeek.SUNDAY:
|
||||
return 7;
|
||||
default:
|
||||
return assertUnreachable(firstDayOfTheWeek);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { type Nullable } from '@/types';
|
||||
import { assertUnreachable } from '@/utils/assertUnreachable';
|
||||
import { type DateTimePeriod } from '@/utils/filter/dates/types/DateTimePeriod';
|
||||
import { type FirstDayOfTheWeek } from '@/utils/filter/dates/utils/firstDayOfWeekSchema';
|
||||
import { type FirstDayOfTheWeekSchema } from '@/utils/filter/dates/utils/firstDayOfWeekSchema';
|
||||
import { getPeriodStart } from '@/utils/filter/dates/utils/getPeriodStart';
|
||||
import { type Temporal } from 'temporal-polyfill';
|
||||
|
||||
@@ -10,7 +10,7 @@ export const FIRST_DAY_OF_WEEK_ISO_8601_MONDAY = 1;
|
||||
export const getNextPeriodStart = (
|
||||
dateTime: Temporal.ZonedDateTime,
|
||||
unit: DateTimePeriod,
|
||||
firstDayOfTheWeek?: Nullable<FirstDayOfTheWeek>,
|
||||
firstDayOfTheWeek?: Nullable<FirstDayOfTheWeekSchema>,
|
||||
) => {
|
||||
switch (unit) {
|
||||
case 'DAY':
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { type Nullable } from '@/types';
|
||||
import { assertUnreachable, type DateTimePeriod } from '@/utils';
|
||||
|
||||
import { type FirstDayOfTheWeek } from '@/utils/filter/dates/utils/firstDayOfWeekSchema';
|
||||
import { type FirstDayOfTheWeekSchema } from '@/utils/filter/dates/utils/firstDayOfWeekSchema';
|
||||
import { getFirstDayOfTheWeekAsISONumber } from '@/utils/filter/dates/utils/getFirstDayOfTheWeekAsISONumber';
|
||||
import { FIRST_DAY_OF_WEEK_ISO_8601_MONDAY } from '@/utils/filter/dates/utils/getNextPeriodStart';
|
||||
import { isDefined } from '@/utils/validation';
|
||||
@@ -10,7 +10,7 @@ import { type Temporal } from 'temporal-polyfill';
|
||||
export const getPeriodStart = (
|
||||
dateTime: Temporal.ZonedDateTime,
|
||||
unit: DateTimePeriod,
|
||||
firstDayOfTheWeek?: Nullable<FirstDayOfTheWeek>,
|
||||
firstDayOfTheWeek?: Nullable<FirstDayOfTheWeekSchema>,
|
||||
) => {
|
||||
switch (unit) {
|
||||
case 'DAY':
|
||||
|
||||
@@ -56,7 +56,7 @@ export { addUnitToDateTime } from './filter/dates/utils/addUnitToDateTime';
|
||||
export { addUnitToZonedDateTime } from './filter/dates/utils/addUnitToZonedDateTime';
|
||||
export { convertCalendarStartDayNonIsoNumberToFirstDayOfTheWeek } from './filter/dates/utils/convertCalendarStartDayNonIsoNumberToFirstDayOfTheWeek';
|
||||
export { convertFirstDayOfTheWeekToCalendarStartDayNumber } from './filter/dates/utils/convertFirstDayOfTheWeekToCalendarStartDayNumber';
|
||||
export type { FirstDayOfTheWeek } from './filter/dates/utils/firstDayOfWeekSchema';
|
||||
export type { FirstDayOfTheWeekSchema } from './filter/dates/utils/firstDayOfWeekSchema';
|
||||
export { firstDayOfWeekSchema } from './filter/dates/utils/firstDayOfWeekSchema';
|
||||
export { getFirstDayOfTheWeekAsANumberForDateFNS } from './filter/dates/utils/getFirstDayOfTheWeekAsANumberForDateFNS';
|
||||
export { getFirstDayOfTheWeekAsISONumber } from './filter/dates/utils/getFirstDayOfTheWeekAsISONumber';
|
||||
|
||||
@@ -67,6 +67,12 @@ export { workflowRunStatusSchema } from './schemas/workflow-run-status-schema';
|
||||
export { workflowRunStepStatusSchema } from './schemas/workflow-run-step-status-schema';
|
||||
export { workflowTriggerSchema } from './schemas/workflow-trigger-schema';
|
||||
export type { EmailRecipients } from './types/EmailRecipients';
|
||||
export type { FunctionInput } from './types/FunctionInput';
|
||||
export type {
|
||||
InputSchemaPropertyType,
|
||||
InputSchemaProperty,
|
||||
InputSchema,
|
||||
} from './types/InputSchema';
|
||||
export type { StepIfElseBranch } from './types/StepIfElseBranch';
|
||||
export type { BodyType } from './types/workflowHttpRequestStep';
|
||||
export type {
|
||||
@@ -76,6 +82,7 @@ export type {
|
||||
export { StepStatus } from './types/WorkflowRunStateStepInfos';
|
||||
export { canObjectBeManagedByWorkflow } from './utils/canObjectBeManagedByWorkflow';
|
||||
export { extractRawVariableNamePart } from './utils/extractRawVariableNameParts';
|
||||
export { getFunctionInputFromInputSchema } from './utils/getFunctionInputFromInputSchema';
|
||||
export { getWorkflowRunContext } from './utils/getWorkflowRunContext';
|
||||
export { parseBooleanFromStringValue } from './utils/parseBooleanFromStringValue';
|
||||
export { parseDataFromContentType } from './utils/parseDataFromContentType';
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
export type FunctionInput =
|
||||
| {
|
||||
[name: string]: FunctionInput;
|
||||
}
|
||||
| any;
|
||||
@@ -0,0 +1,17 @@
|
||||
import { type LeafType, type NodeType } from '@/workflow';
|
||||
import { type FieldMetadataType } from '@/types';
|
||||
|
||||
export type InputSchemaPropertyType = LeafType | NodeType | FieldMetadataType;
|
||||
|
||||
export type InputSchemaProperty = {
|
||||
type: InputSchemaPropertyType;
|
||||
enum?: string[];
|
||||
items?: InputSchemaProperty;
|
||||
properties?: Properties;
|
||||
};
|
||||
|
||||
type Properties = {
|
||||
[name: string]: InputSchemaProperty;
|
||||
};
|
||||
|
||||
export type InputSchema = InputSchemaProperty[];
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import { getFunctionInputFromInputSchema, type InputSchema } from '@/workflow';
|
||||
|
||||
describe('getDefaultFunctionInputFromInputSchema', () => {
|
||||
it('should init function input properly', () => {
|
||||
const inputSchema = [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
a: {
|
||||
type: 'string',
|
||||
},
|
||||
b: {
|
||||
type: 'number',
|
||||
},
|
||||
c: {
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
},
|
||||
d: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
da: { type: 'string', enum: ['my', 'enum'] },
|
||||
db: { type: 'number' },
|
||||
},
|
||||
},
|
||||
e: { type: 'object' },
|
||||
},
|
||||
},
|
||||
] as InputSchema;
|
||||
const expectedResult = [
|
||||
{
|
||||
a: null,
|
||||
b: null,
|
||||
c: [],
|
||||
d: { da: 'my', db: null },
|
||||
e: {},
|
||||
},
|
||||
];
|
||||
expect(getFunctionInputFromInputSchema(inputSchema)).toEqual(
|
||||
expectedResult,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
import { type InputSchema, type FunctionInput } from '@/workflow';
|
||||
import { type InputJsonSchema } from '@/logic-function';
|
||||
import { isDefined } from '@/utils';
|
||||
|
||||
export const getFunctionInputFromInputSchema = (
|
||||
inputSchema: InputSchema | InputJsonSchema[],
|
||||
): FunctionInput => {
|
||||
return inputSchema.map((param) => {
|
||||
if (
|
||||
isDefined(param.type) &&
|
||||
['string', 'number', 'boolean'].includes(param.type)
|
||||
) {
|
||||
return param.enum && param.enum.length > 0 ? param.enum[0] : null;
|
||||
} else if (param.type === 'object') {
|
||||
const result: FunctionInput = {};
|
||||
if (isDefined(param.properties)) {
|
||||
Object.entries(param.properties).forEach(([key, val]) => {
|
||||
result[key] = getFunctionInputFromInputSchema([val])[0];
|
||||
});
|
||||
}
|
||||
return result;
|
||||
} else if (param.type === 'array' && isDefined(param.items)) {
|
||||
return [];
|
||||
}
|
||||
return null;
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user