workbox-background-sync
Advanced tools
Comparing version 5.0.0-rc.1 to 5.0.0-rc.2
"use strict"; | ||
// @ts-ignore | ||
try { | ||
self['workbox:background-sync:5.0.0-rc.1'] && _(); | ||
self['workbox:background-sync:5.0.0-rc.2'] && _(); | ||
} | ||
catch (e) { } |
@@ -8,3 +8,3 @@ import { WorkboxPlugin } from 'workbox-core/types.js'; | ||
* | ||
* @memberof workbox.backgroundSync | ||
* @memberof module:workbox-background-sync | ||
*/ | ||
@@ -14,6 +14,6 @@ declare class BackgroundSyncPlugin implements WorkboxPlugin { | ||
/** | ||
* @param {string} name See the [Queue]{@link workbox.backgroundSync.Queue} | ||
* @param {string} name See the [Queue]{@link module:workbox-background-sync.Queue} | ||
* documentation for parameter details. | ||
* @param {Object} [options] See the | ||
* [Queue]{@link workbox.backgroundSync.Queue} documentation for | ||
* [Queue]{@link module:workbox-background-sync.Queue} documentation for | ||
* parameter details. | ||
@@ -20,0 +20,0 @@ */ |
@@ -14,10 +14,10 @@ /* | ||
* | ||
* @memberof workbox.backgroundSync | ||
* @memberof module:workbox-background-sync | ||
*/ | ||
class BackgroundSyncPlugin { | ||
/** | ||
* @param {string} name See the [Queue]{@link workbox.backgroundSync.Queue} | ||
* @param {string} name See the [Queue]{@link module:workbox-background-sync.Queue} | ||
* documentation for parameter details. | ||
* @param {Object} [options] See the | ||
* [Queue]{@link workbox.backgroundSync.Queue} documentation for | ||
* [Queue]{@link module:workbox-background-sync.Queue} documentation for | ||
* parameter details. | ||
@@ -24,0 +24,0 @@ */ |
@@ -6,3 +6,3 @@ this.workbox = this.workbox || {}; | ||
try { | ||
self['workbox:background-sync:5.0.0-rc.1'] && _(); | ||
self['workbox:background-sync:5.0.0-rc.2'] && _(); | ||
} catch (e) {} | ||
@@ -145,3 +145,3 @@ | ||
* | ||
* @param {Object} options See workbox.backgroundSync.Queue~getAll} | ||
* @param {Object} options See {@link module:workbox-background-sync.Queue~getAll} | ||
* @return {Promise<Array<Object>>} | ||
@@ -376,3 +376,3 @@ * @private | ||
* | ||
* @memberof workbox.backgroundSync | ||
* @memberof module:workbox-background-sync | ||
*/ | ||
@@ -785,3 +785,3 @@ | ||
* | ||
* @memberof workbox.backgroundSync | ||
* @memberof module:workbox-background-sync | ||
*/ | ||
@@ -791,6 +791,6 @@ | ||
/** | ||
* @param {string} name See the [Queue]{@link workbox.backgroundSync.Queue} | ||
* @param {string} name See the [Queue]{@link module:workbox-background-sync.Queue} | ||
* documentation for parameter details. | ||
* @param {Object} [options] See the | ||
* [Queue]{@link workbox.backgroundSync.Queue} documentation for | ||
* [Queue]{@link module:workbox-background-sync.Queue} documentation for | ||
* parameter details. | ||
@@ -797,0 +797,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
this.workbox=this.workbox||{},this.workbox.backgroundSync=function(t,e,s,i,n){"use strict";try{self["workbox:background-sync:5.0.0-rc.1"]&&_()}catch(t){}const a=3,r="workbox-background-sync",c="requests",h="queueName";class o{constructor(t){this.t=t,this.s=new n.DBWrapper(r,a,{onupgradeneeded:this.i})}async pushEntry(t){delete t.id,t.queueName=this.t,await this.s.add(c,t)}async unshiftEntry(t){const[e]=await this.s.getAllMatching(c,{count:1});e?t.id=e.id-1:delete t.id,t.queueName=this.t,await this.s.add(c,t)}async popEntry(){return this.h({direction:"prev"})}async shiftEntry(){return this.h({direction:"next"})}async getAll(){return await this.s.getAllMatching(c,{index:h,query:IDBKeyRange.only(this.t)})}async deleteEntry(t){await this.s.delete(c,t)}async h({direction:t}){const[e]=await this.s.getAllMatching(c,{direction:t,index:h,query:IDBKeyRange.only(this.t),count:1});if(e)return await this.deleteEntry(e.id),e}i(t){const e=t.target.result;t.oldVersion>0&&t.oldVersion<a&&e.objectStoreNames.contains(c)&&e.deleteObjectStore(c),e.createObjectStore(c,{autoIncrement:!0,keyPath:"id"}).createIndex(h,h,{unique:!1})}}const u=["method","referrer","referrerPolicy","mode","credentials","cache","redirect","integrity","keepalive"];class y{static async fromRequest(t){const e={url:t.url,headers:{}};"GET"!==t.method&&(e.body=await t.clone().arrayBuffer());for(const[s,i]of t.headers.entries())e.headers[s]=i;for(const s of u)void 0!==t[s]&&(e[s]=t[s]);return new y(e)}constructor(t){"navigate"===t.mode&&(t.mode="same-origin"),this.o=t}toObject(){const t=Object.assign({},this.o);return t.headers=Object.assign({},this.o.headers),t.body&&(t.body=t.body.slice(0)),t}toRequest(){return new Request(this.o.url,this.o)}clone(){return new y(this.toObject())}}const w="workbox-background-sync",f=10080,d=new Set;class l{constructor(t,{onSync:s,maxRetentionTime:i}={}){if(this.u=!1,this.l=!1,d.has(t))throw new e.WorkboxError("duplicate-queue-name",{name:t});d.add(t),this.q=t,this.m=s||this.replayRequests,this.p=i||f,this.g=new o(this.q),this.R()}get name(){return this.q}async pushRequest(t){await this.k(t,"push")}async unshiftRequest(t){await this.k(t,"unshift")}async popRequest(){return this.D("pop")}async shiftRequest(){return this.D("shift")}async getAll(){const t=await this.g.getAll(),e=Date.now(),s=[];for(const i of t){const t=60*this.p*1e3;e-i.timestamp>t?await this.g.deleteEntry(i.id):s.push(q(i))}return s}async k({request:t,metadata:e,timestamp:s=Date.now()},i){const n={requestData:(await y.fromRequest(t.clone())).toObject(),timestamp:s};e&&(n.metadata=e),await this.g[`${i}Entry`](n),this.u?this.l=!0:await this.registerSync()}async D(t){const e=Date.now(),s=await this.g[`${t}Entry`]();if(s){const i=60*this.p*1e3;return e-s.timestamp>i?this.D(t):q(s)}}async replayRequests(){let t;for(;t=await this.shiftRequest();)try{await fetch(t.request.clone())}catch(s){throw await this.unshiftRequest(t),new e.WorkboxError("queue-replay-failed",{name:this.q})}}async registerSync(){if("sync"in self.registration)try{await self.registration.sync.register(`${w}:${this.q}`)}catch(t){}}R(){"sync"in self.registration?self.addEventListener("sync",t=>{if(t.tag===`${w}:${this.q}`){const e=async()=>{let e;this.u=!0;try{await this.m({queue:this})}catch(t){throw e=t}finally{!this.l||e&&!t.lastChance||await this.registerSync(),this.u=!1,this.l=!1}};t.waitUntil(e())}}):this.m({queue:this})}static get _(){return d}}const q=t=>{const e={request:new y(t.requestData).toRequest(),timestamp:t.timestamp};return t.metadata&&(e.metadata=t.metadata),e};return t.BackgroundSyncPlugin=class{constructor(t,e){this.fetchDidFail=(async({request:t})=>{await this.v.pushRequest({request:t})}),this.v=new l(t,e)}},t.Queue=l,t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private); | ||
this.workbox=this.workbox||{},this.workbox.backgroundSync=function(t,e,s,i,n){"use strict";try{self["workbox:background-sync:5.0.0-rc.2"]&&_()}catch(t){}const a=3,r="workbox-background-sync",c="requests",h="queueName";class o{constructor(t){this.t=t,this.s=new n.DBWrapper(r,a,{onupgradeneeded:this.i})}async pushEntry(t){delete t.id,t.queueName=this.t,await this.s.add(c,t)}async unshiftEntry(t){const[e]=await this.s.getAllMatching(c,{count:1});e?t.id=e.id-1:delete t.id,t.queueName=this.t,await this.s.add(c,t)}async popEntry(){return this.h({direction:"prev"})}async shiftEntry(){return this.h({direction:"next"})}async getAll(){return await this.s.getAllMatching(c,{index:h,query:IDBKeyRange.only(this.t)})}async deleteEntry(t){await this.s.delete(c,t)}async h({direction:t}){const[e]=await this.s.getAllMatching(c,{direction:t,index:h,query:IDBKeyRange.only(this.t),count:1});if(e)return await this.deleteEntry(e.id),e}i(t){const e=t.target.result;t.oldVersion>0&&t.oldVersion<a&&e.objectStoreNames.contains(c)&&e.deleteObjectStore(c),e.createObjectStore(c,{autoIncrement:!0,keyPath:"id"}).createIndex(h,h,{unique:!1})}}const u=["method","referrer","referrerPolicy","mode","credentials","cache","redirect","integrity","keepalive"];class y{static async fromRequest(t){const e={url:t.url,headers:{}};"GET"!==t.method&&(e.body=await t.clone().arrayBuffer());for(const[s,i]of t.headers.entries())e.headers[s]=i;for(const s of u)void 0!==t[s]&&(e[s]=t[s]);return new y(e)}constructor(t){"navigate"===t.mode&&(t.mode="same-origin"),this.o=t}toObject(){const t=Object.assign({},this.o);return t.headers=Object.assign({},this.o.headers),t.body&&(t.body=t.body.slice(0)),t}toRequest(){return new Request(this.o.url,this.o)}clone(){return new y(this.toObject())}}const w="workbox-background-sync",f=10080,d=new Set;class l{constructor(t,{onSync:s,maxRetentionTime:i}={}){if(this.u=!1,this.l=!1,d.has(t))throw new e.WorkboxError("duplicate-queue-name",{name:t});d.add(t),this.q=t,this.m=s||this.replayRequests,this.p=i||f,this.g=new o(this.q),this.R()}get name(){return this.q}async pushRequest(t){await this.k(t,"push")}async unshiftRequest(t){await this.k(t,"unshift")}async popRequest(){return this.D("pop")}async shiftRequest(){return this.D("shift")}async getAll(){const t=await this.g.getAll(),e=Date.now(),s=[];for(const i of t){const t=60*this.p*1e3;e-i.timestamp>t?await this.g.deleteEntry(i.id):s.push(q(i))}return s}async k({request:t,metadata:e,timestamp:s=Date.now()},i){const n={requestData:(await y.fromRequest(t.clone())).toObject(),timestamp:s};e&&(n.metadata=e),await this.g[`${i}Entry`](n),this.u?this.l=!0:await this.registerSync()}async D(t){const e=Date.now(),s=await this.g[`${t}Entry`]();if(s){const i=60*this.p*1e3;return e-s.timestamp>i?this.D(t):q(s)}}async replayRequests(){let t;for(;t=await this.shiftRequest();)try{await fetch(t.request.clone())}catch(s){throw await this.unshiftRequest(t),new e.WorkboxError("queue-replay-failed",{name:this.q})}}async registerSync(){if("sync"in self.registration)try{await self.registration.sync.register(`${w}:${this.q}`)}catch(t){}}R(){"sync"in self.registration?self.addEventListener("sync",t=>{if(t.tag===`${w}:${this.q}`){const e=async()=>{let e;this.u=!0;try{await this.m({queue:this})}catch(t){throw e=t}finally{!this.l||e&&!t.lastChance||await this.registerSync(),this.u=!1,this.l=!1}};t.waitUntil(e())}}):this.m({queue:this})}static get _(){return d}}const q=t=>{const e={request:new y(t.requestData).toRequest(),timestamp:t.timestamp};return t.metadata&&(e.metadata=t.metadata),e};return t.BackgroundSyncPlugin=class{constructor(t,e){this.fetchDidFail=(async({request:t})=>{await this.v.pushRequest({request:t})}),this.v=new l(t,e)}},t.Queue=l,t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private); | ||
//# sourceMappingURL=workbox-background-sync.prod.js.map |
@@ -5,4 +5,4 @@ import { Queue } from './Queue.js'; | ||
/** | ||
* @namespace workbox.backgroundSync | ||
* @module workbox-background-sync | ||
*/ | ||
export { Queue, BackgroundSyncPlugin, }; |
@@ -12,4 +12,4 @@ /* | ||
/** | ||
* @namespace workbox.backgroundSync | ||
* @module workbox-background-sync | ||
*/ | ||
export { Queue, BackgroundSyncPlugin, }; |
@@ -67,3 +67,3 @@ import { RequestData } from './StorableRequest.js'; | ||
* | ||
* @param {Object} options See workbox.backgroundSync.Queue~getAll} | ||
* @param {Object} options See {@link module:workbox-background-sync.Queue~getAll} | ||
* @return {Promise<Array<Object>>} | ||
@@ -70,0 +70,0 @@ * @private |
@@ -123,3 +123,3 @@ /* | ||
* | ||
* @param {Object} options See workbox.backgroundSync.Queue~getAll} | ||
* @param {Object} options See {@link module:workbox-background-sync.Queue~getAll} | ||
* @return {Promise<Array<Object>>} | ||
@@ -126,0 +126,0 @@ * @private |
{ | ||
"name": "workbox-background-sync", | ||
"version": "5.0.0-rc.1", | ||
"version": "5.0.0-rc.2", | ||
"license": "MIT", | ||
@@ -32,5 +32,5 @@ "author": "Google's Web DevRel Team", | ||
"dependencies": { | ||
"workbox-core": "^5.0.0-rc.1" | ||
"workbox-core": "^5.0.0-rc.2" | ||
}, | ||
"gitHead": "f03f71e50507e13d82d4e0a875cc49ba4501aff3" | ||
"gitHead": "89904768b2210e59c830dd380cf88a06e1c26a2b" | ||
} |
import './_version.js'; | ||
interface OnSyncCallbackOptions { | ||
queue: Queue; | ||
} | ||
interface OnSyncCallback { | ||
(options: OnSyncCallbackOptions): void; | ||
} | ||
export interface QueueOptions { | ||
onSync?: Function; | ||
onSync?: OnSyncCallback; | ||
maxRetentionTime?: number; | ||
@@ -16,3 +22,3 @@ } | ||
* | ||
* @memberof workbox.backgroundSync | ||
* @memberof module:workbox-background-sync | ||
*/ | ||
@@ -19,0 +25,0 @@ declare class Queue { |
@@ -23,3 +23,3 @@ /* | ||
* | ||
* @memberof workbox.backgroundSync | ||
* @memberof module:workbox-background-sync | ||
*/ | ||
@@ -26,0 +26,0 @@ class Queue { |
// @ts-ignore | ||
try{self['workbox:background-sync:5.0.0-rc.1']&&_()}catch(e){} | ||
try{self['workbox:background-sync:5.0.0-rc.2']&&_()}catch(e){} |
@@ -17,3 +17,3 @@ /* | ||
* | ||
* @memberof workbox.backgroundSync | ||
* @memberof module:workbox-background-sync | ||
*/ | ||
@@ -24,6 +24,6 @@ class BackgroundSyncPlugin implements WorkboxPlugin { | ||
/** | ||
* @param {string} name See the [Queue]{@link workbox.backgroundSync.Queue} | ||
* @param {string} name See the [Queue]{@link module:workbox-background-sync.Queue} | ||
* documentation for parameter details. | ||
* @param {Object} [options] See the | ||
* [Queue]{@link workbox.backgroundSync.Queue} documentation for | ||
* [Queue]{@link module:workbox-background-sync.Queue} documentation for | ||
* parameter details. | ||
@@ -30,0 +30,0 @@ */ |
@@ -15,3 +15,3 @@ /* | ||
/** | ||
* @namespace workbox.backgroundSync | ||
* @module workbox-background-sync | ||
*/ | ||
@@ -18,0 +18,0 @@ |
@@ -152,3 +152,3 @@ /* | ||
* | ||
* @param {Object} options See workbox.backgroundSync.Queue~getAll} | ||
* @param {Object} options See {@link module:workbox-background-sync.Queue~getAll} | ||
* @return {Promise<Array<Object>>} | ||
@@ -155,0 +155,0 @@ * @private |
@@ -21,9 +21,12 @@ /* | ||
const TAG_PREFIX = 'workbox-background-sync'; | ||
const MAX_RETENTION_TIME = 60 * 24 * 7; // 7 days in minutes | ||
interface OnSyncCallbackOptions { | ||
queue: Queue; | ||
} | ||
const queueNames = new Set(); | ||
interface OnSyncCallback { | ||
(options: OnSyncCallbackOptions): void; | ||
} | ||
export interface QueueOptions { | ||
onSync?: Function; | ||
onSync?: OnSyncCallback; | ||
maxRetentionTime?: number; | ||
@@ -38,2 +41,7 @@ } | ||
const TAG_PREFIX = 'workbox-background-sync'; | ||
const MAX_RETENTION_TIME = 60 * 24 * 7; // 7 days in minutes | ||
const queueNames = new Set(); | ||
/** | ||
@@ -44,7 +52,7 @@ * A class to manage storing failed requests in IndexedDB and retrying them | ||
* | ||
* @memberof workbox.backgroundSync | ||
* @memberof module:workbox-background-sync | ||
*/ | ||
class Queue { | ||
private _name: string; | ||
private _onSync: Function; | ||
private _onSync: OnSyncCallback; | ||
private _maxRetentionTime: number; | ||
@@ -51,0 +59,0 @@ private _queueStore: QueueStore; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2590
263104
3
80
Updatedworkbox-core@^5.0.0-rc.2