From 5c3f29a89e61f274af3dc7f944d4ca0fba786a98 Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Tue, 4 Jul 2017 12:50:23 -0700 Subject: [PATCH] refactor: address comments in code review --- .../service-worker/e2e/server/page-object.ts | 8 +++ .../service-worker/e2e/server/server.ts | 8 +++ .../service-worker/e2e/test/sanity_e2e.ts | 8 +++ .../service-worker/protractor.config.js | 4 +- .../service-worker/src/app/app.component.html | 2 +- .../service-worker/src/app/app.component.ts | 8 +++ .../src/app/controller.component.ts | 10 ++- integration/service-worker/src/main.ts | 8 +++ integration/service-worker/src/polyfills.ts | 8 +++ integration/service-worker/src/test.ts | 8 +++ packages/service-worker/sdk/plugins/index.ts | 8 +++ .../service-worker/sdk/plugins/public_api.ts | 11 +++- .../sdk/plugins/src/dynamic/dynamic.ts | 8 +++ .../sdk/plugins/src/dynamic/group.ts | 8 +++ .../sdk/plugins/src/dynamic/linked.ts | 8 +++ .../sdk/plugins/src/dynamic/manifest.ts | 8 +++ .../plugins/src/dynamic/strategy/freshness.ts | 8 +++ .../src/dynamic/strategy/performance.ts | 8 +++ .../sdk/plugins/src/external/external.ts | 8 +++ .../sdk/plugins/src/routing/routing.ts | 8 +++ .../sdk/plugins/src/static/static.ts | 15 +++-- .../sdk/plugins/test/dynamic/group_spec.ts | 8 +++ .../sdk/plugins/test/dynamic/linked_spec.ts | 8 +++ packages/service-worker/sdk/public_api.ts | 2 +- packages/service-worker/sdk/src/bootstrap.ts | 13 +--- .../service-worker/sdk/src/facade/adapter.ts | 8 +++ .../service-worker/sdk/src/facade/cache.ts | 8 +++ .../service-worker/sdk/src/facade/events.ts | 8 +++ .../service-worker/sdk/src/facade/fetch.ts | 8 +++ packages/service-worker/sdk/src/fsa.ts | 8 +++ packages/service-worker/sdk/src/sha1.ts | 8 +++ .../sdk/src/typings/service-worker.d.ts | 8 +++ packages/service-worker/sdk/test/mock_spec.ts | 8 +++ .../service-worker/sdk/test/worker_spec.ts | 8 ++- packages/service-worker/src/debug.ts | 7 +- packages/service-worker/src/low_level.ts | 66 +++++++++---------- packages/service-worker/src/push.ts | 22 +++---- .../zprebuilt-test/src/prebuilt.ts | 10 ++- packages/service-worker/zprebuilt/index.ts | 8 +++ .../service-worker/zprebuilt/public_api.ts | 8 +++ .../service-worker/zprebuilt/src/prebuilt.ts | 10 ++- 41 files changed, 326 insertions(+), 78 deletions(-) diff --git a/integration/service-worker/e2e/server/page-object.ts b/integration/service-worker/e2e/server/page-object.ts index 737e9ae05c845..4139cd7afb791 100644 --- a/integration/service-worker/e2e/server/page-object.ts +++ b/integration/service-worker/e2e/server/page-object.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {browser, by, element, protractor} from 'protractor'; export class HarnessPageObject { diff --git a/integration/service-worker/e2e/server/server.ts b/integration/service-worker/e2e/server/server.ts index 751568c4660d6..e54d190fef154 100644 --- a/integration/service-worker/e2e/server/server.ts +++ b/integration/service-worker/e2e/server/server.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import express = require('express'); export function create(port: number, harnessPath: string): Promise { diff --git a/integration/service-worker/e2e/test/sanity_e2e.ts b/integration/service-worker/e2e/test/sanity_e2e.ts index affd43988b4ac..45ed50937c56a 100644 --- a/integration/service-worker/e2e/test/sanity_e2e.ts +++ b/integration/service-worker/e2e/test/sanity_e2e.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {create, Server} from '../server/server'; import {HarnessPageObject} from '../server/page-object'; diff --git a/integration/service-worker/protractor.config.js b/integration/service-worker/protractor.config.js index bdbb8607b7e04..173747afd80d7 100644 --- a/integration/service-worker/protractor.config.js +++ b/integration/service-worker/protractor.config.js @@ -32,9 +32,9 @@ exports.config = { }, /** - * ng2 related configuration + * Angular related configuration * - * useAllAngular2AppRoots: tells Protractor to wait for any angular2 apps on the page instead of just the one matching + * useAllAngular2AppRoots: tells Protractor to wait for any Angular apps on the page instead of just the one matching * `rootEl` * */ diff --git a/integration/service-worker/src/app/app.component.html b/integration/service-worker/src/app/app.component.html index 293099ed8725a..0f0ae32eff3ce 100644 --- a/integration/service-worker/src/app/app.component.html +++ b/integration/service-worker/src/app/app.component.html @@ -1,2 +1,2 @@

Service Worker Testing Harness

- \ No newline at end of file + \ No newline at end of file diff --git a/integration/service-worker/src/app/app.component.ts b/integration/service-worker/src/app/app.component.ts index 7b0f672831514..c35a7b0c3a062 100644 --- a/integration/service-worker/src/app/app.component.ts +++ b/integration/service-worker/src/app/app.component.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import { Component } from '@angular/core'; @Component({ diff --git a/integration/service-worker/src/app/controller.component.ts b/integration/service-worker/src/app/controller.component.ts index 9804f334307b1..aab39624c2343 100644 --- a/integration/service-worker/src/app/controller.component.ts +++ b/integration/service-worker/src/app/controller.component.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {Component} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {NgswModule, NgswPush, NgswUpdate, NgswDebug, NgswAppVersion} from '@angular/service-worker'; @@ -10,7 +18,7 @@ import 'rxjs/add/operator/startWith'; import 'rxjs/add/operator/take'; @Component({ - selector: 'controller', + selector: 'test-controller', template: `
diff --git a/integration/service-worker/src/main.ts b/integration/service-worker/src/main.ts index a9ca1caf8ceeb..aeecfd056091a 100644 --- a/integration/service-worker/src/main.ts +++ b/integration/service-worker/src/main.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; diff --git a/integration/service-worker/src/polyfills.ts b/integration/service-worker/src/polyfills.ts index fd01cc9f1ddbe..5b2b305964542 100644 --- a/integration/service-worker/src/polyfills.ts +++ b/integration/service-worker/src/polyfills.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + /** * This file includes polyfills needed by Angular and is loaded before the app. * You can add your own extra polyfills to this file. diff --git a/integration/service-worker/src/test.ts b/integration/service-worker/src/test.ts index cd612eeb0e2f2..e7a43ea3bb64b 100644 --- a/integration/service-worker/src/test.ts +++ b/integration/service-worker/src/test.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license +*/ + // This file is required by karma.conf.js and loads recursively all the .spec and framework files import 'zone.js/dist/long-stack-trace-zone'; diff --git a/packages/service-worker/sdk/plugins/index.ts b/packages/service-worker/sdk/plugins/index.ts index 9a85f300e2df0..78647fcfa7aff 100644 --- a/packages/service-worker/sdk/plugins/index.ts +++ b/packages/service-worker/sdk/plugins/index.ts @@ -1 +1,9 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + export * from './public_api'; \ No newline at end of file diff --git a/packages/service-worker/sdk/plugins/public_api.ts b/packages/service-worker/sdk/plugins/public_api.ts index 3856a6413a61e..13a1441ed9a9a 100644 --- a/packages/service-worker/sdk/plugins/public_api.ts +++ b/packages/service-worker/sdk/plugins/public_api.ts @@ -1,7 +1,16 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + export {Dynamic} from './src/dynamic/dynamic'; +export {DynamicStrategy} from './src/dynamic/group'; export {FreshnessCacheConfig, FreshnessStrategy} from './src/dynamic/strategy/freshness'; export {PerformanceCacheConfig, PerformanceStrategy} from './src/dynamic/strategy/performance'; export {ExternalContentCache, ExternalContentCacheOptions} from './src/external/external'; export {Push} from './src/push/push'; export {RouteRedirection} from './src/routing/routing'; -export {StaticContentCache, StaticContentCacheOptions} from './src/static/static'; +export {StaticContentCache} from './src/static/static'; diff --git a/packages/service-worker/sdk/plugins/src/dynamic/dynamic.ts b/packages/service-worker/sdk/plugins/src/dynamic/dynamic.ts index 069409a03e388..df8c411dc3679 100644 --- a/packages/service-worker/sdk/plugins/src/dynamic/dynamic.ts +++ b/packages/service-worker/sdk/plugins/src/dynamic/dynamic.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {FetchDelegate, FetchInstruction, NgSwCache, Operation, Plugin, PluginFactory, ScopedCache, UrlMatcher, VersionWorker, VersionWorkerImpl} from '@angular/service-worker/sdk'; import {DynamicGroup, DynamicStrategy, DynamicStrategyMap, ResponseWithSideEffect} from './group'; diff --git a/packages/service-worker/sdk/plugins/src/dynamic/group.ts b/packages/service-worker/sdk/plugins/src/dynamic/group.ts index 2c29ab27df0da..7f3dd8c2da7ee 100644 --- a/packages/service-worker/sdk/plugins/src/dynamic/group.ts +++ b/packages/service-worker/sdk/plugins/src/dynamic/group.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {Clock, NgSwAdapter, NgSwCache, ScopedCache, UrlConfig, UrlMatcher} from '@angular/service-worker/sdk'; import {CompareFn, SortedLinkedList} from './linked'; diff --git a/packages/service-worker/sdk/plugins/src/dynamic/linked.ts b/packages/service-worker/sdk/plugins/src/dynamic/linked.ts index ff11d93de1022..0231f49ef8b9e 100644 --- a/packages/service-worker/sdk/plugins/src/dynamic/linked.ts +++ b/packages/service-worker/sdk/plugins/src/dynamic/linked.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + /** * A node in in the linked list, with references to the next and previous nodes. * diff --git a/packages/service-worker/sdk/plugins/src/dynamic/manifest.ts b/packages/service-worker/sdk/plugins/src/dynamic/manifest.ts index 5bba457f0d34c..e4f026a3745f4 100644 --- a/packages/service-worker/sdk/plugins/src/dynamic/manifest.ts +++ b/packages/service-worker/sdk/plugins/src/dynamic/manifest.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {UrlConfig} from '@angular/service-worker/sdk'; /** diff --git a/packages/service-worker/sdk/plugins/src/dynamic/strategy/freshness.ts b/packages/service-worker/sdk/plugins/src/dynamic/strategy/freshness.ts index 69709aa91e429..ba52b33f8dbf0 100644 --- a/packages/service-worker/sdk/plugins/src/dynamic/strategy/freshness.ts +++ b/packages/service-worker/sdk/plugins/src/dynamic/strategy/freshness.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {Clock} from '@angular/service-worker/sdk'; import {DynamicGroup, DynamicStrategy, ResponseWithSideEffect, maybeRun} from '../group'; import {CacheConfig} from '../manifest'; diff --git a/packages/service-worker/sdk/plugins/src/dynamic/strategy/performance.ts b/packages/service-worker/sdk/plugins/src/dynamic/strategy/performance.ts index 5e20ff6d57a9b..055ab4253f4ef 100644 --- a/packages/service-worker/sdk/plugins/src/dynamic/strategy/performance.ts +++ b/packages/service-worker/sdk/plugins/src/dynamic/strategy/performance.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {DynamicGroup, DynamicStrategy, ResponseWithSideEffect, maybeRun} from '../group'; import {CacheConfig} from '../manifest'; diff --git a/packages/service-worker/sdk/plugins/src/external/external.ts b/packages/service-worker/sdk/plugins/src/external/external.ts index fe21371a15491..85f3126a5ea2c 100644 --- a/packages/service-worker/sdk/plugins/src/external/external.ts +++ b/packages/service-worker/sdk/plugins/src/external/external.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {FetchInstruction, Operation, Plugin, PluginFactory, VersionWorker, VersionWorkerImpl, cacheFromNetworkOp, fetchFromCacheInstruction,} from '@angular/service-worker/sdk'; interface UrlConfig { diff --git a/packages/service-worker/sdk/plugins/src/routing/routing.ts b/packages/service-worker/sdk/plugins/src/routing/routing.ts index f57ba81556a07..ac87530a7bbc1 100644 --- a/packages/service-worker/sdk/plugins/src/routing/routing.ts +++ b/packages/service-worker/sdk/plugins/src/routing/routing.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {rewriteUrlInstruction, FetchInstruction, Operation, Plugin, PluginFactory, VersionWorker, UrlConfig, UrlMatcher,} from '@angular/service-worker/sdk'; interface RouteMap { diff --git a/packages/service-worker/sdk/plugins/src/static/static.ts b/packages/service-worker/sdk/plugins/src/static/static.ts index d8c2c5c1fd80b..25efe23fe192e 100644 --- a/packages/service-worker/sdk/plugins/src/static/static.ts +++ b/packages/service-worker/sdk/plugins/src/static/static.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {FetchInstruction, LOG, Operation, Plugin, PluginFactory, Verbosity, VersionWorker, cacheFromNetworkOp, copyExistingOrFetchOp, deleteCacheOp, fetchFromCacheInstruction} from '@angular/service-worker/sdk'; interface UrlToHashMap { @@ -12,12 +20,7 @@ interface StaticManifest { /** * @experimental */ -export interface StaticContentCacheOptions { manifestKey?: string; } - -/** - * @experimental - */ -export function StaticContentCache(options?: StaticContentCacheOptions): +export function StaticContentCache(options?: {manifestKey?: string;}): PluginFactory { const manifestKey = (options && options.manifestKey) || 'static'; return (worker: VersionWorker) => new StaticContentCacheImpl(worker, manifestKey); diff --git a/packages/service-worker/sdk/plugins/test/dynamic/group_spec.ts b/packages/service-worker/sdk/plugins/test/dynamic/group_spec.ts index 7f96eaf966382..889ddfa4e8b69 100644 --- a/packages/service-worker/sdk/plugins/test/dynamic/group_spec.ts +++ b/packages/service-worker/sdk/plugins/test/dynamic/group_spec.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {NgSwAdapter, NgSwCacheImpl} from '@angular/service-worker/sdk'; import {MockCacheStorage, MockClock, TestAdapter} from '@angular/service-worker/sdk/testing'; diff --git a/packages/service-worker/sdk/plugins/test/dynamic/linked_spec.ts b/packages/service-worker/sdk/plugins/test/dynamic/linked_spec.ts index 3c922b9810225..5044ef9794326 100644 --- a/packages/service-worker/sdk/plugins/test/dynamic/linked_spec.ts +++ b/packages/service-worker/sdk/plugins/test/dynamic/linked_spec.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {SortedLinkedList} from '../../src/dynamic/linked'; function compareNumbers(a: number, b: number): number { diff --git a/packages/service-worker/sdk/public_api.ts b/packages/service-worker/sdk/public_api.ts index ef14c5020c4c8..16329868a1175 100644 --- a/packages/service-worker/sdk/public_api.ts +++ b/packages/service-worker/sdk/public_api.ts @@ -1,5 +1,5 @@ export {FetchDelegate, FetchInstruction, Operation, Plugin, PluginFactory, VersionWorker} from './src/api'; -export {BootstrapOptions, bootstrapServiceWorker} from './src/bootstrap'; +export {bootstrapServiceWorker} from './src/bootstrap'; export {ScopedCache} from './src/cache'; export {cacheFromNetworkOp, copyExistingCacheOp, copyExistingOrFetchOp, deleteCacheOp, fetchFromCacheInstruction, fetchFromNetworkInstruction, rewriteUrlInstruction} from './src/common'; export {Driver, DriverState} from './src/driver'; diff --git a/packages/service-worker/sdk/src/bootstrap.ts b/packages/service-worker/sdk/src/bootstrap.ts index 56039ad293489..a3a7731d88c7b 100644 --- a/packages/service-worker/sdk/src/bootstrap.ts +++ b/packages/service-worker/sdk/src/bootstrap.ts @@ -56,17 +56,10 @@ class NgSwBrowserAdapter implements NgSwAdapter { /** * @experimental */ -export interface BootstrapOptions { - manifestUrl?: string; - plugins?: PluginFactory[]; - logLevel?: Verbosity; +export function bootstrapServiceWorker(options?: { + manifestUrl?: string; plugins?: PluginFactory[]; logLevel?: Verbosity; logHandlers?: LogHandler[]; -} - -/** - * @experimental - */ -export function bootstrapServiceWorker(options?: BootstrapOptions): Driver { +}): Driver { const manifestUrl = (options && options.manifestUrl) || '/ngsw-manifest.json'; const plugins = (options && options.plugins) || []; diff --git a/packages/service-worker/sdk/src/facade/adapter.ts b/packages/service-worker/sdk/src/facade/adapter.ts index 30fb5740f9c47..e458f6599d11a 100644 --- a/packages/service-worker/sdk/src/facade/adapter.ts +++ b/packages/service-worker/sdk/src/facade/adapter.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + /** * @experimental */ diff --git a/packages/service-worker/sdk/src/facade/cache.ts b/packages/service-worker/sdk/src/facade/cache.ts index 9c18e4b0c4c48..63a3ed873dc45 100644 --- a/packages/service-worker/sdk/src/facade/cache.ts +++ b/packages/service-worker/sdk/src/facade/cache.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {NgSwAdapter} from './adapter'; /** diff --git a/packages/service-worker/sdk/src/facade/events.ts b/packages/service-worker/sdk/src/facade/events.ts index 91afdd7fa7257..e29ffbf242033 100644 --- a/packages/service-worker/sdk/src/facade/events.ts +++ b/packages/service-worker/sdk/src/facade/events.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + /** * @experimental */ diff --git a/packages/service-worker/sdk/src/facade/fetch.ts b/packages/service-worker/sdk/src/facade/fetch.ts index 63ede7e310d1f..12f19a0fd6ba2 100644 --- a/packages/service-worker/sdk/src/facade/fetch.ts +++ b/packages/service-worker/sdk/src/facade/fetch.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {NgSwAdapter} from './adapter'; /** diff --git a/packages/service-worker/sdk/src/fsa.ts b/packages/service-worker/sdk/src/fsa.ts index 3520fce5a6e44..54831e92ad315 100644 --- a/packages/service-worker/sdk/src/fsa.ts +++ b/packages/service-worker/sdk/src/fsa.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + const protocolVersion = 1; const worker = 'ngsw'; diff --git a/packages/service-worker/sdk/src/sha1.ts b/packages/service-worker/sdk/src/sha1.ts index 4a8744e9391aa..48a2f90cf6577 100644 --- a/packages/service-worker/sdk/src/sha1.ts +++ b/packages/service-worker/sdk/src/sha1.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + /** * Compute the SHA1 of the given string * diff --git a/packages/service-worker/sdk/src/typings/service-worker.d.ts b/packages/service-worker/sdk/src/typings/service-worker.d.ts index 2e15f22f2f158..9475f028d3ac1 100644 --- a/packages/service-worker/sdk/src/typings/service-worker.d.ts +++ b/packages/service-worker/sdk/src/typings/service-worker.d.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + declare interface ServiceWorkerGlobalScope { fetch(url: string|Request); caches: CacheStorage; diff --git a/packages/service-worker/sdk/test/mock_spec.ts b/packages/service-worker/sdk/test/mock_spec.ts index 4dfb2b0bb437d..6492aa73e5b25 100644 --- a/packages/service-worker/sdk/test/mock_spec.ts +++ b/packages/service-worker/sdk/test/mock_spec.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {TestWorkerDriver} from '../testing/src/mock'; class TestWorker {} diff --git a/packages/service-worker/sdk/test/worker_spec.ts b/packages/service-worker/sdk/test/worker_spec.ts index 4ddefb9be9cd7..2ecf5e8613a02 100644 --- a/packages/service-worker/sdk/test/worker_spec.ts +++ b/packages/service-worker/sdk/test/worker_spec.ts @@ -1,4 +1,10 @@ -import 'reflect-metadata'; +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ import {Observable} from 'rxjs/Rx'; diff --git a/packages/service-worker/src/debug.ts b/packages/service-worker/src/debug.ts index cd9a8e7c66f7c..6e8e3f278186b 100644 --- a/packages/service-worker/src/debug.ts +++ b/packages/service-worker/src/debug.ts @@ -35,10 +35,9 @@ export class NgswDebug { ping(): Promise { const nonce = this.sw.generateNonce(); fetch('/ngsw-log', {body: `sending ping with nonce ${nonce}`, method: 'POST'}); - const pongsWithNonce = op_filter.call( - this.sw.eventsOfType(EVENT_PONG), (pong: PongPayload) => pong.nonce === nonce) - as Observable; - const firstPongWithNonce = op_take.call(pongsWithNonce, 1) as Observable; + const pongsWithNonce = >(op_filter.call( + this.sw.eventsOfType(EVENT_PONG), (pong: PongPayload) => pong.nonce === nonce)); + const firstPongWithNonce = (op_take.call(pongsWithNonce, 1) as Observable); const recvPong = (op_toPromise.call(firstPongWithNonce) as Promise).then(() => undefined); const sendPing = this.sw.postMessage(CMD_PING, {nonce}); diff --git a/packages/service-worker/src/low_level.ts b/packages/service-worker/src/low_level.ts index dbd4bcb673673..80602f13520f1 100644 --- a/packages/service-worker/src/low_level.ts +++ b/packages/service-worker/src/low_level.ts @@ -86,32 +86,29 @@ export class NgswCommChannel { this.worker = this.events = errorObservable(ERR_SW_NOT_SUPPORTED); } else { const controllerChangeEvents = - obs_fromEvent(navigator.serviceWorker, 'controllerchange') as Observable; - const controllerChanges = - op_startWith.call(controllerChangeEvents, navigator.serviceWorker.controller) - as Observable; + >(obs_fromEvent(navigator.serviceWorker, 'controllerchange')); + const controllerChanges = >( + op_startWith.call(controllerChangeEvents, navigator.serviceWorker.controller)); - const currentController = obs_defer(() => obs_of(navigator.serviceWorker.controller)) - as Observable; + const currentController = >( + obs_defer(() => obs_of(navigator.serviceWorker.controller))); - const controllerWithChanges = obs_concat(currentController, controllerChanges) - as Observablethis.worker = - op_filter.call(controllerWithChanges, (c: ServiceWorker) => !!c) - as Observable; + const controllerWithChanges = + >(obs_concat(currentController, controllerChanges)); + this.worker = >( + op_filter.call(controllerWithChanges, (c: ServiceWorker) => !!c)); - this.registration = - op_switchMap.call(this.worker, () => navigator.serviceWorker.getRegistration()) - as Observable; + this.registration = >( + op_switchMap.call(this.worker, () => navigator.serviceWorker.getRegistration())); const channel = new BroadcastChannel('ngsw:broadcast'); - const rawEvents = obs_fromEvent(channel, 'message') as Observable; + const rawEvents = >(obs_fromEvent(channel, 'message')); const rawEventPayload = - op_map.call(rawEvents, (event: MessageEvent) => event.data) as Observable; - const eventsUnconnected = - op_filter.call(rawEventPayload, (event: Object) => !!event && !!(event as any)['type']) - as Observable>; - const events = op_publish.call(eventsUnconnected) as ConnectableObservable>; + >(op_map.call(rawEvents, (event: MessageEvent) => event.data)); + const eventsUnconnected = >>( + op_filter.call(rawEventPayload, (event: Object) => !!event && !!(event as any)['type'])); + const events = >>(op_publish.call(eventsUnconnected)); console.log(events); this.events = events; events.connect(); @@ -129,7 +126,7 @@ export class NgswCommChannel { protocolVersion: 1, payload, }); }); - return op_toPromise.call(sideEffect).then(() => undefined) as Promise; + return >(op_toPromise.call(sideEffect).then(() => undefined)); } /** @@ -150,33 +147,32 @@ export class NgswCommChannel { * @internal */ eventsOfType(type: string): Observable { - const matchingEvents = - op_filter.call(this.events, (event: FsaEvent) => event.type === 'NGSW_' + type) - as Observable>; - return op_map.call(matchingEvents, (event: FsaEvent) => event.payload) as Observable; + const matchingEvents = >>( + op_filter.call(this.events, (event: FsaEvent) => event.type === 'NGSW_' + type)); + return >(op_map.call(matchingEvents, (event: FsaEvent) => event.payload)); } /** * @internal */ nextEventOfType(type: string): Observable { - return op_take.call(this.eventsOfType(type), 1) as Observable; + return >(op_take.call(this.eventsOfType(type), 1)); } /** * @internal */ waitForStatus(nonce: number): Promise { - const statusEventsWithNonce = op_filter.call( - this.eventsOfType(EVENT_STATUS), (event: StatusEvent) => event.nonce === nonce) - as Observable; - const singleStatusEvent = op_take.call(statusEventsWithNonce, 1) as Observable; - const mapErrorAndValue = op_map.call(singleStatusEvent, (event: StatusEvent) => { - if (event.status) { - return undefined; - } - throw new Error(event.error !); - }) as Observable; + const statusEventsWithNonce = >(op_filter.call( + this.eventsOfType(EVENT_STATUS), (event: StatusEvent) => event.nonce === nonce)); + const singleStatusEvent = >(op_take.call(statusEventsWithNonce, 1)); + const mapErrorAndValue = + >(op_map.call(singleStatusEvent, (event: StatusEvent) => { + if (event.status) { + return undefined; + } + throw new Error(event.error !); + })); return op_toPromise.call(mapErrorAndValue); } } diff --git a/packages/service-worker/src/push.ts b/packages/service-worker/src/push.ts index f65ec7f15db34..6cfc1a89f46e8 100644 --- a/packages/service-worker/src/push.ts +++ b/packages/service-worker/src/push.ts @@ -27,21 +27,20 @@ export class NgswPush { readonly messages: Observable; readonly subscription: Observable; - private pushManager: Observableprivate subscriptionChanges: - Subject = new Subject(); + private pushManager: Observable; + private subscriptionChanges: Subject = + new Subject(); constructor(private sw: NgswCommChannel) { this.messages = op_map.call( this.sw.eventsOfType(EVENT_PUSH_MESSAGE), (message: {data: object}) => message.data); - this.pushManager = - op_map.call(this.sw.registration, (registration: ServiceWorkerRegistration) => { - return registration.pushManager; - }) as Observable; + this.pushManager = >(op_map.call( + this.sw.registration, + (registration: ServiceWorkerRegistration) => { return registration.pushManager; })); - const workerDrivenSubscriptions = op_switchMap.call( - this.pushManager, (pm: PushManager) => pm.getSubscription().then(sub => { return sub; })) - as Observable; + const workerDrivenSubscriptions = >(op_switchMap.call( + this.pushManager, (pm: PushManager) => pm.getSubscription().then(sub => { return sub; }))); this.subscription = obs_merge.call(workerDrivenSubscriptions, this.subscriptionChanges); } @@ -53,9 +52,8 @@ export class NgswPush { applicationServerKey[i] = key.charCodeAt(i); } pushOptions.applicationServerKey = applicationServerKey; - const subscribe = - op_switchMap.call(this.pushManager, (pm: PushManager) => pm.subscribe(pushOptions)) - as Observable; + const subscribe = >( + op_switchMap.call(this.pushManager, (pm: PushManager) => pm.subscribe(pushOptions))); const subscribeOnce = op_take.call(subscribe, 1); return (op_toPromise.call(subscribeOnce) as Promise).then(sub => { this.subscriptionChanges.next(sub); diff --git a/packages/service-worker/zprebuilt-test/src/prebuilt.ts b/packages/service-worker/zprebuilt-test/src/prebuilt.ts index cace7cbec6471..1588b025f8fc7 100644 --- a/packages/service-worker/zprebuilt-test/src/prebuilt.ts +++ b/packages/service-worker/zprebuilt-test/src/prebuilt.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {HttpHandler, Verbosity, bootstrapServiceWorker} from '@angular/service-worker/sdk'; import {Dynamic, ExternalContentCache, FreshnessStrategy, PerformanceStrategy, Push, RouteRedirection, StaticContentCache} from '@angular/service-worker/sdk/plugins'; @@ -20,5 +28,3 @@ export function main() { ], }); } - -main(); diff --git a/packages/service-worker/zprebuilt/index.ts b/packages/service-worker/zprebuilt/index.ts index 9a85f300e2df0..78647fcfa7aff 100644 --- a/packages/service-worker/zprebuilt/index.ts +++ b/packages/service-worker/zprebuilt/index.ts @@ -1 +1,9 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + export * from './public_api'; \ No newline at end of file diff --git a/packages/service-worker/zprebuilt/public_api.ts b/packages/service-worker/zprebuilt/public_api.ts index 2b2f70b584000..8e716941d9cde 100644 --- a/packages/service-worker/zprebuilt/public_api.ts +++ b/packages/service-worker/zprebuilt/public_api.ts @@ -1 +1,9 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + export {main} from './src/prebuilt'; \ No newline at end of file diff --git a/packages/service-worker/zprebuilt/src/prebuilt.ts b/packages/service-worker/zprebuilt/src/prebuilt.ts index edb304d97c727..c817680805e69 100644 --- a/packages/service-worker/zprebuilt/src/prebuilt.ts +++ b/packages/service-worker/zprebuilt/src/prebuilt.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + import {bootstrapServiceWorker} from '@angular/service-worker/sdk'; import {Dynamic, ExternalContentCache, FreshnessStrategy, PerformanceStrategy, Push, RouteRedirection, StaticContentCache} from '@angular/service-worker/sdk/plugins'; @@ -16,5 +24,3 @@ export function main() { ], }); } - -main(); \ No newline at end of file