@serwist/core 8.1.1 → 8.3.0
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/dist/_private/Deferred.d.cts +18 -0
- package/dist/_private/SerwistError.d.cts +23 -0
- package/dist/_private/assert.d.cts +10 -0
- package/dist/_private/cacheMatchIgnoreParams.d.cts +14 -0
- package/dist/_private/cacheNames.d.cts +39 -0
- package/dist/_private/canConstructReadableStream.d.cts +11 -0
- package/dist/_private/canConstructResponseFromBodyStream.d.cts +10 -0
- package/dist/_private/dontWaitFor.d.cts +6 -0
- package/dist/_private/executeQuotaErrorCallbacks.d.cts +8 -0
- package/dist/_private/getFriendlyURL.d.cts +2 -0
- package/dist/_private/logger.d.cts +10 -0
- package/dist/_private/resultingClientExists.d.cts +11 -0
- package/dist/_private/timeout.d.cts +9 -0
- package/dist/_private/waitUntil.d.cts +0 -0
- package/dist/cacheNames.d.cts +20 -0
- package/dist/clientsClaim.d.cts +6 -0
- package/dist/copyResponse.d.cts +20 -0
- package/dist/index.cjs +154 -0
- package/dist/index.internal.cjs +244 -0
- package/dist/index.internal.d.cts +0 -0
- package/dist/index.internal.js +7 -429
- package/dist/index.js +1 -424
- package/dist/models/messages/messageGenerator.d.cts +1 -0
- package/dist/models/messages/messages.d.cts +8 -0
- package/dist/models/pluginEvents.d.cts +9 -0
- package/dist/models/quotaErrorCallbacks.d.cts +2 -0
- package/dist/{index.old.cjs → quotaErrorCallbacks.cjs} +6 -150
- package/dist/{index.internal.old.cjs → quotaErrorCallbacks.js} +81 -322
- package/dist/registerQuotaErrorCallback.d.cts +0 -0
- package/dist/setCacheNameDetails.d.cts +0 -0
- package/dist/types.d.cts +272 -0
- package/dist/utils/pluginUtils.d.cts +4 -0
- package/dist/utils/welcome.d.cts +1 -0
- package/package.json +7 -7
- package/dist/index.internal.old.d.cts +0 -15
- /package/dist/{index.old.d.cts → index.d.cts} +0 -0
|
@@ -1,4 +1,83 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2018 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
|
+
*/ const _cacheNameDetails = {
|
|
8
|
+
googleAnalytics: "googleAnalytics",
|
|
9
|
+
precache: "precache-v2",
|
|
10
|
+
prefix: "serwist",
|
|
11
|
+
runtime: "runtime",
|
|
12
|
+
suffix: typeof registration !== "undefined" ? registration.scope : ""
|
|
13
|
+
};
|
|
14
|
+
const _createCacheName = (cacheName)=>{
|
|
15
|
+
return [
|
|
16
|
+
_cacheNameDetails.prefix,
|
|
17
|
+
cacheName,
|
|
18
|
+
_cacheNameDetails.suffix
|
|
19
|
+
].filter((value)=>value && value.length > 0).join("-");
|
|
20
|
+
};
|
|
21
|
+
const eachCacheNameDetail = (fn)=>{
|
|
22
|
+
for (const key of Object.keys(_cacheNameDetails)){
|
|
23
|
+
fn(key);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const cacheNames = {
|
|
27
|
+
updateDetails: (details)=>{
|
|
28
|
+
eachCacheNameDetail((key)=>{
|
|
29
|
+
const detail = details[key];
|
|
30
|
+
if (typeof detail === "string") {
|
|
31
|
+
_cacheNameDetails[key] = detail;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
getGoogleAnalyticsName: (userCacheName)=>{
|
|
36
|
+
return userCacheName || _createCacheName(_cacheNameDetails.googleAnalytics);
|
|
37
|
+
},
|
|
38
|
+
getPrecacheName: (userCacheName)=>{
|
|
39
|
+
return userCacheName || _createCacheName(_cacheNameDetails.precache);
|
|
40
|
+
},
|
|
41
|
+
getPrefix: ()=>{
|
|
42
|
+
return _cacheNameDetails.prefix;
|
|
43
|
+
},
|
|
44
|
+
getRuntimeName: (userCacheName)=>{
|
|
45
|
+
return userCacheName || _createCacheName(_cacheNameDetails.runtime);
|
|
46
|
+
},
|
|
47
|
+
getSuffix: ()=>{
|
|
48
|
+
return _cacheNameDetails.suffix;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
Copyright 2019 Google LLC
|
|
54
|
+
|
|
55
|
+
Use of this source code is governed by an MIT-style
|
|
56
|
+
license that can be found in the LICENSE file or at
|
|
57
|
+
https://opensource.org/licenses/MIT.
|
|
58
|
+
*/ let supportStatus;
|
|
59
|
+
/**
|
|
60
|
+
* A utility function that determines whether the current browser supports
|
|
61
|
+
* constructing a new `Response` from a `response.body` stream.
|
|
62
|
+
*
|
|
63
|
+
* @returns `true`, if the current browser can successfully construct
|
|
64
|
+
* a `Response` from a `response.body` stream, `false` otherwise.
|
|
65
|
+
* @private
|
|
66
|
+
*/ function canConstructResponseFromBodyStream() {
|
|
67
|
+
if (supportStatus === undefined) {
|
|
68
|
+
const testResponse = new Response("");
|
|
69
|
+
if ("body" in testResponse) {
|
|
70
|
+
try {
|
|
71
|
+
new Response(testResponse.body);
|
|
72
|
+
supportStatus = true;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
supportStatus = false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
supportStatus = false;
|
|
78
|
+
}
|
|
79
|
+
return supportStatus;
|
|
80
|
+
}
|
|
2
81
|
|
|
3
82
|
/*
|
|
4
83
|
Copyright 2018 Google LLC
|
|
@@ -268,202 +347,6 @@ const finalAssertExports = process.env.NODE_ENV === "production" ? null : {
|
|
|
268
347
|
isArrayOfClass
|
|
269
348
|
};
|
|
270
349
|
|
|
271
|
-
/*
|
|
272
|
-
Copyright 2020 Google LLC
|
|
273
|
-
Use of this source code is governed by an MIT-style
|
|
274
|
-
license that can be found in the LICENSE file or at
|
|
275
|
-
https://opensource.org/licenses/MIT.
|
|
276
|
-
*/ function stripParams(fullURL, ignoreParams) {
|
|
277
|
-
const strippedURL = new URL(fullURL);
|
|
278
|
-
for (const param of ignoreParams){
|
|
279
|
-
strippedURL.searchParams.delete(param);
|
|
280
|
-
}
|
|
281
|
-
return strippedURL.href;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Matches an item in the cache, ignoring specific URL params. This is similar
|
|
285
|
-
* to the `ignoreSearch` option, but it allows you to ignore just specific
|
|
286
|
-
* params (while continuing to match on the others).
|
|
287
|
-
*
|
|
288
|
-
* @private
|
|
289
|
-
* @param cache
|
|
290
|
-
* @param request
|
|
291
|
-
* @param matchOptions
|
|
292
|
-
* @param ignoreParams
|
|
293
|
-
* @returns
|
|
294
|
-
*/ async function cacheMatchIgnoreParams(cache, request, ignoreParams, matchOptions) {
|
|
295
|
-
const strippedRequestURL = stripParams(request.url, ignoreParams);
|
|
296
|
-
// If the request doesn't include any ignored params, match as normal.
|
|
297
|
-
if (request.url === strippedRequestURL) {
|
|
298
|
-
return cache.match(request, matchOptions);
|
|
299
|
-
}
|
|
300
|
-
// Otherwise, match by comparing keys
|
|
301
|
-
const keysOptions = {
|
|
302
|
-
...matchOptions,
|
|
303
|
-
ignoreSearch: true
|
|
304
|
-
};
|
|
305
|
-
const cacheKeys = await cache.keys(request, keysOptions);
|
|
306
|
-
for (const cacheKey of cacheKeys){
|
|
307
|
-
const strippedCacheKeyURL = stripParams(cacheKey.url, ignoreParams);
|
|
308
|
-
if (strippedRequestURL === strippedCacheKeyURL) {
|
|
309
|
-
return cache.match(cacheKey, matchOptions);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/*
|
|
316
|
-
Copyright 2018 Google LLC
|
|
317
|
-
|
|
318
|
-
Use of this source code is governed by an MIT-style
|
|
319
|
-
license that can be found in the LICENSE file or at
|
|
320
|
-
https://opensource.org/licenses/MIT.
|
|
321
|
-
*/ const _cacheNameDetails = {
|
|
322
|
-
googleAnalytics: "googleAnalytics",
|
|
323
|
-
precache: "precache-v2",
|
|
324
|
-
prefix: "serwist",
|
|
325
|
-
runtime: "runtime",
|
|
326
|
-
suffix: typeof registration !== "undefined" ? registration.scope : ""
|
|
327
|
-
};
|
|
328
|
-
const _createCacheName = (cacheName)=>{
|
|
329
|
-
return [
|
|
330
|
-
_cacheNameDetails.prefix,
|
|
331
|
-
cacheName,
|
|
332
|
-
_cacheNameDetails.suffix
|
|
333
|
-
].filter((value)=>value && value.length > 0).join("-");
|
|
334
|
-
};
|
|
335
|
-
const eachCacheNameDetail = (fn)=>{
|
|
336
|
-
for (const key of Object.keys(_cacheNameDetails)){
|
|
337
|
-
fn(key);
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
const cacheNames = {
|
|
341
|
-
updateDetails: (details)=>{
|
|
342
|
-
eachCacheNameDetail((key)=>{
|
|
343
|
-
const detail = details[key];
|
|
344
|
-
if (typeof detail === "string") {
|
|
345
|
-
_cacheNameDetails[key] = detail;
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
},
|
|
349
|
-
getGoogleAnalyticsName: (userCacheName)=>{
|
|
350
|
-
return userCacheName || _createCacheName(_cacheNameDetails.googleAnalytics);
|
|
351
|
-
},
|
|
352
|
-
getPrecacheName: (userCacheName)=>{
|
|
353
|
-
return userCacheName || _createCacheName(_cacheNameDetails.precache);
|
|
354
|
-
},
|
|
355
|
-
getPrefix: ()=>{
|
|
356
|
-
return _cacheNameDetails.prefix;
|
|
357
|
-
},
|
|
358
|
-
getRuntimeName: (userCacheName)=>{
|
|
359
|
-
return userCacheName || _createCacheName(_cacheNameDetails.runtime);
|
|
360
|
-
},
|
|
361
|
-
getSuffix: ()=>{
|
|
362
|
-
return _cacheNameDetails.suffix;
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
/*
|
|
367
|
-
Copyright 2019 Google LLC
|
|
368
|
-
|
|
369
|
-
Use of this source code is governed by an MIT-style
|
|
370
|
-
license that can be found in the LICENSE file or at
|
|
371
|
-
https://opensource.org/licenses/MIT.
|
|
372
|
-
*/ let supportStatus$1;
|
|
373
|
-
/**
|
|
374
|
-
* A utility function that determines whether the current browser supports
|
|
375
|
-
* constructing a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream)
|
|
376
|
-
* object.
|
|
377
|
-
*
|
|
378
|
-
* @returns `true`, if the current browser can successfully construct a `ReadableStream`, `false` otherwise.
|
|
379
|
-
*
|
|
380
|
-
* @private
|
|
381
|
-
*/ function canConstructReadableStream() {
|
|
382
|
-
if (supportStatus$1 === undefined) {
|
|
383
|
-
// See https://github.com/GoogleChrome/workbox/issues/1473
|
|
384
|
-
try {
|
|
385
|
-
new ReadableStream({
|
|
386
|
-
start () {}
|
|
387
|
-
});
|
|
388
|
-
supportStatus$1 = true;
|
|
389
|
-
} catch (error) {
|
|
390
|
-
supportStatus$1 = false;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
return supportStatus$1;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
/*
|
|
397
|
-
Copyright 2019 Google LLC
|
|
398
|
-
|
|
399
|
-
Use of this source code is governed by an MIT-style
|
|
400
|
-
license that can be found in the LICENSE file or at
|
|
401
|
-
https://opensource.org/licenses/MIT.
|
|
402
|
-
*/ let supportStatus;
|
|
403
|
-
/**
|
|
404
|
-
* A utility function that determines whether the current browser supports
|
|
405
|
-
* constructing a new `Response` from a `response.body` stream.
|
|
406
|
-
*
|
|
407
|
-
* @returns `true`, if the current browser can successfully construct
|
|
408
|
-
* a `Response` from a `response.body` stream, `false` otherwise.
|
|
409
|
-
* @private
|
|
410
|
-
*/ function canConstructResponseFromBodyStream() {
|
|
411
|
-
if (supportStatus === undefined) {
|
|
412
|
-
const testResponse = new Response("");
|
|
413
|
-
if ("body" in testResponse) {
|
|
414
|
-
try {
|
|
415
|
-
new Response(testResponse.body);
|
|
416
|
-
supportStatus = true;
|
|
417
|
-
} catch (error) {
|
|
418
|
-
supportStatus = false;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
supportStatus = false;
|
|
422
|
-
}
|
|
423
|
-
return supportStatus;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
/*
|
|
427
|
-
Copyright 2018 Google LLC
|
|
428
|
-
|
|
429
|
-
Use of this source code is governed by an MIT-style
|
|
430
|
-
license that can be found in the LICENSE file or at
|
|
431
|
-
https://opensource.org/licenses/MIT.
|
|
432
|
-
*/ /**
|
|
433
|
-
* The Deferred class composes Promises in a way that allows for them to be
|
|
434
|
-
* resolved or rejected from outside the constructor. In most cases promises
|
|
435
|
-
* should be used directly, but Deferreds can be necessary when the logic to
|
|
436
|
-
* resolve a promise must be separate.
|
|
437
|
-
*
|
|
438
|
-
* @private
|
|
439
|
-
*/ class Deferred {
|
|
440
|
-
promise;
|
|
441
|
-
resolve;
|
|
442
|
-
reject;
|
|
443
|
-
/**
|
|
444
|
-
* Creates a promise and exposes its resolve and reject functions as methods.
|
|
445
|
-
*/ constructor(){
|
|
446
|
-
this.promise = new Promise((resolve, reject)=>{
|
|
447
|
-
this.resolve = resolve;
|
|
448
|
-
this.reject = reject;
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
/*
|
|
454
|
-
Copyright 2019 Google LLC
|
|
455
|
-
Use of this source code is governed by an MIT-style
|
|
456
|
-
license that can be found in the LICENSE file or at
|
|
457
|
-
https://opensource.org/licenses/MIT.
|
|
458
|
-
*/ /**
|
|
459
|
-
* A helper function that prevents a promise from being flagged as unused.
|
|
460
|
-
*
|
|
461
|
-
* @private
|
|
462
|
-
**/ function dontWaitFor(promise) {
|
|
463
|
-
// Effective no-op.
|
|
464
|
-
void promise.then(()=>{});
|
|
465
|
-
}
|
|
466
|
-
|
|
467
350
|
/*
|
|
468
351
|
Copyright 2019 Google LLC
|
|
469
352
|
Use of this source code is governed by an MIT-style
|
|
@@ -540,128 +423,4 @@ const logger = process.env.NODE_ENV === "production" ? null : (()=>{
|
|
|
540
423
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
541
424
|
const quotaErrorCallbacks = new Set();
|
|
542
425
|
|
|
543
|
-
|
|
544
|
-
* Runs all of the callback functions, one at a time sequentially, in the order
|
|
545
|
-
* in which they were registered.
|
|
546
|
-
*
|
|
547
|
-
* @private
|
|
548
|
-
*/ async function executeQuotaErrorCallbacks() {
|
|
549
|
-
if (process.env.NODE_ENV !== "production") {
|
|
550
|
-
logger.log(`About to run ${quotaErrorCallbacks.size} ` + `callbacks to clean up caches.`);
|
|
551
|
-
}
|
|
552
|
-
for (const callback of quotaErrorCallbacks){
|
|
553
|
-
await callback();
|
|
554
|
-
if (process.env.NODE_ENV !== "production") {
|
|
555
|
-
logger.log(callback, "is complete.");
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
if (process.env.NODE_ENV !== "production") {
|
|
559
|
-
logger.log("Finished running callbacks.");
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
/*
|
|
564
|
-
Copyright 2018 Google LLC
|
|
565
|
-
|
|
566
|
-
Use of this source code is governed by an MIT-style
|
|
567
|
-
license that can be found in the LICENSE file or at
|
|
568
|
-
https://opensource.org/licenses/MIT.
|
|
569
|
-
*/ const getFriendlyURL = (url)=>{
|
|
570
|
-
const urlObj = new URL(String(url), location.href);
|
|
571
|
-
// See https://github.com/GoogleChrome/workbox/issues/2323
|
|
572
|
-
// We want to include everything, except for the origin if it's same-origin.
|
|
573
|
-
return urlObj.href.replace(new RegExp(`^${location.origin}`), "");
|
|
574
|
-
};
|
|
575
|
-
|
|
576
|
-
/*
|
|
577
|
-
Copyright 2019 Google LLC
|
|
578
|
-
Use of this source code is governed by an MIT-style
|
|
579
|
-
license that can be found in the LICENSE file or at
|
|
580
|
-
https://opensource.org/licenses/MIT.
|
|
581
|
-
*/ /**
|
|
582
|
-
* Returns a promise that resolves and the passed number of milliseconds.
|
|
583
|
-
* This utility is an async/await-friendly version of `setTimeout`.
|
|
584
|
-
*
|
|
585
|
-
* @param ms
|
|
586
|
-
* @returns
|
|
587
|
-
* @private
|
|
588
|
-
*/ function timeout(ms) {
|
|
589
|
-
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
const MAX_RETRY_TIME = 2000;
|
|
593
|
-
/**
|
|
594
|
-
* Returns a promise that resolves to a window client matching the passed
|
|
595
|
-
* `resultingClientId`. For browsers that don't support `resultingClientId`
|
|
596
|
-
* or if waiting for the resulting client to apper takes too long, resolve to
|
|
597
|
-
* `undefined`.
|
|
598
|
-
*
|
|
599
|
-
* @param resultingClientId
|
|
600
|
-
* @returns
|
|
601
|
-
* @private
|
|
602
|
-
*/ async function resultingClientExists(resultingClientId) {
|
|
603
|
-
if (!resultingClientId) {
|
|
604
|
-
return;
|
|
605
|
-
}
|
|
606
|
-
let existingWindows = await self.clients.matchAll({
|
|
607
|
-
type: "window"
|
|
608
|
-
});
|
|
609
|
-
const existingWindowIds = new Set(existingWindows.map((w)=>w.id));
|
|
610
|
-
let resultingWindow;
|
|
611
|
-
const startTime = performance.now();
|
|
612
|
-
// Only wait up to `MAX_RETRY_TIME` to find a matching client.
|
|
613
|
-
while(performance.now() - startTime < MAX_RETRY_TIME){
|
|
614
|
-
existingWindows = await self.clients.matchAll({
|
|
615
|
-
type: "window"
|
|
616
|
-
});
|
|
617
|
-
resultingWindow = existingWindows.find((w)=>{
|
|
618
|
-
if (resultingClientId) {
|
|
619
|
-
// If we have a `resultingClientId`, we can match on that.
|
|
620
|
-
return w.id === resultingClientId;
|
|
621
|
-
} else {
|
|
622
|
-
// Otherwise match on finding a window not in `existingWindowIds`.
|
|
623
|
-
return !existingWindowIds.has(w.id);
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
if (resultingWindow) {
|
|
627
|
-
break;
|
|
628
|
-
}
|
|
629
|
-
// Sleep for 100ms and retry.
|
|
630
|
-
await timeout(100);
|
|
631
|
-
}
|
|
632
|
-
return resultingWindow;
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
/*
|
|
636
|
-
Copyright 2020 Google LLC
|
|
637
|
-
Use of this source code is governed by an MIT-style
|
|
638
|
-
license that can be found in the LICENSE file or at
|
|
639
|
-
https://opensource.org/licenses/MIT.
|
|
640
|
-
*/ /**
|
|
641
|
-
* A utility method that makes it easier to use `event.waitUntil` with
|
|
642
|
-
* async functions and return the result.
|
|
643
|
-
*
|
|
644
|
-
* @param event
|
|
645
|
-
* @param asyncFn
|
|
646
|
-
* @returns
|
|
647
|
-
* @private
|
|
648
|
-
*/ function waitUntil(event, asyncFn) {
|
|
649
|
-
const returnPromise = asyncFn();
|
|
650
|
-
event.waitUntil(returnPromise);
|
|
651
|
-
return returnPromise;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
exports.Deferred = Deferred;
|
|
655
|
-
exports.SerwistError = SerwistError;
|
|
656
|
-
exports.assert = finalAssertExports;
|
|
657
|
-
exports.cacheMatchIgnoreParams = cacheMatchIgnoreParams;
|
|
658
|
-
exports.canConstructReadableStream = canConstructReadableStream;
|
|
659
|
-
exports.canConstructResponseFromBodyStream = canConstructResponseFromBodyStream;
|
|
660
|
-
exports.dontWaitFor = dontWaitFor;
|
|
661
|
-
exports.executeQuotaErrorCallbacks = executeQuotaErrorCallbacks;
|
|
662
|
-
exports.getFriendlyURL = getFriendlyURL;
|
|
663
|
-
exports.logger = logger;
|
|
664
|
-
exports.privateCacheNames = cacheNames;
|
|
665
|
-
exports.resultingClientExists = resultingClientExists;
|
|
666
|
-
exports.timeout = timeout;
|
|
667
|
-
exports.waitUntil = waitUntil;
|
|
426
|
+
export { SerwistError as S, canConstructResponseFromBodyStream as a, cacheNames as c, finalAssertExports as f, logger as l, quotaErrorCallbacks as q };
|
|
File without changes
|
|
File without changes
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
export interface MapLikeObject {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Using a plain `MapLikeObject` for now, but could extend/restrict this
|
|
6
|
+
* in the future.
|
|
7
|
+
*/
|
|
8
|
+
export type PluginState = MapLikeObject;
|
|
9
|
+
/**
|
|
10
|
+
* Options passed to a `RouteMatchCallback` function.
|
|
11
|
+
*/
|
|
12
|
+
export interface RouteMatchCallbackOptions {
|
|
13
|
+
event: ExtendableEvent;
|
|
14
|
+
request: Request;
|
|
15
|
+
sameOrigin: boolean;
|
|
16
|
+
url: URL;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The "match" callback is used to determine if a `Route` should apply for a
|
|
20
|
+
* particular URL and request. When matching occurs in response to a fetch
|
|
21
|
+
* event from the client, the `event` object is also supplied. However, since
|
|
22
|
+
* the match callback can be invoked outside of a fetch event, matching logic
|
|
23
|
+
* should not assume the `event` object will always be available.
|
|
24
|
+
* If the match callback returns a truthy value, the matching route's
|
|
25
|
+
* `RouteHandlerCallback` will be invoked immediately. If the value returned
|
|
26
|
+
* is a non-empty array or object, that value will be set on the handler's
|
|
27
|
+
* `options.params` argument.
|
|
28
|
+
*/
|
|
29
|
+
export interface RouteMatchCallback {
|
|
30
|
+
(options: RouteMatchCallbackOptions): any;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Options passed to a `RouteHandlerCallback` function.
|
|
34
|
+
*/
|
|
35
|
+
export declare interface RouteHandlerCallbackOptions {
|
|
36
|
+
/**
|
|
37
|
+
* The event associated with the request.
|
|
38
|
+
*/
|
|
39
|
+
event: ExtendableEvent;
|
|
40
|
+
/**
|
|
41
|
+
* A request to run this strategy for.
|
|
42
|
+
*/
|
|
43
|
+
request: Request;
|
|
44
|
+
url: URL;
|
|
45
|
+
/**
|
|
46
|
+
* The return value from `@serwist/routing`'s `matchCallback` (if applicable).
|
|
47
|
+
*/
|
|
48
|
+
params?: string[] | MapLikeObject;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Options passed to a `ManualHandlerCallback` function.
|
|
52
|
+
*/
|
|
53
|
+
export interface ManualHandlerCallbackOptions {
|
|
54
|
+
/**
|
|
55
|
+
* The event associated with the request.
|
|
56
|
+
*/
|
|
57
|
+
event: ExtendableEvent;
|
|
58
|
+
/**
|
|
59
|
+
* A request to run this strategy for.
|
|
60
|
+
*/
|
|
61
|
+
request: Request | string;
|
|
62
|
+
}
|
|
63
|
+
export type HandlerCallbackOptions = RouteHandlerCallbackOptions | ManualHandlerCallbackOptions;
|
|
64
|
+
/**
|
|
65
|
+
* The "handler" callback is invoked whenever a `Router` matches a URL/Request
|
|
66
|
+
* to a `Route` via its `RouteMatchCallback`. This handler callback should
|
|
67
|
+
* return a `Promise` that resolves with a `Response`.
|
|
68
|
+
*
|
|
69
|
+
* If a non-empty array or object is returned by the `RouteMatchCallback` it
|
|
70
|
+
* will be passed in as this handler's `options.params` argument.
|
|
71
|
+
*/
|
|
72
|
+
export interface RouteHandlerCallback {
|
|
73
|
+
(options: RouteHandlerCallbackOptions): Promise<Response>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The "handler" callback is invoked whenever a `Router` matches a URL/Request
|
|
77
|
+
* to a `Route` via its `RouteMatchCallback`. This handler callback should
|
|
78
|
+
* return a `Promise` that resolves with a `Response`.
|
|
79
|
+
*
|
|
80
|
+
* If a non-empty array or object is returned by the `RouteMatchCallback` it
|
|
81
|
+
* will be passed in as this handler's `options.params` argument.
|
|
82
|
+
*/
|
|
83
|
+
export interface ManualHandlerCallback {
|
|
84
|
+
(options: ManualHandlerCallbackOptions): Promise<Response>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* An object with a `handle` method of type `RouteHandlerCallback`.
|
|
88
|
+
*
|
|
89
|
+
* A `Route` object can be created with either an `RouteHandlerCallback`
|
|
90
|
+
* function or this `RouteHandler` object. The benefit of the `RouteHandler`
|
|
91
|
+
* is it can be extended (as is done by the `@serwist/strategies` package).
|
|
92
|
+
*/
|
|
93
|
+
export interface RouteHandlerObject {
|
|
94
|
+
handle: RouteHandlerCallback;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Either a `RouteHandlerCallback` or a `RouteHandlerObject`.
|
|
98
|
+
* Most APIs in `@serwist/routing` that accept route handlers take either.
|
|
99
|
+
*/
|
|
100
|
+
export type RouteHandler = RouteHandlerCallback | RouteHandlerObject;
|
|
101
|
+
export interface HandlerWillStartCallbackParam {
|
|
102
|
+
request: Request;
|
|
103
|
+
event: ExtendableEvent;
|
|
104
|
+
state?: PluginState;
|
|
105
|
+
}
|
|
106
|
+
export interface HandlerWillStartCallback {
|
|
107
|
+
(param: HandlerWillStartCallbackParam): Promise<void | null | undefined>;
|
|
108
|
+
}
|
|
109
|
+
export interface CacheDidUpdateCallbackParam {
|
|
110
|
+
/**
|
|
111
|
+
* Name of the cache the responses belong to. This is included in the
|
|
112
|
+
* broadcast message.
|
|
113
|
+
*/
|
|
114
|
+
cacheName: string;
|
|
115
|
+
/**
|
|
116
|
+
* Possibly updated response to compare.
|
|
117
|
+
*/
|
|
118
|
+
newResponse: Response;
|
|
119
|
+
/**
|
|
120
|
+
* The `Request` object for the cached entry.
|
|
121
|
+
*/
|
|
122
|
+
request: Request;
|
|
123
|
+
/**
|
|
124
|
+
* The event that triggered this possible cache update.
|
|
125
|
+
*/
|
|
126
|
+
event: ExtendableEvent;
|
|
127
|
+
/**
|
|
128
|
+
* Cached response to compare.
|
|
129
|
+
*/
|
|
130
|
+
oldResponse?: Response | null;
|
|
131
|
+
state?: PluginState;
|
|
132
|
+
}
|
|
133
|
+
export interface CacheDidUpdateCallback {
|
|
134
|
+
(param: CacheDidUpdateCallbackParam): Promise<void | null | undefined>;
|
|
135
|
+
}
|
|
136
|
+
export interface CacheKeyWillBeUsedCallbackParam {
|
|
137
|
+
mode: string;
|
|
138
|
+
request: Request;
|
|
139
|
+
event: ExtendableEvent;
|
|
140
|
+
params?: any;
|
|
141
|
+
state?: PluginState;
|
|
142
|
+
}
|
|
143
|
+
export interface CacheKeyWillBeUsedCallback {
|
|
144
|
+
(param: CacheKeyWillBeUsedCallbackParam): Promise<Request | string>;
|
|
145
|
+
}
|
|
146
|
+
export interface CacheWillUpdateCallbackParam {
|
|
147
|
+
request: Request;
|
|
148
|
+
response: Response;
|
|
149
|
+
event: ExtendableEvent;
|
|
150
|
+
state?: PluginState;
|
|
151
|
+
}
|
|
152
|
+
export interface CacheWillUpdateCallback {
|
|
153
|
+
(param: CacheWillUpdateCallbackParam): Promise<Response | void | null | undefined>;
|
|
154
|
+
}
|
|
155
|
+
export interface CachedResponseWillBeUsedCallbackParam {
|
|
156
|
+
/**
|
|
157
|
+
* Name of the cache the response is in.
|
|
158
|
+
*/
|
|
159
|
+
cacheName: string;
|
|
160
|
+
/**
|
|
161
|
+
* The original request, which may or may not
|
|
162
|
+
* contain a Range: header.
|
|
163
|
+
*/
|
|
164
|
+
request: Request;
|
|
165
|
+
/**
|
|
166
|
+
* The complete cached `Response` object that's been read
|
|
167
|
+
* from a cache and whose freshness should be checked.
|
|
168
|
+
*/
|
|
169
|
+
cachedResponse?: Response;
|
|
170
|
+
event: ExtendableEvent;
|
|
171
|
+
matchOptions?: CacheQueryOptions;
|
|
172
|
+
state?: PluginState;
|
|
173
|
+
}
|
|
174
|
+
export interface CachedResponseWillBeUsedCallback {
|
|
175
|
+
(param: CachedResponseWillBeUsedCallbackParam): Promise<Response | void | null | undefined>;
|
|
176
|
+
}
|
|
177
|
+
export interface FetchDidFailCallbackParam {
|
|
178
|
+
error: Error;
|
|
179
|
+
originalRequest: Request;
|
|
180
|
+
request: Request;
|
|
181
|
+
event: ExtendableEvent;
|
|
182
|
+
state?: PluginState;
|
|
183
|
+
}
|
|
184
|
+
export interface FetchDidFailCallback {
|
|
185
|
+
(param: FetchDidFailCallbackParam): Promise<void | null | undefined>;
|
|
186
|
+
}
|
|
187
|
+
export interface FetchDidSucceedCallbackParam {
|
|
188
|
+
request: Request;
|
|
189
|
+
response: Response;
|
|
190
|
+
event: ExtendableEvent;
|
|
191
|
+
state?: PluginState;
|
|
192
|
+
}
|
|
193
|
+
export interface FetchDidSucceedCallback {
|
|
194
|
+
(param: FetchDidSucceedCallbackParam): Promise<Response>;
|
|
195
|
+
}
|
|
196
|
+
export interface RequestWillFetchCallbackParam {
|
|
197
|
+
request: Request;
|
|
198
|
+
event: ExtendableEvent;
|
|
199
|
+
state?: PluginState;
|
|
200
|
+
}
|
|
201
|
+
export interface RequestWillFetchCallback {
|
|
202
|
+
(param: RequestWillFetchCallbackParam): Promise<Request>;
|
|
203
|
+
}
|
|
204
|
+
export interface HandlerWillRespondCallbackParam {
|
|
205
|
+
request: Request;
|
|
206
|
+
response: Response;
|
|
207
|
+
event: ExtendableEvent;
|
|
208
|
+
state?: PluginState;
|
|
209
|
+
}
|
|
210
|
+
export interface HandlerWillRespondCallback {
|
|
211
|
+
(param: HandlerWillRespondCallbackParam): Promise<Response>;
|
|
212
|
+
}
|
|
213
|
+
export interface HandlerDidErrorCallbackParam {
|
|
214
|
+
request: Request;
|
|
215
|
+
event: ExtendableEvent;
|
|
216
|
+
error: Error;
|
|
217
|
+
state?: PluginState;
|
|
218
|
+
}
|
|
219
|
+
export interface HandlerDidErrorCallback {
|
|
220
|
+
(param: HandlerDidErrorCallbackParam): Promise<Response | undefined>;
|
|
221
|
+
}
|
|
222
|
+
export interface HandlerDidRespondCallbackParam {
|
|
223
|
+
request: Request;
|
|
224
|
+
event: ExtendableEvent;
|
|
225
|
+
response?: Response;
|
|
226
|
+
state?: PluginState;
|
|
227
|
+
}
|
|
228
|
+
export interface HandlerDidRespondCallback {
|
|
229
|
+
(param: HandlerDidRespondCallbackParam): Promise<void | null | undefined>;
|
|
230
|
+
}
|
|
231
|
+
export interface HandlerDidCompleteCallbackParam {
|
|
232
|
+
request: Request;
|
|
233
|
+
error?: Error;
|
|
234
|
+
event: ExtendableEvent;
|
|
235
|
+
response?: Response;
|
|
236
|
+
state?: PluginState;
|
|
237
|
+
}
|
|
238
|
+
export interface HandlerDidCompleteCallback {
|
|
239
|
+
(param: HandlerDidCompleteCallbackParam): Promise<void | null | undefined>;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* An object with optional lifecycle callback properties for the fetch and
|
|
243
|
+
* cache operations.
|
|
244
|
+
*/
|
|
245
|
+
export declare interface SerwistPlugin {
|
|
246
|
+
cacheDidUpdate?: CacheDidUpdateCallback;
|
|
247
|
+
cachedResponseWillBeUsed?: CachedResponseWillBeUsedCallback;
|
|
248
|
+
cacheKeyWillBeUsed?: CacheKeyWillBeUsedCallback;
|
|
249
|
+
cacheWillUpdate?: CacheWillUpdateCallback;
|
|
250
|
+
fetchDidFail?: FetchDidFailCallback;
|
|
251
|
+
fetchDidSucceed?: FetchDidSucceedCallback;
|
|
252
|
+
handlerDidComplete?: HandlerDidCompleteCallback;
|
|
253
|
+
handlerDidError?: HandlerDidErrorCallback;
|
|
254
|
+
handlerDidRespond?: HandlerDidRespondCallback;
|
|
255
|
+
handlerWillRespond?: HandlerWillRespondCallback;
|
|
256
|
+
handlerWillStart?: HandlerWillStartCallback;
|
|
257
|
+
requestWillFetch?: RequestWillFetchCallback;
|
|
258
|
+
}
|
|
259
|
+
export interface SerwistPluginCallbackParam {
|
|
260
|
+
cacheDidUpdate: CacheDidUpdateCallbackParam;
|
|
261
|
+
cachedResponseWillBeUsed: CachedResponseWillBeUsedCallbackParam;
|
|
262
|
+
cacheKeyWillBeUsed: CacheKeyWillBeUsedCallbackParam;
|
|
263
|
+
cacheWillUpdate: CacheWillUpdateCallbackParam;
|
|
264
|
+
fetchDidFail: FetchDidFailCallbackParam;
|
|
265
|
+
fetchDidSucceed: FetchDidSucceedCallbackParam;
|
|
266
|
+
handlerDidComplete: HandlerDidCompleteCallbackParam;
|
|
267
|
+
handlerDidError: HandlerDidErrorCallbackParam;
|
|
268
|
+
handlerDidRespond: HandlerDidRespondCallbackParam;
|
|
269
|
+
handlerWillRespond: HandlerWillRespondCallbackParam;
|
|
270
|
+
handlerWillStart: HandlerWillStartCallbackParam;
|
|
271
|
+
requestWillFetch: RequestWillFetchCallbackParam;
|
|
272
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|