@jon49/sw 0.14.8 → 0.15.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.
- package/bin/lib/file-mapper.ts +1 -1
- package/lib/routes.middleware.ts +15 -9
- package/package.json +1 -1
package/bin/lib/file-mapper.ts
CHANGED
|
@@ -59,7 +59,7 @@ export async function fileMapper(targetDirectory: string, force = false) {
|
|
|
59
59
|
|
|
60
60
|
fileMapJsonContent = `${fileMapJsonContent.slice(0, -1)},{"url":"/web/file-map.js","file":"${fileMapUrl}"}]`
|
|
61
61
|
|
|
62
|
-
let fileMapContent = `(() => { self.
|
|
62
|
+
let fileMapContent = `(() => { self.sw = { links: ${fileMapJsonContent} } })()`
|
|
63
63
|
await write(`${targetDirectory}${fileMapUrl}`, fileMapContent)
|
|
64
64
|
|
|
65
65
|
let globalFiles =
|
package/lib/routes.middleware.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { isHtml } from "./utils.js"
|
|
|
3
3
|
|
|
4
4
|
let { links, globalDb } =
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
self.
|
|
6
|
+
self.sw as { links: { file: string, url: string }[], html: Function, db: any, globalDb: any }
|
|
7
7
|
|
|
8
8
|
if (!links) {
|
|
9
|
-
console.error("Expecting links defined with `self.
|
|
9
|
+
console.error("Expecting links defined with `self.sw.links`, but found none.")
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
function redirect(req: Request) {
|
|
@@ -66,12 +66,12 @@ export async function findRoute(url: URL, method: unknown) {
|
|
|
66
66
|
let validMethod: MethodTypes = isMethod(method)
|
|
67
67
|
if (validMethod) {
|
|
68
68
|
// @ts-ignore
|
|
69
|
-
if (!self.
|
|
70
|
-
console.error("Expecting routes defined with `self.
|
|
69
|
+
if (!self.sw?.routes) {
|
|
70
|
+
console.error("Expecting routes defined with `self.sw.routes`, but found none.")
|
|
71
71
|
return null
|
|
72
72
|
}
|
|
73
73
|
// @ts-ignore
|
|
74
|
-
for (const r of self.
|
|
74
|
+
for (const r of self.sw.routes) {
|
|
75
75
|
// @ts-ignore
|
|
76
76
|
if (r.file
|
|
77
77
|
&& (r.route instanceof RegExp && r.route.test(url.pathname)
|
|
@@ -262,8 +262,8 @@ async function cacheResponse(url: string, req?: Request | undefined): Promise<Re
|
|
|
262
262
|
if (!res || res.status !== 200 || res.type !== "basic") return res
|
|
263
263
|
const responseToCache = res.clone()
|
|
264
264
|
// @ts-ignore
|
|
265
|
-
let version: string = self.
|
|
266
|
-
?? (console.warn("The version number is not available, expected glboal value `self.
|
|
265
|
+
let version: string = self.sw?.version
|
|
266
|
+
?? (console.warn("The version number is not available, expected glboal value `self.sw.version`."), "")
|
|
267
267
|
const cache = await caches.open(version)
|
|
268
268
|
cache.put(url, responseToCache)
|
|
269
269
|
return res
|
|
@@ -290,14 +290,20 @@ export interface RouteObjectReturn {
|
|
|
290
290
|
json?: any
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
export
|
|
293
|
+
export type RouteHandler<T> = {
|
|
294
294
|
(options: T): Promise<
|
|
295
295
|
AsyncGenerator
|
|
296
296
|
| Response
|
|
297
297
|
| RouteObjectReturn
|
|
298
298
|
| undefined
|
|
299
299
|
| null
|
|
300
|
-
| void>
|
|
300
|
+
| void> | (
|
|
301
|
+
AsyncGenerator
|
|
302
|
+
| Response
|
|
303
|
+
| RouteObjectReturn
|
|
304
|
+
| undefined
|
|
305
|
+
| null
|
|
306
|
+
| void)
|
|
301
307
|
}
|
|
302
308
|
|
|
303
309
|
export interface RoutePostHandler {
|