Skip to content

Commit

Permalink
feat(interfaces): IAbstractMangoRepositoryBase
Browse files Browse the repository at this point in the history
  • Loading branch information
unicornware committed May 28, 2021
1 parent 073401f commit 9b976a6
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 14 deletions.
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,24 +264,42 @@ allow users to perform write operations on an object collection.
* @template Q - Parsed URL query object
*
* @extends IAbstractMangoFinder
* @extends IAbstractMangoRepositoryBase
*/
export interface IAbstractMangoRepository<
E extends ObjectPlain = ObjectUnknown,
U extends string = DUID,
P extends MangoSearchParams<E> = MangoSearchParams<E>,
Q extends MangoParsedUrlQuery<E> = MangoParsedUrlQuery<E>
> extends IAbstractMangoFinder<E, U, P, Q> {
readonly cache: MangoCacheRepo<E>
readonly options: MangoRepoOptions<E, U>
readonly validator: IMangoValidator<E>

> extends Omit<IAbstractMangoFinder<E, U, P, Q>, 'cache' | 'options'>,
IAbstractMangoRepositoryBase<E, U> {
clear(): OrPromise<boolean>
create(dto: CreateEntityDTO<E>): OrPromise<E>
delete(uid?: OneOrMany<UID>, should_exist?: boolean): OrPromise<UID[]>
patch(uid: UID, dto?: PatchEntityDTO<E>, rfields?: string[]): OrPromise<E>
setCache(collection?: E[]): OrPromise<MangoCacheRepo<E>>
save(dto?: OneOrMany<EntityDTO<E>>): OrPromise<E[]>
}

/**
* Base `AbstractMangoRepository` class interface.
*
* Used to define properties of `MangoRepository`, `MangoRepositoryAsync`,
* and possible derivatives.
*
* @template E - Entity
* @template U - Name of entity uid field
*
* @extends IAbstractMangoFinderBase
*/
export interface IAbstractMangoRepositoryBase<
E extends ObjectPlain = ObjectUnknown,
U extends string = DUID
> extends IAbstractMangoFinderBase<E, U> {
readonly cache: MangoCacheRepo<E>
readonly options: MangoRepoOptions<E, U>
readonly validator: IMangoValidator<E>
}
```

#### Modeling Entities
Expand Down
31 changes: 31 additions & 0 deletions src/interfaces/abstract-mango-repo-base.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { DUID } from '@/types'
import type { ObjectPlain, ObjectUnknown } from '@flex-development/tutils'
import type { IAbstractMangoFinderBase } from './abstract-mango-finder-base.interface'
import type { MangoCacheRepo } from './mango-cache-repo.interface'
import type { MangoRepoOptions } from './mango-repo-options.interface'
import type { IMangoValidator } from './mango-validator.interface'

/**
* @file Interface - IAbstractMangoRepositoryBase
* @module interfaces/AbstractMangoRepositoryBase
*/

/**
* Base `AbstractMangoRepository` class interface.
*
* Used to define properties of `MangoRepository`, `MangoRepositoryAsync`,
* and possible derivatives.
*
* @template E - Entity
* @template U - Name of entity uid field
*
* @extends IAbstractMangoFinderBase
*/
export interface IAbstractMangoRepositoryBase<
E extends ObjectPlain = ObjectUnknown,
U extends string = DUID
> extends IAbstractMangoFinderBase<E, U> {
readonly cache: MangoCacheRepo<E>
readonly options: MangoRepoOptions<E, U>
readonly validator: IMangoValidator<E>
}
11 changes: 4 additions & 7 deletions src/interfaces/abstract-mango-repo.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import type {
OrPromise
} from '@flex-development/tutils'
import type { IAbstractMangoFinder } from './abstract-mango-finder.interface'
import type { IAbstractMangoRepositoryBase } from './abstract-mango-repo-base.interface'
import type { MangoCacheRepo } from './mango-cache-repo.interface'
import type { MangoRepoOptions } from './mango-repo-options.interface'
import type { IMangoValidator } from './mango-validator.interface'

/**
* @file Interface - IAbstractMangoRepository
Expand All @@ -28,17 +27,15 @@ import type { IMangoValidator } from './mango-validator.interface'
* @template Q - Parsed URL query object
*
* @extends IAbstractMangoFinder
* @extends IAbstractMangoRepositoryBase
*/
export interface IAbstractMangoRepository<
E extends ObjectPlain = ObjectUnknown,
U extends string = DUID,
P extends MangoSearchParams<E> = MangoSearchParams<E>,
Q extends MangoParsedUrlQuery<E> = MangoParsedUrlQuery<E>
> extends IAbstractMangoFinder<E, U, P, Q> {
readonly cache: MangoCacheRepo<E>
readonly options: MangoRepoOptions<E, U>
readonly validator: IMangoValidator<E>

> extends Omit<IAbstractMangoFinder<E, U, P, Q>, 'cache' | 'options'>,
IAbstractMangoRepositoryBase<E, U> {
clear(): OrPromise<boolean>
create(dto: CreateEntityDTO<E>): OrPromise<E>
delete(uid?: OneOrMany<UID>, should_exist?: boolean): OrPromise<UID[]>
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

export type { IAbstractMangoFinderBase } from './abstract-mango-finder-base.interface'
export type { IAbstractMangoFinder } from './abstract-mango-finder.interface'
export type { IAbstractMangoRepositoryBase } from './abstract-mango-repo-base.interface'
export type { IAbstractMangoRepository } from './abstract-mango-repo.interface'
export type { AccumulatorOperators } from './accumulator-operators.interface'
export type { AggregationOperators } from './aggregation-operators.interface'
Expand Down
5 changes: 4 additions & 1 deletion src/interfaces/mango-repo-async.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
ObjectUnknown,
OneOrMany
} from '@flex-development/tutils'
import { IAbstractMangoRepositoryBase } from './abstract-mango-repo-base.interface'
import type { MangoCacheRepo } from './mango-cache-repo.interface'
import type { IMangoFinderAsync } from './mango-finder-async.interface'

Expand All @@ -24,13 +25,15 @@ import type { IMangoFinderAsync } from './mango-finder-async.interface'
* @template Q - Parsed URL query object
*
* @extends IMangoFinderAsync
* @extends IAbstractMangoRepositoryBase
*/
export interface IMangoRepositoryAsync<
E extends ObjectPlain = ObjectUnknown,
U extends string = DUID,
P extends MangoSearchParams<E> = MangoSearchParams<E>,
Q extends MangoParsedUrlQuery<E> = MangoParsedUrlQuery<E>
> extends IMangoFinderAsync<E, U, P, Q> {
> extends Omit<IMangoFinderAsync<E, U, P, Q>, 'cache' | 'options'>,
IAbstractMangoRepositoryBase<E, U> {
clear(): Promise<boolean>
create(dto: CreateEntityDTO<E>): Promise<E>
delete(uid?: OneOrMany<UID>, should_exist?: boolean): Promise<UID[]>
Expand Down
5 changes: 4 additions & 1 deletion src/interfaces/mango-repo.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
ObjectUnknown,
OneOrMany
} from '@flex-development/tutils'
import type { IAbstractMangoRepositoryBase } from './abstract-mango-repo-base.interface'
import type { MangoCacheRepo } from './mango-cache-repo.interface'
import type { IMangoFinder } from './mango-finder.interface'

Expand All @@ -24,13 +25,15 @@ import type { IMangoFinder } from './mango-finder.interface'
* @template Q - Parsed URL query object
*
* @extends IMangoFinder
* @extends IAbstractMangoRepositoryBase
*/
export interface IMangoRepository<
E extends ObjectPlain = ObjectUnknown,
U extends string = DUID,
P extends MangoSearchParams<E> = MangoSearchParams<E>,
Q extends MangoParsedUrlQuery<E> = MangoParsedUrlQuery<E>
> extends IMangoFinder<E, U, P, Q> {
> extends Omit<IMangoFinder<E, U, P, Q>, 'cache' | 'options'>,
IAbstractMangoRepositoryBase<E, U> {
clear(): boolean
create(dto: CreateEntityDTO<E>): E
delete(uid?: OneOrMany<UID>, should_exist?: boolean): UID[]
Expand Down

0 comments on commit 9b976a6

Please sign in to comment.