@modern-js/types 2.28.0 → 2.30.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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @modern-js/types
2
2
 
3
+ ## 2.30.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a5ee81a: feat(server): add new server hooks `beforeServerInit` & `afterServerInit`
8
+ feat(server): 添加新的服务端钩子 `beforeServerInit` & `afterServerInit`
9
+
10
+ ### Patch Changes
11
+
12
+ - b6ab299: fix(prod-server): remove req bodyParser, let uesr parses body by themself.
13
+ fix(prod-server): 移除 req bodyParser, 让用户自行解析 body
14
+
15
+ ## 2.29.0
16
+
17
+ ### Minor Changes
18
+
19
+ - cba7675: feat: add a server reporter that report server cost, logger about error, info etc.
20
+ feat: 添加一个 server 端 reporter,来报告 server 端耗时,报错等
21
+
3
22
  ## 2.28.0
4
23
 
5
24
  ### Patch Changes
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.28.0",
18
+ "version": "2.30.0",
19
19
  "types": "./index.d.ts",
20
20
  "exports": {
21
21
  ".": {
@@ -45,8 +45,8 @@
45
45
  "http-proxy-middleware": "^2.0.4",
46
46
  "jest": "^29",
47
47
  "type-fest": "2.15.0",
48
- "@scripts/build": "2.28.0",
49
- "@scripts/jest-config": "2.28.0"
48
+ "@scripts/jest-config": "2.30.0",
49
+ "@scripts/build": "2.30.0"
50
50
  },
51
51
  "sideEffects": false,
52
52
  "publishConfig": {
@@ -1,7 +1,7 @@
1
1
  import { IncomingMessage, ServerResponse, IncomingHttpHeaders } from 'http';
2
2
  import qs from 'querystring';
3
3
  import type { SSRMode } from 'common';
4
- import { Metrics, Logger } from './utils';
4
+ import { Metrics, Logger, Reporter, ServerTiming } from './utils';
5
5
 
6
6
  export interface ModernServerContext {
7
7
  req: IncomingMessage;
@@ -14,6 +14,10 @@ export interface ModernServerContext {
14
14
 
15
15
  metrics: Metrics;
16
16
 
17
+ reporter: Reporter;
18
+
19
+ serverTiming: ServerTiming;
20
+
17
21
  setParams: (params: Record<string, string>) => void;
18
22
 
19
23
  getReqHeader: (key: string) => void;
@@ -56,7 +60,6 @@ export type BaseSSRServerContext = {
56
60
  query: Record<string, string>;
57
61
  headers: IncomingHttpHeaders;
58
62
  host: string;
59
- body?: string;
60
63
  [propsName: string]: any;
61
64
  };
62
65
  response: {
@@ -86,6 +89,8 @@ export type BaseSSRServerContext = {
86
89
  tags: Record<string, unknown> = {},
87
90
  ) => void;
88
91
  };
92
+ reporter: Reporter;
93
+ serverTiming: ServerTiming;
89
94
  cacheConfig?: any;
90
95
 
91
96
  enableUnsafeCtx?: boolean;
@@ -99,6 +104,11 @@ export type BaseSSRServerContext = {
99
104
  mode?: SSRMode; // ssr type
100
105
  };
101
106
 
107
+ export interface ServerInitHookContext {
108
+ app?: httpServer;
109
+ server: ModernServerInterface;
110
+ }
111
+
102
112
  export interface ISAppContext {
103
113
  appDirectory: string;
104
114
  distDirectory: string;
package/server/hook.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { IncomingMessage, ServerResponse, IncomingHttpHeaders } from 'http';
2
+ import { Reporter } from './utils';
2
3
 
3
4
  export type CookieAPI = {
4
5
  /**
@@ -35,6 +36,7 @@ export type HookContext = {
35
36
  response: ModernResponse;
36
37
  request: ModernRequest;
37
38
  logger: Logger;
39
+ reporter?: Reporter;
38
40
  metrics?: Metrics;
39
41
  };
40
42
 
package/server/utils.d.ts CHANGED
@@ -19,6 +19,40 @@ export type Logger = {
19
19
  log: LoggerFunction;
20
20
  };
21
21
 
22
+ export interface ServerTiming {
23
+ addServeTiming: (name: string, dur: number, decs?: string) => this;
24
+ }
25
+
26
+ export type Reporter = {
27
+ sessionId?: string;
28
+ userId?: string;
29
+ client?: any;
30
+
31
+ init: (payload: { match: any }) => void | Promise<void>;
32
+
33
+ reportError: (
34
+ content: string,
35
+ e: Error,
36
+ extra?: Record<string, string | number>,
37
+ ) => void;
38
+
39
+ reportTiming: (
40
+ name: string,
41
+ value: number,
42
+ extra?: Record<string, string>,
43
+ ) => void;
44
+
45
+ reportInfo: (
46
+ content: string,
47
+ extra?: Record<string, string | number>,
48
+ ) => void;
49
+
50
+ reportWarn: (
51
+ content: string,
52
+ extra?: Record<string, string | number>,
53
+ ) => void;
54
+ };
55
+
22
56
  export type NextFunction = () => void;
23
57
 
24
58
  export type ProxyDetail = ProxyOptions & {