Skip to content

Commit e0bcb29

Browse files
Export more classes/types publicly (#2955)
* 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 <[email protected]>
1 parent 97fc646 commit e0bcb29

File tree

9 files changed

+48
-25
lines changed

9 files changed

+48
-25
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
Copyright 2021 Google LLC
3+
4+
Use of this source code is governed by an MIT-style
5+
license that can be found in the LICENSE file or at
6+
https://opensource.org/licenses/MIT.
7+
*/
8+
9+
import './_version.js';
10+
11+
// This is a temporary workaround to expose something from ./lib/ via our
12+
// top-level public API.
13+
// TODO: In Workbox v7, move the actual code from ./lib/ to this file.
14+
export {QueueStore} from './lib/QueueStore';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
Copyright 2021 Google LLC
3+
4+
Use of this source code is governed by an MIT-style
5+
license that can be found in the LICENSE file or at
6+
https://opensource.org/licenses/MIT.
7+
*/
8+
9+
import './_version.js';
10+
11+
// This is a temporary workaround to expose something from ./lib/ via our
12+
// top-level public API.
13+
// TODO: In Workbox v7, move the actual code from ./lib/ to this file.
14+
export {StorableRequest} from './lib/StorableRequest';

packages/workbox-background-sync/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
https://opensource.org/licenses/MIT.
77
*/
88

9-
import {Queue, QueueOptions} from './Queue.js';
109
import {BackgroundSyncPlugin} from './BackgroundSyncPlugin.js';
10+
import {Queue, QueueOptions} from './Queue.js';
11+
import {QueueStore} from './QueueStore.js';
12+
import {StorableRequest} from './StorableRequest.js';
1113

1214
import './_version.js';
1315

@@ -35,4 +37,4 @@ declare global {
3537
/**
3638
* @module workbox-background-sync
3739
*/
38-
export {BackgroundSyncPlugin, Queue, QueueOptions};
40+
export {BackgroundSyncPlugin, Queue, QueueOptions, QueueStore, StorableRequest};

packages/workbox-background-sync/src/lib/QueueStore.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
*/
88

99
import {assert} from 'workbox-core/_private/assert.js';
10-
import '../_version.js';
1110
import {
1211
UnidentifiedQueueStoreEntry,
1312
QueueStoreEntry,
1413
QueueDb,
1514
} from './QueueDb.js';
15+
import '../_version.js';
1616

1717
/**
1818
* A class to manage storing requests from a Queue in IndexedDB,
1919
* indexed by their queue name for easier access.
2020
*
21-
* @private
21+
* Most developers will not need to access this class directly;
22+
* it is exposed for advanced use cases.
2223
*/
2324
export class QueueStore {
2425
private readonly _queueName: string;
@@ -29,7 +30,6 @@ export class QueueStore {
2930
* identified by their queue name.
3031
*
3132
* @param {string} queueName
32-
* @private
3333
*/
3434
constructor(queueName: string) {
3535
this._queueName = queueName;
@@ -43,7 +43,6 @@ export class QueueStore {
4343
* @param {Object} entry.requestData
4444
* @param {number} [entry.timestamp]
4545
* @param {Object} [entry.metadata]
46-
* @private
4746
*/
4847
async pushEntry(entry: UnidentifiedQueueStoreEntry): Promise<void> {
4948
if (process.env.NODE_ENV !== 'production') {
@@ -75,7 +74,6 @@ export class QueueStore {
7574
* @param {Object} entry.requestData
7675
* @param {number} [entry.timestamp]
7776
* @param {Object} [entry.metadata]
78-
* @private
7977
*/
8078
async unshiftEntry(entry: UnidentifiedQueueStoreEntry): Promise<void> {
8179
if (process.env.NODE_ENV !== 'production') {
@@ -111,7 +109,6 @@ export class QueueStore {
111109
* Removes and returns the last entry in the queue matching the `queueName`.
112110
*
113111
* @return {Promise<QueueStoreEntry|undefined>}
114-
* @private
115112
*/
116113
async popEntry(): Promise<QueueStoreEntry | undefined> {
117114
return this._removeEntry(
@@ -123,7 +120,6 @@ export class QueueStore {
123120
* Removes and returns the first entry in the queue matching the `queueName`.
124121
*
125122
* @return {Promise<QueueStoreEntry|undefined>}
126-
* @private
127123
*/
128124
async shiftEntry(): Promise<QueueStoreEntry | undefined> {
129125
return this._removeEntry(
@@ -136,7 +132,6 @@ export class QueueStore {
136132
*
137133
* @param {Object} options See {@link module:workbox-background-sync.Queue~getAll}
138134
* @return {Promise<Array<Object>>}
139-
* @private
140135
*/
141136
async getAll(): Promise<QueueStoreEntry[]> {
142137
return await this._queueDb.getAllEntriesByQueueName(this._queueName);
@@ -147,7 +142,6 @@ export class QueueStore {
147142
*
148143
* @param {Object} options See {@link module:workbox-background-sync.Queue~size}
149144
* @return {Promise<number>}
150-
* @private
151145
*/
152146
async size(): Promise<number> {
153147
return await this._queueDb.getEntryCountByQueueName(this._queueName);
@@ -161,7 +155,6 @@ export class QueueStore {
161155
* as this class is not publicly exposed. An additional check would make
162156
* this method slower than it needs to be.
163157
*
164-
* @private
165158
* @param {number} id
166159
*/
167160
async deleteEntry(id: number): Promise<void> {

packages/workbox-background-sync/src/lib/StorableRequest.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export interface RequestData extends MapLikeObject {
4343
* A class to make it easier to serialize and de-serialize requests so they
4444
* can be stored in IndexedDB.
4545
*
46-
* @private
46+
* Most developers will not need to access this class directly;
47+
* it is exposed for advanced use cases.
4748
*/
4849
class StorableRequest {
4950
private readonly _requestData: RequestData;
@@ -54,8 +55,6 @@ class StorableRequest {
5455
*
5556
* @param {Request} request
5657
* @return {Promise<StorableRequest>}
57-
*
58-
* @private
5958
*/
6059
static async fromRequest(request: Request): Promise<StorableRequest> {
6160
const requestData: RequestData = {
@@ -94,7 +93,6 @@ class StorableRequest {
9493
* @param {Object} requestData An object of request data that includes the
9594
* `url` plus any relevant properties of
9695
* [requestInit]{@link https://fetch.spec.whatwg.org/#requestinit}.
97-
* @private
9896
*/
9997
constructor(requestData: RequestData) {
10098
if (process.env.NODE_ENV !== 'production') {
@@ -125,8 +123,6 @@ class StorableRequest {
125123
* Returns a deep clone of the instances `_requestData` object.
126124
*
127125
* @return {Object}
128-
*
129-
* @private
130126
*/
131127
toObject(): RequestData {
132128
const requestData = Object.assign({}, this._requestData);
@@ -142,8 +138,6 @@ class StorableRequest {
142138
* Converts this instance to a Request.
143139
*
144140
* @return {Request}
145-
*
146-
* @private
147141
*/
148142
toRequest(): Request {
149143
return new Request(this._requestData.url, this._requestData);
@@ -153,8 +147,6 @@ class StorableRequest {
153147
* Creates and returns a deep clone of the instance.
154148
*
155149
* @return {StorableRequest}
156-
*
157-
* @private
158150
*/
159151
clone(): StorableRequest {
160152
return new StorableRequest(this.toObject());

packages/workbox-precaching/src/_types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export declare interface PrecacheEntry {
2222
url: string;
2323
revision?: string | null;
2424
}
25+
2526
export interface PrecacheRouteOptions {
2627
directoryIndex?: string;
2728
ignoreURLParametersMatching?: RegExp[];

packages/workbox-precaching/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ export {
4848
PrecacheStrategy,
4949
PrecacheFallbackPlugin,
5050
};
51+
52+
export * from './_types.js';

packages/workbox-strategies/src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
import {CacheFirst} from './CacheFirst.js';
1010
import {CacheOnly} from './CacheOnly.js';
11-
import {NetworkFirst} from './NetworkFirst.js';
12-
import {NetworkOnly} from './NetworkOnly.js';
11+
import {NetworkFirst, NetworkFirstOptions} from './NetworkFirst.js';
12+
import {NetworkOnly, NetworkOnlyOptions} from './NetworkOnly.js';
1313
import {StaleWhileRevalidate} from './StaleWhileRevalidate.js';
14-
import {Strategy} from './Strategy.js';
14+
import {Strategy, StrategyOptions} from './Strategy.js';
1515
import {StrategyHandler} from './StrategyHandler.js';
1616
import './_version.js';
1717

@@ -33,8 +33,11 @@ export {
3333
CacheFirst,
3434
CacheOnly,
3535
NetworkFirst,
36+
NetworkFirstOptions,
3637
NetworkOnly,
38+
NetworkOnlyOptions,
3739
StaleWhileRevalidate,
3840
Strategy,
3941
StrategyHandler,
42+
StrategyOptions,
4043
};

packages/workbox-streams/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ import './_version.js';
1717
*/
1818

1919
export {concatenate, concatenateToResponse, isSupported, strategy};
20+
21+
export * from './_types.js';

0 commit comments

Comments
 (0)