Compare commits
18 Commits
2dd17f3aed
...
391d773e26
Author | SHA1 | Date | |
---|---|---|---|
391d773e26 | |||
82b77906d7 | |||
8607fdf9f1 | |||
de237618f0 | |||
7165e387c9 | |||
fe8a9082d3 | |||
ff88dbaedf | |||
112c863705 | |||
4905775694 | |||
6567466700 | |||
8d50344a03 | |||
9f8a32d9cf | |||
8c1ba32818 | |||
5a9eee1d14 | |||
7b4b8f2c04 | |||
68a8bf1f06 | |||
52a0c188ac | |||
bd10fae9a5 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -32,6 +32,7 @@ speed-measure-plugin*.json
|
|||||||
.history/*
|
.history/*
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
|
/.angular/cache
|
||||||
/.sass-cache
|
/.sass-cache
|
||||||
/connect.lock
|
/connect.lock
|
||||||
/coverage
|
/coverage
|
||||||
|
28
README.md
28
README.md
@ -1,30 +1,4 @@
|
|||||||
# NgxData
|
> This project was originally initiated by [Powered Software Inc.](https://poweredsoft.com/) and was forked from the [ngx-data](https://github.com/PoweredSoft/ngx-data) Repository
|
||||||
|
|
||||||
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.3.3.
|
|
||||||
|
|
||||||
## Development server
|
|
||||||
|
|
||||||
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
|
|
||||||
|
|
||||||
## Code scaffolding
|
|
||||||
|
|
||||||
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
|
|
||||||
|
|
||||||
## Build
|
|
||||||
|
|
||||||
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
|
|
||||||
|
|
||||||
## Running unit tests
|
|
||||||
|
|
||||||
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
|
||||||
|
|
||||||
## Running end-to-end tests
|
|
||||||
|
|
||||||
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
|
|
||||||
|
|
||||||
## Further help
|
|
||||||
|
|
||||||
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
125
angular.json
125
angular.json
@ -3,7 +3,7 @@
|
|||||||
"version": 1,
|
"version": 1,
|
||||||
"newProjectRoot": "projects",
|
"newProjectRoot": "projects",
|
||||||
"projects": {
|
"projects": {
|
||||||
"ngx-data": {
|
"demo": {
|
||||||
"projectType": "application",
|
"projectType": "application",
|
||||||
"schematics": {
|
"schematics": {
|
||||||
"@schematics/angular:component": {
|
"@schematics/angular:component": {
|
||||||
@ -15,14 +15,16 @@
|
|||||||
"prefix": "app",
|
"prefix": "app",
|
||||||
"architect": {
|
"architect": {
|
||||||
"build": {
|
"build": {
|
||||||
"builder": "@angular-devkit/build-angular:browser",
|
"builder": "@angular-devkit/build-angular:application",
|
||||||
"options": {
|
"options": {
|
||||||
"outputPath": "dist/ngx-data",
|
"outputPath": {
|
||||||
|
"base": "dist/ngx-data"
|
||||||
|
},
|
||||||
"index": "src/index.html",
|
"index": "src/index.html",
|
||||||
"main": "src/main.ts",
|
"polyfills": [
|
||||||
"polyfills": "src/polyfills.ts",
|
"src/polyfills.ts"
|
||||||
|
],
|
||||||
"tsConfig": "tsconfig.app.json",
|
"tsConfig": "tsconfig.app.json",
|
||||||
"aot": false,
|
|
||||||
"assets": [
|
"assets": [
|
||||||
"src/favicon.ico",
|
"src/favicon.ico",
|
||||||
"src/assets"
|
"src/assets"
|
||||||
@ -30,7 +32,12 @@
|
|||||||
"styles": [
|
"styles": [
|
||||||
"src/styles.scss"
|
"src/styles.scss"
|
||||||
],
|
],
|
||||||
"scripts": []
|
"scripts": [],
|
||||||
|
"extractLicenses": false,
|
||||||
|
"sourceMap": true,
|
||||||
|
"optimization": false,
|
||||||
|
"namedChunks": true,
|
||||||
|
"browser": "src/main.ts"
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production": {
|
"production": {
|
||||||
@ -43,12 +50,8 @@
|
|||||||
"optimization": true,
|
"optimization": true,
|
||||||
"outputHashing": "all",
|
"outputHashing": "all",
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
"extractCss": true,
|
|
||||||
"namedChunks": false,
|
"namedChunks": false,
|
||||||
"aot": true,
|
|
||||||
"extractLicenses": true,
|
"extractLicenses": true,
|
||||||
"vendorChunk": false,
|
|
||||||
"buildOptimizer": true,
|
|
||||||
"budgets": [
|
"budgets": [
|
||||||
{
|
{
|
||||||
"type": "initial",
|
"type": "initial",
|
||||||
@ -62,23 +65,24 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"defaultConfiguration": ""
|
||||||
},
|
},
|
||||||
"serve": {
|
"serve": {
|
||||||
"builder": "@angular-devkit/build-angular:dev-server",
|
"builder": "@angular-devkit/build-angular:dev-server",
|
||||||
"options": {
|
"options": {
|
||||||
"browserTarget": "ngx-data:build"
|
"buildTarget": "ngx-data:build"
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production": {
|
"production": {
|
||||||
"browserTarget": "ngx-data:build:production"
|
"buildTarget": "ngx-data:build:production"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"extract-i18n": {
|
"extract-i18n": {
|
||||||
"builder": "@angular-devkit/build-angular:extract-i18n",
|
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||||||
"options": {
|
"options": {
|
||||||
"browserTarget": "ngx-data:build"
|
"buildTarget": "ngx-data:build"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test": {
|
"test": {
|
||||||
@ -98,19 +102,6 @@
|
|||||||
"scripts": []
|
"scripts": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"lint": {
|
|
||||||
"builder": "@angular-devkit/build-angular:tslint",
|
|
||||||
"options": {
|
|
||||||
"tsConfig": [
|
|
||||||
"tsconfig.app.json",
|
|
||||||
"tsconfig.spec.json",
|
|
||||||
"e2e/tsconfig.json"
|
|
||||||
],
|
|
||||||
"exclude": [
|
|
||||||
"**/node_modules/**"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"e2e": {
|
"e2e": {
|
||||||
"builder": "@angular-devkit/build-angular:protractor",
|
"builder": "@angular-devkit/build-angular:protractor",
|
||||||
"options": {
|
"options": {
|
||||||
@ -125,75 +116,33 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@poweredsoft/ngx-data": {
|
"ngx-data": {
|
||||||
"projectType": "library",
|
"projectType": "library",
|
||||||
"root": "projects/poweredsoft/ngx-data",
|
"root": "projects/openharbor/ngx-data",
|
||||||
"sourceRoot": "projects/poweredsoft/ngx-data/src",
|
"sourceRoot": "projects/openharbor/ngx-data/src",
|
||||||
"prefix": "lib",
|
"prefix": "lib",
|
||||||
"architect": {
|
"architect": {
|
||||||
"build": {
|
"build": {
|
||||||
"builder": "@angular-devkit/build-ng-packagr:build",
|
"builder": "@angular-devkit/build-angular:ng-packagr",
|
||||||
"options": {
|
"options": {
|
||||||
"tsConfig": "projects/poweredsoft/ngx-data/tsconfig.lib.json",
|
"tsConfig": "projects/openharbor/ngx-data/tsconfig.lib.json",
|
||||||
"project": "projects/poweredsoft/ngx-data/ng-package.json"
|
"project": "projects/openharbor/ngx-data/ng-package.json"
|
||||||
}
|
}
|
||||||
},
|
, "configurations": {
|
||||||
"test": {
|
"production": {
|
||||||
|
"tsConfig": "projects/openharbor/ngx-data/tsconfig.lib.prod.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"test": {
|
||||||
"builder": "@angular-devkit/build-angular:karma",
|
"builder": "@angular-devkit/build-angular:karma",
|
||||||
"options": {
|
"options": {
|
||||||
"main": "projects/poweredsoft/ngx-data/src/test.ts",
|
"main": "projects/openharbor/ngx-data/src/test.ts",
|
||||||
"tsConfig": "projects/poweredsoft/ngx-data/tsconfig.spec.json",
|
"tsConfig": "projects/openharbor/ngx-data/tsconfig.spec.json",
|
||||||
"karmaConfig": "projects/poweredsoft/ngx-data/karma.conf.js"
|
"karmaConfig": "projects/openharbor/ngx-data/karma.conf.js"
|
||||||
}
|
|
||||||
},
|
|
||||||
"lint": {
|
|
||||||
"builder": "@angular-devkit/build-angular:tslint",
|
|
||||||
"options": {
|
|
||||||
"tsConfig": [
|
|
||||||
"projects/poweredsoft/ngx-data/tsconfig.lib.json",
|
|
||||||
"projects/poweredsoft/ngx-data/tsconfig.spec.json"
|
|
||||||
],
|
|
||||||
"exclude": [
|
|
||||||
"**/node_modules/**"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"@poweredsoft/ngx-data-apollo": {
|
}
|
||||||
"projectType": "library",
|
|
||||||
"root": "projects/poweredsoft/ngx-data-apollo",
|
|
||||||
"sourceRoot": "projects/poweredsoft/ngx-data-apollo/src",
|
|
||||||
"prefix": "lib",
|
|
||||||
"architect": {
|
|
||||||
"build": {
|
|
||||||
"builder": "@angular-devkit/build-ng-packagr:build",
|
|
||||||
"options": {
|
|
||||||
"tsConfig": "projects/poweredsoft/ngx-data-apollo/tsconfig.lib.json",
|
|
||||||
"project": "projects/poweredsoft/ngx-data-apollo/ng-package.json"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"test": {
|
|
||||||
"builder": "@angular-devkit/build-angular:karma",
|
|
||||||
"options": {
|
|
||||||
"main": "projects/poweredsoft/ngx-data-apollo/src/test.ts",
|
|
||||||
"tsConfig": "projects/poweredsoft/ngx-data-apollo/tsconfig.spec.json",
|
|
||||||
"karmaConfig": "projects/poweredsoft/ngx-data-apollo/karma.conf.js"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"lint": {
|
|
||||||
"builder": "@angular-devkit/build-angular:tslint",
|
|
||||||
"options": {
|
|
||||||
"tsConfig": [
|
|
||||||
"projects/poweredsoft/ngx-data-apollo/tsconfig.lib.json",
|
|
||||||
"projects/poweredsoft/ngx-data-apollo/tsconfig.spec.json"
|
|
||||||
],
|
|
||||||
"exclude": [
|
|
||||||
"**/node_modules/**"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}},
|
|
||||||
"defaultProject": "ngx-data"
|
|
||||||
}
|
}
|
@ -3,7 +3,7 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "../out-tsc/e2e",
|
"outDir": "../out-tsc/e2e",
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"target": "es5",
|
"target": "es2018",
|
||||||
"types": [
|
"types": [
|
||||||
"jasmine",
|
"jasmine",
|
||||||
"jasminewd2",
|
"jasminewd2",
|
||||||
|
14257
package-lock.json
generated
14257
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
74
package.json
74
package.json
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "ngx-data",
|
"name": "demo",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
@ -8,55 +8,47 @@
|
|||||||
"test": "ng test",
|
"test": "ng test",
|
||||||
"lint": "ng lint",
|
"lint": "ng lint",
|
||||||
"e2e": "ng e2e",
|
"e2e": "ng e2e",
|
||||||
"build-data": "ng build @poweredsoft/ngx-data",
|
"build-data": "ng build @openharbor/ngx-data",
|
||||||
"build-apollo": "ng build @poweredsoft/ngx-data-apollo",
|
"publish-data": "npm publish dist/openharbor/ngx-data"
|
||||||
"publish-data": "npm publish dist/poweredsoft/ngx-data",
|
|
||||||
"publish-apollo": "npm publish dist/poweredsoft/ngx-data-apollo"
|
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/animations": "~8.2.4",
|
"@angular/animations": "^18.2.1",
|
||||||
"@angular/common": "~8.2.4",
|
"@angular/common": "^18.2.1",
|
||||||
"@angular/compiler": "~8.2.4",
|
"@angular/compiler": "^18.2.1",
|
||||||
"@angular/core": "~8.2.4",
|
"@angular/core": "^18.2.1",
|
||||||
"@angular/forms": "~8.2.4",
|
"@angular/forms": "^18.2.1",
|
||||||
"@angular/platform-browser": "~8.2.4",
|
"@angular/platform-browser": "^18.2.1",
|
||||||
"@angular/platform-browser-dynamic": "~8.2.4",
|
"@angular/platform-browser-dynamic": "^18.2.1",
|
||||||
"@angular/router": "~8.2.4",
|
"@angular/router": "^18.2.1",
|
||||||
"@poweredsoft/data": "0.0.32",
|
"@poweredsoft/data": "0.0.32",
|
||||||
"apollo-angular": "^1.8.0",
|
|
||||||
"apollo-angular-link-http": "^1.9.0",
|
|
||||||
"apollo-cache-inmemory": "^1.6.0",
|
|
||||||
"apollo-client": "^2.6.0",
|
|
||||||
"apollo-link": "^1.2.11",
|
|
||||||
"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",
|
||||||
"tslib": "^1.10.0",
|
"tslib": "^2.0.0",
|
||||||
"zone.js": "~0.9.1"
|
"zone.js": "~0.14.10"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular-devkit/build-angular": "~0.803.3",
|
"@angular-devkit/build-angular": "^18.2.1",
|
||||||
"@angular-devkit/build-ng-packagr": "~0.803.3",
|
"@angular/cli": "^18.2.1",
|
||||||
"@angular/cli": "~8.3.3",
|
"@angular/compiler-cli": "^18.2.1",
|
||||||
"@angular/compiler-cli": "~8.2.4",
|
"@angular/language-service": "^18.2.1",
|
||||||
"@angular/language-service": "~8.2.4",
|
"@types/jasmine": "~3.6.0",
|
||||||
"@types/node": "~8.9.4",
|
|
||||||
"@types/jasmine": "~3.3.8",
|
|
||||||
"@types/jasminewd2": "~2.0.3",
|
"@types/jasminewd2": "~2.0.3",
|
||||||
"codelyzer": "^5.0.0",
|
"@types/node": "^12.11.1",
|
||||||
"jasmine-core": "~3.4.0",
|
"codelyzer": "^6.0.0",
|
||||||
"jasmine-spec-reporter": "~4.2.1",
|
"jasmine-core": "~3.6.0",
|
||||||
"karma": "~4.1.0",
|
"jasmine-spec-reporter": "~5.0.0",
|
||||||
"karma-chrome-launcher": "~2.2.0",
|
"karma": "~6.4.4",
|
||||||
"karma-coverage-istanbul-reporter": "~2.0.1",
|
"karma-chrome-launcher": "~3.1.0",
|
||||||
"karma-jasmine": "~2.0.1",
|
"karma-coverage-istanbul-reporter": "~3.0.2",
|
||||||
"karma-jasmine-html-reporter": "^1.4.0",
|
"karma-jasmine": "~4.0.0",
|
||||||
"ng-packagr": "^5.4.0",
|
"karma-jasmine-html-reporter": "^1.5.0",
|
||||||
"protractor": "~5.4.0",
|
"ng-packagr": "^18.2.1",
|
||||||
|
"protractor": "~7.0.0",
|
||||||
"ts-node": "~7.0.0",
|
"ts-node": "~7.0.0",
|
||||||
"tsickle": "^0.37.0",
|
"tslint": "~6.1.0",
|
||||||
"tslint": "~5.15.0",
|
"typescript": "5.5.4"
|
||||||
"typescript": "~3.5.3"
|
},
|
||||||
}
|
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
|
||||||
}
|
}
|
@ -16,7 +16,7 @@ module.exports = function (config) {
|
|||||||
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
||||||
},
|
},
|
||||||
coverageIstanbulReporter: {
|
coverageIstanbulReporter: {
|
||||||
dir: require('path').join(__dirname, '../../../coverage/poweredsoft/ngx-data'),
|
dir: require('path').join(__dirname, '../../../coverage/openharbor/ngx-data'),
|
||||||
reports: ['html', 'lcovonly', 'text-summary'],
|
reports: ['html', 'lcovonly', 'text-summary'],
|
||||||
fixWebpackSourcePaths: true
|
fixWebpackSourcePaths: true
|
||||||
},
|
},
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
|
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
|
||||||
"dest": "../../../dist/poweredsoft/ngx-data",
|
"dest": "../../../dist/openharbor/ngx-data",
|
||||||
"lib": {
|
"lib": {
|
||||||
"entryFile": "src/public-api.ts"
|
"entryFile": "src/public-api.ts"
|
||||||
}
|
}
|
13
projects/openharbor/ngx-data/package.json
Normal file
13
projects/openharbor/ngx-data/package.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "@openharbor/ngx-data",
|
||||||
|
"version": "18.0.0-alpha.1",
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^2.7.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@angular/common": "^18.0.0",
|
||||||
|
"@angular/core": "^18.0.0",
|
||||||
|
"@poweredsoft/data": "^0.0.31",
|
||||||
|
"rxjs": "^6.5.3"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,138 @@
|
|||||||
|
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>; } = {};
|
||||||
|
protected _keyResolver: (model: TModel) => TKey;
|
||||||
|
protected _defaultCriteria: IQueryCriteria;
|
||||||
|
protected _query: IDataSourceQueryAdapterOptions<TModel>;
|
||||||
|
|
||||||
|
constructor(protected http: HttpClient) {
|
||||||
|
}
|
||||||
|
|
||||||
|
createDataSource(): IDataSource<TModel> {
|
||||||
|
return new DataSource<TModel>(this.createOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected createTransport(): IDataSourceTransportOptions<TModel> {
|
||||||
|
let ret: IDataSourceTransportOptions<TModel> = {
|
||||||
|
query: this._query,
|
||||||
|
commands: this._commands
|
||||||
|
};
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public keyResolver(resolver: (model: TModel) => TKey) {
|
||||||
|
this._keyResolver = resolver;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
createOptions(): IDataSourceOptions<TModel> {
|
||||||
|
let ret: IDataSourceOptions<TModel> = {
|
||||||
|
resolveIdField: this._keyResolver,
|
||||||
|
defaultCriteria: this._defaultCriteria,
|
||||||
|
transport: this.createTransport()
|
||||||
|
};
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _messageErrorHandler(err: HttpErrorResponse) {
|
||||||
|
|
||||||
|
if (typeof err.error == "object") {
|
||||||
|
// if status not okay then its an exception error
|
||||||
|
if (err.error.hasOwnProperty('Message') && typeof (err.error['Message']) == "string") {
|
||||||
|
return throwError(<IDataSourceErrorMessage>{
|
||||||
|
type: 'message',
|
||||||
|
message: err.error['Message']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (err.error.hasOwnProperty('message') && typeof (err.error['message']) == "string") {
|
||||||
|
return throwError(<IDataSourceErrorMessage>{
|
||||||
|
type: 'message',
|
||||||
|
message: err.error['message']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// general error message
|
||||||
|
if (typeof (err.error) == "string") {
|
||||||
|
return throwError(<IDataSourceErrorMessage>{
|
||||||
|
type: 'message',
|
||||||
|
message: err.error
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return throwError(<IDataSourceErrorMessage>{
|
||||||
|
type: 'message',
|
||||||
|
message: 'UNEXPECTED_ERROR_MESSAGE'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleErrorPipe(err: HttpErrorResponse): Observable<IDataSourceError> {
|
||||||
|
|
||||||
|
if (err.status == 400) {
|
||||||
|
if (err.error && err.error.errors)
|
||||||
|
return throwError(<IDataSourceValidationError>{
|
||||||
|
type: 'validation',
|
||||||
|
errors: err.error.errors
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._messageErrorHandler(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public addCommandByCallback<TCommand, TCommandResult>(name: string, commandHandler: (command: TCommand) => Observable<TCommandResult>, resolveCommandModel?: (event: IResolveCommandModelEvent<TModel>) => Observable<TCommand & any>) {
|
||||||
|
const handleWrapper = command => {
|
||||||
|
return commandHandler(command).pipe(catchError(this._handleErrorPipe.bind(this)));
|
||||||
|
};
|
||||||
|
|
||||||
|
this._commands[name] = <IDataSourceCommandAdapterOptions<TModel>>{
|
||||||
|
adapter: {
|
||||||
|
handle: handleWrapper
|
||||||
|
},
|
||||||
|
resolveCommandModel: resolveCommandModel
|
||||||
|
};
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public addCommandByUrl<TCommand, TCommandResult>(name: string, url: string, resolveCommandModel?: (event: IResolveCommandModelEvent<TModel>) => Observable<TCommand & any>, beforeCommand?: (command: TCommand) => Observable<TCommand>) {
|
||||||
|
const handleWrapper = command => {
|
||||||
|
const finalBeforeCommand = beforeCommand || (_ => of(command));
|
||||||
|
return finalBeforeCommand(command)
|
||||||
|
.pipe(
|
||||||
|
switchMap(finalCommand => {
|
||||||
|
return this.http.post<TCommandResult>(url, finalCommand).pipe(catchError(this._handleErrorPipe.bind(this)));
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
this._commands[name] = <IDataSourceCommandAdapterOptions<TModel>>{
|
||||||
|
adapter: {
|
||||||
|
handle: handleWrapper
|
||||||
|
},
|
||||||
|
resolveCommandModel: resolveCommandModel
|
||||||
|
};
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
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>
|
||||||
|
{
|
||||||
|
private _beforeRead: (TQuery: IQueryCriteria) => Observable<IQueryCriteria>;
|
||||||
|
|
||||||
|
constructor(http: HttpClient) {
|
||||||
|
super(http);
|
||||||
|
}
|
||||||
|
|
||||||
|
public beforeRead<TDynamicQuery extends IQueryCriteria>(beforeRead: (query: TDynamicQuery) => Observable<TDynamicQuery>) {
|
||||||
|
this._beforeRead = beforeRead;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public queryUrl(url: string) {
|
||||||
|
this._query = {
|
||||||
|
adapter: {
|
||||||
|
handle: (query: IQueryCriteria) => {
|
||||||
|
const finalBeforeRead = this._beforeRead || (t => of(query));
|
||||||
|
return finalBeforeRead(query)
|
||||||
|
.pipe(
|
||||||
|
switchMap(finalQuery => {
|
||||||
|
return this.http.post<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>(url, finalQuery);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public queryHandler<TQuery extends IQueryCriteria>(queryHandler: (query: TQuery) => Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>) {
|
||||||
|
this._query = {
|
||||||
|
adapter: {
|
||||||
|
handle: (query: TQuery) => {
|
||||||
|
const finalBeforeRead = this._beforeRead || (t => of(query));
|
||||||
|
return finalBeforeRead(query)
|
||||||
|
.pipe(
|
||||||
|
switchMap(finalQuery => {
|
||||||
|
return queryHandler(finalQuery as any);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultCriteria(criteria: IQueryCriteria) {
|
||||||
|
this._defaultCriteria = criteria;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
107
projects/openharbor/ngx-data/src/lib/ListDataSourceBuilder.ts
Normal file
107
projects/openharbor/ngx-data/src/lib/ListDataSourceBuilder.ts
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
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>
|
||||||
|
{
|
||||||
|
private _beforeRead: (query: IQueryCriteria) => Observable<TQuery>;
|
||||||
|
|
||||||
|
constructor(http: HttpClient) {
|
||||||
|
super(http);
|
||||||
|
}
|
||||||
|
|
||||||
|
public beforeRead(beforeRead: (query: IQueryCriteria) => Observable<TQuery>) {
|
||||||
|
this._beforeRead = beforeRead;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public queryUrlWithGet(url: string) {
|
||||||
|
this._query = {
|
||||||
|
adapter: {
|
||||||
|
handle: (query: IQueryCriteria) => {
|
||||||
|
const finalBeforeRead = this._beforeRead || ((_: IQueryCriteria) => of(<TQuery>{}));
|
||||||
|
return finalBeforeRead(query)
|
||||||
|
.pipe(
|
||||||
|
switchMap(finalQuery => {
|
||||||
|
return this.http.get<TModel[]>(url, {
|
||||||
|
params: this.convertToParams(finalQuery)
|
||||||
|
}).pipe(
|
||||||
|
map(result => {
|
||||||
|
return <IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>
|
||||||
|
{
|
||||||
|
totalRecords: result.length,
|
||||||
|
data: result
|
||||||
|
};
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected convertToParams(finalQuery: TQuery)
|
||||||
|
{
|
||||||
|
return Object.keys(finalQuery).reduce((prev, key) => {
|
||||||
|
prev[key] = finalQuery[key];
|
||||||
|
return prev;
|
||||||
|
}, {} as { [param: string]: string | string[]; });
|
||||||
|
}
|
||||||
|
|
||||||
|
public queryUrl(url: string) {
|
||||||
|
this._query = {
|
||||||
|
adapter: {
|
||||||
|
handle: (query: IQueryCriteria) => {
|
||||||
|
const finalBeforeRead = this._beforeRead || ((_: IQueryCriteria) => of(<TQuery>{}));
|
||||||
|
return finalBeforeRead(query)
|
||||||
|
.pipe(
|
||||||
|
switchMap(finalQuery => {
|
||||||
|
return this.http.post<TModel[]>(url, finalQuery).pipe(
|
||||||
|
map(result => {
|
||||||
|
return <IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>
|
||||||
|
{
|
||||||
|
totalRecords: result.length,
|
||||||
|
data: result
|
||||||
|
};
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public queryHandler(queryHandler: (query: IQueryCriteria) => Observable<TModel[]>) {
|
||||||
|
this._query = {
|
||||||
|
adapter: {
|
||||||
|
handle: (query: TQuery) => {
|
||||||
|
const finalBeforeRead = this._beforeRead || (t => of({}));
|
||||||
|
return finalBeforeRead(query)
|
||||||
|
.pipe(
|
||||||
|
switchMap(finalQuery => {
|
||||||
|
return queryHandler(finalQuery).pipe(
|
||||||
|
map(result => {
|
||||||
|
return <IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>{
|
||||||
|
totalRecords: result.length,
|
||||||
|
data: result
|
||||||
|
};
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
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> {
|
||||||
|
private _beforeRead: (query: IQueryCriteria) => Observable<TQuery>;
|
||||||
|
|
||||||
|
constructor(http: HttpClient) {
|
||||||
|
super(http);
|
||||||
|
}
|
||||||
|
|
||||||
|
public beforeRead(beforeRead: (query: IQueryCriteria) => Observable<TQuery>) {
|
||||||
|
this._beforeRead = beforeRead;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public queryUrlWithGet(url: string) {
|
||||||
|
this._query = {
|
||||||
|
adapter: {
|
||||||
|
handle: (query: IQueryCriteria) => {
|
||||||
|
const finalBeforeRead = this._beforeRead || ((query: IQueryCriteria) => of({} as TQuery));
|
||||||
|
return finalBeforeRead(query)
|
||||||
|
.pipe(
|
||||||
|
switchMap(finalQuery => {
|
||||||
|
return this.http.get<TModel>(url, {
|
||||||
|
params: this.convertToParams(finalQuery)
|
||||||
|
}).pipe(
|
||||||
|
map(result => {
|
||||||
|
return {
|
||||||
|
totalRecords: result == null ? 0 : 1,
|
||||||
|
data: [result]
|
||||||
|
} as IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected convertToParams(finalQuery: TQuery) {
|
||||||
|
return Object.keys(finalQuery).reduce((prev, key) => {
|
||||||
|
prev[key] = finalQuery[key];
|
||||||
|
return prev;
|
||||||
|
}, {} as { [param: string]: string | string[]; });
|
||||||
|
}
|
||||||
|
|
||||||
|
public queryUrl(url: string) {
|
||||||
|
this._query = {
|
||||||
|
adapter: {
|
||||||
|
handle: (query: IQueryCriteria) => {
|
||||||
|
const finalBeforeRead = this._beforeRead || ((_: IQueryCriteria) => of({} as TQuery));
|
||||||
|
return finalBeforeRead(query)
|
||||||
|
.pipe(
|
||||||
|
switchMap(finalQuery => {
|
||||||
|
return this.http.post<TModel>(url, finalQuery).pipe(
|
||||||
|
map(result => {
|
||||||
|
return {
|
||||||
|
totalRecords: result == null ? 0 : 1,
|
||||||
|
data: [result]
|
||||||
|
} as IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public queryHandler(queryHandler: (query: IQueryCriteria) => Observable<TModel>) {
|
||||||
|
this._query = {
|
||||||
|
adapter: {
|
||||||
|
handle: (query: TQuery) => {
|
||||||
|
const finalBeforeRead = this._beforeRead || (t => of({}));
|
||||||
|
return finalBeforeRead(query)
|
||||||
|
.pipe(
|
||||||
|
switchMap(finalQuery => {
|
||||||
|
return queryHandler(finalQuery).pipe(
|
||||||
|
map(result => {
|
||||||
|
return {
|
||||||
|
totalRecords: result == null ? 0 : 1,
|
||||||
|
data: [result]
|
||||||
|
} as IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
import {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 {
|
||||||
|
@Inject(HttpClient) protected http!: HttpClient;
|
||||||
|
|
||||||
|
builder<TModel, TKey>() {
|
||||||
|
return new HttpDataSourceOptionsBuilder<TModel, TKey>(this.http);
|
||||||
|
}
|
||||||
|
|
||||||
|
singleBuilder<TQuery, TModel, TKey>() {
|
||||||
|
return new SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>(this.http);
|
||||||
|
}
|
||||||
|
|
||||||
|
listBuilder<TQuery, TModel, TKey>() {
|
||||||
|
return new ListDataSourceOptionsBuilder<TQuery, TModel, TKey>(this.http);
|
||||||
|
}
|
||||||
|
}
|
151
projects/openharbor/ngx-data/src/lib/ngx-data.service.ts
Normal file
151
projects/openharbor/ngx-data/src/lib/ngx-data.service.ts
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
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
|
||||||
|
{
|
||||||
|
@Inject(HttpClient) protected http!: HttpClient;
|
||||||
|
|
||||||
|
private _handleErrorPipe(err: HttpErrorResponse) : Observable<IDataSourceError> {
|
||||||
|
|
||||||
|
if (err.status == 500) {
|
||||||
|
return throwError(<IDataSourceErrorMessage>{
|
||||||
|
type: 'message',
|
||||||
|
message: 'UNEXPECTED_ERROR_MESSAGE'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err.status == 400)
|
||||||
|
{
|
||||||
|
if (err.error && err.error.errors)
|
||||||
|
return throwError(<IDataSourceValidationError>{
|
||||||
|
type: 'validation',
|
||||||
|
errors: err.error.errors
|
||||||
|
});
|
||||||
|
|
||||||
|
// 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',
|
||||||
|
message: err.error['Message']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// general error message
|
||||||
|
if (typeof(err.error) == "string") {
|
||||||
|
return throwError(<IDataSourceErrorMessage>{
|
||||||
|
type: 'message',
|
||||||
|
message: err.error
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return throwError(<IDataSourceErrorMessage>{
|
||||||
|
type: 'message',
|
||||||
|
message: 'UNEXPECTED_ERROR_MESSAGE'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
createDataSourceOptions<TModel, TKey>(route: string, keyResolver: (model: TModel) => TKey, defaultCriteria: IQueryCriteria, beforeRead?: (query: IQueryCriteria) => Observable<IQueryCriteria>) : IDataSourceOptions<TModel>
|
||||||
|
{
|
||||||
|
const dataSourceTransportOptions = this.createStandardRestTransportOptions<TModel, TKey>(route, keyResolver, beforeRead);
|
||||||
|
|
||||||
|
const dataSourceOptions: IDataSourceOptions<TModel> = {
|
||||||
|
defaultCriteria: defaultCriteria,
|
||||||
|
resolveIdField: keyResolver,
|
||||||
|
transport: dataSourceTransportOptions
|
||||||
|
};
|
||||||
|
|
||||||
|
return dataSourceOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
setResolveCommand<TModel>(options: IDataSourceOptions<TModel>, name: string, resolveCommandModel: (event: IResolveCommandModelEvent<TModel>) => Observable<any>) {
|
||||||
|
options.transport.commands[name].resolveCommandModel = resolveCommandModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 => {
|
||||||
|
return this.http.post<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>(queryRoute, finalQuery);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const createCommand: IDataSourceCommandAdapterOptions<TModel> = {
|
||||||
|
adapter: {
|
||||||
|
handle: (command: TModel) => {
|
||||||
|
return this.http.post<TModel>(route, command).pipe(catchError(this._handleErrorPipe));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateCommand: IDataSourceCommandAdapterOptions<TModel> = {
|
||||||
|
adapter: {
|
||||||
|
handle: (command: TModel) => {
|
||||||
|
const key = keyResolver(command);
|
||||||
|
const updateRoute = `${route}/${encodeURIComponent(key as any)}`;
|
||||||
|
return this.http.put<TModel>(updateRoute, command).pipe(catchError(this._handleErrorPipe));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteCommand: IDataSourceCommandAdapterOptions<TModel> = {
|
||||||
|
adapter: {
|
||||||
|
handle: (command: TModel) => {
|
||||||
|
const key = keyResolver(command);
|
||||||
|
const updateRoute = `${route}/${encodeURIComponent(key as any)}`;
|
||||||
|
return this.http.delete<TModel>(updateRoute).pipe(catchError(this._handleErrorPipe));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
query: query,
|
||||||
|
commands: {
|
||||||
|
'create': createCommand,
|
||||||
|
'update': updateCommand,
|
||||||
|
'delete': deleteCommand
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -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';
|
|
@ -2,7 +2,8 @@
|
|||||||
"extends": "../../../tsconfig.json",
|
"extends": "../../../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "../../../out-tsc/lib",
|
"outDir": "../../../out-tsc/lib",
|
||||||
"target": "es2015",
|
"declarationMap": true,
|
||||||
|
"target": "es2020",
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"inlineSources": true,
|
"inlineSources": true,
|
||||||
"types": [],
|
"types": [],
|
||||||
@ -12,7 +13,6 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
"annotateForClosureCompiler": true,
|
|
||||||
"skipTemplateCodegen": true,
|
"skipTemplateCodegen": true,
|
||||||
"strictMetadataEmit": true,
|
"strictMetadataEmit": true,
|
||||||
"fullTemplateTypeCheck": true,
|
"fullTemplateTypeCheck": true,
|
9
projects/openharbor/ngx-data/tsconfig.lib.prod.json
Normal file
9
projects/openharbor/ngx-data/tsconfig.lib.prod.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.lib.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"declarationMap": false
|
||||||
|
},
|
||||||
|
"angularCompilerOptions": {
|
||||||
|
"compilationMode": "partial"
|
||||||
|
}
|
||||||
|
}
|
@ -1,24 +0,0 @@
|
|||||||
# NgxDataApollo
|
|
||||||
|
|
||||||
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.2.4.
|
|
||||||
|
|
||||||
## Code scaffolding
|
|
||||||
|
|
||||||
Run `ng generate component component-name --project ngx-data-apollo` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project ngx-data-apollo`.
|
|
||||||
> Note: Don't forget to add `--project ngx-data-apollo` or else it will be added to the default project in your `angular.json` file.
|
|
||||||
|
|
||||||
## Build
|
|
||||||
|
|
||||||
Run `ng build ngx-data-apollo` to build the project. The build artifacts will be stored in the `dist/` directory.
|
|
||||||
|
|
||||||
## Publishing
|
|
||||||
|
|
||||||
After building your library with `ng build ngx-data-apollo`, go to the dist folder `cd dist/ngx-data-apollo` and run `npm publish`.
|
|
||||||
|
|
||||||
## Running unit tests
|
|
||||||
|
|
||||||
Run `ng test ngx-data-apollo` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
|
||||||
|
|
||||||
## Further help
|
|
||||||
|
|
||||||
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
|
|
@ -1,32 +0,0 @@
|
|||||||
// Karma configuration file, see link for more information
|
|
||||||
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
|
||||||
|
|
||||||
module.exports = function (config) {
|
|
||||||
config.set({
|
|
||||||
basePath: '',
|
|
||||||
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
|
||||||
plugins: [
|
|
||||||
require('karma-jasmine'),
|
|
||||||
require('karma-chrome-launcher'),
|
|
||||||
require('karma-jasmine-html-reporter'),
|
|
||||||
require('karma-coverage-istanbul-reporter'),
|
|
||||||
require('@angular-devkit/build-angular/plugins/karma')
|
|
||||||
],
|
|
||||||
client: {
|
|
||||||
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
|
||||||
},
|
|
||||||
coverageIstanbulReporter: {
|
|
||||||
dir: require('path').join(__dirname, '../../../coverage/poweredsoft/ngx-data-apollo'),
|
|
||||||
reports: ['html', 'lcovonly', 'text-summary'],
|
|
||||||
fixWebpackSourcePaths: true
|
|
||||||
},
|
|
||||||
reporters: ['progress', 'kjhtml'],
|
|
||||||
port: 9876,
|
|
||||||
colors: true,
|
|
||||||
logLevel: config.LOG_INFO,
|
|
||||||
autoWatch: true,
|
|
||||||
browsers: ['Chrome'],
|
|
||||||
singleRun: false,
|
|
||||||
restartOnFileChange: true
|
|
||||||
});
|
|
||||||
};
|
|
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
|
|
||||||
"dest": "../../../dist/poweredsoft/ngx-data-apollo",
|
|
||||||
"lib": {
|
|
||||||
"entryFile": "src/public-api.ts"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@poweredsoft/ngx-data-apollo",
|
|
||||||
"version": "0.0.9",
|
|
||||||
"peerDependencies": {
|
|
||||||
"@poweredsoft/data": "^0.0.31",
|
|
||||||
"@angular/common": "^8.2.4",
|
|
||||||
"@angular/core": "^8.2.4",
|
|
||||||
"apollo-angular-link-http": "^1.9.0",
|
|
||||||
"apollo-link": "^1.2.11",
|
|
||||||
"apollo-client": "^2.6.0",
|
|
||||||
"apollo-cache-inmemory": "^1.6.0",
|
|
||||||
"graphql-tag": "^2.10.0",
|
|
||||||
"graphql": "^14.5.0"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,401 +0,0 @@
|
|||||||
import { IDataSourceOptions, IQueryCriteria, IDataSourceTransportOptions, IDataSourceQueryAdapterOptions, IDataSourceCommandAdapterOptions, IAdvanceQueryAdapter, IFilter, IAggregate, ISort, IGroup, ISimpleFilter, ICompositeFilter, IQueryExecutionGroupResult, IQueryExecutionResult, IAggregateResult, IGroupQueryResult, IResolveCommandModelEvent, IDataSourceErrorMessage, IDataSourceValidationError } from '@poweredsoft/data';
|
|
||||||
import { Apollo } from 'apollo-angular';
|
|
||||||
import { IGraphQLAdvanceQueryResult, IGraphQLAdvanceQueryInput, IGraphQLAdvanceQueryFilterInput, IGraphQLAdvanceQueryAggregateInput, IGraphQLAdvanceQuerySortInput, IGraphQLAdvanceQueryGroupInput, FilterType, IGraphQLAdvanceQueryAggregateResult, IGraphQLVariantResult, AggregateType, IGraphQLAdvanceGroupResult } from './models';
|
|
||||||
import gql from 'graphql-tag';
|
|
||||||
import { DocumentNode, GraphQLError } from 'graphql';
|
|
||||||
import { map, catchError, switchMap } from 'rxjs/operators';
|
|
||||||
import { Observable, throwError, of } from 'rxjs';
|
|
||||||
import { FetchResult } from 'apollo-link';
|
|
||||||
import { ApolloError } from 'apollo-client';
|
|
||||||
|
|
||||||
export class GraphQLDataSourceOptionsBuilder<TModel, TKey> {
|
|
||||||
private _commands: { [key: string] : IDataSourceCommandAdapterOptions<any> } = {};
|
|
||||||
private _beforeRead: (TQuery: IGraphQLAdvanceQueryInput<TModel>) => Observable<IGraphQLAdvanceQueryInput<TModel>>;
|
|
||||||
|
|
||||||
querySelect: string;
|
|
||||||
|
|
||||||
constructor(private apollo: Apollo,
|
|
||||||
private queryName: string,
|
|
||||||
private queryInputName: string,
|
|
||||||
querySelect: string | string[],
|
|
||||||
private keyResolver: (model: TModel) => TKey,
|
|
||||||
private defaultCriteria: IQueryCriteria,
|
|
||||||
private manageNotificationMessage: boolean)
|
|
||||||
{
|
|
||||||
if (Array.isArray(querySelect))
|
|
||||||
this.querySelect = querySelect.join(' ');
|
|
||||||
else
|
|
||||||
this.querySelect = querySelect;
|
|
||||||
}
|
|
||||||
|
|
||||||
create(): IDataSourceOptions<TModel> {
|
|
||||||
let ret: IDataSourceOptions<TModel> = {
|
|
||||||
resolveIdField: this.keyResolver,
|
|
||||||
defaultCriteria: this.defaultCriteria,
|
|
||||||
transport: this.createTransport()
|
|
||||||
};
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected createTransport(): IDataSourceTransportOptions<TModel> {
|
|
||||||
let ret: IDataSourceTransportOptions<TModel> = {
|
|
||||||
query: this.createQuery(),
|
|
||||||
commands: this._commands
|
|
||||||
};
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public beforeRead<TAdvanceQuery extends IGraphQLAdvanceQueryInput<TModel>>(beforeRead: (query: TAdvanceQuery) => Observable<TAdvanceQuery>)
|
|
||||||
{
|
|
||||||
this._beforeRead = beforeRead;
|
|
||||||
return this._beforeRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected createQuery(): IDataSourceQueryAdapterOptions<TModel> {
|
|
||||||
let ret: IDataSourceQueryAdapterOptions<TModel> = {
|
|
||||||
adapter: <IAdvanceQueryAdapter<IQueryCriteria, TModel>>{
|
|
||||||
handle: (query: IQueryCriteria) => {
|
|
||||||
|
|
||||||
const finalBeforeRead = this._beforeRead || (t => of(t));
|
|
||||||
const advanceQuery = this.createGraphQLQueryCriteria(query);
|
|
||||||
return finalBeforeRead(advanceQuery)
|
|
||||||
.pipe(
|
|
||||||
switchMap(finalAdvanceQuery => {
|
|
||||||
const o$ = this.apollo.query<any>({
|
|
||||||
query: this.createGraphQLQuery(finalAdvanceQuery),
|
|
||||||
variables: {
|
|
||||||
criteria: finalAdvanceQuery
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return o$.pipe(
|
|
||||||
map(result => {
|
|
||||||
const queryResult = result.data[this.queryName] as IGraphQLAdvanceQueryResult<TModel>;
|
|
||||||
return this.queryResultFromGraphQLAdvancedResult(finalAdvanceQuery, queryResult);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private queryResultFromGraphQLAdvancedResult(query: IGraphQLAdvanceQueryInput<TModel>, result: IGraphQLAdvanceQueryResult<TModel>): IQueryExecutionResult<TModel> | IQueryExecutionGroupResult<TModel> {
|
|
||||||
|
|
||||||
const ret: IQueryExecutionGroupResult<TModel> & IQueryExecutionResult<TModel> = {
|
|
||||||
data: result.data,
|
|
||||||
groups: result.groups ? result.groups.map(this.fromGraphQLGroupResult.bind(this)) : null,
|
|
||||||
totalRecords: result.totalRecords,
|
|
||||||
numberOfPages: result.numberOfPages,
|
|
||||||
aggregates: result.aggregates ? result.aggregates.map(this.fromGraphQLAggregateResult.bind(this)) : null
|
|
||||||
};
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private fromGraphQLGroupResult(group: IGraphQLAdvanceGroupResult<TModel>) : IGroupQueryResult<TModel> {
|
|
||||||
return {
|
|
||||||
aggregates: group.aggregates ? group.aggregates.map(this.convertAggregates.bind(this)) : null,
|
|
||||||
data: group.data,
|
|
||||||
groupPath: group.groupPath,
|
|
||||||
groupValue: this.getValueFromVariantResult(group.groupValue),
|
|
||||||
hasSubGroups: group.hasSubGroups,
|
|
||||||
subGroups: group.subGroups ? group.subGroups.map(this.fromGraphQLGroupResult.bind(this)) : null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private fromGraphQLAggregateResult(agg: IGraphQLAdvanceQueryAggregateResult): IAggregateResult {
|
|
||||||
return {
|
|
||||||
path: agg.path,
|
|
||||||
type: this.normalizeFirstLetter(agg.type),
|
|
||||||
value: this.getValueFromVariantResult(agg.value)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private normalizeFirstLetter(type: string): string {
|
|
||||||
if (type) {
|
|
||||||
const ret = type.toLowerCase();
|
|
||||||
return ret.substring(0, 1).toUpperCase() + ret.substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getValueFromVariantResult(variant: IGraphQLVariantResult): any {
|
|
||||||
|
|
||||||
if (variant && variant.typeName)
|
|
||||||
{
|
|
||||||
if (variant.typeName.toLowerCase() == "int")
|
|
||||||
return variant.intValue;
|
|
||||||
else if (variant.typeName.toLowerCase() == "long")
|
|
||||||
return variant.longValue;
|
|
||||||
else if (variant.typeName.toLowerCase() == "boolean")
|
|
||||||
return variant.booleanValue;
|
|
||||||
else if (variant.typeName.toLowerCase() == "decimal")
|
|
||||||
return variant.decimalValue;
|
|
||||||
else if (variant.typeName.toLowerCase() == "datetime")
|
|
||||||
return variant.dateTimeValue;
|
|
||||||
else if (variant.typeName.toLowerCase() == "string")
|
|
||||||
return variant.stringValue;
|
|
||||||
else if (variant.typeName.toLowerCase() == "json")
|
|
||||||
return JSON.parse(variant.json);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private createGraphQLQuery(query: IGraphQLAdvanceQueryInput<TModel>): DocumentNode {
|
|
||||||
return gql`
|
|
||||||
query getAll($criteria: ${this.queryInputName}) {
|
|
||||||
${this.queryName}(params: $criteria) {
|
|
||||||
totalRecords
|
|
||||||
numberOfPages
|
|
||||||
${this.createAggregateSelect(query)}
|
|
||||||
${this.createQuerySelect(query)}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
private createAggregateSelect(query: IGraphQLAdvanceQueryInput<TModel>): any {
|
|
||||||
|
|
||||||
if (query.aggregates && query.aggregates.length)
|
|
||||||
{
|
|
||||||
return `
|
|
||||||
aggregates {
|
|
||||||
type
|
|
||||||
path
|
|
||||||
value {
|
|
||||||
${this.createSelectVariant()}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
private createGraphQLQueryCriteria(query: IQueryCriteria): IGraphQLAdvanceQueryInput<TModel> {
|
|
||||||
const ret: IGraphQLAdvanceQueryInput<TModel> = {
|
|
||||||
page: query.page,
|
|
||||||
pageSize: query.pageSize,
|
|
||||||
filters: query.filters ? query.filters.map(this.convertFilter.bind(this)) : null,
|
|
||||||
sorts: query.sorts ? query.sorts.map(this.convertSort.bind(this)) : null,
|
|
||||||
aggregates: query.aggregates ? query.aggregates.map(this.convertAggregates.bind(this)) : null,
|
|
||||||
groups: query.groups ? query.groups.map(this.convertGroup.bind(this)) : null
|
|
||||||
};
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*public addMutationTest<TMutation, TMutationResult>(name: string, mutationName: string, mutationSelect?: string, resolveCommandModel?: (event: IResolveCommandModelEvent<TModel>) => Observable<TMutation & any>) {
|
|
||||||
this._commands[name] = <IDataSourceCommandAdapterOptions<TModel>> {
|
|
||||||
adapter: {
|
|
||||||
handle: this.apollo.use()
|
|
||||||
},
|
|
||||||
resolveCommandModel: resolveCommandModel
|
|
||||||
};
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public addMutation<TMutation, TMutationResult>(name: string, mutationName: string, handle: (command: TMutation) => Observable<FetchResult<TMutationResult>>, resolveCommandModel?: (event: IResolveCommandModelEvent<TModel>) => Observable<TMutation & any>) {
|
|
||||||
const handleWrapper = command => {
|
|
||||||
return handle(command)
|
|
||||||
.pipe(
|
|
||||||
map(result => {
|
|
||||||
return result.data[mutationName];
|
|
||||||
}),
|
|
||||||
catchError((error: ApolloError) => {
|
|
||||||
console.log(error);
|
|
||||||
// should handle bad request with exception
|
|
||||||
// should handle bad request with validation
|
|
||||||
// should handle forbidden result 403
|
|
||||||
// should handle not authorized result 401
|
|
||||||
|
|
||||||
if (!error.networkError) {
|
|
||||||
const validationError = error.graphQLErrors.find(t => t.extensions.code == 'ValidationError');
|
|
||||||
const authenticationError = error.graphQLErrors.find(t => t.extensions.code == 'AuthenticationError');
|
|
||||||
|
|
||||||
if (validationError) {
|
|
||||||
const extensions = validationError.extensions;
|
|
||||||
const result = Object.keys(extensions).filter(t => t != 'code').reduce((prev, attributeName) => {
|
|
||||||
prev[attributeName] = extensions[attributeName];
|
|
||||||
return prev;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
console.log('error result', result);
|
|
||||||
|
|
||||||
return throwError(<IDataSourceValidationError>{
|
|
||||||
type: 'validation',
|
|
||||||
errors: result
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (authenticationError) {
|
|
||||||
return throwError(<IDataSourceErrorMessage>{
|
|
||||||
type: 'message',
|
|
||||||
message: "Unauthorized"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return throwError(<IDataSourceErrorMessage>{
|
|
||||||
type: 'message',
|
|
||||||
message: error.message
|
|
||||||
});
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
this._commands[name] = <IDataSourceCommandAdapterOptions<TModel>> {
|
|
||||||
adapter: {
|
|
||||||
handle: handleWrapper
|
|
||||||
},
|
|
||||||
resolveCommandModel: resolveCommandModel
|
|
||||||
};
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private createGroupSelect(query: IGraphQLAdvanceQueryInput<TModel>, group: IGroup, isLast: boolean) {
|
|
||||||
let ret = `
|
|
||||||
groupPath
|
|
||||||
groupValue {
|
|
||||||
${this.createSelectVariant()}
|
|
||||||
}
|
|
||||||
hasSubGroups
|
|
||||||
${this.createAggregateSelect(query)}
|
|
||||||
`;
|
|
||||||
|
|
||||||
if (isLast) {
|
|
||||||
ret += `
|
|
||||||
data {
|
|
||||||
${this.querySelect}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
} else {
|
|
||||||
ret += `
|
|
||||||
subGroups {
|
|
||||||
___INNER___
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private createSelectVariant() {
|
|
||||||
return `booleanValue dateTimeValue decimalValue intValue json longValue stringValue typeName`;
|
|
||||||
}
|
|
||||||
|
|
||||||
private createQuerySelect(query: IGraphQLAdvanceQueryInput<TModel>): string {
|
|
||||||
if (query.groups && query.groups.length) {
|
|
||||||
|
|
||||||
const groupSelect = query.groups.reduce((prev, current, currentIndex) => {
|
|
||||||
const isLast = currentIndex+1 == query.groups.length;
|
|
||||||
const group = this.createGroupSelect(query, current, isLast);
|
|
||||||
return prev.replace('___INNER___', group);
|
|
||||||
}, `
|
|
||||||
groups {
|
|
||||||
___INNER___
|
|
||||||
}
|
|
||||||
`);
|
|
||||||
|
|
||||||
return groupSelect;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `
|
|
||||||
data {
|
|
||||||
${this.querySelect}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
private convertGroup(group: IGroup): IGraphQLAdvanceQueryGroupInput {
|
|
||||||
return {
|
|
||||||
path: group.path,
|
|
||||||
ascending: group.ascending
|
|
||||||
};
|
|
||||||
}
|
|
||||||
private convertAggregates(aggregate: IAggregate): IGraphQLAdvanceQueryAggregateInput {
|
|
||||||
return {
|
|
||||||
path: aggregate.path,
|
|
||||||
type: this.resolveAggregateType(aggregate.type)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private resolveAggregateType(type: string): AggregateType {
|
|
||||||
|
|
||||||
return type ? type.toUpperCase() as any : null;
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
if (type)
|
|
||||||
{
|
|
||||||
if (type.toUpperCase() == 'COUNT') return AggregateType.COUNT
|
|
||||||
if (type.toUpperCase() == 'SUM') return AggregateType.SUM
|
|
||||||
if (type.toUpperCase() == 'AVG') return AggregateType.AVG
|
|
||||||
if (type.toUpperCase() == 'LONGCOUNT') return AggregateType.LONGCOUNT
|
|
||||||
if (type.toUpperCase() == 'MIN') return AggregateType.MIN
|
|
||||||
if (type.toUpperCase() == 'MAX') return AggregateType.MAX
|
|
||||||
if (type.toUpperCase() == 'FIRST') return AggregateType.FIRST
|
|
||||||
if (type.toUpperCase() == 'FIRSTORDEFAULT') return AggregateType.FIRSTORDEFAULT
|
|
||||||
if (type.toUpperCase() == 'LAST') return AggregateType.LAST
|
|
||||||
if (type.toUpperCase() == 'LASTORDEFAULT') return AggregateType.LASTORDEFAULT
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error('Aggregate type');*/
|
|
||||||
}
|
|
||||||
|
|
||||||
private convertSort(sort: ISort): IGraphQLAdvanceQuerySortInput {
|
|
||||||
return {
|
|
||||||
path: sort.path,
|
|
||||||
ascending: sort.ascending
|
|
||||||
};
|
|
||||||
}
|
|
||||||
private convertFilter(filter: IFilter): IGraphQLAdvanceQueryFilterInput {
|
|
||||||
if (filter.type == "Composite") {
|
|
||||||
const compositeFilter = filter as ICompositeFilter;
|
|
||||||
return {
|
|
||||||
not: false,
|
|
||||||
and: compositeFilter.and,
|
|
||||||
type: FilterType.COMPOSITE,
|
|
||||||
filters: compositeFilter.filters.map(this.convertFilter.bind(this)),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const simpleFilter = filter as ISimpleFilter;
|
|
||||||
return {
|
|
||||||
filters: null,
|
|
||||||
and: filter.and,
|
|
||||||
not: false,
|
|
||||||
path: simpleFilter.path,
|
|
||||||
type: this.resolveFilterType(simpleFilter.type),
|
|
||||||
value: {
|
|
||||||
stringValue: simpleFilter.value as string
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private resolveFilterType(type: string): FilterType {
|
|
||||||
return type ? type.toUpperCase() as any: null;
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (type)
|
|
||||||
{
|
|
||||||
if (type.toUpperCase() == 'EQUAL') return FilterType.EQUAL
|
|
||||||
if (type.toUpperCase() == 'CONTAINS') return FilterType.CONTAINS
|
|
||||||
if (type.toUpperCase() == 'STARTSWITH') return FilterType.STARTSWITH
|
|
||||||
if (type.toUpperCase() == 'ENDSWITH') return FilterType.ENDSWITH
|
|
||||||
if (type.toUpperCase() == 'COMPOSITE') return FilterType.COMPOSITE
|
|
||||||
if (type.toUpperCase() == 'NOTEQUAL') return FilterType.NOTEQUAL
|
|
||||||
if (type.toUpperCase() == 'GREATERTHAN') return FilterType.GREATERTHAN
|
|
||||||
if (type.toUpperCase() == 'LESSTHANOREQUAL') return FilterType.LESSTHANOREQUAL
|
|
||||||
if (type.toUpperCase() == 'GREATERTHANOREQUAL') return FilterType.GREATERTHANOREQUAL
|
|
||||||
if (type.toUpperCase() == 'LESSTHAN') return FilterType.LESSTHAN
|
|
||||||
if (type.toUpperCase() == 'IN') return FilterType.IN
|
|
||||||
if (type.toUpperCase() == 'NOTIN') return FilterType.NOTIN
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error('unknown filter type');*/
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
import { Injectable } from '@angular/core';
|
|
||||||
import { IQueryCriteria, IDataSource } from '@poweredsoft/data';
|
|
||||||
import { Apollo } from 'apollo-angular';
|
|
||||||
import { GraphQLDataSourceOptionsBuilder } from './GraphQLDataSourceOptionsBuilder';
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class GraphQLDataSourceService
|
|
||||||
{
|
|
||||||
constructor(private apollo: Apollo) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
createDataSourceOptionsBuilder<TModel, TKey>(
|
|
||||||
queryName: string,
|
|
||||||
queryInputName: string,
|
|
||||||
querySelect: string | string[],
|
|
||||||
keyResolver: (model: TModel) => TKey,
|
|
||||||
defaultCriteria: IQueryCriteria,
|
|
||||||
manageNotificationMessage: boolean = true) : GraphQLDataSourceOptionsBuilder<TModel, TKey>
|
|
||||||
{
|
|
||||||
if (Array.isArray(querySelect))
|
|
||||||
querySelect = querySelect.join(' ');
|
|
||||||
|
|
||||||
return new GraphQLDataSourceOptionsBuilder(
|
|
||||||
this.apollo,
|
|
||||||
queryName,
|
|
||||||
queryInputName,
|
|
||||||
querySelect,
|
|
||||||
keyResolver,
|
|
||||||
defaultCriteria,
|
|
||||||
manageNotificationMessage
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,103 +0,0 @@
|
|||||||
export enum AggregateType {
|
|
||||||
COUNT,
|
|
||||||
SUM,
|
|
||||||
AVG,
|
|
||||||
LONGCOUNT,
|
|
||||||
MIN,
|
|
||||||
MAX,
|
|
||||||
FIRST,
|
|
||||||
FIRSTORDEFAULT,
|
|
||||||
LAST,
|
|
||||||
LASTORDEFAULT
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum FilterType {
|
|
||||||
EQUAL,
|
|
||||||
CONTAINS,
|
|
||||||
STARTSWITH,
|
|
||||||
ENDSWITH,
|
|
||||||
COMPOSITE,
|
|
||||||
NOTEQUAL,
|
|
||||||
GREATERTHAN,
|
|
||||||
LESSTHANOREQUAL,
|
|
||||||
GREATERTHANOREQUAL,
|
|
||||||
LESSTHAN,
|
|
||||||
IN,
|
|
||||||
NOTIN
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGraphQLVariantInput {
|
|
||||||
dateTimeValue?: Date
|
|
||||||
decimalValue?: number
|
|
||||||
intValue?: number
|
|
||||||
longValue?: number
|
|
||||||
stringValue?: string
|
|
||||||
booleanValue?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGraphQLVariantResult {
|
|
||||||
dateTimeValue?: string;
|
|
||||||
decimalValue?: number;
|
|
||||||
intValue?: number;
|
|
||||||
json?: string;
|
|
||||||
longValue?: number;
|
|
||||||
stringValue?: string;
|
|
||||||
booleanValue?: boolean;
|
|
||||||
typeName: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGraphQLAdvanceQueryAggregateInput {
|
|
||||||
path?: string;
|
|
||||||
type: AggregateType;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGraphQLAdvanceQueryAggregateResult {
|
|
||||||
path: string
|
|
||||||
type: string
|
|
||||||
value: IGraphQLVariantResult
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGraphQLAdvanceQueryFilterInput {
|
|
||||||
and?: boolean
|
|
||||||
filters?: IGraphQLAdvanceQueryFilterInput[]
|
|
||||||
not?: boolean
|
|
||||||
path?: string
|
|
||||||
type: FilterType
|
|
||||||
value?: IGraphQLVariantInput
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGraphQLAdvanceQueryGroupInput {
|
|
||||||
ascending?: boolean
|
|
||||||
path: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGraphQLAdvanceQuerySortInput {
|
|
||||||
ascending?: boolean
|
|
||||||
path: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGraphQLAdvanceQueryInput<T> {
|
|
||||||
aggregates?: IGraphQLAdvanceQueryAggregateInput[]
|
|
||||||
filters?: IGraphQLAdvanceQueryFilterInput[]
|
|
||||||
groups?: IGraphQLAdvanceQueryGroupInput[]
|
|
||||||
page?: number
|
|
||||||
pageSize?: number
|
|
||||||
sorts?: IGraphQLAdvanceQuerySortInput[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGraphQLAdvanceGroupResult<T> {
|
|
||||||
aggregates?: IGraphQLAdvanceQueryAggregateResult[]
|
|
||||||
data?: T[]
|
|
||||||
groupPath?: string
|
|
||||||
groupValue?: IGraphQLVariantResult
|
|
||||||
hasSubGroups?: boolean
|
|
||||||
subGroups?: IGraphQLAdvanceGroupResult<T>[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGraphQLAdvanceQueryResult<T> {
|
|
||||||
aggregates?: IGraphQLAdvanceQueryAggregateResult[];
|
|
||||||
data?: T[];
|
|
||||||
groups?: IGraphQLAdvanceGroupResult<T>[];
|
|
||||||
numberOfPages?: number;
|
|
||||||
totalRecords: number;
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
import { GraphQLDataSourceService } from "./lib/graphql-datas-source.service";
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Public API Surface of ngx-data-apollo
|
|
||||||
*/
|
|
||||||
|
|
||||||
export * from './lib/graphql-datas-source.service';
|
|
||||||
export * from './lib/GraphQLDataSourceOptionsBuilder';
|
|
||||||
export * from './lib/models';
|
|
@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../../../tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "../../../out-tsc/lib",
|
|
||||||
"target": "es2015",
|
|
||||||
"declaration": true,
|
|
||||||
"inlineSources": true,
|
|
||||||
"types": [],
|
|
||||||
"lib": [
|
|
||||||
"dom",
|
|
||||||
"es2018"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"angularCompilerOptions": {
|
|
||||||
"annotateForClosureCompiler": true,
|
|
||||||
"skipTemplateCodegen": true,
|
|
||||||
"strictMetadataEmit": true,
|
|
||||||
"fullTemplateTypeCheck": true,
|
|
||||||
"strictInjectionParameters": true,
|
|
||||||
"enableResourceInlining": true
|
|
||||||
},
|
|
||||||
"exclude": [
|
|
||||||
"src/test.ts",
|
|
||||||
"**/*.spec.ts"
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../../../tslint.json",
|
|
||||||
"rules": {
|
|
||||||
"directive-selector": [
|
|
||||||
true,
|
|
||||||
"attribute",
|
|
||||||
"lib",
|
|
||||||
"camelCase"
|
|
||||||
],
|
|
||||||
"component-selector": [
|
|
||||||
true,
|
|
||||||
"element",
|
|
||||||
"lib",
|
|
||||||
"kebab-case"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@poweredsoft/ngx-data",
|
|
||||||
"version": "0.0.22",
|
|
||||||
"peerDependencies": {
|
|
||||||
"@angular/common": "^8.2.4",
|
|
||||||
"@angular/core": "^8.2.4",
|
|
||||||
"@poweredsoft/data": "^0.0.31",
|
|
||||||
"rxjs": "^6.5.3"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,128 +0,0 @@
|
|||||||
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>; } = {};
|
|
||||||
protected _keyResolver: (model: TModel) => TKey;
|
|
||||||
protected _defaultCriteria: IQueryCriteria;
|
|
||||||
protected _query: IDataSourceQueryAdapterOptions<TModel>;
|
|
||||||
|
|
||||||
constructor(protected http: HttpClient) {
|
|
||||||
}
|
|
||||||
|
|
||||||
createDataSource(): IDataSource<TModel> {
|
|
||||||
return new DataSource<TModel>(this.createOptions());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected createTransport(): IDataSourceTransportOptions<TModel> {
|
|
||||||
let ret: IDataSourceTransportOptions<TModel> = {
|
|
||||||
query: this._query,
|
|
||||||
commands: this._commands
|
|
||||||
};
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public keyResolver(resolver: (model: TModel) => TKey) {
|
|
||||||
this._keyResolver = resolver;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
createOptions(): IDataSourceOptions<TModel> {
|
|
||||||
let ret: IDataSourceOptions<TModel> = {
|
|
||||||
resolveIdField: this._keyResolver,
|
|
||||||
defaultCriteria: this._defaultCriteria,
|
|
||||||
transport: this.createTransport()
|
|
||||||
};
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _messageErrorHandler(err: HttpErrorResponse) {
|
|
||||||
|
|
||||||
if (typeof err.error == "object") {
|
|
||||||
// if status not okay then its an exception error
|
|
||||||
if (err.error.hasOwnProperty('Message') && typeof (err.error['Message']) == "string") {
|
|
||||||
return throwError(<IDataSourceErrorMessage>{
|
|
||||||
type: 'message',
|
|
||||||
message: err.error['Message']
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (err.error.hasOwnProperty('message') && typeof (err.error['message']) == "string") {
|
|
||||||
return throwError(<IDataSourceErrorMessage>{
|
|
||||||
type: 'message',
|
|
||||||
message: err.error['message']
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// general error message
|
|
||||||
if (typeof (err.error) == "string") {
|
|
||||||
return throwError(<IDataSourceErrorMessage>{
|
|
||||||
type: 'message',
|
|
||||||
message: err.error
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return throwError(<IDataSourceErrorMessage>{
|
|
||||||
type: 'message',
|
|
||||||
message: 'UNEXPECTED_ERROR_MESSAGE'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private _handleErrorPipe(err: HttpErrorResponse): Observable<IDataSourceError> {
|
|
||||||
|
|
||||||
if (err.status == 400) {
|
|
||||||
if (err.error && err.error.errors)
|
|
||||||
return throwError(<IDataSourceValidationError>{
|
|
||||||
type: 'validation',
|
|
||||||
errors: err.error.errors
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return this._messageErrorHandler(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public addCommandByCallback<TCommand, TCommandResult>(name: string, commandHandler: (command: TCommand) => Observable<TCommandResult>, resolveCommandModel?: (event: IResolveCommandModelEvent<TModel>) => Observable<TCommand & any>) {
|
|
||||||
const handleWrapper = command => {
|
|
||||||
return commandHandler(command).pipe(catchError(this._handleErrorPipe.bind(this)));
|
|
||||||
};
|
|
||||||
|
|
||||||
this._commands[name] = <IDataSourceCommandAdapterOptions<TModel>>{
|
|
||||||
adapter: {
|
|
||||||
handle: handleWrapper
|
|
||||||
},
|
|
||||||
resolveCommandModel: resolveCommandModel
|
|
||||||
};
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public addCommandByUrl<TCommand, TCommandResult>(name: string, url: string, resolveCommandModel?: (event: IResolveCommandModelEvent<TModel>) => Observable<TCommand & any>, beforeCommand?: (command: TCommand) => Observable<TCommand>) {
|
|
||||||
const handleWrapper = command => {
|
|
||||||
const finalBeforeCommand = beforeCommand || (_ => of(command));
|
|
||||||
return finalBeforeCommand(command)
|
|
||||||
.pipe(
|
|
||||||
switchMap(finalCommand => {
|
|
||||||
return this.http.post<TCommandResult>(url, finalCommand).pipe(catchError(this._handleErrorPipe.bind(this)));
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
this._commands[name] = <IDataSourceCommandAdapterOptions<TModel>>{
|
|
||||||
adapter: {
|
|
||||||
handle: handleWrapper
|
|
||||||
},
|
|
||||||
resolveCommandModel: resolveCommandModel
|
|
||||||
};
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
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";
|
|
||||||
|
|
||||||
export class HttpDataSourceOptionsBuilder<TModel, TKey>
|
|
||||||
extends BaseHttpDataSourceOptionsBuilder<TModel, TKey>
|
|
||||||
{
|
|
||||||
private _beforeRead: (TQuery: IQueryCriteria) => Observable<IQueryCriteria>;
|
|
||||||
|
|
||||||
|
|
||||||
constructor(http: HttpClient) {
|
|
||||||
super(http);
|
|
||||||
}
|
|
||||||
|
|
||||||
public beforeRead<TDynamicQuery extends IQueryCriteria>(beforeRead: (query: TDynamicQuery) => Observable<TDynamicQuery>) {
|
|
||||||
this._beforeRead = beforeRead;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public queryUrl(url: string) {
|
|
||||||
this._query = {
|
|
||||||
adapter: {
|
|
||||||
handle: (query: IQueryCriteria) => {
|
|
||||||
const finalBeforeRead = this._beforeRead || (t => of(query));
|
|
||||||
return finalBeforeRead(query)
|
|
||||||
.pipe(
|
|
||||||
switchMap(finalQuery => {
|
|
||||||
return this.http.post<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>(url, finalQuery);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public queryHandler<TQuery extends IQueryCriteria>(queryHandler: (query: TQuery) => Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>) {
|
|
||||||
this._query = {
|
|
||||||
adapter: {
|
|
||||||
handle: (query: TQuery) => {
|
|
||||||
const finalBeforeRead = this._beforeRead || (t => of(query));
|
|
||||||
return finalBeforeRead(query)
|
|
||||||
.pipe(
|
|
||||||
switchMap(finalQuery => {
|
|
||||||
return queryHandler(finalQuery as any);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultCriteria(criteria: IQueryCriteria) {
|
|
||||||
this._defaultCriteria = criteria;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,107 +0,0 @@
|
|||||||
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";
|
|
||||||
|
|
||||||
export class ListDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
|
||||||
extends BaseHttpDataSourceOptionsBuilder<TModel, TKey>
|
|
||||||
{
|
|
||||||
private _beforeRead: (query: IQueryCriteria) => Observable<TQuery>;
|
|
||||||
|
|
||||||
constructor(http: HttpClient) {
|
|
||||||
super(http);
|
|
||||||
}
|
|
||||||
|
|
||||||
public beforeRead(beforeRead: (query: IQueryCriteria) => Observable<TQuery>) {
|
|
||||||
this._beforeRead = beforeRead;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public queryUrlWithGet(url: string) {
|
|
||||||
this._query = {
|
|
||||||
adapter: {
|
|
||||||
handle: (query: IQueryCriteria) => {
|
|
||||||
const finalBeforeRead = this._beforeRead || ((_: IQueryCriteria) => of(<TQuery>{}));
|
|
||||||
return finalBeforeRead(query)
|
|
||||||
.pipe(
|
|
||||||
switchMap(finalQuery => {
|
|
||||||
return this.http.get<TModel[]>(url, {
|
|
||||||
params: this.convertToParams(finalQuery)
|
|
||||||
}).pipe(
|
|
||||||
map(result => {
|
|
||||||
return <IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>
|
|
||||||
{
|
|
||||||
totalRecords: result.length,
|
|
||||||
data: result
|
|
||||||
};
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected convertToParams(finalQuery: TQuery)
|
|
||||||
{
|
|
||||||
return Object.keys(finalQuery).reduce((prev, key) => {
|
|
||||||
prev[key] = finalQuery[key];
|
|
||||||
return prev;
|
|
||||||
}, {} as { [param: string]: string | string[]; });
|
|
||||||
}
|
|
||||||
|
|
||||||
public queryUrl(url: string) {
|
|
||||||
this._query = {
|
|
||||||
adapter: {
|
|
||||||
handle: (query: IQueryCriteria) => {
|
|
||||||
const finalBeforeRead = this._beforeRead || ((_: IQueryCriteria) => of(<TQuery>{}));
|
|
||||||
return finalBeforeRead(query)
|
|
||||||
.pipe(
|
|
||||||
switchMap(finalQuery => {
|
|
||||||
return this.http.post<TModel[]>(url, finalQuery).pipe(
|
|
||||||
map(result => {
|
|
||||||
return <IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>
|
|
||||||
{
|
|
||||||
totalRecords: result.length,
|
|
||||||
data: result
|
|
||||||
};
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public queryHandler(queryHandler: (query: IQueryCriteria) => Observable<TModel[]>) {
|
|
||||||
this._query = {
|
|
||||||
adapter: {
|
|
||||||
handle: (query: TQuery) => {
|
|
||||||
const finalBeforeRead = this._beforeRead || (t => of({}));
|
|
||||||
return finalBeforeRead(query)
|
|
||||||
.pipe(
|
|
||||||
switchMap(finalQuery => {
|
|
||||||
return queryHandler(finalQuery).pipe(
|
|
||||||
map(result => {
|
|
||||||
return <IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>{
|
|
||||||
totalRecords: result.length,
|
|
||||||
data: result
|
|
||||||
};
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,107 +0,0 @@
|
|||||||
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";
|
|
||||||
|
|
||||||
export class SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
|
||||||
extends BaseHttpDataSourceOptionsBuilder<TModel, TKey>
|
|
||||||
{
|
|
||||||
private _beforeRead: (query: IQueryCriteria) => Observable<TQuery>;
|
|
||||||
|
|
||||||
constructor(http: HttpClient) {
|
|
||||||
super(http);
|
|
||||||
}
|
|
||||||
|
|
||||||
public beforeRead(beforeRead: (query: IQueryCriteria) => Observable<TQuery>) {
|
|
||||||
this._beforeRead = beforeRead;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public queryUrlWithGet(url: string) {
|
|
||||||
this._query = {
|
|
||||||
adapter: {
|
|
||||||
handle: (query: IQueryCriteria) => {
|
|
||||||
const finalBeforeRead = this._beforeRead || ((query: IQueryCriteria) => of(<TQuery>{}));
|
|
||||||
return finalBeforeRead(query)
|
|
||||||
.pipe(
|
|
||||||
switchMap(finalQuery => {
|
|
||||||
return this.http.get<TModel>(url, {
|
|
||||||
params: this.convertToParams(finalQuery)
|
|
||||||
}).pipe(
|
|
||||||
map(result => {
|
|
||||||
return <IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>
|
|
||||||
{
|
|
||||||
totalRecords: result == null ? 0 : 1,
|
|
||||||
data: [result]
|
|
||||||
};
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected convertToParams(finalQuery: TQuery)
|
|
||||||
{
|
|
||||||
return Object.keys(finalQuery).reduce((prev, key) => {
|
|
||||||
prev[key] = finalQuery[key];
|
|
||||||
return prev;
|
|
||||||
}, {} as { [param: string]: string | string[]; });
|
|
||||||
}
|
|
||||||
|
|
||||||
public queryUrl(url: string) {
|
|
||||||
this._query = {
|
|
||||||
adapter: {
|
|
||||||
handle: (query: IQueryCriteria) => {
|
|
||||||
const finalBeforeRead = this._beforeRead || ((_: IQueryCriteria) => of(<TQuery>{}));
|
|
||||||
return finalBeforeRead(query)
|
|
||||||
.pipe(
|
|
||||||
switchMap(finalQuery => {
|
|
||||||
return this.http.post<TModel>(url, finalQuery).pipe(
|
|
||||||
map(result => {
|
|
||||||
return <IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>
|
|
||||||
{
|
|
||||||
totalRecords: result == null ? 0 : 1,
|
|
||||||
data: [result]
|
|
||||||
};
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public queryHandler(queryHandler: (query: IQueryCriteria) => Observable<TModel>) {
|
|
||||||
this._query = {
|
|
||||||
adapter: {
|
|
||||||
handle: (query: TQuery) => {
|
|
||||||
const finalBeforeRead = this._beforeRead || (t => of({}));
|
|
||||||
return finalBeforeRead(query)
|
|
||||||
.pipe(
|
|
||||||
switchMap(finalQuery => {
|
|
||||||
return queryHandler(finalQuery).pipe(
|
|
||||||
map(result => {
|
|
||||||
return <IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>{
|
|
||||||
totalRecords: result == null ? 0 : 1,
|
|
||||||
data: [result]
|
|
||||||
};
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
import { 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 {
|
|
||||||
constructor(private http: HttpClient) {
|
|
||||||
}
|
|
||||||
|
|
||||||
builder<TModel, TKey>() {
|
|
||||||
return new HttpDataSourceOptionsBuilder<TModel, TKey>(this.http);
|
|
||||||
}
|
|
||||||
|
|
||||||
singleBuilder<TQuery, TModel, TKey>() {
|
|
||||||
return new SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>(this.http);
|
|
||||||
}
|
|
||||||
|
|
||||||
listBuilder<TQuery, TModel, TKey>() {
|
|
||||||
return new ListDataSourceOptionsBuilder<TQuery, TModel, TKey>(this.http);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
import { NgModule } from '@angular/core';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@NgModule({
|
|
||||||
declarations: [],
|
|
||||||
imports: [
|
|
||||||
],
|
|
||||||
exports: [],
|
|
||||||
})
|
|
||||||
export class NgxDataModule { }
|
|
@ -1,130 +0,0 @@
|
|||||||
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';
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class GenericRestDataSourceService
|
|
||||||
{
|
|
||||||
constructor(private http: HttpClient) {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _handleErrorPipe(err: HttpErrorResponse) : Observable<IDataSourceError> {
|
|
||||||
|
|
||||||
if (err.status == 500) {
|
|
||||||
return throwError(<IDataSourceErrorMessage>{
|
|
||||||
type: 'message',
|
|
||||||
message: 'UNEXPECTED_ERROR_MESSAGE'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err.status == 400)
|
|
||||||
{
|
|
||||||
if (err.error && err.error.errors)
|
|
||||||
return throwError(<IDataSourceValidationError>{
|
|
||||||
type: 'validation',
|
|
||||||
errors: err.error.errors
|
|
||||||
});
|
|
||||||
|
|
||||||
// if status not okay then its an exception error
|
|
||||||
if (err.error.hasOwnProperty('Message') && typeof(err.error['Message']) == "string") {
|
|
||||||
return throwError(<IDataSourceErrorMessage>{
|
|
||||||
type: 'message',
|
|
||||||
message: err.error['Message']
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// general error message
|
|
||||||
if (typeof(err.error) == "string") {
|
|
||||||
return throwError(<IDataSourceErrorMessage>{
|
|
||||||
type: 'message',
|
|
||||||
message: err.error
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return throwError(<IDataSourceErrorMessage>{
|
|
||||||
type: 'message',
|
|
||||||
message: 'UNEXPECTED_ERROR_MESSAGE'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
createDataSourceOptions<TModel, TKey>(route: string, keyResolver: (model: TModel) => TKey, defaultCriteria: IQueryCriteria, beforeRead?: (query: IQueryCriteria) => Observable<IQueryCriteria>) : IDataSourceOptions<TModel>
|
|
||||||
{
|
|
||||||
const dataSourceTransportOptions = this.createStandardRestTransportOptions<TModel, TKey>(route, keyResolver, beforeRead);
|
|
||||||
|
|
||||||
const dataSourceOptions: IDataSourceOptions<TModel> = {
|
|
||||||
defaultCriteria: defaultCriteria,
|
|
||||||
resolveIdField: keyResolver,
|
|
||||||
transport: dataSourceTransportOptions
|
|
||||||
};
|
|
||||||
|
|
||||||
return dataSourceOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
setResolveCommand<TModel>(options: IDataSourceOptions<TModel>, name: string, resolveCommandModel: (event: IResolveCommandModelEvent<TModel>) => Observable<any>) {
|
|
||||||
options.transport.commands[name].resolveCommandModel = resolveCommandModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 => {
|
|
||||||
return this.http.post<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>(queryRoute, finalQuery);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const createCommand: IDataSourceCommandAdapterOptions<TModel> = {
|
|
||||||
adapter: {
|
|
||||||
handle: (command: TModel) => {
|
|
||||||
return this.http.post<TModel>(route, command).pipe(catchError(this._handleErrorPipe));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateCommand: IDataSourceCommandAdapterOptions<TModel> = {
|
|
||||||
adapter: {
|
|
||||||
handle: (command: TModel) => {
|
|
||||||
const key = keyResolver(command);
|
|
||||||
const updateRoute = `${route}/${encodeURIComponent(key as any)}`;
|
|
||||||
return this.http.put<TModel>(updateRoute, command).pipe(catchError(this._handleErrorPipe));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteCommand: IDataSourceCommandAdapterOptions<TModel> = {
|
|
||||||
adapter: {
|
|
||||||
handle: (command: TModel) => {
|
|
||||||
const key = keyResolver(command);
|
|
||||||
const updateRoute = `${route}/${encodeURIComponent(key as any)}`;
|
|
||||||
return this.http.delete<TModel>(updateRoute).pipe(catchError(this._handleErrorPipe));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
query: query,
|
|
||||||
commands: {
|
|
||||||
'create': createCommand,
|
|
||||||
'update': updateCommand,
|
|
||||||
'delete': deleteCommand
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../../../tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "../../../out-tsc/spec",
|
|
||||||
"types": [
|
|
||||||
"jasmine",
|
|
||||||
"node"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"src/test.ts"
|
|
||||||
],
|
|
||||||
"include": [
|
|
||||||
"**/*.spec.ts",
|
|
||||||
"**/*.d.ts"
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../../../tslint.json",
|
|
||||||
"rules": {
|
|
||||||
"directive-selector": [
|
|
||||||
true,
|
|
||||||
"attribute",
|
|
||||||
"lib",
|
|
||||||
"camelCase"
|
|
||||||
],
|
|
||||||
"component-selector": [
|
|
||||||
true,
|
|
||||||
"element",
|
|
||||||
"lib",
|
|
||||||
"kebab-case"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,7 +5,7 @@ import { Routes, RouterModule } from '@angular/router';
|
|||||||
const routes: Routes = [];
|
const routes: Routes = [];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [RouterModule.forRoot(routes)],
|
imports: [RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' })],
|
||||||
exports: [RouterModule]
|
exports: [RouterModule]
|
||||||
})
|
})
|
||||||
export class AppRoutingModule { }
|
export class AppRoutingModule { }
|
||||||
|
@ -1,49 +1,41 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import { GenericRestDataSourceService } from 'projects/poweredsoft/ngx-data/src/public-api';
|
import {of} from 'rxjs';
|
||||||
import { of, Observable } from 'rxjs';
|
import {IDataSource, IQueryCriteria} from '@poweredsoft/data';
|
||||||
import { DataSource, IDataSource, IQueryCriteria, IResolveCommandModelEvent } from '@poweredsoft/data';
|
import {HttpDataSourceService} from '@openharbor/ngx-data';
|
||||||
import { } from 'projects/poweredsoft/ngx-data-apollo/src/public-api';
|
|
||||||
import { Apollo } from 'apollo-angular';
|
|
||||||
import gql from 'graphql-tag';
|
|
||||||
import { map } from 'rxjs/operators';
|
|
||||||
import { DocumentNode } from 'graphql';
|
|
||||||
import { GraphQLDataSourceService, IGraphQLAdvanceQueryInput } from 'projects/poweredsoft/ngx-data-apollo/src/public-api';
|
|
||||||
import { TestService, ITestModel, IValidationTestCommand } from './services/test.service';
|
|
||||||
import { HttpDataSourceService} from '@poweredsoft/ngx-data';
|
|
||||||
|
|
||||||
export interface IContact
|
export interface IContact
|
||||||
{
|
{
|
||||||
id: number
|
id: number;
|
||||||
displayName: string
|
displayName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPerson {
|
export interface IPerson {
|
||||||
id: number,
|
id: number;
|
||||||
firstName: string,
|
firstName: string;
|
||||||
lastName: string
|
lastName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICreatePerson {
|
export interface ICreatePerson {
|
||||||
firstName: string
|
firstName: string;
|
||||||
lastName: string
|
lastName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IEchoCommand {
|
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 {
|
||||||
personId: number
|
personId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IListPersonQuery {
|
export interface IListPersonQuery {
|
||||||
search?: string
|
search?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -3,20 +3,13 @@ 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 { HttpClientModule } from '@angular/common/http';
|
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
|
||||||
import { GraphQLModule } from './graphql.module';
|
import { GraphQLModule } from './graphql.module';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({ declarations: [
|
||||||
declarations: [
|
AppComponent
|
||||||
AppComponent
|
],
|
||||||
],
|
bootstrap: [AppComponent], imports: [BrowserModule,
|
||||||
imports: [
|
AppRoutingModule,
|
||||||
HttpClientModule,
|
GraphQLModule], providers: [provideHttpClient(withInterceptorsFromDi())] })
|
||||||
BrowserModule,
|
|
||||||
AppRoutingModule,
|
|
||||||
GraphQLModule
|
|
||||||
],
|
|
||||||
providers: [],
|
|
||||||
bootstrap: [AppComponent]
|
|
||||||
})
|
|
||||||
export class AppModule { }
|
export class AppModule { }
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
import {NgModule} from '@angular/core';
|
|
||||||
import {ApolloModule, Apollo} from 'apollo-angular';
|
|
||||||
import {HttpLinkModule, HttpLink} from 'apollo-angular-link-http';
|
|
||||||
import {InMemoryCache} from 'apollo-cache-inmemory';
|
|
||||||
|
|
||||||
@NgModule({
|
|
||||||
exports: [ApolloModule, HttpLinkModule]
|
|
||||||
})
|
|
||||||
export class GraphQLModule {
|
|
||||||
constructor(apollo: Apollo,
|
|
||||||
httpLink: HttpLink)
|
|
||||||
{
|
|
||||||
const cache = new InMemoryCache();
|
|
||||||
|
|
||||||
const endpoint = "https://localhost:5001/graphql";
|
|
||||||
apollo.create({
|
|
||||||
link: httpLink.create({uri: endpoint}),
|
|
||||||
cache,
|
|
||||||
defaultOptions: {
|
|
||||||
query: {
|
|
||||||
fetchPolicy: 'network-only'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
import { Injectable } from '@angular/core';
|
|
||||||
import { IGraphQLAdvanceQueryInput, GraphQLDataSourceService } from 'projects/poweredsoft/ngx-data-apollo/src/public-api';
|
|
||||||
import { IQueryCriteria, DataSource } from '@poweredsoft/data';
|
|
||||||
import { of } from 'rxjs';
|
|
||||||
import { Apollo } from 'apollo-angular';
|
|
||||||
import gql from 'graphql-tag';
|
|
||||||
|
|
||||||
export interface IValidationTestCommand {
|
|
||||||
value: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ITestModel {
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ITestQuery extends IGraphQLAdvanceQueryInput<ITestModel> {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGenerateDatasource<T, TAdvanceQuery extends IGraphQLAdvanceQueryInput<T>> {
|
|
||||||
criteria: IQueryCriteria;
|
|
||||||
beforeReadQueryCriteria?: TAdvanceQuery
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGenerateItemDatasource extends IGenerateDatasource<ITestModel, ITestQuery> {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class TestService {
|
|
||||||
constructor(private graphQLService: GraphQLDataSourceService, private apollo: Apollo) { }
|
|
||||||
|
|
||||||
generateDatasource(options: IGenerateItemDatasource) {
|
|
||||||
const keyResolver = (m: ITestModel) => m.id;
|
|
||||||
let builder = this.graphQLService.createDataSourceOptionsBuilder<ITestModel, string>(
|
|
||||||
"test",
|
|
||||||
"TestQueryInput",
|
|
||||||
[
|
|
||||||
'id'
|
|
||||||
],
|
|
||||||
keyResolver,
|
|
||||||
options.criteria
|
|
||||||
);
|
|
||||||
|
|
||||||
if (options.beforeReadQueryCriteria) {
|
|
||||||
builder.beforeRead<ITestQuery>(query => {
|
|
||||||
return of({ ...query, ...options.beforeReadQueryCriteria });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.addMutation<IValidationTestCommand, string>(
|
|
||||||
'validationTest',
|
|
||||||
'validationTest',
|
|
||||||
(command) => {
|
|
||||||
return this.apollo.mutate<string>({
|
|
||||||
mutation:gql`mutation executeValidationTest($command: ValidationTestCommandInput) {
|
|
||||||
validationTest(params: $command)
|
|
||||||
}`,
|
|
||||||
variables: {
|
|
||||||
command: command
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return new DataSource<ITestModel>(builder.create());
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,4 +13,4 @@ export const environment = {
|
|||||||
* This import should be commented out in production mode because it will have a negative impact
|
* This import should be commented out in production mode because it will have a negative impact
|
||||||
* on performance if an error is thrown.
|
* on performance if an error is thrown.
|
||||||
*/
|
*/
|
||||||
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.
|
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
|
||||||
|
@ -18,16 +18,6 @@
|
|||||||
* BROWSER POLYFILLS
|
* BROWSER POLYFILLS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
|
|
||||||
// import 'classlist.js'; // Run `npm install --save classlist.js`.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Web Animations `@angular/platform-browser/animations`
|
|
||||||
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
|
|
||||||
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
|
|
||||||
*/
|
|
||||||
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By default, zone.js will patch all possible macroTask and DomEvents
|
* By default, zone.js will patch all possible macroTask and DomEvents
|
||||||
* user can disable parts of macroTask/DomEvents patch by setting following flags
|
* user can disable parts of macroTask/DomEvents patch by setting following flags
|
||||||
@ -55,7 +45,7 @@
|
|||||||
/***************************************************************************************************
|
/***************************************************************************************************
|
||||||
* Zone JS is required by default for Angular itself.
|
* Zone JS is required by default for Angular itself.
|
||||||
*/
|
*/
|
||||||
import 'zone.js/dist/zone'; // Included with Angular CLI.
|
import 'zone.js'; // Included with Angular CLI.
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************************************
|
/***************************************************************************************************
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
||||||
|
|
||||||
import 'zone.js/dist/zone-testing';
|
import 'zone.js/testing';
|
||||||
import { getTestBed } from '@angular/core/testing';
|
import { getTestBed } from '@angular/core/testing';
|
||||||
import {
|
import {
|
||||||
BrowserDynamicTestingModule,
|
BrowserDynamicTestingModule,
|
||||||
@ -12,7 +12,9 @@ declare const require: any;
|
|||||||
// First, initialize the Angular testing environment.
|
// First, initialize the Angular testing environment.
|
||||||
getTestBed().initTestEnvironment(
|
getTestBed().initTestEnvironment(
|
||||||
BrowserDynamicTestingModule,
|
BrowserDynamicTestingModule,
|
||||||
platformBrowserDynamicTesting()
|
platformBrowserDynamicTesting(), {
|
||||||
|
teardown: { destroyAfterEach: false }
|
||||||
|
}
|
||||||
);
|
);
|
||||||
// Then we find all the tests.
|
// Then we find all the tests.
|
||||||
const context = require.context('./', true, /\.spec\.ts$/);
|
const context = require.context('./', true, /\.spec\.ts$/);
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"src/polyfills.ts"
|
"src/polyfills.ts"
|
||||||
],
|
],
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*.ts"
|
"src/**/*.d.ts"
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"src/test.ts",
|
"src/test.ts",
|
||||||
|
@ -4,13 +4,13 @@
|
|||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"outDir": "./dist/out-tsc",
|
"outDir": "./dist/out-tsc",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
"declaration": false,
|
"declaration": false,
|
||||||
"downlevelIteration": true,
|
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"importHelpers": true,
|
"importHelpers": true,
|
||||||
"target": "es2015",
|
"target": "es2020",
|
||||||
"typeRoots": [
|
"typeRoots": [
|
||||||
"node_modules/@types"
|
"node_modules/@types"
|
||||||
],
|
],
|
||||||
@ -20,18 +20,9 @@
|
|||||||
"esnext.asynciterable"
|
"esnext.asynciterable"
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@poweredsoft/ngx-data": [
|
"@openharbor/ngx-data": [
|
||||||
"dist/poweredsoft/ngx-data"
|
"./projects/openharbor/ngx-data/src/public-api"
|
||||||
],
|
],
|
||||||
"@poweredsoft/ngx-data/*": [
|
|
||||||
"dist/poweredsoft/ngx-data/*"
|
|
||||||
],
|
|
||||||
"@poweredsoft/ngx-data-apollo": [
|
|
||||||
"dist/poweredsoft/ngx-data-apollo"
|
|
||||||
],
|
|
||||||
"@poweredsoft/ngx-data-apollo/*": [
|
|
||||||
"dist/poweredsoft/ngx-data-apollo/*"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
|
92
tslint.json
92
tslint.json
@ -1,92 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "tslint:recommended",
|
|
||||||
"rules": {
|
|
||||||
"array-type": false,
|
|
||||||
"arrow-parens": false,
|
|
||||||
"deprecation": {
|
|
||||||
"severity": "warning"
|
|
||||||
},
|
|
||||||
"component-class-suffix": true,
|
|
||||||
"contextual-lifecycle": true,
|
|
||||||
"directive-class-suffix": true,
|
|
||||||
"directive-selector": [
|
|
||||||
true,
|
|
||||||
"attribute",
|
|
||||||
"app",
|
|
||||||
"camelCase"
|
|
||||||
],
|
|
||||||
"component-selector": [
|
|
||||||
true,
|
|
||||||
"element",
|
|
||||||
"app",
|
|
||||||
"kebab-case"
|
|
||||||
],
|
|
||||||
"import-blacklist": [
|
|
||||||
true,
|
|
||||||
"rxjs/Rx"
|
|
||||||
],
|
|
||||||
"interface-name": false,
|
|
||||||
"max-classes-per-file": false,
|
|
||||||
"max-line-length": [
|
|
||||||
true,
|
|
||||||
140
|
|
||||||
],
|
|
||||||
"member-access": false,
|
|
||||||
"member-ordering": [
|
|
||||||
true,
|
|
||||||
{
|
|
||||||
"order": [
|
|
||||||
"static-field",
|
|
||||||
"instance-field",
|
|
||||||
"static-method",
|
|
||||||
"instance-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"no-consecutive-blank-lines": false,
|
|
||||||
"no-console": [
|
|
||||||
true,
|
|
||||||
"debug",
|
|
||||||
"info",
|
|
||||||
"time",
|
|
||||||
"timeEnd",
|
|
||||||
"trace"
|
|
||||||
],
|
|
||||||
"no-empty": false,
|
|
||||||
"no-inferrable-types": [
|
|
||||||
true,
|
|
||||||
"ignore-params"
|
|
||||||
],
|
|
||||||
"no-non-null-assertion": true,
|
|
||||||
"no-redundant-jsdoc": true,
|
|
||||||
"no-switch-case-fall-through": true,
|
|
||||||
"no-use-before-declare": true,
|
|
||||||
"no-var-requires": false,
|
|
||||||
"object-literal-key-quotes": [
|
|
||||||
true,
|
|
||||||
"as-needed"
|
|
||||||
],
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"quotemark": [
|
|
||||||
true,
|
|
||||||
"single"
|
|
||||||
],
|
|
||||||
"trailing-comma": false,
|
|
||||||
"no-conflicting-lifecycle": true,
|
|
||||||
"no-host-metadata-property": true,
|
|
||||||
"no-input-rename": true,
|
|
||||||
"no-inputs-metadata-property": true,
|
|
||||||
"no-output-native": true,
|
|
||||||
"no-output-on-prefix": true,
|
|
||||||
"no-output-rename": true,
|
|
||||||
"no-outputs-metadata-property": true,
|
|
||||||
"template-banana-in-box": true,
|
|
||||||
"template-no-negated-async": true,
|
|
||||||
"use-lifecycle-interface": true,
|
|
||||||
"use-pipe-transform-interface": true
|
|
||||||
},
|
|
||||||
"rulesDirectory": [
|
|
||||||
"codelyzer"
|
|
||||||
]
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user