@modern-js/prod-server 2.48.0 → 2.48.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.
- package/dist/cjs/libs/context/context.js +4 -8
- package/dist/cjs/libs/hook-api/base.js +0 -11
- package/dist/cjs/libs/hook-api/index.worker.js +0 -3
- package/dist/cjs/libs/hook-api/route.js +0 -4
- package/dist/cjs/libs/hook-api/template.js +0 -2
- package/dist/cjs/libs/render/ssrCache/cacheMod.js +0 -5
- package/dist/cjs/libs/render/ssrCache/manager.js +2 -3
- package/dist/cjs/libs/route/index.js +1 -3
- package/dist/cjs/libs/route/matcher.js +1 -5
- package/dist/cjs/libs/route/route.js +1 -10
- package/dist/cjs/libs/serverTiming.js +0 -3
- package/dist/cjs/renderHtml.js +0 -7
- package/dist/cjs/server/index.js +1 -7
- package/dist/cjs/server/modernServer.js +4 -20
- package/dist/cjs/workerServer.js +4 -8
- package/dist/esm/libs/context/context.js +66 -98
- package/dist/esm/libs/hook-api/base.js +36 -71
- package/dist/esm/libs/hook-api/index.worker.js +15 -29
- package/dist/esm/libs/hook-api/route.js +12 -27
- package/dist/esm/libs/hook-api/template.js +33 -61
- package/dist/esm/libs/render/ssrCache/cacheMod.js +10 -18
- package/dist/esm/libs/render/ssrCache/manager.js +145 -157
- package/dist/esm/libs/route/index.js +62 -96
- package/dist/esm/libs/route/matcher.js +58 -94
- package/dist/esm/libs/route/route.js +1 -10
- package/dist/esm/libs/serverTiming.js +8 -16
- package/dist/esm/renderHtml.js +22 -39
- package/dist/esm/server/index.js +307 -383
- package/dist/esm/server/modernServer.js +802 -942
- package/dist/esm/server/modernServerSplit.js +61 -86
- package/dist/esm/workerServer.js +87 -82
- package/dist/esm-node/libs/context/context.js +4 -8
- package/dist/esm-node/libs/hook-api/base.js +0 -11
- package/dist/esm-node/libs/hook-api/index.worker.js +0 -3
- package/dist/esm-node/libs/hook-api/route.js +0 -4
- package/dist/esm-node/libs/hook-api/template.js +0 -2
- package/dist/esm-node/libs/render/ssrCache/cacheMod.js +0 -5
- package/dist/esm-node/libs/render/ssrCache/manager.js +2 -3
- package/dist/esm-node/libs/route/index.js +1 -3
- package/dist/esm-node/libs/route/matcher.js +1 -5
- package/dist/esm-node/libs/route/route.js +1 -10
- package/dist/esm-node/libs/serverTiming.js +0 -3
- package/dist/esm-node/renderHtml.js +0 -7
- package/dist/esm-node/server/index.js +1 -7
- package/dist/esm-node/server/modernServer.js +4 -20
- package/dist/esm-node/workerServer.js +4 -8
- package/package.json +8 -8
|
@@ -1,188 +1,176 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
3
|
-
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
4
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
5
3
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
6
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
7
5
|
import { Transform } from "stream";
|
|
6
|
+
import { normalizePathname } from "@modern-js/runtime-utils/url";
|
|
8
7
|
var CacheManager = /* @__PURE__ */ function() {
|
|
9
8
|
"use strict";
|
|
10
9
|
function CacheManager2(container) {
|
|
11
10
|
_class_call_check(this, CacheManager2);
|
|
12
|
-
_define_property(this, "container", void 0);
|
|
13
11
|
this.container = container;
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
interval = Date.now() - cache.cursor;
|
|
37
|
-
if (interval <= maxAge) {
|
|
38
|
-
return [
|
|
39
|
-
2,
|
|
40
|
-
{
|
|
41
|
-
data: cache.val,
|
|
42
|
-
status: "hit"
|
|
43
|
-
}
|
|
44
|
-
];
|
|
45
|
-
} else if (interval <= staleWhileRevalidate + maxAge) {
|
|
46
|
-
_this.processCache(key, render, ssrContext, ttl);
|
|
47
|
-
return [
|
|
48
|
-
2,
|
|
49
|
-
{
|
|
50
|
-
data: cache.val,
|
|
51
|
-
status: "stale"
|
|
52
|
-
}
|
|
53
|
-
];
|
|
54
|
-
} else {
|
|
55
|
-
return [
|
|
56
|
-
2,
|
|
57
|
-
_this.processCache(key, render, ssrContext, ttl, "expired")
|
|
58
|
-
];
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
return [
|
|
62
|
-
2,
|
|
63
|
-
_this.processCache(key, render, ssrContext, ttl, "miss")
|
|
64
|
-
];
|
|
65
|
-
}
|
|
66
|
-
return [
|
|
67
|
-
2
|
|
68
|
-
];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
})();
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
key: "processCache",
|
|
76
|
-
value: function processCache(key, render, ssrContext, ttl, status) {
|
|
77
|
-
var _this = this;
|
|
78
|
-
return _async_to_generator(function() {
|
|
79
|
-
var renderResult, current, cache, html, stream, readable;
|
|
80
|
-
return _ts_generator(this, function(_state) {
|
|
81
|
-
switch (_state.label) {
|
|
82
|
-
case 0:
|
|
83
|
-
return [
|
|
84
|
-
4,
|
|
85
|
-
render(ssrContext)
|
|
86
|
-
];
|
|
87
|
-
case 1:
|
|
88
|
-
renderResult = _state.sent();
|
|
89
|
-
if (!!renderResult)
|
|
90
|
-
return [
|
|
91
|
-
3,
|
|
92
|
-
2
|
|
93
|
-
];
|
|
13
|
+
var _proto = CacheManager2.prototype;
|
|
14
|
+
_proto.getCacheResult = function getCacheResult(req, cacheControl, render, ssrContext) {
|
|
15
|
+
var _this = this;
|
|
16
|
+
return _async_to_generator(function() {
|
|
17
|
+
var key, value, maxAge, staleWhileRevalidate, ttl, cache, interval;
|
|
18
|
+
return _ts_generator(this, function(_state) {
|
|
19
|
+
switch (_state.label) {
|
|
20
|
+
case 0:
|
|
21
|
+
key = _this.computedKey(req, cacheControl);
|
|
22
|
+
return [
|
|
23
|
+
4,
|
|
24
|
+
_this.container.get(key)
|
|
25
|
+
];
|
|
26
|
+
case 1:
|
|
27
|
+
value = _state.sent();
|
|
28
|
+
maxAge = cacheControl.maxAge, staleWhileRevalidate = cacheControl.staleWhileRevalidate;
|
|
29
|
+
ttl = maxAge + staleWhileRevalidate;
|
|
30
|
+
if (value) {
|
|
31
|
+
cache = JSON.parse(value);
|
|
32
|
+
interval = Date.now() - cache.cursor;
|
|
33
|
+
if (interval <= maxAge) {
|
|
94
34
|
return [
|
|
95
35
|
2,
|
|
96
36
|
{
|
|
97
|
-
data:
|
|
37
|
+
data: cache.val,
|
|
38
|
+
status: "hit"
|
|
98
39
|
}
|
|
99
40
|
];
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return [
|
|
103
|
-
3,
|
|
104
|
-
4
|
|
105
|
-
];
|
|
106
|
-
current = Date.now();
|
|
107
|
-
cache = {
|
|
108
|
-
val: renderResult,
|
|
109
|
-
cursor: current
|
|
110
|
-
};
|
|
111
|
-
return [
|
|
112
|
-
4,
|
|
113
|
-
_this.container.set(key, JSON.stringify(cache), {
|
|
114
|
-
ttl
|
|
115
|
-
})
|
|
116
|
-
];
|
|
117
|
-
case 3:
|
|
118
|
-
_state.sent();
|
|
41
|
+
} else if (interval <= staleWhileRevalidate + maxAge) {
|
|
42
|
+
_this.processCache(key, render, ssrContext, ttl);
|
|
119
43
|
return [
|
|
120
44
|
2,
|
|
121
45
|
{
|
|
122
|
-
data:
|
|
123
|
-
status
|
|
46
|
+
data: cache.val,
|
|
47
|
+
status: "stale"
|
|
124
48
|
}
|
|
125
49
|
];
|
|
126
|
-
|
|
127
|
-
html = "";
|
|
128
|
-
stream = new Transform({
|
|
129
|
-
write: function write(chunk, _, callback) {
|
|
130
|
-
html += chunk.toString();
|
|
131
|
-
this.push(chunk);
|
|
132
|
-
callback();
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
stream.on("close", function() {
|
|
136
|
-
var current2 = Date.now();
|
|
137
|
-
var cache2 = {
|
|
138
|
-
val: html,
|
|
139
|
-
cursor: current2
|
|
140
|
-
};
|
|
141
|
-
_this.container.set(key, JSON.stringify(cache2), {
|
|
142
|
-
ttl
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
return [
|
|
146
|
-
4,
|
|
147
|
-
renderResult(stream)
|
|
148
|
-
];
|
|
149
|
-
case 5:
|
|
150
|
-
readable = _state.sent();
|
|
50
|
+
} else {
|
|
151
51
|
return [
|
|
152
52
|
2,
|
|
153
|
-
|
|
154
|
-
data: readable,
|
|
155
|
-
status
|
|
156
|
-
}
|
|
157
|
-
];
|
|
158
|
-
case 6:
|
|
159
|
-
return [
|
|
160
|
-
2
|
|
53
|
+
_this.processCache(key, render, ssrContext, ttl, "expired")
|
|
161
54
|
];
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
return [
|
|
58
|
+
2,
|
|
59
|
+
_this.processCache(key, render, ssrContext, ttl, "miss")
|
|
60
|
+
];
|
|
162
61
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
62
|
+
return [
|
|
63
|
+
2
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
})();
|
|
68
|
+
};
|
|
69
|
+
_proto.processCache = function processCache(key, render, ssrContext, ttl, status) {
|
|
70
|
+
var _this = this;
|
|
71
|
+
return _async_to_generator(function() {
|
|
72
|
+
var renderResult, current, cache, html, stream, readable;
|
|
73
|
+
return _ts_generator(this, function(_state) {
|
|
74
|
+
switch (_state.label) {
|
|
75
|
+
case 0:
|
|
76
|
+
return [
|
|
77
|
+
4,
|
|
78
|
+
render(ssrContext)
|
|
79
|
+
];
|
|
80
|
+
case 1:
|
|
81
|
+
renderResult = _state.sent();
|
|
82
|
+
if (!!renderResult)
|
|
83
|
+
return [
|
|
84
|
+
3,
|
|
85
|
+
2
|
|
86
|
+
];
|
|
87
|
+
return [
|
|
88
|
+
2,
|
|
89
|
+
{
|
|
90
|
+
data: ""
|
|
91
|
+
}
|
|
92
|
+
];
|
|
93
|
+
case 2:
|
|
94
|
+
if (!(typeof renderResult === "string"))
|
|
95
|
+
return [
|
|
96
|
+
3,
|
|
97
|
+
4
|
|
98
|
+
];
|
|
99
|
+
current = Date.now();
|
|
100
|
+
cache = {
|
|
101
|
+
val: renderResult,
|
|
102
|
+
cursor: current
|
|
103
|
+
};
|
|
104
|
+
return [
|
|
105
|
+
4,
|
|
106
|
+
_this.container.set(key, JSON.stringify(cache), {
|
|
107
|
+
ttl
|
|
108
|
+
})
|
|
109
|
+
];
|
|
110
|
+
case 3:
|
|
111
|
+
_state.sent();
|
|
112
|
+
return [
|
|
113
|
+
2,
|
|
114
|
+
{
|
|
115
|
+
data: renderResult,
|
|
116
|
+
status
|
|
117
|
+
}
|
|
118
|
+
];
|
|
119
|
+
case 4:
|
|
120
|
+
html = "";
|
|
121
|
+
stream = new Transform({
|
|
122
|
+
write: function write(chunk, _, callback) {
|
|
123
|
+
html += chunk.toString();
|
|
124
|
+
this.push(chunk);
|
|
125
|
+
callback();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
stream.on("close", function() {
|
|
129
|
+
var current2 = Date.now();
|
|
130
|
+
var cache2 = {
|
|
131
|
+
val: html,
|
|
132
|
+
cursor: current2
|
|
133
|
+
};
|
|
134
|
+
_this.container.set(key, JSON.stringify(cache2), {
|
|
135
|
+
ttl
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
return [
|
|
139
|
+
4,
|
|
140
|
+
renderResult(stream)
|
|
141
|
+
];
|
|
142
|
+
case 5:
|
|
143
|
+
readable = _state.sent();
|
|
144
|
+
return [
|
|
145
|
+
2,
|
|
146
|
+
{
|
|
147
|
+
data: readable,
|
|
148
|
+
status
|
|
149
|
+
}
|
|
150
|
+
];
|
|
151
|
+
case 6:
|
|
152
|
+
return [
|
|
153
|
+
2
|
|
154
|
+
];
|
|
182
155
|
}
|
|
156
|
+
});
|
|
157
|
+
})();
|
|
158
|
+
};
|
|
159
|
+
_proto.computedKey = function computedKey(req, cacheControl) {
|
|
160
|
+
var url = req.url;
|
|
161
|
+
var _url_split = _sliced_to_array(url.split("?"), 1), pathname = _url_split[0];
|
|
162
|
+
var customKey = cacheControl.customKey;
|
|
163
|
+
var defaultKey = normalizePathname(pathname);
|
|
164
|
+
if (customKey) {
|
|
165
|
+
if (typeof customKey === "string") {
|
|
166
|
+
return customKey;
|
|
167
|
+
} else {
|
|
168
|
+
return customKey(defaultKey);
|
|
183
169
|
}
|
|
170
|
+
} else {
|
|
171
|
+
return defaultKey;
|
|
184
172
|
}
|
|
185
|
-
|
|
173
|
+
};
|
|
186
174
|
return CacheManager2;
|
|
187
175
|
}();
|
|
188
176
|
export {
|
|
@@ -1,113 +1,79 @@
|
|
|
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 { RouteMatcher } from "./matcher";
|
|
5
3
|
var RouteMatchManager = /* @__PURE__ */ function() {
|
|
6
4
|
"use strict";
|
|
7
5
|
function RouteMatchManager2() {
|
|
8
6
|
_class_call_check(this, RouteMatchManager2);
|
|
9
|
-
|
|
10
|
-
_define_property(this, "specs", []);
|
|
7
|
+
this.specs = [];
|
|
11
8
|
this.matchers = [];
|
|
12
9
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
var _proto = RouteMatchManager2.prototype;
|
|
11
|
+
_proto.filter = function filter(pathname) {
|
|
12
|
+
return this.matchers.reduce(function(matches, matcher) {
|
|
13
|
+
if (matcher.matchUrlPath(pathname)) {
|
|
14
|
+
matches.push(matcher);
|
|
15
|
+
}
|
|
16
|
+
return matches;
|
|
17
|
+
}, []);
|
|
18
|
+
};
|
|
19
|
+
_proto.best = function best(pathname, matches) {
|
|
20
|
+
var best2;
|
|
21
|
+
var matchedLen = 0;
|
|
22
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
23
|
+
try {
|
|
24
|
+
for (var _iterator = matches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
25
|
+
var match = _step.value;
|
|
26
|
+
var len = match.matchLength(pathname);
|
|
27
|
+
if (len === null) {
|
|
28
|
+
continue;
|
|
25
29
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
key: "best",
|
|
30
|
-
value: (
|
|
31
|
-
// get best match from a set of matches
|
|
32
|
-
function best(pathname, matches) {
|
|
33
|
-
var best2;
|
|
34
|
-
var matchedLen = 0;
|
|
35
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
36
|
-
try {
|
|
37
|
-
for (var _iterator = matches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
38
|
-
var match = _step.value;
|
|
39
|
-
var len = match.matchLength(pathname);
|
|
40
|
-
if (len === null) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (len > matchedLen) {
|
|
44
|
-
best2 = match;
|
|
45
|
-
matchedLen = len;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
} catch (err) {
|
|
49
|
-
_didIteratorError = true;
|
|
50
|
-
_iteratorError = err;
|
|
51
|
-
} finally {
|
|
52
|
-
try {
|
|
53
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
54
|
-
_iterator.return();
|
|
55
|
-
}
|
|
56
|
-
} finally {
|
|
57
|
-
if (_didIteratorError) {
|
|
58
|
-
throw _iteratorError;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return best2;
|
|
30
|
+
if (len > matchedLen) {
|
|
31
|
+
best2 = match;
|
|
32
|
+
matchedLen = len;
|
|
63
33
|
}
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
var matchers = specs.reduce(function(ms, spec) {
|
|
73
|
-
ms.push(new RouteMatcher(spec));
|
|
74
|
-
return ms;
|
|
75
|
-
}, []);
|
|
76
|
-
this.matchers = matchers;
|
|
34
|
+
}
|
|
35
|
+
} catch (err) {
|
|
36
|
+
_didIteratorError = true;
|
|
37
|
+
_iteratorError = err;
|
|
38
|
+
} finally {
|
|
39
|
+
try {
|
|
40
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
41
|
+
_iterator.return();
|
|
77
42
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
key: "match",
|
|
82
|
-
value: (
|
|
83
|
-
// get best match from all matcher in manager
|
|
84
|
-
function match(pathname) {
|
|
85
|
-
var matches = this.filter(pathname);
|
|
86
|
-
var best = this.best(pathname, matches);
|
|
87
|
-
return best;
|
|
43
|
+
} finally {
|
|
44
|
+
if (_didIteratorError) {
|
|
45
|
+
throw _iteratorError;
|
|
88
46
|
}
|
|
89
|
-
)
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
key: "matchEntry",
|
|
93
|
-
value: function matchEntry(entryname) {
|
|
94
|
-
return this.matchers.find(function(matcher) {
|
|
95
|
-
return matcher.matchEntry(entryname);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
key: "getBundles",
|
|
101
|
-
value: function getBundles() {
|
|
102
|
-
var bundles = this.specs.filter(function(route) {
|
|
103
|
-
return route.isSSR;
|
|
104
|
-
}).map(function(route) {
|
|
105
|
-
return route.bundle;
|
|
106
|
-
});
|
|
107
|
-
return bundles;
|
|
108
47
|
}
|
|
109
48
|
}
|
|
110
|
-
|
|
49
|
+
return best2;
|
|
50
|
+
};
|
|
51
|
+
_proto.reset = function reset(specs) {
|
|
52
|
+
this.specs = specs;
|
|
53
|
+
var matchers = specs.reduce(function(ms, spec) {
|
|
54
|
+
ms.push(new RouteMatcher(spec));
|
|
55
|
+
return ms;
|
|
56
|
+
}, []);
|
|
57
|
+
this.matchers = matchers;
|
|
58
|
+
};
|
|
59
|
+
_proto.match = function match(pathname) {
|
|
60
|
+
var matches = this.filter(pathname);
|
|
61
|
+
var best = this.best(pathname, matches);
|
|
62
|
+
return best;
|
|
63
|
+
};
|
|
64
|
+
_proto.matchEntry = function matchEntry(entryname) {
|
|
65
|
+
return this.matchers.find(function(matcher) {
|
|
66
|
+
return matcher.matchEntry(entryname);
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
_proto.getBundles = function getBundles() {
|
|
70
|
+
var bundles = this.specs.filter(function(route) {
|
|
71
|
+
return route.isSSR;
|
|
72
|
+
}).map(function(route) {
|
|
73
|
+
return route.bundle;
|
|
74
|
+
});
|
|
75
|
+
return bundles;
|
|
76
|
+
};
|
|
111
77
|
return RouteMatchManager2;
|
|
112
78
|
}();
|
|
113
79
|
export {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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 {
|