-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up camel case and typed data parsing
Main points: - We don't want `toCamelCase` to call `fromRpcTypedData` because it traverses an entire object recursively and only the top level objects should be RpcTypedData - We will remove triggerMetadata from http/timer triggers. That information is best found on the request/timer objects instead Related to all of these bugs: Azure/azure-functions-nodejs-worker#607 Azure/azure-functions-nodejs-worker#274 Azure/azure-functions-nodejs-worker#204 Azure/azure-functions-nodejs-worker#388
- Loading branch information
Showing
16 changed files
with
598 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { TriggerMetadata } from '@azure/functions'; | ||
import { RpcTypedData } from '@azure/functions-core'; | ||
import { isHttpTrigger, isTimerTrigger } from '../utils/isTrigger'; | ||
import { fromRpcTypedData } from './fromRpcTypedData'; | ||
import { toCamelCaseKey, toCamelCaseValue } from './toCamelCase'; | ||
|
||
export function fromRpcTriggerMetadata( | ||
triggerMetadata: Record<string, RpcTypedData> | null | undefined, | ||
triggerType: string | ||
): TriggerMetadata | undefined { | ||
// For http and timer triggers, we will avoid using `triggerMetadata` for a few reasons: | ||
// 1. It uses `toCamelCase` methods, which can lead to weird casing bugs | ||
// 2. It's generally a large medley of properties that is difficult for us to document/type | ||
// 3. We can represent that information on the request & timer objects instead | ||
if (!triggerMetadata || isHttpTrigger(triggerType) || isTimerTrigger(triggerType)) { | ||
return undefined; | ||
} else { | ||
const result: TriggerMetadata = {}; | ||
for (const [key, value] of Object.entries(triggerMetadata)) { | ||
result[toCamelCaseKey(key)] = toCamelCaseValue(fromRpcTypedData(value)); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
export function toCamelCaseValue(data: unknown): unknown { | ||
if (typeof data !== 'object' || data === null) { | ||
return data; | ||
} else if (Array.isArray(data)) { | ||
return data.map(toCamelCaseValue); | ||
} else { | ||
const result = {}; | ||
for (const [key, value] of Object.entries(data)) { | ||
result[toCamelCaseKey(key)] = toCamelCaseValue(value); | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
export function toCamelCaseKey(key: string): string { | ||
return key.charAt(0).toLowerCase() + key.slice(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
export function isTrigger(typeName: string | undefined | null): boolean { | ||
return !!typeName && /trigger$/i.test(typeName); | ||
} | ||
|
||
export function isHttpTrigger(typeName: string | undefined | null): boolean { | ||
return typeName?.toLowerCase() === 'httptrigger'; | ||
} | ||
|
||
export function isTimerTrigger(typeName: string | undefined | null): boolean { | ||
return typeName?.toLowerCase() === 'timertrigger'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.