@serwist/core 9.0.0-preview.21 → 9.0.0-preview.25

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 +2 -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 +1 -92
  8. package/package.json +10 -7
  9. package/src/index.internal.ts +4 -21
  10. package/src/index.ts +42 -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 -24
  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 -8
  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 -20
  40. package/dist/cacheNames.d.ts.map +0 -1
  41. package/dist/chunks/quotaErrorCallbacks.js +0 -355
  42. package/dist/clientsClaim.d.ts +0 -6
  43. package/dist/clientsClaim.d.ts.map +0 -1
  44. package/dist/copyResponse.d.ts +0 -20
  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 -8
  55. package/dist/registerQuotaErrorCallback.d.ts.map +0 -1
  56. package/dist/setCacheNameDetails.d.ts +0 -9
  57. package/dist/setCacheNameDetails.d.ts.map +0 -1
  58. package/dist/types.d.ts +0 -257
  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 -41
  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 -33
  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 -39
  79. package/src/clientsClaim.ts +0 -18
  80. package/src/copyResponse.ts +0 -60
  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 -34
  86. package/src/setCacheNameDetails.ts +0 -53
  87. package/src/types.ts +0 -300
  88. package/src/utils/pluginUtils.ts +0 -15
  89. package/src/utils/welcome.ts +0 -24
@@ -1,34 +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
- export const 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
- };
@@ -1,53 +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
- export const 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
- };
package/src/types.ts DELETED
@@ -1,300 +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 type RouteMatchCallback = (options: RouteMatchCallbackOptions) => any;
42
-
43
- /**
44
- * Options passed to a `RouteHandlerCallback` function.
45
- */
46
- export interface RouteHandlerCallbackOptions {
47
- /**
48
- * The event associated with the request.
49
- */
50
- event: ExtendableEvent;
51
- /**
52
- * A request to run this strategy for.
53
- */
54
- request: Request;
55
- url: URL;
56
- /**
57
- * The return value from `@serwist/routing`'s `matchCallback` (if applicable).
58
- */
59
- params?: string[] | MapLikeObject;
60
- }
61
- /**
62
- * Options passed to a `ManualHandlerCallback` function.
63
- */
64
- export interface ManualHandlerCallbackOptions {
65
- /**
66
- * The event associated with the request.
67
- */
68
- event: ExtendableEvent;
69
- /**
70
- * A request to run this strategy for.
71
- */
72
- request: Request | string;
73
- url?: never;
74
- /**
75
- * The return value from `@serwist/routing`'s `matchCallback` (if applicable).
76
- */
77
- params?: never;
78
- }
79
-
80
- export type HandlerCallbackOptions = RouteHandlerCallbackOptions | ManualHandlerCallbackOptions;
81
-
82
- /**
83
- * The "handler" callback is invoked whenever a `Router` matches a URL/Request
84
- * to a `Route` via its `RouteMatchCallback`. This handler callback should
85
- * return a `Promise` that resolves with a `Response`.
86
- *
87
- * If a non-empty array or object is returned by the `RouteMatchCallback` it
88
- * will be passed in as this handler's `options.params` argument.
89
- */
90
- export type RouteHandlerCallback = (options: RouteHandlerCallbackOptions) => Promise<Response>;
91
-
92
- /**
93
- * The "handler" callback is invoked whenever a `Router` matches a URL/Request
94
- * to a `Route` via its `RouteMatchCallback`. This handler callback should
95
- * return a `Promise` that resolves with a `Response`.
96
- *
97
- * If a non-empty array or object is returned by the `RouteMatchCallback` it
98
- * will be passed in as this handler's `options.params` argument.
99
- */
100
- export type ManualHandlerCallback = (options: ManualHandlerCallbackOptions) => Promise<Response>;
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 type HandlerWillStartCallback = (param: HandlerWillStartCallbackParam) => Promise<any>;
126
-
127
- export interface CacheDidUpdateCallbackParam {
128
- /**
129
- * Name of the cache the responses belong to. This is included in the
130
- * broadcast message.
131
- */
132
- cacheName: string;
133
- /**
134
- * Possibly updated response to compare.
135
- */
136
- newResponse: Response;
137
- /**
138
- * The `Request` object for the cached entry.
139
- */
140
- request: Request;
141
- /**
142
- * The event that triggered this possible cache update.
143
- */
144
- event: ExtendableEvent;
145
- /**
146
- * Cached response to compare.
147
- */
148
- oldResponse?: Response | null;
149
- state?: PluginState;
150
- }
151
-
152
- export type CacheDidUpdateCallback = (param: CacheDidUpdateCallbackParam) => PromiseOrNot<any>;
153
-
154
- export interface CacheKeyWillBeUsedCallbackParam {
155
- mode: string;
156
- request: Request;
157
- event: ExtendableEvent;
158
- params?: any;
159
- state?: PluginState;
160
- }
161
-
162
- export type CacheKeyWillBeUsedCallback = (param: CacheKeyWillBeUsedCallbackParam) => PromiseOrNot<Request | string>;
163
-
164
- export interface CacheWillUpdateCallbackParam {
165
- request: Request;
166
- response: Response;
167
- event: ExtendableEvent;
168
- state?: PluginState;
169
- }
170
-
171
- export type CacheWillUpdateCallback = (param: CacheWillUpdateCallbackParam) => PromiseOrNot<any>;
172
-
173
- export interface CachedResponseWillBeUsedCallbackParam {
174
- /**
175
- * Name of the cache the response is in.
176
- */
177
- cacheName: string;
178
- /**
179
- * The original request, which may or may not
180
- * contain a Range: header.
181
- */
182
- request: Request;
183
- /**
184
- * The complete cached `Response` object that's been read
185
- * from a cache and whose freshness should be checked.
186
- */
187
- cachedResponse?: Response;
188
- event: ExtendableEvent;
189
- matchOptions?: CacheQueryOptions;
190
- state?: PluginState;
191
- }
192
-
193
- export type CachedResponseWillBeUsedCallback = (param: CachedResponseWillBeUsedCallbackParam) => PromiseOrNot<any>;
194
-
195
- export interface FetchDidFailCallbackParam {
196
- error: Error;
197
- originalRequest: Request;
198
- request: Request;
199
- event: ExtendableEvent;
200
- state?: PluginState;
201
- }
202
-
203
- export type FetchDidFailCallback = (param: FetchDidFailCallbackParam) => PromiseOrNot<any>;
204
-
205
- export interface FetchDidSucceedCallbackParam {
206
- request: Request;
207
- response: Response;
208
- event: ExtendableEvent;
209
- state?: PluginState;
210
- }
211
-
212
- export type FetchDidSucceedCallback = (param: FetchDidSucceedCallbackParam) => PromiseOrNot<Response>;
213
-
214
- export interface RequestWillFetchCallbackParam {
215
- request: Request;
216
- event: ExtendableEvent;
217
- state?: PluginState;
218
- }
219
-
220
- export type RequestWillFetchCallback = (param: RequestWillFetchCallbackParam) => PromiseOrNot<Request>;
221
-
222
- export interface HandlerWillRespondCallbackParam {
223
- request: Request;
224
- response: Response;
225
- event: ExtendableEvent;
226
- state?: PluginState;
227
- }
228
-
229
- export type HandlerWillRespondCallback = (param: HandlerWillRespondCallbackParam) => PromiseOrNot<Response>;
230
-
231
- export interface HandlerDidErrorCallbackParam {
232
- request: Request;
233
- event: ExtendableEvent;
234
- error: Error;
235
- state?: PluginState;
236
- }
237
-
238
- export type HandlerDidErrorCallback = (param: HandlerDidErrorCallbackParam) => PromiseOrNot<Response | undefined>;
239
-
240
- export interface HandlerDidRespondCallbackParam {
241
- request: Request;
242
- event: ExtendableEvent;
243
- response?: Response;
244
- state?: PluginState;
245
- }
246
-
247
- export type HandlerDidRespondCallback = (param: HandlerDidRespondCallbackParam) => PromiseOrNot<any>;
248
-
249
- export interface HandlerDidCompleteCallbackParam {
250
- request: Request;
251
- error?: Error;
252
- event: ExtendableEvent;
253
- response?: Response;
254
- state?: PluginState;
255
- }
256
-
257
- export type HandlerDidCompleteCallback = (param: HandlerDidCompleteCallbackParam) => PromiseOrNot<any>;
258
-
259
- /**
260
- * An object with optional lifecycle callback properties for the fetch and
261
- * cache operations.
262
- */
263
- export declare interface SerwistPlugin {
264
- cacheDidUpdate?: CacheDidUpdateCallback;
265
- cachedResponseWillBeUsed?: CachedResponseWillBeUsedCallback;
266
- cacheKeyWillBeUsed?: CacheKeyWillBeUsedCallback;
267
- cacheWillUpdate?: CacheWillUpdateCallback;
268
- fetchDidFail?: FetchDidFailCallback;
269
- fetchDidSucceed?: FetchDidSucceedCallback;
270
- handlerDidComplete?: HandlerDidCompleteCallback;
271
- handlerDidError?: HandlerDidErrorCallback;
272
- handlerDidRespond?: HandlerDidRespondCallback;
273
- handlerWillRespond?: HandlerWillRespondCallback;
274
- handlerWillStart?: HandlerWillStartCallback;
275
- requestWillFetch?: RequestWillFetchCallback;
276
- }
277
-
278
- export interface SerwistPluginCallbackParam {
279
- cacheDidUpdate: CacheDidUpdateCallbackParam;
280
- cachedResponseWillBeUsed: CachedResponseWillBeUsedCallbackParam;
281
- cacheKeyWillBeUsed: CacheKeyWillBeUsedCallbackParam;
282
- cacheWillUpdate: CacheWillUpdateCallbackParam;
283
- fetchDidFail: FetchDidFailCallbackParam;
284
- fetchDidSucceed: FetchDidSucceedCallbackParam;
285
- handlerDidComplete: HandlerDidCompleteCallbackParam;
286
- handlerDidError: HandlerDidErrorCallbackParam;
287
- handlerDidRespond: HandlerDidRespondCallbackParam;
288
- handlerWillRespond: HandlerWillRespondCallbackParam;
289
- handlerWillStart: HandlerWillStartCallbackParam;
290
- requestWillFetch: RequestWillFetchCallbackParam;
291
- }
292
-
293
- export interface SerwistGlobalConfig {
294
- /**
295
- * Whether Serwist should disable development logging.
296
- *
297
- * @default false
298
- */
299
- __WB_DISABLE_DEV_LOGS: boolean;
300
- }
@@ -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,24 +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(`🐛 Found a bug or want to ask a question? Open a new issue on GitLab\n${padding}https://gitlab.com/serwist/serwist/issues/new`);
23
- logger.groupEnd();
24
- }