UNPKG

1.3 kBPlain TextView Raw
1// Copyright (c) .NET Foundation. All rights reserved.
2// Licensed under the MIT License.
3
4import { TriggerMetadata } from '@azure/functions';
5import { RpcTypedData } from '@azure/functions-core';
6import { isHttpTrigger, isTimerTrigger } from '../utils/isTrigger';
7import { fromRpcTypedData } from './fromRpcTypedData';
8import { toCamelCaseKey, toCamelCaseValue } from './toCamelCase';
9
10export function fromRpcTriggerMetadata(
11 triggerMetadata: Record<string, RpcTypedData> | null | undefined,
12 triggerType: string
13): TriggerMetadata | undefined {
14 // For http and timer triggers, we will avoid using `triggerMetadata` for a few reasons:
15 // 1. It uses `toCamelCase` methods, which can lead to weird casing bugs
16 // 2. It's generally a large medley of properties that is difficult for us to document/type
17 // 3. We can represent that information on the request & timer objects instead
18 if (!triggerMetadata || isHttpTrigger(triggerType) || isTimerTrigger(triggerType)) {
19 return undefined;
20 } else {
21 const result: TriggerMetadata = {};
22 for (const [key, value] of Object.entries(triggerMetadata)) {
23 result[toCamelCaseKey(key)] = toCamelCaseValue(fromRpcTypedData(value));
24 }
25 return result;
26 }
27}