@serwist/routing 8.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.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/NavigationRoute.d.ts +58 -0
- package/dist/NavigationRoute.d.ts.map +1 -0
- package/dist/RegExpRoute.d.ts +25 -0
- package/dist/RegExpRoute.d.ts.map +1 -0
- package/dist/Route.d.ts +34 -0
- package/dist/Route.d.ts.map +1 -0
- package/dist/Router.d.ts +125 -0
- package/dist/Router.d.ts.map +1 -0
- package/dist/_types.d.ts +48 -0
- package/dist/_types.d.ts.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +721 -0
- package/dist/index.old.cjs +729 -0
- package/dist/registerRoute.d.ts +16 -0
- package/dist/registerRoute.d.ts.map +1 -0
- package/dist/setCatchHandler.d.ts +10 -0
- package/dist/setCatchHandler.d.ts.map +1 -0
- package/dist/setDefaultHandler.d.ts +13 -0
- package/dist/setDefaultHandler.d.ts.map +1 -0
- package/dist/utils/constants.d.ts +19 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/getOrCreateDefaultRouter.d.ts +10 -0
- package/dist/utils/getOrCreateDefaultRouter.d.ts.map +1 -0
- package/dist/utils/normalizeHandler.d.ts +10 -0
- package/dist/utils/normalizeHandler.d.ts.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RouteHandler, RouteMatchCallback } from "@serwist/core";
|
|
2
|
+
import { Route } from "./Route.js";
|
|
3
|
+
import type { HTTPMethod } from "./utils/constants.js";
|
|
4
|
+
/**
|
|
5
|
+
* Easily register a RegExp, string, or function with a caching
|
|
6
|
+
* strategy to a singleton Router instance.
|
|
7
|
+
*
|
|
8
|
+
* @param capture If the capture param is a `Route`, all other arguments will be ignored.
|
|
9
|
+
* @param handler A callback function that returns a Promise resulting in a Response.
|
|
10
|
+
* This parameter is required if `capture` is not a `Route` object.
|
|
11
|
+
* @param method The HTTP method to match the Route against. Defaults to GET.
|
|
12
|
+
* @returns The generated `Route`.
|
|
13
|
+
*/
|
|
14
|
+
declare function registerRoute(capture: RegExp | string | RouteMatchCallback | Route, handler?: RouteHandler, method?: HTTPMethod): Route;
|
|
15
|
+
export { registerRoute };
|
|
16
|
+
//# sourceMappingURL=registerRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerRoute.d.ts","sourceRoot":"","sources":["../src/registerRoute.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAItE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGvD;;;;;;;;;GASG;AACH,iBAAS,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,kBAAkB,GAAG,KAAK,EAAE,OAAO,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,KAAK,CAkEhI;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RouteHandler } from "@serwist/core";
|
|
2
|
+
/**
|
|
3
|
+
* If a Route throws an error while handling a request, this `handler`
|
|
4
|
+
* will be called and given a chance to provide a response.
|
|
5
|
+
*
|
|
6
|
+
* @param handler A callback function that returns a Promise resulting in a Response.
|
|
7
|
+
*/
|
|
8
|
+
declare function setCatchHandler(handler: RouteHandler): void;
|
|
9
|
+
export { setCatchHandler };
|
|
10
|
+
//# sourceMappingURL=setCatchHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setCatchHandler.d.ts","sourceRoot":"","sources":["../src/setCatchHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAIlD;;;;;GAKG;AACH,iBAAS,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAGpD;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RouteHandler } from "@serwist/core";
|
|
2
|
+
/**
|
|
3
|
+
* Define a default `handler` that's called when no routes explicitly
|
|
4
|
+
* match the incoming request.
|
|
5
|
+
*
|
|
6
|
+
* Without a default handler, unmatched requests will go against the
|
|
7
|
+
* network as if there were no service worker present.
|
|
8
|
+
*
|
|
9
|
+
* @param handler A callback function that returns a Promise resulting in a Response.
|
|
10
|
+
*/
|
|
11
|
+
declare function setDefaultHandler(handler: RouteHandler): void;
|
|
12
|
+
export { setDefaultHandler };
|
|
13
|
+
//# sourceMappingURL=setDefaultHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setDefaultHandler.d.ts","sourceRoot":"","sources":["../src/setDefaultHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAIlD;;;;;;;;GAQG;AACH,iBAAS,iBAAiB,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAGtD;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type HTTPMethod = "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT";
|
|
2
|
+
/**
|
|
3
|
+
* The default HTTP method, 'GET', used when there's no specific method
|
|
4
|
+
* configured for a route.
|
|
5
|
+
*
|
|
6
|
+
* @type {string}
|
|
7
|
+
*
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
export declare const defaultMethod: HTTPMethod;
|
|
11
|
+
/**
|
|
12
|
+
* The list of valid HTTP methods associated with requests that could be routed.
|
|
13
|
+
*
|
|
14
|
+
* @type {Array<string>}
|
|
15
|
+
*
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
export declare const validMethods: HTTPMethod[];
|
|
19
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAE9E;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,UAAkB,CAAC;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,EAAE,UAAU,EAAsD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Router } from "../Router.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new, singleton Router instance if one does not exist. If one
|
|
4
|
+
* does already exist, that instance is returned.
|
|
5
|
+
*
|
|
6
|
+
* @private
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const getOrCreateDefaultRouter: () => Router;
|
|
10
|
+
//# sourceMappingURL=getOrCreateDefaultRouter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOrCreateDefaultRouter.d.ts","sourceRoot":"","sources":["../../src/utils/getOrCreateDefaultRouter.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,QAAO,MAS3C,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RouteHandler, RouteHandlerObject } from "@serwist/core";
|
|
2
|
+
/**
|
|
3
|
+
* @param handler Either a function, or an object with a
|
|
4
|
+
* 'handle' method.
|
|
5
|
+
* @returns An object with a handle method.
|
|
6
|
+
*
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
export declare const normalizeHandler: (handler: RouteHandler) => RouteHandlerObject;
|
|
10
|
+
//# sourceMappingURL=normalizeHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeHandler.d.ts","sourceRoot":"","sources":["../../src/utils/normalizeHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGtE;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,YAAa,YAAY,KAAG,kBAsBxD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@serwist/routing",
|
|
3
|
+
"version": "8.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A service worker helper library to route request URLs to handlers.",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"!dist/**/dts"
|
|
9
|
+
],
|
|
10
|
+
"keywords": [
|
|
11
|
+
"serwist",
|
|
12
|
+
"serwistjs",
|
|
13
|
+
"service worker",
|
|
14
|
+
"sw",
|
|
15
|
+
"router",
|
|
16
|
+
"routing"
|
|
17
|
+
],
|
|
18
|
+
"author": "Google's Web DevRel Team, Serwist's Team",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": "serwist/serwist",
|
|
21
|
+
"bugs": "https://github.com/serwist/serwist/issues",
|
|
22
|
+
"homepage": "https://ducanh-next-pwa.vercel.app",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"main": "./dist/index.old.cjs",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"require": "./dist/index.old.cjs",
|
|
30
|
+
"types": "./dist/index.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@serwist/core": "8.0.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"rollup": "3.28.1",
|
|
39
|
+
"@serwist/constants": "8.0.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "rimraf dist && cross-env NODE_ENV=production rollup --config rollup.config.js",
|
|
43
|
+
"lint": "eslint src --ext ts,tsx,js,jsx,cjs,mjs",
|
|
44
|
+
"typecheck": "tsc"
|
|
45
|
+
}
|
|
46
|
+
}
|