@loomcore/api 0.1.50 → 0.1.52

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.
@@ -10,7 +10,7 @@ export declare class MigrationRunner {
10
10
  private parseSql;
11
11
  private getMigrator;
12
12
  private wipeDatabase;
13
- run(command: 'up' | 'down' | 'reset', target?: string): Promise<void>;
13
+ run(command?: 'up' | 'down' | 'reset', target?: string): Promise<void>;
14
14
  private closeConnection;
15
15
  create(name: string): Promise<void>;
16
16
  }
@@ -121,7 +121,7 @@ export class MigrationRunner {
121
121
  }
122
122
  console.log('✅ Database wiped.');
123
123
  }
124
- async run(command, target) {
124
+ async run(command = 'up', target) {
125
125
  try {
126
126
  if (command === 'reset') {
127
127
  await this.wipeDatabase();
@@ -1,6 +1,6 @@
1
1
  import { Request, Response, NextFunction } from 'express';
2
2
  export interface RequestLifecycleOptions {
3
3
  onRequestStart?: (req: Request, res: Response) => void | Promise<void>;
4
- onRequestEnd?: (req: Request, res: Response, error?: Error) => void | Promise<void>;
4
+ onRequestEnd?: (req: Request, res: Response, duration: number, error?: Error) => void | Promise<void>;
5
5
  }
6
6
  export declare const requestLifecycle: (options?: RequestLifecycleOptions) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
@@ -1,7 +1,7 @@
1
1
  export const requestLifecycle = (options = {}) => {
2
2
  const { onRequestStart, onRequestEnd } = options;
3
3
  return async (req, res, next) => {
4
- req.startTime = Date.now();
4
+ const startTime = Date.now();
5
5
  if (onRequestStart) {
6
6
  try {
7
7
  await onRequestStart(req, res);
@@ -17,7 +17,8 @@ export const requestLifecycle = (options = {}) => {
17
17
  endCallbackCalled = true;
18
18
  if (onRequestEnd) {
19
19
  try {
20
- await onRequestEnd(req, res, error);
20
+ const duration = Date.now() - startTime;
21
+ await onRequestEnd(req, res, duration, error);
21
22
  }
22
23
  catch (callbackError) {
23
24
  console.error('Error in onRequestEnd callback:', callbackError);
@@ -25,21 +26,13 @@ export const requestLifecycle = (options = {}) => {
25
26
  }
26
27
  };
27
28
  res.on('finish', () => {
28
- const error = req.lifecycleError;
29
- callOnRequestEnd(error);
29
+ callOnRequestEnd();
30
30
  });
31
31
  res.on('close', () => {
32
32
  if (!res.writableEnded && !endCallbackCalled) {
33
- const error = req.lifecycleError || new Error('Request closed before completion');
34
- callOnRequestEnd(error);
33
+ callOnRequestEnd(new Error('Request closed before completion'));
35
34
  }
36
35
  });
37
- try {
38
- await next();
39
- }
40
- catch (error) {
41
- req.lifecycleError = error instanceof Error ? error : new Error(String(error));
42
- throw error;
43
- }
36
+ next();
44
37
  };
45
38
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.1.50",
3
+ "version": "0.1.52",
4
4
  "private": false,
5
5
  "description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb or PostgreSQL",
6
6
  "scripts": {