code cleanup
This commit is contained in:
parent
8607fdf9f1
commit
82b77906d7
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@openharbor/ngx-data",
|
"name": "@openharbor/ngx-data",
|
||||||
"version": "0.1.0",
|
"version": "18.0.0-alpha.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.0.0"
|
"tslib": "^2.7.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@angular/common": "^8.2.4",
|
"@angular/common": "^18.0.0",
|
||||||
"@angular/core": "^8.2.4",
|
"@angular/core": "^18.0.0",
|
||||||
"@poweredsoft/data": "^0.0.31",
|
"@poweredsoft/data": "^0.0.31",
|
||||||
"rxjs": "^6.5.3"
|
"rxjs": "^6.5.3"
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,19 @@
|
|||||||
import { HttpClient, HttpErrorResponse } from "@angular/common/http";
|
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
|
||||||
import { DataSource, IDataSource, IDataSourceCommandAdapterOptions, IDataSourceError, IDataSourceErrorMessage, IDataSourceOptions, IDataSourceQueryAdapterOptions, IDataSourceTransportOptions, IDataSourceValidationError, IQueryCriteria, IResolveCommandModelEvent } from "@poweredsoft/data";
|
import {
|
||||||
import { Observable, of, throwError } from "rxjs";
|
DataSource,
|
||||||
import { catchError, switchMap } from "rxjs/operators";
|
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> {
|
export abstract class BaseHttpDataSourceOptionsBuilder<TModel, TKey> {
|
||||||
protected _commands: { [key: string]: IDataSourceCommandAdapterOptions<any>; } = {};
|
protected _commands: { [key: string]: IDataSourceCommandAdapterOptions<any>; } = {};
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
import { HttpClient, HttpResponse } from "@angular/common/http";
|
import {HttpClient} from "@angular/common/http";
|
||||||
import { IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult } from "@poweredsoft/data";
|
import {IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult} from "@poweredsoft/data";
|
||||||
import { Observable, of } from "rxjs";
|
import {Observable, of} from "rxjs";
|
||||||
import { switchMap } from "rxjs/operators";
|
import {switchMap} from "rxjs/operators";
|
||||||
import { BaseHttpDataSourceOptionsBuilder } from "./BaseHttpDataSourceOptionsBuilder";
|
import {BaseHttpDataSourceOptionsBuilder} from "./BaseHttpDataSourceOptionsBuilder";
|
||||||
|
|
||||||
export class HttpDataSourceOptionsBuilder<TModel, TKey>
|
export class HttpDataSourceOptionsBuilder<TModel, TKey> extends BaseHttpDataSourceOptionsBuilder<TModel, TKey>
|
||||||
extends BaseHttpDataSourceOptionsBuilder<TModel, TKey>
|
|
||||||
{
|
{
|
||||||
private _beforeRead: (TQuery: IQueryCriteria) => Observable<IQueryCriteria>;
|
private _beforeRead: (TQuery: IQueryCriteria) => Observable<IQueryCriteria>;
|
||||||
|
|
||||||
|
|
||||||
constructor(http: HttpClient) {
|
constructor(http: HttpClient) {
|
||||||
super(http);
|
super(http);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { HttpClient } from "@angular/common/http";
|
import {HttpClient} from "@angular/common/http";
|
||||||
import { IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult, IQueryExecutionResultPaging } from "@poweredsoft/data";
|
import {IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult} from "@poweredsoft/data";
|
||||||
import { Observable, of } from "rxjs";
|
import {Observable, of} from "rxjs";
|
||||||
import { map, switchMap } from "rxjs/operators";
|
import {map, switchMap} from "rxjs/operators";
|
||||||
import { BaseHttpDataSourceOptionsBuilder } from "./BaseHttpDataSourceOptionsBuilder";
|
import {BaseHttpDataSourceOptionsBuilder} from "./BaseHttpDataSourceOptionsBuilder";
|
||||||
|
|
||||||
export class ListDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
export class ListDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
||||||
extends BaseHttpDataSourceOptionsBuilder<TModel, TKey>
|
extends BaseHttpDataSourceOptionsBuilder<TModel, TKey>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { HttpClient } from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import { IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult, IQueryExecutionResultPaging } from '@poweredsoft/data';
|
import {IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult} from '@poweredsoft/data';
|
||||||
import { Observable, of } from 'rxjs';
|
import {Observable, of} from 'rxjs';
|
||||||
import { map, switchMap } from 'rxjs/operators';
|
import {map, switchMap} from 'rxjs/operators';
|
||||||
import { BaseHttpDataSourceOptionsBuilder } from './BaseHttpDataSourceOptionsBuilder';
|
import {BaseHttpDataSourceOptionsBuilder} from './BaseHttpDataSourceOptionsBuilder';
|
||||||
|
|
||||||
export class SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
export class SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
||||||
extends BaseHttpDataSourceOptionsBuilder<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 { HttpClient } from '@angular/common/http';
|
||||||
import { HttpDataSourceOptionsBuilder } from "./HttpDataSourceBuilder";
|
import { HttpDataSourceOptionsBuilder } from "./HttpDataSourceBuilder";
|
||||||
import { SingleDataSourceOptionsBuilder } from "./SingleObjectDataSourceBuilder";
|
import { SingleDataSourceOptionsBuilder } from "./SingleObjectDataSourceBuilder";
|
||||||
@ -9,8 +9,7 @@ import { ListDataSourceOptionsBuilder } from "./ListDataSourceBuilder";
|
|||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class HttpDataSourceService {
|
export class HttpDataSourceService {
|
||||||
constructor(private http: HttpClient) {
|
@Inject(HttpClient) protected http!: HttpClient;
|
||||||
}
|
|
||||||
|
|
||||||
builder<TModel, TKey>() {
|
builder<TModel, TKey>() {
|
||||||
return new HttpDataSourceOptionsBuilder<TModel, TKey>(this.http);
|
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 {Inject, Injectable} from '@angular/core';
|
||||||
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
import {HttpClient, HttpErrorResponse} from '@angular/common/http';
|
||||||
import { IDataSourceTransportOptions, IDataSourceCommandAdapterOptions, IDataSourceOptions, IResolveCommandModelEvent, IDataSourceError, IDataSourceErrorMessage, IDataSourceValidationError } from '@poweredsoft/data';
|
import {
|
||||||
import { IQueryExecutionResult, IQueryExecutionGroupResult, IQueryCriteria } from '@poweredsoft/data';
|
IDataSourceCommandAdapterOptions,
|
||||||
import { IDataSourceQueryAdapterOptions } from '@poweredsoft/data';
|
IDataSourceError,
|
||||||
import { catchError, switchMap} from 'rxjs/operators';
|
IDataSourceErrorMessage,
|
||||||
import { throwError, Observable, of } from 'rxjs';
|
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({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class GenericRestDataSourceService
|
export class GenericRestDataSourceService
|
||||||
{
|
{
|
||||||
constructor(private http: HttpClient) {
|
@Inject(HttpClient) protected http!: HttpClient;
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _handleErrorPipe(err: HttpErrorResponse) : Observable<IDataSourceError> {
|
private _handleErrorPipe(err: HttpErrorResponse) : Observable<IDataSourceError> {
|
||||||
|
|
||||||
@ -33,7 +57,7 @@ export class GenericRestDataSourceService
|
|||||||
errors: err.error.errors
|
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") {
|
if (err.error.hasOwnProperty('Message') && typeof(err.error['Message']) == "string") {
|
||||||
return throwError(<IDataSourceErrorMessage>{
|
return throwError(<IDataSourceErrorMessage>{
|
||||||
type: 'message',
|
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> {
|
createStandardRestTransportOptions<TModel, TKey>(route: string, keyResolver: (model: TModel) => TKey, beforeRead?: (query: IQueryCriteria) => Observable<IQueryCriteria>) : IDataSourceTransportOptions<TModel> {
|
||||||
|
|
||||||
const query: IDataSourceQueryAdapterOptions<TModel> = {
|
const query: IDataSourceQueryAdapterOptions<TModel> = {
|
||||||
adapter: {
|
adapter: {
|
||||||
handle: (criteria: IQueryCriteria) => {
|
handle: (criteria: IQueryCriteria) => {
|
||||||
const queryRoute = `${route}/read`;
|
const queryRoute = `${route}/read`;
|
||||||
const finalBeforeRead = beforeRead || (t => of(criteria));
|
const finalBeforeRead = beforeRead || (t => of(criteria));
|
||||||
return finalBeforeRead(criteria)
|
return finalBeforeRead(criteria)
|
||||||
.pipe(
|
.pipe(switchMap(finalQuery => {
|
||||||
switchMap(finalQuery => {
|
|
||||||
return this.http.post<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>(queryRoute, finalQuery);
|
return this.http.post<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>(queryRoute, finalQuery);
|
||||||
})
|
}));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Public API Surface of ngx-data
|
* Public API Surface of ngx-data
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './lib/ngx-data.service';
|
export * from './lib/ngx-data.service';
|
||||||
export * from './lib/http-data-source-service.service'
|
export * from './lib/http-data-source-service.service'
|
||||||
export * from './lib/ngx-data.module';
|
|
||||||
|
Loading…
Reference in New Issue
Block a user