fix some types and simplified back IDataSource generics
This commit is contained in:
parent
acffd90d47
commit
23df06b67f
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@openharbor/data",
|
"name": "@openharbor/data",
|
||||||
"version": "1.0.0-alpha.2",
|
"version": "1.0.0-alpha.4",
|
||||||
"repository": "https://git.openharbor.io/Open-Harbor/ts-data",
|
"repository": "https://git.openharbor.io/Open-Harbor/ts-data",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
@ -10,6 +10,6 @@ export interface ICommandAdapter<TCommand extends {}, TResult> {
|
|||||||
|
|
||||||
export interface IResolveCommandModelEvent<TModel> {
|
export interface IResolveCommandModelEvent<TModel> {
|
||||||
command: string;
|
command: string;
|
||||||
model: TModel;
|
model: Partial<TModel>;
|
||||||
params?: any;
|
params?: any;
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,12 @@ import {
|
|||||||
ISort
|
ISort
|
||||||
} from './query.abstraction';
|
} from './query.abstraction';
|
||||||
|
|
||||||
export interface IDataSource<TQuery extends IQueryCriteria, TModel>
|
export interface IDataSource<TModel>
|
||||||
{
|
{
|
||||||
resolveCommandModelByName<TCommand extends ICommand>(event: IResolveCommandModelEvent<TModel>) : Observable<TCommand>;
|
resolveCommandModelByName<TCommand extends ICommand>(event: IResolveCommandModelEvent<TModel>) : Observable<TCommand>;
|
||||||
executeCommandByName<TCommand extends ICommand, TResult>(name: string, command: TCommand) : Observable<TResult>;
|
executeCommandByName<TCommand extends ICommand, TResult>(name: string, command: TCommand) : Observable<TResult>;
|
||||||
query(query: TQuery): Subscription;
|
query<TQuery extends IQueryCriteria>(query: TQuery): Subscription;
|
||||||
executeQuery(query: TQuery): Observable<IQueryExecutionGroupResult<TModel>>;
|
executeQuery<TQuery extends IQueryCriteria>(query: TQuery): Observable<IQueryExecutionGroupResult<TModel>>;
|
||||||
refresh(): Subscription;
|
refresh(): Subscription;
|
||||||
resolveIdField(model: TModel) : TModel[keyof TModel];
|
resolveIdField(model: TModel) : TModel[keyof TModel];
|
||||||
clear(): void;
|
clear(): void;
|
||||||
@ -40,21 +40,21 @@ export interface IDataSource<TQuery extends IQueryCriteria, TModel>
|
|||||||
page: number;
|
page: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDataSourceOptions<TQuery extends IQueryCriteria, TResult>{
|
export interface IDataSourceOptions<TResult>{
|
||||||
transport: IDataSourceTransportOptions<TQuery, TResult>;
|
transport: IDataSourceTransportOptions<TResult>;
|
||||||
idField?: keyof TResult;
|
idField?: keyof TResult;
|
||||||
resolveIdField?: (model: TResult) => TResult[keyof TResult];
|
resolveIdField?: (model: TResult) => TResult[keyof TResult];
|
||||||
defaultCriteria: IQueryCriteria;
|
defaultCriteria: IQueryCriteria;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDataSourceTransportOptions<TQuery extends IQueryCriteria, TResult> {
|
export interface IDataSourceTransportOptions<TResult> {
|
||||||
query: IDataSourceQueryAdapterOptions<TQuery, TResult>;
|
query: IDataSourceQueryAdapterOptions<TResult>;
|
||||||
commands: {
|
commands: {
|
||||||
[name: string]: IDataSourceCommandAdapterOptions<TResult>;
|
[name: string]: IDataSourceCommandAdapterOptions<TResult>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDataSourceQueryAdapterOptions<TQuery extends IQueryCriteria, TResult> {
|
export interface IDataSourceQueryAdapterOptions<TResult, TQuery extends IQueryCriteria = IQueryCriteria> {
|
||||||
adapter: IAdvanceQueryAdapter<TQuery, TResult>;
|
adapter: IAdvanceQueryAdapter<TQuery, TResult>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import {
|
|||||||
import {ICommand, IResolveCommandModelEvent} from './abstractions/command.abstraction';
|
import {ICommand, IResolveCommandModelEvent} from './abstractions/command.abstraction';
|
||||||
|
|
||||||
|
|
||||||
export class DataSource<TQuery extends IQueryCriteria, TModel extends {}> implements IDataSource<TQuery, TModel>
|
export class DataSource<TModel extends {}> implements IDataSource<TModel>
|
||||||
{
|
{
|
||||||
data?: IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>;
|
data?: IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>;
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ export class DataSource<TQuery extends IQueryCriteria, TModel extends {}> implem
|
|||||||
return this._notifyMessage$;
|
return this._notifyMessage$;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(public options: IDataSourceOptions<TQuery, TModel>) {
|
constructor(public options: IDataSourceOptions<TModel>) {
|
||||||
this._initCriteria();
|
this._initCriteria();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ export class DataSource<TQuery extends IQueryCriteria, TModel extends {}> implem
|
|||||||
private _query() : Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>> {
|
private _query() : Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>> {
|
||||||
return new Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>((o: Observer<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>) => {
|
return new Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>((o: Observer<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>) => {
|
||||||
this._loadingSubject.next(true);
|
this._loadingSubject.next(true);
|
||||||
this.options.transport.query.adapter.handle(this._criteria as TQuery)
|
this.options.transport.query.adapter.handle(this._criteria)
|
||||||
.pipe(
|
.pipe(
|
||||||
finalize(() => {
|
finalize(() => {
|
||||||
o.complete();
|
o.complete();
|
||||||
@ -220,7 +220,7 @@ export class DataSource<TQuery extends IQueryCriteria, TModel extends {}> implem
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
query(query: TQuery) {
|
query<TQuery extends IQueryCriteria>(query: TQuery) {
|
||||||
this._criteria.page = query.page === undefined ? this._criteria.page:query.page;
|
this._criteria.page = query.page === undefined ? this._criteria.page:query.page;
|
||||||
this._criteria.pageSize = query.pageSize === undefined ? this._criteria.pageSize: query.pageSize;
|
this._criteria.pageSize = query.pageSize === undefined ? this._criteria.pageSize: query.pageSize;
|
||||||
this._criteria.filters = query.filters || this._criteria.filters;
|
this._criteria.filters = query.filters || this._criteria.filters;
|
||||||
@ -230,7 +230,7 @@ export class DataSource<TQuery extends IQueryCriteria, TModel extends {}> implem
|
|||||||
return this.refresh();
|
return this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
executeQuery(query: TQuery): Observable<IQueryExecutionGroupResult<TModel>>{
|
executeQuery<TQuery extends IQueryCriteria>(query: TQuery): Observable<IQueryExecutionGroupResult<TModel>>{
|
||||||
return this.options.transport.query.adapter.handle(query);
|
return this.options.transport.query.adapter.handle(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user