fix type strict errors
This commit is contained in:
parent
ce880013cc
commit
44f296cdf8
26
package.json
26
package.json
@ -12,26 +12,26 @@
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "^18.2.1",
|
||||
"@angular/common": "^18.2.1",
|
||||
"@angular/compiler": "^18.2.1",
|
||||
"@angular/core": "^18.2.1",
|
||||
"@angular/forms": "^18.2.1",
|
||||
"@angular/platform-browser": "^18.2.1",
|
||||
"@angular/platform-browser-dynamic": "^18.2.1",
|
||||
"@angular/router": "^18.2.1",
|
||||
"@angular/animations": "^18.0.0",
|
||||
"@angular/common": "^18.0.0",
|
||||
"@angular/compiler": "^18.0.0",
|
||||
"@angular/core": "^18.0.0",
|
||||
"@angular/forms": "^18.0.0",
|
||||
"@angular/platform-browser": "^18.0.0",
|
||||
"@angular/platform-browser-dynamic": "^18.0.0",
|
||||
"@angular/router": "^18.0.0",
|
||||
"@openharbor/data": "^1.0.0-alpha.1",
|
||||
"graphql": "^14.5.0",
|
||||
"graphql-tag": "^2.10.0",
|
||||
"rxjs": "~6.5.3",
|
||||
"rxjs": "~7.8.0",
|
||||
"tslib": "^2.0.0",
|
||||
"zone.js": "~0.14.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "^18.2.1",
|
||||
"@angular/cli": "^18.2.1",
|
||||
"@angular/compiler-cli": "^18.2.1",
|
||||
"@angular/language-service": "^18.2.1",
|
||||
"@angular-devkit/build-angular": "^18.0.0",
|
||||
"@angular/cli": "^18.0.0",
|
||||
"@angular/compiler-cli": "^18.0.0",
|
||||
"@angular/language-service": "^18.0.0",
|
||||
"@types/jasmine": "~3.6.0",
|
||||
"@types/jasminewd2": "~2.0.3",
|
||||
"@types/node": "^12.11.1",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@openharbor/ngx-data",
|
||||
"version": "18.0.0-alpha.6",
|
||||
"version": "18.0.0-alpha.7",
|
||||
"repository": "https://git.openharbor.io/Open-Harbor/ngx-data",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
@ -15,13 +15,13 @@ import {
|
||||
import {Observable, of, throwError} from "rxjs";
|
||||
import {catchError, switchMap} from "rxjs/operators";
|
||||
|
||||
export abstract class BaseHttpDataSourceOptionsBuilder<TQuery, TModel> {
|
||||
export abstract class BaseHttpDataSourceOptionsBuilder<TQuery extends IQueryCriteria, TModel extends {}> {
|
||||
protected _commands: { [key: string]: IDataSourceCommandAdapterOptions<any>; } = {};
|
||||
protected _keyResolver: (model: TModel) => TModel[keyof TModel];
|
||||
protected _defaultCriteria: IQueryCriteria;
|
||||
protected _query: IDataSourceQueryAdapterOptions<TQuery, TModel>;
|
||||
protected _keyResolver?: (model: TModel) => TModel[keyof TModel];
|
||||
protected _defaultCriteria!: IQueryCriteria;
|
||||
protected _query!: IDataSourceQueryAdapterOptions<TQuery, TModel>;
|
||||
|
||||
constructor(protected readonly http: HttpClient) {
|
||||
constructor(protected http: HttpClient) {
|
||||
}
|
||||
|
||||
createDataSource(): IDataSource<TQuery, TModel> {
|
||||
|
@ -2,12 +2,17 @@ import {IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult} from
|
||||
import {Observable, of} from "rxjs";
|
||||
import {switchMap} from "rxjs/operators";
|
||||
import {BaseHttpDataSourceOptionsBuilder} from "./BaseHttpDataSourceOptionsBuilder";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
|
||||
export class HttpDataSourceOptionsBuilder<TQuery extends IQueryCriteria, TModel> extends BaseHttpDataSourceOptionsBuilder<TQuery, TModel>
|
||||
export class HttpDataSourceOptionsBuilder<TQuery extends IQueryCriteria, TModel extends {}> extends BaseHttpDataSourceOptionsBuilder<TQuery, TModel>
|
||||
{
|
||||
private _beforeRead: (TQuery: IQueryCriteria) => Observable<IQueryCriteria>;
|
||||
constructor(http: HttpClient) {
|
||||
super(http);
|
||||
}
|
||||
|
||||
public beforeRead<TDynamicQuery extends IQueryCriteria>(beforeRead: (query: TDynamicQuery) => Observable<TDynamicQuery>) {
|
||||
private _beforeRead?: (query: IQueryCriteria) => Observable<TQuery>;
|
||||
|
||||
public beforeRead(beforeRead: (query: IQueryCriteria) => Observable<TQuery>) {
|
||||
this._beforeRead = beforeRead;
|
||||
return this;
|
||||
}
|
@ -2,11 +2,16 @@ import {IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult} from
|
||||
import {Observable, of} from "rxjs";
|
||||
import {map, switchMap} from "rxjs/operators";
|
||||
import {BaseHttpDataSourceOptionsBuilder} from "./BaseHttpDataSourceOptionsBuilder";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
|
||||
export class ListDataSourceOptionsBuilder<TQuery extends IQueryCriteria, TModel>
|
||||
export class ListDataSourceOptionsBuilder<TQuery extends IQueryCriteria, TModel extends {}>
|
||||
extends BaseHttpDataSourceOptionsBuilder<TQuery, TModel>
|
||||
{
|
||||
private _beforeRead: (query: IQueryCriteria) => Observable<TQuery>;
|
||||
private _beforeRead?: (query: IQueryCriteria) => Observable<TQuery>;
|
||||
|
||||
constructor(http: HttpClient) {
|
||||
super(http);
|
||||
}
|
||||
|
||||
public beforeRead(beforeRead: (query: IQueryCriteria) => Observable<TQuery>) {
|
||||
this._beforeRead = beforeRead;
|
||||
@ -41,10 +46,9 @@ export class ListDataSourceOptionsBuilder<TQuery extends IQueryCriteria, TModel>
|
||||
return this;
|
||||
}
|
||||
|
||||
protected convertToParams(finalQuery: TQuery)
|
||||
{
|
||||
protected convertToParams(finalQuery: TQuery) {
|
||||
return Object.keys(finalQuery).reduce((prev, key) => {
|
||||
prev[key] = finalQuery[key];
|
||||
prev[key] = (finalQuery as any)[key]; // Cast finalQuery to any to bypass the error
|
||||
return prev;
|
||||
}, {} as { [param: string]: string | string[]; });
|
||||
}
|
||||
|
@ -2,10 +2,15 @@ import {IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult} from
|
||||
import {Observable, of} from 'rxjs';
|
||||
import {map, switchMap} from 'rxjs/operators';
|
||||
import {BaseHttpDataSourceOptionsBuilder} from './BaseHttpDataSourceOptionsBuilder';
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
|
||||
export class SingleDataSourceOptionsBuilder<TQuery, TModel>
|
||||
export class SingleDataSourceOptionsBuilder<TQuery extends IQueryCriteria, TModel extends {}>
|
||||
extends BaseHttpDataSourceOptionsBuilder<TQuery, TModel> {
|
||||
private _beforeRead: (query: IQueryCriteria) => Observable<TQuery>;
|
||||
private _beforeRead?: (query: IQueryCriteria) => Observable<TQuery>;
|
||||
|
||||
constructor(http: HttpClient) {
|
||||
super(http);
|
||||
}
|
||||
|
||||
public beforeRead(beforeRead: (query: IQueryCriteria) => Observable<TQuery>) {
|
||||
this._beforeRead = beforeRead;
|
||||
@ -41,7 +46,7 @@ export class SingleDataSourceOptionsBuilder<TQuery, TModel>
|
||||
|
||||
protected convertToParams(finalQuery: TQuery) {
|
||||
return Object.keys(finalQuery).reduce((prev, key) => {
|
||||
prev[key] = finalQuery[key];
|
||||
prev[key] = (finalQuery as any)[key]; // Cast finalQuery to any to bypass the error
|
||||
return prev;
|
||||
}, {} as { [param: string]: string | string[]; });
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
import {inject, Inject, Injectable} from "@angular/core";
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { HttpDataSourceOptionsBuilder } from "./HttpDataSourceBuilder";
|
||||
import { SingleDataSourceOptionsBuilder } from "./SingleObjectDataSourceBuilder";
|
||||
import { ListDataSourceOptionsBuilder } from "./ListDataSourceBuilder";
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class HttpDataSourceService {
|
||||
protected http: HttpClient = inject(HttpClient);
|
||||
|
||||
builder<TQuery, TModel>() {
|
||||
return new HttpDataSourceOptionsBuilder<TQuery, TModel>(this.http);
|
||||
}
|
||||
|
||||
singleBuilder<TQuery, TModel>() {
|
||||
return new SingleDataSourceOptionsBuilder<TQuery, TModel>(this.http);
|
||||
}
|
||||
|
||||
listBuilder<TQuery, TModel>() {
|
||||
return new ListDataSourceOptionsBuilder<TQuery, TModel>(this.http);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
import {Injectable} from "@angular/core";
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {HttpDataSourceOptionsBuilder} from "./HttpDataSourceOptionsBuilder";
|
||||
import {SingleDataSourceOptionsBuilder} from "./SingleObjectDataSourceBuilder";
|
||||
import {ListDataSourceOptionsBuilder} from "./ListDataSourceBuilder";
|
||||
import {IQueryCriteria} from "@openharbor/data";
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class HttpDataSourceService {
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
builder<TQuery extends IQueryCriteria, TModel extends {}>() {
|
||||
return new HttpDataSourceOptionsBuilder<TQuery, TModel>(this.http);
|
||||
}
|
||||
|
||||
singleBuilder<TQuery extends IQueryCriteria, TModel extends {}>() {
|
||||
return new SingleDataSourceOptionsBuilder<TQuery, TModel>(this.http);
|
||||
}
|
||||
|
||||
listBuilder<TQuery extends IQueryCriteria, TModel extends {}>() {
|
||||
return new ListDataSourceOptionsBuilder<TQuery, TModel>(this.http);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import {Inject, Injectable} from '@angular/core';
|
||||
import {inject, Inject, Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpErrorResponse} from '@angular/common/http';
|
||||
import {
|
||||
ICommand,
|
||||
IDataSourceCommandAdapterOptions,
|
||||
IDataSourceError,
|
||||
IDataSourceErrorMessage,
|
||||
@ -21,7 +22,7 @@ import {Observable, of, throwError} from 'rxjs';
|
||||
})
|
||||
export class GenericRestDataSourceService
|
||||
{
|
||||
@Inject(HttpClient) protected http!: HttpClient;
|
||||
protected readonly http = inject(HttpClient);
|
||||
|
||||
private _handleErrorPipe(err: HttpErrorResponse) : Observable<IDataSourceError> {
|
||||
|
||||
@ -63,7 +64,7 @@ export class GenericRestDataSourceService
|
||||
});
|
||||
}
|
||||
|
||||
createDataSourceOptions<TQuery, TModel>(route: string, keyResolver: (model: TModel) => TModel[keyof TModel], defaultCriteria: IQueryCriteria, beforeRead?: (query: IQueryCriteria) => Observable<IQueryCriteria>) : IDataSourceOptions<TQuery, TModel>
|
||||
createDataSourceOptions<TQuery extends IQueryCriteria, TModel extends ICommand>(route: string, keyResolver: (model: TModel) => TModel[keyof TModel], defaultCriteria: IQueryCriteria, beforeRead?: (query: IQueryCriteria) => Observable<IQueryCriteria>) : IDataSourceOptions<TQuery, TModel>
|
||||
{
|
||||
const dataSourceTransportOptions = this.createStandardRestTransportOptions<TQuery, TModel>(route, keyResolver, beforeRead);
|
||||
|
||||
@ -74,11 +75,11 @@ export class GenericRestDataSourceService
|
||||
};
|
||||
}
|
||||
|
||||
setResolveCommand<TQuery, TModel>(options: IDataSourceOptions<TQuery, TModel>, name: string, resolveCommandModel: (event: IResolveCommandModelEvent<TModel>) => Observable<any>) {
|
||||
setResolveCommand<TQuery extends IQueryCriteria, TModel>(options: IDataSourceOptions<TQuery, TModel>, name: string, resolveCommandModel: (event: IResolveCommandModelEvent<TModel>) => Observable<any>) {
|
||||
options.transport.commands[name].resolveCommandModel = resolveCommandModel;
|
||||
}
|
||||
|
||||
createStandardRestTransportOptions<TQuery, TModel>(route: string, keyResolver: (model: TModel) => TModel[keyof TModel], beforeRead?: (query: IQueryCriteria) => Observable<IQueryCriteria>) : IDataSourceTransportOptions<TQuery, TModel> {
|
||||
createStandardRestTransportOptions<TQuery extends IQueryCriteria, TModel extends ICommand>(route: string, keyResolver: (model: TModel) => TModel[keyof TModel], beforeRead?: (query: IQueryCriteria) => Observable<IQueryCriteria>) : IDataSourceTransportOptions<TQuery, TModel> {
|
||||
const query: IDataSourceQueryAdapterOptions<TQuery, TModel> = {
|
||||
adapter: {
|
||||
handle: (criteria: IQueryCriteria) => {
|
||||
|
@ -2,4 +2,4 @@
|
||||
* Public API Surface of ngx-data
|
||||
*/
|
||||
export * from './lib/ngx-data.service';
|
||||
export * from './lib/http-data-source-service.service'
|
||||
export * from './lib/http-data-source.service'
|
||||
|
Loading…
Reference in New Issue
Block a user