@modern-js/prod-server 2.6.1-alpha.0 → 2.7.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.
Files changed (129) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/cjs/libs/serveFile.js +3 -4
  3. package/dist/cjs/server/modernServer.js +18 -15
  4. package/dist/cjs/utils.js +4 -13
  5. package/dist/esm/libs/serveFile.js +4 -5
  6. package/dist/esm/server/modernServer.js +14 -10
  7. package/dist/esm/utils.js +4 -8
  8. package/dist/esm-node/libs/serveFile.js +3 -4
  9. package/dist/esm-node/server/modernServer.js +18 -15
  10. package/dist/esm-node/utils.js +4 -12
  11. package/dist/types/libs/context/context.d.ts +1 -1
  12. package/dist/types/libs/serveFile.d.ts +1 -2
  13. package/dist/types/server/modernServer.d.ts +1 -1
  14. package/dist/types/utils.d.ts +2 -3
  15. package/package.json +9 -9
  16. package/dist/js/modern/constants.js +0 -35
  17. package/dist/js/modern/index.js +0 -18
  18. package/dist/js/modern/libs/context/context.js +0 -160
  19. package/dist/js/modern/libs/context/index.js +0 -6
  20. package/dist/js/modern/libs/hook-api/index.js +0 -134
  21. package/dist/js/modern/libs/hook-api/route.js +0 -20
  22. package/dist/js/modern/libs/hook-api/template.js +0 -73
  23. package/dist/js/modern/libs/loadConfig.js +0 -62
  24. package/dist/js/modern/libs/logger.js +0 -111
  25. package/dist/js/modern/libs/metrics.js +0 -11
  26. package/dist/js/modern/libs/proxy.js +0 -92
  27. package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +0 -114
  28. package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +0 -254
  29. package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +0 -47
  30. package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +0 -37
  31. package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +0 -91
  32. package/dist/js/modern/libs/render/cache/index.js +0 -115
  33. package/dist/js/modern/libs/render/cache/page-caches/index.js +0 -32
  34. package/dist/js/modern/libs/render/cache/page-caches/lru.js +0 -29
  35. package/dist/js/modern/libs/render/cache/spr.js +0 -248
  36. package/dist/js/modern/libs/render/cache/type.js +0 -0
  37. package/dist/js/modern/libs/render/cache/util.js +0 -102
  38. package/dist/js/modern/libs/render/index.js +0 -86
  39. package/dist/js/modern/libs/render/measure.js +0 -68
  40. package/dist/js/modern/libs/render/reader.js +0 -107
  41. package/dist/js/modern/libs/render/ssr.js +0 -100
  42. package/dist/js/modern/libs/render/static.js +0 -60
  43. package/dist/js/modern/libs/render/type.js +0 -9
  44. package/dist/js/modern/libs/route/index.js +0 -54
  45. package/dist/js/modern/libs/route/matcher.js +0 -87
  46. package/dist/js/modern/libs/route/route.js +0 -16
  47. package/dist/js/modern/libs/serve-file.js +0 -67
  48. package/dist/js/modern/server/index.js +0 -208
  49. package/dist/js/modern/server/modern-server-split.js +0 -74
  50. package/dist/js/modern/server/modern-server.js +0 -554
  51. package/dist/js/modern/type.js +0 -0
  52. package/dist/js/modern/utils.js +0 -136
  53. package/dist/js/modern/worker-server.js +0 -89
  54. package/dist/js/node/constants.js +0 -62
  55. package/dist/js/node/index.js +0 -44
  56. package/dist/js/node/libs/context/context.js +0 -189
  57. package/dist/js/node/libs/context/index.js +0 -30
  58. package/dist/js/node/libs/hook-api/index.js +0 -164
  59. package/dist/js/node/libs/hook-api/route.js +0 -43
  60. package/dist/js/node/libs/hook-api/template.js +0 -97
  61. package/dist/js/node/libs/loadConfig.js +0 -91
  62. package/dist/js/node/libs/logger.js +0 -133
  63. package/dist/js/node/libs/metrics.js +0 -34
  64. package/dist/js/node/libs/proxy.js +0 -114
  65. package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +0 -115
  66. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +0 -245
  67. package/dist/js/node/libs/render/cache/__tests__/cacheable.js +0 -70
  68. package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +0 -60
  69. package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +0 -114
  70. package/dist/js/node/libs/render/cache/index.js +0 -134
  71. package/dist/js/node/libs/render/cache/page-caches/index.js +0 -55
  72. package/dist/js/node/libs/render/cache/page-caches/lru.js +0 -58
  73. package/dist/js/node/libs/render/cache/spr.js +0 -270
  74. package/dist/js/node/libs/render/cache/type.js +0 -15
  75. package/dist/js/node/libs/render/cache/util.js +0 -138
  76. package/dist/js/node/libs/render/index.js +0 -115
  77. package/dist/js/node/libs/render/measure.js +0 -90
  78. package/dist/js/node/libs/render/reader.js +0 -140
  79. package/dist/js/node/libs/render/ssr.js +0 -123
  80. package/dist/js/node/libs/render/static.js +0 -89
  81. package/dist/js/node/libs/render/type.js +0 -32
  82. package/dist/js/node/libs/route/index.js +0 -78
  83. package/dist/js/node/libs/route/matcher.js +0 -106
  84. package/dist/js/node/libs/route/route.js +0 -39
  85. package/dist/js/node/libs/serve-file.js +0 -97
  86. package/dist/js/node/server/index.js +0 -219
  87. package/dist/js/node/server/modern-server-split.js +0 -97
  88. package/dist/js/node/server/modern-server.js +0 -559
  89. package/dist/js/node/type.js +0 -15
  90. package/dist/js/node/utils.js +0 -166
  91. package/dist/js/node/worker-server.js +0 -113
  92. package/dist/js/treeshaking/constants.js +0 -29
  93. package/dist/js/treeshaking/index.js +0 -13
  94. package/dist/js/treeshaking/libs/context/context.js +0 -274
  95. package/dist/js/treeshaking/libs/context/index.js +0 -5
  96. package/dist/js/treeshaking/libs/hook-api/index.js +0 -281
  97. package/dist/js/treeshaking/libs/hook-api/route.js +0 -68
  98. package/dist/js/treeshaking/libs/hook-api/template.js +0 -127
  99. package/dist/js/treeshaking/libs/loadConfig.js +0 -82
  100. package/dist/js/treeshaking/libs/logger.js +0 -205
  101. package/dist/js/treeshaking/libs/metrics.js +0 -6
  102. package/dist/js/treeshaking/libs/proxy.js +0 -244
  103. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +0 -291
  104. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +0 -781
  105. package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +0 -67
  106. package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +0 -45
  107. package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +0 -147
  108. package/dist/js/treeshaking/libs/render/cache/index.js +0 -346
  109. package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +0 -154
  110. package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +0 -84
  111. package/dist/js/treeshaking/libs/render/cache/spr.js +0 -492
  112. package/dist/js/treeshaking/libs/render/cache/type.js +0 -1
  113. package/dist/js/treeshaking/libs/render/cache/util.js +0 -280
  114. package/dist/js/treeshaking/libs/render/index.js +0 -234
  115. package/dist/js/treeshaking/libs/render/measure.js +0 -146
  116. package/dist/js/treeshaking/libs/render/reader.js +0 -339
  117. package/dist/js/treeshaking/libs/render/ssr.js +0 -223
  118. package/dist/js/treeshaking/libs/render/static.js +0 -216
  119. package/dist/js/treeshaking/libs/render/type.js +0 -7
  120. package/dist/js/treeshaking/libs/route/index.js +0 -130
  121. package/dist/js/treeshaking/libs/route/matcher.js +0 -143
  122. package/dist/js/treeshaking/libs/route/route.js +0 -40
  123. package/dist/js/treeshaking/libs/serve-file.js +0 -184
  124. package/dist/js/treeshaking/server/index.js +0 -505
  125. package/dist/js/treeshaking/server/modern-server-split.js +0 -360
  126. package/dist/js/treeshaking/server/modern-server.js +0 -1089
  127. package/dist/js/treeshaking/type.js +0 -1
  128. package/dist/js/treeshaking/utils.js +0 -147
  129. package/dist/js/treeshaking/worker-server.js +0 -233
@@ -1,114 +0,0 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __commonJS = (cb, mod) => function __require() {
3
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
- };
5
- var __async = (__this, __arguments, generator) => {
6
- return new Promise((resolve, reject) => {
7
- var fulfilled = (value) => {
8
- try {
9
- step(generator.next(value));
10
- } catch (e) {
11
- reject(e);
12
- }
13
- };
14
- var rejected = (value) => {
15
- try {
16
- step(generator.throw(value));
17
- } catch (e) {
18
- reject(e);
19
- }
20
- };
21
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
22
- step((generator = generator.apply(__this, __arguments)).next());
23
- });
24
- };
25
- import url from "url";
26
- import { createCache, destroyCache } from "../spr";
27
- import {
28
- cacheAddition,
29
- connectFactor,
30
- fname,
31
- maybeSync,
32
- namespaceHash,
33
- valueFactory,
34
- withCoalescedInvoke
35
- } from "../util";
36
- var require_cache_fun_test = __commonJS({
37
- "src/libs/render/cache/__tests__/cache.fun.test.ts"(exports) {
38
- describe("test spr util functions", () => {
39
- it("should return value correctly", () => {
40
- expect(connectFactor("bar", "foo")).toBe("bar-foo");
41
- expect(fname(1)).toBe("f1");
42
- expect(namespaceHash("modern", "!@#$%^&")).toBe("modern/!@#$%^&");
43
- });
44
- it("should create or destroy instance correctly", () => {
45
- const ins1 = createCache();
46
- const ins2 = createCache();
47
- expect(ins1 === ins2).toBe(true);
48
- destroyCache();
49
- const ins3 = createCache();
50
- expect(ins1 === ins3).toBe(false);
51
- expect(ins2 === ins3).toBe(false);
52
- });
53
- it("should return function correctly", () => {
54
- const urlParams = (() => new url.URLSearchParams())();
55
- urlParams.set("name", "modern");
56
- const getParam = valueFactory(urlParams);
57
- expect(getParam("name")).toBe("modern");
58
- const headers = { age: "12345" };
59
- const getHeader = valueFactory(headers);
60
- expect(getHeader("age")).toBe("12345");
61
- });
62
- it("should add target html content", () => {
63
- const contentNoHead = "<div>123</div>";
64
- const html = cacheAddition(contentNoHead, Math.random().toString());
65
- expect(html).toBe(contentNoHead);
66
- const contentWithHead = "<head></head><div>123</div>";
67
- const hash = Math.random().toString();
68
- const htmlWithHead = cacheAddition(contentWithHead, hash);
69
- expect(htmlWithHead).toBe(
70
- `<head><meta name="x-moden-spr" content="${hash}"></head><div>123</div>`
71
- );
72
- });
73
- it("should only invoke func one time", () => __async(exports, null, function* () {
74
- let index = 0;
75
- const fn = withCoalescedInvoke(
76
- () => __async(exports, null, function* () {
77
- return new Promise((resolve) => {
78
- setTimeout(() => {
79
- index += 1;
80
- resolve(index);
81
- }, 500);
82
- });
83
- })
84
- );
85
- const key = "test";
86
- const [res1, res2] = yield Promise.all([fn(key, []), fn(key, [])]);
87
- expect(res1.isOrigin && res2.isOrigin).toBe(false);
88
- expect(res1.isOrigin || res2.isOrigin).toBe(true);
89
- expect(res1.value).toBe(1);
90
- expect(res2.value).toBe(1);
91
- }));
92
- it("should invoke sync or async", () => __async(exports, null, function* () {
93
- const foo = "";
94
- const async = yield maybeSync(
95
- () => new Promise((resolve) => {
96
- setTimeout(() => {
97
- resolve(foo);
98
- }, 100);
99
- })
100
- )(false);
101
- expect(async).toBeUndefined();
102
- const sync = yield maybeSync(
103
- () => new Promise((resolve) => {
104
- setTimeout(() => {
105
- resolve(foo);
106
- }, 100);
107
- })
108
- )(true);
109
- expect(sync).toBe(foo);
110
- }));
111
- });
112
- }
113
- });
114
- export default require_cache_fun_test();
@@ -1,254 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __spreadValues = (a, b) => {
8
- for (var prop in b || (b = {}))
9
- if (__hasOwnProp.call(b, prop))
10
- __defNormalProp(a, prop, b[prop]);
11
- if (__getOwnPropSymbols)
12
- for (var prop of __getOwnPropSymbols(b)) {
13
- if (__propIsEnum.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- }
16
- return a;
17
- };
18
- var __commonJS = (cb, mod) => function __require() {
19
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
20
- };
21
- var __async = (__this, __arguments, generator) => {
22
- return new Promise((resolve, reject) => {
23
- var fulfilled = (value) => {
24
- try {
25
- step(generator.next(value));
26
- } catch (e) {
27
- reject(e);
28
- }
29
- };
30
- var rejected = (value) => {
31
- try {
32
- step(generator.throw(value));
33
- } catch (e) {
34
- reject(e);
35
- }
36
- };
37
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
38
- step((generator = generator.apply(__this, __arguments)).next());
39
- });
40
- };
41
- import { createCache, destroyCache } from "../spr";
42
- import { errorConfiguration } from "./error-configuration";
43
- import { cacheabelAry } from "./cacheable";
44
- import { matchedCacheableAry } from "./matched-cache";
45
- var require_cache_test = __commonJS({
46
- "src/libs/render/cache/__tests__/cache.test.ts"(exports) {
47
- const createCacheConfig = (config = {}) => __spreadValues({
48
- excludes: null,
49
- includes: null,
50
- interval: 10,
51
- staleLimit: false,
52
- level: 0,
53
- fallback: false,
54
- matches: null
55
- }, config);
56
- jest.setTimeout(6e4);
57
- describe("cache", () => {
58
- it("should cache correctly", () => __async(exports, null, function* () {
59
- destroyCache();
60
- const cache = createCache();
61
- const context = {
62
- entry: "",
63
- pathname: "",
64
- query: {},
65
- headers: {}
66
- };
67
- const content = "hello";
68
- const cacheConfig = createCacheConfig();
69
- yield cache.set(context, content, cacheConfig, true);
70
- const cacheResult = yield cache.get(context);
71
- expect(cacheResult).not.toBe(null);
72
- expect(cacheResult == null ? void 0 : cacheResult.content).toBe("hello");
73
- }));
74
- it("should ignore cache set when cache config not exist", () => __async(exports, null, function* () {
75
- destroyCache();
76
- destroyCache();
77
- const cache = createCache();
78
- const context = {
79
- entry: "",
80
- pathname: "",
81
- query: {},
82
- headers: {}
83
- };
84
- const content = "hello";
85
- const shouldCache = yield cache.set(context, content, null, true);
86
- expect(shouldCache).toBe(false);
87
- }));
88
- it("should calcual cache key error", () => __async(exports, null, function* () {
89
- destroyCache();
90
- const cache = createCache();
91
- const content = "hello";
92
- for (const config of errorConfiguration) {
93
- const cacheConfig = createCacheConfig(config);
94
- const tmpEntry = Math.random().toString();
95
- const context = {
96
- entry: tmpEntry,
97
- pathname: "",
98
- query: {},
99
- headers: {}
100
- };
101
- const shouldCache = yield cache.set(context, content, cacheConfig);
102
- expect(shouldCache).toBe(false);
103
- }
104
- }));
105
- it("should get nothing for diff requestKey", () => __async(exports, null, function* () {
106
- destroyCache();
107
- const cache = createCache();
108
- const context = {
109
- entry: "",
110
- pathname: "",
111
- query: {},
112
- headers: {}
113
- };
114
- const content = "hello";
115
- const cacheConfig = createCacheConfig({
116
- level: 1,
117
- includes: { query: ["name"] }
118
- });
119
- yield cache.set(context, content, cacheConfig, true);
120
- const context_req = {
121
- entry: "",
122
- pathname: "/home",
123
- query: {},
124
- headers: {}
125
- };
126
- const cacheResult = yield cache.get(context_req);
127
- expect(cacheResult).toBe(null);
128
- }));
129
- it("should get nothing for diff cacheHash", () => __async(exports, null, function* () {
130
- destroyCache();
131
- const cache = createCache();
132
- const context = {
133
- entry: "",
134
- pathname: "",
135
- query: {},
136
- headers: {}
137
- };
138
- const content = "hello";
139
- const cacheConfig = createCacheConfig({
140
- level: 1,
141
- includes: { query: ["name"] }
142
- });
143
- yield cache.set(context, content, cacheConfig, true);
144
- const context_req = {
145
- entry: "",
146
- pathname: "",
147
- query: { name: "zll" },
148
- headers: {}
149
- };
150
- const cacheResult = yield cache.get(context_req);
151
- expect(cacheResult).toBe(null);
152
- }));
153
- it("should get cache correctly", () => __async(exports, null, function* () {
154
- destroyCache();
155
- const cache = createCache();
156
- for (const cacheable of cacheabelAry) {
157
- const context = {
158
- entry: "",
159
- pathname: cacheable.requestOpt.url,
160
- query: cacheable.requestOpt.query || {},
161
- headers: cacheable.requestOpt.headers || {}
162
- };
163
- const cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
164
- yield cache.set(context, cacheable.content, cacheConfig, true);
165
- const cacheResult = yield cache.get(context);
166
- expect(cacheResult == null ? void 0 : cacheResult.content).toBe(cacheable.content);
167
- }
168
- }));
169
- it("should match cache correctly", () => __async(exports, null, function* () {
170
- destroyCache();
171
- const cache = createCache();
172
- for (const cacheable of matchedCacheableAry) {
173
- const [baseCacheable, matchOne, ...other] = cacheable;
174
- const { requestOpt = {}, cacheConfig, content } = baseCacheable;
175
- const context = {
176
- entry: "",
177
- pathname: requestOpt.url,
178
- query: requestOpt.query,
179
- headers: requestOpt.headers
180
- };
181
- yield cache.set(context, content, createCacheConfig(cacheConfig), true);
182
- const matchContext = {
183
- entry: "",
184
- pathname: matchOne.url,
185
- query: matchOne.query,
186
- headers: matchOne.headers
187
- };
188
- const cacheResult = yield cache.get(matchContext);
189
- expect(cacheResult == null ? void 0 : cacheResult.content).toBe(content);
190
- for (const notMatch of other) {
191
- const notMatchContext = {
192
- entry: "",
193
- pathname: notMatch.url,
194
- query: notMatch.query,
195
- headers: notMatch.headers
196
- };
197
- const nothing = yield cache.get(notMatchContext);
198
- expect(nothing).toBe(null);
199
- }
200
- }
201
- }));
202
- it("should stale cache correctly", () => __async(exports, null, function* () {
203
- destroyCache();
204
- const cache = createCache();
205
- const context = {
206
- entry: "",
207
- pathname: "",
208
- query: {},
209
- headers: {}
210
- };
211
- const config = createCacheConfig({ interval: 5 });
212
- const content = "hello";
213
- const shouldCache = yield cache.set(context, content, config, true);
214
- expect(shouldCache.value).toBe(true);
215
- const freshResult = yield cache.get(context);
216
- expect(freshResult == null ? void 0 : freshResult.isStale).toBe(false);
217
- yield new Promise((resolve) => {
218
- setTimeout(() => {
219
- resolve();
220
- }, 6e3);
221
- });
222
- const staleResult = yield cache.get(context);
223
- expect(staleResult == null ? void 0 : staleResult.isStale).toBe(true);
224
- }));
225
- it("should garbage cache correctly", () => __async(exports, null, function* () {
226
- destroyCache();
227
- const cache = createCache();
228
- const context = {
229
- entry: "",
230
- pathname: "",
231
- query: {},
232
- headers: {}
233
- };
234
- const config = createCacheConfig({
235
- interval: 3,
236
- staleLimit: 8
237
- });
238
- const content = "hello";
239
- const shouldCache = yield cache.set(context, content, config, true);
240
- expect(shouldCache.value).toBe(true);
241
- const freshResult = yield cache.get(context);
242
- expect(freshResult == null ? void 0 : freshResult.isGarbage).toBe(false);
243
- yield new Promise((resolve) => {
244
- setTimeout(() => {
245
- resolve();
246
- }, 1e4);
247
- });
248
- const staleResult = yield cache.get(context);
249
- expect(staleResult == null ? void 0 : staleResult.isGarbage).toBe(true);
250
- }));
251
- });
252
- }
253
- });
254
- export default require_cache_test();
@@ -1,47 +0,0 @@
1
- const cacheabelAry = [
2
- {
3
- requestOpt: { url: "/" },
4
- cacheConfig: {},
5
- content: "level0"
6
- },
7
- {
8
- requestOpt: {
9
- url: "/level-one",
10
- query: { name: "modern" }
11
- },
12
- cacheConfig: {
13
- level: 1,
14
- includes: { query: ["name"] }
15
- },
16
- content: "level1"
17
- },
18
- {
19
- requestOpt: {
20
- url: "/level-two",
21
- headers: { age: "18" }
22
- },
23
- cacheConfig: {
24
- level: 2,
25
- includes: { header: ["age"] }
26
- },
27
- content: "level2"
28
- },
29
- {
30
- requestOpt: {
31
- url: "/level-three",
32
- query: { name: "modern" },
33
- headers: { age: "18" }
34
- },
35
- cacheConfig: {
36
- level: 3,
37
- includes: {
38
- query: ["name"],
39
- header: ["age"]
40
- }
41
- },
42
- content: "level3"
43
- }
44
- ];
45
- export {
46
- cacheabelAry
47
- };
@@ -1,37 +0,0 @@
1
- const errorConfiguration = [
2
- { level: 1 },
3
- {
4
- level: 1,
5
- includes: {}
6
- },
7
- {
8
- level: 1,
9
- includes: { query: [] }
10
- },
11
- {
12
- level: 2,
13
- includes: {}
14
- },
15
- {
16
- level: 2,
17
- includes: { header: [] }
18
- },
19
- {
20
- level: 3,
21
- includes: { header: [] }
22
- },
23
- {
24
- level: 3,
25
- includes: { query: [] }
26
- },
27
- {
28
- level: 3,
29
- includes: {
30
- query: [],
31
- header: []
32
- }
33
- }
34
- ];
35
- export {
36
- errorConfiguration
37
- };
@@ -1,91 +0,0 @@
1
- const matchedCacheableAry = [
2
- [
3
- {
4
- requestOpt: {
5
- url: "/level-one",
6
- headers: {},
7
- query: { name: "byted" }
8
- },
9
- cacheConfig: {
10
- level: 1,
11
- includes: { query: ["name"] },
12
- matches: { query: { name: { weixin: "^byted" } } }
13
- },
14
- content: "level1"
15
- },
16
- {
17
- url: "/level-one",
18
- headers: {},
19
- query: { name: "byted_likely" }
20
- },
21
- {
22
- url: "/level-one",
23
- headers: {},
24
- query: { name: "not_byted" }
25
- }
26
- ],
27
- [
28
- {
29
- requestOpt: {
30
- url: "/level-two",
31
- query: {},
32
- headers: { age: "17" }
33
- },
34
- cacheConfig: {
35
- level: 2,
36
- includes: { header: ["age"] },
37
- matches: { header: { age: { one: "^1" } } }
38
- },
39
- content: "level2"
40
- },
41
- {
42
- url: "/level-two",
43
- query: {},
44
- headers: { age: "11" }
45
- },
46
- {
47
- url: "/level-two",
48
- query: {},
49
- headers: { age: "22" }
50
- }
51
- ],
52
- [
53
- {
54
- requestOpt: {
55
- url: "/level-three",
56
- headers: { age: "17" },
57
- query: { name: "byted" }
58
- },
59
- cacheConfig: {
60
- level: 3,
61
- includes: {
62
- query: ["name"],
63
- header: ["age"]
64
- },
65
- matches: {
66
- query: { name: { weixin: "^byted" } },
67
- header: { age: { one: "^1" } }
68
- }
69
- },
70
- content: "level3"
71
- },
72
- {
73
- url: "/level-three",
74
- query: { name: "byted_likely" },
75
- headers: { age: "19" }
76
- },
77
- {
78
- url: "/level-three",
79
- query: { name: "byted_likely" },
80
- headers: {}
81
- },
82
- {
83
- url: "/level-three",
84
- query: { name: "not_byted" },
85
- headers: { age: "19" }
86
- }
87
- ]
88
- ];
89
- export {
90
- matchedCacheableAry
91
- };
@@ -1,115 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
- var __async = (__this, __arguments, generator) => {
18
- return new Promise((resolve, reject) => {
19
- var fulfilled = (value) => {
20
- try {
21
- step(generator.next(value));
22
- } catch (e) {
23
- reject(e);
24
- }
25
- };
26
- var rejected = (value) => {
27
- try {
28
- step(generator.throw(value));
29
- } catch (e) {
30
- reject(e);
31
- }
32
- };
33
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
34
- step((generator = generator.apply(__this, __arguments)).next());
35
- });
36
- };
37
- import { Transform } from "stream";
38
- import { ERROR_DIGEST } from "../../../constants";
39
- import { createCache } from "./spr";
40
- import { namespaceHash, withCoalescedInvoke } from "./util";
41
- var cache_default = (renderFn, ctx) => {
42
- const sprCache = createCache();
43
- const doRender = (context) => __async(void 0, null, function* () {
44
- const cacheContext = __spreadValues({
45
- entry: context.entryName
46
- }, context.request);
47
- const cacheFile = yield sprCache.get(cacheContext);
48
- function afterRender(source, onAfterRender) {
49
- return __async(this, null, function* () {
50
- if (!source) {
51
- return "";
52
- }
53
- if (typeof source === "string") {
54
- yield onAfterRender(source);
55
- return source;
56
- } else {
57
- let htmlForStream = "";
58
- const cacheStream = new Transform({
59
- write(chunk, _, callback) {
60
- htmlForStream += chunk.toString();
61
- this.push(chunk);
62
- callback();
63
- }
64
- });
65
- cacheStream.on("close", () => onAfterRender(htmlForStream));
66
- return source(cacheStream);
67
- }
68
- });
69
- }
70
- function saveHtmlIntoCache(html) {
71
- return __async(this, null, function* () {
72
- const { cacheConfig } = context;
73
- if (html && cacheConfig) {
74
- yield sprCache.set(cacheContext, html, cacheConfig);
75
- }
76
- });
77
- }
78
- if (!cacheFile) {
79
- const renderResult = yield renderFn(context);
80
- return afterRender(renderResult, saveHtmlIntoCache);
81
- }
82
- const cacheHash = cacheFile == null ? void 0 : cacheFile.hash;
83
- if (cacheFile.isGarbage) {
84
- const renderResult = yield renderFn(context);
85
- return afterRender(renderResult, saveHtmlIntoCache);
86
- } else if (cacheFile.isStale) {
87
- const render = withCoalescedInvoke(() => renderFn(context)).bind(
88
- null,
89
- namespaceHash("render", cacheFile.hash),
90
- []
91
- );
92
- render().then((res) => __async(void 0, null, function* () {
93
- if (res.value && res.isOrigin) {
94
- const { cacheConfig } = context;
95
- if (cacheConfig) {
96
- afterRender(res.value, (html) => __async(void 0, null, function* () {
97
- sprCache.set(cacheContext, html, cacheConfig);
98
- }));
99
- } else {
100
- sprCache.del(cacheContext, cacheHash);
101
- }
102
- }
103
- })).catch((e) => {
104
- sprCache.del(cacheContext, cacheHash);
105
- ctx.error(ERROR_DIGEST.ERENDER, e);
106
- });
107
- }
108
- ctx.res.setHeader("x-modern-spr", "1");
109
- return cacheFile.content;
110
- });
111
- return doRender;
112
- };
113
- export {
114
- cache_default as default
115
- };
@@ -1,32 +0,0 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- import { LRUCaches } from "./lru";
22
- function createPageCaches(max) {
23
- return __async(this, null, function* () {
24
- const constructorOptions = { max };
25
- const cacheInstance = new LRUCaches(constructorOptions);
26
- yield cacheInstance.init();
27
- return cacheInstance;
28
- });
29
- }
30
- export {
31
- createPageCaches
32
- };