@wooksjs/event-http 0.4.35 → 0.4.36

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
@@ -579,7 +579,7 @@ class HttpErrorRenderer extends BaseHttpResponseRenderer {
579
579
  `<head><title>${data.statusCode} ${httpStatusCodes[data.statusCode]}</title></head>` +
580
580
  `<body><center><h1>${data.statusCode} ${httpStatusCodes[data.statusCode]}</h1></center>` +
581
581
  `<center><h4>${data.message}</h1></center><hr color="#666">` +
582
- `<center style="color: #666;"> Wooks v${"0.4.35"} </center>` +
582
+ `<center style="color: #666;"> Wooks v${"0.4.36"} </center>` +
583
583
  `${keys.length > 0
584
584
  ? `<pre style="${preStyles}">${JSON.stringify({
585
585
  ...data,
@@ -950,7 +950,7 @@ class WooksHttp extends wooks.WooksAdapterBase {
950
950
  }
951
951
  getServerCb() {
952
952
  return async (req, res) => {
953
- const { restoreCtx, clearCtx } = createHttpContext({ req, res }, this.mergeEventOptions(this.opts?.eventOptions));
953
+ const { restoreCtx, endEvent } = createHttpContext({ req, res }, this.mergeEventOptions(this.opts?.eventOptions));
954
954
  const { handlers } = this.wooks.lookup(req.method, req.url);
955
955
  if (handlers || this.opts?.onNotFound) {
956
956
  try {
@@ -960,18 +960,18 @@ class WooksHttp extends wooks.WooksAdapterBase {
960
960
  this.logger.error('Internal error, please report', error);
961
961
  restoreCtx();
962
962
  this.respond(error);
963
- clearCtx();
963
+ endEvent(error.message);
964
964
  }
965
965
  }
966
966
  else {
967
967
  this.logger.debug(`404 Not found (${req.method})${req.url}`);
968
968
  this.respond(new HttpError(404));
969
- clearCtx();
969
+ endEvent('Request handler not registered');
970
970
  }
971
971
  };
972
972
  }
973
973
  async processHandlers(handlers) {
974
- const { restoreCtx, clearCtx, store } = useHttpContext();
974
+ const { restoreCtx, endEvent, clearCtx, store } = useHttpContext();
975
975
  for (const [i, handler] of handlers.entries()) {
976
976
  const isLastHandler = handlers.length === i + 1;
977
977
  try {
@@ -981,7 +981,7 @@ class WooksHttp extends wooks.WooksAdapterBase {
981
981
  const result = await promise;
982
982
  restoreCtx();
983
983
  this.respond(result);
984
- clearCtx();
984
+ endEvent();
985
985
  break;
986
986
  }
987
987
  catch (error) {
@@ -994,7 +994,7 @@ class WooksHttp extends wooks.WooksAdapterBase {
994
994
  if (isLastHandler) {
995
995
  restoreCtx();
996
996
  this.respond(error);
997
- clearCtx();
997
+ endEvent(error.message);
998
998
  }
999
999
  }
1000
1000
  }
package/dist/index.d.ts CHANGED
@@ -383,6 +383,7 @@ declare function createHttpContext(data: THttpEventData, options: TEventOptions)
383
383
  getCtx: () => THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>;
384
384
  restoreCtx: () => _wooksjs_event_core.TGenericContextStore<TEmpty>;
385
385
  clearCtx: () => null;
386
+ endEvent: (abortReason?: string | undefined) => void;
386
387
  store: <K extends keyof THttpContextStore | keyof _wooksjs_event_core.TGenericContextStore<THttpEventData>>(key: K) => {
387
388
  value: (THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>)[K];
388
389
  hook: <K2 extends keyof Required<THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2) => {
@@ -410,6 +411,7 @@ declare function useHttpContext<T extends TEmpty>(): {
410
411
  getCtx: () => THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>;
411
412
  restoreCtx: () => _wooksjs_event_core.TGenericContextStore<TEmpty>;
412
413
  clearCtx: () => null;
414
+ endEvent: (abortReason?: string | undefined) => void;
413
415
  store: <K extends keyof THttpContextStore | keyof _wooksjs_event_core.TGenericContextStore<THttpEventData> | keyof T>(key: K) => {
414
416
  value: (THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>)[K];
415
417
  hook: <K2 extends keyof Required<THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2) => {
package/dist/index.mjs CHANGED
@@ -577,7 +577,7 @@ class HttpErrorRenderer extends BaseHttpResponseRenderer {
577
577
  `<head><title>${data.statusCode} ${httpStatusCodes[data.statusCode]}</title></head>` +
578
578
  `<body><center><h1>${data.statusCode} ${httpStatusCodes[data.statusCode]}</h1></center>` +
579
579
  `<center><h4>${data.message}</h1></center><hr color="#666">` +
580
- `<center style="color: #666;"> Wooks v${"0.4.35"} </center>` +
580
+ `<center style="color: #666;"> Wooks v${"0.4.36"} </center>` +
581
581
  `${keys.length > 0
582
582
  ? `<pre style="${preStyles}">${JSON.stringify({
583
583
  ...data,
@@ -948,7 +948,7 @@ class WooksHttp extends WooksAdapterBase {
948
948
  }
949
949
  getServerCb() {
950
950
  return async (req, res) => {
951
- const { restoreCtx, clearCtx } = createHttpContext({ req, res }, this.mergeEventOptions(this.opts?.eventOptions));
951
+ const { restoreCtx, endEvent } = createHttpContext({ req, res }, this.mergeEventOptions(this.opts?.eventOptions));
952
952
  const { handlers } = this.wooks.lookup(req.method, req.url);
953
953
  if (handlers || this.opts?.onNotFound) {
954
954
  try {
@@ -958,18 +958,18 @@ class WooksHttp extends WooksAdapterBase {
958
958
  this.logger.error('Internal error, please report', error);
959
959
  restoreCtx();
960
960
  this.respond(error);
961
- clearCtx();
961
+ endEvent(error.message);
962
962
  }
963
963
  }
964
964
  else {
965
965
  this.logger.debug(`404 Not found (${req.method})${req.url}`);
966
966
  this.respond(new HttpError(404));
967
- clearCtx();
967
+ endEvent('Request handler not registered');
968
968
  }
969
969
  };
970
970
  }
971
971
  async processHandlers(handlers) {
972
- const { restoreCtx, clearCtx, store } = useHttpContext();
972
+ const { restoreCtx, endEvent, clearCtx, store } = useHttpContext();
973
973
  for (const [i, handler] of handlers.entries()) {
974
974
  const isLastHandler = handlers.length === i + 1;
975
975
  try {
@@ -979,7 +979,7 @@ class WooksHttp extends WooksAdapterBase {
979
979
  const result = await promise;
980
980
  restoreCtx();
981
981
  this.respond(result);
982
- clearCtx();
982
+ endEvent();
983
983
  break;
984
984
  }
985
985
  catch (error) {
@@ -992,7 +992,7 @@ class WooksHttp extends WooksAdapterBase {
992
992
  if (isLastHandler) {
993
993
  restoreCtx();
994
994
  this.respond(error);
995
- clearCtx();
995
+ endEvent(error.message);
996
996
  }
997
997
  }
998
998
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-http",
3
- "version": "0.4.35",
3
+ "version": "0.4.36",
4
4
  "description": "@wooksjs/event-http",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -39,9 +39,9 @@
39
39
  "url": "https://github.com/wooksjs/wooksjs/issues"
40
40
  },
41
41
  "peerDependencies": {
42
- "wooks": "0.4.35",
42
+ "wooks": "0.4.36",
43
43
  "@prostojs/router": "^0.2.1",
44
- "@wooksjs/event-core": "0.4.35"
44
+ "@wooksjs/event-core": "0.4.36"
45
45
  },
46
46
  "dependencies": {
47
47
  "@prostojs/logger": "^0.4.0"