Skip to content

Commit

Permalink
Export more classes/types publicly (#2955)
Browse files Browse the repository at this point in the history
* Export more classes/types

* Fixes for test cases

* Update packages/workbox-background-sync/src/StorableRequest.ts

* Update packages/workbox-background-sync/src/QueueStore.ts

Co-authored-by: Adriana Jara <32825533+tropicadri@users.noreply.github.com>
  • Loading branch information
jeffposnick and tropicadri committed Oct 14, 2021
1 parent 97fc646 commit e0bcb29
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 25 deletions.
14 changes: 14 additions & 0 deletions packages/workbox-background-sync/src/QueueStore.ts
@@ -0,0 +1,14 @@
/*
Copyright 2021 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/

import './_version.js';

// This is a temporary workaround to expose something from ./lib/ via our
// top-level public API.
// TODO: In Workbox v7, move the actual code from ./lib/ to this file.
export {QueueStore} from './lib/QueueStore';
14 changes: 14 additions & 0 deletions packages/workbox-background-sync/src/StorableRequest.ts
@@ -0,0 +1,14 @@
/*
Copyright 2021 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/

import './_version.js';

// This is a temporary workaround to expose something from ./lib/ via our
// top-level public API.
// TODO: In Workbox v7, move the actual code from ./lib/ to this file.
export {StorableRequest} from './lib/StorableRequest';
6 changes: 4 additions & 2 deletions packages/workbox-background-sync/src/index.ts
Expand Up @@ -6,8 +6,10 @@
https://opensource.org/licenses/MIT.
*/

import {Queue, QueueOptions} from './Queue.js';
import {BackgroundSyncPlugin} from './BackgroundSyncPlugin.js';
import {Queue, QueueOptions} from './Queue.js';
import {QueueStore} from './QueueStore.js';
import {StorableRequest} from './StorableRequest.js';

import './_version.js';

Expand Down Expand Up @@ -35,4 +37,4 @@ declare global {
/**
* @module workbox-background-sync
*/
export {BackgroundSyncPlugin, Queue, QueueOptions};
export {BackgroundSyncPlugin, Queue, QueueOptions, QueueStore, StorableRequest};
13 changes: 3 additions & 10 deletions packages/workbox-background-sync/src/lib/QueueStore.ts
Expand Up @@ -7,18 +7,19 @@
*/

import {assert} from 'workbox-core/_private/assert.js';
import '../_version.js';
import {
UnidentifiedQueueStoreEntry,
QueueStoreEntry,
QueueDb,
} from './QueueDb.js';
import '../_version.js';

/**
* A class to manage storing requests from a Queue in IndexedDB,
* indexed by their queue name for easier access.
*
* @private
* Most developers will not need to access this class directly;
* it is exposed for advanced use cases.
*/
export class QueueStore {
private readonly _queueName: string;
Expand All @@ -29,7 +30,6 @@ export class QueueStore {
* identified by their queue name.
*
* @param {string} queueName
* @private
*/
constructor(queueName: string) {
this._queueName = queueName;
Expand All @@ -43,7 +43,6 @@ export class QueueStore {
* @param {Object} entry.requestData
* @param {number} [entry.timestamp]
* @param {Object} [entry.metadata]
* @private
*/
async pushEntry(entry: UnidentifiedQueueStoreEntry): Promise<void> {
if (process.env.NODE_ENV !== 'production') {
Expand Down Expand Up @@ -75,7 +74,6 @@ export class QueueStore {
* @param {Object} entry.requestData
* @param {number} [entry.timestamp]
* @param {Object} [entry.metadata]
* @private
*/
async unshiftEntry(entry: UnidentifiedQueueStoreEntry): Promise<void> {
if (process.env.NODE_ENV !== 'production') {
Expand Down Expand Up @@ -111,7 +109,6 @@ export class QueueStore {
* Removes and returns the last entry in the queue matching the `queueName`.
*
* @return {Promise<QueueStoreEntry|undefined>}
* @private
*/
async popEntry(): Promise<QueueStoreEntry | undefined> {
return this._removeEntry(
Expand All @@ -123,7 +120,6 @@ export class QueueStore {
* Removes and returns the first entry in the queue matching the `queueName`.
*
* @return {Promise<QueueStoreEntry|undefined>}
* @private
*/
async shiftEntry(): Promise<QueueStoreEntry | undefined> {
return this._removeEntry(
Expand All @@ -136,7 +132,6 @@ export class QueueStore {
*
* @param {Object} options See {@link module:workbox-background-sync.Queue~getAll}
* @return {Promise<Array<Object>>}
* @private
*/
async getAll(): Promise<QueueStoreEntry[]> {
return await this._queueDb.getAllEntriesByQueueName(this._queueName);
Expand All @@ -147,7 +142,6 @@ export class QueueStore {
*
* @param {Object} options See {@link module:workbox-background-sync.Queue~size}
* @return {Promise<number>}
* @private
*/
async size(): Promise<number> {
return await this._queueDb.getEntryCountByQueueName(this._queueName);
Expand All @@ -161,7 +155,6 @@ export class QueueStore {
* as this class is not publicly exposed. An additional check would make
* this method slower than it needs to be.
*
* @private
* @param {number} id
*/
async deleteEntry(id: number): Promise<void> {
Expand Down
12 changes: 2 additions & 10 deletions packages/workbox-background-sync/src/lib/StorableRequest.ts
Expand Up @@ -43,7 +43,8 @@ export interface RequestData extends MapLikeObject {
* A class to make it easier to serialize and de-serialize requests so they
* can be stored in IndexedDB.
*
* @private
* Most developers will not need to access this class directly;
* it is exposed for advanced use cases.
*/
class StorableRequest {
private readonly _requestData: RequestData;
Expand All @@ -54,8 +55,6 @@ class StorableRequest {
*
* @param {Request} request
* @return {Promise<StorableRequest>}
*
* @private
*/
static async fromRequest(request: Request): Promise<StorableRequest> {
const requestData: RequestData = {
Expand Down Expand Up @@ -94,7 +93,6 @@ class StorableRequest {
* @param {Object} requestData An object of request data that includes the
* `url` plus any relevant properties of
* [requestInit]{@link https://fetch.spec.whatwg.org/#requestinit}.
* @private
*/
constructor(requestData: RequestData) {
if (process.env.NODE_ENV !== 'production') {
Expand Down Expand Up @@ -125,8 +123,6 @@ class StorableRequest {
* Returns a deep clone of the instances `_requestData` object.
*
* @return {Object}
*
* @private
*/
toObject(): RequestData {
const requestData = Object.assign({}, this._requestData);
Expand All @@ -142,8 +138,6 @@ class StorableRequest {
* Converts this instance to a Request.
*
* @return {Request}
*
* @private
*/
toRequest(): Request {
return new Request(this._requestData.url, this._requestData);
Expand All @@ -153,8 +147,6 @@ class StorableRequest {
* Creates and returns a deep clone of the instance.
*
* @return {StorableRequest}
*
* @private
*/
clone(): StorableRequest {
return new StorableRequest(this.toObject());
Expand Down
1 change: 1 addition & 0 deletions packages/workbox-precaching/src/_types.ts
Expand Up @@ -22,6 +22,7 @@ export declare interface PrecacheEntry {
url: string;
revision?: string | null;
}

export interface PrecacheRouteOptions {
directoryIndex?: string;
ignoreURLParametersMatching?: RegExp[];
Expand Down
2 changes: 2 additions & 0 deletions packages/workbox-precaching/src/index.ts
Expand Up @@ -48,3 +48,5 @@ export {
PrecacheStrategy,
PrecacheFallbackPlugin,
};

export * from './_types.js';
9 changes: 6 additions & 3 deletions packages/workbox-strategies/src/index.ts
Expand Up @@ -8,10 +8,10 @@

import {CacheFirst} from './CacheFirst.js';
import {CacheOnly} from './CacheOnly.js';
import {NetworkFirst} from './NetworkFirst.js';
import {NetworkOnly} from './NetworkOnly.js';
import {NetworkFirst, NetworkFirstOptions} from './NetworkFirst.js';
import {NetworkOnly, NetworkOnlyOptions} from './NetworkOnly.js';
import {StaleWhileRevalidate} from './StaleWhileRevalidate.js';
import {Strategy} from './Strategy.js';
import {Strategy, StrategyOptions} from './Strategy.js';
import {StrategyHandler} from './StrategyHandler.js';
import './_version.js';

Expand All @@ -33,8 +33,11 @@ export {
CacheFirst,
CacheOnly,
NetworkFirst,
NetworkFirstOptions,
NetworkOnly,
NetworkOnlyOptions,
StaleWhileRevalidate,
Strategy,
StrategyHandler,
StrategyOptions,
};
2 changes: 2 additions & 0 deletions packages/workbox-streams/src/index.ts
Expand Up @@ -17,3 +17,5 @@ import './_version.js';
*/

export {concatenate, concatenateToResponse, isSupported, strategy};

export * from './_types.js';

0 comments on commit e0bcb29

Please sign in to comment.