@modern-js/prod-server 2.47.1 → 2.48.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.
Files changed (56) hide show
  1. package/dist/cjs/libs/context/context.js +4 -8
  2. package/dist/cjs/libs/hook-api/base.js +0 -11
  3. package/dist/cjs/libs/hook-api/index.worker.js +0 -3
  4. package/dist/cjs/libs/hook-api/route.js +0 -4
  5. package/dist/cjs/libs/hook-api/template.js +0 -2
  6. package/dist/cjs/libs/render/ssr.js +7 -3
  7. package/dist/cjs/libs/render/ssrCache/cacheMod.js +0 -5
  8. package/dist/cjs/libs/render/ssrCache/index.js +10 -3
  9. package/dist/cjs/libs/render/ssrCache/manager.js +25 -11
  10. package/dist/cjs/libs/route/index.js +1 -3
  11. package/dist/cjs/libs/route/matcher.js +1 -5
  12. package/dist/cjs/libs/route/route.js +1 -10
  13. package/dist/cjs/libs/serverTiming.js +0 -3
  14. package/dist/cjs/renderHtml.js +0 -7
  15. package/dist/cjs/server/index.js +1 -7
  16. package/dist/cjs/server/modernServer.js +11 -21
  17. package/dist/cjs/workerServer.js +4 -8
  18. package/dist/esm/libs/context/context.js +66 -98
  19. package/dist/esm/libs/hook-api/base.js +36 -71
  20. package/dist/esm/libs/hook-api/index.worker.js +15 -29
  21. package/dist/esm/libs/hook-api/route.js +12 -27
  22. package/dist/esm/libs/hook-api/template.js +33 -61
  23. package/dist/esm/libs/render/ssr.js +8 -4
  24. package/dist/esm/libs/render/ssrCache/cacheMod.js +10 -18
  25. package/dist/esm/libs/render/ssrCache/index.js +40 -21
  26. package/dist/esm/libs/render/ssrCache/manager.js +149 -141
  27. package/dist/esm/libs/route/index.js +62 -96
  28. package/dist/esm/libs/route/matcher.js +58 -94
  29. package/dist/esm/libs/route/route.js +1 -10
  30. package/dist/esm/libs/serverTiming.js +8 -16
  31. package/dist/esm/renderHtml.js +22 -39
  32. package/dist/esm/server/index.js +307 -383
  33. package/dist/esm/server/modernServer.js +802 -936
  34. package/dist/esm/server/modernServerSplit.js +61 -86
  35. package/dist/esm/workerServer.js +87 -82
  36. package/dist/esm-node/libs/context/context.js +4 -8
  37. package/dist/esm-node/libs/hook-api/base.js +0 -11
  38. package/dist/esm-node/libs/hook-api/index.worker.js +0 -3
  39. package/dist/esm-node/libs/hook-api/route.js +0 -4
  40. package/dist/esm-node/libs/hook-api/template.js +0 -2
  41. package/dist/esm-node/libs/render/ssr.js +7 -3
  42. package/dist/esm-node/libs/render/ssrCache/cacheMod.js +0 -5
  43. package/dist/esm-node/libs/render/ssrCache/index.js +10 -3
  44. package/dist/esm-node/libs/render/ssrCache/manager.js +25 -11
  45. package/dist/esm-node/libs/route/index.js +1 -3
  46. package/dist/esm-node/libs/route/matcher.js +1 -5
  47. package/dist/esm-node/libs/route/route.js +1 -10
  48. package/dist/esm-node/libs/serverTiming.js +0 -3
  49. package/dist/esm-node/renderHtml.js +0 -7
  50. package/dist/esm-node/server/index.js +1 -7
  51. package/dist/esm-node/server/modernServer.js +11 -21
  52. package/dist/esm-node/workerServer.js +4 -8
  53. package/dist/types/libs/render/ssrCache/index.d.ts +2 -3
  54. package/dist/types/libs/render/ssrCache/manager.d.ts +7 -1
  55. package/dist/types/type.d.ts +1 -0
  56. package/package.json +8 -8
@@ -1,6 +1,4 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  import { match, pathToRegexp, compile } from "path-to-regexp";
5
3
  import { ModernRoute } from "./route";
6
4
  var removeTailSlash = function(s) {
@@ -23,104 +21,70 @@ var RouteMatcher = /* @__PURE__ */ function() {
23
21
  "use strict";
24
22
  function RouteMatcher2(spec) {
25
23
  _class_call_check(this, RouteMatcher2);
26
- _define_property(this, "spec", void 0);
27
- _define_property(this, "urlPath", "");
28
- _define_property(this, "urlMatcher", void 0);
29
- _define_property(this, "urlReg", void 0);
24
+ this.urlPath = "";
30
25
  this.spec = spec;
31
26
  this.setupUrlPath();
32
27
  }
33
- _create_class(RouteMatcher2, [
34
- {
35
- key: "generate",
36
- value: (
37
- // generate modern route object
38
- function generate(url) {
39
- var route = new ModernRoute(this.spec);
40
- if (this.urlPath) {
41
- var params = this.parseURLParams(url);
42
- route.urlPath = toPath(route.urlPath, params);
43
- route.params = params;
44
- }
45
- return route;
46
- }
47
- )
48
- },
49
- {
50
- key: "parseURLParams",
51
- value: function parseURLParams(pathname) {
52
- if (!this.urlMatcher) {
53
- return {};
54
- } else {
55
- var matchResult = this.urlMatcher(pathname);
56
- return matchResult.params;
57
- }
58
- }
59
- },
60
- {
61
- key: "matchLength",
62
- value: (
63
- // get match url length
64
- function matchLength(pathname) {
65
- if (!this.urlReg) {
66
- return this.urlPath.length;
67
- } else {
68
- var _result_;
69
- var result = this.urlReg.exec(pathname);
70
- return (result === null || result === void 0 ? void 0 : (_result_ = result[0]) === null || _result_ === void 0 ? void 0 : _result_.length) || null;
71
- }
72
- }
73
- )
74
- },
75
- {
76
- key: "matchUrlPath",
77
- value: (
78
- // if match url path
79
- function matchUrlPath(requestUrl) {
80
- var urlWithoutSlash = requestUrl.endsWith("/") && requestUrl !== "/" ? requestUrl.slice(0, -1) : requestUrl;
81
- urlWithoutSlash = removeHtmlSuffix(urlWithoutSlash);
82
- if (this.urlMatcher) {
83
- return Boolean(this.urlMatcher(urlWithoutSlash));
84
- } else {
85
- var urlPath = removeHtmlSuffix(this.urlPath);
86
- if (urlWithoutSlash.startsWith(urlPath)) {
87
- if (urlPath !== "/" && urlWithoutSlash.length > urlPath.length && !urlWithoutSlash.startsWith("".concat(urlPath, "/"))) {
88
- return false;
89
- }
90
- return true;
91
- }
92
- return false;
93
- }
28
+ var _proto = RouteMatcher2.prototype;
29
+ _proto.generate = function generate(url) {
30
+ var route = new ModernRoute(this.spec);
31
+ if (this.urlPath) {
32
+ var params = this.parseURLParams(url);
33
+ route.urlPath = toPath(route.urlPath, params);
34
+ route.params = params;
35
+ }
36
+ return route;
37
+ };
38
+ _proto.parseURLParams = function parseURLParams(pathname) {
39
+ if (!this.urlMatcher) {
40
+ return {};
41
+ } else {
42
+ var matchResult = this.urlMatcher(pathname);
43
+ return matchResult.params;
44
+ }
45
+ };
46
+ _proto.matchLength = function matchLength(pathname) {
47
+ if (!this.urlReg) {
48
+ return this.urlPath.length;
49
+ } else {
50
+ var _result_;
51
+ var result = this.urlReg.exec(pathname);
52
+ return (result === null || result === void 0 ? void 0 : (_result_ = result[0]) === null || _result_ === void 0 ? void 0 : _result_.length) || null;
53
+ }
54
+ };
55
+ _proto.matchUrlPath = function matchUrlPath(requestUrl) {
56
+ var urlWithoutSlash = requestUrl.endsWith("/") && requestUrl !== "/" ? requestUrl.slice(0, -1) : requestUrl;
57
+ urlWithoutSlash = removeHtmlSuffix(urlWithoutSlash);
58
+ if (this.urlMatcher) {
59
+ return Boolean(this.urlMatcher(urlWithoutSlash));
60
+ } else {
61
+ var urlPath = removeHtmlSuffix(this.urlPath);
62
+ if (urlWithoutSlash.startsWith(urlPath)) {
63
+ if (urlPath !== "/" && urlWithoutSlash.length > urlPath.length && !urlWithoutSlash.startsWith("".concat(urlPath, "/"))) {
64
+ return false;
94
65
  }
95
- )
96
- },
97
- {
98
- key: "matchEntry",
99
- value: function matchEntry(entryName) {
100
- return this.spec.entryName === entryName;
66
+ return true;
101
67
  }
102
- },
103
- {
104
- key: "setupUrlPath",
105
- value: (
106
- // compiler urlPath to regexp if necessary
107
- function setupUrlPath() {
108
- var urlPath = this.spec.urlPath;
109
- this.urlPath = urlPath === "/" ? urlPath : removeTailSlash(urlPath);
110
- var useReg = regCharsDetector.test(urlPath);
111
- if (useReg) {
112
- this.urlMatcher = match(urlPath, {
113
- end: false,
114
- decode: decodeURIComponent
115
- });
116
- this.urlReg = pathToRegexp(urlPath, [], {
117
- end: false
118
- });
119
- }
120
- }
121
- )
68
+ return false;
69
+ }
70
+ };
71
+ _proto.matchEntry = function matchEntry(entryName) {
72
+ return this.spec.entryName === entryName;
73
+ };
74
+ _proto.setupUrlPath = function setupUrlPath() {
75
+ var urlPath = this.spec.urlPath;
76
+ this.urlPath = urlPath === "/" ? urlPath : removeTailSlash(urlPath);
77
+ var useReg = regCharsDetector.test(urlPath);
78
+ if (useReg) {
79
+ this.urlMatcher = match(urlPath, {
80
+ end: false,
81
+ decode: decodeURIComponent
82
+ });
83
+ this.urlReg = pathToRegexp(urlPath, [], {
84
+ end: false
85
+ });
122
86
  }
123
- ]);
87
+ };
124
88
  return RouteMatcher2;
125
89
  }();
126
90
  export {
@@ -1,17 +1,8 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
3
2
  var ModernRoute = function ModernRoute2(routeSpec) {
4
3
  "use strict";
5
4
  _class_call_check(this, ModernRoute2);
6
- _define_property(this, "entryName", void 0);
7
- _define_property(this, "urlPath", void 0);
8
- _define_property(this, "entryPath", void 0);
9
- _define_property(this, "bundle", void 0);
10
- _define_property(this, "isApi", void 0);
11
- _define_property(this, "isSSR", void 0);
12
- _define_property(this, "isSPA", void 0);
13
- _define_property(this, "params", {});
14
- _define_property(this, "responseHeaders", void 0);
5
+ this.params = {};
15
6
  this.entryName = routeSpec.entryName || "";
16
7
  this.urlPath = routeSpec.urlPath;
17
8
  this.entryPath = routeSpec.entryPath || "";
@@ -1,28 +1,20 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  var SERVER_TIMING = "Server-Timing";
5
3
  var ServerTiming = /* @__PURE__ */ function() {
6
4
  "use strict";
7
5
  function ServerTiming2(res, meta) {
8
6
  _class_call_check(this, ServerTiming2);
9
- _define_property(this, "meta", void 0);
10
- _define_property(this, "res", void 0);
11
7
  this.meta = meta;
12
8
  this.res = res;
13
9
  }
14
- _create_class(ServerTiming2, [
15
- {
16
- key: "addServeTiming",
17
- value: function addServeTiming(name, dur, desc) {
18
- var _name = "bd-".concat(this.meta, "-").concat(name);
19
- var serverTiming = this.res.getHeader(SERVER_TIMING) || this.res.getHeader(SERVER_TIMING.toLocaleLowerCase());
20
- var value = "".concat(_name, ";").concat(desc ? 'decs="'.concat(desc, '";') : "", " dur=").concat(dur);
21
- this.res.set(SERVER_TIMING, serverTiming ? "".concat(serverTiming, ", ").concat(value) : value);
22
- return this;
23
- }
24
- }
25
- ]);
10
+ var _proto = ServerTiming2.prototype;
11
+ _proto.addServeTiming = function addServeTiming(name, dur, desc) {
12
+ var _name = "bd-".concat(this.meta, "-").concat(name);
13
+ var serverTiming = this.res.getHeader(SERVER_TIMING) || this.res.getHeader(SERVER_TIMING.toLocaleLowerCase());
14
+ var value = "".concat(_name, ";").concat(desc ? 'decs="'.concat(desc, '";') : "", " dur=").concat(dur);
15
+ this.res.set(SERVER_TIMING, serverTiming ? "".concat(serverTiming, ", ").concat(value) : value);
16
+ return this;
17
+ };
26
18
  return ServerTiming2;
27
19
  }();
28
20
  export {
@@ -2,11 +2,8 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
2
2
  var __commonJS = (cb, mod) => function __require() {
3
3
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
4
  };
5
- import { _ as _assert_this_initialized } from "@swc/helpers/_/_assert_this_initialized";
6
5
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
7
6
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
8
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
9
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
10
7
  import { _ as _inherits } from "@swc/helpers/_/_inherits";
11
8
  import { _ as _create_super } from "@swc/helpers/_/_create_super";
12
9
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
@@ -26,10 +23,6 @@ var require_renderHtml = __commonJS({
26
23
  _class_call_check(this, IncomingMessageLike2);
27
24
  var _this;
28
25
  _this = _super.call(this);
29
- _define_property(_assert_this_initialized(_this), "headers", void 0);
30
- _define_property(_assert_this_initialized(_this), "method", void 0);
31
- _define_property(_assert_this_initialized(_this), "url", void 0);
32
- _define_property(_assert_this_initialized(_this), "socket", void 0);
33
26
  _this.socket = new Socket();
34
27
  _this.headers = headers || {};
35
28
  _this.headers.host = "localhost:8080";
@@ -47,23 +40,17 @@ var require_renderHtml = __commonJS({
47
40
  _class_call_check(this, ServerResponseLike2);
48
41
  var _this;
49
42
  _this = _super.call(this);
50
- _define_property(_assert_this_initialized(_this), "statusCode", void 0);
51
- _define_property(_assert_this_initialized(_this), "data", void 0);
52
43
  _this.statusCode = 200;
53
44
  _this.data = [];
54
45
  return _this;
55
46
  }
56
- _create_class(ServerResponseLike2, [
57
- {
58
- key: "end",
59
- value: function end(chunk, _encoding, cb) {
60
- this.data.push(chunk.toString());
61
- cb && cb();
62
- this.emit("finish");
63
- return this;
64
- }
65
- }
66
- ]);
47
+ var _proto = ServerResponseLike2.prototype;
48
+ _proto.end = function end(chunk, _encoding, cb) {
49
+ this.data.push(chunk.toString());
50
+ cb && cb();
51
+ this.emit("finish");
52
+ return this;
53
+ };
67
54
  return ServerResponseLike2;
68
55
  }(OutgoingMessage);
69
56
  var CustomServer = /* @__PURE__ */ function(Server2) {
@@ -74,25 +61,21 @@ var require_renderHtml = __commonJS({
74
61
  _class_call_check(this, CustomServer2);
75
62
  return _super.apply(this, arguments);
76
63
  }
77
- _create_class(CustomServer2, [
78
- {
79
- key: "render",
80
- value: function render(req, res, _url) {
81
- var _this = this;
82
- return _async_to_generator(function() {
83
- var handler;
84
- return _ts_generator(this, function(_state) {
85
- handler = _this.getRequestHandler();
86
- handler(req, res);
87
- return [
88
- 2,
89
- null
90
- ];
91
- });
92
- })();
93
- }
94
- }
95
- ]);
64
+ var _proto = CustomServer2.prototype;
65
+ _proto.render = function render(req, res, _url) {
66
+ var _this = this;
67
+ return _async_to_generator(function() {
68
+ var handler;
69
+ return _ts_generator(this, function(_state) {
70
+ handler = _this.getRequestHandler();
71
+ handler(req, res);
72
+ return [
73
+ 2,
74
+ null
75
+ ];
76
+ });
77
+ })();
78
+ };
96
79
  return CustomServer2;
97
80
  }(Server);
98
81
  function renderHtml(_) {