Skip to content

Commit

Permalink
Add types for [workbox-build] (#42069)
Browse files Browse the repository at this point in the history
* Add types for workbox-build

* Remove package.json

* Fix lint errors

* Fix types

* Fix tests

* Remove TS requirement
  • Loading branch information
prichey committed Feb 11, 2020
1 parent db4d8c5 commit 28ff2e3
Show file tree
Hide file tree
Showing 10 changed files with 781 additions and 0 deletions.
150 changes: 150 additions & 0 deletions types/workbox-build/_types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import { RouteHandlerCallback, RouteMatchCallback } from 'workbox-routing';

export interface ManifestEntry {
/**
* The URL to the asset in the manifest.
*/
url: string;

/**
* The revision details for the file. This is a hash generated by node
* based on the file contents.
*/
revision?: string;

/**
* Integrity metadata that will be used when making the network request
* for the URL. based on the file contents.
*/
integrity?: string;
}

export type ManifestTransform = (
/**
* The full array of entries, prior to the current transformation.
*/
manifestEntries: ManifestEntry[],

/**
* When used in the webpack plugins, this param
* will be set to the current `compilation`.
*/
compilation?: object,
) => Promise<ManifestTransformResult>;

export interface ManifestTransformResult {
manifest: ManifestEntry[];
warnings: Array<string | undefined>;
}

export interface RuntimeCachingEntry {
/**
* * Either the name of one of the [built-in strategy classes](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-strategies)
* or custom handler callback to use when the generated route matches.
*/
handler: string | RouteHandlerCallback;

/**
* The value that will be passed to [`registerRoute()`](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-routing#.registerRoute),
* used to determine whether the generated route will match a given request.
*/
urlPattern: string | RegExp | RouteMatchCallback;

/**
* The [HTTP method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) that
* will match the generated route.
*
* @default 'GET'
*/
method?: string;

options?: RuntimeCachingEntryOptions;
}

export interface RuntimeCachingEntryOptions {
backgroundSync?: {
/**
* The `name` property to use when creating the
* [`BackgroundSyncPlugin`](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-background-sync.BackgroundSyncPlugin).
*/
name?: string;

/**
* The `options` property to use when creating the
* [`BackgroundSyncPlugin`](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-background-sync.BackgroundSyncPlugin).
*/
options?: object;
};

broadcastUpdate?: {
/**
* The `channelName` property to use when creating the
* [`BroadcastCacheUpdatePlugin`](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-broadcast-update.BroadcastUpdatePlugin).
*/
channelName?: string;

/**
* The `options` property to use when creating the
* [`BroadcastCacheUpdatePlugin`](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-broadcast-update.BroadcastUpdatePlugin).
*/
options?: object;
};

cacheableResponse?: {
/**
* The `headers` property to use when creating the
* [`CacheableResponsePlugin`](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-cacheable-response.CacheableResponsePlugin).
*/
headers?: object;

/**
* The `statuses` property to use when creating the
* [`CacheableResponsePlugin`](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-cacheable-response.CacheableResponsePlugin).
*/
statuses?: number[];
};

/**
* The `cacheName` to use when constructing one of the [Workbox strategy classes](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-strategies.html).
*/
cacheName?: string;

/**
* The `fetchOptions` property value to use when constructing one of the
* [Workbox strategy classes](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-strategies.html).
*/
fetchOptions?: object;

expiration?: {
/**
* The `maxAgeSeconds` property to use when creating the
* [`ExpirationPlugin`](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-expiration.ExpirationPlugin.html)
*/
maxAgeSeconds?: number;

/**
* The `maxEntries` property to use when creating the
* [`ExpirationPlugin`](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-expiration.ExpirationPlugin.html)
*/
maxEntries?: number;
};

/**
* The `matchOptions` property value to use when constructing one of the
* [Workbox strategy classes](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-strategies.html).
*/
matchOptions?: object;

/**
* The `networkTimeoutSeconds` property value to use when creating a
* [`NetworkFirst`](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-strategies.NetworkFirst) strategy.
*/
networkTimeoutSeconds?: number;

/**
* One or more [additional plugins](https://developers.google.com/web/tools/workbox/guides/using-plugins#custom_plugins)
* to apply to the handler. Useful when you want a plugin that doesn't have a
* "shortcut" configuration.
*/
plugins?: object[];
}

0 comments on commit 28ff2e3

Please sign in to comment.