({
sourceFile,
config,
}: GetLambdaOptionsFromFunctionOptions)
| 526 | } |
| 527 | |
| 528 | export async function getLambdaOptionsFromFunction({ |
| 529 | sourceFile, |
| 530 | config, |
| 531 | }: GetLambdaOptionsFromFunctionOptions): Promise< |
| 532 | Pick< |
| 533 | LambdaOptions, |
| 534 | | 'architecture' |
| 535 | | 'memory' |
| 536 | | 'maxDuration' |
| 537 | | 'regions' |
| 538 | | 'functionFailoverRegions' |
| 539 | | 'experimentalTriggers' |
| 540 | | 'supportsCancellation' |
| 541 | > |
| 542 | > { |
| 543 | if (config?.functions) { |
| 544 | // `pattern` is service-root-relative, so two services sharing a function |
| 545 | // path would derive the same consumer; scope it by service name. |
| 546 | const serviceName = |
| 547 | typeof config.serviceName === 'string' && config.serviceName !== '' |
| 548 | ? config.serviceName |
| 549 | : undefined; |
| 550 | for (const [pattern, fn] of Object.entries(config.functions)) { |
| 551 | if (sourceFile === pattern || minimatch(sourceFile, pattern)) { |
| 552 | const consumer = sanitizeConsumerName( |
| 553 | serviceName ? `${serviceName}~${pattern}` : pattern |
| 554 | ); |
| 555 | const experimentalTriggers: TriggerEvent[] | undefined = |
| 556 | fn.experimentalTriggers?.map( |
| 557 | (trigger: TriggerEventInput): TriggerEvent => { |
| 558 | if (trigger.type === 'queue/v2beta') { |
| 559 | return { |
| 560 | ...trigger, |
| 561 | consumer, |
| 562 | }; |
| 563 | } |
| 564 | return trigger; |
| 565 | } |
| 566 | ); |
| 567 | |
| 568 | // User-configured functions can only have one v2beta trigger. |
| 569 | // Services may attach multiple triggers programmatically. |
| 570 | if ( |
| 571 | experimentalTriggers && |
| 572 | experimentalTriggers.length > 1 && |
| 573 | experimentalTriggers.some(t => t.type === 'queue/v2beta') |
| 574 | ) { |
| 575 | throw new Error( |
| 576 | `functions["${pattern}"].experimentalTriggers can only have one item for queue/v2beta` |
| 577 | ); |
| 578 | } |
| 579 | |
| 580 | return { |
| 581 | architecture: fn.architecture, |
| 582 | memory: fn.memory, |
| 583 | maxDuration: fn.maxDuration, |
| 584 | regions: fn.regions, |
| 585 | functionFailoverRegions: fn.functionFailoverRegions, |
no test coverage detected