@modern-js/server-core 2.55.0 → 2.56.1
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/cjs/adapters/node/plugins/resource.js +1 -1
- package/dist/cjs/constants.js +12 -9
- package/dist/cjs/plugins/customServer/index.js +35 -8
- package/dist/cjs/plugins/index.js +7 -3
- package/dist/cjs/plugins/log.js +3 -3
- package/dist/cjs/plugins/monitors.js +183 -0
- package/dist/cjs/plugins/render/index.js +5 -3
- package/dist/cjs/plugins/render/render.js +4 -11
- package/dist/cjs/utils/error.js +3 -3
- package/dist/esm/adapters/node/plugins/resource.js +1 -1
- package/dist/esm/constants.js +10 -8
- package/dist/esm/plugins/customServer/index.js +86 -36
- package/dist/esm/plugins/index.js +4 -2
- package/dist/esm/plugins/log.js +4 -4
- package/dist/esm/plugins/monitors.js +261 -0
- package/dist/esm/plugins/render/index.js +5 -3
- package/dist/esm/plugins/render/render.js +5 -12
- package/dist/esm/utils/error.js +3 -3
- package/dist/esm-node/adapters/node/plugins/resource.js +1 -1
- package/dist/esm-node/constants.js +10 -8
- package/dist/esm-node/plugins/customServer/index.js +26 -9
- package/dist/esm-node/plugins/index.js +4 -2
- package/dist/esm-node/plugins/log.js +3 -3
- package/dist/esm-node/plugins/monitors.js +156 -0
- package/dist/esm-node/plugins/render/index.js +4 -2
- package/dist/esm-node/plugins/render/render.js +4 -11
- package/dist/esm-node/utils/error.js +3 -3
- package/dist/types/constants.d.ts +2 -1
- package/dist/types/plugins/index.d.ts +1 -1
- package/dist/types/plugins/monitors.d.ts +6 -0
- package/dist/types/types/render.d.ts +7 -4
- package/dist/types/types/requestHandler.d.ts +0 -2
- package/dist/types/types/server.d.ts +6 -2
- package/dist/types/utils/error.d.ts +2 -2
- package/package.json +7 -7
- package/dist/cjs/plugins/monitor.js +0 -87
- package/dist/cjs/plugins/render/serverTiming.js +0 -42
- package/dist/esm/plugins/monitor.js +0 -120
- package/dist/esm/plugins/render/serverTiming.js +0 -29
- package/dist/esm-node/plugins/monitor.js +0 -62
- package/dist/esm-node/plugins/render/serverTiming.js +0 -18
- package/dist/types/plugins/monitor.d.ts +0 -9
- package/dist/types/plugins/render/serverTiming.d.ts +0 -8
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
-
import { time } from "@modern-js/runtime-utils/time";
|
|
4
|
-
import { ServerReportTimings } from "../constants";
|
|
5
|
-
var defaultReporter = {
|
|
6
|
-
init: function init() {
|
|
7
|
-
},
|
|
8
|
-
reportError: function reportError() {
|
|
9
|
-
},
|
|
10
|
-
reportTiming: function reportTiming() {
|
|
11
|
-
},
|
|
12
|
-
reportInfo: function reportInfo() {
|
|
13
|
-
},
|
|
14
|
-
reportWarn: function reportWarn() {
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
function initReporter(entryName) {
|
|
18
|
-
return function() {
|
|
19
|
-
var _ref = _async_to_generator(function(c, next) {
|
|
20
|
-
var reporter, getCost, cost;
|
|
21
|
-
return _ts_generator(this, function(_state) {
|
|
22
|
-
switch (_state.label) {
|
|
23
|
-
case 0:
|
|
24
|
-
reporter = c.get("reporter");
|
|
25
|
-
if (!!reporter)
|
|
26
|
-
return [
|
|
27
|
-
3,
|
|
28
|
-
2
|
|
29
|
-
];
|
|
30
|
-
return [
|
|
31
|
-
4,
|
|
32
|
-
next()
|
|
33
|
-
];
|
|
34
|
-
case 1:
|
|
35
|
-
_state.sent();
|
|
36
|
-
return [
|
|
37
|
-
2
|
|
38
|
-
];
|
|
39
|
-
case 2:
|
|
40
|
-
return [
|
|
41
|
-
4,
|
|
42
|
-
reporter.init({
|
|
43
|
-
entryName
|
|
44
|
-
})
|
|
45
|
-
];
|
|
46
|
-
case 3:
|
|
47
|
-
_state.sent();
|
|
48
|
-
getCost = time();
|
|
49
|
-
return [
|
|
50
|
-
4,
|
|
51
|
-
next()
|
|
52
|
-
];
|
|
53
|
-
case 4:
|
|
54
|
-
_state.sent();
|
|
55
|
-
cost = getCost();
|
|
56
|
-
reporter.reportTiming(ServerReportTimings.SERVER_HANDLE_REQUEST, cost);
|
|
57
|
-
return [
|
|
58
|
-
2
|
|
59
|
-
];
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
return function(c, next) {
|
|
64
|
-
return _ref.apply(this, arguments);
|
|
65
|
-
};
|
|
66
|
-
}();
|
|
67
|
-
}
|
|
68
|
-
var monitorPlugin = function(options) {
|
|
69
|
-
return {
|
|
70
|
-
name: "@modern-js/plugin-monitor",
|
|
71
|
-
setup: function setup(api) {
|
|
72
|
-
return {
|
|
73
|
-
prepare: function prepare() {
|
|
74
|
-
var middlewares = api.useAppContext().middlewares;
|
|
75
|
-
middlewares.push({
|
|
76
|
-
name: "monitor",
|
|
77
|
-
handler: function() {
|
|
78
|
-
var _ref = _async_to_generator(function(c, next) {
|
|
79
|
-
var logger, metrics, reporter;
|
|
80
|
-
return _ts_generator(this, function(_state) {
|
|
81
|
-
switch (_state.label) {
|
|
82
|
-
case 0:
|
|
83
|
-
logger = c.get("logger");
|
|
84
|
-
if (!logger && options.logger) {
|
|
85
|
-
c.set("logger", options.logger);
|
|
86
|
-
}
|
|
87
|
-
metrics = c.get("metrics");
|
|
88
|
-
if (!metrics && options.metrics) {
|
|
89
|
-
c.set("metrics", metrics);
|
|
90
|
-
}
|
|
91
|
-
reporter = c.get("reporter");
|
|
92
|
-
if (!reporter) {
|
|
93
|
-
c.set("reporter", reporter || defaultReporter);
|
|
94
|
-
}
|
|
95
|
-
return [
|
|
96
|
-
4,
|
|
97
|
-
next()
|
|
98
|
-
];
|
|
99
|
-
case 1:
|
|
100
|
-
_state.sent();
|
|
101
|
-
return [
|
|
102
|
-
2
|
|
103
|
-
];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
return function(c, next) {
|
|
108
|
-
return _ref.apply(this, arguments);
|
|
109
|
-
};
|
|
110
|
-
}()
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
export {
|
|
118
|
-
initReporter,
|
|
119
|
-
monitorPlugin
|
|
120
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
2
|
-
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
3
|
-
var ServerTiming = /* @__PURE__ */ function() {
|
|
4
|
-
"use strict";
|
|
5
|
-
function ServerTiming2(meta) {
|
|
6
|
-
_class_call_check(this, ServerTiming2);
|
|
7
|
-
this.headerList = [];
|
|
8
|
-
this.meta = meta;
|
|
9
|
-
}
|
|
10
|
-
var _proto = ServerTiming2.prototype;
|
|
11
|
-
_proto.addServeTiming = function addServeTiming(name, dur, desc) {
|
|
12
|
-
var _name = "bd-".concat(this.meta, "-").concat(name);
|
|
13
|
-
var value = "".concat(_name, ";").concat(desc ? 'decs="'.concat(desc, '";') : "", " dur=").concat(dur);
|
|
14
|
-
this.headerList.push(value);
|
|
15
|
-
return this;
|
|
16
|
-
};
|
|
17
|
-
_create_class(ServerTiming2, [
|
|
18
|
-
{
|
|
19
|
-
key: "headers",
|
|
20
|
-
get: function get() {
|
|
21
|
-
return this.headerList;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
]);
|
|
25
|
-
return ServerTiming2;
|
|
26
|
-
}();
|
|
27
|
-
export {
|
|
28
|
-
ServerTiming
|
|
29
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { time } from "@modern-js/runtime-utils/time";
|
|
2
|
-
import { ServerReportTimings } from "../constants";
|
|
3
|
-
const defaultReporter = {
|
|
4
|
-
init() {
|
|
5
|
-
},
|
|
6
|
-
reportError() {
|
|
7
|
-
},
|
|
8
|
-
reportTiming() {
|
|
9
|
-
},
|
|
10
|
-
reportInfo() {
|
|
11
|
-
},
|
|
12
|
-
reportWarn() {
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
function initReporter(entryName) {
|
|
16
|
-
return async (c, next) => {
|
|
17
|
-
const reporter = c.get("reporter");
|
|
18
|
-
if (!reporter) {
|
|
19
|
-
await next();
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
await reporter.init({
|
|
23
|
-
entryName
|
|
24
|
-
});
|
|
25
|
-
const getCost = time();
|
|
26
|
-
await next();
|
|
27
|
-
const cost = getCost();
|
|
28
|
-
reporter.reportTiming(ServerReportTimings.SERVER_HANDLE_REQUEST, cost);
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
const monitorPlugin = (options) => ({
|
|
32
|
-
name: "@modern-js/plugin-monitor",
|
|
33
|
-
setup(api) {
|
|
34
|
-
return {
|
|
35
|
-
prepare() {
|
|
36
|
-
const { middlewares } = api.useAppContext();
|
|
37
|
-
middlewares.push({
|
|
38
|
-
name: "monitor",
|
|
39
|
-
handler: async (c, next) => {
|
|
40
|
-
const logger = c.get("logger");
|
|
41
|
-
if (!logger && options.logger) {
|
|
42
|
-
c.set("logger", options.logger);
|
|
43
|
-
}
|
|
44
|
-
const metrics = c.get("metrics");
|
|
45
|
-
if (!metrics && options.metrics) {
|
|
46
|
-
c.set("metrics", metrics);
|
|
47
|
-
}
|
|
48
|
-
const reporter = c.get("reporter");
|
|
49
|
-
if (!reporter) {
|
|
50
|
-
c.set("reporter", reporter || defaultReporter);
|
|
51
|
-
}
|
|
52
|
-
await next();
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
export {
|
|
60
|
-
initReporter,
|
|
61
|
-
monitorPlugin
|
|
62
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
class ServerTiming {
|
|
2
|
-
get headers() {
|
|
3
|
-
return this.headerList;
|
|
4
|
-
}
|
|
5
|
-
addServeTiming(name, dur, desc) {
|
|
6
|
-
const _name = `bd-${this.meta}-${name}`;
|
|
7
|
-
const value = `${_name};${desc ? `decs="${desc}";` : ""} dur=${dur}`;
|
|
8
|
-
this.headerList.push(value);
|
|
9
|
-
return this;
|
|
10
|
-
}
|
|
11
|
-
constructor(meta) {
|
|
12
|
-
this.headerList = [];
|
|
13
|
-
this.meta = meta;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export {
|
|
17
|
-
ServerTiming
|
|
18
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Logger, Metrics, Reporter } from '@modern-js/types';
|
|
2
|
-
import { Context, Next, ServerEnv, ServerPlugin } from '../types';
|
|
3
|
-
export interface MonitorOptions {
|
|
4
|
-
logger?: Logger;
|
|
5
|
-
metrics?: Metrics;
|
|
6
|
-
reporter?: Reporter;
|
|
7
|
-
}
|
|
8
|
-
export declare function initReporter(entryName: string): (c: Context<ServerEnv>, next: Next) => Promise<void>;
|
|
9
|
-
export declare const monitorPlugin: (options: MonitorOptions) => ServerPlugin;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ServerTiming as ServerTimingInterafce } from '@modern-js/types';
|
|
2
|
-
export declare class ServerTiming implements ServerTimingInterafce {
|
|
3
|
-
private headerList;
|
|
4
|
-
private meta;
|
|
5
|
-
constructor(meta: string);
|
|
6
|
-
get headers(): string[];
|
|
7
|
-
addServeTiming(name: string, dur: number, desc?: string): this;
|
|
8
|
-
}
|