Skip to content

Commit

Permalink
fix: Fix transform-keys for primitive data
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Mar 25, 2021
1 parent c368011 commit 93c2a14
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Http } from './http';
import { AdminRepositories } from './repositories';

export class AdminFacadeRepositories {
constructor(readonly http: Http, readonly version: string) {}
constructor(private readonly http: Http, private readonly version: string) {}

readonly account = new AdminRepositories.AccountRepository(
this.http,
Expand Down
6 changes: 3 additions & 3 deletions src/masto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export interface SearchParams extends DefaultPaginationParams {

export class FacadeRepositories {
constructor(
readonly http: Http,
readonly ws: Ws,
private readonly http: Http,
private readonly ws: Ws,
readonly version: string,
readonly config: MastoConfig,
private readonly config: MastoConfig,
) {}

readonly admin = new AdminFacadeRepositories(this.http, this.version);
Expand Down
16 changes: 10 additions & 6 deletions src/serializers/transform-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ export const transformKeys = <T>(
return data.map((value) => transformKeys(value, transform)) as unknown as T;
}

return fromEntries<T>(
Object.entries(data).map(([key, value]) => [
transform(key),
isObject(value) ? transformKeys(value, transform) : value,
]) as any,
);
if (isObject(data)) {
return fromEntries<T>(
Object.entries(data).map(([key, value]) => [
transform(key),
isObject(value) ? transformKeys(value, transform) : value,
]) as any,
);
}

return data;
}

0 comments on commit 93c2a14

Please sign in to comment.