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.cjs CHANGED
@@ -781,6 +781,15 @@ function serializeEventStreamMessage(message) {
781
781
  }
782
782
 
783
783
  class EventStream {
784
+ constructor(response){
785
+ this.response = response;
786
+ this.passThrough = new readableStream.PassThrough({
787
+ encoding: 'utf-8'
788
+ });
789
+ this.flushed = false;
790
+ this.eventHandlers = {};
791
+ this.open();
792
+ }
784
793
  open() {
785
794
  this.response.req.on('close', ()=>this.end());
786
795
  this.response.req.on('error', (err)=>{
@@ -837,15 +846,6 @@ class EventStream {
837
846
  listeners[i].apply(this, args);
838
847
  }
839
848
  }
840
- constructor(response){
841
- this.response = response;
842
- this.passThrough = new readableStream.PassThrough({
843
- encoding: 'utf-8'
844
- });
845
- this.flushed = false;
846
- this.eventHandlers = {};
847
- this.open();
848
- }
849
849
  }
850
850
 
851
851
  function createEventStream(response) {
@@ -1430,12 +1430,6 @@ function isDispatcherErrorEvent(event) {
1430
1430
  }
1431
1431
 
1432
1432
  class DispatchEvent {
1433
- get dispatched() {
1434
- return this._dispatched || this.response.writableEnded || this.response.headersSent;
1435
- }
1436
- set dispatched(value) {
1437
- this._dispatched = value;
1438
- }
1439
1433
  constructor(context){
1440
1434
  this.request = context.request;
1441
1435
  this.response = context.response;
@@ -1447,6 +1441,12 @@ class DispatchEvent {
1447
1441
  this.routerPath = [];
1448
1442
  this.next = nextPlaceholder;
1449
1443
  }
1444
+ get dispatched() {
1445
+ return this._dispatched || this.response.writableEnded || this.response.headersSent;
1446
+ }
1447
+ set dispatched(value) {
1448
+ this._dispatched = value;
1449
+ }
1450
1450
  }
1451
1451
 
1452
1452
  class DispatchErrorEvent extends DispatchEvent {
@@ -1608,6 +1608,10 @@ var HookName = /*#__PURE__*/ function(HookName) {
1608
1608
  }({});
1609
1609
 
1610
1610
  class HookManager {
1611
+ // --------------------------------------------------
1612
+ constructor(){
1613
+ this.items = {};
1614
+ }
1611
1615
  // --------------------------------------------------
1612
1616
  addListener(name, fn) {
1613
1617
  this.items[name] = this.items[name] || [];
@@ -1683,10 +1687,6 @@ class HookManager {
1683
1687
  isErrorListenerHook(input) {
1684
1688
  return input === HookName.ERROR;
1685
1689
  }
1686
- // --------------------------------------------------
1687
- constructor(){
1688
- this.items = {};
1689
- }
1690
1690
  }
1691
1691
 
1692
1692
  function decodeParam(val) {
@@ -1696,6 +1696,14 @@ function decodeParam(val) {
1696
1696
  return decodeURIComponent(val);
1697
1697
  }
1698
1698
  class PathMatcher {
1699
+ constructor(path, options){
1700
+ this.regexpKeys = [];
1701
+ this.path = path;
1702
+ this.regexpOptions = options || {};
1703
+ const regexp = pathToRegexp.pathToRegexp(path, options);
1704
+ this.regexp = regexp.regexp;
1705
+ this.regexpKeys = regexp.keys;
1706
+ }
1699
1707
  test(path) {
1700
1708
  return this.regexp.test(path);
1701
1709
  }
@@ -1732,14 +1740,6 @@ class PathMatcher {
1732
1740
  params
1733
1741
  };
1734
1742
  }
1735
- constructor(path, options){
1736
- this.regexpKeys = [];
1737
- this.path = path;
1738
- this.regexpOptions = options || {};
1739
- const regexp = pathToRegexp.pathToRegexp(path, options);
1740
- this.regexp = regexp.regexp;
1741
- this.regexpKeys = regexp.keys;
1742
- }
1743
1743
  }
1744
1744
 
1745
1745
  function isPath(input) {
@@ -1747,6 +1747,14 @@ function isPath(input) {
1747
1747
  }
1748
1748
 
1749
1749
  class Handler {
1750
+ // --------------------------------------------------
1751
+ constructor(handler){
1752
+ this['@instanceof'] = HandlerSymbol;
1753
+ this.config = handler;
1754
+ this.hookManager = new HookManager();
1755
+ this.mountHooks();
1756
+ this.setPath(handler.path);
1757
+ }
1750
1758
  // --------------------------------------------------
1751
1759
  get type() {
1752
1760
  return this.config.type;
@@ -1841,14 +1849,6 @@ class Handler {
1841
1849
  this.hookManager.addListener(HookName.ERROR, this.config.onError);
1842
1850
  }
1843
1851
  }
1844
- // --------------------------------------------------
1845
- constructor(handler){
1846
- this['@instanceof'] = HandlerSymbol;
1847
- this.config = handler;
1848
- this.hookManager = new HookManager();
1849
- this.mountHooks();
1850
- this.setPath(handler.path);
1851
- }
1852
1852
  }
1853
1853
 
1854
1854
  function coreHandler(input) {
@@ -1924,6 +1924,20 @@ function isRouterInstance(input) {
1924
1924
  }
1925
1925
 
1926
1926
  class Router {
1927
+ // --------------------------------------------------
1928
+ constructor(options = {}){
1929
+ this['@instanceof'] = RouterSymbol;
1930
+ /**
1931
+ * Array of mounted layers, routes & routers.
1932
+ *
1933
+ * @protected
1934
+ */ this.stack = [];
1935
+ this.id = generateRouterID();
1936
+ this.name = options.name;
1937
+ this.hookManager = new HookManager();
1938
+ this.setPath(options.path);
1939
+ setRouterOptions(this.id, transformRouterOptions(options));
1940
+ }
1927
1941
  // --------------------------------------------------
1928
1942
  matchPath(path) {
1929
1943
  if (this.pathMatcher) {
@@ -2217,20 +2231,6 @@ class Router {
2217
2231
  this.hookManager.removeListener(name, fn);
2218
2232
  return this;
2219
2233
  }
2220
- // --------------------------------------------------
2221
- constructor(options = {}){
2222
- this['@instanceof'] = RouterSymbol;
2223
- /**
2224
- * Array of mounted layers, routes & routers.
2225
- *
2226
- * @protected
2227
- */ this.stack = [];
2228
- this.id = generateRouterID();
2229
- this.name = options.name;
2230
- this.hookManager = new HookManager();
2231
- this.setPath(options.path);
2232
- setRouterOptions(this.id, transformRouterOptions(options));
2233
- }
2234
2234
  }
2235
2235
 
2236
2236
  exports.DispatchErrorEvent = DispatchErrorEvent;