ing
This commit is contained in:
commit
241d657149
46
.gitignore
vendored
Normal file
46
.gitignore
vendored
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# compiled output
|
||||||
|
/dist
|
||||||
|
/dist-server
|
||||||
|
/tmp
|
||||||
|
/out-tsc
|
||||||
|
/docs
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
|
||||||
|
# IDEs and editors
|
||||||
|
/.idea
|
||||||
|
.project
|
||||||
|
.classpath
|
||||||
|
.c9/
|
||||||
|
*.launch
|
||||||
|
.settings/
|
||||||
|
*.sublime-workspace
|
||||||
|
|
||||||
|
# IDE - VSCode
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
|
||||||
|
# misc
|
||||||
|
/.sass-cache
|
||||||
|
/connect.lock
|
||||||
|
/coverage
|
||||||
|
/libpeerconnection.log
|
||||||
|
npm-debug.log
|
||||||
|
testem.log
|
||||||
|
/typings
|
||||||
|
|
||||||
|
# e2e
|
||||||
|
/e2e/*.js
|
||||||
|
/e2e/*.map
|
||||||
|
|
||||||
|
# System Files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
yarn.lock
|
9
.make-package.js
Normal file
9
.make-package.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
const fs = require('fs');
|
||||||
|
const packageJson = JSON.parse(fs.readFileSync('./package.json').toString());
|
||||||
|
|
||||||
|
delete packageJson.devDependencies;
|
||||||
|
delete packageJson.scripts;
|
||||||
|
|
||||||
|
packageJson.private = false;
|
||||||
|
|
||||||
|
fs.writeFileSync('./dist/package.json', JSON.stringify(packageJson, null, 2));
|
21
License
Normal file
21
License
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2017
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
5483
package-lock.json
generated
Normal file
5483
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
43
package.json
Normal file
43
package.json
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
{
|
||||||
|
"name": "@loafer/ng-rest",
|
||||||
|
"description": "Angular REST",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"license": "MIT",
|
||||||
|
"private": true,
|
||||||
|
"main": "./index.js",
|
||||||
|
"typings": "./index.d.ts",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.loafle.net/loafer/typescript/ng-rest.git"
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"registry": "https://nexus.loafle.net/repository/npm-loafle/"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "Loafle <loafer@loafle.com>",
|
||||||
|
"scripts": {
|
||||||
|
"generate:package": "node .make-package.js",
|
||||||
|
"generate:doc": "rimraf docs && typedoc --out docs --target es6 --theme minimal --mode file src",
|
||||||
|
"bundle": "rimraf dist && tsc",
|
||||||
|
"build": "npm run bundle && npm run generate:package && npm run generate:doc"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@angular/common": "^5.2.9",
|
||||||
|
"@angular/core": "^5.2.9",
|
||||||
|
"rxjs": "^5.5.8"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/jasmine": "~2.8.5",
|
||||||
|
"@types/node": "^9.3.0",
|
||||||
|
"jasmine-core": "~2.8.0",
|
||||||
|
"prettier": "^1.12.1",
|
||||||
|
"rimraf": "^2.6.2",
|
||||||
|
"ts-jest": "^22.4.6",
|
||||||
|
"ts-node": "^6.0.3",
|
||||||
|
"tslint": "^5.10.0",
|
||||||
|
"tslint-config-prettier": "^1.12.0",
|
||||||
|
"tslint-config-standard": "^7.0.0",
|
||||||
|
"typedoc": "^0.11.1",
|
||||||
|
"typescript": "^2.8.3"
|
||||||
|
}
|
||||||
|
}
|
64
src/client/RESTClient.ts
Normal file
64
src/client/RESTClient.ts
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import { Injectable, Inject } from '@angular/core';
|
||||||
|
import { Location } from '@angular/common';
|
||||||
|
import { HttpClient, HttpHeaders, HttpParams, HttpErrorResponse } from '@angular/common/http';
|
||||||
|
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import 'rxjs/add/operator/do';
|
||||||
|
import 'rxjs/add/operator/map';
|
||||||
|
import 'rxjs/add/operator/catch';
|
||||||
|
import 'rxjs/add/operator/timeout';
|
||||||
|
import 'rxjs/add/observable/throw';
|
||||||
|
|
||||||
|
import {
|
||||||
|
RESTError,
|
||||||
|
RESTClientError,
|
||||||
|
} from '../protocol';
|
||||||
|
|
||||||
|
export class RESTClient {
|
||||||
|
constructor(
|
||||||
|
private _baseURL: string,
|
||||||
|
private _httpClient: HttpClient,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public get httpClient(): HttpClient {
|
||||||
|
return this._httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public request<T>(method: string, entry: string, options?: {
|
||||||
|
body?: any;
|
||||||
|
headers?: HttpHeaders | {
|
||||||
|
[header: string]: string | string[];
|
||||||
|
};
|
||||||
|
observe?: 'body';
|
||||||
|
params?: HttpParams | {
|
||||||
|
[param: string]: string | string[];
|
||||||
|
};
|
||||||
|
responseType?: 'json';
|
||||||
|
reportProgress?: boolean;
|
||||||
|
withCredentials?: boolean;
|
||||||
|
}): Observable<T> {
|
||||||
|
return this._httpClient
|
||||||
|
.request<T>(method, Location.joinWithSlash(this._baseURL, entry), options)
|
||||||
|
.map(response => response)
|
||||||
|
.catch((error: HttpErrorResponse) => {
|
||||||
|
const restClientError: RESTClientError = {
|
||||||
|
request: {
|
||||||
|
method: method,
|
||||||
|
entry: entry,
|
||||||
|
options: options,
|
||||||
|
},
|
||||||
|
response: error.error,
|
||||||
|
};
|
||||||
|
|
||||||
|
console.error(restClientError);
|
||||||
|
// const aryMsg = error.error.message.split('|');
|
||||||
|
// const resError: RESTError = {
|
||||||
|
// code: error.error.code,
|
||||||
|
// message: aryMsg[0],
|
||||||
|
// data: aryMsg[1] === 'null' ? '' : aryMsg[1],
|
||||||
|
// };
|
||||||
|
return Observable.throw(restClientError);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
1
src/client/index.ts
Normal file
1
src/client/index.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export * from './RESTClient';
|
1
src/core/index.ts
Normal file
1
src/core/index.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export * from './token';
|
3
src/core/token.ts
Normal file
3
src/core/token.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import { InjectionToken } from '@angular/core';
|
||||||
|
|
||||||
|
export const _REST_BASE_URL = new InjectionToken('@loafer/ng-rest Internal Base URL');
|
1
src/index.ts
Normal file
1
src/index.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export * from './ng-rest.module';
|
64
src/ng-rest.module.ts
Normal file
64
src/ng-rest.module.ts
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import {
|
||||||
|
NgModule,
|
||||||
|
ModuleWithProviders,
|
||||||
|
Type,
|
||||||
|
Inject,
|
||||||
|
InjectionToken,
|
||||||
|
} from '@angular/core';
|
||||||
|
|
||||||
|
import {
|
||||||
|
_REST_BASE_URL,
|
||||||
|
} from './core';
|
||||||
|
|
||||||
|
import {
|
||||||
|
SERVICES, RESTService,
|
||||||
|
} from './service';
|
||||||
|
|
||||||
|
export interface RESTFeatureModuleConfig {
|
||||||
|
url?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RESTRootModuleConfig {
|
||||||
|
baseURL: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NgModule({})
|
||||||
|
export class RESTRootModule {
|
||||||
|
constructor(
|
||||||
|
private restService: RESTService,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NgModule({})
|
||||||
|
export class RESTFeatureModule {
|
||||||
|
constructor(
|
||||||
|
private restService: RESTService,
|
||||||
|
private root: RESTRootModule,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NgModule({})
|
||||||
|
export class RESTModule {
|
||||||
|
static forRoot(config: RESTRootModuleConfig): ModuleWithProviders {
|
||||||
|
return {
|
||||||
|
ngModule: RESTRootModule,
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: _REST_BASE_URL,
|
||||||
|
useValue: config.baseURL,
|
||||||
|
},
|
||||||
|
SERVICES,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static forFeature(config: RESTFeatureModuleConfig): ModuleWithProviders {
|
||||||
|
return {
|
||||||
|
ngModule: RESTFeatureModule,
|
||||||
|
providers: [
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
14
src/protocol/RESTError.ts
Normal file
14
src/protocol/RESTError.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
export interface RESTClientError {
|
||||||
|
request: {
|
||||||
|
method: string;
|
||||||
|
entry: string;
|
||||||
|
options?: any;
|
||||||
|
};
|
||||||
|
response: RESTError;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RESTError {
|
||||||
|
code: number;
|
||||||
|
message: string;
|
||||||
|
data?: any;
|
||||||
|
}
|
1
src/protocol/index.ts
Normal file
1
src/protocol/index.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export * from './RESTError';
|
7
src/service/index.ts
Normal file
7
src/service/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export * from './rest.service';
|
||||||
|
|
||||||
|
import { RESTService } from './rest.service';
|
||||||
|
|
||||||
|
export const SERVICES = [
|
||||||
|
RESTService,
|
||||||
|
];
|
16
src/service/rest.service.spec.ts
Normal file
16
src/service/rest.service.spec.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import {} from 'jasmine';
|
||||||
|
|
||||||
|
import { TestBed, inject } from '@angular/core/testing';
|
||||||
|
import { RESTService } from './rest.service';
|
||||||
|
|
||||||
|
describe('RESTService', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [RESTService]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', inject([RESTService], (service: RESTService) => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
}));
|
||||||
|
});
|
26
src/service/rest.service.ts
Normal file
26
src/service/rest.service.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import { Injectable, Inject } from '@angular/core';
|
||||||
|
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
|
||||||
|
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
|
||||||
|
import { Location } from '@angular/common';
|
||||||
|
|
||||||
|
import 'rxjs/add/operator/do';
|
||||||
|
import 'rxjs/add/operator/map';
|
||||||
|
import 'rxjs/add/operator/catch';
|
||||||
|
import 'rxjs/add/operator/timeout';
|
||||||
|
import 'rxjs/add/observable/throw';
|
||||||
|
|
||||||
|
import { _REST_BASE_URL } from '../core';
|
||||||
|
import { RESTClient } from '../client';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class RESTService extends RESTClient {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@Inject(_REST_BASE_URL) _baseURL: string,
|
||||||
|
@Inject(HttpClient) _httpClient: HttpClient,
|
||||||
|
) {
|
||||||
|
super(_baseURL, _httpClient);
|
||||||
|
}
|
||||||
|
}
|
45
tsconfig.json
Normal file
45
tsconfig.json
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
{
|
||||||
|
"compileOnSave": false,
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": "./src",
|
||||||
|
"outDir": "./dist",
|
||||||
|
"sourceMap": true,
|
||||||
|
"declaration": true,
|
||||||
|
"newLine": "LF",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
|
||||||
|
/* Strict Type-Checking Options */
|
||||||
|
// "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
|
||||||
|
// "strictNullChecks": true /* Enable strict null checks. */,
|
||||||
|
// "strictFunctionTypes": true /* Enable strict checking of function types. */,
|
||||||
|
// "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
|
||||||
|
// "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
|
||||||
|
// "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
|
||||||
|
|
||||||
|
/* Additional Checks */
|
||||||
|
// "noUnusedLocals": true /* Report errors on unused locals. */,
|
||||||
|
// "noUnusedParameters": true /* Report errors on unused parameters. */,
|
||||||
|
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
|
||||||
|
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
|
||||||
|
|
||||||
|
/* Debugging Options */
|
||||||
|
"traceResolution": false /* Report module resolution log messages. */,
|
||||||
|
"listEmittedFiles": false /* Print names of generated files part of the compilation. */,
|
||||||
|
"listFiles": false /* Print names of files part of the compilation. */,
|
||||||
|
"pretty": true /* Stylize errors and messages using color and context. */,
|
||||||
|
|
||||||
|
/* Experimental Options */
|
||||||
|
"experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
|
||||||
|
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,
|
||||||
|
|
||||||
|
"target": "es5",
|
||||||
|
"typeRoots": [
|
||||||
|
"node_modules/@types"
|
||||||
|
],
|
||||||
|
"types": [
|
||||||
|
],
|
||||||
|
"lib": [
|
||||||
|
"es2015", "es2016", "es2017", "dom"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
34
tslint.json
Normal file
34
tslint.json
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
"extends": ["tslint:latest", "tslint-config-prettier", "tslint-immutable"],
|
||||||
|
"rules": {
|
||||||
|
"interface-name": [true, "never-prefix"],
|
||||||
|
// TODO: allow devDependencies only in **/*.spec.ts files:
|
||||||
|
// waiting on https://github.com/palantir/tslint/pull/3708
|
||||||
|
"no-implicit-dependencies": [true, "dev"],
|
||||||
|
|
||||||
|
/* tslint-immutable rules */
|
||||||
|
// Recommended built-in rules
|
||||||
|
"no-var-keyword": true,
|
||||||
|
"no-parameter-reassignment": true,
|
||||||
|
"typedef": [true, "call-signature"],
|
||||||
|
|
||||||
|
// Immutability rules
|
||||||
|
"readonly-keyword": true,
|
||||||
|
"readonly-array": true,
|
||||||
|
"no-let": true,
|
||||||
|
"no-object-mutation": true,
|
||||||
|
"no-delete": true,
|
||||||
|
"no-method-signature": true,
|
||||||
|
|
||||||
|
// Functional style rules
|
||||||
|
"no-this": true,
|
||||||
|
"no-class": true,
|
||||||
|
"no-mixed-interface": true,
|
||||||
|
"no-expression-statement": [
|
||||||
|
true,
|
||||||
|
{ "ignore-prefix": ["console.", "process.exit"] }
|
||||||
|
],
|
||||||
|
"no-if-statement": true
|
||||||
|
/* end tslint-immutable rules */
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user