(ctx: ExecutionContext, value: unknown)
| 13 | import type { VariableResolver } from '@/executor/variables/resolver' |
| 14 | |
| 15 | async function normalizeCollectionValue(ctx: ExecutionContext, value: unknown): Promise<any[]> { |
| 16 | if (Array.isArray(value)) { |
| 17 | return value |
| 18 | } |
| 19 | |
| 20 | if (isLargeArrayManifest(value)) { |
| 21 | const materialized = await materializeLargeArrayManifest(value, { |
| 22 | workspaceId: ctx.workspaceId, |
| 23 | workflowId: ctx.workflowId, |
| 24 | executionId: ctx.executionId, |
| 25 | largeValueExecutionIds: ctx.largeValueExecutionIds, |
| 26 | largeValueKeys: ctx.largeValueKeys, |
| 27 | fileKeys: ctx.fileKeys, |
| 28 | allowLargeValueWorkflowScope: ctx.allowLargeValueWorkflowScope, |
| 29 | userId: ctx.userId, |
| 30 | maxBytes: MAX_DURABLE_LARGE_VALUE_BYTES, |
| 31 | }) |
| 32 | recordMaterializedAccessKeys(ctx, materialized) |
| 33 | return materialized |
| 34 | } |
| 35 | |
| 36 | if (isLargeValueRef(value)) { |
| 37 | const materialized = await materializeLargeValueRef(value, { |
| 38 | workspaceId: ctx.workspaceId, |
| 39 | workflowId: ctx.workflowId, |
| 40 | executionId: ctx.executionId, |
| 41 | largeValueExecutionIds: ctx.largeValueExecutionIds, |
| 42 | largeValueKeys: ctx.largeValueKeys, |
| 43 | fileKeys: ctx.fileKeys, |
| 44 | allowLargeValueWorkflowScope: ctx.allowLargeValueWorkflowScope, |
| 45 | userId: ctx.userId, |
| 46 | maxBytes: MAX_DURABLE_LARGE_VALUE_BYTES, |
| 47 | }) |
| 48 | if (materialized === undefined) { |
| 49 | throw new Error('Large execution value is unavailable.') |
| 50 | } |
| 51 | recordMaterializedAccessKeys(ctx, materialized) |
| 52 | return normalizeCollectionValue(ctx, materialized) |
| 53 | } |
| 54 | |
| 55 | if (typeof value === 'object' && value !== null) { |
| 56 | if ((value as Record<string, unknown>)[LARGE_ARRAY_MANIFEST_MARKER] === true) { |
| 57 | throw new Error('Invalid large array manifest.') |
| 58 | } |
| 59 | if ((value as Record<string, unknown>)[LARGE_VALUE_REF_MARKER] === true) { |
| 60 | throw new Error('Invalid large value ref.') |
| 61 | } |
| 62 | return Object.entries(value) |
| 63 | } |
| 64 | |
| 65 | if (value === null) { |
| 66 | return [] |
| 67 | } |
| 68 | |
| 69 | throw new Error('Value did not resolve to an array or object') |
| 70 | } |
| 71 | |
| 72 | /** |
no test coverage detected