@serwist/core 9.0.0-preview.8 → 9.0.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.
Files changed (89) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +3 -11
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.internal.d.ts +1 -15
  5. package/dist/index.internal.d.ts.map +1 -1
  6. package/dist/index.internal.js +1 -120
  7. package/dist/index.js +2 -92
  8. package/package.json +9 -6
  9. package/src/index.internal.ts +4 -21
  10. package/src/index.ts +43 -13
  11. package/dist/_private/Deferred.d.ts +0 -19
  12. package/dist/_private/Deferred.d.ts.map +0 -1
  13. package/dist/_private/SerwistError.d.ts +0 -25
  14. package/dist/_private/SerwistError.d.ts.map +0 -1
  15. package/dist/_private/assert.d.ts +0 -11
  16. package/dist/_private/assert.d.ts.map +0 -1
  17. package/dist/_private/cacheMatchIgnoreParams.d.ts +0 -15
  18. package/dist/_private/cacheMatchIgnoreParams.d.ts.map +0 -1
  19. package/dist/_private/cacheNames.d.ts +0 -40
  20. package/dist/_private/cacheNames.d.ts.map +0 -1
  21. package/dist/_private/canConstructReadableStream.d.ts +0 -12
  22. package/dist/_private/canConstructReadableStream.d.ts.map +0 -1
  23. package/dist/_private/canConstructResponseFromBodyStream.d.ts +0 -11
  24. package/dist/_private/canConstructResponseFromBodyStream.d.ts.map +0 -1
  25. package/dist/_private/dontWaitFor.d.ts +0 -7
  26. package/dist/_private/dontWaitFor.d.ts.map +0 -1
  27. package/dist/_private/executeQuotaErrorCallbacks.d.ts +0 -9
  28. package/dist/_private/executeQuotaErrorCallbacks.d.ts.map +0 -1
  29. package/dist/_private/getFriendlyURL.d.ts +0 -3
  30. package/dist/_private/getFriendlyURL.d.ts.map +0 -1
  31. package/dist/_private/logger.d.ts +0 -24
  32. package/dist/_private/logger.d.ts.map +0 -1
  33. package/dist/_private/resultingClientExists.d.ts +0 -12
  34. package/dist/_private/resultingClientExists.d.ts.map +0 -1
  35. package/dist/_private/timeout.d.ts +0 -10
  36. package/dist/_private/timeout.d.ts.map +0 -1
  37. package/dist/_private/waitUntil.d.ts +0 -11
  38. package/dist/_private/waitUntil.d.ts.map +0 -1
  39. package/dist/cacheNames.d.ts +0 -21
  40. package/dist/cacheNames.d.ts.map +0 -1
  41. package/dist/chunks/quotaErrorCallbacks.js +0 -355
  42. package/dist/clientsClaim.d.ts +0 -7
  43. package/dist/clientsClaim.d.ts.map +0 -1
  44. package/dist/copyResponse.d.ts +0 -21
  45. package/dist/copyResponse.d.ts.map +0 -1
  46. package/dist/models/messages/messageGenerator.d.ts +0 -4
  47. package/dist/models/messages/messageGenerator.d.ts.map +0 -1
  48. package/dist/models/messages/messages.d.ts +0 -44
  49. package/dist/models/messages/messages.d.ts.map +0 -1
  50. package/dist/models/pluginEvents.d.ts +0 -10
  51. package/dist/models/pluginEvents.d.ts.map +0 -1
  52. package/dist/models/quotaErrorCallbacks.d.ts +0 -3
  53. package/dist/models/quotaErrorCallbacks.d.ts.map +0 -1
  54. package/dist/registerQuotaErrorCallback.d.ts +0 -9
  55. package/dist/registerQuotaErrorCallback.d.ts.map +0 -1
  56. package/dist/setCacheNameDetails.d.ts +0 -10
  57. package/dist/setCacheNameDetails.d.ts.map +0 -1
  58. package/dist/types.d.ts +0 -279
  59. package/dist/types.d.ts.map +0 -1
  60. package/dist/utils/pluginUtils.d.ts +0 -5
  61. package/dist/utils/pluginUtils.d.ts.map +0 -1
  62. package/dist/utils/welcome.d.ts +0 -2
  63. package/dist/utils/welcome.d.ts.map +0 -1
  64. package/src/_private/Deferred.ts +0 -33
  65. package/src/_private/SerwistError.ts +0 -43
  66. package/src/_private/assert.ts +0 -89
  67. package/src/_private/cacheMatchIgnoreParams.ts +0 -54
  68. package/src/_private/cacheNames.ts +0 -87
  69. package/src/_private/canConstructReadableStream.ts +0 -34
  70. package/src/_private/canConstructResponseFromBodyStream.ts +0 -37
  71. package/src/_private/dontWaitFor.ts +0 -16
  72. package/src/_private/executeQuotaErrorCallbacks.ts +0 -35
  73. package/src/_private/getFriendlyURL.ts +0 -16
  74. package/src/_private/logger.ts +0 -95
  75. package/src/_private/resultingClientExists.ts +0 -58
  76. package/src/_private/timeout.ts +0 -19
  77. package/src/_private/waitUntil.ts +0 -21
  78. package/src/cacheNames.ts +0 -41
  79. package/src/clientsClaim.ts +0 -20
  80. package/src/copyResponse.ts +0 -62
  81. package/src/models/messages/messageGenerator.ts +0 -29
  82. package/src/models/messages/messages.ts +0 -233
  83. package/src/models/pluginEvents.ts +0 -17
  84. package/src/models/quotaErrorCallbacks.ts +0 -13
  85. package/src/registerQuotaErrorCallback.ts +0 -36
  86. package/src/setCacheNameDetails.ts +0 -55
  87. package/src/types.ts +0 -322
  88. package/src/utils/pluginUtils.ts +0 -15
  89. package/src/utils/welcome.ts +0 -25
@@ -1,13 +0,0 @@
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 };
@@ -1,36 +0,0 @@
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 };
@@ -1,55 +0,0 @@
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 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 DELETED
@@ -1,322 +0,0 @@
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
- export type PromiseOrNot<T> = T | Promise<T>;
9
-
10
- export interface MapLikeObject {
11
- [key: string]: any;
12
- }
13
-
14
- /**
15
- * Using a plain `MapLikeObject` for now, but could extend/restrict this
16
- * in the future.
17
- */
18
- export type PluginState = MapLikeObject;
19
-
20
- /**
21
- * Options passed to a `RouteMatchCallback` function.
22
- */
23
- export interface RouteMatchCallbackOptions {
24
- event: ExtendableEvent;
25
- request: Request;
26
- sameOrigin: boolean;
27
- url: URL;
28
- }
29
-
30
- /**
31
- * The "match" callback is used to determine if a `Route` should apply for a
32
- * particular URL and request. When matching occurs in response to a fetch
33
- * event from the client, the `event` object is also supplied. However, since
34
- * the match callback can be invoked outside of a fetch event, matching logic
35
- * should not assume the `event` object will always be available.
36
- * If the match callback returns a truthy value, the matching route's
37
- * `RouteHandlerCallback` will be invoked immediately. If the value returned
38
- * is a non-empty array or object, that value will be set on the handler's
39
- * `options.params` argument.
40
- */
41
- export interface RouteMatchCallback {
42
- (options: RouteMatchCallbackOptions): any;
43
- }
44
-
45
- /**
46
- * Options passed to a `RouteHandlerCallback` function.
47
- */
48
- export declare interface RouteHandlerCallbackOptions {
49
- /**
50
- * The event associated with the request.
51
- */
52
- event: ExtendableEvent;
53
- /**
54
- * A request to run this strategy for.
55
- */
56
- request: Request;
57
- url: URL;
58
- /**
59
- * The return value from `@serwist/routing`'s `matchCallback` (if applicable).
60
- */
61
- params?: string[] | MapLikeObject;
62
- }
63
- /**
64
- * Options passed to a `ManualHandlerCallback` function.
65
- */
66
- export interface ManualHandlerCallbackOptions {
67
- /**
68
- * The event associated with the request.
69
- */
70
- event: ExtendableEvent;
71
- /**
72
- * A request to run this strategy for.
73
- */
74
- request: Request | string;
75
- }
76
-
77
- export type HandlerCallbackOptions = RouteHandlerCallbackOptions | ManualHandlerCallbackOptions;
78
-
79
- /**
80
- * The "handler" callback is invoked whenever a `Router` matches a URL/Request
81
- * to a `Route` via its `RouteMatchCallback`. This handler callback should
82
- * return a `Promise` that resolves with a `Response`.
83
- *
84
- * If a non-empty array or object is returned by the `RouteMatchCallback` it
85
- * will be passed in as this handler's `options.params` argument.
86
- */
87
- export interface RouteHandlerCallback {
88
- (options: RouteHandlerCallbackOptions): Promise<Response>;
89
- }
90
-
91
- /**
92
- * The "handler" callback is invoked whenever a `Router` matches a URL/Request
93
- * to a `Route` via its `RouteMatchCallback`. This handler callback should
94
- * return a `Promise` that resolves with a `Response`.
95
- *
96
- * If a non-empty array or object is returned by the `RouteMatchCallback` it
97
- * will be passed in as this handler's `options.params` argument.
98
- */
99
- export interface ManualHandlerCallback {
100
- (options: ManualHandlerCallbackOptions): Promise<Response>;
101
- }
102
-
103
- /**
104
- * An object with a `handle` method of type `RouteHandlerCallback`.
105
- *
106
- * A `Route` object can be created with either an `RouteHandlerCallback`
107
- * function or this `RouteHandler` object. The benefit of the `RouteHandler`
108
- * is it can be extended (as is done by the `@serwist/strategies` package).
109
- */
110
- export interface RouteHandlerObject {
111
- handle: RouteHandlerCallback;
112
- }
113
-
114
- /**
115
- * Either a `RouteHandlerCallback` or a `RouteHandlerObject`.
116
- * Most APIs in `@serwist/routing` that accept route handlers take either.
117
- */
118
- export type RouteHandler = RouteHandlerCallback | RouteHandlerObject;
119
-
120
- export interface HandlerWillStartCallbackParam {
121
- request: Request;
122
- event: ExtendableEvent;
123
- state?: PluginState;
124
- }
125
-
126
- export interface HandlerWillStartCallback {
127
- (param: HandlerWillStartCallbackParam): Promise<any>;
128
- }
129
-
130
- export interface CacheDidUpdateCallbackParam {
131
- /**
132
- * Name of the cache the responses belong to. This is included in the
133
- * broadcast message.
134
- */
135
- cacheName: string;
136
- /**
137
- * Possibly updated response to compare.
138
- */
139
- newResponse: Response;
140
- /**
141
- * The `Request` object for the cached entry.
142
- */
143
- request: Request;
144
- /**
145
- * The event that triggered this possible cache update.
146
- */
147
- event: ExtendableEvent;
148
- /**
149
- * Cached response to compare.
150
- */
151
- oldResponse?: Response | null;
152
- state?: PluginState;
153
- }
154
-
155
- export interface CacheDidUpdateCallback {
156
- (param: CacheDidUpdateCallbackParam): PromiseOrNot<any>;
157
- }
158
-
159
- export interface CacheKeyWillBeUsedCallbackParam {
160
- mode: string;
161
- request: Request;
162
- event: ExtendableEvent;
163
- params?: any;
164
- state?: PluginState;
165
- }
166
-
167
- export interface CacheKeyWillBeUsedCallback {
168
- (param: CacheKeyWillBeUsedCallbackParam): PromiseOrNot<Request | string>;
169
- }
170
-
171
- export interface CacheWillUpdateCallbackParam {
172
- request: Request;
173
- response: Response;
174
- event: ExtendableEvent;
175
- state?: PluginState;
176
- }
177
-
178
- export interface CacheWillUpdateCallback {
179
- (param: CacheWillUpdateCallbackParam): PromiseOrNot<any>;
180
- }
181
-
182
- export interface CachedResponseWillBeUsedCallbackParam {
183
- /**
184
- * Name of the cache the response is in.
185
- */
186
- cacheName: string;
187
- /**
188
- * The original request, which may or may not
189
- * contain a Range: header.
190
- */
191
- request: Request;
192
- /**
193
- * The complete cached `Response` object that's been read
194
- * from a cache and whose freshness should be checked.
195
- */
196
- cachedResponse?: Response;
197
- event: ExtendableEvent;
198
- matchOptions?: CacheQueryOptions;
199
- state?: PluginState;
200
- }
201
-
202
- export interface CachedResponseWillBeUsedCallback {
203
- (param: CachedResponseWillBeUsedCallbackParam): PromiseOrNot<any>;
204
- }
205
-
206
- export interface FetchDidFailCallbackParam {
207
- error: Error;
208
- originalRequest: Request;
209
- request: Request;
210
- event: ExtendableEvent;
211
- state?: PluginState;
212
- }
213
-
214
- export interface FetchDidFailCallback {
215
- (param: FetchDidFailCallbackParam): PromiseOrNot<any>;
216
- }
217
-
218
- export interface FetchDidSucceedCallbackParam {
219
- request: Request;
220
- response: Response;
221
- event: ExtendableEvent;
222
- state?: PluginState;
223
- }
224
-
225
- export interface FetchDidSucceedCallback {
226
- (param: FetchDidSucceedCallbackParam): PromiseOrNot<Response>;
227
- }
228
-
229
- export interface RequestWillFetchCallbackParam {
230
- request: Request;
231
- event: ExtendableEvent;
232
- state?: PluginState;
233
- }
234
-
235
- export interface RequestWillFetchCallback {
236
- (param: RequestWillFetchCallbackParam): PromiseOrNot<Request>;
237
- }
238
-
239
- export interface HandlerWillRespondCallbackParam {
240
- request: Request;
241
- response: Response;
242
- event: ExtendableEvent;
243
- state?: PluginState;
244
- }
245
-
246
- export interface HandlerWillRespondCallback {
247
- (param: HandlerWillRespondCallbackParam): PromiseOrNot<Response>;
248
- }
249
-
250
- export interface HandlerDidErrorCallbackParam {
251
- request: Request;
252
- event: ExtendableEvent;
253
- error: Error;
254
- state?: PluginState;
255
- }
256
-
257
- export interface HandlerDidErrorCallback {
258
- (param: HandlerDidErrorCallbackParam): PromiseOrNot<Response | undefined>;
259
- }
260
-
261
- export interface HandlerDidRespondCallbackParam {
262
- request: Request;
263
- event: ExtendableEvent;
264
- response?: Response;
265
- state?: PluginState;
266
- }
267
-
268
- export interface HandlerDidRespondCallback {
269
- (param: HandlerDidRespondCallbackParam): PromiseOrNot<any>;
270
- }
271
-
272
- export interface HandlerDidCompleteCallbackParam {
273
- request: Request;
274
- error?: Error;
275
- event: ExtendableEvent;
276
- response?: Response;
277
- state?: PluginState;
278
- }
279
-
280
- export interface HandlerDidCompleteCallback {
281
- (param: HandlerDidCompleteCallbackParam): PromiseOrNot<any>;
282
- }
283
-
284
- /**
285
- * An object with optional lifecycle callback properties for the fetch and
286
- * cache operations.
287
- */
288
- export declare interface SerwistPlugin {
289
- cacheDidUpdate?: CacheDidUpdateCallback;
290
- cachedResponseWillBeUsed?: CachedResponseWillBeUsedCallback;
291
- cacheKeyWillBeUsed?: CacheKeyWillBeUsedCallback;
292
- cacheWillUpdate?: CacheWillUpdateCallback;
293
- fetchDidFail?: FetchDidFailCallback;
294
- fetchDidSucceed?: FetchDidSucceedCallback;
295
- handlerDidComplete?: HandlerDidCompleteCallback;
296
- handlerDidError?: HandlerDidErrorCallback;
297
- handlerDidRespond?: HandlerDidRespondCallback;
298
- handlerWillRespond?: HandlerWillRespondCallback;
299
- handlerWillStart?: HandlerWillStartCallback;
300
- requestWillFetch?: RequestWillFetchCallback;
301
- }
302
-
303
- export interface SerwistPluginCallbackParam {
304
- cacheDidUpdate: CacheDidUpdateCallbackParam;
305
- cachedResponseWillBeUsed: CachedResponseWillBeUsedCallbackParam;
306
- cacheKeyWillBeUsed: CacheKeyWillBeUsedCallbackParam;
307
- cacheWillUpdate: CacheWillUpdateCallbackParam;
308
- fetchDidFail: FetchDidFailCallbackParam;
309
- fetchDidSucceed: FetchDidSucceedCallbackParam;
310
- handlerDidComplete: HandlerDidCompleteCallbackParam;
311
- handlerDidError: HandlerDidErrorCallbackParam;
312
- handlerDidRespond: HandlerDidRespondCallbackParam;
313
- handlerWillRespond: HandlerWillRespondCallbackParam;
314
- handlerWillStart: HandlerWillStartCallbackParam;
315
- requestWillFetch: RequestWillFetchCallbackParam;
316
- }
317
-
318
- export interface SerwistGlobalConfig {
319
- __WB_DISABLE_DEV_LOGS: boolean;
320
- __WB_FORCE_RUNTIME_CACHING: boolean;
321
- __WB_CONCURRENT_PRECACHING: number;
322
- }
@@ -1,15 +0,0 @@
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
- };
@@ -1,25 +0,0 @@
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
- }