itty-router 3.0.10 → 3.0.11

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 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.11** - changed environment build to rollup (from tsup) and code golfed the toQuery logic. (credit [@DrLoopFall](https://github.com/DrLoopFall))
6
7
  - **v3.0.9** - fixes some TS issue, previously requiring you to define Router Methods to chain request definitions. (credit [@jahands](https://github.com/jahands))
7
8
  - **v3.0.0** - total TS conversion with improved types, adding greedy params (credit [@markusahlstrand](https://github.com/markusahlstrand))
8
9
  - **v2.6.4** - merely a republish, attempting to solve NPM test scores vs CI/CD
package/README.md CHANGED
@@ -29,7 +29,8 @@ Here are the major changes in version 3, with `itty-router-extras` (certainly) a
29
29
  ```js
30
30
  router.handle('/foo', ({ query }) => query)
31
31
 
32
- // GET /foo?pets=mittens&pets=fluffy&pets=rex&bar=baz => { bar: "baz", pets: ["mittens", "fluffy", "rex"] }
32
+ // GET /foo?pets=mittens&pets=fluffy&pets=rex&bar=baz
33
+ // ==> { bar: "baz", pets: ["mittens", "fluffy", "rex"] }
33
34
  ```
34
35
 
35
36
  ### Addons & Related Libraries
@@ -38,7 +39,7 @@ Here are the major changes in version 3, with `itty-router-extras` (certainly) a
38
39
  2. [itty-durable](https://www.npmjs.com/package/itty-durable) - creates a more direct object-like API for interacting with [Cloudflare Durable Objects](https://developers.cloudflare.com/workers/learning/using-durable-objects).
39
40
 
40
41
  ## Features
41
- - [x] Tiny ([~780 bytes](https://bundlephobia.com/package/itty-router) compressed), with zero dependencies.
42
+ - [x] Tiny ([~550 bytes](https://bundlephobia.com/package/itty-router) compressed), with zero dependencies.
42
43
  - [x] [Fully typed/TypeScript support](#typescript)
43
44
  - [x] Supports sync/async handlers/middleware.
44
45
  - [x] Parses route params, with wildcards and optionals (e.g. `/api/:collection/:id?`)
@@ -467,12 +468,14 @@ This trick allows methods (e.g. "get", "post") to by defined dynamically by the
467
468
  ## Contributors
468
469
  These folks are the real heroes, making open source the powerhouse that it is! Help out and get your name added to this list! <3
469
470
 
470
- #### Core, Concepts, and Codebase
471
+ #### Core Concepts
471
472
  - [@mvasigh](https://github.com/mvasigh) - proxy hack wizard behind itty, coding partner in crime, maker of the entire doc site, etc, etc.
472
- - [@taralx](https://github.com/taralx) - router internal code-golfing refactor for performance and character savings
473
473
  - [@hunterloftis](https://github.com/hunterloftis) - router.handle() method now accepts extra arguments and passed them to route functions
474
474
  - [@SupremeTechnopriest](https://github.com/SupremeTechnopriest) - improved TypeScript support and documentation! :D
475
- #### Fixes
475
+ #### Code Golfing
476
+ - [@taralx](https://github.com/taralx) - router internal code-golfing refactor for performance and character savings
477
+ - [@DrLoopFall](https://github.com/DrLoopFall) - v3.x re-minification
478
+ #### Fixes & Build
476
479
  - [@taralx](https://github.com/taralx) - QOL fixes for contributing (dev dep fix and test file consistency) <3
477
480
  - [@technoyes](https://github.com/technoyes) - three kind-of-a-big-deal errors fixed. Imagine the look on my face... thanks man!! :)
478
481
  - [@roojay520](https://github.com/roojay520) - TS interface fixes
@@ -1,31 +1,31 @@
1
- declare type GenericTraps = {
1
+ export declare type GenericTraps = {
2
2
  [key: string]: any;
3
3
  };
4
- declare type RequestLike = {
4
+ export declare type RequestLike = {
5
5
  method: string;
6
6
  url: string;
7
7
  } & GenericTraps;
8
- declare type IRequest = {
8
+ export declare type IRequest = {
9
9
  method: string;
10
10
  url: string;
11
11
  params: {
12
12
  [key: string]: string;
13
13
  };
14
14
  query: {
15
- [key: string]: string | undefined;
15
+ [key: string]: string | string[] | undefined;
16
16
  };
17
17
  proxy?: any;
18
18
  } & GenericTraps;
19
- interface RouterOptions {
19
+ export interface RouterOptions {
20
20
  base?: string;
21
21
  routes?: RouteEntry[];
22
22
  }
23
- interface RouteHandler {
23
+ export interface RouteHandler {
24
24
  (request: IRequest, ...args: any): any;
25
25
  }
26
- declare type RouteEntry = [string, RegExp, RouteHandler[]];
27
- declare type Route = <T extends RouterType>(path: string, ...handlers: RouteHandler[]) => T;
28
- declare type RouterHints = {
26
+ export declare type RouteEntry = [string, RegExp, RouteHandler[]];
27
+ export declare type Route = <T extends RouterType>(path: string, ...handlers: RouteHandler[]) => T;
28
+ export declare type RouterHints = {
29
29
  all: Route;
30
30
  delete: Route;
31
31
  get: Route;
@@ -34,11 +34,9 @@ declare type RouterHints = {
34
34
  post: Route;
35
35
  put: Route;
36
36
  };
37
- declare type RouterType = {
37
+ export declare type RouterType = {
38
38
  __proto__: RouterType;
39
39
  routes: RouteEntry[];
40
40
  handle: (request: RequestLike, ...extra: any) => Promise<any>;
41
41
  } & RouterHints;
42
- declare const Router: ({ base, routes }?: RouterOptions) => RouterType;
43
-
44
- export { GenericTraps, IRequest, RequestLike, Route, RouteEntry, RouteHandler, Router, RouterHints, RouterOptions, RouterType };
42
+ export declare const Router: ({ base, routes }?: RouterOptions) => RouterType;
@@ -1 +1 @@
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});
1
+ "use strict";exports.Router=({base:e="",routes:r=[]}={})=>({__proto__:new Proxy({},{get:(a,o,t)=>(a,...p)=>r.push([o.toUpperCase(),RegExp(`^${(e+a).replace(/(\/?)\*/g,"($1.*)?").replace(/(\/$)|((?<=\/)\/)/,"").replace(/(:(\w+)\+)/,"(?<$2>.*)").replace(/:(\w+)(\?)?(\.)?/g,"$2(?<$1>[^/]+)$2$3").replace(/\.(?=[\w(])/,"\\.").replace(/\)\.\?\(([^\[]+)\[\^/g,"?)\\.?($1(?<=\\.)[^\\.")}/*$`),p])&&t}),routes:r,async handle(e,...a){let o,t,p=new URL(e.url),l=e.query={};for(let[e,r]of p.searchParams)l[e]=void 0===l[e]?r:[l[e],r].flat();for(let[l,s,c]of r)if((l===e.method||"ALL"===l)&&(t=p.pathname.match(s))){e.params=t.groups||{};for(let r of c)if(void 0!==(o=await r(e.proxy||e,...a)))return o}}});
@@ -1 +1 @@
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};
1
+ const e=({base:e="",routes:r=[]}={})=>({__proto__:new Proxy({},{get:(a,o,t)=>(a,...p)=>r.push([o.toUpperCase(),RegExp(`^${(e+a).replace(/(\/?)\*/g,"($1.*)?").replace(/(\/$)|((?<=\/)\/)/,"").replace(/(:(\w+)\+)/,"(?<$2>.*)").replace(/:(\w+)(\?)?(\.)?/g,"$2(?<$1>[^/]+)$2$3").replace(/\.(?=[\w(])/,"\\.").replace(/\)\.\?\(([^\[]+)\[\^/g,"?)\\.?($1(?<=\\.)[^\\.")}/*$`),p])&&t}),routes:r,async handle(e,...a){let o,t,p=new URL(e.url),l=e.query={};for(let[e,r]of p.searchParams)l[e]=void 0===l[e]?r:[l[e],r].flat();for(let[l,s,c]of r)if((l===e.method||"ALL"===l)&&(t=p.pathname.match(s))){e.params=t.groups||{};for(let r of c)if(void 0!==(o=await r(e.proxy||e,...a)))return o}}});export{e as Router};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itty-router",
3
- "version": "3.0.10",
3
+ "version": "3.0.11",
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",
@@ -41,7 +41,7 @@
41
41
  "dev": "yarn test",
42
42
  "prerelease": "yarn verify",
43
43
  "prebuild": "rimraf dist && mkdir dist",
44
- "build": "tsup src/itty-router.ts --format cjs,esm --dts --minify --clean",
44
+ "build": "rollup -c",
45
45
  "release": "release --tag --push --patch",
46
46
  "prerelease:next": "yarn verify",
47
47
  "release:next": "release --push --type=next"
@@ -58,6 +58,8 @@
58
58
  "homepage": "https://itty-router.dev",
59
59
  "devDependencies": {
60
60
  "@cloudflare/workers-types": "^4.20221111.1",
61
+ "@rollup/plugin-terser": "^0.2.1",
62
+ "@rollup/plugin-typescript": "^10.0.1",
61
63
  "@vitejs/plugin-vue": "^2.2.4",
62
64
  "@vitest/coverage-c8": "^0.24.3",
63
65
  "coveralls": "^3.1.1",
@@ -70,7 +72,8 @@
70
72
  "jsdom": "^20.0.1",
71
73
  "npm-run-all": "^4.1.5",
72
74
  "rimraf": "^3.0.2",
73
- "tsup": "^6.3.0",
75
+ "rollup": "^3.8.1",
76
+ "rollup-plugin-bundle-size": "^1.0.3",
74
77
  "typescript": "^4.8.4",
75
78
  "vite": "^2.8.6",
76
79
  "vitest": "^0.24.3",