rollbar-backend: remove camelize-ts dep

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-04-03 10:28:58 +02:00
parent d7f955f300
commit 070ca41f0f
4 changed files with 35 additions and 15 deletions
-1
View File
@@ -36,7 +36,6 @@
"@backstage/backend-common": "workspace:^",
"@backstage/config": "workspace:^",
"@types/express": "^4.17.6",
"camelize-ts": "^2.3.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"express": "^4.17.1",
@@ -19,7 +19,6 @@ import { setupRequestMockHandlers } from '@backstage/backend-test-utils';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
import { getVoidLogger } from '@backstage/backend-common';
import { RollbarProject } from './types';
describe('RollbarApi', () => {
describe('getRequestHeaders', () => {
@@ -38,9 +37,15 @@ describe('RollbarApi', () => {
const mockBaseUrl = 'https://api.rollbar.com/api/1';
const mockProjects: RollbarProject[] = [
{ id: 123, name: 'abc', accountId: 1, status: 'enabled' },
{ id: 456, name: 'xyz', accountId: 1, status: 'enabled' },
const mockProjects = [
{ id: 123, name: 'abc', account_id: 1, status: 'enabled' },
{
id: 456,
name: 'xyz',
account_id: 1,
status: 'enabled',
extra_nested: { nested_value: [{ value_here: 1 }] },
},
];
const setupHandlers = () => {
@@ -55,7 +60,16 @@ describe('RollbarApi', () => {
setupHandlers();
const api = new RollbarApi('my-access-token', getVoidLogger());
const projects = await api.getAllProjects();
expect(projects).toEqual(mockProjects);
expect(projects).toEqual([
{ id: 123, name: 'abc', accountId: 1, status: 'enabled' },
{
id: 456,
name: 'xyz',
accountId: 1,
status: 'enabled',
extraNested: { nestedValue: [{ valueHere: 1 }] },
},
]);
});
});
});
+16 -1
View File
@@ -15,7 +15,7 @@
*/
import { Logger } from 'winston';
import camelize from 'camelize-ts';
import { camelCase } from 'lodash';
import { buildQuery } from '../util';
import {
RollbarItemCount,
@@ -30,6 +30,21 @@ const baseUrl = 'https://api.rollbar.com/api/1';
const buildUrl = (url: string) => `${baseUrl}${url}`;
function camelize<T extends unknown>(val: T): T {
if (typeof val === 'string') {
return camelCase(val) as T;
}
if (Array.isArray(val)) {
return val.map(camelize) as T;
}
if (val && typeof val === 'object') {
return Object.fromEntries(
Object.entries(val).map(([k, v]) => [camelize(k), camelize(v)]),
) as T;
}
return val;
}
/** @public */
export class RollbarApi {
private projectMap: ProjectMetadataMap | undefined;
-8
View File
@@ -7825,7 +7825,6 @@ __metadata:
"@backstage/config": "workspace:^"
"@types/express": ^4.17.6
"@types/supertest": ^2.0.8
camelize-ts: ^2.3.0
compression: ^1.7.4
cors: ^2.8.5
express: ^4.17.1
@@ -19242,13 +19241,6 @@ __metadata:
languageName: node
linkType: hard
"camelize-ts@npm:^2.3.0":
version: 2.3.0
resolution: "camelize-ts@npm:2.3.0"
checksum: 0f33c65468cc0883128bb15df96f244b21b94aa80094b358bda5a07db28b1f6e79fddb96b5af57cd754c6c8e07dc40ad2cb0d73b79b2ad584683babc57675ea6
languageName: node
linkType: hard
"camelize@npm:^1.0.0":
version: 1.0.0
resolution: "camelize@npm:1.0.0"