diff --git a/packages/server/src/automations/automationUtils.ts b/packages/server/src/automations/automationUtils.ts index 7c1bb4d685..4c03f0f994 100644 --- a/packages/server/src/automations/automationUtils.ts +++ b/packages/server/src/automations/automationUtils.ts @@ -6,10 +6,10 @@ import { import sdk from "../sdk" import { AutomationAttachment, + BaseIOStructure, + FieldSchema, FieldType, Row, - LoopStepType, - LoopStepInputs, } from "@budibase/types" import { objectStore, context } from "@budibase/backend-core" import * as uuid from "uuid" @@ -33,17 +33,15 @@ import path from "path" */ export function cleanInputValues>( inputs: T, - schema?: any + schema?: Partial> ): T { - if (schema == null) { - return inputs - } - for (let inputKey of Object.keys(inputs)) { + const keys = Object.keys(inputs) as (keyof T)[] + for (let inputKey of keys) { let input = inputs[inputKey] if (typeof input !== "string") { continue } - let propSchema = schema.properties[inputKey] + let propSchema = schema?.[inputKey] if (!propSchema) { continue } @@ -96,7 +94,7 @@ export function cleanInputValues>( */ export async function cleanUpRow(tableId: string, row: Row) { let table = await sdk.tables.getTable(tableId) - return cleanInputValues(row, { properties: table.schema }) + return cleanInputValues(row, table.schema) } export function getError(err: any) { diff --git a/packages/server/src/automations/tests/automationUtils.spec.ts b/packages/server/src/automations/tests/automationUtils.spec.ts index a4346079e1..05dd7483e9 100644 --- a/packages/server/src/automations/tests/automationUtils.spec.ts +++ b/packages/server/src/automations/tests/automationUtils.spec.ts @@ -1,3 +1,4 @@ +import { AutomationIOType } from "@budibase/types" import { cleanInputValues, substituteLoopStep } from "../automationUtils" describe("automationUtils", () => { @@ -42,15 +43,12 @@ describe("automationUtils", () => { }, } expect( - cleanInputValues( - { - row: { - relationship: `[{"_id": "ro_ta_users_us_3"}]`, - }, - schema, + cleanInputValues({ + row: { + relationship: `[{"_id": "ro_ta_users_us_3"}]`, }, - schema - ) + schema, + }) ).toEqual({ row: { relationship: [{ _id: "ro_ta_users_us_3" }], @@ -75,15 +73,12 @@ describe("automationUtils", () => { }, } expect( - cleanInputValues( - { - row: { - relationship: `ro_ta_users_us_3`, - }, - schema, + cleanInputValues({ + row: { + relationship: `ro_ta_users_us_3`, }, - schema - ) + schema, + }) ).toEqual({ row: { relationship: "ro_ta_users_us_3", @@ -94,28 +89,27 @@ describe("automationUtils", () => { it("should be able to clean inputs with the utilities", () => { // can't clean without a schema - let output = cleanInputValues({ a: "1" }) - expect(output.a).toBe("1") - output = cleanInputValues( + const one = cleanInputValues({ a: "1" }) + expect(one.a).toBe("1") + + const two = cleanInputValues( { a: "1", b: "true", c: "false", d: 1, e: "help" }, { - properties: { - a: { - type: "number", - }, - b: { - type: "boolean", - }, - c: { - type: "boolean", - }, + a: { + type: AutomationIOType.NUMBER, + }, + b: { + type: AutomationIOType.BOOLEAN, + }, + c: { + type: AutomationIOType.BOOLEAN, }, } ) - expect(output.a).toBe(1) - expect(output.b).toBe(true) - expect(output.c).toBe(false) - expect(output.d).toBe(1) + expect(two.a).toBe(1) + expect(two.b).toBe(true) + expect(two.c).toBe(false) + expect(two.d).toBe(1) }) }) }) diff --git a/packages/server/src/automations/tests/scenarios.spec.ts b/packages/server/src/automations/tests/scenarios.spec.ts index fdecfe3461..91934a9e22 100644 --- a/packages/server/src/automations/tests/scenarios.spec.ts +++ b/packages/server/src/automations/tests/scenarios.spec.ts @@ -407,7 +407,7 @@ if (descriptions.length) { client = ds.client! }) - it.only("should query an external database for some data then insert than into an internal table", async () => { + it("should query an external database for some data then insert than into an internal table", async () => { const newTable = await config.api.table.save({ ...basicTable(), name: "table", diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index 0634fe4c61..5e1764403b 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -557,7 +557,7 @@ class Orchestrator { const stepFn = await this.getStepFunctionality(step.stepId) const inputs = automationUtils.cleanInputValues( await processObject(cloneDeep(step.inputs), prepareContext(ctx)), - step.schema.inputs + step.schema.inputs.properties ) const outputs = await stepFn({ diff --git a/packages/types/src/documents/app/automation/automation.ts b/packages/types/src/documents/app/automation/automation.ts index d7f5810761..ea21b5e23d 100644 --- a/packages/types/src/documents/app/automation/automation.ts +++ b/packages/types/src/documents/app/automation/automation.ts @@ -146,7 +146,7 @@ export interface Automation extends Document { } } -interface BaseIOStructure { +export interface BaseIOStructure { type?: AutomationIOType subtype?: AutomationIOType customType?: AutomationCustomIOType