Skip to content

Commit

Permalink
Updates type naming, removes unused generics
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed Feb 6, 2025
1 parent d45a0e3 commit e336716
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/mappers/generic-element.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Contracts } from '../contracts';
import { ClientTypes as TClientTypes, IGenericElement } from '../models';
import { IGenericElement } from '../models';

export class GenericElementMapper<T extends TClientTypes> {
export class GenericElementMapper {
mapElement(response: Contracts.IViewContentTypeElementContract): IGenericElement {
if (!response) {
throw Error(`Invalid response for mapping element`);
Expand Down
4 changes: 2 additions & 2 deletions lib/mappers/sync.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Contracts } from '../contracts';
import { ClientTypes, IContentItemDelta } from '../models';
import { IContentItemDelta } from '../models';

export class SyncMapper<TClientTypes extends ClientTypes> {
export class SyncMapper {
mapContentItemDelta(itemDeltaContract: Contracts.IContentItemDeltaContract): IContentItemDelta {
const systemContract = itemDeltaContract.data.system;

Expand Down
14 changes: 8 additions & 6 deletions lib/mappers/type.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { Contracts } from '../contracts';
import { ClientTypes as TClientTypes, IContentType, IContentTypeSystemAttributes, IGenericElement } from '../models';
import { ClientTypes, IContentType, IContentTypeSystemAttributes, IGenericElement } from '../models';

export class TypeMapper<T extends TClientTypes> {
mapSingleType(response: Contracts.IViewContentTypeContract): IContentType<T['contentTypeCodenames']> {
export class TypeMapper<TClientTypes extends ClientTypes> {
mapSingleType(response: Contracts.IViewContentTypeContract): IContentType<TClientTypes['contentTypeCodenames']> {
return this.mapType(response);
}

mapMultipleTypes(response: Contracts.IListContentTypeContract): IContentType<T['contentTypeCodenames']>[] {
mapMultipleTypes(
response: Contracts.IListContentTypeContract
): IContentType<TClientTypes['contentTypeCodenames']>[] {
return response.types.map((type) => {
return this.mapType(type);
});
}

private mapType(type: Contracts.IContentTypeContract): IContentType<T['contentTypeCodenames']> {
private mapType(type: Contracts.IContentTypeContract): IContentType<TClientTypes['contentTypeCodenames']> {
if (!type) {
throw Error(`Cannot map type`);
}
Expand All @@ -21,7 +23,7 @@ export class TypeMapper<T extends TClientTypes> {
throw Error(`Cannot map type elements`);
}

const system: IContentTypeSystemAttributes<T['contentTypeCodenames']> = {
const system: IContentTypeSystemAttributes<TClientTypes['contentTypeCodenames']> = {
codename: type.system.codename,
id: type.system.id,
name: type.system.name,
Expand Down
4 changes: 2 additions & 2 deletions lib/services/mapping.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export class MappingService<TClientTypes extends ClientTypes> implements IMappin
private readonly languageMapper: LanguageMapper<TClientTypes>;
private readonly itemMapper: ItemMapper<TClientTypes>;
private readonly taxonomyMapper: TaxonomyMapper<TClientTypes>;
private readonly genericElementMapper: GenericElementMapper<TClientTypes>;
private readonly syncMapper: SyncMapper<TClientTypes>;
private readonly genericElementMapper: GenericElementMapper;
private readonly syncMapper: SyncMapper;

constructor(readonly config: IDeliveryClientConfig) {
this.typeMapper = new TypeMapper();
Expand Down

0 comments on commit e336716

Please sign in to comment.