routup 0.10.0 → 0.11.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.
Files changed (51) hide show
  1. package/dist/index.cjs +2 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.mjs +2 -0
  4. package/dist/index.mjs.map +1 -0
  5. package/package.json +19 -6
  6. package/dist/handler/index.js +0 -24
  7. package/dist/handler/index.js.map +0 -1
  8. package/dist/handler/utils.js +0 -29
  9. package/dist/handler/utils.js.map +0 -1
  10. package/dist/index.js +0 -31
  11. package/dist/index.js.map +0 -1
  12. package/dist/layer/index.js +0 -26
  13. package/dist/layer/index.js.map +0 -1
  14. package/dist/layer/module.js +0 -82
  15. package/dist/layer/module.js.map +0 -1
  16. package/dist/layer/type.js +0 -9
  17. package/dist/layer/type.js.map +0 -1
  18. package/dist/layer/utils.js +0 -15
  19. package/dist/layer/utils.js.map +0 -1
  20. package/dist/path/index.js +0 -25
  21. package/dist/path/index.js.map +0 -1
  22. package/dist/path/matcher.js +0 -74
  23. package/dist/path/matcher.js.map +0 -1
  24. package/dist/path/type.js +0 -9
  25. package/dist/path/type.js.map +0 -1
  26. package/dist/route/index.js +0 -26
  27. package/dist/route/index.js.map +0 -1
  28. package/dist/route/module.js +0 -125
  29. package/dist/route/module.js.map +0 -1
  30. package/dist/route/type.js +0 -9
  31. package/dist/route/type.js.map +0 -1
  32. package/dist/route/utils.js +0 -15
  33. package/dist/route/utils.js.map +0 -1
  34. package/dist/router/index.js +0 -25
  35. package/dist/router/index.js.map +0 -1
  36. package/dist/router/module.js +0 -285
  37. package/dist/router/module.js.map +0 -1
  38. package/dist/router/type.js +0 -3
  39. package/dist/router/type.js.map +0 -1
  40. package/dist/type.js +0 -9
  41. package/dist/type.js.map +0 -1
  42. package/dist/utils/index.js +0 -27
  43. package/dist/utils/index.js.map +0 -1
  44. package/dist/utils/is-instance.js +0 -16
  45. package/dist/utils/is-instance.js.map +0 -1
  46. package/dist/utils/path.js +0 -14
  47. package/dist/utils/path.js.map +0 -1
  48. package/dist/utils/promise.js +0 -19
  49. package/dist/utils/promise.js.map +0 -1
  50. package/dist/utils/request.js +0 -32
  51. package/dist/utils/request.js.map +0 -1
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var a=require("@routup/core"),f=require("smob"),l=require("@ebec/http"),k=require("path-to-regexp"),D=require("http");function g(r,t){return typeof r=="object"&&r!==null&&r["@instanceof"]===Symbol.for(t)}function b(r){return typeof r=="string"||r instanceof RegExp}function v(r){return f.isObject(r)&&(r instanceof Promise||typeof r.then=="function")}function T(r,t,e){const s=setTimeout(()=>{r.statusCode=l.GatewayTimeoutErrorOptions.statusCode,r.statusMessage=l.GatewayTimeoutErrorOptions.message,r.end()},t);r.once("close",()=>{clearTimeout(s),typeof e=="function"&&e()}),r.once("error",h=>{clearTimeout(s),typeof e=="function"&&e(h)})}function I(r,t,e){if(v(e)){e.then(s=>(typeof s<"u"&&a.send(r,s),s)).catch(t);return}typeof e<"u"&&a.send(r,e)}function S(r){return typeof r!="string"||r.length===0?r:decodeURIComponent(r)}class M{constructor(t,e){this.regexpKeys=[],this.path=t,this.regexpOptions=e||{},t instanceof RegExp?this.regexp=t:this.regexp=k.pathToRegexp(t,this.regexpKeys,e)}test(t){return this.path==="/"&&this.regexpOptions.end===!1?!0:this.regexp.test(t)}exec(t){let e=null;if(this.path==="/"&&this.regexpOptions.end===!1)return{path:"/",params:{}};if(e=this.regexp.exec(t),!e)return;if(this.path instanceof RegExp)return{path:t,params:{0:S(e[0])}};const s={};for(let h=1;h<e.length;h++){const p=this.regexpKeys[h-1].name,i=S(e[h]);typeof i<"u"&&(s[p]=i)}return{path:e[0],params:s}}}class E{constructor(t,e){this["@instanceof"]=Symbol.for("Layer"),this.pathMatcher=new M(t.path,t.pathMatcher),this.fn=e}isError(){return this.fn.length===4}dispatch(t,e,s,h,p){if(a.setRequestParams(t,s.params||{}),a.setRequestMountPath(t,s.mountPath||"/"),typeof p<"u"){if(this.fn.length===4){try{this.fn(p,t,e,h)}catch(i){i instanceof Error?h(i):h(new l.BadRequestError({message:"The request could not be processed by the error handler."}))}return}h(p);return}if(this.fn.length>3){h();return}try{const i=this.fn(t,e,h);I(e,h,i)}catch(i){i instanceof Error?h(i):h(new l.BadRequestError({message:"The request could not be processed by the handler."}))}}matchPath(t){return this.pathMatcher.test(t)}exec(t){return this.pathMatcher.exec(t)}}function O(r){return g(r,"Layer")}var $=Object.defineProperty,L=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable,q=(r,t,e)=>t in r?$(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,w=(r,t)=>{for(var e in t||(t={}))G.call(t,e)&&q(r,e,t[e]);if(L)for(var e of L(t))N.call(t,e)&&q(r,e,t[e]);return r};class j{constructor(t){this["@instanceof"]=Symbol.for("Route"),this.layers={},this.path=t.path,this.pathMatcherOptions=w({end:!0,strict:this.isStrictPath()},t.pathMatcher),this.pathMatcher=new M(this.path,this.pathMatcherOptions)}matchPath(t){return this.pathMatcher.test(t)}matchMethod(t){let e=t.toLowerCase();return e===a.Method.HEAD&&!f.hasOwnProperty(this.layers,e)&&(e=a.Method.GET),Object.prototype.hasOwnProperty.call(this.layers,e)}getMethods(){const t=Object.keys(this.layers);return f.hasOwnProperty(this.layers,a.Method.GET)&&!f.hasOwnProperty(this.layers,a.Method.HEAD)&&t.push(a.Method.HEAD),t}dispatch(t,e,s,h){if(!t.method){h();return}let p=t.method.toLowerCase();p===a.Method.HEAD&&!f.hasOwnProperty(this.layers,p)&&(p=a.Method.GET);const i=this.layers[p];if(typeof i>"u"||i.length===0||typeof s.path>"u"){h();return}const y=w({},s),c=this.pathMatcher.exec(s.path);c&&(y.params=f.merge({},s.params||{},c.params));let d=-1;const o=n=>{if(d++,d>=i.length){setImmediate(h,n);return}const u=i[d];if(n&&!u.isError()){o(n);return}u.dispatch(t,e,w({},y),o)};o()}register(t,...e){this.layers[t]=[];for(let s=0;s<e.length;s++){const h=new E({path:this.path,pathMatcher:this.pathMatcherOptions},e[s]);this.layers[t].push(h)}}get(...t){return this.register(a.Method.GET,...t)}post(...t){return this.register(a.Method.POST,...t)}put(...t){return this.register(a.Method.PUT,...t)}patch(...t){return this.register(a.Method.PATCH,...t)}delete(...t){return this.register(a.Method.DELETE,...t)}head(...t){return this.register(a.Method.HEAD,...t)}options(...t){return this.register(a.Method.OPTIONS,...t)}isStrictPath(){return typeof this.path!="string"||this.path!=="/"&&this.path.length!==0}}function R(r){return g(r,"Route")}var B=Object.defineProperty,C=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,H=(r,t,e)=>t in r?B(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,A=(r,t)=>{for(var e in t||(t={}))K.call(t,e)&&H(r,e,t[e]);if(C)for(var e of C(t))U.call(t,e)&&H(r,e,t[e]);return r};function x(r){return g(r,"Router")}class F{constructor(t){this["@instanceof"]=Symbol.for("Router"),this.stack=[],t=t||{},this.pathMatcherOptions=A({end:!1,sensitive:!0},t.pathMatcher||{}),this.timeout=t.timeout,this.setPath(t.path||"/")}setPathMatcherOptions(t){this.pathMatcherOptions=t,this.pathMatcher&&(this.pathMatcher.regexpOptions=this.pathMatcherOptions)}setPath(t){if(t==="/"||!b(t)){this.path="/";return}typeof t=="string"?this.path=a.withLeadingSlash(a.withoutTrailingSlash(`${t}`)):this.path=t,this.pathMatcher=new M(this.path,this.pathMatcherOptions)}createListener(){return this.isRoot=!0,(t,e)=>{this.dispatch(t,e)}}listen(t){return D.createServer(this.createListener()).listen(t)}matchPath(t){return this.pathMatcher?this.pathMatcher.test(t):!0}dispatch(t,e,s,h){let p=-1;s=s||{};let i=[];this.isRoot&&typeof this.timeout=="number"&&T(e,this.timeout,h);const y=o=>{if(!this.isRoot){typeof h<"u"&&setImmediate(()=>h(o));return}if(typeof o<"u"){e.statusCode=l.BadRequestErrorOptions.statusCode,e.statusMessage=l.BadRequestErrorOptions.message,e.end();return}if(t.method&&t.method.toLowerCase()===a.Method.OPTIONS){const n=i.map(u=>u.toUpperCase()).join(",");e.setHeader(a.HeaderName.ALLOW,n),a.send(e,n);return}e.statusCode=l.NotFoundErrorOptions.statusCode,e.end()};let c=s.path||a.useRequestPath(t);if(this.pathMatcher){const o=this.pathMatcher.exec(c);typeof o<"u"&&(s.mountPath=a.cleanDoubleSlashes(`${s.mountPath||""}/${o.path}`),c===o.path?c="/":c=a.withLeadingSlash(c.substring(o.path.length)),s.params=f.merge(s.params||{},o.params))}s.path=c,s.mountPath||(s.mountPath="/");const d=o=>{if(p>=this.stack.length){setImmediate(y,o);return}let n,u=!1;for(;!u&&p<this.stack.length;){if(p++,n=this.stack[p],O(n)){if(!n.isError()&&o)continue;u=n.matchPath(c)}x(n)&&(u=n.matchPath(c)),R(n)&&(u=n.matchPath(c),t.method&&!n.matchMethod(t.method)&&(u=!1,t.method.toLowerCase()===a.Method.OPTIONS&&(i=f.mergeArrays(i,n.getMethods(),!0))))}if(!u||!n){setImmediate(y,o);return}const m=A({},s);if(O(n)){const P=n.exec(c);P&&(m.params=f.merge(P.params,m.params||{}),m.mountPath=a.cleanDoubleSlashes(`${m.mountPath||""}/${P.path}`))}if(o){if(O(n)&&n.isError()){n.dispatch(t,e,m,d,o);return}setImmediate(d,o);return}n.dispatch(t,e,m,d)};d()}dispatchAsync(t,e){return new Promise((s,h)=>{this.dispatch(t,e,{},p=>{if(p){h(p);return}s()})})}route(t){typeof t=="string"&&t.length>0&&(t=a.withLeadingSlash(t));const e=this.stack.findIndex(h=>R(h)&&h.path===t);if(e!==-1)return this.stack[e];const s=new j({path:t,pathMatcher:{sensitive:this.pathMatcherOptions.sensitive}});return this.stack.push(s),s}delete(t,...e){return this.route(t).delete(...e),this}get(t,...e){return this.route(t).get(...e),this}post(t,...e){return this.route(t).post(...e),this}put(t,...e){return this.route(t).put(...e),this}patch(t,...e){return this.route(t).patch(...e),this}head(t,...e){return this.route(t).head(...e),this}options(t,...e){return this.route(t).options(...e),this}use(...t){if(t.length===0)return this;let e;b(t[0])&&(e=t.shift());for(let s=0;s<t.length;s++){const h=t[s];if(x(h)){e&&h.setPath(e),h.setPathMatcherOptions(this.pathMatcherOptions),this.stack.push(h);continue}typeof h=="function"&&this.stack.push(new E({path:e||"/",pathMatcher:{strict:!1,end:!1,sensitive:this.pathMatcherOptions.sensitive}},h))}return this}}exports.Layer=E,exports.PathMatcher=M,exports.Route=j,exports.Router=F,exports.createRequestTimeout=T,exports.isInstance=g,exports.isLayerInstance=O,exports.isPath=b,exports.isPromise=v,exports.isRouteInstance=R,exports.isRouterInstance=x,exports.processHandlerExecutionOutput=I,Object.keys(a).forEach(function(r){r!=="default"&&!exports.hasOwnProperty(r)&&Object.defineProperty(exports,r,{enumerable:!0,get:function(){return a[r]}})});
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/utils/is-instance.ts","../src/utils/path.ts","../src/utils/promise.ts","../src/utils/request.ts","../src/handler/utils.ts","../src/path/matcher.ts","../src/layer/module.ts","../src/layer/utils.ts","../src/route/module.ts","../src/route/utils.ts","../src/router/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2022-2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isInstance(input: unknown, name: string) {\n return (\n typeof input === 'object' &&\n input !== null &&\n (input as { '@instanceof': symbol })['@instanceof'] === Symbol.for(name)\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Path } from '../type';\n\nexport function isPath(input: unknown) : input is Path {\n return typeof input === 'string' || input instanceof RegExp;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isObject } from 'smob';\n\nexport function isPromise(p: unknown) : p is Promise<unknown> {\n return isObject(p) &&\n (\n p instanceof Promise ||\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n typeof p.then === 'function'\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { GatewayTimeoutErrorOptions } from '@ebec/http';\nimport { Next, Response } from '@routup/core';\n\n/* istanbul ignore next */\nexport function createRequestTimeout(res: Response, timeout: number, done?: Next) {\n const instance = setTimeout(() => {\n res.statusCode = GatewayTimeoutErrorOptions.statusCode;\n res.statusMessage = GatewayTimeoutErrorOptions.message;\n\n res.end();\n }, timeout);\n\n res.once('close', () => {\n clearTimeout(instance);\n\n if (typeof done === 'function') {\n done();\n }\n });\n\n res.once('error', (e) => {\n clearTimeout(instance);\n\n if (typeof done === 'function') {\n done(e);\n }\n });\n}\n","/*\n * Copyright (c) 2022-2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Next, Response, send } from '@routup/core';\nimport { isPromise } from '../utils';\n\nexport function processHandlerExecutionOutput(res: Response, next: Next, output?: unknown) {\n if (isPromise(output)) {\n output\n .then((r) => {\n if (typeof r !== 'undefined') {\n send(res, r);\n }\n\n return r;\n })\n .catch(next);\n return;\n }\n\n if (typeof output !== 'undefined') {\n send(res, output);\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport {\n Key, pathToRegexp,\n} from 'path-to-regexp';\nimport { Path } from '../type';\nimport { PathMatcherExecResult, PathMatcherOptions } from './type';\n\nfunction decodeParam(val: unknown) {\n /* istanbul ignore next */\n if (typeof val !== 'string' || val.length === 0) {\n return val;\n }\n\n return decodeURIComponent(val);\n}\n\nexport class PathMatcher {\n path: Path;\n\n regexp : RegExp;\n\n regexpKeys : Key[] = [];\n\n regexpOptions: PathMatcherOptions;\n\n constructor(path: Path, options?: PathMatcherOptions) {\n this.path = path;\n this.regexpOptions = options || {};\n\n if (path instanceof RegExp) {\n this.regexp = path;\n } else {\n this.regexp = pathToRegexp(path, this.regexpKeys, options);\n }\n }\n\n test(path: string) {\n const fastSlash = this.path === '/' && this.regexpOptions.end === false;\n if (fastSlash) {\n return true;\n }\n\n return this.regexp.test(path);\n }\n\n exec(path: string) : PathMatcherExecResult | undefined {\n let match : RegExpExecArray | null = null;\n\n const fastSlash = this.path === '/' && this.regexpOptions.end === false;\n if (fastSlash) {\n return {\n path: '/',\n params: {},\n };\n }\n\n match = this.regexp.exec(path);\n\n if (!match) {\n return undefined;\n }\n\n if (this.path instanceof RegExp) {\n return {\n path,\n params: {\n 0: decodeParam(match[0]),\n },\n };\n }\n\n const output : Record<string, unknown> = {};\n\n for (let i = 1; i < match.length; i++) {\n const key = this.regexpKeys[i - 1];\n const prop = key.name;\n const val = decodeParam(match[i]);\n\n if (typeof val !== 'undefined') {\n output[prop] = val;\n }\n }\n\n return {\n path: match[0],\n params: output,\n };\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BadRequestError } from '@ebec/http';\nimport {\n Next, Request, Response, setRequestMountPath, setRequestParams,\n} from '@routup/core';\nimport { processHandlerExecutionOutput } from '../handler';\nimport { PathMatcher } from '../path';\nimport {\n DispatcherMeta,\n} from '../type';\nimport { LayerOptions } from './type';\n\nexport class Layer {\n readonly '@instanceof' = Symbol.for('Layer');\n\n protected fn : CallableFunction;\n\n protected pathMatcher : PathMatcher;\n\n // --------------------------------------------------\n\n constructor(\n options: LayerOptions,\n fn: CallableFunction,\n ) {\n this.pathMatcher = new PathMatcher(options.path, options.pathMatcher);\n this.fn = fn;\n }\n\n // --------------------------------------------------\n\n isError() {\n return this.fn.length === 4;\n }\n\n // --------------------------------------------------\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n next: CallableFunction\n ) : void;\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n next: CallableFunction,\n err: Error,\n ) : void;\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n next: Next,\n err?: Error,\n ) : void {\n setRequestParams(req, meta.params || {});\n setRequestMountPath(req, meta.mountPath || '/');\n\n if (typeof err !== 'undefined') {\n if (this.fn.length === 4) {\n try {\n this.fn(err, req, res, next);\n } catch (e) {\n /* istanbul ignore next */\n /* istanbul ignore next */\n if (e instanceof Error) {\n next(e);\n } else {\n next(new BadRequestError({\n message: 'The request could not be processed by the error handler.',\n }));\n }\n }\n\n return;\n }\n\n /* istanbul ignore next */\n next(err);\n /* istanbul ignore next */\n return;\n }\n\n /* istanbul ignore next */\n if (this.fn.length > 3) {\n next();\n return;\n }\n\n try {\n const output = this.fn(req, res, next);\n\n processHandlerExecutionOutput(res, next, output);\n } catch (e) {\n /* istanbul ignore next */\n if (e instanceof Error) {\n next(e);\n } else {\n next(new BadRequestError({\n message: 'The request could not be processed by the handler.',\n }));\n }\n }\n }\n\n // --------------------------------------------------\n\n matchPath(path: string) : boolean {\n return this.pathMatcher.test(path);\n }\n\n exec(path: string) {\n return this.pathMatcher.exec(path);\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isInstance } from '../utils';\nimport { Layer } from './module';\n\nexport function isLayerInstance(input: unknown) : input is Layer {\n return isInstance(input, 'Layer');\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty, merge } from 'smob';\nimport {\n Handler, Method, Next, Request, Response,\n} from '@routup/core';\nimport { Layer } from '../layer';\nimport { PathMatcher, PathMatcherOptions } from '../path';\nimport {\n DispatcherMeta,\n Path,\n} from '../type';\nimport { RouteOptions } from './type';\n\nexport class Route {\n readonly '@instanceof' = Symbol.for('Route');\n\n public path : Path;\n\n protected pathMatcher : PathMatcher;\n\n protected pathMatcherOptions : PathMatcherOptions;\n\n protected layers : Record<string, Layer[]> = {};\n\n // --------------------------------------------------\n\n constructor(options: RouteOptions) {\n this.path = options.path;\n\n this.pathMatcherOptions = {\n end: true,\n strict: this.isStrictPath(),\n ...options.pathMatcher,\n };\n this.pathMatcher = new PathMatcher(this.path, this.pathMatcherOptions);\n }\n\n // --------------------------------------------------\n\n matchPath(path: string) : boolean {\n return this.pathMatcher.test(path);\n }\n\n matchMethod(method: string) : boolean {\n let name = method.toLowerCase();\n\n if (\n name === Method.HEAD &&\n !hasOwnProperty(this.layers, name)\n ) {\n name = Method.GET;\n }\n\n return Object.prototype.hasOwnProperty.call(this.layers, name);\n }\n\n // --------------------------------------------------\n\n getMethods() : string[] {\n const keys = Object.keys(this.layers);\n\n if (\n hasOwnProperty(this.layers, Method.GET) &&\n !hasOwnProperty(this.layers, Method.HEAD)\n ) {\n keys.push(Method.HEAD);\n }\n\n return keys;\n }\n\n // --------------------------------------------------\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n done: Next,\n ) : void {\n /* istanbul ignore next */\n if (!req.method) {\n done();\n return;\n }\n\n let name = req.method.toLowerCase();\n\n if (\n name === Method.HEAD &&\n !hasOwnProperty(this.layers, name)\n ) {\n name = Method.GET;\n }\n\n const layers = this.layers[name];\n\n /* istanbul ignore next */\n if (\n typeof layers === 'undefined' ||\n layers.length === 0 ||\n typeof meta.path === 'undefined'\n ) {\n done();\n\n return;\n }\n\n const layerMeta : DispatcherMeta = {\n ...meta,\n };\n\n const output = this.pathMatcher.exec(meta.path);\n if (output) {\n layerMeta.params = merge({}, (meta.params || {}), output.params);\n }\n\n let index = -1;\n\n const next = (err?: Error) : void => {\n index++;\n\n if (index >= layers.length) {\n setImmediate(done, err);\n return;\n }\n\n const layer = layers[index];\n if (\n err &&\n !layer.isError()\n ) {\n next(err);\n return;\n }\n\n layer.dispatch(req, res, { ...layerMeta }, next);\n };\n\n next();\n }\n\n // --------------------------------------------------\n\n register(method: `${Method}`, ...handlers: Handler[]) {\n this.layers[method] = [];\n\n for (let i = 0; i < handlers.length; i++) {\n const layer = new Layer(\n {\n path: this.path,\n pathMatcher: this.pathMatcherOptions,\n },\n handlers[i],\n );\n\n this.layers[method].push(layer);\n }\n }\n\n get(...handlers: Handler[]) {\n return this.register(Method.GET, ...handlers);\n }\n\n post(...handlers: Handler[]) {\n return this.register(Method.POST, ...handlers);\n }\n\n put(...handlers: Handler[]) {\n return this.register(Method.PUT, ...handlers);\n }\n\n patch(...handlers: Handler[]) {\n return this.register(Method.PATCH, ...handlers);\n }\n\n delete(...handlers: Handler[]) {\n return this.register(Method.DELETE, ...handlers);\n }\n\n head(...handlers: Handler[]) {\n return this.register(Method.HEAD, ...handlers);\n }\n\n options(...handlers: Handler[]) {\n return this.register(Method.OPTIONS, ...handlers);\n }\n\n // --------------------------------------------------\n\n private isStrictPath() {\n return typeof this.path !== 'string' ||\n (this.path !== '/' && this.path.length !== 0);\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isInstance } from '../utils';\nimport { Route } from './module';\n\nexport function isRouteInstance(input: unknown) : input is Route {\n return isInstance(input, 'Route');\n}\n","/*\n * Copyright (c) 2022-2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport {\n BadRequestErrorOptions,\n NotFoundErrorOptions,\n} from '@ebec/http';\nimport { RequestListener, createServer } from 'http';\nimport { merge, mergeArrays } from 'smob';\nimport {\n ErrorHandler,\n Handler,\n HeaderName,\n Method,\n Next,\n Request,\n Response,\n cleanDoubleSlashes,\n send,\n useRequestPath,\n withLeadingSlash,\n withoutTrailingSlash,\n} from '@routup/core';\nimport { PathMatcher, PathMatcherOptions } from '../path';\nimport {\n createRequestTimeout,\n isInstance,\n isPath,\n\n} from '../utils';\nimport { Layer, isLayerInstance } from '../layer';\nimport { Route, isRouteInstance } from '../route';\nimport {\n DispatcherMeta,\n Path,\n} from '../type';\nimport { RouterOptions } from './type';\n\nexport function isRouterInstance(input: unknown) : input is Router {\n return isInstance(input, 'Router');\n}\n\nexport class Router {\n readonly '@instanceof' = Symbol.for('Router');\n\n /**\n * Array of mounted layers, routes & routers.\n *\n * @protected\n */\n protected stack : (Router | Route | Layer)[] = [];\n\n /**\n * Mount path of instance\n *\n * @protected\n */\n protected path : Path | undefined;\n\n /**\n * Path matcher for the current mount path.\n *\n * @protected\n */\n protected pathMatcher : PathMatcher | undefined;\n\n /**\n * Path matcher options.\n *\n * @protected\n */\n protected pathMatcherOptions : PathMatcherOptions;\n\n /**\n * Is this the root instance?\n *\n * @protected\n */\n protected isRoot : boolean | undefined;\n\n /**\n * Timeout before the router decides to abort the request.\n *\n * @protected\n */\n protected timeout: number | undefined;\n\n // --------------------------------------------------\n\n constructor(ctx?: RouterOptions) {\n ctx = ctx || {};\n\n this.pathMatcherOptions = {\n end: false,\n sensitive: true,\n ...(ctx.pathMatcher || {}),\n };\n\n this.timeout = ctx.timeout;\n\n this.setPath(ctx.path || '/');\n }\n\n // --------------------------------------------------\n\n setPathMatcherOptions(input: PathMatcherOptions) {\n this.pathMatcherOptions = input;\n\n if (this.pathMatcher) {\n this.pathMatcher.regexpOptions = this.pathMatcherOptions;\n }\n }\n\n setPath(value: Path) {\n if (value === '/' || !isPath(value)) {\n this.path = '/';\n return;\n }\n\n if (typeof value === 'string') {\n this.path = withLeadingSlash(withoutTrailingSlash(`${value}`));\n } else {\n this.path = value;\n }\n\n this.pathMatcher = new PathMatcher(this.path, this.pathMatcherOptions);\n }\n\n // --------------------------------------------------\n\n createListener() : RequestListener {\n this.isRoot = true;\n\n return (req, res) => {\n this.dispatch(req, res);\n };\n }\n\n /* istanbul ignore next */\n listen(port: number) {\n const server = createServer(this.createListener());\n return server.listen(port);\n }\n\n // --------------------------------------------------\n\n matchPath(path: string) : boolean {\n if (this.pathMatcher) {\n return this.pathMatcher.test(path);\n }\n\n return true;\n }\n\n // --------------------------------------------------\n\n dispatch(\n req: Request,\n res: Response,\n meta?: DispatcherMeta,\n done?: Next,\n ) : void {\n let index = -1;\n\n meta = meta || {};\n\n let allowedMethods : string[] = [];\n\n if (\n this.isRoot &&\n typeof this.timeout === 'number'\n ) {\n createRequestTimeout(res, this.timeout, done);\n }\n\n const fn = (err?: Error) => {\n /* istanbul ignore if */\n if (!this.isRoot) {\n if (typeof done !== 'undefined') {\n setImmediate(() => done(err));\n }\n\n return;\n }\n\n if (typeof err !== 'undefined') {\n res.statusCode = BadRequestErrorOptions.statusCode;\n res.statusMessage = BadRequestErrorOptions.message;\n\n res.end();\n\n return;\n }\n\n if (\n req.method &&\n req.method.toLowerCase() === Method.OPTIONS\n ) {\n const options = allowedMethods\n .map((key) => key.toUpperCase())\n .join(',');\n\n res.setHeader(HeaderName.ALLOW, options);\n send(res, options);\n\n return;\n }\n\n res.statusCode = NotFoundErrorOptions.statusCode;\n res.end();\n };\n\n let path = meta.path || useRequestPath(req);\n\n if (this.pathMatcher) {\n const output = this.pathMatcher.exec(path);\n if (typeof output !== 'undefined') {\n meta.mountPath = cleanDoubleSlashes(`${meta.mountPath || ''}/${output.path}`);\n\n if (path === output.path) {\n path = '/';\n } else {\n path = withLeadingSlash(path.substring(output.path.length));\n }\n\n meta.params = merge(meta.params || {}, output.params);\n }\n }\n\n meta.path = path;\n\n if (!meta.mountPath) {\n meta.mountPath = '/';\n }\n\n const next = (err?: Error) : void => {\n if (index >= this.stack.length) {\n setImmediate(fn, err);\n return;\n }\n\n let layer : Route | Router | Layer | undefined;\n let match = false;\n\n while (!match && index < this.stack.length) {\n index++;\n\n layer = this.stack[index];\n\n if (isLayerInstance(layer)) {\n if (!layer.isError() && err) {\n continue;\n }\n\n match = layer.matchPath(path);\n }\n\n if (isRouterInstance(layer)) {\n match = layer.matchPath(path);\n }\n\n if (isRouteInstance(layer)) {\n match = layer.matchPath(path);\n\n if (\n req.method &&\n !layer.matchMethod(req.method)\n ) {\n match = false;\n\n if (req.method.toLowerCase() === Method.OPTIONS) {\n allowedMethods = mergeArrays(\n allowedMethods,\n layer.getMethods(),\n true,\n );\n }\n }\n }\n }\n\n if (!match || !layer) {\n setImmediate(fn, err);\n return;\n }\n\n const layerMeta : DispatcherMeta = { ...meta };\n\n if (isLayerInstance(layer)) {\n const output = layer.exec(path);\n\n if (output) {\n layerMeta.params = merge(output.params, layerMeta.params || {});\n layerMeta.mountPath = cleanDoubleSlashes(`${layerMeta.mountPath || ''}/${output.path}`);\n }\n }\n\n if (err) {\n if (\n isLayerInstance(layer) &&\n layer.isError()\n ) {\n layer.dispatch(req, res, layerMeta, next, err);\n return;\n }\n\n /* istanbul ignore next */\n setImmediate(next, err);\n return;\n }\n\n layer.dispatch(req, res, layerMeta, next);\n };\n\n next();\n }\n\n /* istanbul ignore next */\n dispatchAsync(\n req: Request,\n res: Response,\n ) : Promise<void> {\n return new Promise((resolve, reject) => {\n this.dispatch(req, res, {}, (err?: Error) => {\n if (err) {\n reject(err);\n return;\n }\n\n resolve();\n });\n });\n }\n\n // --------------------------------------------------\n\n route(\n path: Path,\n ) : Route {\n if (\n typeof path === 'string' &&\n path.length > 0\n ) {\n path = withLeadingSlash(path);\n }\n\n const index = this.stack.findIndex(\n (item) => isRouteInstance(item) && item.path === path,\n );\n\n if (index !== -1) {\n return this.stack[index] as Route;\n }\n\n const route = new Route({\n path,\n pathMatcher: {\n sensitive: this.pathMatcherOptions.sensitive,\n },\n });\n this.stack.push(route);\n\n return route;\n }\n\n delete(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.delete(...handlers);\n\n return this;\n }\n\n get(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.get(...handlers);\n\n return this;\n }\n\n post(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.post(...handlers);\n\n return this;\n }\n\n put(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.put(...handlers);\n\n return this;\n }\n\n patch(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.patch(...handlers);\n\n return this;\n }\n\n head(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.head(...handlers);\n\n return this;\n }\n\n options(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.options(...handlers);\n\n return this;\n }\n\n // --------------------------------------------------\n\n use(router: Router) : this;\n\n use(handler: Handler) : this;\n\n use(handler: ErrorHandler) : this;\n\n use(path: Path, router: Router) : this;\n\n use(path: Path, handler: Handler) : this;\n\n use(path: Path, handler: ErrorHandler) : this;\n\n use(...input: unknown[]) : this {\n /* istanbul ignore next */\n if (input.length === 0) {\n return this;\n }\n\n let path : Path | undefined;\n\n if (isPath(input[0])) {\n path = input.shift() as Path;\n }\n\n for (let i = 0; i < input.length; i++) {\n const item = input[i];\n if (isRouterInstance(item)) {\n if (path) {\n item.setPath(path);\n }\n item.setPathMatcherOptions(this.pathMatcherOptions);\n this.stack.push(item);\n continue;\n }\n\n if (typeof item === 'function') {\n this.stack.push(new Layer({\n path: path || '/',\n pathMatcher: {\n strict: false,\n end: false,\n sensitive: this.pathMatcherOptions.sensitive,\n },\n }, item));\n }\n }\n\n return this;\n }\n}\n"],"names":["isInstance","input","name","isPath","isPromise","p","isObject","createRequestTimeout","res","timeout","done","instance","GatewayTimeoutErrorOptions","e","processHandlerExecutionOutput","next","output","r","send","decodeParam","val","PathMatcher","path","options","pathToRegexp","match","i","prop","Layer","fn","req","meta","err","setRequestParams","setRequestMountPath","BadRequestError","isLayerInstance","Route","__spreadValues","method","Method","hasOwnProperty","keys","layers","layerMeta","merge","index","layer","handlers","isRouteInstance","isRouterInstance","Router","ctx","value","withLeadingSlash","withoutTrailingSlash","port","createServer","allowedMethods","BadRequestErrorOptions","key","HeaderName","NotFoundErrorOptions","useRequestPath","cleanDoubleSlashes","mergeArrays","resolve","reject","item","route"],"mappings":"mIAOO,SAASA,EAAWC,EAAgBC,EAAc,CACrD,OACI,OAAOD,GAAU,UACjBA,IAAU,MACTA,EAAoC,iBAAmB,OAAO,IAAIC,CAAI,CAE/E,CCJgB,SAAAC,EAAOF,EAAgC,CACnD,OAAO,OAAOA,GAAU,UAAYA,aAAiB,MACzD,CCFgB,SAAAG,EAAUC,EAAoC,CAC1D,OAAOC,EAAAA,SAASD,CAAC,IAETA,aAAa,SAGb,OAAOA,EAAE,MAAS,WAE9B,CCNgB,SAAAE,EAAqBC,EAAeC,EAAiBC,EAAa,CAC9E,MAAMC,EAAW,WAAW,IAAM,CAC9BH,EAAI,WAAaI,EAAAA,2BAA2B,WAC5CJ,EAAI,cAAgBI,EAAAA,2BAA2B,QAE/CJ,EAAI,KACR,EAAGC,CAAO,EAEVD,EAAI,KAAK,QAAS,IAAM,CACpB,aAAaG,CAAQ,EAEjB,OAAOD,GAAS,YAChBA,EAAAA,CAER,CAAC,EAEDF,EAAI,KAAK,QAAUK,GAAM,CACrB,aAAaF,CAAQ,EAEjB,OAAOD,GAAS,YAChBA,EAAKG,CAAC,CAEd,CAAC,CACL,CCxBgB,SAAAC,EAA8BN,EAAeO,EAAYC,EAAkB,CACvF,GAAIZ,EAAUY,CAAM,EAAG,CACnBA,EACK,KAAMC,IACC,OAAOA,EAAM,KACbC,OAAKV,EAAKS,CAAC,EAGRA,EACV,EACA,MAAMF,CAAI,EACf,MACJ,CAEI,OAAOC,EAAW,KAClBE,EAAAA,KAAKV,EAAKQ,CAAM,CAExB,CCdA,SAASG,EAAYC,EAAc,CAE/B,OAAI,OAAOA,GAAQ,UAAYA,EAAI,SAAW,EACnCA,EAGJ,mBAAmBA,CAAG,CACjC,CAEO,MAAMC,CAAY,CASrB,YAAYC,EAAYC,EAA8B,CAJtD,KAAqB,WAAA,CAAA,EAK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AAQ,IACd,YAAa,CACT,OAAQ,GACR,IAAK,GACL,UAAW,KAAK,mBAAmB,SACvC,CACJ,EAAG8C,CAAI,CAAC,CAEhB,CAEA,OAAO,IACX,CACJ"}
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import{send as P,setRequestParams as U,setRequestMountPath as B,Method as p,withLeadingSlash as b,withoutTrailingSlash as F,useRequestPath as W,cleanDoubleSlashes as I,HeaderName as z}from"@routup/core";export*from"@routup/core";import{isObject as J,hasOwnProperty as d,merge as E,mergeArrays as Q}from"smob";import{GatewayTimeoutErrorOptions as S,BadRequestError as L,BadRequestErrorOptions as j,NotFoundErrorOptions as V}from"@ebec/http";import{pathToRegexp as X}from"path-to-regexp";import{createServer as Y}from"http";function y(r,t){return typeof r=="object"&&r!==null&&r["@instanceof"]===Symbol.for(t)}function x(r){return typeof r=="string"||r instanceof RegExp}function C(r){return J(r)&&(r instanceof Promise||typeof r.then=="function")}function k(r,t,e){const s=setTimeout(()=>{r.statusCode=S.statusCode,r.statusMessage=S.message,r.end()},t);r.once("close",()=>{clearTimeout(s),typeof e=="function"&&e()}),r.once("error",h=>{clearTimeout(s),typeof e=="function"&&e(h)})}function H(r,t,e){if(C(e)){e.then(s=>(typeof s<"u"&&P(r,s),s)).catch(t);return}typeof e<"u"&&P(r,e)}function A(r){return typeof r!="string"||r.length===0?r:decodeURIComponent(r)}class g{constructor(t,e){this.regexpKeys=[],this.path=t,this.regexpOptions=e||{},t instanceof RegExp?this.regexp=t:this.regexp=X(t,this.regexpKeys,e)}test(t){return this.path==="/"&&this.regexpOptions.end===!1?!0:this.regexp.test(t)}exec(t){let e=null;if(this.path==="/"&&this.regexpOptions.end===!1)return{path:"/",params:{}};if(e=this.regexp.exec(t),!e)return;if(this.path instanceof RegExp)return{path:t,params:{0:A(e[0])}};const s={};for(let h=1;h<e.length;h++){const o=this.regexpKeys[h-1].name,i=A(e[h]);typeof i<"u"&&(s[o]=i)}return{path:e[0],params:s}}}class w{constructor(t,e){this["@instanceof"]=Symbol.for("Layer"),this.pathMatcher=new g(t.path,t.pathMatcher),this.fn=e}isError(){return this.fn.length===4}dispatch(t,e,s,h,o){if(U(t,s.params||{}),B(t,s.mountPath||"/"),typeof o<"u"){if(this.fn.length===4){try{this.fn(o,t,e,h)}catch(i){i instanceof Error?h(i):h(new L({message:"The request could not be processed by the error handler."}))}return}h(o);return}if(this.fn.length>3){h();return}try{const i=this.fn(t,e,h);H(e,h,i)}catch(i){i instanceof Error?h(i):h(new L({message:"The request could not be processed by the handler."}))}}matchPath(t){return this.pathMatcher.test(t)}exec(t){return this.pathMatcher.exec(t)}}function O(r){return y(r,"Layer")}var Z=Object.defineProperty,q=Object.getOwnPropertySymbols,_=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable,D=(r,t,e)=>t in r?Z(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,R=(r,t)=>{for(var e in t||(t={}))_.call(t,e)&&D(r,e,t[e]);if(q)for(var e of q(t))tt.call(t,e)&&D(r,e,t[e]);return r};class ${constructor(t){this["@instanceof"]=Symbol.for("Route"),this.layers={},this.path=t.path,this.pathMatcherOptions=R({end:!0,strict:this.isStrictPath()},t.pathMatcher),this.pathMatcher=new g(this.path,this.pathMatcherOptions)}matchPath(t){return this.pathMatcher.test(t)}matchMethod(t){let e=t.toLowerCase();return e===p.HEAD&&!d(this.layers,e)&&(e=p.GET),Object.prototype.hasOwnProperty.call(this.layers,e)}getMethods(){const t=Object.keys(this.layers);return d(this.layers,p.GET)&&!d(this.layers,p.HEAD)&&t.push(p.HEAD),t}dispatch(t,e,s,h){if(!t.method){h();return}let o=t.method.toLowerCase();o===p.HEAD&&!d(this.layers,o)&&(o=p.GET);const i=this.layers[o];if(typeof i>"u"||i.length===0||typeof s.path>"u"){h();return}const l=R({},s),c=this.pathMatcher.exec(s.path);c&&(l.params=E({},s.params||{},c.params));let f=-1;const n=a=>{if(f++,f>=i.length){setImmediate(h,a);return}const u=i[f];if(a&&!u.isError()){n(a);return}u.dispatch(t,e,R({},l),n)};n()}register(t,...e){this.layers[t]=[];for(let s=0;s<e.length;s++){const h=new w({path:this.path,pathMatcher:this.pathMatcherOptions},e[s]);this.layers[t].push(h)}}get(...t){return this.register(p.GET,...t)}post(...t){return this.register(p.POST,...t)}put(...t){return this.register(p.PUT,...t)}patch(...t){return this.register(p.PATCH,...t)}delete(...t){return this.register(p.DELETE,...t)}head(...t){return this.register(p.HEAD,...t)}options(...t){return this.register(p.OPTIONS,...t)}isStrictPath(){return typeof this.path!="string"||this.path!=="/"&&this.path.length!==0}}function v(r){return y(r,"Route")}var et=Object.defineProperty,G=Object.getOwnPropertySymbols,rt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable,N=(r,t,e)=>t in r?et(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,K=(r,t)=>{for(var e in t||(t={}))rt.call(t,e)&&N(r,e,t[e]);if(G)for(var e of G(t))st.call(t,e)&&N(r,e,t[e]);return r};function T(r){return y(r,"Router")}class ht{constructor(t){this["@instanceof"]=Symbol.for("Router"),this.stack=[],t=t||{},this.pathMatcherOptions=K({end:!1,sensitive:!0},t.pathMatcher||{}),this.timeout=t.timeout,this.setPath(t.path||"/")}setPathMatcherOptions(t){this.pathMatcherOptions=t,this.pathMatcher&&(this.pathMatcher.regexpOptions=this.pathMatcherOptions)}setPath(t){if(t==="/"||!x(t)){this.path="/";return}typeof t=="string"?this.path=b(F(`${t}`)):this.path=t,this.pathMatcher=new g(this.path,this.pathMatcherOptions)}createListener(){return this.isRoot=!0,(t,e)=>{this.dispatch(t,e)}}listen(t){return Y(this.createListener()).listen(t)}matchPath(t){return this.pathMatcher?this.pathMatcher.test(t):!0}dispatch(t,e,s,h){let o=-1;s=s||{};let i=[];this.isRoot&&typeof this.timeout=="number"&&k(e,this.timeout,h);const l=n=>{if(!this.isRoot){typeof h<"u"&&setImmediate(()=>h(n));return}if(typeof n<"u"){e.statusCode=j.statusCode,e.statusMessage=j.message,e.end();return}if(t.method&&t.method.toLowerCase()===p.OPTIONS){const a=i.map(u=>u.toUpperCase()).join(",");e.setHeader(z.ALLOW,a),P(e,a);return}e.statusCode=V.statusCode,e.end()};let c=s.path||W(t);if(this.pathMatcher){const n=this.pathMatcher.exec(c);typeof n<"u"&&(s.mountPath=I(`${s.mountPath||""}/${n.path}`),c===n.path?c="/":c=b(c.substring(n.path.length)),s.params=E(s.params||{},n.params))}s.path=c,s.mountPath||(s.mountPath="/");const f=n=>{if(o>=this.stack.length){setImmediate(l,n);return}let a,u=!1;for(;!u&&o<this.stack.length;){if(o++,a=this.stack[o],O(a)){if(!a.isError()&&n)continue;u=a.matchPath(c)}T(a)&&(u=a.matchPath(c)),v(a)&&(u=a.matchPath(c),t.method&&!a.matchMethod(t.method)&&(u=!1,t.method.toLowerCase()===p.OPTIONS&&(i=Q(i,a.getMethods(),!0))))}if(!u||!a){setImmediate(l,n);return}const m=K({},s);if(O(a)){const M=a.exec(c);M&&(m.params=E(M.params,m.params||{}),m.mountPath=I(`${m.mountPath||""}/${M.path}`))}if(n){if(O(a)&&a.isError()){a.dispatch(t,e,m,f,n);return}setImmediate(f,n);return}a.dispatch(t,e,m,f)};f()}dispatchAsync(t,e){return new Promise((s,h)=>{this.dispatch(t,e,{},o=>{if(o){h(o);return}s()})})}route(t){typeof t=="string"&&t.length>0&&(t=b(t));const e=this.stack.findIndex(h=>v(h)&&h.path===t);if(e!==-1)return this.stack[e];const s=new $({path:t,pathMatcher:{sensitive:this.pathMatcherOptions.sensitive}});return this.stack.push(s),s}delete(t,...e){return this.route(t).delete(...e),this}get(t,...e){return this.route(t).get(...e),this}post(t,...e){return this.route(t).post(...e),this}put(t,...e){return this.route(t).put(...e),this}patch(t,...e){return this.route(t).patch(...e),this}head(t,...e){return this.route(t).head(...e),this}options(t,...e){return this.route(t).options(...e),this}use(...t){if(t.length===0)return this;let e;x(t[0])&&(e=t.shift());for(let s=0;s<t.length;s++){const h=t[s];if(T(h)){e&&h.setPath(e),h.setPathMatcherOptions(this.pathMatcherOptions),this.stack.push(h);continue}typeof h=="function"&&this.stack.push(new w({path:e||"/",pathMatcher:{strict:!1,end:!1,sensitive:this.pathMatcherOptions.sensitive}},h))}return this}}export{w as Layer,g as PathMatcher,$ as Route,ht as Router,k as createRequestTimeout,y as isInstance,O as isLayerInstance,x as isPath,C as isPromise,v as isRouteInstance,T as isRouterInstance,H as processHandlerExecutionOutput};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../src/utils/is-instance.ts","../src/utils/path.ts","../src/utils/promise.ts","../src/utils/request.ts","../src/handler/utils.ts","../src/path/matcher.ts","../src/layer/module.ts","../src/layer/utils.ts","../src/route/module.ts","../src/route/utils.ts","../src/router/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2022-2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isInstance(input: unknown, name: string) {\n return (\n typeof input === 'object' &&\n input !== null &&\n (input as { '@instanceof': symbol })['@instanceof'] === Symbol.for(name)\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Path } from '../type';\n\nexport function isPath(input: unknown) : input is Path {\n return typeof input === 'string' || input instanceof RegExp;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isObject } from 'smob';\n\nexport function isPromise(p: unknown) : p is Promise<unknown> {\n return isObject(p) &&\n (\n p instanceof Promise ||\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n typeof p.then === 'function'\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { GatewayTimeoutErrorOptions } from '@ebec/http';\nimport { Next, Response } from '@routup/core';\n\n/* istanbul ignore next */\nexport function createRequestTimeout(res: Response, timeout: number, done?: Next) {\n const instance = setTimeout(() => {\n res.statusCode = GatewayTimeoutErrorOptions.statusCode;\n res.statusMessage = GatewayTimeoutErrorOptions.message;\n\n res.end();\n }, timeout);\n\n res.once('close', () => {\n clearTimeout(instance);\n\n if (typeof done === 'function') {\n done();\n }\n });\n\n res.once('error', (e) => {\n clearTimeout(instance);\n\n if (typeof done === 'function') {\n done(e);\n }\n });\n}\n","/*\n * Copyright (c) 2022-2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Next, Response, send } from '@routup/core';\nimport { isPromise } from '../utils';\n\nexport function processHandlerExecutionOutput(res: Response, next: Next, output?: unknown) {\n if (isPromise(output)) {\n output\n .then((r) => {\n if (typeof r !== 'undefined') {\n send(res, r);\n }\n\n return r;\n })\n .catch(next);\n return;\n }\n\n if (typeof output !== 'undefined') {\n send(res, output);\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport {\n Key, pathToRegexp,\n} from 'path-to-regexp';\nimport { Path } from '../type';\nimport { PathMatcherExecResult, PathMatcherOptions } from './type';\n\nfunction decodeParam(val: unknown) {\n /* istanbul ignore next */\n if (typeof val !== 'string' || val.length === 0) {\n return val;\n }\n\n return decodeURIComponent(val);\n}\n\nexport class PathMatcher {\n path: Path;\n\n regexp : RegExp;\n\n regexpKeys : Key[] = [];\n\n regexpOptions: PathMatcherOptions;\n\n constructor(path: Path, options?: PathMatcherOptions) {\n this.path = path;\n this.regexpOptions = options || {};\n\n if (path instanceof RegExp) {\n this.regexp = path;\n } else {\n this.regexp = pathToRegexp(path, this.regexpKeys, options);\n }\n }\n\n test(path: string) {\n const fastSlash = this.path === '/' && this.regexpOptions.end === false;\n if (fastSlash) {\n return true;\n }\n\n return this.regexp.test(path);\n }\n\n exec(path: string) : PathMatcherExecResult | undefined {\n let match : RegExpExecArray | null = null;\n\n const fastSlash = this.path === '/' && this.regexpOptions.end === false;\n if (fastSlash) {\n return {\n path: '/',\n params: {},\n };\n }\n\n match = this.regexp.exec(path);\n\n if (!match) {\n return undefined;\n }\n\n if (this.path instanceof RegExp) {\n return {\n path,\n params: {\n 0: decodeParam(match[0]),\n },\n };\n }\n\n const output : Record<string, unknown> = {};\n\n for (let i = 1; i < match.length; i++) {\n const key = this.regexpKeys[i - 1];\n const prop = key.name;\n const val = decodeParam(match[i]);\n\n if (typeof val !== 'undefined') {\n output[prop] = val;\n }\n }\n\n return {\n path: match[0],\n params: output,\n };\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BadRequestError } from '@ebec/http';\nimport {\n Next, Request, Response, setRequestMountPath, setRequestParams,\n} from '@routup/core';\nimport { processHandlerExecutionOutput } from '../handler';\nimport { PathMatcher } from '../path';\nimport {\n DispatcherMeta,\n} from '../type';\nimport { LayerOptions } from './type';\n\nexport class Layer {\n readonly '@instanceof' = Symbol.for('Layer');\n\n protected fn : CallableFunction;\n\n protected pathMatcher : PathMatcher;\n\n // --------------------------------------------------\n\n constructor(\n options: LayerOptions,\n fn: CallableFunction,\n ) {\n this.pathMatcher = new PathMatcher(options.path, options.pathMatcher);\n this.fn = fn;\n }\n\n // --------------------------------------------------\n\n isError() {\n return this.fn.length === 4;\n }\n\n // --------------------------------------------------\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n next: CallableFunction\n ) : void;\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n next: CallableFunction,\n err: Error,\n ) : void;\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n next: Next,\n err?: Error,\n ) : void {\n setRequestParams(req, meta.params || {});\n setRequestMountPath(req, meta.mountPath || '/');\n\n if (typeof err !== 'undefined') {\n if (this.fn.length === 4) {\n try {\n this.fn(err, req, res, next);\n } catch (e) {\n /* istanbul ignore next */\n /* istanbul ignore next */\n if (e instanceof Error) {\n next(e);\n } else {\n next(new BadRequestError({\n message: 'The request could not be processed by the error handler.',\n }));\n }\n }\n\n return;\n }\n\n /* istanbul ignore next */\n next(err);\n /* istanbul ignore next */\n return;\n }\n\n /* istanbul ignore next */\n if (this.fn.length > 3) {\n next();\n return;\n }\n\n try {\n const output = this.fn(req, res, next);\n\n processHandlerExecutionOutput(res, next, output);\n } catch (e) {\n /* istanbul ignore next */\n if (e instanceof Error) {\n next(e);\n } else {\n next(new BadRequestError({\n message: 'The request could not be processed by the handler.',\n }));\n }\n }\n }\n\n // --------------------------------------------------\n\n matchPath(path: string) : boolean {\n return this.pathMatcher.test(path);\n }\n\n exec(path: string) {\n return this.pathMatcher.exec(path);\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isInstance } from '../utils';\nimport { Layer } from './module';\n\nexport function isLayerInstance(input: unknown) : input is Layer {\n return isInstance(input, 'Layer');\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty, merge } from 'smob';\nimport {\n Handler, Method, Next, Request, Response,\n} from '@routup/core';\nimport { Layer } from '../layer';\nimport { PathMatcher, PathMatcherOptions } from '../path';\nimport {\n DispatcherMeta,\n Path,\n} from '../type';\nimport { RouteOptions } from './type';\n\nexport class Route {\n readonly '@instanceof' = Symbol.for('Route');\n\n public path : Path;\n\n protected pathMatcher : PathMatcher;\n\n protected pathMatcherOptions : PathMatcherOptions;\n\n protected layers : Record<string, Layer[]> = {};\n\n // --------------------------------------------------\n\n constructor(options: RouteOptions) {\n this.path = options.path;\n\n this.pathMatcherOptions = {\n end: true,\n strict: this.isStrictPath(),\n ...options.pathMatcher,\n };\n this.pathMatcher = new PathMatcher(this.path, this.pathMatcherOptions);\n }\n\n // --------------------------------------------------\n\n matchPath(path: string) : boolean {\n return this.pathMatcher.test(path);\n }\n\n matchMethod(method: string) : boolean {\n let name = method.toLowerCase();\n\n if (\n name === Method.HEAD &&\n !hasOwnProperty(this.layers, name)\n ) {\n name = Method.GET;\n }\n\n return Object.prototype.hasOwnProperty.call(this.layers, name);\n }\n\n // --------------------------------------------------\n\n getMethods() : string[] {\n const keys = Object.keys(this.layers);\n\n if (\n hasOwnProperty(this.layers, Method.GET) &&\n !hasOwnProperty(this.layers, Method.HEAD)\n ) {\n keys.push(Method.HEAD);\n }\n\n return keys;\n }\n\n // --------------------------------------------------\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n done: Next,\n ) : void {\n /* istanbul ignore next */\n if (!req.method) {\n done();\n return;\n }\n\n let name = req.method.toLowerCase();\n\n if (\n name === Method.HEAD &&\n !hasOwnProperty(this.layers, name)\n ) {\n name = Method.GET;\n }\n\n const layers = this.layers[name];\n\n /* istanbul ignore next */\n if (\n typeof layers === 'undefined' ||\n layers.length === 0 ||\n typeof meta.path === 'undefined'\n ) {\n done();\n\n return;\n }\n\n const layerMeta : DispatcherMeta = {\n ...meta,\n };\n\n const output = this.pathMatcher.exec(meta.path);\n if (output) {\n layerMeta.params = merge({}, (meta.params || {}), output.params);\n }\n\n let index = -1;\n\n const next = (err?: Error) : void => {\n index++;\n\n if (index >= layers.length) {\n setImmediate(done, err);\n return;\n }\n\n const layer = layers[index];\n if (\n err &&\n !layer.isError()\n ) {\n next(err);\n return;\n }\n\n layer.dispatch(req, res, { ...layerMeta }, next);\n };\n\n next();\n }\n\n // --------------------------------------------------\n\n register(method: `${Method}`, ...handlers: Handler[]) {\n this.layers[method] = [];\n\n for (let i = 0; i < handlers.length; i++) {\n const layer = new Layer(\n {\n path: this.path,\n pathMatcher: this.pathMatcherOptions,\n },\n handlers[i],\n );\n\n this.layers[method].push(layer);\n }\n }\n\n get(...handlers: Handler[]) {\n return this.register(Method.GET, ...handlers);\n }\n\n post(...handlers: Handler[]) {\n return this.register(Method.POST, ...handlers);\n }\n\n put(...handlers: Handler[]) {\n return this.register(Method.PUT, ...handlers);\n }\n\n patch(...handlers: Handler[]) {\n return this.register(Method.PATCH, ...handlers);\n }\n\n delete(...handlers: Handler[]) {\n return this.register(Method.DELETE, ...handlers);\n }\n\n head(...handlers: Handler[]) {\n return this.register(Method.HEAD, ...handlers);\n }\n\n options(...handlers: Handler[]) {\n return this.register(Method.OPTIONS, ...handlers);\n }\n\n // --------------------------------------------------\n\n private isStrictPath() {\n return typeof this.path !== 'string' ||\n (this.path !== '/' && this.path.length !== 0);\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isInstance } from '../utils';\nimport { Route } from './module';\n\nexport function isRouteInstance(input: unknown) : input is Route {\n return isInstance(input, 'Route');\n}\n","/*\n * Copyright (c) 2022-2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport {\n BadRequestErrorOptions,\n NotFoundErrorOptions,\n} from '@ebec/http';\nimport { RequestListener, createServer } from 'http';\nimport { merge, mergeArrays } from 'smob';\nimport {\n ErrorHandler,\n Handler,\n HeaderName,\n Method,\n Next,\n Request,\n Response,\n cleanDoubleSlashes,\n send,\n useRequestPath,\n withLeadingSlash,\n withoutTrailingSlash,\n} from '@routup/core';\nimport { PathMatcher, PathMatcherOptions } from '../path';\nimport {\n createRequestTimeout,\n isInstance,\n isPath,\n\n} from '../utils';\nimport { Layer, isLayerInstance } from '../layer';\nimport { Route, isRouteInstance } from '../route';\nimport {\n DispatcherMeta,\n Path,\n} from '../type';\nimport { RouterOptions } from './type';\n\nexport function isRouterInstance(input: unknown) : input is Router {\n return isInstance(input, 'Router');\n}\n\nexport class Router {\n readonly '@instanceof' = Symbol.for('Router');\n\n /**\n * Array of mounted layers, routes & routers.\n *\n * @protected\n */\n protected stack : (Router | Route | Layer)[] = [];\n\n /**\n * Mount path of instance\n *\n * @protected\n */\n protected path : Path | undefined;\n\n /**\n * Path matcher for the current mount path.\n *\n * @protected\n */\n protected pathMatcher : PathMatcher | undefined;\n\n /**\n * Path matcher options.\n *\n * @protected\n */\n protected pathMatcherOptions : PathMatcherOptions;\n\n /**\n * Is this the root instance?\n *\n * @protected\n */\n protected isRoot : boolean | undefined;\n\n /**\n * Timeout before the router decides to abort the request.\n *\n * @protected\n */\n protected timeout: number | undefined;\n\n // --------------------------------------------------\n\n constructor(ctx?: RouterOptions) {\n ctx = ctx || {};\n\n this.pathMatcherOptions = {\n end: false,\n sensitive: true,\n ...(ctx.pathMatcher || {}),\n };\n\n this.timeout = ctx.timeout;\n\n this.setPath(ctx.path || '/');\n }\n\n // --------------------------------------------------\n\n setPathMatcherOptions(input: PathMatcherOptions) {\n this.pathMatcherOptions = input;\n\n if (this.pathMatcher) {\n this.pathMatcher.regexpOptions = this.pathMatcherOptions;\n }\n }\n\n setPath(value: Path) {\n if (value === '/' || !isPath(value)) {\n this.path = '/';\n return;\n }\n\n if (typeof value === 'string') {\n this.path = withLeadingSlash(withoutTrailingSlash(`${value}`));\n } else {\n this.path = value;\n }\n\n this.pathMatcher = new PathMatcher(this.path, this.pathMatcherOptions);\n }\n\n // --------------------------------------------------\n\n createListener() : RequestListener {\n this.isRoot = true;\n\n return (req, res) => {\n this.dispatch(req, res);\n };\n }\n\n /* istanbul ignore next */\n listen(port: number) {\n const server = createServer(this.createListener());\n return server.listen(port);\n }\n\n // --------------------------------------------------\n\n matchPath(path: string) : boolean {\n if (this.pathMatcher) {\n return this.pathMatcher.test(path);\n }\n\n return true;\n }\n\n // --------------------------------------------------\n\n dispatch(\n req: Request,\n res: Response,\n meta?: DispatcherMeta,\n done?: Next,\n ) : void {\n let index = -1;\n\n meta = meta || {};\n\n let allowedMethods : string[] = [];\n\n if (\n this.isRoot &&\n typeof this.timeout === 'number'\n ) {\n createRequestTimeout(res, this.timeout, done);\n }\n\n const fn = (err?: Error) => {\n /* istanbul ignore if */\n if (!this.isRoot) {\n if (typeof done !== 'undefined') {\n setImmediate(() => done(err));\n }\n\n return;\n }\n\n if (typeof err !== 'undefined') {\n res.statusCode = BadRequestErrorOptions.statusCode;\n res.statusMessage = BadRequestErrorOptions.message;\n\n res.end();\n\n return;\n }\n\n if (\n req.method &&\n req.method.toLowerCase() === Method.OPTIONS\n ) {\n const options = allowedMethods\n .map((key) => key.toUpperCase())\n .join(',');\n\n res.setHeader(HeaderName.ALLOW, options);\n send(res, options);\n\n return;\n }\n\n res.statusCode = NotFoundErrorOptions.statusCode;\n res.end();\n };\n\n let path = meta.path || useRequestPath(req);\n\n if (this.pathMatcher) {\n const output = this.pathMatcher.exec(path);\n if (typeof output !== 'undefined') {\n meta.mountPath = cleanDoubleSlashes(`${meta.mountPath || ''}/${output.path}`);\n\n if (path === output.path) {\n path = '/';\n } else {\n path = withLeadingSlash(path.substring(output.path.length));\n }\n\n meta.params = merge(meta.params || {}, output.params);\n }\n }\n\n meta.path = path;\n\n if (!meta.mountPath) {\n meta.mountPath = '/';\n }\n\n const next = (err?: Error) : void => {\n if (index >= this.stack.length) {\n setImmediate(fn, err);\n return;\n }\n\n let layer : Route | Router | Layer | undefined;\n let match = false;\n\n while (!match && index < this.stack.length) {\n index++;\n\n layer = this.stack[index];\n\n if (isLayerInstance(layer)) {\n if (!layer.isError() && err) {\n continue;\n }\n\n match = layer.matchPath(path);\n }\n\n if (isRouterInstance(layer)) {\n match = layer.matchPath(path);\n }\n\n if (isRouteInstance(layer)) {\n match = layer.matchPath(path);\n\n if (\n req.method &&\n !layer.matchMethod(req.method)\n ) {\n match = false;\n\n if (req.method.toLowerCase() === Method.OPTIONS) {\n allowedMethods = mergeArrays(\n allowedMethods,\n layer.getMethods(),\n true,\n );\n }\n }\n }\n }\n\n if (!match || !layer) {\n setImmediate(fn, err);\n return;\n }\n\n const layerMeta : DispatcherMeta = { ...meta };\n\n if (isLayerInstance(layer)) {\n const output = layer.exec(path);\n\n if (output) {\n layerMeta.params = merge(output.params, layerMeta.params || {});\n layerMeta.mountPath = cleanDoubleSlashes(`${layerMeta.mountPath || ''}/${output.path}`);\n }\n }\n\n if (err) {\n if (\n isLayerInstance(layer) &&\n layer.isError()\n ) {\n layer.dispatch(req, res, layerMeta, next, err);\n return;\n }\n\n /* istanbul ignore next */\n setImmediate(next, err);\n return;\n }\n\n layer.dispatch(req, res, layerMeta, next);\n };\n\n next();\n }\n\n /* istanbul ignore next */\n dispatchAsync(\n req: Request,\n res: Response,\n ) : Promise<void> {\n return new Promise((resolve, reject) => {\n this.dispatch(req, res, {}, (err?: Error) => {\n if (err) {\n reject(err);\n return;\n }\n\n resolve();\n });\n });\n }\n\n // --------------------------------------------------\n\n route(\n path: Path,\n ) : Route {\n if (\n typeof path === 'string' &&\n path.length > 0\n ) {\n path = withLeadingSlash(path);\n }\n\n const index = this.stack.findIndex(\n (item) => isRouteInstance(item) && item.path === path,\n );\n\n if (index !== -1) {\n return this.stack[index] as Route;\n }\n\n const route = new Route({\n path,\n pathMatcher: {\n sensitive: this.pathMatcherOptions.sensitive,\n },\n });\n this.stack.push(route);\n\n return route;\n }\n\n delete(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.delete(...handlers);\n\n return this;\n }\n\n get(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.get(...handlers);\n\n return this;\n }\n\n post(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.post(...handlers);\n\n return this;\n }\n\n put(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.put(...handlers);\n\n return this;\n }\n\n patch(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.patch(...handlers);\n\n return this;\n }\n\n head(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.head(...handlers);\n\n return this;\n }\n\n options(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.options(...handlers);\n\n return this;\n }\n\n // --------------------------------------------------\n\n use(router: Router) : this;\n\n use(handler: Handler) : this;\n\n use(handler: ErrorHandler) : this;\n\n use(path: Path, router: Router) : this;\n\n use(path: Path, handler: Handler) : this;\n\n use(path: Path, handler: ErrorHandler) : this;\n\n use(...input: unknown[]) : this {\n /* istanbul ignore next */\n if (input.length === 0) {\n return this;\n }\n\n let path : Path | undefined;\n\n if (isPath(input[0])) {\n path = input.shift() as Path;\n }\n\n for (let i = 0; i < input.length; i++) {\n const item = input[i];\n if (isRouterInstance(item)) {\n if (path) {\n item.setPath(path);\n }\n item.setPathMatcherOptions(this.pathMatcherOptions);\n this.stack.push(item);\n continue;\n }\n\n if (typeof item === 'function') {\n this.stack.push(new Layer({\n path: path || '/',\n pathMatcher: {\n strict: false,\n end: false,\n sensitive: this.pathMatcherOptions.sensitive,\n },\n }, item));\n }\n }\n\n return this;\n }\n}\n"],"names":["isInstance","input","name","isPath","isPromise","p","isObject","createRequestTimeout","res","timeout","done","instance","GatewayTimeoutErrorOptions","e","processHandlerExecutionOutput","next","output","r","send","decodeParam","val","PathMatcher","path","options","pathToRegexp","match","i","prop","Layer","fn","req","meta","err","setRequestParams","setRequestMountPath","BadRequestError","isLayerInstance","Route","__spreadValues","method","Method","hasOwnProperty","keys","layers","layerMeta","merge","index","layer","handlers","isRouteInstance","isRouterInstance","Router","ctx","value","withLeadingSlash","withoutTrailingSlash","port","createServer","allowedMethods","BadRequestErrorOptions","key","HeaderName","NotFoundErrorOptions","useRequestPath","cleanDoubleSlashes","mergeArrays","resolve","reject","item","route"],"mappings":"0gBAOO,SAASA,EAAWC,EAAgBC,EAAc,CACrD,OACI,OAAOD,GAAU,UACjBA,IAAU,MACTA,EAAoC,iBAAmB,OAAO,IAAIC,CAAI,CAE/E,CCJgB,SAAAC,EAAOF,EAAgC,CACnD,OA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B,CAAI,EACvB,MAAM,GAAG0B,CAAQ,EAEhB,IACX,CAEA,KAAK1B,KAAe0B,EAA4B,CAE5C,OADc,KAAK,MAAM1B,CAAI,EACvB,KAAK,GAAG0B,CAAQ,EAEf,IACX,CAEA,QAAQ1B,KAAe0B,EAA4B,CAE/C,OADc,KAAK,MAAM1B,CAAI,EACvB,QAAQ,GAAG0B,CAAQ,EAElB,IACX,CAgBA,OAAO/C,EAAyB,CAE5B,GAAIA,EAAM,SAAW,EACjB,OAAO,KAGX,IAAIqB,EAEAnB,EAAOF,EAAM,EAAE,IACfqB,EAAOrB,EAAM,MAAM,GAGvB,QAASyB,EAAI,EAAGA,EAAIzB,EAAM,OAAQyB,IAAK,CACnC,MAAM0C,EAAOnE,EAAMyB,GACnB,GAAIwB,EAAiBkB,CAAI,EAAG,CACpB9C,GACA8C,EAAK,QAAQ9C,CAAI,EAErB8C,EAAK,sBAAsB,KAAK,kBAAkB,EAClD,KAAK,MAAM,KAAKA,CAAI,EACpB,QACJ,CAEI,OAAOA,GAAS,YAChB,KAAK,MAAM,KAAK,IAAIxC,EAAM,CACtB,KAAMN,GAAQ,IACd,YAAa,CACT,OAAQ,GACR,IAAK,GACL,UAAW,KAAK,mBAAmB,SACvC,CACJ,EAAG8C,CAAI,CAAC,CAEhB,CAEA,OAAO,IACX,CACJ"}
package/package.json CHANGED
@@ -1,14 +1,24 @@
1
1
  {
2
2
  "name": "routup",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Routup is a minimalistic http based routing framework.",
5
- "main": "./dist/index.js",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.mjs",
6
7
  "typings": "dist/index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "require": "./dist/index.cjs",
12
+ "import": "./dist/index.mjs"
13
+ }
14
+ },
7
15
  "files": [
8
16
  "dist/"
9
17
  ],
10
18
  "scripts": {
11
- "build": "rimraf ./dist && tsc -p tsconfig.build.json",
19
+ "build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
20
+ "build:js": "rollup -c",
21
+ "build": "rimraf ./dist && cross-env NODE_ENV=production npm run build:js && npm run build:types",
12
22
  "test": "cross-env NODE_ENV=test jest --config ./test/jest.config.js",
13
23
  "test:coverage": "cross-env NODE_ENV=test jest --config ./test/jest.config.js --coverage",
14
24
  "lint": "eslint --ext .js,.ts ./src",
@@ -38,15 +48,18 @@
38
48
  "url": "https://github.com/Tada5hi/routup/issues"
39
49
  },
40
50
  "homepage": "https://github.com/Tada5hi/routup#readme",
51
+ "peerDependencies": {
52
+ "@routup/core": ">=0.5.0 <1.0.0"
53
+ },
41
54
  "dependencies": {
42
55
  "@ebec/http": "^0.1.0",
43
- "@routup/core": "^0.4.0",
44
56
  "path-to-regexp": "^6.2.1",
45
- "smob": "^0.0.6"
57
+ "smob": "^0.0.7"
46
58
  },
47
59
  "devDependencies": {
60
+ "@routup/core": "^0.5.0",
48
61
  "@types/supertest": "^2.0.12",
49
62
  "supertest": "^6.3.3"
50
63
  },
51
- "gitHead": "f4e5ac3f6604b4281cc6e4557a862bfcfe25f5b6"
64
+ "gitHead": "3aac0797ad68a1e748f819ffbf0423168a4906ae"
52
65
  }
@@ -1,24 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- __exportStar(require("./utils"), exports);
24
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/handler/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,0CAAwB"}
@@ -1,29 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022-2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.processHandlerExecutionOutput = void 0;
10
- const core_1 = require("@routup/core");
11
- const utils_1 = require("../utils");
12
- function processHandlerExecutionOutput(res, next, output) {
13
- if ((0, utils_1.isPromise)(output)) {
14
- output
15
- .then((r) => {
16
- if (typeof r !== 'undefined') {
17
- (0, core_1.send)(res, r);
18
- }
19
- return r;
20
- })
21
- .catch(next);
22
- return;
23
- }
24
- if (typeof output !== 'undefined') {
25
- (0, core_1.send)(res, output);
26
- }
27
- }
28
- exports.processHandlerExecutionOutput = processHandlerExecutionOutput;
29
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/handler/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uCAAoD;AACpD,oCAAqC;AAErC,SAAgB,6BAA6B,CAAC,GAAa,EAAE,IAAU,EAAE,MAAgB;IACrF,IAAI,IAAA,iBAAS,EAAC,MAAM,CAAC,EAAE;QACnB,MAAM;aACD,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACR,IAAI,OAAO,CAAC,KAAK,WAAW,EAAE;gBAC1B,IAAA,WAAI,EAAC,GAAG,EAAE,CAAC,CAAC,CAAC;aAChB;YAED,OAAO,CAAC,CAAC;QACb,CAAC,CAAC;aACD,KAAK,CAAC,IAAI,CAAC,CAAC;QACjB,OAAO;KACV;IAED,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QAC/B,IAAA,WAAI,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;KACrB;AACL,CAAC;AAjBD,sEAiBC"}
package/dist/index.js DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- __exportStar(require("./handler"), exports);
24
- __exportStar(require("./layer"), exports);
25
- __exportStar(require("./path"), exports);
26
- __exportStar(require("./route"), exports);
27
- __exportStar(require("./router"), exports);
28
- __exportStar(require("./type"), exports);
29
- __exportStar(require("./utils"), exports);
30
- __exportStar(require("@routup/core"), exports);
31
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,4CAA0B;AAC1B,0CAAwB;AACxB,yCAAuB;AACvB,0CAAwB;AACxB,2CAAyB;AACzB,yCAAuB;AACvB,0CAAwB;AAExB,+CAA6B"}
@@ -1,26 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- __exportStar(require("./module"), exports);
24
- __exportStar(require("./type"), exports);
25
- __exportStar(require("./utils"), exports);
26
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/layer/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,yCAAuB;AACvB,0CAAwB"}
@@ -1,82 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.Layer = void 0;
10
- const http_1 = require("@ebec/http");
11
- const core_1 = require("@routup/core");
12
- const handler_1 = require("../handler");
13
- const path_1 = require("../path");
14
- class Layer {
15
- // --------------------------------------------------
16
- constructor(options, fn) {
17
- this['@instanceof'] = Symbol.for('Layer');
18
- this.pathMatcher = new path_1.PathMatcher(options.path, options.pathMatcher);
19
- this.fn = fn;
20
- }
21
- // --------------------------------------------------
22
- isError() {
23
- return this.fn.length === 4;
24
- }
25
- dispatch(req, res, meta, next, err) {
26
- (0, core_1.setRequestParams)(req, meta.params || {});
27
- (0, core_1.setRequestMountPath)(req, meta.mountPath || '/');
28
- if (typeof err !== 'undefined') {
29
- if (this.fn.length === 4) {
30
- try {
31
- this.fn(err, req, res, next);
32
- }
33
- catch (e) {
34
- /* istanbul ignore next */
35
- /* istanbul ignore next */
36
- if (e instanceof Error) {
37
- next(e);
38
- }
39
- else {
40
- next(new http_1.BadRequestError({
41
- message: 'The request could not be processed by the error handler.',
42
- }));
43
- }
44
- }
45
- return;
46
- }
47
- /* istanbul ignore next */
48
- next(err);
49
- /* istanbul ignore next */
50
- return;
51
- }
52
- /* istanbul ignore next */
53
- if (this.fn.length > 3) {
54
- next();
55
- return;
56
- }
57
- try {
58
- const output = this.fn(req, res, next);
59
- (0, handler_1.processHandlerExecutionOutput)(res, next, output);
60
- }
61
- catch (e) {
62
- /* istanbul ignore next */
63
- if (e instanceof Error) {
64
- next(e);
65
- }
66
- else {
67
- next(new http_1.BadRequestError({
68
- message: 'The request could not be processed by the handler.',
69
- }));
70
- }
71
- }
72
- }
73
- // --------------------------------------------------
74
- matchPath(path) {
75
- return this.pathMatcher.test(path);
76
- }
77
- exec(path) {
78
- return this.pathMatcher.exec(path);
79
- }
80
- }
81
- exports.Layer = Layer;
82
- //# sourceMappingURL=module.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/layer/module.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,qCAA6C;AAC7C,uCAEsB;AACtB,wCAA2D;AAC3D,kCAAsC;AAMtC,MAAa,KAAK;IAOd,qDAAqD;IAErD,YACI,OAAqB,EACrB,EAAoB;QAVf,mBAAa,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAYzC,IAAI,CAAC,WAAW,GAA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YAEvC,IAAA,uCAA6B,EAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;SACpD;QAAC,OAAO,CAAC,EAAE;YACR,0BAA0B;YAC1B,IAAI,CAAC,YAAY,KAAK,EAAE;gBACpB,IAAI,CAAC,CAAC,CAAC,CAAC;aACX;iBAAM;gBACH,IAAI,CAAC,IAAI,sBAAe,CAAC;oBACrB,OAAO,EAAE,oDAAoD;iBAChE,CAAC,CAAC,CAAC;aACP;SACJ;IACL,CAAC;IAED,qDAAqD;IAErD,SAAS,CAAC,IAAY;QAClB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,CAAC,IAAY;QACb,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACJ;AA1GD,sBA0GC"}
@@ -1,9 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- //# sourceMappingURL=type.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/layer/type.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
@@ -1,15 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.isLayerInstance = void 0;
10
- const utils_1 = require("../utils");
11
- function isLayerInstance(input) {
12
- return (0, utils_1.isInstance)(input, 'Layer');
13
- }
14
- exports.isLayerInstance = isLayerInstance;
15
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/layer/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,oCAAsC;AAGtC,SAAgB,eAAe,CAAC,KAAc;IAC1C,OAAO,IAAA,kBAAU,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACtC,CAAC;AAFD,0CAEC"}
@@ -1,25 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- __exportStar(require("./matcher"), exports);
24
- __exportStar(require("./type"), exports);
25
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/path/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,4CAA0B;AAC1B,yCAAuB"}