code cleanup and version 1.0.0-alpha.1 release
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
|
||||
"dest": "../../dist/data",
|
||||
"lib": {
|
||||
"entryFile": "src/public-api.ts"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "@openharbor/data",
|
||||
"version": "1.0.0-alpha.1",
|
||||
"repository": "https://git.openharbor.io/Open-Harbor/ts-data",
|
||||
"peerDependencies": {
|
||||
"rxjs": "^6.5.3"
|
||||
}
|
||||
}
|
||||
+38
-40
@@ -9,10 +9,10 @@ import { IDataSourceError } from './IDataSourceError';
|
||||
import { IDataSourceNotifyMessage } from './IDataSourceNotifyMessage';
|
||||
import { IDataSourceCommandStarted } from './IDataSourceCommandStarted';
|
||||
|
||||
export class DataSource<TModel> implements IDataSource<TModel>
|
||||
export class DataSource<TModel> implements IDataSource<TModel>
|
||||
{
|
||||
data: IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel> = null;
|
||||
|
||||
|
||||
protected _dataSubject: BehaviorSubject<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>> = new BehaviorSubject(null);
|
||||
protected _loadingSubject: BehaviorSubject<boolean> = new BehaviorSubject(false);
|
||||
protected _validationSubject: Subject<IDataSourceValidationError> = new Subject();
|
||||
@@ -24,7 +24,7 @@ export class DataSource<TModel> implements IDataSource<TModel>
|
||||
protected _validationError$: Observable<IDataSourceValidationError>;
|
||||
protected _notifyMessage$: Observable<IDataSourceNotifyMessage>;
|
||||
protected _commandStarted$: Observable<IDataSourceCommandStarted>;
|
||||
|
||||
|
||||
protected _criteria: IQueryCriteria = {
|
||||
page: null,
|
||||
pageSize: null,
|
||||
@@ -107,7 +107,7 @@ export class DataSource<TModel> implements IDataSource<TModel>
|
||||
}
|
||||
|
||||
protected _initCriteria() {
|
||||
if (!this.options.defaultCriteria)
|
||||
if (!this.options.defaultCriteria)
|
||||
return;
|
||||
|
||||
const copy: IQueryCriteria = JSON.parse(JSON.stringify(this.options.defaultCriteria));
|
||||
@@ -120,10 +120,10 @@ export class DataSource<TModel> implements IDataSource<TModel>
|
||||
}
|
||||
|
||||
resolveIdField<TKeyType extends any>(model: TModel): TKeyType {
|
||||
|
||||
|
||||
if (this.options.idField)
|
||||
return model[this.options.idField];
|
||||
|
||||
|
||||
if (this.options.resolveIdField)
|
||||
return this.options.resolveIdField(model);
|
||||
|
||||
@@ -157,7 +157,7 @@ export class DataSource<TModel> implements IDataSource<TModel>
|
||||
map(t => {
|
||||
this._notifyMessageSubject.next({
|
||||
type: 'success',
|
||||
message: 'COMMAND_EXECUTED_SUCCESFULLY',
|
||||
message: 'COMMAND_EXECUTED_SUCCESSFULLY',
|
||||
messageParams: {
|
||||
command: name
|
||||
}
|
||||
@@ -179,34 +179,34 @@ export class DataSource<TModel> implements IDataSource<TModel>
|
||||
}
|
||||
|
||||
private _query() : Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>> {
|
||||
return Observable.create((o: Observer<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>) => {
|
||||
this._loadingSubject.next(true);
|
||||
this.options.transport.query.adapter.handle(this._criteria)
|
||||
.pipe(
|
||||
finalize(() => {
|
||||
o.complete();
|
||||
this._loadingSubject.next(false);
|
||||
})
|
||||
)
|
||||
.subscribe(
|
||||
result => {
|
||||
this.data = result;
|
||||
o.next(result);
|
||||
this._dataSubject.next(this.data);
|
||||
this._notifyMessageSubject.next({
|
||||
message: 'NEW_DATA_READ_SUCCESFULLY',
|
||||
type: 'info'
|
||||
});
|
||||
},
|
||||
err => {
|
||||
o.error(err);
|
||||
this._notifyMessageSubject.next({
|
||||
message: 'UNEXPECTED_ERROR_OCCURED',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
return new Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>((o: Observer<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>) => {
|
||||
this._loadingSubject.next(true);
|
||||
this.options.transport.query.adapter.handle(this._criteria)
|
||||
.pipe(
|
||||
finalize(() => {
|
||||
o.complete();
|
||||
this._loadingSubject.next(false);
|
||||
})
|
||||
)
|
||||
.subscribe(
|
||||
result => {
|
||||
this.data = result;
|
||||
o.next(result);
|
||||
this._dataSubject.next(this.data);
|
||||
this._notifyMessageSubject.next({
|
||||
message: 'NEW_DATA_READ_SUCCESSFULLY',
|
||||
type: 'info'
|
||||
});
|
||||
},
|
||||
err => {
|
||||
o.error(err);
|
||||
this._notifyMessageSubject.next({
|
||||
message: 'UNEXPECTED_ERROR_OCCURRED',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
query<TQuery extends IQueryCriteria>(query: TQuery) {
|
||||
@@ -219,15 +219,13 @@ export class DataSource<TModel> implements IDataSource<TModel>
|
||||
return this.refresh();
|
||||
}
|
||||
|
||||
excuteQuery<TQuery extends IQueryCriteria>(query: TQuery): Observable<IQueryExecutionGroupResult<TModel> & IQueryExecutionGroupResult<TModel>>{
|
||||
executeQuery<TQuery extends IQueryCriteria>(query: TQuery): Observable<IQueryExecutionGroupResult<TModel>>{
|
||||
return this.options.transport.query.adapter.handle(query);
|
||||
}
|
||||
|
||||
refresh() {
|
||||
return this._query().subscribe(
|
||||
res => {},
|
||||
err => {}
|
||||
);
|
||||
return this._query()
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
get sorts() {
|
||||
+2
-2
@@ -10,7 +10,7 @@ export interface IDataSource<TModel>
|
||||
resolveCommandModelByName<T extends any>(event: IResolveCommandModelEvent<TModel>) : Observable<T>;
|
||||
executeCommandByName<TCommand, TResult>(name: string, command: TCommand) : Observable<TResult>;
|
||||
query<TQuery extends IQueryCriteria>(query: TQuery);
|
||||
excuteQuery<TQuery extends IQueryCriteria>(query: TQuery): Observable<IQueryExecutionGroupResult<TModel> & IQueryExecutionGroupResult<TModel>>;
|
||||
executeQuery<TQuery extends IQueryCriteria>(query: TQuery): Observable<IQueryExecutionGroupResult<TModel> & IQueryExecutionGroupResult<TModel>>;
|
||||
refresh();
|
||||
resolveIdField<TKeyType extends any>(model: TModel) : TKeyType;
|
||||
clear();
|
||||
@@ -32,4 +32,4 @@ export interface IDataSource<TModel>
|
||||
aggregates: IAggregate[];
|
||||
pageSize: number;
|
||||
page: number;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../out-tsc/lib",
|
||||
"target": "es2015",
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../out-tsc/spec",
|
||||
"types": [
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "../../../tslint.json",
|
||||
"extends": "../../tslint.json",
|
||||
"rules": {
|
||||
"directive-selector": [
|
||||
true,
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
|
||||
"dest": "../../../dist/poweredsoft/data",
|
||||
"lib": {
|
||||
"entryFile": "src/public-api.ts"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"name": "@poweredsoft/data",
|
||||
"version": "0.0.36",
|
||||
"peerDependencies": {
|
||||
"rxjs": "^6.5.3"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user