routup 4.0.2 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -779,6 +779,15 @@ function serializeEventStreamMessage(message) {
779
779
  }
780
780
 
781
781
  class EventStream {
782
+ constructor(response){
783
+ this.response = response;
784
+ this.passThrough = new PassThrough({
785
+ encoding: 'utf-8'
786
+ });
787
+ this.flushed = false;
788
+ this.eventHandlers = {};
789
+ this.open();
790
+ }
782
791
  open() {
783
792
  this.response.req.on('close', ()=>this.end());
784
793
  this.response.req.on('error', (err)=>{
@@ -835,15 +844,6 @@ class EventStream {
835
844
  listeners[i].apply(this, args);
836
845
  }
837
846
  }
838
- constructor(response){
839
- this.response = response;
840
- this.passThrough = new PassThrough({
841
- encoding: 'utf-8'
842
- });
843
- this.flushed = false;
844
- this.eventHandlers = {};
845
- this.open();
846
- }
847
847
  }
848
848
 
849
849
  function createEventStream(response) {
@@ -1428,12 +1428,6 @@ function isDispatcherErrorEvent(event) {
1428
1428
  }
1429
1429
 
1430
1430
  class DispatchEvent {
1431
- get dispatched() {
1432
- return this._dispatched || this.response.writableEnded || this.response.headersSent;
1433
- }
1434
- set dispatched(value) {
1435
- this._dispatched = value;
1436
- }
1437
1431
  constructor(context){
1438
1432
  this.request = context.request;
1439
1433
  this.response = context.response;
@@ -1445,6 +1439,12 @@ class DispatchEvent {
1445
1439
  this.routerPath = [];
1446
1440
  this.next = nextPlaceholder;
1447
1441
  }
1442
+ get dispatched() {
1443
+ return this._dispatched || this.response.writableEnded || this.response.headersSent;
1444
+ }
1445
+ set dispatched(value) {
1446
+ this._dispatched = value;
1447
+ }
1448
1448
  }
1449
1449
 
1450
1450
  class DispatchErrorEvent extends DispatchEvent {
@@ -1606,6 +1606,10 @@ var HookName = /*#__PURE__*/ function(HookName) {
1606
1606
  }({});
1607
1607
 
1608
1608
  class HookManager {
1609
+ // --------------------------------------------------
1610
+ constructor(){
1611
+ this.items = {};
1612
+ }
1609
1613
  // --------------------------------------------------
1610
1614
  addListener(name, fn) {
1611
1615
  this.items[name] = this.items[name] || [];
@@ -1681,10 +1685,6 @@ class HookManager {
1681
1685
  isErrorListenerHook(input) {
1682
1686
  return input === HookName.ERROR;
1683
1687
  }
1684
- // --------------------------------------------------
1685
- constructor(){
1686
- this.items = {};
1687
- }
1688
1688
  }
1689
1689
 
1690
1690
  function decodeParam(val) {
@@ -1694,6 +1694,14 @@ function decodeParam(val) {
1694
1694
  return decodeURIComponent(val);
1695
1695
  }
1696
1696
  class PathMatcher {
1697
+ constructor(path, options){
1698
+ this.regexpKeys = [];
1699
+ this.path = path;
1700
+ this.regexpOptions = options || {};
1701
+ const regexp = pathToRegexp(path, options);
1702
+ this.regexp = regexp.regexp;
1703
+ this.regexpKeys = regexp.keys;
1704
+ }
1697
1705
  test(path) {
1698
1706
  return this.regexp.test(path);
1699
1707
  }
@@ -1730,14 +1738,6 @@ class PathMatcher {
1730
1738
  params
1731
1739
  };
1732
1740
  }
1733
- constructor(path, options){
1734
- this.regexpKeys = [];
1735
- this.path = path;
1736
- this.regexpOptions = options || {};
1737
- const regexp = pathToRegexp(path, options);
1738
- this.regexp = regexp.regexp;
1739
- this.regexpKeys = regexp.keys;
1740
- }
1741
1741
  }
1742
1742
 
1743
1743
  function isPath(input) {
@@ -1745,6 +1745,14 @@ function isPath(input) {
1745
1745
  }
1746
1746
 
1747
1747
  class Handler {
1748
+ // --------------------------------------------------
1749
+ constructor(handler){
1750
+ this['@instanceof'] = HandlerSymbol;
1751
+ this.config = handler;
1752
+ this.hookManager = new HookManager();
1753
+ this.mountHooks();
1754
+ this.setPath(handler.path);
1755
+ }
1748
1756
  // --------------------------------------------------
1749
1757
  get type() {
1750
1758
  return this.config.type;
@@ -1839,14 +1847,6 @@ class Handler {
1839
1847
  this.hookManager.addListener(HookName.ERROR, this.config.onError);
1840
1848
  }
1841
1849
  }
1842
- // --------------------------------------------------
1843
- constructor(handler){
1844
- this['@instanceof'] = HandlerSymbol;
1845
- this.config = handler;
1846
- this.hookManager = new HookManager();
1847
- this.mountHooks();
1848
- this.setPath(handler.path);
1849
- }
1850
1850
  }
1851
1851
 
1852
1852
  function coreHandler(input) {
@@ -1922,6 +1922,20 @@ function isRouterInstance(input) {
1922
1922
  }
1923
1923
 
1924
1924
  class Router {
1925
+ // --------------------------------------------------
1926
+ constructor(options = {}){
1927
+ this['@instanceof'] = RouterSymbol;
1928
+ /**
1929
+ * Array of mounted layers, routes & routers.
1930
+ *
1931
+ * @protected
1932
+ */ this.stack = [];
1933
+ this.id = generateRouterID();
1934
+ this.name = options.name;
1935
+ this.hookManager = new HookManager();
1936
+ this.setPath(options.path);
1937
+ setRouterOptions(this.id, transformRouterOptions(options));
1938
+ }
1925
1939
  // --------------------------------------------------
1926
1940
  matchPath(path) {
1927
1941
  if (this.pathMatcher) {
@@ -2215,20 +2229,6 @@ class Router {
2215
2229
  this.hookManager.removeListener(name, fn);
2216
2230
  return this;
2217
2231
  }
2218
- // --------------------------------------------------
2219
- constructor(options = {}){
2220
- this['@instanceof'] = RouterSymbol;
2221
- /**
2222
- * Array of mounted layers, routes & routers.
2223
- *
2224
- * @protected
2225
- */ this.stack = [];
2226
- this.id = generateRouterID();
2227
- this.name = options.name;
2228
- this.hookManager = new HookManager();
2229
- this.setPath(options.path);
2230
- setRouterOptions(this.id, transformRouterOptions(options));
2231
- }
2232
2232
  }
2233
2233
 
2234
2234
  export { DispatchErrorEvent, DispatchEvent, EventStream, Handler, HandlerSymbol, HandlerType, HeaderName, MethodName, PathMatcher, Router, RoutupError, appendResponseHeader, appendResponseHeaderDirective, coreHandler, createError, createEventStream, createNodeDispatcher, createRawDispatcher, createRequest, createResponse, createWebDispatcher, dispatch, dispatchNodeRequest, dispatchRawRequest, dispatchWebRequest, errorHandler, getRequestAcceptableCharset, getRequestAcceptableCharsets, getRequestAcceptableContentType, getRequestAcceptableContentTypes, getRequestAcceptableEncoding, getRequestAcceptableEncodings, getRequestAcceptableLanguage, getRequestAcceptableLanguages, getRequestHeader, getRequestHostName, getRequestIP, getRequestProtocol, isDispatcherErrorEvent, isError, isHandler, isHandlerConfig, isPath, isPlugin, isRequestCacheable, isRequestHTTP2, isResponseGone, matchRequestContentType, send, sendAccepted, sendCreated, sendFile, sendFormat, sendRedirect, sendStream, sendWebBlob, sendWebResponse, setRequestEnv, setRequestHeader, setRequestMountPath, setRequestParam, setRequestParams, setRequestRouterPath, setResponseCacheHeaders, setResponseContentTypeByFileName, setResponseGone, setResponseHeaderAttachment, setResponseHeaderContentType, transformHeaderToTuples, transformHeadersToTuples, unsetRequestEnv, useRequestEnv, useRequestMountPath, useRequestNegotiator, useRequestParam, useRequestParams, useRequestPath, useRequestRouterPath };