(templateString, params, stream)
| 327 | } |
| 328 | |
| 329 | function formatIntoSections(templateString, params, stream) { |
| 330 | const lines = templateString.split('\n'); |
| 331 | |
| 332 | const sections = [ |
| 333 | { templateId: '$PARAMS_SECTION', index: undefined }, |
| 334 | { templateId: '$NON_STREAMING_SECTION', index: undefined }, |
| 335 | { templateId: '$STREAMING_SECTION', index: undefined }, |
| 336 | ]; |
| 337 | |
| 338 | for (const section of sections) { |
| 339 | for (let i = 0; i < lines.length; i++) { |
| 340 | const line = lines[i]; |
| 341 | |
| 342 | if (line.includes(section.templateId)) { |
| 343 | section.index = i; |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | const [ |
| 349 | { index: paramsSectionIndex }, |
| 350 | { index: nonStreamingSectionIndex }, |
| 351 | { index: streamingSectionIndex }, |
| 352 | ] = sections; |
| 353 | |
| 354 | const linesBeforeParamsSection = lines.slice(0, paramsSectionIndex); |
| 355 | |
| 356 | if (!paramsExist(params) && !stream) { |
| 357 | const nonStreamingWithOutParamsString = [ |
| 358 | ...linesBeforeParamsSection, |
| 359 | ...lines.slice(nonStreamingSectionIndex + 1, streamingSectionIndex), |
| 360 | ].join('\n'); |
| 361 | |
| 362 | return nonStreamingWithOutParamsString; |
| 363 | } |
| 364 | |
| 365 | if (!paramsExist(params) && stream) { |
| 366 | const streamingWithOutParamsString = [ |
| 367 | ...linesBeforeParamsSection, |
| 368 | ...lines.slice(streamingSectionIndex + 1), |
| 369 | ].join('\n'); |
| 370 | |
| 371 | return streamingWithOutParamsString; |
| 372 | } |
| 373 | |
| 374 | if (paramsExist(params) && stream) { |
| 375 | const streamingWithParamsString = [ |
| 376 | ...linesBeforeParamsSection, |
| 377 | ...lines.slice(paramsSectionIndex + 1, nonStreamingSectionIndex), |
| 378 | ...lines.slice(streamingSectionIndex + 1), |
| 379 | ].join('\n'); |
| 380 | |
| 381 | return streamingWithParamsString; |
| 382 | } |
| 383 | |
| 384 | if (paramsExist(params) && !stream) { |
| 385 | const nonStreamingWithParamsString = [ |
| 386 | ...linesBeforeParamsSection, |
no test coverage detected