(
ctx: ExecutionContext,
currentNodeId: string,
template: string,
loopScope?: LoopScope,
block?: SerializedBlock,
options: { allowLargeValueRefs?: boolean } = {}
)
| 1242 | } |
| 1243 | |
| 1244 | private async resolveTemplate( |
| 1245 | ctx: ExecutionContext, |
| 1246 | currentNodeId: string, |
| 1247 | template: string, |
| 1248 | loopScope?: LoopScope, |
| 1249 | block?: SerializedBlock, |
| 1250 | options: { allowLargeValueRefs?: boolean } = {} |
| 1251 | ): Promise<string> { |
| 1252 | const resolutionContext: ResolutionContext = { |
| 1253 | executionContext: ctx, |
| 1254 | executionState: this.state, |
| 1255 | currentNodeId, |
| 1256 | loopScope, |
| 1257 | allowLargeValueRefs: options.allowLargeValueRefs, |
| 1258 | } |
| 1259 | |
| 1260 | let replacementError: Error | null = null |
| 1261 | |
| 1262 | const blockType = block?.metadata?.id |
| 1263 | const language = |
| 1264 | blockType === BlockType.FUNCTION |
| 1265 | ? ((block?.config?.params as Record<string, unknown> | undefined)?.language as |
| 1266 | | string |
| 1267 | | undefined) |
| 1268 | : undefined |
| 1269 | |
| 1270 | let result = await replaceValidReferencesAsync(template, async (match) => { |
| 1271 | if (replacementError) return match |
| 1272 | |
| 1273 | try { |
| 1274 | const resolved = await this.resolveReference(match, resolutionContext) |
| 1275 | if (resolved === undefined) { |
| 1276 | return match |
| 1277 | } |
| 1278 | |
| 1279 | if (resolved === RESOLVED_EMPTY) { |
| 1280 | if (blockType === BlockType.FUNCTION) { |
| 1281 | return this.blockResolver.formatValueForBlock(null, blockType, language) |
| 1282 | } |
| 1283 | return '' |
| 1284 | } |
| 1285 | |
| 1286 | return this.blockResolver.formatValueForBlock(resolved, blockType, language) |
| 1287 | } catch (error) { |
| 1288 | replacementError = toError(error) |
| 1289 | return match |
| 1290 | } |
| 1291 | }) |
| 1292 | |
| 1293 | if (replacementError !== null) { |
| 1294 | throw replacementError |
| 1295 | } |
| 1296 | |
| 1297 | result = await replaceEnvVarsAsync(result, async (match) => { |
| 1298 | const resolved = await this.resolveReference(match, resolutionContext) |
| 1299 | return typeof resolved === 'string' ? resolved : match |
| 1300 | }) |
| 1301 | return result |
no test coverage detected