jekyll-pwa-workbox 0.0.6 → 0.0.7.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-pwa-workbox.rb +1 -1
  3. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.dev.js +819 -0
  4. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.dev.js.map +1 -0
  5. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.prod.js +2 -0
  6. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.prod.js.map +1 -0
  7. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.dev.js +486 -0
  8. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.dev.js.map +1 -0
  9. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.prod.js +2 -0
  10. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.prod.js.map +1 -0
  11. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.dev.js +192 -0
  12. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.dev.js.map +1 -0
  13. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.prod.js +2 -0
  14. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.prod.js.map +1 -0
  15. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.dev.js +1643 -0
  16. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.dev.js.map +1 -0
  17. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.prod.js +2 -0
  18. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.prod.js.map +1 -0
  19. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.dev.js +652 -0
  20. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.dev.js.map +1 -0
  21. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.prod.js +2 -0
  22. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.prod.js.map +1 -0
  23. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.dev.js +103 -0
  24. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.dev.js.map +1 -0
  25. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.prod.js +2 -0
  26. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.prod.js.map +1 -0
  27. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.dev.js +236 -0
  28. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.dev.js.map +1 -0
  29. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.prod.js +2 -0
  30. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.prod.js.map +1 -0
  31. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.dev.js +994 -0
  32. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.dev.js.map +1 -0
  33. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.prod.js +2 -0
  34. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.prod.js.map +1 -0
  35. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.dev.js +263 -0
  36. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.dev.js.map +1 -0
  37. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.prod.js +2 -0
  38. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.prod.js.map +1 -0
  39. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.dev.js +1026 -0
  40. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.dev.js.map +1 -0
  41. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.prod.js +2 -0
  42. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.prod.js.map +1 -0
  43. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.dev.js +1127 -0
  44. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.dev.js.map +1 -0
  45. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.prod.js +2 -0
  46. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.prod.js.map +1 -0
  47. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.dev.js +333 -0
  48. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.dev.js.map +1 -0
  49. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.prod.js +2 -0
  50. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.prod.js.map +1 -0
  51. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-sw.js +2 -0
  52. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-sw.js.map +1 -0
  53. data/lib/vendor/{workbox-v4.3.1 → workbox-v5.0.0.alpha1}/workbox-window.dev.es5.mjs +248 -262
  54. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.es5.mjs.map +1 -0
  55. data/lib/vendor/{workbox-v4.3.1 → workbox-v5.0.0.alpha1}/workbox-window.dev.mjs +234 -242
  56. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.mjs.map +1 -0
  57. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.umd.js +882 -0
  58. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.umd.js.map +1 -0
  59. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.es5.mjs +2 -0
  60. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.es5.mjs.map +1 -0
  61. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.mjs +2 -0
  62. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.mjs.map +1 -0
  63. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.umd.js +2 -0
  64. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.umd.js.map +1 -0
  65. metadata +75 -80
  66. data/lib/vendor/workbox-v4.3.1/workbox-background-sync.dev.js +0 -822
  67. data/lib/vendor/workbox-v4.3.1/workbox-background-sync.dev.js.map +0 -1
  68. data/lib/vendor/workbox-v4.3.1/workbox-background-sync.prod.js +0 -2
  69. data/lib/vendor/workbox-v4.3.1/workbox-background-sync.prod.js.map +0 -1
  70. data/lib/vendor/workbox-v4.3.1/workbox-broadcast-update.dev.js +0 -496
  71. data/lib/vendor/workbox-v4.3.1/workbox-broadcast-update.dev.js.map +0 -1
  72. data/lib/vendor/workbox-v4.3.1/workbox-broadcast-update.prod.js +0 -2
  73. data/lib/vendor/workbox-v4.3.1/workbox-broadcast-update.prod.js.map +0 -1
  74. data/lib/vendor/workbox-v4.3.1/workbox-cacheable-response.dev.js +0 -200
  75. data/lib/vendor/workbox-v4.3.1/workbox-cacheable-response.dev.js.map +0 -1
  76. data/lib/vendor/workbox-v4.3.1/workbox-cacheable-response.prod.js +0 -2
  77. data/lib/vendor/workbox-v4.3.1/workbox-cacheable-response.prod.js.map +0 -1
  78. data/lib/vendor/workbox-v4.3.1/workbox-core.dev.js +0 -1712
  79. data/lib/vendor/workbox-v4.3.1/workbox-core.dev.js.map +0 -1
  80. data/lib/vendor/workbox-v4.3.1/workbox-core.prod.js +0 -2
  81. data/lib/vendor/workbox-v4.3.1/workbox-core.prod.js.map +0 -1
  82. data/lib/vendor/workbox-v4.3.1/workbox-expiration.dev.js +0 -652
  83. data/lib/vendor/workbox-v4.3.1/workbox-expiration.dev.js.map +0 -1
  84. data/lib/vendor/workbox-v4.3.1/workbox-expiration.prod.js +0 -2
  85. data/lib/vendor/workbox-v4.3.1/workbox-expiration.prod.js.map +0 -1
  86. data/lib/vendor/workbox-v4.3.1/workbox-navigation-preload.dev.js +0 -110
  87. data/lib/vendor/workbox-v4.3.1/workbox-navigation-preload.dev.js.map +0 -1
  88. data/lib/vendor/workbox-v4.3.1/workbox-navigation-preload.prod.js +0 -2
  89. data/lib/vendor/workbox-v4.3.1/workbox-navigation-preload.prod.js.map +0 -1
  90. data/lib/vendor/workbox-v4.3.1/workbox-offline-ga.dev.js +0 -243
  91. data/lib/vendor/workbox-v4.3.1/workbox-offline-ga.dev.js.map +0 -1
  92. data/lib/vendor/workbox-v4.3.1/workbox-offline-ga.prod.js +0 -2
  93. data/lib/vendor/workbox-v4.3.1/workbox-offline-ga.prod.js.map +0 -1
  94. data/lib/vendor/workbox-v4.3.1/workbox-precaching.dev.js +0 -989
  95. data/lib/vendor/workbox-v4.3.1/workbox-precaching.dev.js.map +0 -1
  96. data/lib/vendor/workbox-v4.3.1/workbox-precaching.prod.js +0 -2
  97. data/lib/vendor/workbox-v4.3.1/workbox-precaching.prod.js.map +0 -1
  98. data/lib/vendor/workbox-v4.3.1/workbox-range-requests.dev.js +0 -268
  99. data/lib/vendor/workbox-v4.3.1/workbox-range-requests.dev.js.map +0 -1
  100. data/lib/vendor/workbox-v4.3.1/workbox-range-requests.prod.js +0 -2
  101. data/lib/vendor/workbox-v4.3.1/workbox-range-requests.prod.js.map +0 -1
  102. data/lib/vendor/workbox-v4.3.1/workbox-routing.dev.js +0 -1020
  103. data/lib/vendor/workbox-v4.3.1/workbox-routing.dev.js.map +0 -1
  104. data/lib/vendor/workbox-v4.3.1/workbox-routing.prod.js +0 -2
  105. data/lib/vendor/workbox-v4.3.1/workbox-routing.prod.js.map +0 -1
  106. data/lib/vendor/workbox-v4.3.1/workbox-strategies.dev.js +0 -1138
  107. data/lib/vendor/workbox-v4.3.1/workbox-strategies.dev.js.map +0 -1
  108. data/lib/vendor/workbox-v4.3.1/workbox-strategies.prod.js +0 -2
  109. data/lib/vendor/workbox-v4.3.1/workbox-strategies.prod.js.map +0 -1
  110. data/lib/vendor/workbox-v4.3.1/workbox-streams.dev.js +0 -337
  111. data/lib/vendor/workbox-v4.3.1/workbox-streams.dev.js.map +0 -1
  112. data/lib/vendor/workbox-v4.3.1/workbox-streams.prod.js +0 -2
  113. data/lib/vendor/workbox-v4.3.1/workbox-streams.prod.js.map +0 -1
  114. data/lib/vendor/workbox-v4.3.1/workbox-sw.js +0 -2
  115. data/lib/vendor/workbox-v4.3.1/workbox-sw.js.map +0 -1
  116. data/lib/vendor/workbox-v4.3.1/workbox-window.dev.es5.mjs.map +0 -1
  117. data/lib/vendor/workbox-v4.3.1/workbox-window.dev.mjs.map +0 -1
  118. data/lib/vendor/workbox-v4.3.1/workbox-window.dev.umd.js +0 -896
  119. data/lib/vendor/workbox-v4.3.1/workbox-window.dev.umd.js.map +0 -1
  120. data/lib/vendor/workbox-v4.3.1/workbox-window.prod.es5.mjs +0 -2
  121. data/lib/vendor/workbox-v4.3.1/workbox-window.prod.es5.mjs.map +0 -1
  122. data/lib/vendor/workbox-v4.3.1/workbox-window.prod.mjs +0 -2
  123. data/lib/vendor/workbox-v4.3.1/workbox-window.prod.mjs.map +0 -1
  124. data/lib/vendor/workbox-v4.3.1/workbox-window.prod.umd.js +0 -2
  125. data/lib/vendor/workbox-v4.3.1/workbox-window.prod.umd.js.map +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cca62e49b0c77764563ace8d9ba25e47ddff893f8367e97722d1dff22db96455
4
- data.tar.gz: 57b4d18801373e3fafb277ce33acbd81752f34aa6ac23ae7eb3fc18a28bc4a40
3
+ metadata.gz: 5366e7ac1ef780c398dcc0f0e6fcb98d38ac16a9cbe2a8901db7f6b09d50196c
4
+ data.tar.gz: 2d3afd783da518ce5892d01149e7979dae3ce9d27366cd1585078ed818a7ffb8
5
5
  SHA512:
6
- metadata.gz: 1046adda5ab8efb14a8daea92f838f76fb474557ec6f3a3cfc7e80c2522f0b822887a011bcee8a311ff4442324beb84f895ff150848c1ff31b86aee1b63c2e87
7
- data.tar.gz: 7cd61cbf7b095fd5ca6972f8e4649e33bfe3bb7d5727fbfec855be0367fc1c6dd9af3d333e825a436dab23fc4a90d8bd32516a40fe51355eb561dd67f841305f
6
+ metadata.gz: 1eba883f35e01b4961d9a9c973e4a0f97416e59b8c472702fa07fa22ae6881fc18a7fd14b07fe1fbcbd8696bd7c087f1740eaeba61c97d011cf88fa8877c725e
7
+ data.tar.gz: 64051cd75e2592c4dffd2d93c83d497f4bdbef3e6ba5fe186be1e49608a6c5cb5a2112cd28d4e4f3661a355da1999af6c9a8e8fca8e10610537df02af555928a
@@ -1,5 +1,5 @@
1
1
  class SWHelper
2
- WORKBOX_VERSION = 'v4.3.1'
2
+ WORKBOX_VERSION = 'v5.0.0.alpha1'
3
3
  def initialize(site, config)
4
4
  @site = site
5
5
  @config = config
@@ -0,0 +1,819 @@
1
+ this.workbox = this.workbox || {};
2
+ this.workbox.backgroundSync = (function (exports, WorkboxError_js, logger_js, assert_js, getFriendlyURL_js, DBWrapper_js) {
3
+ 'use strict';
4
+
5
+ // @ts-ignore
6
+ try {
7
+ self['workbox:background-sync:5.0.0-alpha.0'] && _();
8
+ } catch (e) {}
9
+
10
+ /*
11
+ Copyright 2018 Google LLC
12
+
13
+ Use of this source code is governed by an MIT-style
14
+ license that can be found in the LICENSE file or at
15
+ https://opensource.org/licenses/MIT.
16
+ */
17
+ const DB_VERSION = 3;
18
+ const DB_NAME = 'workbox-background-sync';
19
+ const OBJECT_STORE_NAME = 'requests';
20
+ const INDEXED_PROP = 'queueName';
21
+ /**
22
+ * A class to manage storing requests from a Queue in IndexedbDB,
23
+ * indexed by their queue name for easier access.
24
+ *
25
+ * @private
26
+ */
27
+
28
+ class QueueStore {
29
+ /**
30
+ * Associates this instance with a Queue instance, so entries added can be
31
+ * identified by their queue name.
32
+ *
33
+ * @param {string} queueName
34
+ * @private
35
+ */
36
+ constructor(queueName) {
37
+ this._queueName = queueName;
38
+ this._db = new DBWrapper_js.DBWrapper(DB_NAME, DB_VERSION, {
39
+ onupgradeneeded: this._upgradeDb
40
+ });
41
+ }
42
+ /**
43
+ * Append an entry last in the queue.
44
+ *
45
+ * @param {Object} entry
46
+ * @param {Object} entry.requestData
47
+ * @param {number} [entry.timestamp]
48
+ * @param {Object} [entry.metadata]
49
+ * @private
50
+ */
51
+
52
+
53
+ async pushEntry(entry) {
54
+ {
55
+ assert_js.assert.isType(entry, 'object', {
56
+ moduleName: 'workbox-background-sync',
57
+ className: 'QueueStore',
58
+ funcName: 'pushEntry',
59
+ paramName: 'entry'
60
+ });
61
+ assert_js.assert.isType(entry.requestData, 'object', {
62
+ moduleName: 'workbox-background-sync',
63
+ className: 'QueueStore',
64
+ funcName: 'pushEntry',
65
+ paramName: 'entry.requestData'
66
+ });
67
+ } // Don't specify an ID since one is automatically generated.
68
+
69
+
70
+ delete entry.id;
71
+ entry.queueName = this._queueName;
72
+ await this._db.add(OBJECT_STORE_NAME, entry);
73
+ }
74
+ /**
75
+ * Preppend an entry first in the queue.
76
+ *
77
+ * @param {Object} entry
78
+ * @param {Object} entry.requestData
79
+ * @param {number} [entry.timestamp]
80
+ * @param {Object} [entry.metadata]
81
+ * @private
82
+ */
83
+
84
+
85
+ async unshiftEntry(entry) {
86
+ {
87
+ assert_js.assert.isType(entry, 'object', {
88
+ moduleName: 'workbox-background-sync',
89
+ className: 'QueueStore',
90
+ funcName: 'unshiftEntry',
91
+ paramName: 'entry'
92
+ });
93
+ assert_js.assert.isType(entry.requestData, 'object', {
94
+ moduleName: 'workbox-background-sync',
95
+ className: 'QueueStore',
96
+ funcName: 'unshiftEntry',
97
+ paramName: 'entry.requestData'
98
+ });
99
+ }
100
+
101
+ const [firstEntry] = await this._db.getAllMatching(OBJECT_STORE_NAME, {
102
+ count: 1
103
+ });
104
+
105
+ if (firstEntry) {
106
+ // Pick an ID one less than the lowest ID in the object store.
107
+ entry.id = firstEntry.id - 1;
108
+ } else {
109
+ // Otherwise let the auto-incrementor assign the ID.
110
+ delete entry.id;
111
+ }
112
+
113
+ entry.queueName = this._queueName;
114
+ await this._db.add(OBJECT_STORE_NAME, entry);
115
+ }
116
+ /**
117
+ * Removes and returns the last entry in the queue matching the `queueName`.
118
+ *
119
+ * @return {Promise<Object>}
120
+ * @private
121
+ */
122
+
123
+
124
+ async popEntry() {
125
+ return this._removeEntry({
126
+ direction: 'prev'
127
+ });
128
+ }
129
+ /**
130
+ * Removes and returns the first entry in the queue matching the `queueName`.
131
+ *
132
+ * @return {Promise<Object>}
133
+ * @private
134
+ */
135
+
136
+
137
+ async shiftEntry() {
138
+ return this._removeEntry({
139
+ direction: 'next'
140
+ });
141
+ }
142
+ /**
143
+ * Returns all entries in the store matching the `queueName`.
144
+ *
145
+ * @param {Object} options See workbox.backgroundSync.Queue~getAll}
146
+ * @return {Promise<Array<Object>>}
147
+ * @private
148
+ */
149
+
150
+
151
+ async getAll() {
152
+ return await this._db.getAllMatching(OBJECT_STORE_NAME, {
153
+ index: INDEXED_PROP,
154
+ query: IDBKeyRange.only(this._queueName)
155
+ });
156
+ }
157
+ /**
158
+ * Deletes the entry for the given ID.
159
+ *
160
+ * WARNING: this method does not ensure the deleted enry belongs to this
161
+ * queue (i.e. matches the `queueName`). But this limitation is acceptable
162
+ * as this class is not publicly exposed. An additional check would make
163
+ * this method slower than it needs to be.
164
+ *
165
+ * @private
166
+ * @param {number} id
167
+ */
168
+
169
+
170
+ async deleteEntry(id) {
171
+ await this._db.delete(OBJECT_STORE_NAME, id);
172
+ }
173
+ /**
174
+ * Removes and returns the first or last entry in the queue (based on the
175
+ * `direction` argument) matching the `queueName`.
176
+ *
177
+ * @return {Promise<Object>}
178
+ * @private
179
+ */
180
+
181
+
182
+ async _removeEntry({
183
+ direction
184
+ }) {
185
+ const [entry] = await this._db.getAllMatching(OBJECT_STORE_NAME, {
186
+ direction,
187
+ index: INDEXED_PROP,
188
+ query: IDBKeyRange.only(this._queueName),
189
+ count: 1
190
+ });
191
+
192
+ if (entry) {
193
+ await this.deleteEntry(entry.id);
194
+ return entry;
195
+ }
196
+ }
197
+ /**
198
+ * Upgrades the database given an `upgradeneeded` event.
199
+ *
200
+ * @param {Event} event
201
+ * @private
202
+ */
203
+
204
+
205
+ _upgradeDb(event) {
206
+ const db = event.target.result;
207
+
208
+ if (event.oldVersion > 0 && event.oldVersion < DB_VERSION) {
209
+ if (db.objectStoreNames.contains(OBJECT_STORE_NAME)) {
210
+ db.deleteObjectStore(OBJECT_STORE_NAME);
211
+ }
212
+ }
213
+
214
+ const objStore = db.createObjectStore(OBJECT_STORE_NAME, {
215
+ autoIncrement: true,
216
+ keyPath: 'id'
217
+ });
218
+ objStore.createIndex(INDEXED_PROP, INDEXED_PROP, {
219
+ unique: false
220
+ });
221
+ }
222
+
223
+ }
224
+
225
+ /*
226
+ Copyright 2018 Google LLC
227
+
228
+ Use of this source code is governed by an MIT-style
229
+ license that can be found in the LICENSE file or at
230
+ https://opensource.org/licenses/MIT.
231
+ */
232
+ const serializableProperties = ['method', 'referrer', 'referrerPolicy', 'mode', 'credentials', 'cache', 'redirect', 'integrity', 'keepalive'];
233
+ /**
234
+ * A class to make it easier to serialize and de-serialize requests so they
235
+ * can be stored in IndexedDB.
236
+ *
237
+ * @private
238
+ */
239
+
240
+ class StorableRequest {
241
+ /**
242
+ * Converts a Request object to a plain object that can be structured
243
+ * cloned or JSON-stringified.
244
+ *
245
+ * @param {Request} request
246
+ * @return {Promise<StorableRequest>}
247
+ *
248
+ * @private
249
+ */
250
+ static async fromRequest(request) {
251
+ const requestData = {
252
+ url: request.url,
253
+ headers: {}
254
+ }; // Set the body if present.
255
+
256
+ if (request.method !== 'GET') {
257
+ // Use ArrayBuffer to support non-text request bodies.
258
+ // NOTE: we can't use Blobs becuse Safari doesn't support storing
259
+ // Blobs in IndexedDB in some cases:
260
+ // https://github.com/dfahlander/Dexie.js/issues/618#issuecomment-398348457
261
+ requestData.body = await request.clone().arrayBuffer();
262
+ } // Convert the headers from an iterable to an object.
263
+
264
+
265
+ for (const [key, value] of request.headers.entries()) {
266
+ requestData.headers[key] = value;
267
+ } // Add all other serializable request properties
268
+
269
+
270
+ for (const prop of serializableProperties) {
271
+ if (request[prop] !== undefined) {
272
+ requestData[prop] = request[prop];
273
+ }
274
+ }
275
+
276
+ return new StorableRequest(requestData);
277
+ }
278
+ /**
279
+ * Accepts an object of request data that can be used to construct a
280
+ * `Request` but can also be stored in IndexedDB.
281
+ *
282
+ * @param {Object} requestData An object of request data that includes the
283
+ * `url` plus any relevant properties of
284
+ * [requestInit]{@link https://fetch.spec.whatwg.org/#requestinit}.
285
+ * @private
286
+ */
287
+
288
+
289
+ constructor(requestData) {
290
+ {
291
+ assert_js.assert.isType(requestData, 'object', {
292
+ moduleName: 'workbox-background-sync',
293
+ className: 'StorableRequest',
294
+ funcName: 'constructor',
295
+ paramName: 'requestData'
296
+ });
297
+ assert_js.assert.isType(requestData.url, 'string', {
298
+ moduleName: 'workbox-background-sync',
299
+ className: 'StorableRequest',
300
+ funcName: 'constructor',
301
+ paramName: 'requestData.url'
302
+ });
303
+ } // If the request's mode is `navigate`, convert it to `same-origin` since
304
+ // navigation requests can't be constructed via script.
305
+
306
+
307
+ if (requestData.mode === 'navigate') {
308
+ requestData.mode = 'same-origin';
309
+ }
310
+
311
+ this._requestData = requestData;
312
+ }
313
+ /**
314
+ * Returns a deep clone of the instances `_requestData` object.
315
+ *
316
+ * @return {Object}
317
+ *
318
+ * @private
319
+ */
320
+
321
+
322
+ toObject() {
323
+ const requestData = Object.assign({}, this._requestData);
324
+ requestData.headers = Object.assign({}, this._requestData.headers);
325
+
326
+ if (requestData.body) {
327
+ requestData.body = requestData.body.slice(0);
328
+ }
329
+
330
+ return requestData;
331
+ }
332
+ /**
333
+ * Converts this instance to a Request.
334
+ *
335
+ * @return {Request}
336
+ *
337
+ * @private
338
+ */
339
+
340
+
341
+ toRequest() {
342
+ return new Request(this._requestData.url, this._requestData);
343
+ }
344
+ /**
345
+ * Creates and returns a deep clone of the instance.
346
+ *
347
+ * @return {StorableRequest}
348
+ *
349
+ * @private
350
+ */
351
+
352
+
353
+ clone() {
354
+ return new StorableRequest(this.toObject());
355
+ }
356
+
357
+ }
358
+
359
+ /*
360
+ Copyright 2018 Google LLC
361
+
362
+ Use of this source code is governed by an MIT-style
363
+ license that can be found in the LICENSE file or at
364
+ https://opensource.org/licenses/MIT.
365
+ */
366
+ const TAG_PREFIX = 'workbox-background-sync';
367
+ const MAX_RETENTION_TIME = 60 * 24 * 7; // 7 days in minutes
368
+
369
+ const queueNames = new Set();
370
+ /**
371
+ * A class to manage storing failed requests in IndexedDB and retrying them
372
+ * later. All parts of the storing and replaying process are observable via
373
+ * callbacks.
374
+ *
375
+ * @memberof workbox.backgroundSync
376
+ */
377
+
378
+ class Queue {
379
+ /**
380
+ * Creates an instance of Queue with the given options
381
+ *
382
+ * @param {string} name The unique name for this queue. This name must be
383
+ * unique as it's used to register sync events and store requests
384
+ * in IndexedDB specific to this instance. An error will be thrown if
385
+ * a duplicate name is detected.
386
+ * @param {Object} [options]
387
+ * @param {Function} [options.onSync] A function that gets invoked whenever
388
+ * the 'sync' event fires. The function is invoked with an object
389
+ * containing the `queue` property (referencing this instance), and you
390
+ * can use the callback to customize the replay behavior of the queue.
391
+ * When not set the `replayRequests()` method is called.
392
+ * Note: if the replay fails after a sync event, make sure you throw an
393
+ * error, so the browser knows to retry the sync event later.
394
+ * @param {number} [options.maxRetentionTime=7 days] The amount of time (in
395
+ * minutes) a request may be retried. After this amount of time has
396
+ * passed, the request will be deleted from the queue.
397
+ */
398
+ constructor(name, {
399
+ onSync,
400
+ maxRetentionTime
401
+ } = {}) {
402
+ this._syncInProgress = false;
403
+ this._requestsAddedDuringSync = false; // Ensure the store name is not already being used
404
+
405
+ if (queueNames.has(name)) {
406
+ throw new WorkboxError_js.WorkboxError('duplicate-queue-name', {
407
+ name
408
+ });
409
+ } else {
410
+ queueNames.add(name);
411
+ }
412
+
413
+ this._name = name;
414
+ this._onSync = onSync || this.replayRequests;
415
+ this._maxRetentionTime = maxRetentionTime || MAX_RETENTION_TIME;
416
+ this._queueStore = new QueueStore(this._name);
417
+
418
+ this._addSyncListener();
419
+ }
420
+ /**
421
+ * @return {string}
422
+ */
423
+
424
+
425
+ get name() {
426
+ return this._name;
427
+ }
428
+ /**
429
+ * Stores the passed request in IndexedDB (with its timestamp and any
430
+ * metadata) at the end of the queue.
431
+ *
432
+ * @param {Object} entry
433
+ * @param {Request} entry.request The request to store in the queue.
434
+ * @param {Object} [entry.metadata] Any metadata you want associated with the
435
+ * stored request. When requests are replayed you'll have access to this
436
+ * metadata object in case you need to modify the request beforehand.
437
+ * @param {number} [entry.timestamp] The timestamp (Epoch time in
438
+ * milliseconds) when the request was first added to the queue. This is
439
+ * used along with `maxRetentionTime` to remove outdated requests. In
440
+ * general you don't need to set this value, as it's automatically set
441
+ * for you (defaulting to `Date.now()`), but you can update it if you
442
+ * don't want particular requests to expire.
443
+ */
444
+
445
+
446
+ async pushRequest(entry) {
447
+ {
448
+ assert_js.assert.isType(entry, 'object', {
449
+ moduleName: 'workbox-background-sync',
450
+ className: 'Queue',
451
+ funcName: 'pushRequest',
452
+ paramName: 'entry'
453
+ });
454
+ assert_js.assert.isInstance(entry.request, Request, {
455
+ moduleName: 'workbox-background-sync',
456
+ className: 'Queue',
457
+ funcName: 'pushRequest',
458
+ paramName: 'entry.request'
459
+ });
460
+ }
461
+
462
+ await this._addRequest(entry, 'push');
463
+ }
464
+ /**
465
+ * Stores the passed request in IndexedDB (with its timestamp and any
466
+ * metadata) at the beginning of the queue.
467
+ *
468
+ * @param {Object} entry
469
+ * @param {Request} entry.request The request to store in the queue.
470
+ * @param {Object} [entry.metadata] Any metadata you want associated with the
471
+ * stored request. When requests are replayed you'll have access to this
472
+ * metadata object in case you need to modify the request beforehand.
473
+ * @param {number} [entry.timestamp] The timestamp (Epoch time in
474
+ * milliseconds) when the request was first added to the queue. This is
475
+ * used along with `maxRetentionTime` to remove outdated requests. In
476
+ * general you don't need to set this value, as it's automatically set
477
+ * for you (defaulting to `Date.now()`), but you can update it if you
478
+ * don't want particular requests to expire.
479
+ */
480
+
481
+
482
+ async unshiftRequest(entry) {
483
+ {
484
+ assert_js.assert.isType(entry, 'object', {
485
+ moduleName: 'workbox-background-sync',
486
+ className: 'Queue',
487
+ funcName: 'unshiftRequest',
488
+ paramName: 'entry'
489
+ });
490
+ assert_js.assert.isInstance(entry.request, Request, {
491
+ moduleName: 'workbox-background-sync',
492
+ className: 'Queue',
493
+ funcName: 'unshiftRequest',
494
+ paramName: 'entry.request'
495
+ });
496
+ }
497
+
498
+ await this._addRequest(entry, 'unshift');
499
+ }
500
+ /**
501
+ * Removes and returns the last request in the queue (along with its
502
+ * timestamp and any metadata). The returned object takes the form:
503
+ * `{request, timestamp, metadata}`.
504
+ *
505
+ * @return {Promise<Object>}
506
+ */
507
+
508
+
509
+ async popRequest() {
510
+ return this._removeRequest('pop');
511
+ }
512
+ /**
513
+ * Removes and returns the first request in the queue (along with its
514
+ * timestamp and any metadata). The returned object takes the form:
515
+ * `{request, timestamp, metadata}`.
516
+ *
517
+ * @return {Promise<Object>}
518
+ */
519
+
520
+
521
+ async shiftRequest() {
522
+ return this._removeRequest('shift');
523
+ }
524
+ /**
525
+ * Returns all the entries that have not expired (per `maxRetentionTime`).
526
+ * Any expired entries are removed from the queue.
527
+ *
528
+ * @return {Promise<Array<Object>>}
529
+ */
530
+
531
+
532
+ async getAll() {
533
+ const allEntries = await this._queueStore.getAll();
534
+ const now = Date.now();
535
+ const unexpiredEntries = [];
536
+
537
+ for (const entry of allEntries) {
538
+ // Ignore requests older than maxRetentionTime. Call this function
539
+ // recursively until an unexpired request is found.
540
+ const maxRetentionTimeInMs = this._maxRetentionTime * 60 * 1000;
541
+
542
+ if (now - entry.timestamp > maxRetentionTimeInMs) {
543
+ await this._queueStore.deleteEntry(entry.id);
544
+ } else {
545
+ unexpiredEntries.push(convertEntry(entry));
546
+ }
547
+ }
548
+
549
+ return unexpiredEntries;
550
+ }
551
+ /**
552
+ * Adds the entry to the QueueStore and registers for a sync event.
553
+ *
554
+ * @param {Object} entry
555
+ * @param {Request} entry.request
556
+ * @param {Object} [entry.metadata]
557
+ * @param {number} [entry.timestamp=Date.now()]
558
+ * @param {string} operation ('push' or 'unshift')
559
+ * @private
560
+ */
561
+
562
+
563
+ async _addRequest({
564
+ request,
565
+ metadata,
566
+ timestamp = Date.now()
567
+ }, operation) {
568
+ const storableRequest = await StorableRequest.fromRequest(request.clone());
569
+ const entry = {
570
+ requestData: storableRequest.toObject(),
571
+ timestamp
572
+ }; // Only include metadata if it's present.
573
+
574
+ if (metadata) {
575
+ entry.metadata = metadata;
576
+ }
577
+
578
+ await this._queueStore[`${operation}Entry`](entry);
579
+
580
+ {
581
+ logger_js.logger.log(`Request for '${getFriendlyURL_js.getFriendlyURL(request.url)}' has ` + `been added to background sync queue '${this._name}'.`);
582
+ } // Don't register for a sync if we're in the middle of a sync. Instead,
583
+ // we wait until the sync is complete and call register if
584
+ // `this._requestsAddedDuringSync` is true.
585
+
586
+
587
+ if (this._syncInProgress) {
588
+ this._requestsAddedDuringSync = true;
589
+ } else {
590
+ await this.registerSync();
591
+ }
592
+ }
593
+ /**
594
+ * Removes and returns the first or last (depending on `operation`) entry
595
+ * from the QueueStore that's not older than the `maxRetentionTime`.
596
+ *
597
+ * @param {string} operation ('pop' or 'shift')
598
+ * @return {Object|undefined}
599
+ * @private
600
+ */
601
+
602
+
603
+ async _removeRequest(operation) {
604
+ const now = Date.now();
605
+ const entry = await this._queueStore[`${operation}Entry`]();
606
+
607
+ if (entry) {
608
+ // Ignore requests older than maxRetentionTime. Call this function
609
+ // recursively until an unexpired request is found.
610
+ const maxRetentionTimeInMs = this._maxRetentionTime * 60 * 1000;
611
+
612
+ if (now - entry.timestamp > maxRetentionTimeInMs) {
613
+ return this._removeRequest(operation);
614
+ }
615
+
616
+ return convertEntry(entry);
617
+ } else {
618
+ return undefined;
619
+ }
620
+ }
621
+ /**
622
+ * Loops through each request in the queue and attempts to re-fetch it.
623
+ * If any request fails to re-fetch, it's put back in the same position in
624
+ * the queue (which registers a retry for the next sync event).
625
+ */
626
+
627
+
628
+ async replayRequests() {
629
+ let entry;
630
+
631
+ while (entry = await this.shiftRequest()) {
632
+ try {
633
+ await fetch(entry.request.clone());
634
+
635
+ if ("dev" !== 'production') {
636
+ logger_js.logger.log(`Request for '${getFriendlyURL_js.getFriendlyURL(entry.request.url)}'` + `has been replayed in queue '${this._name}'`);
637
+ }
638
+ } catch (error) {
639
+ await this.unshiftRequest(entry);
640
+
641
+ {
642
+ logger_js.logger.log(`Request for '${getFriendlyURL_js.getFriendlyURL(entry.request.url)}'` + `failed to replay, putting it back in queue '${this._name}'`);
643
+ }
644
+
645
+ throw new WorkboxError_js.WorkboxError('queue-replay-failed', {
646
+ name: this._name
647
+ });
648
+ }
649
+ }
650
+
651
+ {
652
+ logger_js.logger.log(`All requests in queue '${this.name}' have successfully ` + `replayed; the queue is now empty!`);
653
+ }
654
+ }
655
+ /**
656
+ * Registers a sync event with a tag unique to this instance.
657
+ */
658
+
659
+
660
+ async registerSync() {
661
+ if ('sync' in self.registration) {
662
+ try {
663
+ await self.registration.sync.register(`${TAG_PREFIX}:${this._name}`);
664
+ } catch (err) {
665
+ // This means the registration failed for some reason, possibly due to
666
+ // the user disabling it.
667
+ {
668
+ logger_js.logger.warn(`Unable to register sync event for '${this._name}'.`, err);
669
+ }
670
+ }
671
+ }
672
+ }
673
+ /**
674
+ * In sync-supporting browsers, this adds a listener for the sync event.
675
+ * In non-sync-supporting browsers, this will retry the queue on service
676
+ * worker startup.
677
+ *
678
+ * @private
679
+ */
680
+
681
+
682
+ _addSyncListener() {
683
+ if ('sync' in self.registration) {
684
+ self.addEventListener('sync', event => {
685
+ if (event.tag === `${TAG_PREFIX}:${this._name}`) {
686
+ {
687
+ logger_js.logger.log(`Background sync for tag '${event.tag}'` + `has been received`);
688
+ }
689
+
690
+ const syncComplete = async () => {
691
+ this._syncInProgress = true;
692
+ let syncError;
693
+
694
+ try {
695
+ await this._onSync({
696
+ queue: this
697
+ });
698
+ } catch (error) {
699
+ syncError = error; // Rethrow the error. Note: the logic in the finally clause
700
+ // will run before this gets rethrown.
701
+
702
+ throw syncError;
703
+ } finally {
704
+ // New items may have been added to the queue during the sync,
705
+ // so we need to register for a new sync if that's happened...
706
+ // Unless there was an error during the sync, in which
707
+ // case the browser will automatically retry later, as long
708
+ // as `event.lastChance` is not true.
709
+ if (this._requestsAddedDuringSync && !(syncError && !event.lastChance)) {
710
+ await this.registerSync();
711
+ }
712
+
713
+ this._syncInProgress = false;
714
+ this._requestsAddedDuringSync = false;
715
+ }
716
+ };
717
+
718
+ event.waitUntil(syncComplete());
719
+ }
720
+ });
721
+ } else {
722
+ {
723
+ logger_js.logger.log(`Background sync replaying without background sync event`);
724
+ } // If the browser doesn't support background sync, retry
725
+ // every time the service worker starts up as a fallback.
726
+
727
+
728
+ this._onSync({
729
+ queue: this
730
+ });
731
+ }
732
+ }
733
+ /**
734
+ * Returns the set of queue names. This is primarily used to reset the list
735
+ * of queue names in tests.
736
+ *
737
+ * @return {Set}
738
+ *
739
+ * @private
740
+ */
741
+
742
+
743
+ static get _queueNames() {
744
+ return queueNames;
745
+ }
746
+
747
+ }
748
+ /**
749
+ * Converts a QueueStore entry into the format exposed by Queue. This entails
750
+ * converting the request data into a real request and omitting the `id` and
751
+ * `queueName` properties.
752
+ *
753
+ * @param {Object} queueStoreEntry
754
+ * @return {Object}
755
+ * @private
756
+ */
757
+
758
+
759
+ const convertEntry = queueStoreEntry => {
760
+ const queueEntry = {
761
+ request: new StorableRequest(queueStoreEntry.requestData).toRequest(),
762
+ timestamp: queueStoreEntry.timestamp
763
+ };
764
+
765
+ if (queueStoreEntry.metadata) {
766
+ queueEntry.metadata = queueStoreEntry.metadata;
767
+ }
768
+
769
+ return queueEntry;
770
+ };
771
+
772
+ /*
773
+ Copyright 2018 Google LLC
774
+
775
+ Use of this source code is governed by an MIT-style
776
+ license that can be found in the LICENSE file or at
777
+ https://opensource.org/licenses/MIT.
778
+ */
779
+ /**
780
+ * A class implementing the `fetchDidFail` lifecycle callback. This makes it
781
+ * easier to add failed requests to a background sync Queue.
782
+ *
783
+ * @memberof workbox.backgroundSync
784
+ */
785
+
786
+ class Plugin {
787
+ /**
788
+ * @param {string} name See the [Queue]{@link workbox.backgroundSync.Queue}
789
+ * documentation for parameter details.
790
+ * @param {Object} [options] See the
791
+ * [Queue]{@link workbox.backgroundSync.Queue} documentation for
792
+ * parameter details.
793
+ */
794
+ constructor(name, options) {
795
+ /**
796
+ * @param {Object} options
797
+ * @param {Request} options.request
798
+ * @private
799
+ */
800
+ this.fetchDidFail = async ({
801
+ request
802
+ }) => {
803
+ await this._queue.pushRequest({
804
+ request
805
+ });
806
+ };
807
+
808
+ this._queue = new Queue(name, options);
809
+ }
810
+
811
+ }
812
+
813
+ exports.Plugin = Plugin;
814
+ exports.Queue = Queue;
815
+
816
+ return exports;
817
+
818
+ }({}, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private));
819
+ //# sourceMappingURL=workbox-background-sync.dev.js.map