@common-stack/frontend-stack-react 4.0.1-alpha.22 → 4.0.1-alpha.24

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.
@@ -1,3 +1,3 @@
1
1
  import 'reflect-metadata';
2
- import { IAppLoadContext } from './interfaces/loaderContext';
2
+ import { IAppLoadContext } from '@common-stack/client-core';
3
3
  export declare const loadContext: (req: Request, res: Response) => Promise<IAppLoadContext>;
@@ -1,5 +1,12 @@
1
- import { IAppLoadContext } from '../interfaces/loaderContext';
1
+ import { IAppLoadContext } from '@common-stack/client-core';
2
2
  import { Middleware, MiddlewareOptions } from '../interfaces/middleware';
3
+ /**
4
+ * Executes the middleware stack in sequence
5
+ * @param params - The loader context
6
+ * @param middlewareOptions - The middleware options
7
+ * @param middlewareStack - The middleware stack
8
+ * @returns The middleware options
9
+ */
3
10
  export declare function loaderWithMiddleware(params: {
4
11
  context: IAppLoadContext;
5
12
  }, middlewareOptions: MiddlewareOptions | undefined, middlewareStack: Middleware[]): Promise<MiddlewareOptions>;
@@ -1,4 +1,10 @@
1
- const isDevelopment = process.env.NODE_ENV === 'development';
1
+ /**
2
+ * Executes the middleware stack in sequence
3
+ * @param params - The loader context
4
+ * @param middlewareOptions - The middleware options
5
+ * @param middlewareStack - The middleware stack
6
+ * @returns The middleware options
7
+ */
2
8
  async function loaderWithMiddleware(params, middlewareOptions, middlewareStack) {
3
9
  const { logger } = params.context;
4
10
  logger.debug('middlewares [%j]', middlewareStack);
@@ -7,15 +13,11 @@ async function loaderWithMiddleware(params, middlewareOptions, middlewareStack)
7
13
  if (index < middlewareStack.length) {
8
14
  const middleware = middlewareStack[index];
9
15
  const start = process.hrtime(); // Get start time
10
- if (isDevelopment) {
11
- console.log(`[[Middleware ${middleware.name}]] starts to run`); // Log start
12
- }
16
+ logger.debug(`[[Middleware ${middleware.name}]] starts to run`);
13
17
  await middleware.func(params, loaderData, async () => await executeMiddlewares(index + 1));
14
- if (isDevelopment) {
15
- const end = process.hrtime(start); // Get end time
16
- const elapsedTime = (end[0] * 1e9 + end[1]) / 1e6; // Convert to milliseconds
17
- console.log(`[[Middleware ${middleware.name}]] took ${elapsedTime} ms`); // Log time taken
18
- }
18
+ const end = process.hrtime(start); // Get end time
19
+ const elapsedTime = (end[0] * 1e9 + end[1]) / 1e6; // Convert to milliseconds
20
+ logger.debug(`[[Middleware ${middleware.name}]] took ${elapsedTime} ms`);
19
21
  }
20
22
  };
21
23
  await executeMiddlewares(0); // Start middleware execution from the first one
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@common-stack/frontend-stack-react",
3
- "version": "4.0.1-alpha.22",
3
+ "version": "4.0.1-alpha.24",
4
4
  "description": "Client Module for react app",
5
5
  "homepage": "https://github.com/cdmbase/fullstack-pro#readme",
6
6
  "bugs": {
@@ -29,7 +29,7 @@
29
29
  "watch": "npm run build:lib:watch"
30
30
  },
31
31
  "dependencies": {
32
- "@common-stack/client-react": "4.0.1-alpha.11",
32
+ "@common-stack/client-react": "4.0.1-alpha.24",
33
33
  "@common-stack/core": "4.0.1-alpha.11"
34
34
  },
35
35
  "devDependencies": {
@@ -50,5 +50,5 @@
50
50
  "typescript": {
51
51
  "definition": "lib/index.d.ts"
52
52
  },
53
- "gitHead": "bf95b21de1b87576ba961fed1336c51e2e25dec8"
53
+ "gitHead": "02786a5008e25af0ee36cf6996835b9864c5ec75"
54
54
  }
@@ -1,15 +0,0 @@
1
- import type { Feature } from '@common-stack/client-react';
2
- import type { CdmLogger } from '@cdm-logger/core';
3
- import type { Redis } from 'ioredis';
4
- import type { Container } from 'inversify';
5
- import type { ApolloClient, NormalizedCache } from '@apollo/client/index';
6
- export interface IAppLoadContext<S = any> {
7
- modules: Feature;
8
- routeConfig: any;
9
- store: any;
10
- container: Container;
11
- apolloClient: ApolloClient<NormalizedCache>;
12
- services: S;
13
- redisClient: Redis;
14
- logger?: CdmLogger.ILogger;
15
- }