@tramvai/module-server 4.18.5 → 4.19.2

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,15 +1,20 @@
1
1
  /// <reference types="node" />
2
- import type { EXECUTION_CONTEXT_MANAGER_TOKEN, LOGGER_TOKEN } from '@tramvai/tokens-common';
2
+ import type { ASYNC_LOCAL_STORAGE_TOKEN, EXECUTION_CONTEXT_MANAGER_TOKEN, LOGGER_TOKEN } from '@tramvai/tokens-common';
3
3
  import type { COMMAND_LINE_RUNNER_TOKEN } from '@tramvai/core';
4
4
  import type { SERVER_TOKEN } from '@tramvai/tokens-server';
5
5
  import type { WEB_FASTIFY_APP_TOKEN, WEB_FASTIFY_APP_AFTER_INIT_TOKEN, WEB_FASTIFY_APP_BEFORE_INIT_TOKEN, WEB_FASTIFY_APP_INIT_TOKEN, WEB_FASTIFY_APP_LIMITER_TOKEN, WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN, WEB_FASTIFY_APP_AFTER_ERROR_TOKEN, WEB_FASTIFY_APP_METRICS_TOKEN } from '@tramvai/tokens-server-private';
6
6
  import { type FETCH_WEBPACK_STATS_TOKEN } from '@tramvai/tokens-render';
7
- import type { ExtractDependencyType } from '@tinkoff/dippy';
7
+ import type { DI_TOKEN, ExtractDependencyType } from '@tinkoff/dippy';
8
8
  import type { STATIC_ROOT_ERROR_BOUNDARY_ERROR_TOKEN } from '@tramvai/tokens-server';
9
+ declare module '@tramvai/tokens-common' {
10
+ interface AsyncLocalStorageState {
11
+ tramvaiRequestDi?: ExtractDependencyType<typeof DI_TOKEN>;
12
+ }
13
+ }
9
14
  export declare const webAppFactory: ({ server }: {
10
15
  server: typeof SERVER_TOKEN;
11
16
  }) => import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>>;
12
- export declare const webAppInitCommand: ({ app, logger, commandLineRunner, executionContextManager, beforeInit, requestMetrics, limiterRequest, init, afterInit, beforeError, afterError, fetchWebpackStats, staticRootErrorBoundaryError, }: {
17
+ export declare const webAppInitCommand: ({ app, logger, commandLineRunner, executionContextManager, beforeInit, requestMetrics, limiterRequest, init, afterInit, beforeError, afterError, fetchWebpackStats, staticRootErrorBoundaryError, rootDi, asyncLocalStorage, }: {
13
18
  app: ExtractDependencyType<typeof WEB_FASTIFY_APP_TOKEN>;
14
19
  logger: ExtractDependencyType<typeof LOGGER_TOKEN>;
15
20
  commandLineRunner: ExtractDependencyType<typeof COMMAND_LINE_RUNNER_TOKEN>;
@@ -23,5 +28,7 @@ export declare const webAppInitCommand: ({ app, logger, commandLineRunner, execu
23
28
  afterError: ExtractDependencyType<typeof WEB_FASTIFY_APP_AFTER_ERROR_TOKEN>;
24
29
  fetchWebpackStats: ExtractDependencyType<typeof FETCH_WEBPACK_STATS_TOKEN>;
25
30
  staticRootErrorBoundaryError: ExtractDependencyType<typeof STATIC_ROOT_ERROR_BOUNDARY_ERROR_TOKEN>;
31
+ rootDi: ExtractDependencyType<typeof DI_TOKEN>;
32
+ asyncLocalStorage: ExtractDependencyType<typeof ASYNC_LOCAL_STORAGE_TOKEN>;
26
33
  }) => () => Promise<void>;
27
34
  //# sourceMappingURL=webApp.d.ts.map
@@ -19,7 +19,7 @@ const webAppFactory = ({ server }) => {
19
19
  });
20
20
  return app;
21
21
  };
22
- const webAppInitCommand = ({ app, logger, commandLineRunner, executionContextManager, beforeInit, requestMetrics, limiterRequest, init, afterInit, beforeError, afterError, fetchWebpackStats, staticRootErrorBoundaryError, }) => {
22
+ const webAppInitCommand = ({ app, logger, commandLineRunner, executionContextManager, beforeInit, requestMetrics, limiterRequest, init, afterInit, beforeError, afterError, fetchWebpackStats, staticRootErrorBoundaryError, rootDi, asyncLocalStorage, }) => {
23
23
  const log = logger('server:webapp');
24
24
  const runHandlers = (instance, handlers) => {
25
25
  return Promise.all([handlers && Promise.all(handlers.map((handler) => handler(instance)))]);
@@ -56,7 +56,7 @@ const webAppInitCommand = ({ app, logger, commandLineRunner, executionContextMan
56
56
  url: request.url,
57
57
  });
58
58
  await executionContextManager.withContext(null, 'root', async (rootExecutionContext) => {
59
- const di = await commandLineRunner.run('server', 'customer', [
59
+ const providers = [
60
60
  provide({
61
61
  provide: ROOT_EXECUTION_CONTEXT_TOKEN,
62
62
  useValue: rootExecutionContext,
@@ -71,7 +71,15 @@ const webAppInitCommand = ({ app, logger, commandLineRunner, executionContextMan
71
71
  scope: Scope.REQUEST,
72
72
  useValue: reply,
73
73
  },
74
- ]);
74
+ ];
75
+ const di = commandLineRunner.resolveDi('server', 'customer', rootDi, providers);
76
+ const storage = asyncLocalStorage.getStore();
77
+ if (storage) {
78
+ // save Request DI container to async local storage context for current request
79
+ // eslint-disable-next-line no-param-reassign
80
+ storage.tramvaiRequestDi = di;
81
+ }
82
+ await commandLineRunner.run('server', 'customer', [], di);
75
83
  const serverResponseStream = di.get(SERVER_RESPONSE_STREAM);
76
84
  const serverResponseTaskManager = di.get(SERVER_RESPONSE_TASK_MANAGER);
77
85
  const responseManager = di.get(RESPONSE_MANAGER_TOKEN);
@@ -28,7 +28,7 @@ const webAppFactory = ({ server }) => {
28
28
  });
29
29
  return app;
30
30
  };
31
- const webAppInitCommand = ({ app, logger, commandLineRunner, executionContextManager, beforeInit, requestMetrics, limiterRequest, init, afterInit, beforeError, afterError, fetchWebpackStats, staticRootErrorBoundaryError, }) => {
31
+ const webAppInitCommand = ({ app, logger, commandLineRunner, executionContextManager, beforeInit, requestMetrics, limiterRequest, init, afterInit, beforeError, afterError, fetchWebpackStats, staticRootErrorBoundaryError, rootDi, asyncLocalStorage, }) => {
32
32
  const log = logger('server:webapp');
33
33
  const runHandlers = (instance, handlers) => {
34
34
  return Promise.all([handlers && Promise.all(handlers.map((handler) => handler(instance)))]);
@@ -65,7 +65,7 @@ const webAppInitCommand = ({ app, logger, commandLineRunner, executionContextMan
65
65
  url: request.url,
66
66
  });
67
67
  await executionContextManager.withContext(null, 'root', async (rootExecutionContext) => {
68
- const di = await commandLineRunner.run('server', 'customer', [
68
+ const providers = [
69
69
  dippy.provide({
70
70
  provide: tokensCommon.ROOT_EXECUTION_CONTEXT_TOKEN,
71
71
  useValue: rootExecutionContext,
@@ -80,7 +80,15 @@ const webAppInitCommand = ({ app, logger, commandLineRunner, executionContextMan
80
80
  scope: core.Scope.REQUEST,
81
81
  useValue: reply,
82
82
  },
83
- ]);
83
+ ];
84
+ const di = commandLineRunner.resolveDi('server', 'customer', rootDi, providers);
85
+ const storage = asyncLocalStorage.getStore();
86
+ if (storage) {
87
+ // save Request DI container to async local storage context for current request
88
+ // eslint-disable-next-line no-param-reassign
89
+ storage.tramvaiRequestDi = di;
90
+ }
91
+ await commandLineRunner.run('server', 'customer', [], di);
84
92
  const serverResponseStream = di.get(tokensServerPrivate.SERVER_RESPONSE_STREAM);
85
93
  const serverResponseTaskManager = di.get(tokensServerPrivate.SERVER_RESPONSE_TASK_MANAGER);
86
94
  const responseManager = di.get(tokensCommon.RESPONSE_MANAGER_TOKEN);
package/lib/server.es.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { __decorate } from 'tslib';
2
2
  import { setDefaultResultOrder } from 'dns';
3
3
  import EventEmitter from 'events';
4
- import { Module, provide, Scope, commandLineListTokens, COMMAND_LINE_RUNNER_TOKEN, APP_INFO_TOKEN } from '@tramvai/core';
4
+ import { Module, provide, Scope, commandLineListTokens, COMMAND_LINE_RUNNER_TOKEN, DI_TOKEN, APP_INFO_TOKEN } from '@tramvai/core';
5
5
  import { SERVER_TOKEN, STATIC_ROOT_ERROR_BOUNDARY_ERROR_TOKEN } from '@tramvai/tokens-server';
6
6
  export * from '@tramvai/tokens-server';
7
7
  import { FETCH_WEBPACK_STATS_TOKEN } from '@tramvai/tokens-render';
8
8
  import { SERVER_FACTORY_TOKEN, WEB_FASTIFY_APP_FACTORY_TOKEN, WEB_FASTIFY_APP_TOKEN, WEB_FASTIFY_APP_BEFORE_INIT_TOKEN, WEB_FASTIFY_APP_INIT_TOKEN, WEB_FASTIFY_APP_AFTER_INIT_TOKEN, WEB_FASTIFY_APP_METRICS_TOKEN, WEB_FASTIFY_APP_LIMITER_TOKEN, WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN, WEB_FASTIFY_APP_AFTER_ERROR_TOKEN, SERVER_RESPONSE_STREAM, SERVER_RESPONSE_TASK_MANAGER } from '@tramvai/tokens-server-private';
9
- import { LOGGER_TOKEN, EXECUTION_CONTEXT_MANAGER_TOKEN, ENV_MANAGER_TOKEN, ENV_USED_TOKEN } from '@tramvai/tokens-common';
9
+ import { LOGGER_TOKEN, EXECUTION_CONTEXT_MANAGER_TOKEN, ASYNC_LOCAL_STORAGE_TOKEN, ENV_MANAGER_TOKEN, ENV_USED_TOKEN } from '@tramvai/tokens-common';
10
10
  import { MetricsModule } from '@tramvai/module-metrics';
11
11
  import { CacheWarmupModule } from '@tramvai/module-cache-warmup';
12
12
  import { ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN } from '@tramvai/react';
@@ -103,6 +103,8 @@ ServerModule = __decorate([
103
103
  token: STATIC_ROOT_ERROR_BOUNDARY_ERROR_TOKEN,
104
104
  optional: true,
105
105
  },
106
+ rootDi: DI_TOKEN,
107
+ asyncLocalStorage: ASYNC_LOCAL_STORAGE_TOKEN,
106
108
  },
107
109
  },
108
110
  provide({
package/lib/server.js CHANGED
@@ -110,6 +110,8 @@ exports.ServerModule = tslib.__decorate([
110
110
  token: tokensServer.STATIC_ROOT_ERROR_BOUNDARY_ERROR_TOKEN,
111
111
  optional: true,
112
112
  },
113
+ rootDi: core.DI_TOKEN,
114
+ asyncLocalStorage: tokensCommon.ASYNC_LOCAL_STORAGE_TOKEN,
113
115
  },
114
116
  },
115
117
  core.provide({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-server",
3
- "version": "4.18.5",
3
+ "version": "4.19.2",
4
4
  "description": "",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -26,12 +26,12 @@
26
26
  "@tinkoff/monkeypatch": "4.0.1",
27
27
  "@tinkoff/terminus": "0.3.1",
28
28
  "@tinkoff/url": "0.10.1",
29
- "@tramvai/module-cache-warmup": "4.18.5",
30
- "@tramvai/module-metrics": "4.18.5",
31
- "@tramvai/papi": "4.18.5",
32
- "@tramvai/tokens-server": "4.18.5",
33
- "@tramvai/tokens-router": "4.18.5",
34
- "@tramvai/tokens-server-private": "4.18.5",
29
+ "@tramvai/module-cache-warmup": "4.19.2",
30
+ "@tramvai/module-metrics": "4.19.2",
31
+ "@tramvai/papi": "4.19.2",
32
+ "@tramvai/tokens-server": "4.19.2",
33
+ "@tramvai/tokens-router": "4.19.2",
34
+ "@tramvai/tokens-server-private": "4.19.2",
35
35
  "@tramvai/safe-strings": "0.7.1",
36
36
  "fastify": "^4.14.1",
37
37
  "@fastify/cookie": "^8.3.0",
@@ -42,16 +42,16 @@
42
42
  "http-proxy-middleware": "^2.0.2"
43
43
  },
44
44
  "peerDependencies": {
45
- "@tinkoff/dippy": "0.10.6",
45
+ "@tinkoff/dippy": "0.10.7",
46
46
  "@tinkoff/utils": "^2.1.2",
47
- "@tramvai/cli": "4.18.5",
48
- "@tramvai/core": "4.18.5",
49
- "@tramvai/react": "4.18.5",
50
- "@tramvai/module-common": "4.18.5",
51
- "@tramvai/module-environment": "4.18.5",
52
- "@tramvai/tokens-common": "4.18.5",
53
- "@tramvai/tokens-core-private": "4.18.5",
54
- "@tramvai/tokens-render": "4.18.5",
47
+ "@tramvai/cli": "4.19.2",
48
+ "@tramvai/core": "4.19.2",
49
+ "@tramvai/react": "4.19.2",
50
+ "@tramvai/module-common": "4.19.2",
51
+ "@tramvai/module-environment": "4.19.2",
52
+ "@tramvai/tokens-common": "4.19.2",
53
+ "@tramvai/tokens-core-private": "4.19.2",
54
+ "@tramvai/tokens-render": "4.19.2",
55
55
  "react": ">=16.14.0",
56
56
  "react-dom": ">=16.14.0",
57
57
  "tslib": "^2.4.0"