textbrowser 0.54.9 → 0.54.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +4 -0
- package/dist/activateCallback-es.js +23 -0
- package/dist/sw-helper.js +13 -4
- package/package.json +1 -1
- package/resources/activateCallback.js +23 -0
package/CHANGES.md
CHANGED
|
@@ -55,10 +55,12 @@ async function activateCallback ({
|
|
|
55
55
|
// anyways); also important to avoid conflicts with
|
|
56
56
|
// already-running versions upon future sw updates
|
|
57
57
|
log('Activate: Callback called');
|
|
58
|
+
log('Activate: Fetching files manifest', files);
|
|
58
59
|
const r = await fetch(files);
|
|
59
60
|
const {groups} = /** @type {import('./utils/WorkInfo.js').FilesObject} */ (
|
|
60
61
|
await r.json()
|
|
61
62
|
);
|
|
63
|
+
log('Activate: Manifest loaded; groups:', groups.length);
|
|
62
64
|
|
|
63
65
|
/* eslint-disable jsdoc/reject-any-type -- Generic */
|
|
64
66
|
/**
|
|
@@ -67,6 +69,7 @@ async function activateCallback ({
|
|
|
67
69
|
*/
|
|
68
70
|
const addJSONFetch = (arr, path) => {
|
|
69
71
|
/* eslint-enable jsdoc/reject-any-type -- Generic */
|
|
72
|
+
log('Activate: Queueing JSON fetch', basePath + path);
|
|
70
73
|
arr.push(
|
|
71
74
|
(async () => (await fetch(basePath + path)).json())()
|
|
72
75
|
);
|
|
@@ -89,6 +92,13 @@ async function activateCallback ({
|
|
|
89
92
|
const metadataFiles = [];
|
|
90
93
|
groups.forEach(
|
|
91
94
|
({files: fileObjs, metadataBaseDirectory, schemaBaseDirectory}) => {
|
|
95
|
+
log(
|
|
96
|
+
'Activate: Processing group',
|
|
97
|
+
metadataBaseDirectory,
|
|
98
|
+
schemaBaseDirectory,
|
|
99
|
+
'files:',
|
|
100
|
+
fileObjs.length
|
|
101
|
+
);
|
|
92
102
|
fileObjs.forEach(({file: {$ref: filePath}, metadataFile, schemaFile, name}) => {
|
|
93
103
|
// We don't i18nize the name here
|
|
94
104
|
dataFileNames.push(name);
|
|
@@ -98,6 +108,7 @@ async function activateCallback ({
|
|
|
98
108
|
});
|
|
99
109
|
}
|
|
100
110
|
);
|
|
111
|
+
log('Activate: Awaiting queued fetches; works:', dataFiles.length);
|
|
101
112
|
const promises = await Promise.all([
|
|
102
113
|
...dataFiles, ...schemaFiles, ...metadataFiles
|
|
103
114
|
]);
|
|
@@ -109,11 +120,14 @@ async function activateCallback ({
|
|
|
109
120
|
|
|
110
121
|
log('Activate: Files fetched');
|
|
111
122
|
const dbName = namespace + '-textbrowser-cache-data';
|
|
123
|
+
log('Activate: Deleting existing database', dbName);
|
|
112
124
|
indexedDB.deleteDatabase(dbName);
|
|
113
125
|
return new Promise((resolve, reject) => {
|
|
126
|
+
log('Activate: Opening database', dbName);
|
|
114
127
|
const req = indexedDB.open(dbName);
|
|
115
128
|
// @ts-expect-error Ok
|
|
116
129
|
req.addEventListener('upgradeneeded', ({target: {result: db}}) => {
|
|
130
|
+
log('Activate: Database upgrade needed', dbName);
|
|
117
131
|
db.onversionchange = () => {
|
|
118
132
|
db.close();
|
|
119
133
|
const err = /** @type {Error & {type: string}} */ (new Error('versionchange'));
|
|
@@ -122,6 +136,7 @@ async function activateCallback ({
|
|
|
122
136
|
};
|
|
123
137
|
dataFileResponses.forEach(({data: tableRows}, i) => {
|
|
124
138
|
const dataFileName = dataFileNames[i];
|
|
139
|
+
log('Activate: Creating object store', dataFileName, 'rows:', tableRows.length);
|
|
125
140
|
const store = db.createObjectStore('files-to-cache-' + dataFileName);
|
|
126
141
|
|
|
127
142
|
const schemaFileResponse = schemaFileResponses[i];
|
|
@@ -180,6 +195,12 @@ async function activateCallback ({
|
|
|
180
195
|
});
|
|
181
196
|
|
|
182
197
|
const uniqueColumnIndexes = [...new Set(columnIndexes)];
|
|
198
|
+
log(
|
|
199
|
+
'Activate: Preparing rows for store',
|
|
200
|
+
dataFileName,
|
|
201
|
+
'unique indexes:',
|
|
202
|
+
uniqueColumnIndexes.length
|
|
203
|
+
);
|
|
183
204
|
|
|
184
205
|
tableRows.forEach((tableRow, j) => {
|
|
185
206
|
// Todo: Optionally send notice when complete
|
|
@@ -203,6 +224,7 @@ async function activateCallback ({
|
|
|
203
224
|
// log('objRow', objRow);
|
|
204
225
|
store.put(objRow, j);
|
|
205
226
|
});
|
|
227
|
+
log('Activate: Finished object store population', dataFileName);
|
|
206
228
|
});
|
|
207
229
|
});
|
|
208
230
|
|
|
@@ -218,6 +240,7 @@ async function activateCallback ({
|
|
|
218
240
|
* @param {Event & {error?: Error}} ev
|
|
219
241
|
*/
|
|
220
242
|
const onerr = (ev) => {
|
|
243
|
+
log('Activate: Database request error event fired');
|
|
221
244
|
const error = /** @type {Error & {type: string}} */ (
|
|
222
245
|
ev.error ?? new Error('dbError')
|
|
223
246
|
);
|
package/dist/sw-helper.js
CHANGED
|
@@ -184,7 +184,7 @@ function swHelper (self) {
|
|
|
184
184
|
* @returns {Promise<void>}
|
|
185
185
|
*/
|
|
186
186
|
async function install (time) {
|
|
187
|
-
post({type: 'beginInstall'});
|
|
187
|
+
await post({type: 'beginInstall'});
|
|
188
188
|
log(`Install: Trying, attempt ${time}`);
|
|
189
189
|
const now = Date.now();
|
|
190
190
|
const json = await getJSON(/** @type {string} */ (pathToUserJSON));
|
|
@@ -300,7 +300,7 @@ function swHelper (self) {
|
|
|
300
300
|
|
|
301
301
|
// Although we only need one client to which to send
|
|
302
302
|
// arguments, we want to signal phase complete to all
|
|
303
|
-
post({type: 'finishedInstall'});
|
|
303
|
+
await post({type: 'finishedInstall'});
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
/**
|
|
@@ -309,7 +309,12 @@ function swHelper (self) {
|
|
|
309
309
|
* @returns {Promise<void>}
|
|
310
310
|
*/
|
|
311
311
|
async function activate (time) {
|
|
312
|
-
|
|
312
|
+
console.log('Activate event worker callback entered', time);
|
|
313
|
+
await post({
|
|
314
|
+
type: 'log',
|
|
315
|
+
message: `Activate: Event callback entered (attempt ${time})`
|
|
316
|
+
});
|
|
317
|
+
await post({type: 'beginActivate'});
|
|
313
318
|
log(`Activate: Trying, attempt ${time}`);
|
|
314
319
|
const [json, cacheNames] = await Promise.all([
|
|
315
320
|
getJSON(/** @type {string} */ (pathToUserJSON)),
|
|
@@ -329,9 +334,12 @@ function swHelper (self) {
|
|
|
329
334
|
await activateCallback({namespace, files, basePath, log});
|
|
330
335
|
log('Activate: Database changes completed');
|
|
331
336
|
|
|
337
|
+
await self.clients.claim();
|
|
338
|
+
log('Activate: Clients claimed');
|
|
339
|
+
|
|
332
340
|
log(`Activate: Posting finished message to clients`);
|
|
333
341
|
// Signal phase complete to all clients
|
|
334
|
-
post({type: 'finishedActivate'});
|
|
342
|
+
await post({type: 'finishedActivate'});
|
|
335
343
|
}
|
|
336
344
|
|
|
337
345
|
// @ts-expect-error Ok
|
|
@@ -348,6 +356,7 @@ function swHelper (self) {
|
|
|
348
356
|
});
|
|
349
357
|
|
|
350
358
|
self.addEventListener('activate', (e) => {
|
|
359
|
+
console.log('sw activate event fired');
|
|
351
360
|
// Erring is of no present use here:
|
|
352
361
|
// https://github.com/w3c/ServiceWorker/issues/659#issuecomment-384919053
|
|
353
362
|
e.waitUntil(tryAndRetry(activate, 5 * minutes, 'Error activating'));
|
package/package.json
CHANGED
|
@@ -55,10 +55,12 @@ export default async function activateCallback ({
|
|
|
55
55
|
// anyways); also important to avoid conflicts with
|
|
56
56
|
// already-running versions upon future sw updates
|
|
57
57
|
log('Activate: Callback called');
|
|
58
|
+
log('Activate: Fetching files manifest', files);
|
|
58
59
|
const r = await fetch(files);
|
|
59
60
|
const {groups} = /** @type {import('./utils/WorkInfo.js').FilesObject} */ (
|
|
60
61
|
await r.json()
|
|
61
62
|
);
|
|
63
|
+
log('Activate: Manifest loaded; groups:', groups.length);
|
|
62
64
|
|
|
63
65
|
/* eslint-disable jsdoc/reject-any-type -- Generic */
|
|
64
66
|
/**
|
|
@@ -67,6 +69,7 @@ export default async function activateCallback ({
|
|
|
67
69
|
*/
|
|
68
70
|
const addJSONFetch = (arr, path) => {
|
|
69
71
|
/* eslint-enable jsdoc/reject-any-type -- Generic */
|
|
72
|
+
log('Activate: Queueing JSON fetch', basePath + path);
|
|
70
73
|
arr.push(
|
|
71
74
|
(async () => (await fetch(basePath + path)).json())()
|
|
72
75
|
);
|
|
@@ -89,6 +92,13 @@ export default async function activateCallback ({
|
|
|
89
92
|
const metadataFiles = [];
|
|
90
93
|
groups.forEach(
|
|
91
94
|
({files: fileObjs, metadataBaseDirectory, schemaBaseDirectory}) => {
|
|
95
|
+
log(
|
|
96
|
+
'Activate: Processing group',
|
|
97
|
+
metadataBaseDirectory,
|
|
98
|
+
schemaBaseDirectory,
|
|
99
|
+
'files:',
|
|
100
|
+
fileObjs.length
|
|
101
|
+
);
|
|
92
102
|
fileObjs.forEach(({file: {$ref: filePath}, metadataFile, schemaFile, name}) => {
|
|
93
103
|
// We don't i18nize the name here
|
|
94
104
|
dataFileNames.push(name);
|
|
@@ -98,6 +108,7 @@ export default async function activateCallback ({
|
|
|
98
108
|
});
|
|
99
109
|
}
|
|
100
110
|
);
|
|
111
|
+
log('Activate: Awaiting queued fetches; works:', dataFiles.length);
|
|
101
112
|
const promises = await Promise.all([
|
|
102
113
|
...dataFiles, ...schemaFiles, ...metadataFiles
|
|
103
114
|
]);
|
|
@@ -109,11 +120,14 @@ export default async function activateCallback ({
|
|
|
109
120
|
|
|
110
121
|
log('Activate: Files fetched');
|
|
111
122
|
const dbName = namespace + '-textbrowser-cache-data';
|
|
123
|
+
log('Activate: Deleting existing database', dbName);
|
|
112
124
|
indexedDB.deleteDatabase(dbName);
|
|
113
125
|
return new Promise((resolve, reject) => {
|
|
126
|
+
log('Activate: Opening database', dbName);
|
|
114
127
|
const req = indexedDB.open(dbName);
|
|
115
128
|
// @ts-expect-error Ok
|
|
116
129
|
req.addEventListener('upgradeneeded', ({target: {result: db}}) => {
|
|
130
|
+
log('Activate: Database upgrade needed', dbName);
|
|
117
131
|
db.onversionchange = () => {
|
|
118
132
|
db.close();
|
|
119
133
|
const err = /** @type {Error & {type: string}} */ (new Error('versionchange'));
|
|
@@ -122,6 +136,7 @@ export default async function activateCallback ({
|
|
|
122
136
|
};
|
|
123
137
|
dataFileResponses.forEach(({data: tableRows}, i) => {
|
|
124
138
|
const dataFileName = dataFileNames[i];
|
|
139
|
+
log('Activate: Creating object store', dataFileName, 'rows:', tableRows.length);
|
|
125
140
|
const store = db.createObjectStore('files-to-cache-' + dataFileName);
|
|
126
141
|
|
|
127
142
|
const schemaFileResponse = schemaFileResponses[i];
|
|
@@ -180,6 +195,12 @@ export default async function activateCallback ({
|
|
|
180
195
|
});
|
|
181
196
|
|
|
182
197
|
const uniqueColumnIndexes = [...new Set(columnIndexes)];
|
|
198
|
+
log(
|
|
199
|
+
'Activate: Preparing rows for store',
|
|
200
|
+
dataFileName,
|
|
201
|
+
'unique indexes:',
|
|
202
|
+
uniqueColumnIndexes.length
|
|
203
|
+
);
|
|
183
204
|
|
|
184
205
|
tableRows.forEach((tableRow, j) => {
|
|
185
206
|
// Todo: Optionally send notice when complete
|
|
@@ -203,6 +224,7 @@ export default async function activateCallback ({
|
|
|
203
224
|
// log('objRow', objRow);
|
|
204
225
|
store.put(objRow, j);
|
|
205
226
|
});
|
|
227
|
+
log('Activate: Finished object store population', dataFileName);
|
|
206
228
|
});
|
|
207
229
|
});
|
|
208
230
|
|
|
@@ -218,6 +240,7 @@ export default async function activateCallback ({
|
|
|
218
240
|
* @param {Event & {error?: Error}} ev
|
|
219
241
|
*/
|
|
220
242
|
const onerr = (ev) => {
|
|
243
|
+
log('Activate: Database request error event fired');
|
|
221
244
|
const error = /** @type {Error & {type: string}} */ (
|
|
222
245
|
ev.error ?? new Error('dbError')
|
|
223
246
|
);
|