-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[One Workflow] Add entries Liquid filter for iterating over object keys
#259249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
797f265
8e1b52a
5e40641
f29ecbe
747a323
fdeda10
a9711e8
fccd195
2ae5380
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -97,12 +97,15 @@ const extractForeachItemSchemaFromJson = (foreachParam: string): z.ZodType => { | |||||||||||||||||||||||||||||||||||||
| return extractForeachItemSchemaFromArray(foreachParamParsed); | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const ENTRIES_FILTER = 'entries'; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export function getForeachItemSchema( | ||||||||||||||||||||||||||||||||||||||
| stepContextSchema: typeof DynamicStepContextSchema, | ||||||||||||||||||||||||||||||||||||||
| foreachParam: string | ||||||||||||||||||||||||||||||||||||||
| ): z.ZodType { | ||||||||||||||||||||||||||||||||||||||
| const parsedPath = parseVariablePath(foreachParam); | ||||||||||||||||||||||||||||||||||||||
| const iterateOverPath = parsedPath?.propertyPath; | ||||||||||||||||||||||||||||||||||||||
| const hasEntriesFilter = parsedPath?.filters?.includes(ENTRIES_FILTER) ?? false; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // If we have a valid variable path syntax (e.g., {{some.path}}) | ||||||||||||||||||||||||||||||||||||||
| if (parsedPath && !parsedPath.errors && iterateOverPath) { | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -140,6 +143,8 @@ export function getForeachItemSchema( | |||||||||||||||||||||||||||||||||||||
| InvalidForeachParameterErrorCodes.INVALID_UNION | ||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } else if (iterableSchema instanceof z.ZodObject && hasEntriesFilter) { | ||||||||||||||||||||||||||||||||||||||
| return z.object({ key: z.string(), value: z.unknown() }); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+146
to
+147
|
||||||||||||||||||||||||||||||||||||||
| } else if (iterableSchema instanceof z.ZodObject && hasEntriesFilter) { | |
| return z.object({ key: z.string(), value: z.unknown() }); | |
| } else if ( | |
| hasEntriesFilter && | |
| (iterableSchema instanceof z.ZodObject || iterableSchema instanceof z.ZodRecord) | |
| ) { | |
| // When using the "entries" filter on an object or record, we expose { key, value } items. | |
| // For ZodRecord, try to reuse the record's value schema if available; otherwise fall back to unknown. | |
| let valueSchema: z.ZodType = z.unknown(); | |
| if (iterableSchema instanceof z.ZodRecord) { | |
| const recordAny = iterableSchema as any; | |
| const recordValueSchema: z.ZodType | undefined = | |
| recordAny.valueType ?? recordAny._def?.valueType; | |
| if (recordValueSchema) { | |
| valueSchema = recordValueSchema; | |
| } | |
| } | |
| return z.object({ key: z.string(), value: valueSchema }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not reproducible today. I investigated: (1) inferZodType() always produces z.ZodObject for objects, never ZodRecord. (2) elasticsearch.request has no output schema — returns z.unknown(). (3) Typed ES connectors use ZodObject/ZodUnion, not ZodRecord. No current code path produces a ZodRecord here. Will add when we implement output schemas for ES request steps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
entriesis intended for object/maps, but this schema branch only triggers forz.ZodObject. In practice, many map-shaped payloads (e.g., Elasticsearch index-name → settings) are modeled asz.ZodRecord, soforeach: '{{ someMap | entries }}'may still throw 'Expected array...' in the editor. Consider extending the condition to also handlez.ZodRecord(and ideally use the record's value schema forvaluewhen available) so the schema matches real-world map usage.