@modern-js/prod-server 2.0.0-beta.3 → 2.0.0-beta.4

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 (130) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/js/modern/constants.js +32 -25
  3. package/dist/js/modern/index.js +11 -6
  4. package/dist/js/modern/libs/context/context.js +52 -84
  5. package/dist/js/modern/libs/context/index.js +5 -2
  6. package/dist/js/modern/libs/hook-api/index.js +42 -35
  7. package/dist/js/modern/libs/hook-api/route.js +6 -7
  8. package/dist/js/modern/libs/hook-api/template.js +20 -34
  9. package/dist/js/modern/libs/loadConfig.js +45 -24
  10. package/dist/js/modern/libs/metrics.js +3 -4
  11. package/dist/js/modern/libs/proxy.js +68 -37
  12. package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +112 -67
  13. package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +246 -216
  14. package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +43 -49
  15. package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +36 -34
  16. package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +83 -113
  17. package/dist/js/modern/libs/render/cache/index.js +88 -54
  18. package/dist/js/modern/libs/render/cache/page-caches/index.js +31 -8
  19. package/dist/js/modern/libs/render/cache/page-caches/lru.js +6 -6
  20. package/dist/js/modern/libs/render/cache/spr.js +133 -117
  21. package/dist/js/modern/libs/render/cache/type.js +0 -1
  22. package/dist/js/modern/libs/render/cache/util.js +71 -39
  23. package/dist/js/modern/libs/render/index.js +76 -56
  24. package/dist/js/modern/libs/render/measure.js +38 -27
  25. package/dist/js/modern/libs/render/reader.js +65 -62
  26. package/dist/js/modern/libs/render/ssr.js +50 -32
  27. package/dist/js/modern/libs/render/static.js +50 -33
  28. package/dist/js/modern/libs/render/type.js +9 -6
  29. package/dist/js/modern/libs/route/index.js +8 -15
  30. package/dist/js/modern/libs/route/matcher.js +20 -34
  31. package/dist/js/modern/libs/route/route.js +9 -18
  32. package/dist/js/modern/libs/serve-file.js +33 -20
  33. package/dist/js/modern/server/index.js +144 -145
  34. package/dist/js/modern/server/modern-server-split.js +46 -12
  35. package/dist/js/modern/server/modern-server.js +377 -417
  36. package/dist/js/modern/type.js +0 -1
  37. package/dist/js/modern/utils.js +62 -43
  38. package/dist/js/modern/worker-server.js +34 -14
  39. package/dist/js/node/constants.js +45 -30
  40. package/dist/js/node/index.js +31 -57
  41. package/dist/js/node/libs/context/context.js +79 -94
  42. package/dist/js/node/libs/context/index.js +23 -13
  43. package/dist/js/node/libs/hook-api/index.js +69 -48
  44. package/dist/js/node/libs/hook-api/route.js +22 -11
  45. package/dist/js/node/libs/hook-api/template.js +36 -39
  46. package/dist/js/node/libs/loadConfig.js +69 -35
  47. package/dist/js/node/libs/metrics.js +21 -9
  48. package/dist/js/node/libs/proxy.js +86 -44
  49. package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +132 -70
  50. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +268 -218
  51. package/dist/js/node/libs/render/cache/__tests__/cacheable.js +61 -55
  52. package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +54 -40
  53. package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +101 -119
  54. package/dist/js/node/libs/render/cache/index.js +110 -64
  55. package/dist/js/node/libs/render/cache/page-caches/index.js +50 -14
  56. package/dist/js/node/libs/render/cache/page-caches/lru.js +29 -12
  57. package/dist/js/node/libs/render/cache/spr.js +156 -129
  58. package/dist/js/node/libs/render/cache/type.js +0 -5
  59. package/dist/js/node/libs/render/cache/util.js +88 -45
  60. package/dist/js/node/libs/render/index.js +102 -67
  61. package/dist/js/node/libs/render/measure.js +55 -31
  62. package/dist/js/node/libs/render/reader.js +87 -70
  63. package/dist/js/node/libs/render/ssr.js +76 -47
  64. package/dist/js/node/libs/render/static.js +75 -40
  65. package/dist/js/node/libs/render/type.js +27 -12
  66. package/dist/js/node/libs/route/index.js +26 -26
  67. package/dist/js/node/libs/route/matcher.js +36 -41
  68. package/dist/js/node/libs/route/route.js +25 -22
  69. package/dist/js/node/libs/serve-file.js +61 -32
  70. package/dist/js/node/server/index.js +160 -160
  71. package/dist/js/node/server/modern-server-split.js +68 -22
  72. package/dist/js/node/server/modern-server.js +395 -441
  73. package/dist/js/node/type.js +0 -3
  74. package/dist/js/node/utils.js +74 -52
  75. package/dist/js/node/worker-server.js +53 -21
  76. package/dist/js/treeshaking/constants.js +26 -25
  77. package/dist/js/treeshaking/index.js +10 -10
  78. package/dist/js/treeshaking/libs/context/context.js +268 -237
  79. package/dist/js/treeshaking/libs/context/index.js +3 -3
  80. package/dist/js/treeshaking/libs/hook-api/index.js +265 -143
  81. package/dist/js/treeshaking/libs/hook-api/route.js +65 -30
  82. package/dist/js/treeshaking/libs/hook-api/template.js +121 -85
  83. package/dist/js/treeshaking/libs/loadConfig.js +80 -37
  84. package/dist/js/treeshaking/libs/metrics.js +4 -10
  85. package/dist/js/treeshaking/libs/proxy.js +240 -76
  86. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +288 -121
  87. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +772 -455
  88. package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +65 -51
  89. package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -35
  90. package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +144 -118
  91. package/dist/js/treeshaking/libs/render/cache/index.js +337 -175
  92. package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +151 -27
  93. package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +80 -42
  94. package/dist/js/treeshaking/libs/render/cache/spr.js +470 -340
  95. package/dist/js/treeshaking/libs/render/cache/type.js +1 -1
  96. package/dist/js/treeshaking/libs/render/cache/util.js +271 -92
  97. package/dist/js/treeshaking/libs/render/index.js +228 -95
  98. package/dist/js/treeshaking/libs/render/measure.js +142 -57
  99. package/dist/js/treeshaking/libs/render/reader.js +325 -177
  100. package/dist/js/treeshaking/libs/render/ssr.js +220 -95
  101. package/dist/js/treeshaking/libs/render/static.js +210 -78
  102. package/dist/js/treeshaking/libs/render/type.js +7 -6
  103. package/dist/js/treeshaking/libs/route/index.js +125 -89
  104. package/dist/js/treeshaking/libs/route/matcher.js +132 -107
  105. package/dist/js/treeshaking/libs/route/route.js +40 -26
  106. package/dist/js/treeshaking/libs/serve-file.js +177 -68
  107. package/dist/js/treeshaking/server/index.js +468 -327
  108. package/dist/js/treeshaking/server/modern-server-split.js +352 -144
  109. package/dist/js/treeshaking/server/modern-server.js +1046 -909
  110. package/dist/js/treeshaking/type.js +1 -1
  111. package/dist/js/treeshaking/utils.js +138 -81
  112. package/dist/js/treeshaking/worker-server.js +176 -55
  113. package/dist/types/index.d.ts +2 -0
  114. package/dist/types/libs/context/context.d.ts +4 -1
  115. package/dist/types/libs/loadConfig.d.ts +1 -0
  116. package/dist/types/libs/render/cache/index.d.ts +2 -0
  117. package/dist/types/libs/render/cache/spr.d.ts +2 -0
  118. package/dist/types/libs/route/route.d.ts +0 -1
  119. package/dist/types/server/index.d.ts +3 -0
  120. package/dist/types/utils.d.ts +1 -1
  121. package/dist/types/worker-server.d.ts +1 -2
  122. package/package.json +7 -14
  123. package/dist/js/modern/libs/render/modern/browser-list.js +0 -7
  124. package/dist/js/modern/libs/render/modern/index.js +0 -37
  125. package/dist/js/node/libs/render/modern/browser-list.js +0 -14
  126. package/dist/js/node/libs/render/modern/index.js +0 -46
  127. package/dist/js/treeshaking/libs/render/modern/browser-list.js +0 -7
  128. package/dist/js/treeshaking/libs/render/modern/index.js +0 -39
  129. package/dist/types/libs/render/modern/browser-list.d.ts +0 -1
  130. package/dist/types/libs/render/modern/index.d.ts +0 -3
@@ -1,17 +1,57 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var stdin_exports = {};
25
+ __export(stdin_exports, {
26
+ createCache: () => createCache,
27
+ destroyCache: () => destroyCache
5
28
  });
6
- exports.createCache = createCache;
7
- exports.destroyCache = destroyCache;
8
- var _crypto = _interopRequireDefault(require("crypto"));
9
- var _lruCache = _interopRequireDefault(require("lru-cache"));
10
- var _utils = require("@modern-js/utils");
11
- var _util = require("./util");
12
- var _pageCaches = require("./page-caches");
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
29
+ module.exports = __toCommonJS(stdin_exports);
30
+ var import_crypto = __toESM(require("crypto"));
31
+ var import_lru_cache = __toESM(require("lru-cache"));
32
+ var import_utils = require("@modern-js/utils");
33
+ var import_util = require("./util");
34
+ var import_page_caches = require("./page-caches");
35
+ var __async = (__this, __arguments, generator) => {
36
+ return new Promise((resolve, reject) => {
37
+ var fulfilled = (value) => {
38
+ try {
39
+ step(generator.next(value));
40
+ } catch (e) {
41
+ reject(e);
42
+ }
43
+ };
44
+ var rejected = (value) => {
45
+ try {
46
+ step(generator.throw(value));
47
+ } catch (e) {
48
+ reject(e);
49
+ }
50
+ };
51
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
52
+ step((generator = generator.apply(__this, __arguments)).next());
53
+ });
54
+ };
15
55
  const MAX_CACHE_EACH_REQ = Number(process.env.ROUTE_CACHE_LIMIT) || 10;
16
56
  const MAX_SIZE_EACH_CLUSTER = Number(process.env.CLUSTER_CACHE_LIMIT) || 100;
17
57
  const BASE_LEVEL = 0;
@@ -20,70 +60,61 @@ const HEADER_LEVEL = 2;
20
60
  const QUERY_HEADER_LEVEL = 3;
21
61
  class CacheManager {
22
62
  constructor(cacheOptions) {
23
- _defineProperty(this, "cache", void 0);
24
- _defineProperty(this, "cacheOptions", void 0);
25
- _defineProperty(this, "find", (() => {
63
+ this.find = (() => {
26
64
  {
27
- // eslint-disable-next-line consistent-this,@typescript-eslint/no-this-alias
28
65
  const _this = this;
29
66
  return {
30
- [(0, _util.fname)(BASE_LEVEL)](context, cacheKey
31
- // data: CacheContent,
32
- ) {
67
+ [(0, import_util.fname)(BASE_LEVEL)](context, cacheKey) {
33
68
  return _this.md5(cacheKey);
34
69
  },
35
- [(0, _util.fname)(QUERY_LEVEL)](context, cacheKey, data) {
70
+ [(0, import_util.fname)(QUERY_LEVEL)](context, cacheKey, data) {
36
71
  const queryFactor = _this.queryFactor(context, data);
37
72
  if (!queryFactor) {
38
73
  return null;
39
74
  }
40
- return _this.md5((0, _util.connectFactor)(cacheKey, queryFactor));
75
+ return _this.md5((0, import_util.connectFactor)(cacheKey, queryFactor));
41
76
  },
42
- [(0, _util.fname)(HEADER_LEVEL)](context, cacheKey, data) {
77
+ [(0, import_util.fname)(HEADER_LEVEL)](context, cacheKey, data) {
43
78
  const headerFactor = _this.headerFactor(context, data);
44
79
  if (!headerFactor) {
45
80
  return null;
46
81
  }
47
- return _this.md5((0, _util.connectFactor)(cacheKey, headerFactor));
82
+ return _this.md5((0, import_util.connectFactor)(cacheKey, headerFactor));
48
83
  },
49
- [(0, _util.fname)(QUERY_HEADER_LEVEL)](context, cacheKey, data) {
84
+ [(0, import_util.fname)(QUERY_HEADER_LEVEL)](context, cacheKey, data) {
50
85
  const queryFactor = _this.queryFactor(context, data);
51
86
  const headerFactor = _this.headerFactor(context, data);
52
87
  if (!queryFactor || !headerFactor) {
53
88
  return null;
54
89
  }
55
- return _this.md5((0, _util.connectFactor)(cacheKey, headerFactor, queryFactor));
90
+ return _this.md5((0, import_util.connectFactor)(cacheKey, headerFactor, queryFactor));
56
91
  }
57
92
  };
58
93
  }
59
- })());
94
+ })();
60
95
  this.cacheOptions = cacheOptions;
61
- this.cache = new _lruCache.default({
96
+ this.cache = new import_lru_cache.default({
62
97
  max: Math.min(MAX_SIZE_EACH_CLUSTER, 600) * 1024 * 1024,
63
- // 默认存 100M,最大 600M
64
98
  length(n) {
65
99
  const len = n.caches.keys().reduce((total, cur) => {
66
- var _n$caches$peek;
67
- return total + (((_n$caches$peek = n.caches.peek(cur)) === null || _n$caches$peek === void 0 ? void 0 : _n$caches$peek.size) || 0);
100
+ var _a;
101
+ return total + (((_a = n.caches.peek(cur)) == null ? void 0 : _a.size) || 0);
68
102
  }, 1);
69
103
  return len;
70
104
  }
71
105
  });
72
106
  }
73
107
  md5(content) {
74
- const md5 = _crypto.default.createHash('md5');
75
- return md5.update(content).digest('hex');
108
+ const md5 = import_crypto.default.createHash("md5");
109
+ return md5.update(content).digest("hex");
76
110
  }
77
111
  generateRequestKey(context) {
78
- const {
79
- pathname,
80
- entry
81
- } = context;
112
+ const { pathname, entry } = context;
82
113
  return this.md5(`${pathname}_${entry}`);
83
114
  }
84
115
  replaceValue(value, matcher) {
85
116
  let final = value;
86
- Object.keys(matcher).some(replacer => {
117
+ Object.keys(matcher).some((replacer) => {
87
118
  const reg = new RegExp(matcher[replacer]);
88
119
  if (reg.test(value)) {
89
120
  final = replacer;
@@ -95,21 +126,21 @@ class CacheManager {
95
126
  }
96
127
  factor(keys, obj, matches = {}) {
97
128
  keys.sort();
98
- const getValue = (0, _util.valueFactory)(obj);
129
+ const getValue = (0, import_util.valueFactory)(obj);
99
130
  const factorAry = keys.reduce((ary, key) => {
100
- let value = getValue(key) || '';
131
+ let value = getValue(key) || "";
101
132
  const matcher = matches[key];
102
133
  if (matcher) {
103
134
  value = this.replaceValue(value, matcher);
104
135
  }
105
136
  return ary.concat([key, value]);
106
137
  }, []);
107
- return factorAry.join(',');
138
+ return factorAry.join(",");
108
139
  }
109
140
  queryFactor(context, data) {
110
- var _data$includes, _data$matches;
111
- const queryKeys = (_data$includes = data.includes) === null || _data$includes === void 0 ? void 0 : _data$includes.query;
112
- const queryMatches = (_data$matches = data.matches) === null || _data$matches === void 0 ? void 0 : _data$matches.query;
141
+ var _a, _b;
142
+ const queryKeys = (_a = data.includes) == null ? void 0 : _a.query;
143
+ const queryMatches = (_b = data.matches) == null ? void 0 : _b.query;
113
144
  if (!queryKeys || queryKeys.length === 0) {
114
145
  return null;
115
146
  }
@@ -118,9 +149,9 @@ class CacheManager {
118
149
  return queryFactor;
119
150
  }
120
151
  headerFactor(context, data) {
121
- var _data$includes2, _data$matches2;
122
- const headerKeys = (_data$includes2 = data.includes) === null || _data$includes2 === void 0 ? void 0 : _data$includes2.header;
123
- const headerMatches = (_data$matches2 = data.matches) === null || _data$matches2 === void 0 ? void 0 : _data$matches2.header;
152
+ var _a, _b;
153
+ const headerKeys = (_a = data.includes) == null ? void 0 : _a.header;
154
+ const headerMatches = (_b = data.matches) == null ? void 0 : _b.header;
124
155
  if (!headerKeys || headerKeys.length === 0) {
125
156
  return null;
126
157
  }
@@ -128,15 +159,15 @@ class CacheManager {
128
159
  const headerFactor = this.factor(headerKeys, requestHeader, headerMatches);
129
160
  return headerFactor;
130
161
  }
131
- async best(context, cacheKey, data) {
132
- const {
133
- level
134
- } = data;
135
- const cacheHash = this.find[(0, _util.fname)(level)](context, cacheKey, data);
136
- if (!cacheHash) {
137
- return null;
138
- }
139
- return data.caches.get(cacheHash);
162
+ best(context, cacheKey, data) {
163
+ return __async(this, null, function* () {
164
+ const { level } = data;
165
+ const cacheHash = this.find[(0, import_util.fname)(level)](context, cacheKey, data);
166
+ if (!cacheHash) {
167
+ return null;
168
+ }
169
+ return data.caches.get(cacheHash);
170
+ });
140
171
  }
141
172
  createCacheContent(config, caches) {
142
173
  return {
@@ -148,77 +179,77 @@ class CacheManager {
148
179
  caches
149
180
  };
150
181
  }
151
- async get(context) {
152
- const cacheKey = this.generateRequestKey(context);
153
- const data = this.cache.get(cacheKey);
154
-
155
- // no cache key matched
156
- if (!data) {
157
- return null;
158
- }
159
- const dest = await this.best(context, cacheKey, data);
160
- // no cache for current page with current config
161
- if (!dest) {
162
- return null;
163
- }
164
- const {
165
- expireTime,
166
- limitTime,
167
- html,
168
- cacheHash
169
- } = dest;
170
- const isStale = Date.now() - expireTime > 0;
171
- const isGarbage = limitTime ? Date.now() - limitTime > 0 : false;
172
- return {
173
- content: html || '',
174
- contentType: _utils.mime.contentType('html'),
175
- isStale,
176
- isGarbage,
177
- hash: cacheHash
178
- };
182
+ get(context) {
183
+ return __async(this, null, function* () {
184
+ const cacheKey = this.generateRequestKey(context);
185
+ const data = this.cache.get(cacheKey);
186
+ if (!data) {
187
+ return null;
188
+ }
189
+ const dest = yield this.best(context, cacheKey, data);
190
+ if (!dest) {
191
+ return null;
192
+ }
193
+ const { expireTime, limitTime, html, cacheHash } = dest;
194
+ const isStale = Date.now() - expireTime > 0;
195
+ const isGarbage = limitTime ? Date.now() - limitTime > 0 : false;
196
+ return {
197
+ content: html || "",
198
+ contentType: import_utils.mime.contentType("html"),
199
+ isStale,
200
+ isGarbage,
201
+ hash: cacheHash
202
+ };
203
+ });
179
204
  }
180
- async set(context, html, cacheConfig, sync = false) {
181
- if (!cacheConfig) {
182
- return false;
183
- }
184
-
185
- // each version with route is a separate cache
186
- const cacheKey = this.generateRequestKey(context);
187
- let data = this.cache.get(cacheKey);
188
- if (!data) {
189
- const caches = await (0, _pageCaches.createPageCaches)(MAX_CACHE_EACH_REQ);
190
- data = this.createCacheContent(cacheConfig, caches);
191
- }
192
- const cacheHash = this.find[(0, _util.fname)(cacheConfig.level)](context, cacheKey, data);
193
-
194
- // if cacheHash is null, maybe level not match meta key, do not cache
195
- if (!cacheHash) {
196
- return false;
197
- }
198
- const cacheSyncOrAsync = async () => {
199
- const next = data;
200
- const limit = cacheConfig.staleLimit;
201
- const storeHTML = (0, _util.cacheAddition)(html, cacheHash);
202
- const size = storeHTML.length;
203
- await next.caches.set(cacheHash, {
204
- expireTime: Date.now() + cacheConfig.interval * 1000,
205
- limitTime: typeof limit === 'number' ? Date.now() + limit * 1000 : null,
206
- cacheHash,
207
- html: storeHTML,
208
- size
205
+ set(context, html, cacheConfig, sync = false) {
206
+ return __async(this, null, function* () {
207
+ if (!cacheConfig) {
208
+ return false;
209
+ }
210
+ const cacheKey = this.generateRequestKey(context);
211
+ let data = this.cache.get(cacheKey);
212
+ if (!data) {
213
+ const caches = yield (0, import_page_caches.createPageCaches)(MAX_CACHE_EACH_REQ);
214
+ data = this.createCacheContent(cacheConfig, caches);
215
+ }
216
+ const cacheHash = this.find[(0, import_util.fname)(cacheConfig.level)](
217
+ context,
218
+ cacheKey,
219
+ data
220
+ );
221
+ if (!cacheHash) {
222
+ return false;
223
+ }
224
+ const cacheSyncOrAsync = () => __async(this, null, function* () {
225
+ const next = data;
226
+ const limit = cacheConfig.staleLimit;
227
+ const storeHTML = (0, import_util.cacheAddition)(html, cacheHash);
228
+ const size = storeHTML.length;
229
+ yield next.caches.set(cacheHash, {
230
+ expireTime: Date.now() + cacheConfig.interval * 1e3,
231
+ limitTime: typeof limit === "number" ? Date.now() + limit * 1e3 : null,
232
+ cacheHash,
233
+ html: storeHTML,
234
+ size
235
+ });
236
+ this.cache.set(cacheKey, next);
237
+ return true;
209
238
  });
210
- this.cache.set(cacheKey, next);
211
- return true;
212
- };
213
-
214
- // cache set is async, each hash is cached only once at the same time
215
- const doCache = (0, _util.withCoalescedInvoke)(cacheSyncOrAsync).bind(null, (0, _util.namespaceHash)('stream', cacheHash), []);
216
- return (0, _util.maybeSync)(doCache)(sync);
239
+ const doCache = (0, import_util.withCoalescedInvoke)(cacheSyncOrAsync).bind(
240
+ null,
241
+ (0, import_util.namespaceHash)("stream", cacheHash),
242
+ []
243
+ );
244
+ return (0, import_util.maybeSync)(doCache)(sync);
245
+ });
217
246
  }
218
- async del(context, cacheHash) {
219
- const cacheKey = this.generateRequestKey(context);
220
- const data = this.cache.get(cacheKey);
221
- data === null || data === void 0 ? void 0 : data.caches.del(cacheHash);
247
+ del(context, cacheHash) {
248
+ return __async(this, null, function* () {
249
+ const cacheKey = this.generateRequestKey(context);
250
+ const data = this.cache.get(cacheKey);
251
+ data == null ? void 0 : data.caches.del(cacheHash);
252
+ });
222
253
  }
223
254
  }
224
255
  let manager;
@@ -226,13 +257,9 @@ function createCache() {
226
257
  if (manager) {
227
258
  return manager;
228
259
  }
229
- manager = new CacheManager({
230
- max: 0
231
- });
260
+ manager = new CacheManager({ max: 0 });
232
261
  return manager;
233
262
  }
234
263
  function destroyCache() {
235
264
  manager = null;
236
265
  }
237
- /* eslint-enable no-lone-blocks */
238
- /* eslint-enable @typescript-eslint/member-ordering */
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,18 +1,59 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var stdin_exports = {};
25
+ __export(stdin_exports, {
26
+ cacheAddition: () => cacheAddition,
27
+ connectFactor: () => connectFactor,
28
+ fname: () => fname,
29
+ getTime: () => getTime,
30
+ maybeSync: () => maybeSync,
31
+ namespaceHash: () => namespaceHash,
32
+ valueFactory: () => valueFactory,
33
+ withCoalescedInvoke: () => withCoalescedInvoke
5
34
  });
6
- exports.cacheAddition = cacheAddition;
7
- exports.connectFactor = connectFactor;
8
- exports.fname = fname;
9
- exports.getTime = getTime;
10
- exports.maybeSync = maybeSync;
11
- exports.namespaceHash = namespaceHash;
12
- exports.valueFactory = valueFactory;
13
- exports.withCoalescedInvoke = withCoalescedInvoke;
14
- var _url = _interopRequireDefault(require("url"));
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
+ module.exports = __toCommonJS(stdin_exports);
36
+ var import_url = __toESM(require("url"));
37
+ var __async = (__this, __arguments, generator) => {
38
+ return new Promise((resolve, reject) => {
39
+ var fulfilled = (value) => {
40
+ try {
41
+ step(generator.next(value));
42
+ } catch (e) {
43
+ reject(e);
44
+ }
45
+ };
46
+ var rejected = (value) => {
47
+ try {
48
+ step(generator.throw(value));
49
+ } catch (e) {
50
+ reject(e);
51
+ }
52
+ };
53
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
54
+ step((generator = generator.apply(__this, __arguments)).next());
55
+ });
56
+ };
16
57
  function namespaceHash(namespace, hash) {
17
58
  return `${namespace}/${hash}`;
18
59
  }
@@ -20,18 +61,18 @@ function fname(lv) {
20
61
  return `f${lv}`;
21
62
  }
22
63
  function connectFactor(...args) {
23
- return args.join('-');
64
+ return args.join("-");
24
65
  }
25
66
  function valueFactory(obj) {
26
- if (obj instanceof _url.default.URLSearchParams) {
27
- return function (key) {
67
+ if (obj instanceof import_url.default.URLSearchParams) {
68
+ return function(key) {
28
69
  return obj.get(key);
29
70
  };
30
71
  } else {
31
- return function (key) {
72
+ return function(key) {
32
73
  const value = obj[key];
33
74
  if (Array.isArray(value)) {
34
- return value.join(',');
75
+ return value.join(",");
35
76
  }
36
77
  return value;
37
78
  };
@@ -42,38 +83,40 @@ function getTime([s, ns]) {
42
83
  }
43
84
  const RE_START_IN_HEAD = /<head>/;
44
85
  function cacheAddition(html, hash) {
45
- const additionHtml = html.replace(RE_START_IN_HEAD, `<head><meta name="x-moden-spr" content="${hash}">`);
86
+ const additionHtml = html.replace(
87
+ RE_START_IN_HEAD,
88
+ `<head><meta name="x-moden-spr" content="${hash}">`
89
+ );
46
90
  return additionHtml;
47
91
  }
48
- const globalInvokeCache = new Map();
92
+ const globalInvokeCache = /* @__PURE__ */ new Map();
49
93
  function withCoalescedInvoke(func) {
50
- return async function (key, args) {
51
- const entry = globalInvokeCache.get(key);
52
- if (entry) {
53
- return entry.then(res => ({
54
- isOrigin: false,
55
- value: res.value
56
- }));
57
- }
58
- function __wrapper() {
59
- return func(...args);
60
- }
61
- const future = __wrapper().then(res => {
62
- globalInvokeCache.delete(key);
63
- return {
64
- isOrigin: true,
65
- value: res
66
- };
67
- }).catch(err => {
68
- globalInvokeCache.delete(key);
69
- throw err;
94
+ return function(key, args) {
95
+ return __async(this, null, function* () {
96
+ const entry = globalInvokeCache.get(key);
97
+ if (entry) {
98
+ return entry.then((res) => ({
99
+ isOrigin: false,
100
+ value: res.value
101
+ }));
102
+ }
103
+ function __wrapper() {
104
+ return func(...args);
105
+ }
106
+ const future = __wrapper().then((res) => {
107
+ globalInvokeCache.delete(key);
108
+ return { isOrigin: true, value: res };
109
+ }).catch((err) => {
110
+ globalInvokeCache.delete(key);
111
+ throw err;
112
+ });
113
+ globalInvokeCache.set(key, future);
114
+ return future;
70
115
  });
71
- globalInvokeCache.set(key, future);
72
- return future;
73
116
  };
74
117
  }
75
118
  function maybeSync(fn) {
76
- return sync => {
119
+ return (sync) => {
77
120
  if (sync) {
78
121
  return fn();
79
122
  } else {
@@ -81,4 +124,4 @@ function maybeSync(fn) {
81
124
  return Promise.resolve();
82
125
  }
83
126
  };
84
- }
127
+ }