From c12d2e5bbaaa90918a3da4e7876a9970341d110d Mon Sep 17 00:00:00 2001 From: tgpetrov Date: Fri, 9 Aug 2019 17:03:28 +0300 Subject: [PATCH] refactor: remove http module --- e2e/animation-examples/app/vendor.ts | 1 - e2e/animation-examples/package.json | 1 - e2e/modal-navigation-ng/package.json | 1 - e2e/nested-router-tab-view/package.json | 1 - e2e/renderer/package.json | 1 - e2e/routable-animations/package.json | 1 - e2e/router-tab-view/package.json | 1 - e2e/router/package.json | 1 - e2e/single-page/package.json | 1 - nativescript-angular/http/http.module.ts | 34 ------- nativescript-angular/http/index.ts | 1 - nativescript-angular/http/ns-http.ts | 71 -------------- nativescript-angular/index.ts | 1 - nativescript-angular/package.json | 2 - ng-sample/package.json | 1 - tests/app/tests/http.ts | 116 ----------------------- tests/package.json | 1 - 17 files changed, 236 deletions(-) delete mode 100644 nativescript-angular/http/http.module.ts delete mode 100644 nativescript-angular/http/index.ts delete mode 100644 nativescript-angular/http/ns-http.ts delete mode 100644 tests/app/tests/http.ts diff --git a/e2e/animation-examples/app/vendor.ts b/e2e/animation-examples/app/vendor.ts index fd29170f2..3dceebdfa 100644 --- a/e2e/animation-examples/app/vendor.ts +++ b/e2e/animation-examples/app/vendor.ts @@ -10,7 +10,6 @@ require("@angular/platform-browser"); require("@angular/core"); require("@angular/common"); require("@angular/forms"); -require("@angular/http"); require("@angular/router"); require("nativescript-angular/platform-static"); diff --git a/e2e/animation-examples/package.json b/e2e/animation-examples/package.json index 0e21b2e4b..8a6bbc7bc 100644 --- a/e2e/animation-examples/package.json +++ b/e2e/animation-examples/package.json @@ -18,7 +18,6 @@ "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", - "@angular/http": "8.0.0-beta.10", "@angular/platform-browser": "~8.2.0", "@angular/platform-browser-dynamic": "~8.2.0", "@angular/router": "~8.2.0", diff --git a/e2e/modal-navigation-ng/package.json b/e2e/modal-navigation-ng/package.json index 368f0e202..90ed2666d 100644 --- a/e2e/modal-navigation-ng/package.json +++ b/e2e/modal-navigation-ng/package.json @@ -18,7 +18,6 @@ "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", - "@angular/http": "8.0.0-beta.10", "@angular/platform-browser": "~8.2.0", "@angular/platform-browser-dynamic": "~8.2.0", "@angular/router": "~8.2.0", diff --git a/e2e/nested-router-tab-view/package.json b/e2e/nested-router-tab-view/package.json index f5550acff..89fd27d65 100644 --- a/e2e/nested-router-tab-view/package.json +++ b/e2e/nested-router-tab-view/package.json @@ -12,7 +12,6 @@ "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", - "@angular/http": "8.0.0-beta.10", "@angular/platform-browser": "~8.2.0", "@angular/platform-browser-dynamic": "~8.2.0", "@angular/router": "~8.2.0", diff --git a/e2e/renderer/package.json b/e2e/renderer/package.json index 01388980e..d59b354b6 100644 --- a/e2e/renderer/package.json +++ b/e2e/renderer/package.json @@ -11,7 +11,6 @@ "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", - "@angular/http": "8.0.0-beta.10", "@angular/platform-browser": "~8.2.0", "@angular/platform-browser-dynamic": "~8.2.0", "@angular/router": "~8.2.0", diff --git a/e2e/routable-animations/package.json b/e2e/routable-animations/package.json index bb31b1a2f..c3b47a425 100644 --- a/e2e/routable-animations/package.json +++ b/e2e/routable-animations/package.json @@ -12,7 +12,6 @@ "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", - "@angular/http": "8.0.0-beta.10", "@angular/platform-browser": "~8.2.0", "@angular/platform-browser-dynamic": "~8.2.0", "@angular/router": "~8.2.0", diff --git a/e2e/router-tab-view/package.json b/e2e/router-tab-view/package.json index bcc4a768c..523805087 100644 --- a/e2e/router-tab-view/package.json +++ b/e2e/router-tab-view/package.json @@ -12,7 +12,6 @@ "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", - "@angular/http": "8.0.0-beta.10", "@angular/platform-browser": "~8.2.0", "@angular/platform-browser-dynamic": "~8.2.0", "@angular/router": "~8.2.0", diff --git a/e2e/router/package.json b/e2e/router/package.json index ec60685ff..7b8954b3e 100644 --- a/e2e/router/package.json +++ b/e2e/router/package.json @@ -12,7 +12,6 @@ "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", - "@angular/http": "8.0.0-beta.10", "@angular/platform-browser": "~8.2.0", "@angular/platform-browser-dynamic": "~8.2.0", "@angular/router": "~8.2.0", diff --git a/e2e/single-page/package.json b/e2e/single-page/package.json index 66cb390ea..909e79e36 100644 --- a/e2e/single-page/package.json +++ b/e2e/single-page/package.json @@ -12,7 +12,6 @@ "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", - "@angular/http": "8.0.0-beta.10", "@angular/platform-browser": "~8.2.0", "@angular/platform-browser-dynamic": "~8.2.0", "@angular/router": "~8.2.0", diff --git a/nativescript-angular/http/http.module.ts b/nativescript-angular/http/http.module.ts deleted file mode 100644 index b6d35172c..000000000 --- a/nativescript-angular/http/http.module.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { NgModule } from "@angular/core"; -import { Http, XHRBackend, RequestOptions, HttpModule, XSRFStrategy } from "@angular/http"; - -import { NSXSRFStrategy, NSHttp } from "./ns-http"; -import { NSFileSystem } from "../file-system/ns-file-system"; - -export { NSHttp } from "./ns-http"; - -export function nsHttpFactory(backend, options, nsFileSystem) { - return new NSHttp(backend, options, nsFileSystem); -} - -export function nsXSRFStrategyFactory() { - return new NSXSRFStrategy(); -} - -@NgModule({ - providers: [ - { provide: XSRFStrategy, useFactory: nsXSRFStrategyFactory }, - NSFileSystem, - { - provide: Http, useFactory: nsHttpFactory, - deps: [XHRBackend, RequestOptions, NSFileSystem] - } - ], - imports: [ - HttpModule, - ], - exports: [ - HttpModule, - ] -}) -export class NativeScriptHttpModule { -} diff --git a/nativescript-angular/http/index.ts b/nativescript-angular/http/index.ts deleted file mode 100644 index 720657322..000000000 --- a/nativescript-angular/http/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./http.module"; diff --git a/nativescript-angular/http/ns-http.ts b/nativescript-angular/http/ns-http.ts deleted file mode 100644 index 5d609473e..000000000 --- a/nativescript-angular/http/ns-http.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { Injectable } from "@angular/core"; -import { - Http, - ConnectionBackend, - Request, - RequestOptions, - RequestOptionsArgs, - ResponseOptions, - ResponseType, - Response -} from "@angular/http"; -import { Observable } from "rxjs"; - -import { isLocalRequest, processLocalFileRequest } from "../http-client/http-utils"; - -import { NSFileSystem } from "../file-system/ns-file-system"; - -export class NSXSRFStrategy { - public configureRequest(_req: any) { - // noop - } -} - -@Injectable() -export class NSHttp extends Http { - constructor(backend: ConnectionBackend, defaultOptions: RequestOptions, private nsFileSystem: NSFileSystem) { - super(backend, defaultOptions); - } - - /** - * Performs a request with `request` http method. - */ - request(req: string | Request, options?: RequestOptionsArgs): Observable { - const urlString = typeof req === "string" ? req : req.url; - if (isLocalRequest(urlString)) { - return this.requestLocalFile(urlString); - } else { - return super.request(req, options); - } - } - - /** - * Performs a request with `get` http method. - */ - get(url: string, options?: RequestOptionsArgs): Observable { - if (isLocalRequest(url)) { - return this.requestLocalFile(url); - } else { - return super.get(url, options); - } - } - - private requestLocalFile(url: string): Observable { - return processLocalFileRequest( - url, - this.nsFileSystem, - createResponse, - createResponse - ); - } -} - -function createResponse(url: string, body: string | Object, status: number): Response { - return new Response(new ResponseOptions({ - body: body, - status: status, - statusText: "OK", - type: status === 200 ? ResponseType.Default : ResponseType.Error, - url: url - })); -} diff --git a/nativescript-angular/index.ts b/nativescript-angular/index.ts index e5f4bfb8b..db3cb4279 100644 --- a/nativescript-angular/index.ts +++ b/nativescript-angular/index.ts @@ -5,7 +5,6 @@ export * from "./platform"; export * from "./platform-static"; export * from "./router"; export * from "./forms"; -export * from "./http"; export * from "./directives"; export * from "./common/detached-loader"; export * from "./trace"; diff --git a/nativescript-angular/package.json b/nativescript-angular/package.json index e570f62b6..c82578388 100644 --- a/nativescript-angular/package.json +++ b/nativescript-angular/package.json @@ -50,7 +50,6 @@ "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", - "@angular/http": "8.0.0-beta.10", "@angular/platform-browser": "~8.2.0", "@angular/router": "~8.2.0", "rxjs": "^6.4.0", @@ -65,7 +64,6 @@ "@angular/compiler-cli": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", - "@angular/http": "8.0.0-beta.10", "@angular/platform-browser": "~8.2.0", "@angular/platform-browser-dynamic": "~8.2.0", "@angular/router": "~8.2.0", diff --git a/ng-sample/package.json b/ng-sample/package.json index 1028abb04..18cf74409 100644 --- a/ng-sample/package.json +++ b/ng-sample/package.json @@ -31,7 +31,6 @@ "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", - "@angular/http": "8.0.0-beta.10", "@angular/platform-browser": "~8.2.0", "@angular/platform-browser-dynamic": "~8.2.0", "@angular/router": "~8.2.0", diff --git a/tests/app/tests/http.ts b/tests/app/tests/http.ts deleted file mode 100644 index 7aa625fef..000000000 --- a/tests/app/tests/http.ts +++ /dev/null @@ -1,116 +0,0 @@ -// make sure you import mocha-config before @angular/core -import { assert } from "./test-config"; -import { - async, - inject, -} from "@angular/core/testing"; -import { ReflectiveInjector, Injectable } from "@angular/core"; -import { Request, BaseRequestOptions, ConnectionBackend, Http, Response, ResponseOptions } from "@angular/http"; -import { map } from "rxjs/operators"; -import { MockBackend } from "@angular/http/testing"; -import { NSHttp } from "nativescript-angular/http/ns-http"; -import { NSFileSystem } from "nativescript-angular/file-system/ns-file-system"; - -const AWESOME_TEAM: string = '[{"name":"Alex"}, {"name":"Rosen"}, {"name":"Panayot"}]'; - -// Filesystem mock -@Injectable() -export class NSFileSystemMock implements NSFileSystem { - public currentApp(): any { - return { path: "/app/dir" }; - } - - public fileFromPath(path: string): any { - if (path === "/app/dir/test.json") { - return { - readText: () => { return Promise.resolve(AWESOME_TEAM); } - }; - } - throw new Error("Opening non-existing file"); - } - - public fileExists(path: string): boolean { - return path === "/app/dir/test.json"; - } - -} - -describe("Http", () => { - let http: Http; - let backend: MockBackend; - - beforeEach(() => { - let injector = ReflectiveInjector.resolveAndCreate([ - BaseRequestOptions, - MockBackend, - { provide: NSFileSystem, useClass: NSFileSystemMock }, - { - provide: Http, - useFactory: function ( - connectionBackend: ConnectionBackend, - defaultOptions: BaseRequestOptions, - nsFileSystem: NSFileSystem) { - // HACK: cast backend to any to work around an angular typings problem - return new NSHttp(connectionBackend, defaultOptions, nsFileSystem); - }, - deps: [MockBackend, BaseRequestOptions, NSFileSystem] - } - ]); - - backend = injector.get(MockBackend); - http = injector.get(Http); - }); - - it("should work with local files prefixed with '~'", () => { - http.get("~/test.json").pipe( - map(res => res.json()) - ).subscribe((response: any) => { - assert.strictEqual(3, response.length); - assert.strictEqual("Alex", response[0].name); - }); - }); - - it("request method should work with local files prefixed with '~'", () => { - http.request("~/test.json").pipe( - map(res => res.json()) - ).subscribe((response: any) => { - assert.strictEqual(3, response.length); - assert.strictEqual("Alex", response[0].name); - }); - }); - - it("request method using Request type should work with local files prefixed with '~'", () => { - const url = "~/test.json"; - const req = new Request({ - method: 'GET', - url - }); - http.request(req).pipe( - map(res => res.json()) - ).subscribe((response: any) => { - assert.strictEqual(3, response.length); - assert.strictEqual("Alex", response[0].name); - }); - }); - - it("should work with local files prefixed with '/'", () => { - http.get("/test.json").pipe( - map(res => res.json()) - ).subscribe((response: any) => { - assert.strictEqual(3, response.length); - assert.strictEqual("Panayot", response[2].name); - }); - }); - - it("should work with remote files", () => { - let connection: any; - backend.connections.subscribe((c: any) => connection = c); - http.get("http://www.nativescript.org/test.json").pipe( - map(res => res.json()) - ).subscribe((response: any) => { - assert.strictEqual(3, response.length); - assert.strictEqual("Rosen", response[1].name); - }); - connection.mockRespond(new Response(new ResponseOptions({ body: AWESOME_TEAM }))); - }); -}); diff --git a/tests/package.json b/tests/package.json index c2178d682..55bd35ee1 100644 --- a/tests/package.json +++ b/tests/package.json @@ -24,7 +24,6 @@ "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", - "@angular/http": "8.0.0-beta.10", "@angular/platform-browser": "~8.2.0", "@angular/platform-browser-dynamic": "~8.2.0", "@angular/router": "~8.2.0",