Skip to content

Commit e5714eb

Browse files
committed
fix(workflows): scope the typed-elements check to arrays and type the field helper
1 parent 6f3aa73 commit e5714eb

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-block-output-fields.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@ describe('createFieldFromOutput', () => {
2020
})
2121
expect(field.children?.map((child) => child.name)).toEqual(['id'])
2222
})
23+
24+
it('keeps the fields of an untyped object that has a field named items', () => {
25+
const field = createFieldFromOutput('page', {
26+
items: { type: 'string' },
27+
total: { type: 'number' },
28+
})
29+
expect(field.children?.map((child) => child.name)).toEqual(['items', 'total'])
30+
})
2331
})

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-block-output-fields.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const RESERVED_KEYS = new Set(['type', 'description'])
1212
/**
1313
* Checks if a property is an object type
1414
*/
15-
const isObject = (prop: any): boolean => prop && typeof prop === 'object'
15+
const isObject = (prop: unknown): prop is Record<string, any> =>
16+
prop !== null && typeof prop === 'object'
1617

1718
/**
1819
* Gets a subblock value from the store
@@ -36,7 +37,7 @@ const extractChildFields = (prop: any): SchemaField[] | undefined => {
3637
}
3738

3839
/** Typed elements without `properties` (strings, `any`) have no fields to reference. */
39-
if (isObject(prop.items) && typeof prop.items.type === 'string') {
40+
if (prop.type === 'array' && isObject(prop.items) && typeof prop.items.type === 'string') {
4041
return undefined
4142
}
4243

@@ -76,7 +77,7 @@ const extractNestedFields = (properties: Record<string, any>): SchemaField[] =>
7677
/**
7778
* Creates a schema field from an output definition
7879
*/
79-
export const createFieldFromOutput = (name: string, output: any): SchemaField => {
80+
export const createFieldFromOutput = (name: string, output: unknown): SchemaField => {
8081
const hasExplicitType = isObject(output) && typeof output.type === 'string'
8182
const type = hasExplicitType ? output.type : isObject(output) ? 'object' : 'string'
8283

0 commit comments

Comments
 (0)