@modern-js/prod-server 2.6.1-alpha.0 → 2.8.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 (133) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +2 -2
  3. package/dist/cjs/libs/context/context.js +8 -9
  4. package/dist/cjs/libs/serveFile.js +3 -4
  5. package/dist/cjs/server/modernServer.js +25 -15
  6. package/dist/cjs/utils.js +4 -13
  7. package/dist/esm/libs/context/context.js +11 -12
  8. package/dist/esm/libs/serveFile.js +4 -5
  9. package/dist/esm/server/modernServer.js +50 -28
  10. package/dist/esm/utils.js +4 -8
  11. package/dist/esm-node/libs/context/context.js +8 -9
  12. package/dist/esm-node/libs/serveFile.js +3 -4
  13. package/dist/esm-node/server/modernServer.js +32 -16
  14. package/dist/esm-node/utils.js +4 -12
  15. package/dist/types/libs/context/context.d.ts +2 -4
  16. package/dist/types/libs/serveFile.d.ts +1 -2
  17. package/dist/types/server/modernServer.d.ts +1 -1
  18. package/dist/types/utils.d.ts +2 -3
  19. package/package.json +11 -11
  20. package/dist/js/modern/constants.js +0 -35
  21. package/dist/js/modern/index.js +0 -18
  22. package/dist/js/modern/libs/context/context.js +0 -160
  23. package/dist/js/modern/libs/context/index.js +0 -6
  24. package/dist/js/modern/libs/hook-api/index.js +0 -134
  25. package/dist/js/modern/libs/hook-api/route.js +0 -20
  26. package/dist/js/modern/libs/hook-api/template.js +0 -73
  27. package/dist/js/modern/libs/loadConfig.js +0 -62
  28. package/dist/js/modern/libs/logger.js +0 -111
  29. package/dist/js/modern/libs/metrics.js +0 -11
  30. package/dist/js/modern/libs/proxy.js +0 -92
  31. package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +0 -114
  32. package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +0 -254
  33. package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +0 -47
  34. package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +0 -37
  35. package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +0 -91
  36. package/dist/js/modern/libs/render/cache/index.js +0 -115
  37. package/dist/js/modern/libs/render/cache/page-caches/index.js +0 -32
  38. package/dist/js/modern/libs/render/cache/page-caches/lru.js +0 -29
  39. package/dist/js/modern/libs/render/cache/spr.js +0 -248
  40. package/dist/js/modern/libs/render/cache/type.js +0 -0
  41. package/dist/js/modern/libs/render/cache/util.js +0 -102
  42. package/dist/js/modern/libs/render/index.js +0 -86
  43. package/dist/js/modern/libs/render/measure.js +0 -68
  44. package/dist/js/modern/libs/render/reader.js +0 -107
  45. package/dist/js/modern/libs/render/ssr.js +0 -100
  46. package/dist/js/modern/libs/render/static.js +0 -60
  47. package/dist/js/modern/libs/render/type.js +0 -9
  48. package/dist/js/modern/libs/route/index.js +0 -54
  49. package/dist/js/modern/libs/route/matcher.js +0 -87
  50. package/dist/js/modern/libs/route/route.js +0 -16
  51. package/dist/js/modern/libs/serve-file.js +0 -67
  52. package/dist/js/modern/server/index.js +0 -208
  53. package/dist/js/modern/server/modern-server-split.js +0 -74
  54. package/dist/js/modern/server/modern-server.js +0 -554
  55. package/dist/js/modern/type.js +0 -0
  56. package/dist/js/modern/utils.js +0 -136
  57. package/dist/js/modern/worker-server.js +0 -89
  58. package/dist/js/node/constants.js +0 -62
  59. package/dist/js/node/index.js +0 -44
  60. package/dist/js/node/libs/context/context.js +0 -189
  61. package/dist/js/node/libs/context/index.js +0 -30
  62. package/dist/js/node/libs/hook-api/index.js +0 -164
  63. package/dist/js/node/libs/hook-api/route.js +0 -43
  64. package/dist/js/node/libs/hook-api/template.js +0 -97
  65. package/dist/js/node/libs/loadConfig.js +0 -91
  66. package/dist/js/node/libs/logger.js +0 -133
  67. package/dist/js/node/libs/metrics.js +0 -34
  68. package/dist/js/node/libs/proxy.js +0 -114
  69. package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +0 -115
  70. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +0 -245
  71. package/dist/js/node/libs/render/cache/__tests__/cacheable.js +0 -70
  72. package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +0 -60
  73. package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +0 -114
  74. package/dist/js/node/libs/render/cache/index.js +0 -134
  75. package/dist/js/node/libs/render/cache/page-caches/index.js +0 -55
  76. package/dist/js/node/libs/render/cache/page-caches/lru.js +0 -58
  77. package/dist/js/node/libs/render/cache/spr.js +0 -270
  78. package/dist/js/node/libs/render/cache/type.js +0 -15
  79. package/dist/js/node/libs/render/cache/util.js +0 -138
  80. package/dist/js/node/libs/render/index.js +0 -115
  81. package/dist/js/node/libs/render/measure.js +0 -90
  82. package/dist/js/node/libs/render/reader.js +0 -140
  83. package/dist/js/node/libs/render/ssr.js +0 -123
  84. package/dist/js/node/libs/render/static.js +0 -89
  85. package/dist/js/node/libs/render/type.js +0 -32
  86. package/dist/js/node/libs/route/index.js +0 -78
  87. package/dist/js/node/libs/route/matcher.js +0 -106
  88. package/dist/js/node/libs/route/route.js +0 -39
  89. package/dist/js/node/libs/serve-file.js +0 -97
  90. package/dist/js/node/server/index.js +0 -219
  91. package/dist/js/node/server/modern-server-split.js +0 -97
  92. package/dist/js/node/server/modern-server.js +0 -559
  93. package/dist/js/node/type.js +0 -15
  94. package/dist/js/node/utils.js +0 -166
  95. package/dist/js/node/worker-server.js +0 -113
  96. package/dist/js/treeshaking/constants.js +0 -29
  97. package/dist/js/treeshaking/index.js +0 -13
  98. package/dist/js/treeshaking/libs/context/context.js +0 -274
  99. package/dist/js/treeshaking/libs/context/index.js +0 -5
  100. package/dist/js/treeshaking/libs/hook-api/index.js +0 -281
  101. package/dist/js/treeshaking/libs/hook-api/route.js +0 -68
  102. package/dist/js/treeshaking/libs/hook-api/template.js +0 -127
  103. package/dist/js/treeshaking/libs/loadConfig.js +0 -82
  104. package/dist/js/treeshaking/libs/logger.js +0 -205
  105. package/dist/js/treeshaking/libs/metrics.js +0 -6
  106. package/dist/js/treeshaking/libs/proxy.js +0 -244
  107. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +0 -291
  108. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +0 -781
  109. package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +0 -67
  110. package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +0 -45
  111. package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +0 -147
  112. package/dist/js/treeshaking/libs/render/cache/index.js +0 -346
  113. package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +0 -154
  114. package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +0 -84
  115. package/dist/js/treeshaking/libs/render/cache/spr.js +0 -492
  116. package/dist/js/treeshaking/libs/render/cache/type.js +0 -1
  117. package/dist/js/treeshaking/libs/render/cache/util.js +0 -280
  118. package/dist/js/treeshaking/libs/render/index.js +0 -234
  119. package/dist/js/treeshaking/libs/render/measure.js +0 -146
  120. package/dist/js/treeshaking/libs/render/reader.js +0 -339
  121. package/dist/js/treeshaking/libs/render/ssr.js +0 -223
  122. package/dist/js/treeshaking/libs/render/static.js +0 -216
  123. package/dist/js/treeshaking/libs/render/type.js +0 -7
  124. package/dist/js/treeshaking/libs/route/index.js +0 -130
  125. package/dist/js/treeshaking/libs/route/matcher.js +0 -143
  126. package/dist/js/treeshaking/libs/route/route.js +0 -40
  127. package/dist/js/treeshaking/libs/serve-file.js +0 -184
  128. package/dist/js/treeshaking/server/index.js +0 -505
  129. package/dist/js/treeshaking/server/modern-server-split.js +0 -360
  130. package/dist/js/treeshaking/server/modern-server.js +0 -1089
  131. package/dist/js/treeshaking/type.js +0 -1
  132. package/dist/js/treeshaking/utils.js +0 -147
  133. package/dist/js/treeshaking/worker-server.js +0 -233
@@ -1,111 +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
- const LOG_LEVEL = {
18
- error: 0,
19
- warn: 1,
20
- info: 2,
21
- debug: 3,
22
- log: 4
23
- };
24
- const LOG_TYPES = {
25
- error: {
26
- color: "red",
27
- label: "error",
28
- level: "error"
29
- },
30
- info: {
31
- color: "cyan",
32
- label: "info",
33
- level: "info"
34
- },
35
- success: {
36
- color: "green",
37
- label: "Success",
38
- level: "info"
39
- },
40
- warn: {
41
- color: "yellow",
42
- label: "warn",
43
- level: "warn"
44
- },
45
- debug: {
46
- color: "red",
47
- label: "debug",
48
- level: "debug"
49
- },
50
- log: { level: "log" }
51
- };
52
- const DEFAULT_CONFIG = {
53
- displayLabel: true,
54
- uppercaseLabel: false
55
- };
56
- class Logger {
57
- constructor(options = {}) {
58
- this.level = options.level || LOG_TYPES.log.level;
59
- this.config = __spreadValues(__spreadValues({}, DEFAULT_CONFIG), options.config || {});
60
- this.types = __spreadValues(__spreadValues({}, LOG_TYPES), options.types || {});
61
- this.longestLabel = this.getLongestLabel();
62
- Object.keys(this.types).forEach((type) => {
63
- this[type] = this._log.bind(this, type);
64
- });
65
- }
66
- _log(type, message, ...args) {
67
- if (message === void 0 || message === null) {
68
- console.log();
69
- return;
70
- }
71
- if (LOG_LEVEL[type] > LOG_LEVEL[this.level]) {
72
- return;
73
- }
74
- let label = "";
75
- let text = "";
76
- const logType = this.types[type];
77
- if (this.config.displayLabel && logType.label) {
78
- label = this.config.uppercaseLabel ? logType.label.toUpperCase() : logType.label;
79
- label = label.padEnd(this.longestLabel.length);
80
- }
81
- if (message instanceof Error) {
82
- if (message.stack) {
83
- const [name, ...rest] = message.stack.split("\n");
84
- text = `${name}
85
- ${rest.join("\n")}`;
86
- } else {
87
- text = message.message;
88
- }
89
- } else {
90
- text = `${message}`;
91
- }
92
- const log = label.length > 0 ? `${label} ${text}` : text;
93
- console.log(log, ...args);
94
- }
95
- getLongestLabel() {
96
- let longestLabel = "";
97
- Object.keys(this.types).forEach((type) => {
98
- const { label = "" } = this.types[type];
99
- if (label.length > longestLabel.length) {
100
- longestLabel = label;
101
- }
102
- });
103
- return longestLabel;
104
- }
105
- }
106
- const logger = new Logger();
107
- logger.Logger = Logger;
108
- export {
109
- Logger,
110
- logger
111
- };
@@ -1,11 +0,0 @@
1
- const metrics = {
2
- gauges() {
3
- },
4
- emitCounter() {
5
- },
6
- emitTimer() {
7
- }
8
- };
9
- export {
10
- metrics
11
- };
@@ -1,92 +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 { createProxyMiddleware } from "http-proxy-middleware";
38
- import { debug } from "../utils";
39
- function formatProxyOptions(proxyOptions) {
40
- const formattedProxy = [];
41
- if (!Array.isArray(proxyOptions)) {
42
- if ("target" in proxyOptions) {
43
- formattedProxy.push(proxyOptions);
44
- } else {
45
- Array.prototype.push.apply(
46
- formattedProxy,
47
- Object.keys(proxyOptions).reduce(
48
- (total, source) => {
49
- const option = proxyOptions[source];
50
- total.push(__spreadValues({
51
- context: source,
52
- changeOrigin: true,
53
- logLevel: "warn"
54
- }, typeof option === "string" ? { target: option } : option));
55
- return total;
56
- },
57
- []
58
- )
59
- );
60
- }
61
- } else {
62
- formattedProxy.push(...proxyOptions);
63
- }
64
- return formattedProxy;
65
- }
66
- const createProxyHandler = (proxyOptions) => {
67
- debug("createProxyHandler", proxyOptions);
68
- if (!proxyOptions) {
69
- return null;
70
- }
71
- const formattedProxy = formatProxyOptions(proxyOptions);
72
- const middlewares = formattedProxy.map((option) => {
73
- const middleware = createProxyMiddleware(option.context, option);
74
- return (ctx, next) => __async(void 0, null, function* () {
75
- const { req, res } = ctx;
76
- const bypassUrl = typeof option.bypass === "function" ? option.bypass(req, res, option) : null;
77
- if (typeof bypassUrl === "boolean") {
78
- ctx.status = 404;
79
- return next();
80
- } else if (typeof bypassUrl === "string") {
81
- ctx.url = bypassUrl;
82
- return next();
83
- }
84
- middleware(req, res, next);
85
- });
86
- });
87
- return middlewares;
88
- };
89
- export {
90
- createProxyHandler,
91
- formatProxyOptions
92
- };
@@ -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
- };