code cleanup
This commit is contained in:
parent
8607fdf9f1
commit
82b77906d7
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@openharbor/ngx-data",
|
||||
"version": "0.1.0",
|
||||
"version": "18.0.0-alpha.1",
|
||||
"dependencies": {
|
||||
"tslib": "^2.0.0"
|
||||
"tslib": "^2.7.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@angular/common": "^8.2.4",
|
||||
"@angular/core": "^8.2.4",
|
||||
"@angular/common": "^18.0.0",
|
||||
"@angular/core": "^18.0.0",
|
||||
"@poweredsoft/data": "^0.0.31",
|
||||
"rxjs": "^6.5.3"
|
||||
}
|
||||
|
@ -1,9 +1,19 @@
|
||||
import { HttpClient, HttpErrorResponse } from "@angular/common/http";
|
||||
import { DataSource, IDataSource, IDataSourceCommandAdapterOptions, IDataSourceError, IDataSourceErrorMessage, IDataSourceOptions, IDataSourceQueryAdapterOptions, IDataSourceTransportOptions, IDataSourceValidationError, IQueryCriteria, IResolveCommandModelEvent } from "@poweredsoft/data";
|
||||
import { Observable, of, throwError } from "rxjs";
|
||||
import { catchError, switchMap } from "rxjs/operators";
|
||||
|
||||
|
||||
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
|
||||
import {
|
||||
DataSource,
|
||||
IDataSource,
|
||||
IDataSourceCommandAdapterOptions,
|
||||
IDataSourceError,
|
||||
IDataSourceErrorMessage,
|
||||
IDataSourceOptions,
|
||||
IDataSourceQueryAdapterOptions,
|
||||
IDataSourceTransportOptions,
|
||||
IDataSourceValidationError,
|
||||
IQueryCriteria,
|
||||
IResolveCommandModelEvent
|
||||
} from "@poweredsoft/data";
|
||||
import {Observable, of, throwError} from "rxjs";
|
||||
import {catchError, switchMap} from "rxjs/operators";
|
||||
|
||||
export abstract class BaseHttpDataSourceOptionsBuilder<TModel, TKey> {
|
||||
protected _commands: { [key: string]: IDataSourceCommandAdapterOptions<any>; } = {};
|
||||
|
@ -1,15 +1,13 @@
|
||||
import { HttpClient, HttpResponse } from "@angular/common/http";
|
||||
import { IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult } from "@poweredsoft/data";
|
||||
import { Observable, of } from "rxjs";
|
||||
import { switchMap } from "rxjs/operators";
|
||||
import { BaseHttpDataSourceOptionsBuilder } from "./BaseHttpDataSourceOptionsBuilder";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult} from "@poweredsoft/data";
|
||||
import {Observable, of} from "rxjs";
|
||||
import {switchMap} from "rxjs/operators";
|
||||
import {BaseHttpDataSourceOptionsBuilder} from "./BaseHttpDataSourceOptionsBuilder";
|
||||
|
||||
export class HttpDataSourceOptionsBuilder<TModel, TKey>
|
||||
extends BaseHttpDataSourceOptionsBuilder<TModel, TKey>
|
||||
export class HttpDataSourceOptionsBuilder<TModel, TKey> extends BaseHttpDataSourceOptionsBuilder<TModel, TKey>
|
||||
{
|
||||
private _beforeRead: (TQuery: IQueryCriteria) => Observable<IQueryCriteria>;
|
||||
|
||||
|
||||
constructor(http: HttpClient) {
|
||||
super(http);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import { IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult, IQueryExecutionResultPaging } from "@poweredsoft/data";
|
||||
import { Observable, of } from "rxjs";
|
||||
import { map, switchMap } from "rxjs/operators";
|
||||
import { BaseHttpDataSourceOptionsBuilder } from "./BaseHttpDataSourceOptionsBuilder";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult} from "@poweredsoft/data";
|
||||
import {Observable, of} from "rxjs";
|
||||
import {map, switchMap} from "rxjs/operators";
|
||||
import {BaseHttpDataSourceOptionsBuilder} from "./BaseHttpDataSourceOptionsBuilder";
|
||||
|
||||
export class ListDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
||||
extends BaseHttpDataSourceOptionsBuilder<TModel, TKey>
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult, IQueryExecutionResultPaging } from '@poweredsoft/data';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { BaseHttpDataSourceOptionsBuilder } from './BaseHttpDataSourceOptionsBuilder';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult} from '@poweredsoft/data';
|
||||
import {Observable, of} from 'rxjs';
|
||||
import {map, switchMap} from 'rxjs/operators';
|
||||
import {BaseHttpDataSourceOptionsBuilder} from './BaseHttpDataSourceOptionsBuilder';
|
||||
|
||||
export class SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
||||
extends BaseHttpDataSourceOptionsBuilder<TModel, TKey> {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import {Inject, Injectable} from "@angular/core";
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { HttpDataSourceOptionsBuilder } from "./HttpDataSourceBuilder";
|
||||
import { SingleDataSourceOptionsBuilder } from "./SingleObjectDataSourceBuilder";
|
||||
@ -9,8 +9,7 @@ import { ListDataSourceOptionsBuilder } from "./ListDataSourceBuilder";
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class HttpDataSourceService {
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
@Inject(HttpClient) protected http!: HttpClient;
|
||||
|
||||
builder<TModel, TKey>() {
|
||||
return new HttpDataSourceOptionsBuilder<TModel, TKey>(this.http);
|
||||
|
@ -1,11 +0,0 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [],
|
||||
imports: [
|
||||
],
|
||||
exports: [],
|
||||
})
|
||||
export class NgxDataModule { }
|
@ -1,20 +1,44 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
||||
import { IDataSourceTransportOptions, IDataSourceCommandAdapterOptions, IDataSourceOptions, IResolveCommandModelEvent, IDataSourceError, IDataSourceErrorMessage, IDataSourceValidationError } from '@poweredsoft/data';
|
||||
import { IQueryExecutionResult, IQueryExecutionGroupResult, IQueryCriteria } from '@poweredsoft/data';
|
||||
import { IDataSourceQueryAdapterOptions } from '@poweredsoft/data';
|
||||
import { catchError, switchMap} from 'rxjs/operators';
|
||||
import { throwError, Observable, of } from 'rxjs';
|
||||
import {Inject, Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpErrorResponse} from '@angular/common/http';
|
||||
import {
|
||||
IDataSourceCommandAdapterOptions,
|
||||
IDataSourceError,
|
||||
IDataSourceErrorMessage,
|
||||
IDataSourceOptions,
|
||||
IDataSourceQueryAdapterOptions,
|
||||
IDataSourceTransportOptions,
|
||||
IDataSourceValidationError,
|
||||
IQueryCriteria,
|
||||
IQueryExecutionGroupResult,
|
||||
IQueryExecutionResult,
|
||||
IResolveCommandModelEvent
|
||||
} from '@poweredsoft/data';
|
||||
import {catchError, switchMap} from 'rxjs/operators';
|
||||
import {Observable, of, throwError} from 'rxjs';
|
||||
|
||||
/**
|
||||
* providedIn: "root"
|
||||
*
|
||||
* Automatic Injection: When you use providedIn: "root", Angular automatically
|
||||
* provides the service in the root injector, making it a singleton and available
|
||||
* throughout the application without needing any manual import in a module.
|
||||
*
|
||||
* Tree-shakable: This method is tree-shakable, meaning if the service is not
|
||||
* used anywhere in the application, it can be removed during the build process,
|
||||
* reducing the final bundle size.
|
||||
*
|
||||
* Convenience: It is simpler for the user, as they do not need to worry about
|
||||
* importing the module for the service. They can just inject the service wherever
|
||||
* they need it.
|
||||
*
|
||||
*/
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class GenericRestDataSourceService
|
||||
{
|
||||
constructor(private http: HttpClient) {
|
||||
|
||||
|
||||
}
|
||||
@Inject(HttpClient) protected http!: HttpClient;
|
||||
|
||||
private _handleErrorPipe(err: HttpErrorResponse) : Observable<IDataSourceError> {
|
||||
|
||||
@ -33,7 +57,7 @@ export class GenericRestDataSourceService
|
||||
errors: err.error.errors
|
||||
});
|
||||
|
||||
// if status not okay then its an exception error
|
||||
// if status not okay then it's an exception error
|
||||
if (err.error.hasOwnProperty('Message') && typeof(err.error['Message']) == "string") {
|
||||
return throwError(<IDataSourceErrorMessage>{
|
||||
type: 'message',
|
||||
@ -74,18 +98,15 @@ export class GenericRestDataSourceService
|
||||
}
|
||||
|
||||
createStandardRestTransportOptions<TModel, TKey>(route: string, keyResolver: (model: TModel) => TKey, beforeRead?: (query: IQueryCriteria) => Observable<IQueryCriteria>) : IDataSourceTransportOptions<TModel> {
|
||||
|
||||
const query: IDataSourceQueryAdapterOptions<TModel> = {
|
||||
adapter: {
|
||||
handle: (criteria: IQueryCriteria) => {
|
||||
const queryRoute = `${route}/read`;
|
||||
const finalBeforeRead = beforeRead || (t => of(criteria));
|
||||
return finalBeforeRead(criteria)
|
||||
.pipe(
|
||||
switchMap(finalQuery => {
|
||||
.pipe(switchMap(finalQuery => {
|
||||
return this.http.post<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>(queryRoute, finalQuery);
|
||||
})
|
||||
);
|
||||
}));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,7 +1,5 @@
|
||||
/*
|
||||
* Public API Surface of ngx-data
|
||||
*/
|
||||
|
||||
export * from './lib/ngx-data.service';
|
||||
export * from './lib/http-data-source-service.service'
|
||||
export * from './lib/ngx-data.module';
|
||||
|
Loading…
Reference in New Issue
Block a user