Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 7 additions & 24 deletions src/internal/api/case-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
interface CustomData {
customData: unknown;
}

interface ObjectWithData {
data: Record<string, unknown>;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function isTopLevelCustomDataCamel(input: any): input is CustomData {
return 'customData' in input;
}

function isObject(input: unknown): boolean {
return input != null && typeof input === 'object';
}
Expand All @@ -25,7 +12,7 @@ function snakeCase(input: string): string {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function decamelizeKeys(obj: any): ObjectWithData {
function decamelizeKeys(obj: any): any {
if (
!isObject(obj) ||
obj instanceof Date ||
Expand All @@ -50,7 +37,11 @@ function decamelizeKeys(obj: any): ObjectWithData {
output = {};
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
output[snakeCase(key)] = decamelizeKeys(obj[key]);
if (key === 'customData') {
output['custom_data'] = obj[key];
} else {
output[snakeCase(key)] = decamelizeKeys(obj[key]);
}
}
}
}
Expand All @@ -62,13 +53,5 @@ export function convertToSnakeCase(input: unknown) {
return input;
}

if (isTopLevelCustomDataCamel(input)) {
// top level customData
const { customData, ...rest } = input;
const result = decamelizeKeys(rest);
return { ...result, custom_data: customData };
} else {
// phew
return decamelizeKeys(input);
}
return decamelizeKeys(input);
}