@serwist/core 8.4.4 → 9.0.0-preview.1

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.
Files changed (117) hide show
  1. package/dist/_private/Deferred.d.ts +1 -0
  2. package/dist/_private/Deferred.d.ts.map +1 -0
  3. package/dist/_private/SerwistError.d.ts +1 -0
  4. package/dist/_private/SerwistError.d.ts.map +1 -0
  5. package/dist/_private/assert.d.ts +1 -0
  6. package/dist/_private/assert.d.ts.map +1 -0
  7. package/dist/_private/cacheMatchIgnoreParams.d.ts +1 -0
  8. package/dist/_private/cacheMatchIgnoreParams.d.ts.map +1 -0
  9. package/dist/_private/cacheNames.d.ts +1 -0
  10. package/dist/_private/cacheNames.d.ts.map +1 -0
  11. package/dist/_private/canConstructReadableStream.d.ts +1 -0
  12. package/dist/_private/canConstructReadableStream.d.ts.map +1 -0
  13. package/dist/_private/canConstructResponseFromBodyStream.d.ts +1 -0
  14. package/dist/_private/canConstructResponseFromBodyStream.d.ts.map +1 -0
  15. package/dist/_private/dontWaitFor.d.ts +1 -0
  16. package/dist/_private/dontWaitFor.d.ts.map +1 -0
  17. package/dist/_private/executeQuotaErrorCallbacks.d.ts +1 -0
  18. package/dist/_private/executeQuotaErrorCallbacks.d.ts.map +1 -0
  19. package/dist/_private/getFriendlyURL.d.ts +1 -0
  20. package/dist/_private/getFriendlyURL.d.ts.map +1 -0
  21. package/dist/_private/logger.d.ts +1 -0
  22. package/dist/_private/logger.d.ts.map +1 -0
  23. package/dist/_private/resultingClientExists.d.ts +1 -0
  24. package/dist/_private/resultingClientExists.d.ts.map +1 -0
  25. package/dist/_private/timeout.d.ts +1 -0
  26. package/dist/_private/timeout.d.ts.map +1 -0
  27. package/dist/_private/waitUntil.d.ts +1 -0
  28. package/dist/_private/waitUntil.d.ts.map +1 -0
  29. package/dist/cacheNames.d.ts +1 -0
  30. package/dist/cacheNames.d.ts.map +1 -0
  31. package/dist/{quotaErrorCallbacks.js → chunks/quotaErrorCallbacks.js} +9 -77
  32. package/dist/clientsClaim.d.ts +1 -0
  33. package/dist/clientsClaim.d.ts.map +1 -0
  34. package/dist/copyResponse.d.ts +1 -0
  35. package/dist/copyResponse.d.ts.map +1 -0
  36. package/dist/index.d.ts +1 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.internal.d.ts +1 -0
  39. package/dist/index.internal.d.ts.map +1 -0
  40. package/dist/index.internal.js +14 -123
  41. package/dist/index.js +5 -60
  42. package/dist/models/messages/messageGenerator.d.ts +1 -0
  43. package/dist/models/messages/messageGenerator.d.ts.map +1 -0
  44. package/dist/models/messages/messages.d.ts +1 -0
  45. package/dist/models/messages/messages.d.ts.map +1 -0
  46. package/dist/models/pluginEvents.d.ts +1 -0
  47. package/dist/models/pluginEvents.d.ts.map +1 -0
  48. package/dist/models/quotaErrorCallbacks.d.ts +1 -0
  49. package/dist/models/quotaErrorCallbacks.d.ts.map +1 -0
  50. package/dist/registerQuotaErrorCallback.d.ts +1 -0
  51. package/dist/registerQuotaErrorCallback.d.ts.map +1 -0
  52. package/dist/setCacheNameDetails.d.ts +1 -0
  53. package/dist/setCacheNameDetails.d.ts.map +1 -0
  54. package/dist/types.d.ts +1 -0
  55. package/dist/types.d.ts.map +1 -0
  56. package/dist/utils/pluginUtils.d.ts +1 -0
  57. package/dist/utils/pluginUtils.d.ts.map +1 -0
  58. package/dist/utils/welcome.d.ts +1 -0
  59. package/dist/utils/welcome.d.ts.map +1 -0
  60. package/package.json +18 -22
  61. package/src/_private/Deferred.ts +33 -0
  62. package/src/_private/SerwistError.ts +42 -0
  63. package/src/_private/assert.ts +89 -0
  64. package/src/_private/cacheMatchIgnoreParams.ts +54 -0
  65. package/src/_private/cacheNames.ts +87 -0
  66. package/src/_private/canConstructReadableStream.ts +34 -0
  67. package/src/_private/canConstructResponseFromBodyStream.ts +37 -0
  68. package/src/_private/dontWaitFor.ts +16 -0
  69. package/src/_private/executeQuotaErrorCallbacks.ts +35 -0
  70. package/src/_private/getFriendlyURL.ts +16 -0
  71. package/src/_private/logger.ts +92 -0
  72. package/src/_private/resultingClientExists.ts +58 -0
  73. package/src/_private/timeout.ts +19 -0
  74. package/src/_private/waitUntil.ts +23 -0
  75. package/src/cacheNames.ts +41 -0
  76. package/src/clientsClaim.ts +20 -0
  77. package/src/copyResponse.ts +62 -0
  78. package/{dist/index.internal.d.cts → src/index.internal.ts} +19 -1
  79. package/{dist/index.d.cts → src/index.ts} +9 -0
  80. package/src/models/messages/messageGenerator.ts +28 -0
  81. package/src/models/messages/messages.ts +231 -0
  82. package/src/models/pluginEvents.ts +17 -0
  83. package/src/models/quotaErrorCallbacks.ts +13 -0
  84. package/src/registerQuotaErrorCallback.ts +36 -0
  85. package/src/setCacheNameDetails.ts +55 -0
  86. package/src/types.ts +315 -0
  87. package/src/utils/pluginUtils.ts +15 -0
  88. package/src/utils/welcome.ts +25 -0
  89. package/dist/_private/Deferred.d.cts +0 -18
  90. package/dist/_private/SerwistError.d.cts +0 -23
  91. package/dist/_private/assert.d.cts +0 -10
  92. package/dist/_private/cacheMatchIgnoreParams.d.cts +0 -14
  93. package/dist/_private/cacheNames.d.cts +0 -39
  94. package/dist/_private/canConstructReadableStream.d.cts +0 -11
  95. package/dist/_private/canConstructResponseFromBodyStream.d.cts +0 -10
  96. package/dist/_private/dontWaitFor.d.cts +0 -6
  97. package/dist/_private/executeQuotaErrorCallbacks.d.cts +0 -8
  98. package/dist/_private/getFriendlyURL.d.cts +0 -2
  99. package/dist/_private/logger.d.cts +0 -10
  100. package/dist/_private/resultingClientExists.d.cts +0 -11
  101. package/dist/_private/timeout.d.cts +0 -9
  102. package/dist/_private/waitUntil.d.cts +0 -11
  103. package/dist/cacheNames.d.cts +0 -20
  104. package/dist/clientsClaim.d.cts +0 -6
  105. package/dist/copyResponse.d.cts +0 -20
  106. package/dist/index.cjs +0 -153
  107. package/dist/index.internal.cjs +0 -243
  108. package/dist/models/messages/messageGenerator.d.cts +0 -1
  109. package/dist/models/messages/messages.d.cts +0 -8
  110. package/dist/models/pluginEvents.d.cts +0 -9
  111. package/dist/models/quotaErrorCallbacks.d.cts +0 -2
  112. package/dist/quotaErrorCallbacks.cjs +0 -432
  113. package/dist/registerQuotaErrorCallback.d.cts +0 -8
  114. package/dist/setCacheNameDetails.d.cts +0 -9
  115. package/dist/types.d.cts +0 -272
  116. package/dist/utils/pluginUtils.d.cts +0 -4
  117. package/dist/utils/welcome.d.cts +0 -1
@@ -0,0 +1,17 @@
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
+ */
8
+
9
+ export enum pluginEvents {
10
+ CACHE_DID_UPDATE = "cacheDidUpdate",
11
+ CACHE_KEY_WILL_BE_USED = "cacheKeyWillBeUsed",
12
+ CACHE_WILL_UPDATE = "cacheWillUpdate",
13
+ CACHED_RESPONSE_WILL_BE_USED = "cachedResponseWillBeUsed",
14
+ FETCH_DID_FAIL = "fetchDidFail",
15
+ FETCH_DID_SUCCEED = "fetchDidSucceed",
16
+ REQUEST_WILL_FETCH = "requestWillFetch",
17
+ }
@@ -0,0 +1,13 @@
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
+ */
8
+
9
+ // Callbacks to be executed whenever there's a quota error.
10
+ // biome-ignore lint/complexity/noBannedTypes: Can't change Function type right now.
11
+ const quotaErrorCallbacks: Set<Function> = new Set();
12
+
13
+ export { quotaErrorCallbacks };
@@ -0,0 +1,36 @@
1
+ /*
2
+ Copyright 2019 Google LLC
3
+
4
+ Use of this source code is governed by an MIT-style
5
+ license that can be found in the LICENSE file or at
6
+ https://opensource.org/licenses/MIT.
7
+ */
8
+
9
+ import { assert } from "./_private/assert.js";
10
+ import { logger } from "./_private/logger.js";
11
+ import { quotaErrorCallbacks } from "./models/quotaErrorCallbacks.js";
12
+
13
+ /**
14
+ * Adds a function to the set of quotaErrorCallbacks that will be executed if
15
+ * there's a quota error.
16
+ *
17
+ * @param callback
18
+ */
19
+ // biome-ignore lint/complexity/noBannedTypes: Can't change Function type
20
+ function registerQuotaErrorCallback(callback: Function): void {
21
+ if (process.env.NODE_ENV !== "production") {
22
+ assert!.isType(callback, "function", {
23
+ moduleName: "@serwist/core",
24
+ funcName: "register",
25
+ paramName: "callback",
26
+ });
27
+ }
28
+
29
+ quotaErrorCallbacks.add(callback);
30
+
31
+ if (process.env.NODE_ENV !== "production") {
32
+ logger.log("Registered a callback to respond to quota errors.", callback);
33
+ }
34
+ }
35
+
36
+ export { registerQuotaErrorCallback };
@@ -0,0 +1,55 @@
1
+ /*
2
+ Copyright 2019 Google LLC
3
+
4
+ Use of this source code is governed by an MIT-style
5
+ license that can be found in the LICENSE file or at
6
+ https://opensource.org/licenses/MIT.
7
+ */
8
+
9
+ import { SerwistError } from "./_private/SerwistError.js";
10
+ import { assert } from "./_private/assert.js";
11
+ import type { PartialCacheNameDetails } from "./_private/cacheNames.js";
12
+ import { cacheNames } from "./_private/cacheNames.js";
13
+
14
+ /**
15
+ * Modifies the default cache names used by the Serwist packages.
16
+ * Cache names are generated as `<prefix>-<Cache Name>-<suffix>`.
17
+ *
18
+ * @param details
19
+ */
20
+ function setCacheNameDetails(details: PartialCacheNameDetails): void {
21
+ if (process.env.NODE_ENV !== "production") {
22
+ for (const key of Object.keys(details)) {
23
+ assert!.isType(details[key], "string", {
24
+ moduleName: "@serwist/core",
25
+ funcName: "setCacheNameDetails",
26
+ paramName: `details.${key}`,
27
+ });
28
+ }
29
+
30
+ if (details.precache?.length === 0) {
31
+ throw new SerwistError("invalid-cache-name", {
32
+ cacheNameId: "precache",
33
+ value: details.precache,
34
+ });
35
+ }
36
+
37
+ if (details.runtime?.length === 0) {
38
+ throw new SerwistError("invalid-cache-name", {
39
+ cacheNameId: "runtime",
40
+ value: details.runtime,
41
+ });
42
+ }
43
+
44
+ if (details.googleAnalytics?.length === 0) {
45
+ throw new SerwistError("invalid-cache-name", {
46
+ cacheNameId: "googleAnalytics",
47
+ value: details.googleAnalytics,
48
+ });
49
+ }
50
+ }
51
+
52
+ cacheNames.updateDetails(details);
53
+ }
54
+
55
+ export { setCacheNameDetails };
package/src/types.ts ADDED
@@ -0,0 +1,315 @@
1
+ /*
2
+ Copyright 2019 Google LLC
3
+
4
+ Use of this source code is governed by an MIT-style
5
+ license that can be found in the LICENSE file or at
6
+ https://opensource.org/licenses/MIT.
7
+ */
8
+
9
+ export interface MapLikeObject {
10
+ [key: string]: any;
11
+ }
12
+
13
+ /**
14
+ * Using a plain `MapLikeObject` for now, but could extend/restrict this
15
+ * in the future.
16
+ */
17
+ export type PluginState = MapLikeObject;
18
+
19
+ /**
20
+ * Options passed to a `RouteMatchCallback` function.
21
+ */
22
+ export interface RouteMatchCallbackOptions {
23
+ event: ExtendableEvent;
24
+ request: Request;
25
+ sameOrigin: boolean;
26
+ url: URL;
27
+ }
28
+
29
+ /**
30
+ * The "match" callback is used to determine if a `Route` should apply for a
31
+ * particular URL and request. When matching occurs in response to a fetch
32
+ * event from the client, the `event` object is also supplied. However, since
33
+ * the match callback can be invoked outside of a fetch event, matching logic
34
+ * should not assume the `event` object will always be available.
35
+ * If the match callback returns a truthy value, the matching route's
36
+ * `RouteHandlerCallback` will be invoked immediately. If the value returned
37
+ * is a non-empty array or object, that value will be set on the handler's
38
+ * `options.params` argument.
39
+ */
40
+ export interface RouteMatchCallback {
41
+ (options: RouteMatchCallbackOptions): any;
42
+ }
43
+
44
+ /**
45
+ * Options passed to a `RouteHandlerCallback` function.
46
+ */
47
+ export declare interface RouteHandlerCallbackOptions {
48
+ /**
49
+ * The event associated with the request.
50
+ */
51
+ event: ExtendableEvent;
52
+ /**
53
+ * A request to run this strategy for.
54
+ */
55
+ request: Request;
56
+ url: URL;
57
+ /**
58
+ * The return value from `@serwist/routing`'s `matchCallback` (if applicable).
59
+ */
60
+ params?: string[] | MapLikeObject;
61
+ }
62
+ /**
63
+ * Options passed to a `ManualHandlerCallback` function.
64
+ */
65
+ export interface ManualHandlerCallbackOptions {
66
+ /**
67
+ * The event associated with the request.
68
+ */
69
+ event: ExtendableEvent;
70
+ /**
71
+ * A request to run this strategy for.
72
+ */
73
+ request: Request | string;
74
+ }
75
+
76
+ export type HandlerCallbackOptions = RouteHandlerCallbackOptions | ManualHandlerCallbackOptions;
77
+
78
+ /**
79
+ * The "handler" callback is invoked whenever a `Router` matches a URL/Request
80
+ * to a `Route` via its `RouteMatchCallback`. This handler callback should
81
+ * return a `Promise` that resolves with a `Response`.
82
+ *
83
+ * If a non-empty array or object is returned by the `RouteMatchCallback` it
84
+ * will be passed in as this handler's `options.params` argument.
85
+ */
86
+ export interface RouteHandlerCallback {
87
+ (options: RouteHandlerCallbackOptions): Promise<Response>;
88
+ }
89
+
90
+ /**
91
+ * The "handler" callback is invoked whenever a `Router` matches a URL/Request
92
+ * to a `Route` via its `RouteMatchCallback`. This handler callback should
93
+ * return a `Promise` that resolves with a `Response`.
94
+ *
95
+ * If a non-empty array or object is returned by the `RouteMatchCallback` it
96
+ * will be passed in as this handler's `options.params` argument.
97
+ */
98
+ export interface ManualHandlerCallback {
99
+ (options: ManualHandlerCallbackOptions): Promise<Response>;
100
+ }
101
+
102
+ /**
103
+ * An object with a `handle` method of type `RouteHandlerCallback`.
104
+ *
105
+ * A `Route` object can be created with either an `RouteHandlerCallback`
106
+ * function or this `RouteHandler` object. The benefit of the `RouteHandler`
107
+ * is it can be extended (as is done by the `@serwist/strategies` package).
108
+ */
109
+ export interface RouteHandlerObject {
110
+ handle: RouteHandlerCallback;
111
+ }
112
+
113
+ /**
114
+ * Either a `RouteHandlerCallback` or a `RouteHandlerObject`.
115
+ * Most APIs in `@serwist/routing` that accept route handlers take either.
116
+ */
117
+ export type RouteHandler = RouteHandlerCallback | RouteHandlerObject;
118
+
119
+ export interface HandlerWillStartCallbackParam {
120
+ request: Request;
121
+ event: ExtendableEvent;
122
+ state?: PluginState;
123
+ }
124
+
125
+ export interface HandlerWillStartCallback {
126
+ (param: HandlerWillStartCallbackParam): Promise<any>;
127
+ }
128
+
129
+ export interface CacheDidUpdateCallbackParam {
130
+ /**
131
+ * Name of the cache the responses belong to. This is included in the
132
+ * broadcast message.
133
+ */
134
+ cacheName: string;
135
+ /**
136
+ * Possibly updated response to compare.
137
+ */
138
+ newResponse: Response;
139
+ /**
140
+ * The `Request` object for the cached entry.
141
+ */
142
+ request: Request;
143
+ /**
144
+ * The event that triggered this possible cache update.
145
+ */
146
+ event: ExtendableEvent;
147
+ /**
148
+ * Cached response to compare.
149
+ */
150
+ oldResponse?: Response | null;
151
+ state?: PluginState;
152
+ }
153
+
154
+ export interface CacheDidUpdateCallback {
155
+ (param: CacheDidUpdateCallbackParam): Promise<any>;
156
+ }
157
+
158
+ export interface CacheKeyWillBeUsedCallbackParam {
159
+ mode: string;
160
+ request: Request;
161
+ event: ExtendableEvent;
162
+ params?: any;
163
+ state?: PluginState;
164
+ }
165
+
166
+ export interface CacheKeyWillBeUsedCallback {
167
+ (param: CacheKeyWillBeUsedCallbackParam): Promise<Request | string>;
168
+ }
169
+
170
+ export interface CacheWillUpdateCallbackParam {
171
+ request: Request;
172
+ response: Response;
173
+ event: ExtendableEvent;
174
+ state?: PluginState;
175
+ }
176
+
177
+ export interface CacheWillUpdateCallback {
178
+ (param: CacheWillUpdateCallbackParam): Promise<any>;
179
+ }
180
+
181
+ export interface CachedResponseWillBeUsedCallbackParam {
182
+ /**
183
+ * Name of the cache the response is in.
184
+ */
185
+ cacheName: string;
186
+ /**
187
+ * The original request, which may or may not
188
+ * contain a Range: header.
189
+ */
190
+ request: Request;
191
+ /**
192
+ * The complete cached `Response` object that's been read
193
+ * from a cache and whose freshness should be checked.
194
+ */
195
+ cachedResponse?: Response;
196
+ event: ExtendableEvent;
197
+ matchOptions?: CacheQueryOptions;
198
+ state?: PluginState;
199
+ }
200
+
201
+ export interface CachedResponseWillBeUsedCallback {
202
+ (param: CachedResponseWillBeUsedCallbackParam): Promise<any>;
203
+ }
204
+
205
+ export interface FetchDidFailCallbackParam {
206
+ error: Error;
207
+ originalRequest: Request;
208
+ request: Request;
209
+ event: ExtendableEvent;
210
+ state?: PluginState;
211
+ }
212
+
213
+ export interface FetchDidFailCallback {
214
+ (param: FetchDidFailCallbackParam): Promise<any>;
215
+ }
216
+
217
+ export interface FetchDidSucceedCallbackParam {
218
+ request: Request;
219
+ response: Response;
220
+ event: ExtendableEvent;
221
+ state?: PluginState;
222
+ }
223
+
224
+ export interface FetchDidSucceedCallback {
225
+ (param: FetchDidSucceedCallbackParam): Promise<Response>;
226
+ }
227
+
228
+ export interface RequestWillFetchCallbackParam {
229
+ request: Request;
230
+ event: ExtendableEvent;
231
+ state?: PluginState;
232
+ }
233
+
234
+ export interface RequestWillFetchCallback {
235
+ (param: RequestWillFetchCallbackParam): Promise<Request>;
236
+ }
237
+
238
+ export interface HandlerWillRespondCallbackParam {
239
+ request: Request;
240
+ response: Response;
241
+ event: ExtendableEvent;
242
+ state?: PluginState;
243
+ }
244
+
245
+ export interface HandlerWillRespondCallback {
246
+ (param: HandlerWillRespondCallbackParam): Promise<Response>;
247
+ }
248
+
249
+ export interface HandlerDidErrorCallbackParam {
250
+ request: Request;
251
+ event: ExtendableEvent;
252
+ error: Error;
253
+ state?: PluginState;
254
+ }
255
+
256
+ export interface HandlerDidErrorCallback {
257
+ (param: HandlerDidErrorCallbackParam): Promise<Response | undefined>;
258
+ }
259
+
260
+ export interface HandlerDidRespondCallbackParam {
261
+ request: Request;
262
+ event: ExtendableEvent;
263
+ response?: Response;
264
+ state?: PluginState;
265
+ }
266
+
267
+ export interface HandlerDidRespondCallback {
268
+ (param: HandlerDidRespondCallbackParam): Promise<any>;
269
+ }
270
+
271
+ export interface HandlerDidCompleteCallbackParam {
272
+ request: Request;
273
+ error?: Error;
274
+ event: ExtendableEvent;
275
+ response?: Response;
276
+ state?: PluginState;
277
+ }
278
+
279
+ export interface HandlerDidCompleteCallback {
280
+ (param: HandlerDidCompleteCallbackParam): Promise<any>;
281
+ }
282
+
283
+ /**
284
+ * An object with optional lifecycle callback properties for the fetch and
285
+ * cache operations.
286
+ */
287
+ export declare interface SerwistPlugin {
288
+ cacheDidUpdate?: CacheDidUpdateCallback;
289
+ cachedResponseWillBeUsed?: CachedResponseWillBeUsedCallback;
290
+ cacheKeyWillBeUsed?: CacheKeyWillBeUsedCallback;
291
+ cacheWillUpdate?: CacheWillUpdateCallback;
292
+ fetchDidFail?: FetchDidFailCallback;
293
+ fetchDidSucceed?: FetchDidSucceedCallback;
294
+ handlerDidComplete?: HandlerDidCompleteCallback;
295
+ handlerDidError?: HandlerDidErrorCallback;
296
+ handlerDidRespond?: HandlerDidRespondCallback;
297
+ handlerWillRespond?: HandlerWillRespondCallback;
298
+ handlerWillStart?: HandlerWillStartCallback;
299
+ requestWillFetch?: RequestWillFetchCallback;
300
+ }
301
+
302
+ export interface SerwistPluginCallbackParam {
303
+ cacheDidUpdate: CacheDidUpdateCallbackParam;
304
+ cachedResponseWillBeUsed: CachedResponseWillBeUsedCallbackParam;
305
+ cacheKeyWillBeUsed: CacheKeyWillBeUsedCallbackParam;
306
+ cacheWillUpdate: CacheWillUpdateCallbackParam;
307
+ fetchDidFail: FetchDidFailCallbackParam;
308
+ fetchDidSucceed: FetchDidSucceedCallbackParam;
309
+ handlerDidComplete: HandlerDidCompleteCallbackParam;
310
+ handlerDidError: HandlerDidErrorCallbackParam;
311
+ handlerDidRespond: HandlerDidRespondCallbackParam;
312
+ handlerWillRespond: HandlerWillRespondCallbackParam;
313
+ handlerWillStart: HandlerWillStartCallbackParam;
314
+ requestWillFetch: RequestWillFetchCallbackParam;
315
+ }
@@ -0,0 +1,15 @@
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
+ */
8
+
9
+ import type { SerwistPlugin } from "../types.js";
10
+
11
+ export const pluginUtils = {
12
+ filter: (plugins: SerwistPlugin[], callbackName: string): SerwistPlugin[] => {
13
+ return plugins.filter((plugin) => callbackName in plugin);
14
+ },
15
+ };
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright 2019 Google LLC
3
+
4
+ Use of this source code is governed by an MIT-style
5
+ license that can be found in the LICENSE file or at
6
+ https://opensource.org/licenses/MIT.
7
+ */
8
+
9
+ import { logger } from "../_private/logger.js";
10
+
11
+ // A SerwistCore instance must be exported before we can use the logger.
12
+ // This is so it can get the current log level.
13
+ if (process.env.NODE_ENV !== "production") {
14
+ const padding = " ";
15
+ logger.groupCollapsed("Welcome to Serwist!");
16
+ logger.log(
17
+ "You are currently using a development build. " +
18
+ "By default this will switch to prod builds when not on localhost. " +
19
+ "You can force this with serwist.setConfig({debug: true|false}).",
20
+ );
21
+ logger.log(`📖 Read the guides and documentation\n${padding}https://developers.google.com/web/tools/workbox/`);
22
+ logger.log(`❓ Use the Discussions tab on Github to ask questions\n${padding}https://github.com/serwist/serwist/discussions`);
23
+ logger.log(`🐛 Found a bug? Report it on GitHub\n${padding}https://github.com/serwist/serwist/issues/new`);
24
+ logger.groupEnd();
25
+ }
@@ -1,18 +0,0 @@
1
- /**
2
- * The Deferred class composes Promises in a way that allows for them to be
3
- * resolved or rejected from outside the constructor. In most cases promises
4
- * should be used directly, but Deferreds can be necessary when the logic to
5
- * resolve a promise must be separate.
6
- *
7
- * @private
8
- */
9
- declare class Deferred<T> {
10
- promise: Promise<T>;
11
- resolve: (value: T) => void;
12
- reject: (reason?: any) => void;
13
- /**
14
- * Creates a promise and exposes its resolve and reject functions as methods.
15
- */
16
- constructor();
17
- }
18
- export { Deferred };
@@ -1,23 +0,0 @@
1
- import type { MapLikeObject } from "../types.js";
2
- /**
3
- * Serwist errors should be thrown with this class.
4
- * This allows use to ensure the type easily in tests,
5
- * helps developers identify errors from Serwist
6
- * easily and allows use to optimise error
7
- * messages correctly.
8
- *
9
- * @private
10
- */
11
- declare class SerwistError extends Error {
12
- details?: MapLikeObject;
13
- /**
14
- *
15
- * @param errorCode The error code that
16
- * identifies this particular error.
17
- * @param details Any relevant arguments
18
- * that will help developers identify issues should
19
- * be added as a key on the context object.
20
- */
21
- constructor(errorCode: string, details?: MapLikeObject);
22
- }
23
- export { SerwistError };
@@ -1,10 +0,0 @@
1
- import type { MapLikeObject } from "../types.js";
2
- declare const finalAssertExports: {
3
- hasMethod: (object: MapLikeObject, expectedMethod: string, details: MapLikeObject) => void;
4
- isArray: (value: any[], details: MapLikeObject) => void;
5
- isInstance: (object: unknown, expectedClass: Function, details: MapLikeObject) => void;
6
- isOneOf: (value: any, validValues: any[], details: MapLikeObject) => void;
7
- isType: (object: unknown, expectedType: string, details: MapLikeObject) => void;
8
- isArrayOfClass: (value: any, expectedClass: Function, details: MapLikeObject) => void;
9
- } | null;
10
- export { finalAssertExports as assert };
@@ -1,14 +0,0 @@
1
- /**
2
- * Matches an item in the cache, ignoring specific URL params. This is similar
3
- * to the `ignoreSearch` option, but it allows you to ignore just specific
4
- * params (while continuing to match on the others).
5
- *
6
- * @private
7
- * @param cache
8
- * @param request
9
- * @param matchOptions
10
- * @param ignoreParams
11
- * @returns
12
- */
13
- declare function cacheMatchIgnoreParams(cache: Cache, request: Request, ignoreParams: string[], matchOptions?: CacheQueryOptions): Promise<Response | undefined>;
14
- export { cacheMatchIgnoreParams };
@@ -1,39 +0,0 @@
1
- export interface CacheNameDetails {
2
- googleAnalytics: string;
3
- precache: string;
4
- prefix: string;
5
- runtime: string;
6
- suffix: string;
7
- }
8
- export interface PartialCacheNameDetails {
9
- /**
10
- * The string to add to the beginning of the precache and runtime cache names.
11
- */
12
- prefix?: string;
13
- /**
14
- * The string to add to the end of the precache and runtime cache names.
15
- */
16
- suffix?: string;
17
- /**
18
- * The cache name to use for precache caching.
19
- */
20
- precache?: string;
21
- /**
22
- * The cache name to use for runtime caching.
23
- */
24
- runtime?: string;
25
- /**
26
- * The cache name to use for `@serwist/google-analytics` caching.
27
- */
28
- googleAnalytics?: string;
29
- [propName: string]: string | undefined;
30
- }
31
- export type CacheNameDetailsProp = "googleAnalytics" | "precache" | "prefix" | "runtime" | "suffix";
32
- export declare const cacheNames: {
33
- updateDetails: (details: PartialCacheNameDetails) => void;
34
- getGoogleAnalyticsName: (userCacheName?: string) => string;
35
- getPrecacheName: (userCacheName?: string) => string;
36
- getPrefix: () => string;
37
- getRuntimeName: (userCacheName?: string) => string;
38
- getSuffix: () => string;
39
- };
@@ -1,11 +0,0 @@
1
- /**
2
- * A utility function that determines whether the current browser supports
3
- * constructing a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream)
4
- * object.
5
- *
6
- * @returns `true`, if the current browser can successfully construct a `ReadableStream`, `false` otherwise.
7
- *
8
- * @private
9
- */
10
- declare function canConstructReadableStream(): boolean;
11
- export { canConstructReadableStream };
@@ -1,10 +0,0 @@
1
- /**
2
- * A utility function that determines whether the current browser supports
3
- * constructing a new `Response` from a `response.body` stream.
4
- *
5
- * @returns `true`, if the current browser can successfully construct
6
- * a `Response` from a `response.body` stream, `false` otherwise.
7
- * @private
8
- */
9
- declare function canConstructResponseFromBodyStream(): boolean;
10
- export { canConstructResponseFromBodyStream };
@@ -1,6 +0,0 @@
1
- /**
2
- * A helper function that prevents a promise from being flagged as unused.
3
- *
4
- * @private
5
- **/
6
- export declare function dontWaitFor(promise: Promise<any>): void;
@@ -1,8 +0,0 @@
1
- /**
2
- * Runs all of the callback functions, one at a time sequentially, in the order
3
- * in which they were registered.
4
- *
5
- * @private
6
- */
7
- declare function executeQuotaErrorCallbacks(): Promise<void>;
8
- export { executeQuotaErrorCallbacks };
@@ -1,2 +0,0 @@
1
- declare const getFriendlyURL: (url: URL | string) => string;
2
- export { getFriendlyURL };
@@ -1,10 +0,0 @@
1
- declare global {
2
- interface WorkerGlobalScope {
3
- __WB_DISABLE_DEV_LOGS: boolean;
4
- }
5
- interface Window {
6
- __WB_DISABLE_DEV_LOGS: boolean;
7
- }
8
- }
9
- declare const logger: Console;
10
- export { logger };
@@ -1,11 +0,0 @@
1
- /**
2
- * Returns a promise that resolves to a window client matching the passed
3
- * `resultingClientId`. For browsers that don't support `resultingClientId`
4
- * or if waiting for the resulting client to apper takes too long, resolve to
5
- * `undefined`.
6
- *
7
- * @param resultingClientId
8
- * @returns
9
- * @private
10
- */
11
- export declare function resultingClientExists(resultingClientId?: string): Promise<Client | undefined>;
@@ -1,9 +0,0 @@
1
- /**
2
- * Returns a promise that resolves and the passed number of milliseconds.
3
- * This utility is an async/await-friendly version of `setTimeout`.
4
- *
5
- * @param ms
6
- * @returns
7
- * @private
8
- */
9
- export declare function timeout(ms: number): Promise<unknown>;
@@ -1,11 +0,0 @@
1
- /**
2
- * A utility method that makes it easier to use `event.waitUntil` with
3
- * async functions and return the result.
4
- *
5
- * @param event
6
- * @param asyncFn
7
- * @returns
8
- * @private
9
- */
10
- declare function waitUntil(event: ExtendableEvent, asyncFn: () => Promise<any>): Promise<any>;
11
- export { waitUntil };