This repository has been archived by the owner on Sep 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
FRONTEND-8643 :: Feature :: Create NetworkDataSource repository providers #144
Open
orioljp
wants to merge
1
commit into
master
Choose a base branch
from
feature/frontend-8643-network-datasource-providers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
packages/core/src/repository/data-source/array-network.data-source.provider.ts
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,49 @@ | ||
import { ApiRequestService } from "./api-request.service"; | ||
import { Type } from "../../helpers"; | ||
import { DataSource, GetDataSource, PutDataSource } from "./data-source"; | ||
import { NetworkDataSource } from "./network.data-source"; | ||
import { DataSourceMapper, GetDataSourceMapper, PutDataSourceMapper } from "./data-source-mapper"; | ||
import { ArrayMapper, BlankMapper, JsonDeserializerMapper } from "../mapper/mapper"; | ||
|
||
export function provideGetArrayNetworkDataSource<T extends unknown | void>( | ||
requestService: ApiRequestService, | ||
type?: Type<T>, | ||
): GetDataSource<T[]> { | ||
const dataSource = new NetworkDataSource(requestService); | ||
return new GetDataSourceMapper( | ||
dataSource, | ||
type | ||
? new ArrayMapper(new JsonDeserializerMapper(type)) | ||
: new ArrayMapper(new BlankMapper()) | ||
); | ||
} | ||
|
||
export function providePutArrayNetworkDataSource<T extends unknown | void>( | ||
requestService: ApiRequestService, | ||
type?: Type<T>, | ||
): PutDataSource<T[]> { | ||
const dataSource = new NetworkDataSource(requestService); | ||
return new PutDataSourceMapper( | ||
dataSource, | ||
type | ||
? new ArrayMapper(new JsonDeserializerMapper(type)) | ||
: new ArrayMapper(new BlankMapper()), | ||
new ArrayMapper(new BlankMapper()), | ||
); | ||
} | ||
|
||
export function provideArrayNetworkDataSource<T extends unknown | void>( | ||
requestService: ApiRequestService, | ||
type?: Type<T>, | ||
): DataSource<T[]> { | ||
const dataSource = new NetworkDataSource(requestService); | ||
return new DataSourceMapper( | ||
dataSource, | ||
dataSource, | ||
dataSource, | ||
type | ||
? new ArrayMapper(new JsonDeserializerMapper(type)) | ||
: new ArrayMapper(new BlankMapper()), | ||
new ArrayMapper(new BlankMapper()), | ||
); | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/core/src/repository/data-source/network.data-source.provider.ts
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,39 @@ | ||
import { ApiRequestService } from "./api-request.service"; | ||
import { Type } from "../../helpers"; | ||
import { DataSource, DeleteDataSource, GetDataSource, PutDataSource } from "./data-source"; | ||
import { NetworkDataSource } from "./network.data-source"; | ||
import { DataSourceMapper, GetDataSourceMapper, PutDataSourceMapper } from "./data-source-mapper"; | ||
import { BlankMapper, JsonDeserializerMapper } from "../mapper/mapper"; | ||
|
||
export function provideNetworkDataSource<T extends unknown | void>(requestService: ApiRequestService, type?: Type<T>): DataSource<T> { | ||
const dataSource = new NetworkDataSource(requestService); | ||
return new DataSourceMapper( | ||
dataSource, | ||
dataSource, | ||
dataSource, | ||
type ? new JsonDeserializerMapper(type) : new BlankMapper<T>(), | ||
new BlankMapper<T>(), | ||
); | ||
} | ||
|
||
export function provideGetNetworkDataSource<T extends unknown | void>(requestService: ApiRequestService, type?: Type<T>): GetDataSource<T> { | ||
const dataSource = new NetworkDataSource(requestService); | ||
return new GetDataSourceMapper( | ||
dataSource, | ||
type ? new JsonDeserializerMapper(type) : new BlankMapper<T>(), | ||
); | ||
} | ||
|
||
export function providePutNetworkDataSource<T extends unknown | void>(requestService: ApiRequestService, type?: Type<T>): PutDataSource<T> { | ||
const dataSource = new NetworkDataSource(requestService); | ||
return new PutDataSourceMapper( | ||
dataSource, | ||
type ? new JsonDeserializerMapper(type) : new BlankMapper<T>(), | ||
new BlankMapper<T>(), | ||
); | ||
} | ||
|
||
export function provideDeleteNetworkDataSource(requestService: ApiRequestService): DeleteDataSource { | ||
return new NetworkDataSource(requestService); | ||
} | ||
|
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
62 changes: 62 additions & 0 deletions
62
packages/core/src/repository/network-array.repository-provider.ts
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,62 @@ | ||
import { GetRepository, PutRepository, Repository } from "./repository"; | ||
import { ArrayMapper, Mapper} from "./mapper/mapper"; | ||
import { | ||
SingleDataSourceRepository, | ||
SingleGetDataSourceRepository, | ||
SinglePutDataSourceRepository | ||
} from "./single-data-source.repository"; | ||
import { GetRepositoryMapper, PutRepositoryMapper, RepositoryMapper } from "./repository-mapper"; | ||
import { ApiRequestService } from "./data-source/api-request.service"; | ||
import { Type } from "../helpers"; | ||
import { | ||
provideArrayNetworkDataSource, | ||
provideGetArrayNetworkDataSource, | ||
providePutArrayNetworkDataSource | ||
} from "./data-source/array-network.data-source.provider"; | ||
|
||
export function provideGetArrayNetworkRepository<In, Out>( | ||
apiRequestService: ApiRequestService, | ||
toOutMapper: Mapper<In, Out>, | ||
type: Type<In> | ||
): GetRepository<Out[]> { | ||
const networkDatasource = provideGetArrayNetworkDataSource<In>(apiRequestService, type); | ||
const repository = new SingleGetDataSourceRepository(networkDatasource); | ||
return new GetRepositoryMapper<In[], Out[]>(repository, new ArrayMapper(toOutMapper)); | ||
} | ||
|
||
export function providePutArrayNetworkRepository<In, Out>( | ||
apiRequestService: ApiRequestService, | ||
toInMapper: Mapper<Out, In>, | ||
toOutMapper: Mapper<In, Out>, | ||
type: Type<In> | ||
): PutRepository<Out[]> { | ||
const networkDatasource = providePutArrayNetworkDataSource<In>(apiRequestService, type); | ||
const repository = new SinglePutDataSourceRepository(networkDatasource); | ||
return new PutRepositoryMapper<In[], Out[]>( | ||
repository, | ||
new ArrayMapper(toOutMapper), | ||
new ArrayMapper(toInMapper) | ||
); | ||
} | ||
|
||
export function provideArrayNetworkRepository<In, Out>( | ||
apiRequestService: ApiRequestService, | ||
toInMapper: Mapper<Out, In>, | ||
toOutMapper: Mapper<In, Out>, | ||
type: Type<In> | ||
): Repository<Out[]> { | ||
const networkDatasource = provideArrayNetworkDataSource<In>(apiRequestService, type); | ||
const repository = new SingleDataSourceRepository( | ||
networkDatasource, | ||
networkDatasource, | ||
networkDatasource | ||
); | ||
|
||
return new RepositoryMapper<In[], Out[]>( | ||
repository, | ||
repository, | ||
repository, | ||
new ArrayMapper(toOutMapper), | ||
new ArrayMapper(toInMapper) | ||
); | ||
} |
67 changes: 67 additions & 0 deletions
67
packages/core/src/repository/network.repository-provider.ts
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,67 @@ | ||
import { DeleteRepository, GetRepository, PutRepository } from "./repository"; | ||
import { Mapper } from "./mapper/mapper"; | ||
import { | ||
SingleDataSourceRepository, | ||
SingleDeleteDataSourceRepository, | ||
SingleGetDataSourceRepository, | ||
SinglePutDataSourceRepository | ||
} from "./single-data-source.repository"; | ||
import { GetRepositoryMapper, PutRepositoryMapper, RepositoryMapper } from "./repository-mapper"; | ||
import { ApiRequestService } from "./data-source/api-request.service"; | ||
import { Type } from "../helpers"; | ||
import { | ||
provideDeleteNetworkDataSource, | ||
provideGetNetworkDataSource, | ||
provideNetworkDataSource, | ||
providePutNetworkDataSource | ||
} from "./data-source/network.data-source.provider"; | ||
|
||
export function provideGetNetworkRepository<In, Out>( | ||
apiRequestService: ApiRequestService, | ||
toOutMapper: Mapper<In, Out>, | ||
type?: Type<In> | ||
): GetRepository<Out> { | ||
const networkDatasource = provideGetNetworkDataSource<In>(apiRequestService, type); | ||
const repository = new SingleGetDataSourceRepository(networkDatasource); | ||
return new GetRepositoryMapper<In, Out>(repository, toOutMapper); | ||
} | ||
|
||
export function providePutNetworkRepository<In, Out>( | ||
apiRequestService: ApiRequestService, | ||
toInMapper: Mapper<Out, In>, | ||
toOutMapper: Mapper<In, Out>, | ||
type?: Type<In> | ||
): PutRepository<Out> { | ||
const networkDatasource = providePutNetworkDataSource<In>(apiRequestService, type); | ||
const repository = new SinglePutDataSourceRepository(networkDatasource); | ||
return new PutRepositoryMapper<In, Out>(repository, toOutMapper, toInMapper); | ||
} | ||
|
||
export function provideDeleteNetworkRepository( | ||
apiRequestService: ApiRequestService | ||
): DeleteRepository { | ||
const networkDatasource = provideDeleteNetworkDataSource(apiRequestService); | ||
return new SingleDeleteDataSourceRepository(networkDatasource); | ||
} | ||
|
||
export function provideNetworkRepository<In, Out>( | ||
apiRequestService: ApiRequestService, | ||
toInMapper: Mapper<Out, In>, | ||
toOutMapper: Mapper<In, Out>, | ||
type?: Type<In> | ||
): PutRepository<Out> { | ||
const networkDatasource = provideNetworkDataSource<In>(apiRequestService, type); | ||
const repository = new SingleDataSourceRepository( | ||
networkDatasource, | ||
networkDatasource, | ||
networkDatasource | ||
); | ||
|
||
return new RepositoryMapper<In, Out>( | ||
repository, | ||
repository, | ||
repository, | ||
toOutMapper, | ||
toInMapper | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by
T extends unknown | void
? Isn't this the same as justT
? Also, regarding thevoid
, doesGetDataSource<void[]>
make sense? We can probably leave it as:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@doup The thing is that the generic type should allow void as a type, and having T you cannot create a
GetDataSource<void>
.Since this is a generic library, I didn't want to restrict the usage because the API might not be ours and might return nothing at some endpoint with a call of type GET. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me