@modern-js/server-core 2.60.4-alpha.0 → 2.60.5-alpha.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.
@@ -57,7 +57,7 @@ const createWebRequest = (req, res, body) => {
57
57
  signal: controller.signal
58
58
  };
59
59
  res.on("close", () => controller.abort("res closed"));
60
- if (body || !(method === "GET" || method === "HEAD") && ((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes("__loader"))) {
60
+ if (body || !(method === "GET" || method === "HEAD") && ((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes("__loader")) || req.headers["x-mf-micro"]) {
61
61
  init.body = body !== null && body !== void 0 ? body : (0, import_stream.createReadableStreamFromReadable)(req);
62
62
  init.duplex = "half";
63
63
  }
@@ -29,6 +29,7 @@ const ZERO_RENDER_LEVEL = /"renderLevel":0/;
29
29
  const NO_SSR_CACHE = /<meta\s+[^>]*name=["']no-ssr-cache["'][^>]*>/i;
30
30
  async function processCache({ request, key, requestHandler, requestHandlerOptions, ttl, container, cacheStatus }) {
31
31
  const response = await requestHandler(request, requestHandlerOptions);
32
+ const { onError } = requestHandlerOptions;
32
33
  const decoder = new TextDecoder();
33
34
  if (response.body) {
34
35
  const stream = (0, import_utils.createTransformStream)();
@@ -49,6 +50,12 @@ async function processCache({ request, key, requestHandler, requestHandlerOption
49
50
  };
50
51
  container.set(key, JSON.stringify(cache), {
51
52
  ttl
53
+ }).catch(() => {
54
+ if (onError) {
55
+ onError(`[render-cache] set cache failed, key: ${key}, value: ${JSON.stringify(cache)}`);
56
+ } else {
57
+ console.error(`[render-cache] set cache failed, key: ${key}, value: ${JSON.stringify(cache)}`);
58
+ }
52
59
  });
53
60
  writer.close();
54
61
  return;
@@ -113,8 +120,19 @@ function matchCacheControl(cacheOption, req) {
113
120
  }
114
121
  async function getCacheResult(request, options) {
115
122
  const { cacheControl, container = storage, requestHandler, requestHandlerOptions } = options;
123
+ const { onError } = requestHandlerOptions;
116
124
  const key = computedKey(request, cacheControl);
117
- const value = await container.get(key);
125
+ let value;
126
+ try {
127
+ value = await container.get(key);
128
+ } catch (_) {
129
+ if (onError) {
130
+ onError(`[render-cache] get cache failed, key: ${key}`);
131
+ } else {
132
+ console.error(`[render-cache] get cache failed, key: ${key}`);
133
+ }
134
+ value = void 0;
135
+ }
118
136
  const { maxAge, staleWhileRevalidate } = cacheControl;
119
137
  const ttl = maxAge + staleWhileRevalidate;
120
138
  if (value) {
@@ -27,7 +27,7 @@ var createWebRequest = function(req, res, body) {
27
27
  res.on("close", function() {
28
28
  return controller.abort("res closed");
29
29
  });
30
- if (body || !(method === "GET" || method === "HEAD") && ((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes("__loader"))) {
30
+ if (body || !(method === "GET" || method === "HEAD") && ((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes("__loader")) || req.headers["x-mf-micro"]) {
31
31
  init.body = body !== null && body !== void 0 ? body : createReadableStreamFromReadable(req);
32
32
  init.duplex = "half";
33
33
  }
@@ -13,7 +13,7 @@ function processCache(_) {
13
13
  }
14
14
  function _processCache() {
15
15
  _processCache = _async_to_generator(function(param) {
16
- var request, key, requestHandler, requestHandlerOptions, ttl, container, cacheStatus, response, decoder, stream, reader, writer, html, push;
16
+ var request, key, requestHandler, requestHandlerOptions, ttl, container, cacheStatus, response, onError, decoder, stream, reader, writer, html, push;
17
17
  return _ts_generator(this, function(_state) {
18
18
  switch (_state.label) {
19
19
  case 0:
@@ -24,6 +24,7 @@ function _processCache() {
24
24
  ];
25
25
  case 1:
26
26
  response = _state.sent();
27
+ onError = requestHandlerOptions.onError;
27
28
  decoder = new TextDecoder();
28
29
  if (response.body) {
29
30
  stream = createTransformStream();
@@ -46,6 +47,12 @@ function _processCache() {
46
47
  };
47
48
  container.set(key, JSON.stringify(cache), {
48
49
  ttl
50
+ }).catch(function() {
51
+ if (onError) {
52
+ onError("[render-cache] set cache failed, key: ".concat(key, ", value: ").concat(JSON.stringify(cache)));
53
+ } else {
54
+ console.error("[render-cache] set cache failed, key: ".concat(key, ", value: ").concat(JSON.stringify(cache)));
55
+ }
49
56
  });
50
57
  writer.close();
51
58
  return;
@@ -141,18 +148,44 @@ function getCacheResult(request, options) {
141
148
  }
142
149
  function _getCacheResult() {
143
150
  _getCacheResult = _async_to_generator(function(request, options) {
144
- var cacheControl, _options_container, container, requestHandler, requestHandlerOptions, key, value, maxAge, staleWhileRevalidate, ttl, cache, interval, cacheStatus, cacheStatus1;
151
+ var cacheControl, _options_container, container, requestHandler, requestHandlerOptions, onError, key, value, _, maxAge, staleWhileRevalidate, ttl, cache, interval, cacheStatus, cacheStatus1;
145
152
  return _ts_generator(this, function(_state) {
146
153
  switch (_state.label) {
147
154
  case 0:
148
155
  cacheControl = options.cacheControl, _options_container = options.container, container = _options_container === void 0 ? storage : _options_container, requestHandler = options.requestHandler, requestHandlerOptions = options.requestHandlerOptions;
156
+ onError = requestHandlerOptions.onError;
149
157
  key = computedKey(request, cacheControl);
158
+ _state.label = 1;
159
+ case 1:
160
+ _state.trys.push([
161
+ 1,
162
+ 3,
163
+ ,
164
+ 4
165
+ ]);
150
166
  return [
151
167
  4,
152
168
  container.get(key)
153
169
  ];
154
- case 1:
170
+ case 2:
155
171
  value = _state.sent();
172
+ return [
173
+ 3,
174
+ 4
175
+ ];
176
+ case 3:
177
+ _ = _state.sent();
178
+ if (onError) {
179
+ onError("[render-cache] get cache failed, key: ".concat(key));
180
+ } else {
181
+ console.error("[render-cache] get cache failed, key: ".concat(key));
182
+ }
183
+ value = void 0;
184
+ return [
185
+ 3,
186
+ 4
187
+ ];
188
+ case 4:
156
189
  maxAge = cacheControl.maxAge, staleWhileRevalidate = cacheControl.staleWhileRevalidate;
157
190
  ttl = maxAge + staleWhileRevalidate;
158
191
  if (value) {
@@ -21,7 +21,7 @@ const createWebRequest = (req, res, body) => {
21
21
  signal: controller.signal
22
22
  };
23
23
  res.on("close", () => controller.abort("res closed"));
24
- if (body || !(method === "GET" || method === "HEAD") && ((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes("__loader"))) {
24
+ if (body || !(method === "GET" || method === "HEAD") && ((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes("__loader")) || req.headers["x-mf-micro"]) {
25
25
  init.body = body !== null && body !== void 0 ? body : createReadableStreamFromReadable(req);
26
26
  init.duplex = "half";
27
27
  }
@@ -5,6 +5,7 @@ const ZERO_RENDER_LEVEL = /"renderLevel":0/;
5
5
  const NO_SSR_CACHE = /<meta\s+[^>]*name=["']no-ssr-cache["'][^>]*>/i;
6
6
  async function processCache({ request, key, requestHandler, requestHandlerOptions, ttl, container, cacheStatus }) {
7
7
  const response = await requestHandler(request, requestHandlerOptions);
8
+ const { onError } = requestHandlerOptions;
8
9
  const decoder = new TextDecoder();
9
10
  if (response.body) {
10
11
  const stream = createTransformStream();
@@ -25,6 +26,12 @@ async function processCache({ request, key, requestHandler, requestHandlerOption
25
26
  };
26
27
  container.set(key, JSON.stringify(cache), {
27
28
  ttl
29
+ }).catch(() => {
30
+ if (onError) {
31
+ onError(`[render-cache] set cache failed, key: ${key}, value: ${JSON.stringify(cache)}`);
32
+ } else {
33
+ console.error(`[render-cache] set cache failed, key: ${key}, value: ${JSON.stringify(cache)}`);
34
+ }
28
35
  });
29
36
  writer.close();
30
37
  return;
@@ -89,8 +96,19 @@ function matchCacheControl(cacheOption, req) {
89
96
  }
90
97
  async function getCacheResult(request, options) {
91
98
  const { cacheControl, container = storage, requestHandler, requestHandlerOptions } = options;
99
+ const { onError } = requestHandlerOptions;
92
100
  const key = computedKey(request, cacheControl);
93
- const value = await container.get(key);
101
+ let value;
102
+ try {
103
+ value = await container.get(key);
104
+ } catch (_) {
105
+ if (onError) {
106
+ onError(`[render-cache] get cache failed, key: ${key}`);
107
+ } else {
108
+ console.error(`[render-cache] get cache failed, key: ${key}`);
109
+ }
110
+ value = void 0;
111
+ }
94
112
  const { maxAge, staleWhileRevalidate } = cacheControl;
95
113
  const ttl = maxAge + staleWhileRevalidate;
96
114
  if (value) {
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.60.4-alpha.0",
18
+ "version": "2.60.5-alpha.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -53,9 +53,9 @@
53
53
  "flatted": "^3.2.9",
54
54
  "hono": "^3.12.2",
55
55
  "ts-deepmerge": "7.0.1",
56
- "@modern-js/utils": "2.60.3",
57
- "@modern-js/plugin": "2.60.3",
58
- "@modern-js/runtime-utils": "2.60.3"
56
+ "@modern-js/runtime-utils": "2.60.4",
57
+ "@modern-js/utils": "2.60.4",
58
+ "@modern-js/plugin": "2.60.4"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/jest": "^29",
@@ -65,9 +65,9 @@
65
65
  "jest": "^29",
66
66
  "ts-jest": "^29.1.0",
67
67
  "typescript": "^5",
68
- "@scripts/build": "2.60.3",
69
- "@modern-js/types": "2.60.3",
70
- "@scripts/jest-config": "2.60.3"
68
+ "@modern-js/types": "2.60.4",
69
+ "@scripts/build": "2.60.4",
70
+ "@scripts/jest-config": "2.60.4"
71
71
  },
72
72
  "sideEffects": false,
73
73
  "publishConfig": {