Skip to content
Permalink
Browse files

feat(service-worker): add JSON schema for service worker config

  • Loading branch information...
cyrilletuzi committed Dec 29, 2018
1 parent 0754ef1 commit d03afccf529862dcbda8427f87e1b794286515a2
@@ -40,7 +40,6 @@ ng_package(
srcs = [
"package.json",
"safety-worker.js",
"schema.json",
"//packages/service-worker/config:package.json",
],
data = [
@@ -1,6 +1,9 @@
package(default_visibility = ["//visibility:public"])

exports_files(["package.json"])
exports_files([
"package.json",
"schema.json"
])

load("//tools:defaults.bzl", "ng_module")

@@ -6,7 +6,7 @@
},
"index": {
"type": "string",
"description": "Specifies the file that serves as the index page to satisfy navigation requests. Usually this is /index.html."
"description": "Specifies the file that serves as the index page to satisfy navigation requests. Usually this is '/index.html'."
},
"assetGroups": {
"type": "array",
@@ -24,29 +24,29 @@
"lazy"
],
"default": "prefetch",
"description": "The installMode determines how these resources are initially cached. prefetch tells the Angular service worker to fetch every single listed resource while it's caching the current version of the app. This is bandwidth-intensive but ensures resources are available whenever they're requested, even if the browser is currently offline. lazy does not cache any of the resources up front. Instead, the Angular service worker only caches resources for which it receives requests. This is an on-demand caching mode. Resources that are never requested will not be cached. This is useful for things like images at different resolutions, so the service worker only caches the correct assets for the particular screen and orientation."
"description": "Determines how the resources are initially cached. 'prefetch' tells the Angular service worker to fetch every single listed resource while it's caching the current version of the app. This is bandwidth-intensive but ensures resources are available whenever they're requested, even if the browser is currently offline. 'lazy' does not cache any of the resources up front. Instead, the Angular service worker only caches resources for which it receives requests. This is an on-demand caching mode. Resources that are never requested will not be cached. This is useful for things like images at different resolutions, so the service worker only caches the correct assets for the particular screen and orientation."
},
"updateMode": {
"enum": [
"prefetch",
"lazy"
],
"description": "For resources already in the cache, the updateMode determines the caching behavior when a new version of the app is discovered. Any resources in the group that have changed since the previous version are updated in accordance with updateMode. prefetch tells the service worker to download and cache the changed resources immediately. lazy tells the service worker to not cache those resources. Instead, it treats them as unrequested and waits until they're requested again before updating them. An updateMode of lazy is only valid if the installMode is also lazy. Default to the same value as installMode."
"description": "For resources already in the cache, determines the caching behavior when a new version of the app is discovered. Any resources in the group that have changed since the previous version are updated in accordance with 'updateMode'. 'prefetch' tells the service worker to download and cache the changed resources immediately. 'lazy' tells the service worker to not cache those resources. Instead, it treats them as unrequested and waits until they're requested again before updating them. An 'updateMode' of lazy is only valid if the 'installMode' is also lazy. Default to the same value as 'installMode'."
},
"resources": {
"type": "object",
"description": "This section describes the resources to cache",
"description": "This section describes the resources to cache.",
"properties": {
"files": {
"type": "array",
"description": "files lists patterns that match files in the distribution directory. These can be single files or glob-like patterns that match a number of files.",
"description": "Lists patterns that match files in the distribution directory. These can be single files or glob-like patterns that match a number of files.",
"items": {
"type": "string"
}
},
"urls": {
"type": "array",
"description": "urls includes both URLs and URL patterns that will be matched at runtime. These resources are not fetched directly and do not have content hashes, but they will be cached according to their HTTP headers. This is most useful for CDNs such as the Google Fonts service. (Negative glob patterns are not supported and ? will be matched literally; i.e. it will not match any character other than ?.)",
"description": "Includes both URLs and URL patterns that will be matched at runtime. These resources are not fetched directly and do not have content hashes, but they will be cached according to their HTTP headers. This is most useful for CDNs such as the Google Fonts service. (Negative glob patterns are not supported and '?' will be matched literally; i.e. it will not match any character other than '?'.)",
"items": {
"type": "string"
}
@@ -62,7 +62,7 @@
},
"dataGroups": {
"type": "array",
"description": "Unlike asset resources, data requests are not versioned along with the app. They're cached according to manually-configured policies that are more useful for situations such as API requests and other data dependencies.",
"description": "Policies for caching data requests, such as API requests and other data dependencies. Unlike asset resources, data requests are not versioned along with the app.",
"items": {
"type": "object",
"properties": {
@@ -72,15 +72,15 @@
},
"urls": {
"type": "array",
"description": "A list of URL patterns. URLs that match these patterns will be cached according to this data group's policy. (Negative glob patterns are not supported and ? will be matched literally; i.e. it will not match any character other than ?.)",
"description": "A list of URL patterns. URLs that match these patterns will be cached according to this data group's policy. (Negative glob patterns are not supported and '?' will be matched literally; i.e. it will not match any character other than '?'.)",
"items": {
"type": "string"
}
},
"version": {
"type": "integer",
"default": 1,
"description": "Occasionally APIs change formats in a way that is not backward-compatible. A new version of the app may not be compatible with the old API format and thus may not be compatible with existing cached resources from that API. version provides a mechanism to indicate that the resources being cached have been updated in a backwards-incompatible way, and that the old cache entries—those from previous versions—should be discarded. version is an integer field and defaults to 0."
"description": "Occasionally APIs change formats in a way that is not backward-compatible. A new version of the app may not be compatible with the old API format and thus may not be compatible with existing cached resources from that API. 'version' provides a mechanism to indicate that the resources being cached have been updated in a backwards-incompatible way, and that the old cache entries—those from previous versions—should be discarded."
},
"cacheConfig": {
"type": "object",
@@ -92,19 +92,19 @@
},
"maxAge": {
"type": "string",
"description": "The maxAge parameter indicates how long responses are allowed to remain in the cache before being considered invalid and evicted. maxAge is a duration string, using the following unit suffixes: d= days, h= hours, m= minutes, s= seconds, u= milliseconds. For example, the string 3d12h will cache content for up to three and a half days."
"description": "The maxAge parameter indicates how long responses are allowed to remain in the cache before being considered invalid and evicted. 'maxAge' is a duration string, using the following unit suffixes: d= days, h= hours, m= minutes, s= seconds, u= milliseconds. For example, the string '3d12h' will cache content for up to three and a half days."
},
"timeout": {
"type": "string",
"description": "This duration string specifies the network timeout. The network timeout is how long the Angular service worker will wait for the network to respond before using a cached response, if configured to do so. timeout is a duration string, using the following unit suffixes: d= days, h= hours, m= minutes, s= seconds, u= milliseconds. For example, the string 5s30u will translate to five seconds and 30 milliseconds of network timeout."
"description": "This duration string specifies the network timeout. The network timeout is how long the Angular service worker will wait for the network to respond before using a cached response, if configured to do so. 'timeout' is a duration string, using the following unit suffixes: d= days, h= hours, m= minutes, s= seconds, u= milliseconds. For example, the string '5s30u' will translate to five seconds and 30 milliseconds of network timeout."
},
"strategy": {
"enum": [
"freshness",
"performance"
],
"default": "performance",
"description": "The Angular service worker can use either of two caching strategies for data resources. performance, the default, optimizes for responses that are as fast as possible. If a resource exists in the cache, the cached version is used. This allows for some staleness, depending on the maxAge, in exchange for better performance. This is suitable for resources that don't change often; for example, user avatar images. freshness optimizes for currency of data, preferentially fetching requested data from the network. Only if the network times out, according to timeout, does the request fall back to the cache. This is useful for resources that change frequently; for example, account balances."
"description": "The Angular service worker can use either of two caching strategies for data resources. 'performance', the default, optimizes for responses that are as fast as possible. If a resource exists in the cache, the cached version is used. This allows for some staleness, depending on the 'maxAge', in exchange for better performance. This is suitable for resources that don't change often; for example, user avatar images. freshness optimizes for currency of data, preferentially fetching requested data from the network. Only if the network times out, according to 'timeout', does the request fall back to the cache. This is useful for resources that change frequently; for example, account balances."
}
},
"required": [
@@ -122,7 +122,7 @@
},
"navigationUrls": {
"type": "array",
"description": "This optional section enables you to specify a custom list of URLs that will be redirected to the index file.",
"description": "This optional section enables you to specify a custom list of URLs or URL patterns that will be redirected to the 'index' file.",
"items": {
"type": "string"
}
@@ -22,7 +22,6 @@ export type Duration = string;
* @publicApi
*/
export interface Config {
$schema?: string;
appData?: {};
index: string;
assetGroups?: AssetGroup[];
@@ -22,7 +22,6 @@ describe('Generator', () => {
});
const gen = new Generator(fs, '/test');
const res = gen.process({
$schema: '',
appData: {
test: true,
},
@@ -10,7 +10,6 @@ export interface AssetGroup {
}

export interface Config {
$schema?: string;
appData?: {};
assetGroups?: AssetGroup[];
dataGroups?: DataGroup[];

0 comments on commit d03afcc

Please sign in to comment.
You can’t perform that action at this time.