Add sunder project
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Yusuke Wada · committed by Yusuke Wada · parent f7a6da1 · Browse files · 8 files·+163 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+163 added−3 removed
- other:+163 added−3 removed
Provenance
- Commit
2b958a2- Tree
a2a8308- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
Yusuke Wada <yusuke@kamawada.com>- Parent
f7a6da1
8 files changed+163 added−3 removed
modified:benchmark/hono/worker/script.js+1 added-1 removed
1-!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){const n=r(1)();n.get("/",()=>new Response("Root Page!")),n.get("/hello",()=>new Response("GET Hello!")),n.put("/hello",()=>new Response("PUT Hello!")),n.post("/hello",()=>new Response("POST Hello!")),n.delete("/hello",()=>new Response("DELETE Hello!")),n.get("/foo/bar",()=>new Response("GET Foo Bar!")),n.put("/foo/bar",()=>new Response("PUT Foo Bar!")),n.post("/foo/bar",()=>new Response("POST Foo Bar!")),n.delete("/foo/bar",()=>new Response("DELETE Foo Bar!")),n.get("/todos",()=>new Response("Todos Index!")),n.get("/todos/:id",e=>new Response("Todo #"+e.req.params("id"))),n.post("/todos",async e=>{const t=await e.req.json();return new Response("Creating Todo: "+JSON.stringify(t))}),n.all("*",()=>new Response("Not Found.",{status:404})),n.fire()},function(e,t,r){"use strict";const n=r(2),o=r(3),s=r(4);class a{constructor(){this.node=new n,this.tempPath="/"}add(e,t,...r){this.node.insert(e,t,r)}match(e,t){return e=e.toLowerCase(),this.node.search(e,t)}}const i={get:(e,t)=>(...r)=>e.constructor.prototype.hasOwnProperty(t)?e[t](...r):1==r.length?e.addRoute(t,e.router.tempPath,...r):e.addRoute(t,...r)};class l{constructor(){this.router=new a,this.middlewareRouter=new a,this.middleware=[]}addRoute(e,t,...r){return this.router.add(e,t,...r),u(this)}matchRoute(e,t){return this.router.match(e,t)}route(e){return this.router.tempPath=e,u(this)}use(e,t){t=[t];const r=this.middlewareRouter.match("all",e);r&&t.push(...r.handler),this.middlewareRouter.add("all",e,...t)}createContext(e,t){return{req:e,res:t}}async dispatch(e,t){const[r,n]=[e.method,(a=e.url,(a=new URL(a)).pathname)];var a;const i=this.matchRoute(r,n);if(!i)return this.notFound();e.params=e=>i.params[e];const l=[s],u=this.middlewareRouter.match("all",n);u&&l.push(...u.handler);let h=i.handler[0];l.push((e,t)=>{e.res=h(e),t()});const c=o(l),d=this.createContext(e,t);return c(d),d.res}async handleEvent(e){return await this.dispatch(e.request,new Response)}fire(){addEventListener("fetch",e=>{e.respondWith(this.handleEvent(e))})}notFound(){return new Response("Not Found",{status:404})}}const u=(e=new l)=>new Proxy(e,i);e.exports=u},function(e,t){class r{constructor({method:e,label:t,handler:r,children:n}={}){this.label=t||"",this.children=n||[],this.method={},e&&r&&(this.method[e]=r)}insert(e,t,n){let o=this;for(const e of this.splitPath(t)){let t=o.children[e];t?o=t:(o.children[e]=new r({label:e,handler:n}),o=o.children[e])}o.method[e]=n}splitPath(e){return["/",...e.split("/").filter(e=>""!==e)]}getPattern(e){const t=e.match(/^\:.+?\{(.+)\}$/);return t?"("+t[1]+")":"(.+)"}getParamName(e){const t=e.match(/^\:([^\{\}]+)/);if(t)return t[1]}search(e,t){let r,n=this,o={};if("/"===t){const t=this.children["/"];if(!t)return this.noRoute();const n=t.children["*"];if(n)r=n.method[e]||n.method.all;else if(!t.method[e])return this.noRoute()}for(const e of this.splitPath(t)){let t=n.children[e];if(t){n=t;continue}let r=!1;for(const t in n.children){if("*"===t){n=n.children[t],r=!0;break}if(t.match(/^:/)){const s=this.getPattern(t),a=e.match(new RegExp(s));if(a){o[this.getParamName(t)]=a[0],n=n.children[t],r=!0;break}return this.noRoute()}}if(0==r)return this.noRoute()}return r=r||n.method.all||n.method[e],r?(({handler:e,params:t}={})=>({handler:e,params:t}))({handler:r,params:o}):this.noRoute()}noRoute(){return null}}e.exports=r},function(e,t){e.exports=e=>function(t,r){let n=-1;return function o(s){if(s<=n)return Promise.reject(new Error("next() called multiple times"));n=s;let a=e[s];s===e.length&&(a=r);if(!a)return Promise.resolve();try{return Promise.resolve(a(t,o.bind(null,s+1)))}catch(e){return Promise.reject(e)}}(0)}},function(e,t){e.exports=(e,t)=>{e.req.query=t=>new URL(e.req.url).searchParams.get(t),t(),"string"==typeof e.res&&(e.res=new Response(e.res,{status:200,headers:{"Content-Type":"text/plain"}}))}}]);1+!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){const n=r(1)();n.get("/",()=>new Response("Root Page!")),n.get("/hello",()=>new Response("GET Hello!")),n.put("/hello",()=>new Response("PUT Hello!")),n.post("/hello",()=>new Response("POST Hello!")),n.delete("/hello",()=>new Response("DELETE Hello!")),n.get("/foo/bar",()=>new Response("GET Foo Bar!")),n.put("/foo/bar",()=>new Response("PUT Foo Bar!")),n.post("/foo/bar",()=>new Response("POST Foo Bar!")),n.delete("/foo/bar",()=>new Response("DELETE Foo Bar!")),n.get("/todos",()=>new Response("Todos Index!")),n.get("/todos/:id",e=>new Response("Todo #"+e.req.params("id"),{status:200,headers:{"Content-Type":"text/plain;charset=UTF-8"}})),n.post("/todos",async e=>{const t=await e.req.json();return new Response("Creating Todo: "+JSON.stringify(t))}),n.all("*",()=>new Response("Not Found.",{status:404})),n.fire()},function(e,t,r){"use strict";const n=r(2),o=r(3),s=r(4);class a{constructor(){this.node=new n,this.tempPath="/"}add(e,t,...r){this.node.insert(e,t,r)}match(e,t){return e=e.toLowerCase(),this.node.search(e,t)}}const i={get:(e,t)=>(...r)=>e.constructor.prototype.hasOwnProperty(t)?e[t](...r):1==r.length?e.addRoute(t,e.router.tempPath,...r):e.addRoute(t,...r)};class l{constructor(){this.router=new a,this.middlewareRouter=new a,this.middleware=[]}addRoute(e,t,...r){return this.router.add(e,t,...r),u(this)}matchRoute(e,t){return this.router.match(e,t)}route(e){return this.router.tempPath=e,u(this)}use(e,t){t=[t];const r=this.middlewareRouter.match("all",e);r&&t.push(...r.handler),this.middlewareRouter.add("all",e,...t)}createContext(e,t){return{req:e,res:t}}async dispatch(e,t){const[r,n]=[e.method,(a=e.url,(a=new URL(a)).pathname)];var a;const i=this.matchRoute(r,n);if(!i)return this.notFound();e.params=e=>i.params[e];const l=[s],u=this.middlewareRouter.match("all",n);u&&l.push(...u.handler);let h=i.handler[0];l.push((e,t)=>{e.res=h(e),t()});const c=o(l),d=this.createContext(e,t);return c(d),d.res}async handleEvent(e){return await this.dispatch(e.request,new Response)}fire(){addEventListener("fetch",e=>{e.respondWith(this.handleEvent(e))})}notFound(){return new Response("Not Found",{status:404})}}const u=(e=new l)=>new Proxy(e,i);e.exports=u},function(e,t){class r{constructor({method:e,label:t,handler:r,children:n}={}){this.label=t||"",this.children=n||[],this.method={},e&&r&&(this.method[e]=r)}insert(e,t,n){let o=this;for(const e of this.splitPath(t)){let t=o.children[e];t?o=t:(o.children[e]=new r({label:e,handler:n}),o=o.children[e])}o.method[e]=n}splitPath(e){return["/",...e.split("/").filter(e=>""!==e)]}getPattern(e){const t=e.match(/^\:.+?\{(.+)\}$/);return t?"("+t[1]+")":"(.+)"}getParamName(e){const t=e.match(/^\:([^\{\}]+)/);if(t)return t[1]}search(e,t){let r,n=this,o={};if("/"===t){const t=this.children["/"];if(!t)return this.noRoute();const n=t.children["*"];if(n)r=n.method[e]||n.method.all;else if(!t.method[e])return this.noRoute()}for(const e of this.splitPath(t)){let t=n.children[e];if(t){n=t;continue}let r=!1;for(const t in n.children){if("*"===t){n=n.children[t],r=!0;break}if(t.match(/^:/)){const s=this.getPattern(t),a=e.match(new RegExp(s));if(a){o[this.getParamName(t)]=a[0],n=n.children[t],r=!0;break}return this.noRoute()}}if(0==r)return this.noRoute()}return r=r||n.method.all||n.method[e],r?(({handler:e,params:t}={})=>({handler:e,params:t}))({handler:r,params:o}):this.noRoute()}noRoute(){return null}}e.exports=r},function(e,t){e.exports=e=>function(t,r){let n=-1;return function o(s){if(s<=n)return Promise.reject(new Error("next() called multiple times"));n=s;let a=e[s];s===e.length&&(a=r);if(!a)return Promise.resolve();try{return Promise.resolve(a(t,o.bind(null,s+1)))}catch(e){return Promise.reject(e)}}(0)}},function(e,t){e.exports=(e,t)=>{e.req.query=t=>new URL(e.req.url).searchParams.get(t),t(),"string"==typeof e.res&&(e.res=new Response(e.res,{status:200,headers:{"Content-Type":"text/plain"}}))}}]);modified:benchmark/hono/index.js+10 added-1 removed
13 unmodified lines141516171818192021222324252627282930315 unmodified lines13 unmodified linesapp.post('/foo/bar', () => new Response('POST Foo Bar!'))app.delete('/foo/bar', () => new Response('DELETE Foo Bar!'))
app.get('/todos', () => new Response('Todos Index!'))app.get('/todos/:id', (c) => new Response(`Todo #${c.req.params('id')}`))app.get( '/todos/:id', (c) => new Response(`Todo #${c.req.params('id')}`, { status: 200, headers: { 'Content-Type': 'text/plain;charset=UTF-8', }, }))
app.post('/todos', async (c) => { const content = await c.req.json() return new Response('Creating Todo: ' + JSON.stringify(content))5 unmodified linesmodified:benchmark/itty-router/index.js+10 added-1 removed
12 unmodified lines131415161717181920212223242526272829307 unmodified lines12 unmodified linesrouter.post('/foo/bar', () => new Response('POST Foo Bar!'))router.delete('/foo/bar', () => new Response('DELETE Foo Bar!'))
router.get('/todos', () => new Response('Todos Index!'))router.get('/todos/:id', ({ params }) => new Response(`Todo #${params.id}`))router.get( '/todos/:id', ({ params }) => new Response(`Todo #${params.id}`, { status: 200, headers: { 'Content-Type': 'text/plain;charset=UTF-8', }, }))
router.post('/todos', async (request) => { const content = await request.json() return new Response('Creating Todo: ' + JSON.stringify(content))7 unmodified linesadded:benchmark/sunder/.gitignore+3 added
1+dist2+node_modules3+workeradded:benchmark/sunder/index.js+47 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import { Sunder, Router, Context } from 'sunder'
const app = new Sunder()const router = new Router()
router.get('/', (response) => { response.body = 'Root Page!'})
router.get('/hello', (response) => { response.body = 'GET Hello!'})router.put('/hello', (response) => { response.body = 'PUT Hello!'})router.post('/hello', (response) => { response.body = 'POST Hello!'})router.delete('/hello', (response) => { response.body = 'DELETE Hello!'})
router.get('/foo/bar', (response) => { response.body = 'GET Foo Bar!'})router.put('/foo/bar', (response) => { response.body = 'PUT Foo Bar!'})router.post('/foo/bar', (response) => { response.body = 'POST Foo Bar!'})router.delete('/foo/bar', (response) => { response.body = 'DELETE Foo Bar!'})
router.get('/todos', ({ response }) => { response.body = 'Todo Index!'})router.get('/todos/:id', ({ response, params }) => { response.body = `Todo #${params.id}`})
app.use(router.middleware)
addEventListener('fetch', (event) => { event.respondWith(app.handle(event))})added:benchmark/sunder/package.json+14 added
1234567891011121314{ "name": "sunder-todos", "version": "0.0.1", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "Yusuke Wada <yusuke@kamawada.com> (https://github.com/yusukebe)", "license": "MIT", "dependencies": { "sunder": "^0.10.0" }}added:benchmark/sunder/wrangler.toml+8 added
12345678name = "sunder"type = "webpack"route = ''zone_id = ''usage_model = ''compatibility_flags = []workers_dev = truecompatibility_date = "2021-12-22"added:benchmark/sunder/yarn.lock+70 added
1+# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.2+# yarn lockfile v13+4+5+depd@2.0.0:6+ version "2.0.0"7+ resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df"8+ integrity sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==9+10+fast-deep-equal@^3.1.3:11+ version "3.1.3"12+ resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"13+ integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==14+15+"http-errors@github:jshttp/http-errors#2.0":16+ version "2.0.0"17+ resolved "https://codeload.github.com/jshttp/http-errors/tar.gz/206aa2c15635dc1212c06c279540972aa90e23ea"18+ dependencies:19+ depd "2.0.0"20+ inherits "2.0.4"21+ setprototypeof "1.2.0"22+ statuses "2.0.1"23+ toidentifier "1.0.1"24+25+inherits@2.0.4:26+ version "2.0.4"27+ resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"28+ integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==29+30+path-to-regexp@^6.1.0:31+ version "6.2.0"32+ resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-6.2.0.tgz#f7b3803336104c346889adece614669230645f38"33+ integrity sha512-f66KywYG6+43afgE/8j/GoiNyygk/bnoCbps++3ErRKsIYkGGupyv07R2Ok5m9i67Iqc+T2g1eAUGUPzWhYTyg==34+35+secure-json-parse@^2.1.0:36+ version "2.4.0"37+ resolved "https://registry.yarnpkg.com/secure-json-parse/-/secure-json-parse-2.4.0.tgz#5aaeaaef85c7a417f76271a4f5b0cc3315ddca85"38+ integrity sha512-Q5Z/97nbON5t/L/sH6mY2EacfjVGwrCcSi5D3btRO2GZ8pf1K1UN7Z9H5J57hjVU2Qzxr1xO+FmBhOvEkzCMmg==39+40+setprototypeof@1.2.0:41+ version "1.2.0"42+ resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424"43+ integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==44+45+statuses@2.0.1:46+ version "2.0.1"47+ resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63"48+ integrity sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==49+50+sunder@^0.10.0:51+ version "0.10.0"52+ resolved "https://registry.yarnpkg.com/sunder/-/sunder-0.10.0.tgz#40f943de8f3c33d7ab4d766729336febcdfa362c"53+ integrity sha512-uhap0K18pg1pvXKh7JfTFt4JhkUjCi+UAHVs4TRccQ/csDbVfzmayzzZkahlREIalq7Iq/WBQ9ZWpM8qipJAxg==54+ dependencies:55+ fast-deep-equal "^3.1.3"56+ http-errors "github:jshttp/http-errors#2.0"57+ secure-json-parse "^2.1.0"58+ tiny-request-router "^1.2.2"59+60+tiny-request-router@^1.2.2:61+ version "1.2.2"62+ resolved "https://registry.yarnpkg.com/tiny-request-router/-/tiny-request-router-1.2.2.tgz#1b80694497e4e8dcbb8e93851ec7f03c6ca13e75"63+ integrity sha512-6ZMFU7AP9so+hkqmMM9fJ11V44EAcYuHCmNdsyM8k94oVnNDPQwUAAPoBHqchHSpKG6yZbCasgVeRxaY5v2BCg==64+ dependencies:65+ path-to-regexp "^6.1.0"66+67+toidentifier@1.0.1:68+ version "1.0.1"69+ resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35"70+ integrity sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==