itty-router 3.0.8 → 3.0.10
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/CHANGELOG.md +1 -0
- package/README.md +4 -10
- package/dist/itty-router.d.ts +20 -11
- package/dist/itty-router.js +1 -1
- package/dist/itty-router.mjs +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,7 @@ Until this library makes it to a production release of v1.x, **minor versions ma
|
|
|
3
3
|
|
|
4
4
|
[@SupremeTechnopriest)(https://github.com/SupremeTechnopriest) - improved TypeScript support and documentation! :D\
|
|
5
5
|
|
|
6
|
+
- **v3.0.9** - fixes some TS issue, previously requiring you to define Router Methods to chain request definitions. (credit [@jahands](https://github.com/jahands))
|
|
6
7
|
- **v3.0.0** - total TS conversion with improved types, adding greedy params (credit [@markusahlstrand](https://github.com/markusahlstrand))
|
|
7
8
|
- **v2.6.4** - merely a republish, attempting to solve NPM test scores vs CI/CD
|
|
8
9
|
- **v2.6.2** - fixes issue with using base path of "/" with route definitions starting with "/" (creating double slash)
|
package/README.md
CHANGED
|
@@ -421,13 +421,6 @@ import {
|
|
|
421
421
|
Route, // generic Route type
|
|
422
422
|
} from './itty-router'
|
|
423
423
|
|
|
424
|
-
// declare a custom Router type with used methods
|
|
425
|
-
interface CustomRouter extends RouterType {
|
|
426
|
-
all: Route,
|
|
427
|
-
get: Route,
|
|
428
|
-
puppy: Route,
|
|
429
|
-
}
|
|
430
|
-
|
|
431
424
|
// declare a custom Request type to allow request injection from middleware
|
|
432
425
|
type RequestWithAuthors = {
|
|
433
426
|
authors?: string[]
|
|
@@ -438,11 +431,11 @@ const withAuthors = (request: IRequest) => {
|
|
|
438
431
|
request.authors = ['foo', 'bar']
|
|
439
432
|
}
|
|
440
433
|
|
|
441
|
-
const router =
|
|
434
|
+
const router = Router({ base: '/' })
|
|
442
435
|
|
|
443
436
|
router
|
|
444
|
-
.all
|
|
445
|
-
.get
|
|
437
|
+
.all('*', () => {})
|
|
438
|
+
.get('/authors', withAuthors, (request: RequestWithAuthors) => {
|
|
446
439
|
return request.authors?.[0]
|
|
447
440
|
})
|
|
448
441
|
.puppy('*', (request) => {
|
|
@@ -483,6 +476,7 @@ These folks are the real heroes, making open source the powerhouse that it is!
|
|
|
483
476
|
- [@taralx](https://github.com/taralx) - QOL fixes for contributing (dev dep fix and test file consistency) <3
|
|
484
477
|
- [@technoyes](https://github.com/technoyes) - three kind-of-a-big-deal errors fixed. Imagine the look on my face... thanks man!! :)
|
|
485
478
|
- [@roojay520](https://github.com/roojay520) - TS interface fixes
|
|
479
|
+
- [@jahands](https://github.com/jahands) - v3.x TS fixes
|
|
486
480
|
#### Documentation
|
|
487
481
|
- [@arunsathiya](https://github.com/arunsathiya),
|
|
488
482
|
[@poacher2k](https://github.com/poacher2k),
|
package/dist/itty-router.d.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
declare type GenericTraps = {
|
|
2
2
|
[key: string]: any;
|
|
3
3
|
};
|
|
4
|
+
declare type RequestLike = {
|
|
5
|
+
method: string;
|
|
6
|
+
url: string;
|
|
7
|
+
} & GenericTraps;
|
|
4
8
|
declare type IRequest = {
|
|
5
9
|
method: string;
|
|
6
10
|
url: string;
|
|
7
|
-
params:
|
|
8
|
-
|
|
11
|
+
params: {
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
};
|
|
14
|
+
query: {
|
|
15
|
+
[key: string]: string | undefined;
|
|
16
|
+
};
|
|
17
|
+
proxy?: any;
|
|
9
18
|
} & GenericTraps;
|
|
10
19
|
interface RouterOptions {
|
|
11
20
|
base?: string;
|
|
@@ -17,19 +26,19 @@ interface RouteHandler {
|
|
|
17
26
|
declare type RouteEntry = [string, RegExp, RouteHandler[]];
|
|
18
27
|
declare type Route = <T extends RouterType>(path: string, ...handlers: RouteHandler[]) => T;
|
|
19
28
|
declare type RouterHints = {
|
|
20
|
-
all
|
|
21
|
-
delete
|
|
22
|
-
get
|
|
23
|
-
options
|
|
24
|
-
patch
|
|
25
|
-
post
|
|
26
|
-
put
|
|
29
|
+
all: Route;
|
|
30
|
+
delete: Route;
|
|
31
|
+
get: Route;
|
|
32
|
+
options: Route;
|
|
33
|
+
patch: Route;
|
|
34
|
+
post: Route;
|
|
35
|
+
put: Route;
|
|
27
36
|
};
|
|
28
37
|
declare type RouterType = {
|
|
29
38
|
__proto__: RouterType;
|
|
30
39
|
routes: RouteEntry[];
|
|
31
|
-
handle: (request:
|
|
40
|
+
handle: (request: RequestLike, ...extra: any) => Promise<any>;
|
|
32
41
|
} & RouterHints;
|
|
33
42
|
declare const Router: ({ base, routes }?: RouterOptions) => RouterType;
|
|
34
43
|
|
|
35
|
-
export { GenericTraps, IRequest, Route, RouteEntry, RouteHandler, Router, RouterHints, RouterOptions, RouterType };
|
|
44
|
+
export { GenericTraps, IRequest, RequestLike, Route, RouteEntry, RouteHandler, Router, RouterHints, RouterOptions, RouterType };
|
package/dist/itty-router.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var x=(r,e)=>{for(var t in e)s(r,t,{get:e[t],enumerable:!0})},h=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of g(e))!d.call(r,o)&&o!==t&&s(r,o,{get:()=>e[o],enumerable:!(n=l(e,o))||n.enumerable});return r};var f=r=>h(s({},"__esModule",{value:!0}),r);var $={};x($,{Router:()=>T});module.exports=f($);var m=r=>[...r.entries()].reduce((e,[t,n])=>(e[t]===void 0?e[t]=n:e[t]=[e[t],n].flat())&&e||e,{}),T=({base:r="",routes:e=[]}={})=>({__proto__:new Proxy({},{get:(t,n,o)=>(p,...a)=>e.push([n.toUpperCase(),RegExp(`^${(r+p).replace(/(\/?)\*/g,"($1.*)?").replace(/(\/$)|((?<=\/)\/)/,"").replace(/(:(\w+)\+)/,"(?<$2>.*)").replace(/:(\w+)(\?)?(\.)?/g,"$2(?<$1>[^/]+)$2$3").replace(/\.(?=[\w(])/,"\\.").replace(/\)\.\?\(([^\[]+)\[\^/g,"?)\\.?($1(?<=\\.)[^\\.")}/*$`),a])&&o}),routes:e,async handle(t,...n){let o,p,a=new URL(t.url);t.query=m(a.searchParams);for(let[u,i,R]of e)if((u===t.method||u==="ALL")&&(p=a.pathname.match(i))){t.params=p.groups||{};for(let y of R)if((o=await y(t.proxy||t,...n))!==void 0)return o}}});0&&(module.exports={Router});
|
package/dist/itty-router.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var y=a=>[...a.entries()].reduce((t,[e,r])=>(t[e]===void 0?t[e]=r:t[e]=[t[e],r].flat())&&t||t,{}),l=({base:a="",routes:t=[]}={})=>({__proto__:new Proxy({},{get:(e,r,o)=>(n,...p)=>t.push([r.toUpperCase(),RegExp(`^${(a+n).replace(/(\/?)\*/g,"($1.*)?").replace(/(\/$)|((?<=\/)\/)/,"").replace(/(:(\w+)\+)/,"(?<$2>.*)").replace(/:(\w+)(\?)?(\.)?/g,"$2(?<$1>[^/]+)$2$3").replace(/\.(?=[\w(])/,"\\.").replace(/\)\.\?\(([^\[]+)\[\^/g,"?)\\.?($1(?<=\\.)[^\\.")}/*$`),p])&&o}),routes:t,async handle(e,...r){let o,n,p=new URL(e.url);e.query=y(p.searchParams);for(let[s,u,i]of t)if((s===e.method||s==="ALL")&&(n=p.pathname.match(u))){e.params=n.groups||{};for(let R of i)if((o=await R(e.proxy||e,...r))!==void 0)return o}}});export{l as Router};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "itty-router",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.10",
|
|
4
4
|
"description": "Tiny, zero-dependency API router - built for Cloudflare Workers, but works everywhere!",
|
|
5
5
|
"sourceType": "module",
|
|
6
6
|
"main": "./dist/itty-router.js",
|
|
@@ -42,7 +42,6 @@
|
|
|
42
42
|
"prerelease": "yarn verify",
|
|
43
43
|
"prebuild": "rimraf dist && mkdir dist",
|
|
44
44
|
"build": "tsup src/itty-router.ts --format cjs,esm --dts --minify --clean",
|
|
45
|
-
"postbuild": "node check-size.js",
|
|
46
45
|
"release": "release --tag --push --patch",
|
|
47
46
|
"prerelease:next": "yarn verify",
|
|
48
47
|
"release:next": "release --push --type=next"
|
|
@@ -58,6 +57,7 @@
|
|
|
58
57
|
},
|
|
59
58
|
"homepage": "https://itty-router.dev",
|
|
60
59
|
"devDependencies": {
|
|
60
|
+
"@cloudflare/workers-types": "^4.20221111.1",
|
|
61
61
|
"@vitejs/plugin-vue": "^2.2.4",
|
|
62
62
|
"@vitest/coverage-c8": "^0.24.3",
|
|
63
63
|
"coveralls": "^3.1.1",
|