update library to use @openharbor/data instead with refactorings
This commit is contained in:
parent
5aab276b2a
commit
dab175e12f
@ -7,7 +7,6 @@
|
|||||||
"build": "ng build",
|
"build": "ng build",
|
||||||
"test": "ng test",
|
"test": "ng test",
|
||||||
"lint": "ng lint",
|
"lint": "ng lint",
|
||||||
"e2e": "ng e2e",
|
|
||||||
"build-data": "ng build ngx-data --configuration production",
|
"build-data": "ng build ngx-data --configuration production",
|
||||||
"publish-data": "npm publish dist/openharbor/ngx-data --access public"
|
"publish-data": "npm publish dist/openharbor/ngx-data --access public"
|
||||||
},
|
},
|
||||||
@ -21,7 +20,7 @@
|
|||||||
"@angular/platform-browser": "^18.2.1",
|
"@angular/platform-browser": "^18.2.1",
|
||||||
"@angular/platform-browser-dynamic": "^18.2.1",
|
"@angular/platform-browser-dynamic": "^18.2.1",
|
||||||
"@angular/router": "^18.2.1",
|
"@angular/router": "^18.2.1",
|
||||||
"@poweredsoft/data": "0.0.32",
|
"@openharbor/data": "^1.0.0-alpha.1",
|
||||||
"graphql": "^14.5.0",
|
"graphql": "^14.5.0",
|
||||||
"graphql-tag": "^2.10.0",
|
"graphql-tag": "^2.10.0",
|
||||||
"rxjs": "~6.5.3",
|
"rxjs": "~6.5.3",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@openharbor/ngx-data",
|
"name": "@openharbor/ngx-data",
|
||||||
"version": "18.0.0-alpha.3",
|
"version": "18.0.0-alpha.4",
|
||||||
"repository": "https://git.openharbor.io/Open-Harbor/ngx-data",
|
"repository": "https://git.openharbor.io/Open-Harbor/ngx-data",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.7.0"
|
"tslib": "^2.7.0"
|
||||||
@ -8,7 +8,7 @@
|
|||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@angular/common": "^18.0.0",
|
"@angular/common": "^18.0.0",
|
||||||
"@angular/core": "^18.0.0",
|
"@angular/core": "^18.0.0",
|
||||||
"@poweredsoft/data": "^0.0.31",
|
"@openharbor/data": "^1.0.0",
|
||||||
"rxjs": "^6.5.3||^7.4.0"
|
"rxjs": "^6.5.3||^7.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,50 +11,47 @@ import {
|
|||||||
IDataSourceValidationError,
|
IDataSourceValidationError,
|
||||||
IQueryCriteria,
|
IQueryCriteria,
|
||||||
IResolveCommandModelEvent
|
IResolveCommandModelEvent
|
||||||
} from "@poweredsoft/data";
|
} from "@openharbor/data";
|
||||||
import {Observable, of, throwError} from "rxjs";
|
import {Observable, of, throwError} from "rxjs";
|
||||||
import {catchError, switchMap} from "rxjs/operators";
|
import {catchError, switchMap} from "rxjs/operators";
|
||||||
|
import {inject} from "@angular/core";
|
||||||
|
|
||||||
export abstract class BaseHttpDataSourceOptionsBuilder<TModel, TKey> {
|
export abstract class BaseHttpDataSourceOptionsBuilder<TQuery, TModel> {
|
||||||
protected _commands: { [key: string]: IDataSourceCommandAdapterOptions<any>; } = {};
|
protected _commands: { [key: string]: IDataSourceCommandAdapterOptions<any>; } = {};
|
||||||
protected _keyResolver: (model: TModel) => TKey;
|
protected _keyResolver: (model: TModel) => TModel[keyof TModel];
|
||||||
protected _defaultCriteria: IQueryCriteria;
|
protected _defaultCriteria: IQueryCriteria;
|
||||||
protected _query: IDataSourceQueryAdapterOptions<TModel>;
|
protected _query: IDataSourceQueryAdapterOptions<TQuery, TModel>;
|
||||||
|
|
||||||
constructor(protected http: HttpClient) {
|
readonly http: HttpClient = inject(HttpClient);
|
||||||
|
|
||||||
|
createDataSource(): IDataSource<TQuery, TModel> {
|
||||||
|
return new DataSource<TQuery, TModel>(this.createOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
createDataSource(): IDataSource<TModel> {
|
protected createTransport(): IDataSourceTransportOptions<TQuery, TModel> {
|
||||||
return new DataSource<TModel>(this.createOptions());
|
return {
|
||||||
}
|
|
||||||
|
|
||||||
protected createTransport(): IDataSourceTransportOptions<TModel> {
|
|
||||||
let ret: IDataSourceTransportOptions<TModel> = {
|
|
||||||
query: this._query,
|
query: this._query,
|
||||||
commands: this._commands
|
commands: this._commands
|
||||||
};
|
};
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public keyResolver(resolver: (model: TModel) => TKey) {
|
public keyResolver(resolver: (model: TModel) => TModel[keyof TModel]) {
|
||||||
this._keyResolver = resolver;
|
this._keyResolver = resolver;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
createOptions(): IDataSourceOptions<TModel> {
|
createOptions(): IDataSourceOptions<TQuery, TModel> {
|
||||||
let ret: IDataSourceOptions<TModel> = {
|
return {
|
||||||
resolveIdField: this._keyResolver,
|
resolveIdField: this._keyResolver,
|
||||||
defaultCriteria: this._defaultCriteria,
|
defaultCriteria: this._defaultCriteria,
|
||||||
transport: this.createTransport()
|
transport: this.createTransport()
|
||||||
};
|
};
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _messageErrorHandler(err: HttpErrorResponse) {
|
private _messageErrorHandler(err: HttpErrorResponse) {
|
||||||
|
|
||||||
if (typeof err.error == "object") {
|
if (typeof err.error == "object") {
|
||||||
// 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',
|
||||||
@ -96,11 +93,8 @@ export abstract class BaseHttpDataSourceOptionsBuilder<TModel, TKey> {
|
|||||||
return this._messageErrorHandler(err);
|
return this._messageErrorHandler(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public addCommandByCallback<TCommand, TCommandResult>(name: string, commandHandler: (command: TCommand) => Observable<TCommandResult>, resolveCommandModel?: (event: IResolveCommandModelEvent<TModel>) => Observable<TCommand & any>) {
|
public addCommandByCallback<TCommand, TCommandResult>(name: string, commandHandler: (command: TCommand) => Observable<TCommandResult>, resolveCommandModel?: (event: IResolveCommandModelEvent<TModel>) => Observable<TCommand & any>) {
|
||||||
const handleWrapper = command => {
|
const handleWrapper = (command: TCommand) => {
|
||||||
return commandHandler(command).pipe(catchError(this._handleErrorPipe.bind(this)));
|
return commandHandler(command).pipe(catchError(this._handleErrorPipe.bind(this)));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -115,7 +109,7 @@ export abstract class BaseHttpDataSourceOptionsBuilder<TModel, TKey> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public addCommandByUrl<TCommand, TCommandResult>(name: string, url: string, resolveCommandModel?: (event: IResolveCommandModelEvent<TModel>) => Observable<TCommand & any>, beforeCommand?: (command: TCommand) => Observable<TCommand>) {
|
public addCommandByUrl<TCommand, TCommandResult>(name: string, url: string, resolveCommandModel?: (event: IResolveCommandModelEvent<TModel>) => Observable<TCommand & any>, beforeCommand?: (command: TCommand) => Observable<TCommand>) {
|
||||||
const handleWrapper = command => {
|
const handleWrapper = (command: TCommand) => {
|
||||||
const finalBeforeCommand = beforeCommand || (_ => of(command));
|
const finalBeforeCommand = beforeCommand || (_ => of(command));
|
||||||
return finalBeforeCommand(command)
|
return finalBeforeCommand(command)
|
||||||
.pipe(
|
.pipe(
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
import {HttpClient} from "@angular/common/http";
|
import {IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult} from "@openharbor/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> extends BaseHttpDataSourceOptionsBuilder<TModel, TKey>
|
export class HttpDataSourceOptionsBuilder<TQuery extends IQueryCriteria, TModel> extends BaseHttpDataSourceOptionsBuilder<TQuery, TModel>
|
||||||
{
|
{
|
||||||
private _beforeRead: (TQuery: IQueryCriteria) => Observable<IQueryCriteria>;
|
private _beforeRead: (TQuery: IQueryCriteria) => Observable<IQueryCriteria>;
|
||||||
|
|
||||||
constructor(http: HttpClient) {
|
|
||||||
super(http);
|
|
||||||
}
|
|
||||||
|
|
||||||
public beforeRead<TDynamicQuery extends IQueryCriteria>(beforeRead: (query: TDynamicQuery) => Observable<TDynamicQuery>) {
|
public beforeRead<TDynamicQuery extends IQueryCriteria>(beforeRead: (query: TDynamicQuery) => Observable<TDynamicQuery>) {
|
||||||
this._beforeRead = beforeRead;
|
this._beforeRead = beforeRead;
|
||||||
return this;
|
return this;
|
||||||
@ -21,7 +16,7 @@ export class HttpDataSourceOptionsBuilder<TModel, TKey> extends BaseHttpDataSour
|
|||||||
this._query = {
|
this._query = {
|
||||||
adapter: {
|
adapter: {
|
||||||
handle: (query: IQueryCriteria) => {
|
handle: (query: IQueryCriteria) => {
|
||||||
const finalBeforeRead = this._beforeRead || (t => of(query));
|
const finalBeforeRead = this._beforeRead || (() => of(query));
|
||||||
return finalBeforeRead(query)
|
return finalBeforeRead(query)
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(finalQuery => {
|
switchMap(finalQuery => {
|
||||||
@ -35,11 +30,11 @@ export class HttpDataSourceOptionsBuilder<TModel, TKey> extends BaseHttpDataSour
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public queryHandler<TQuery extends IQueryCriteria>(queryHandler: (query: TQuery) => Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>) {
|
public queryHandler(queryHandler: (query: TQuery) => Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>) {
|
||||||
this._query = {
|
this._query = {
|
||||||
adapter: {
|
adapter: {
|
||||||
handle: (query: TQuery) => {
|
handle: (query: TQuery) => {
|
||||||
const finalBeforeRead = this._beforeRead || (t => of(query));
|
const finalBeforeRead = this._beforeRead || (() => of(query));
|
||||||
return finalBeforeRead(query)
|
return finalBeforeRead(query)
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(finalQuery => {
|
switchMap(finalQuery => {
|
||||||
@ -49,7 +44,6 @@ export class HttpDataSourceOptionsBuilder<TModel, TKey> extends BaseHttpDataSour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +1,13 @@
|
|||||||
import {HttpClient} from "@angular/common/http";
|
import {IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult} from "@openharbor/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 extends IQueryCriteria, TModel>
|
||||||
extends BaseHttpDataSourceOptionsBuilder<TModel, TKey>
|
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>) {
|
public beforeRead(beforeRead: (query: IQueryCriteria) => Observable<TQuery>) {
|
||||||
this._beforeRead = beforeRead;
|
this._beforeRead = beforeRead;
|
||||||
return this;
|
return this;
|
||||||
@ -75,7 +70,7 @@ export class ListDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -84,7 +79,7 @@ export class ListDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
|||||||
this._query = {
|
this._query = {
|
||||||
adapter: {
|
adapter: {
|
||||||
handle: (query: TQuery) => {
|
handle: (query: TQuery) => {
|
||||||
const finalBeforeRead = this._beforeRead || (t => of({}));
|
const finalBeforeRead = this._beforeRead || (() => of({}));
|
||||||
return finalBeforeRead(query)
|
return finalBeforeRead(query)
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(finalQuery => {
|
switchMap(finalQuery => {
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
import {HttpClient} from '@angular/common/http';
|
import {IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult} from '@openharbor/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>
|
||||||
extends BaseHttpDataSourceOptionsBuilder<TModel, TKey> {
|
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>) {
|
public beforeRead(beforeRead: (query: IQueryCriteria) => Observable<TQuery>) {
|
||||||
this._beforeRead = beforeRead;
|
this._beforeRead = beforeRead;
|
||||||
return this;
|
return this;
|
||||||
@ -21,7 +16,7 @@ export class SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
|||||||
this._query = {
|
this._query = {
|
||||||
adapter: {
|
adapter: {
|
||||||
handle: (query: IQueryCriteria) => {
|
handle: (query: IQueryCriteria) => {
|
||||||
const finalBeforeRead = this._beforeRead || ((query: IQueryCriteria) => of({} as TQuery));
|
const finalBeforeRead = this._beforeRead || (() => of({} as TQuery));
|
||||||
return finalBeforeRead(query)
|
return finalBeforeRead(query)
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(finalQuery => {
|
switchMap(finalQuery => {
|
||||||
@ -80,7 +75,7 @@ export class SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
|||||||
this._query = {
|
this._query = {
|
||||||
adapter: {
|
adapter: {
|
||||||
handle: (query: TQuery) => {
|
handle: (query: TQuery) => {
|
||||||
const finalBeforeRead = this._beforeRead || (t => of({}));
|
const finalBeforeRead = this._beforeRead || (() => of({}));
|
||||||
return finalBeforeRead(query)
|
return finalBeforeRead(query)
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(finalQuery => {
|
switchMap(finalQuery => {
|
||||||
|
@ -11,15 +11,15 @@ import { ListDataSourceOptionsBuilder } from "./ListDataSourceBuilder";
|
|||||||
export class HttpDataSourceService {
|
export class HttpDataSourceService {
|
||||||
@Inject(HttpClient) protected http!: HttpClient;
|
@Inject(HttpClient) protected http!: HttpClient;
|
||||||
|
|
||||||
builder<TModel, TKey>() {
|
builder<TQuery, TModel>() {
|
||||||
return new HttpDataSourceOptionsBuilder<TModel, TKey>(this.http);
|
return new HttpDataSourceOptionsBuilder<TQuery, TModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
singleBuilder<TQuery, TModel, TKey>() {
|
singleBuilder<TQuery, TModel>() {
|
||||||
return new SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>(this.http);
|
return new SingleDataSourceOptionsBuilder<TQuery, TModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
listBuilder<TQuery, TModel, TKey>() {
|
listBuilder<TQuery, TModel>() {
|
||||||
return new ListDataSourceOptionsBuilder<TQuery, TModel, TKey>(this.http);
|
return new ListDataSourceOptionsBuilder<TQuery, TModel>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
import {
|
||||||
|
DataSource,
|
||||||
|
IDataSource,
|
||||||
|
IDataSourceCommandAdapterOptions,
|
||||||
|
IDataSourceOptions,
|
||||||
|
IDataSourceQueryAdapterOptions,
|
||||||
|
IDataSourceTransportOptions,
|
||||||
|
IQueryCriteria
|
||||||
|
} from "@openharbor/data";
|
||||||
|
|
||||||
|
export abstract class InMemoryDataSourceOptionBuilderAbstraction<TQuery, TModel> {
|
||||||
|
protected _commands: { [key: string]: IDataSourceCommandAdapterOptions<any>; } = {};
|
||||||
|
protected _keyResolver: (model: TModel) => TModel[keyof TModel];
|
||||||
|
protected _defaultCriteria: IQueryCriteria;
|
||||||
|
protected _query: IDataSourceQueryAdapterOptions<TQuery, TModel>;
|
||||||
|
|
||||||
|
createDataSource(): IDataSource<TQuery, TModel> {
|
||||||
|
return new DataSource<TQuery, TModel>(this.createOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
createOptions(): IDataSourceOptions<TQuery, TModel> {
|
||||||
|
return {
|
||||||
|
resolveIdField: this._keyResolver,
|
||||||
|
defaultCriteria: this._defaultCriteria,
|
||||||
|
transport: this.createTransport()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected createTransport(): IDataSourceTransportOptions<TQuery, TModel> {
|
||||||
|
return {
|
||||||
|
query: this._query,
|
||||||
|
commands: this._commands
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -12,27 +12,10 @@ import {
|
|||||||
IQueryExecutionGroupResult,
|
IQueryExecutionGroupResult,
|
||||||
IQueryExecutionResult,
|
IQueryExecutionResult,
|
||||||
IResolveCommandModelEvent
|
IResolveCommandModelEvent
|
||||||
} from '@poweredsoft/data';
|
} from '@openharbor/data';
|
||||||
import {catchError, switchMap} from 'rxjs/operators';
|
import {catchError, switchMap} from 'rxjs/operators';
|
||||||
import {Observable, of, throwError} from 'rxjs';
|
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'
|
||||||
})
|
})
|
||||||
@ -80,29 +63,27 @@ export class GenericRestDataSourceService
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createDataSourceOptions<TModel, TKey>(route: string, keyResolver: (model: TModel) => TKey, defaultCriteria: IQueryCriteria, beforeRead?: (query: IQueryCriteria) => Observable<IQueryCriteria>) : IDataSourceOptions<TModel>
|
createDataSourceOptions<TQuery, TModel>(route: string, keyResolver: (model: TModel) => TModel[keyof TModel], defaultCriteria: IQueryCriteria, beforeRead?: (query: IQueryCriteria) => Observable<IQueryCriteria>) : IDataSourceOptions<TQuery, TModel>
|
||||||
{
|
{
|
||||||
const dataSourceTransportOptions = this.createStandardRestTransportOptions<TModel, TKey>(route, keyResolver, beforeRead);
|
const dataSourceTransportOptions = this.createStandardRestTransportOptions<TQuery, TModel>(route, keyResolver, beforeRead);
|
||||||
|
|
||||||
const dataSourceOptions: IDataSourceOptions<TModel> = {
|
return {
|
||||||
defaultCriteria: defaultCriteria,
|
defaultCriteria: defaultCriteria,
|
||||||
resolveIdField: keyResolver,
|
resolveIdField: keyResolver,
|
||||||
transport: dataSourceTransportOptions
|
transport: dataSourceTransportOptions
|
||||||
};
|
};
|
||||||
|
|
||||||
return dataSourceOptions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setResolveCommand<TModel>(options: IDataSourceOptions<TModel>, name: string, resolveCommandModel: (event: IResolveCommandModelEvent<TModel>) => Observable<any>) {
|
setResolveCommand<TQuery, TModel>(options: IDataSourceOptions<TQuery, TModel>, name: string, resolveCommandModel: (event: IResolveCommandModelEvent<TModel>) => Observable<any>) {
|
||||||
options.transport.commands[name].resolveCommandModel = resolveCommandModel;
|
options.transport.commands[name].resolveCommandModel = resolveCommandModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
createStandardRestTransportOptions<TModel, TKey>(route: string, keyResolver: (model: TModel) => TKey, beforeRead?: (query: IQueryCriteria) => Observable<IQueryCriteria>) : IDataSourceTransportOptions<TModel> {
|
createStandardRestTransportOptions<TQuery, TModel>(route: string, keyResolver: (model: TModel) => TModel[keyof TModel], beforeRead?: (query: IQueryCriteria) => Observable<IQueryCriteria>) : IDataSourceTransportOptions<TQuery, TModel> {
|
||||||
const query: IDataSourceQueryAdapterOptions<TModel> = {
|
const query: IDataSourceQueryAdapterOptions<TQuery, 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 || (() => of(criteria));
|
||||||
return finalBeforeRead(criteria)
|
return finalBeforeRead(criteria)
|
||||||
.pipe(switchMap(finalQuery => {
|
.pipe(switchMap(finalQuery => {
|
||||||
return this.http.post<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>(queryRoute, finalQuery);
|
return this.http.post<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>(queryRoute, finalQuery);
|
||||||
|
@ -5,7 +5,7 @@ import { Routes, RouterModule } from '@angular/router';
|
|||||||
const routes: Routes = [];
|
const routes: Routes = [];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' })],
|
imports: [RouterModule.forRoot(routes)],
|
||||||
exports: [RouterModule]
|
exports: [RouterModule]
|
||||||
})
|
})
|
||||||
export class AppRoutingModule { }
|
export class AppRoutingModule { }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {Component, OnInit} from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import {of} from 'rxjs';
|
import {of} from 'rxjs';
|
||||||
import {IDataSource, IQueryCriteria} from '@poweredsoft/data';
|
import {IDataSource, IQueryCriteria} from '@openharbor/data';
|
||||||
import {HttpDataSourceService} from '@openharbor/ngx-data';
|
import {HttpDataSourceService} from '@openharbor/ngx-data';
|
||||||
|
|
||||||
export interface IContact
|
export interface IContact
|
||||||
@ -24,17 +24,17 @@ export interface IEchoCommand {
|
|||||||
message: string;
|
message: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IMyQuery extends IQueryCriteria{
|
export interface IMyQuery extends IQueryCriteria {
|
||||||
params: {
|
params: {
|
||||||
showDisabled: boolean;
|
showDisabled: boolean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IOnePersonQuery {
|
export interface IOnePersonQuery extends IQueryCriteria {
|
||||||
personId: number;
|
personId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IListPersonQuery {
|
export interface IListPersonQuery extends IQueryCriteria {
|
||||||
search?: string;
|
search?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,17 +45,17 @@ export interface IListPersonQuery {
|
|||||||
})
|
})
|
||||||
export class AppComponent implements OnInit {
|
export class AppComponent implements OnInit {
|
||||||
title = 'ngx-data';
|
title = 'ngx-data';
|
||||||
dataSource: IDataSource<IContact>;
|
dataSource: IDataSource<IMyQuery, IContact>;
|
||||||
latestData: any;
|
latestData: any;
|
||||||
|
|
||||||
onePersonDs: IDataSource<IPerson>;
|
onePersonDs: IDataSource<IOnePersonQuery, IPerson>;
|
||||||
listPersonDs: IDataSource<IPerson>;
|
listPersonDs: IDataSource<IListPersonQuery, IPerson>;
|
||||||
latestSingle: any;
|
latestSingle: any;
|
||||||
latestList: any;
|
latestList: any;
|
||||||
|
|
||||||
constructor(private hdss: HttpDataSourceService) {
|
constructor(private hdss: HttpDataSourceService) {
|
||||||
|
|
||||||
this.onePersonDs = hdss.singleBuilder<IOnePersonQuery, IPerson, number>()
|
this.onePersonDs = hdss.singleBuilder<IOnePersonQuery, IPerson>()
|
||||||
.keyResolver(t => t.id)
|
.keyResolver(t => t.id)
|
||||||
.queryUrl('https://localhost:5001/api/query/onePerson')
|
.queryUrl('https://localhost:5001/api/query/onePerson')
|
||||||
.beforeRead(_ => {
|
.beforeRead(_ => {
|
||||||
@ -65,7 +65,7 @@ export class AppComponent implements OnInit {
|
|||||||
})
|
})
|
||||||
.createDataSource();
|
.createDataSource();
|
||||||
|
|
||||||
this.listPersonDs = hdss.listBuilder<IListPersonQuery, IPerson, number>()
|
this.listPersonDs = hdss.listBuilder<IListPersonQuery, IPerson>()
|
||||||
.keyResolver(t => t.id)
|
.keyResolver(t => t.id)
|
||||||
.queryUrl('https://localhost:5001/api/query/listPerson')
|
.queryUrl('https://localhost:5001/api/query/listPerson')
|
||||||
.beforeRead(criteria => {
|
.beforeRead(criteria => {
|
||||||
@ -76,7 +76,7 @@ export class AppComponent implements OnInit {
|
|||||||
.createDataSource();
|
.createDataSource();
|
||||||
|
|
||||||
const ds = hdss
|
const ds = hdss
|
||||||
.builder<IContact, number>()
|
.builder<IMyQuery, IContact>()
|
||||||
.keyResolver(m => m.id)
|
.keyResolver(m => m.id)
|
||||||
.defaultCriteria({
|
.defaultCriteria({
|
||||||
page: 1,
|
page: 1,
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { BrowserModule } from '@angular/platform-browser';
|
import {BrowserModule} from '@angular/platform-browser';
|
||||||
import { NgModule } from '@angular/core';
|
import {NgModule} from '@angular/core';
|
||||||
|
|
||||||
import { AppRoutingModule } from './app-routing.module';
|
import {AppRoutingModule} from './app-routing.module';
|
||||||
import { AppComponent } from './app.component';
|
import {AppComponent} from './app.component';
|
||||||
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
|
import {provideHttpClient, withInterceptorsFromDi} from '@angular/common/http';
|
||||||
import { GraphQLModule } from './graphql.module';
|
|
||||||
|
|
||||||
@NgModule({ declarations: [
|
@NgModule({ declarations: [
|
||||||
AppComponent
|
AppComponent
|
||||||
],
|
],
|
||||||
bootstrap: [AppComponent], imports: [BrowserModule,
|
bootstrap: [AppComponent],
|
||||||
AppRoutingModule,
|
imports: [BrowserModule, AppRoutingModule],
|
||||||
GraphQLModule], providers: [provideHttpClient(withInterceptorsFromDi())] })
|
providers: [provideHttpClient(withInterceptorsFromDi())]
|
||||||
|
})
|
||||||
export class AppModule { }
|
export class AppModule { }
|
||||||
|
14
yarn.lock
14
yarn.lock
@ -1995,18 +1995,18 @@
|
|||||||
proc-log "^4.0.0"
|
proc-log "^4.0.0"
|
||||||
which "^4.0.0"
|
which "^4.0.0"
|
||||||
|
|
||||||
|
"@openharbor/data@^1.0.0-alpha.1":
|
||||||
|
version "1.0.0-alpha.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/@openharbor/data/-/data-1.0.0-alpha.1.tgz#69c2bf7a0e1bac6e54459d0123fd006dce86553a"
|
||||||
|
integrity sha512-MLcfYd8ZFLxcFi13z8PnRiKLnt2Hn1FbHiXts9KBix/R8FIOSeIRZwrOFIBSrYRqk+muBvif9IGYx+uxHQlk8Q==
|
||||||
|
dependencies:
|
||||||
|
tslib "^2.3.0"
|
||||||
|
|
||||||
"@pkgjs/parseargs@^0.11.0":
|
"@pkgjs/parseargs@^0.11.0":
|
||||||
version "0.11.0"
|
version "0.11.0"
|
||||||
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
|
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
|
||||||
integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==
|
integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==
|
||||||
|
|
||||||
"@poweredsoft/data@0.0.32":
|
|
||||||
version "0.0.32"
|
|
||||||
resolved "https://registry.yarnpkg.com/@poweredsoft/data/-/data-0.0.32.tgz#61e4868d94f87a774aa367ab6f3ad7c6993254a0"
|
|
||||||
integrity sha512-vBsjBjKeNvjj3R0QwhBa+eKDZR3rK5lCueYUXIMU5iVFmw1UxVM3tW/0dbWmsDYnXi+/nm53Uz2MlqX9xpCStQ==
|
|
||||||
dependencies:
|
|
||||||
tslib "^1.9.0"
|
|
||||||
|
|
||||||
"@rollup/plugin-json@^6.1.0":
|
"@rollup/plugin-json@^6.1.0":
|
||||||
version "6.1.0"
|
version "6.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/@rollup/plugin-json/-/plugin-json-6.1.0.tgz#fbe784e29682e9bb6dee28ea75a1a83702e7b805"
|
resolved "https://registry.yarnpkg.com/@rollup/plugin-json/-/plugin-json-6.1.0.tgz#fbe784e29682e9bb6dee28ea75a1a83702e7b805"
|
||||||
|
Loading…
Reference in New Issue
Block a user