@modern-js/prod-server 1.21.6 → 2.0.0-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.
- package/CHANGELOG.md +274 -13
- package/dist/js/modern/constants.js +32 -27
- package/dist/js/modern/index.js +11 -7
- package/dist/js/modern/libs/context/context.js +54 -132
- package/dist/js/modern/libs/context/index.js +5 -2
- package/dist/js/modern/libs/hook-api/index.js +134 -0
- package/dist/js/modern/libs/hook-api/route.js +13 -37
- package/dist/js/modern/libs/hook-api/template.js +41 -32
- package/dist/js/modern/libs/loadConfig.js +46 -32
- package/dist/js/modern/libs/metrics.js +6 -7
- package/dist/js/modern/libs/proxy.js +70 -44
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +112 -68
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +246 -225
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +43 -49
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +36 -34
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +83 -113
- package/dist/js/modern/libs/render/cache/index.js +93 -50
- package/dist/js/modern/libs/render/cache/page-caches/index.js +31 -8
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +6 -16
- package/dist/js/modern/libs/render/cache/spr.js +133 -167
- package/dist/js/modern/libs/render/cache/type.js +0 -1
- package/dist/js/modern/libs/render/cache/util.js +71 -45
- package/dist/js/modern/libs/render/index.js +76 -61
- package/dist/js/modern/libs/render/measure.js +42 -34
- package/dist/js/modern/libs/render/reader.js +68 -76
- package/dist/js/modern/libs/render/ssr.js +63 -33
- package/dist/js/modern/libs/render/static.js +51 -37
- package/dist/js/modern/libs/render/type.js +9 -7
- package/dist/js/modern/libs/route/index.js +12 -30
- package/dist/js/modern/libs/route/matcher.js +28 -50
- package/dist/js/modern/libs/route/route.js +9 -31
- package/dist/js/modern/libs/serve-file.js +40 -20
- package/dist/js/modern/server/index.js +152 -168
- package/dist/js/modern/server/modern-server-split.js +44 -60
- package/dist/js/modern/server/modern-server.js +416 -526
- package/dist/js/modern/type.js +0 -1
- package/dist/js/modern/utils.js +62 -58
- package/dist/js/modern/worker-server.js +54 -0
- package/dist/js/node/constants.js +53 -32
- package/dist/js/node/index.js +37 -67
- package/dist/js/node/libs/context/context.js +84 -150
- package/dist/js/node/libs/context/index.js +28 -16
- package/dist/js/node/libs/hook-api/index.js +164 -0
- package/dist/js/node/libs/hook-api/route.js +35 -45
- package/dist/js/node/libs/hook-api/template.js +64 -40
- package/dist/js/node/libs/loadConfig.js +74 -55
- package/dist/js/node/libs/metrics.js +28 -12
- package/dist/js/node/libs/proxy.js +90 -55
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +99 -61
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +147 -140
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +65 -55
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +58 -40
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +105 -119
- package/dist/js/node/libs/render/cache/index.js +115 -65
- package/dist/js/node/libs/render/cache/page-caches/index.js +54 -16
- package/dist/js/node/libs/render/cache/page-caches/lru.js +33 -26
- package/dist/js/node/libs/render/cache/spr.js +161 -188
- package/dist/js/node/libs/render/cache/type.js +15 -5
- package/dist/js/node/libs/render/cache/util.js +99 -63
- package/dist/js/node/libs/render/index.js +106 -87
- package/dist/js/node/libs/render/measure.js +61 -44
- package/dist/js/node/libs/render/reader.js +98 -100
- package/dist/js/node/libs/render/ssr.js +92 -58
- package/dist/js/node/libs/render/static.js +80 -53
- package/dist/js/node/libs/render/type.js +31 -13
- package/dist/js/node/libs/route/index.js +35 -44
- package/dist/js/node/libs/route/matcher.js +48 -65
- package/dist/js/node/libs/route/route.js +29 -37
- package/dist/js/node/libs/serve-file.js +74 -37
- package/dist/js/node/server/index.js +170 -203
- package/dist/js/node/server/modern-server-split.js +70 -73
- package/dist/js/node/server/modern-server.js +432 -577
- package/dist/js/node/type.js +15 -3
- package/dist/js/node/utils.js +87 -93
- package/dist/js/node/worker-server.js +77 -0
- package/dist/js/treeshaking/constants.js +29 -0
- package/dist/js/treeshaking/index.js +13 -0
- package/dist/js/treeshaking/libs/context/context.js +274 -0
- package/dist/js/treeshaking/libs/context/index.js +5 -0
- package/dist/js/treeshaking/libs/hook-api/index.js +281 -0
- package/dist/js/treeshaking/libs/hook-api/route.js +68 -0
- package/dist/js/treeshaking/libs/hook-api/template.js +127 -0
- package/dist/js/treeshaking/libs/loadConfig.js +82 -0
- package/dist/js/treeshaking/libs/metrics.js +6 -0
- package/dist/js/treeshaking/libs/proxy.js +244 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +291 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +781 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +67 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +147 -0
- package/dist/js/treeshaking/libs/render/cache/index.js +346 -0
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +154 -0
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +84 -0
- package/dist/js/treeshaking/libs/render/cache/spr.js +492 -0
- package/dist/js/treeshaking/libs/render/cache/type.js +1 -0
- package/dist/js/treeshaking/libs/render/cache/util.js +280 -0
- package/dist/js/treeshaking/libs/render/index.js +233 -0
- package/dist/js/treeshaking/libs/render/measure.js +146 -0
- package/dist/js/treeshaking/libs/render/reader.js +339 -0
- package/dist/js/treeshaking/libs/render/ssr.js +223 -0
- package/dist/js/treeshaking/libs/render/static.js +216 -0
- package/dist/js/treeshaking/libs/render/type.js +7 -0
- package/dist/js/treeshaking/libs/route/index.js +130 -0
- package/dist/js/treeshaking/libs/route/matcher.js +138 -0
- package/dist/js/treeshaking/libs/route/route.js +40 -0
- package/dist/js/treeshaking/libs/serve-file.js +184 -0
- package/dist/js/treeshaking/server/index.js +505 -0
- package/dist/js/treeshaking/server/modern-server-split.js +360 -0
- package/dist/js/treeshaking/server/modern-server.js +1083 -0
- package/dist/js/treeshaking/type.js +1 -0
- package/dist/js/treeshaking/utils.js +147 -0
- package/dist/js/treeshaking/worker-server.js +177 -0
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/libs/hook-api/index.d.ts +5 -0
- package/dist/types/libs/hook-api/route.d.ts +9 -14
- package/dist/types/libs/hook-api/template.d.ts +19 -9
- package/dist/types/libs/render/cache/index.d.ts +4 -2
- package/dist/types/libs/render/type.d.ts +3 -1
- package/dist/types/libs/route/route.d.ts +0 -1
- package/dist/types/libs/serve-file.d.ts +2 -1
- package/dist/types/server/index.d.ts +2 -0
- package/dist/types/server/modern-server.d.ts +11 -11
- package/dist/types/type.d.ts +8 -10
- package/dist/types/utils.d.ts +3 -4
- package/dist/types/worker-server.d.ts +15 -0
- package/package.json +31 -45
- package/dist/js/modern/libs/render/modern/browser-list.js +0 -7
- package/dist/js/modern/libs/render/modern/index.js +0 -48
- package/dist/js/node/libs/render/modern/browser-list.js +0 -14
- package/dist/js/node/libs/render/modern/index.js +0 -64
- package/dist/types/libs/render/modern/browser-list.d.ts +0 -1
- package/dist/types/libs/render/modern/index.d.ts +0 -3
|
@@ -1,77 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
17
|
+
mod
|
|
18
|
+
));
|
|
19
|
+
var __async = (__this, __arguments, generator) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var fulfilled = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
step(generator.next(value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rejected = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.throw(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var import_url = __toESM(require("url"));
|
|
40
|
+
var import_spr = require("../spr");
|
|
41
|
+
var import_util = require("../util");
|
|
42
|
+
describe("test spr util functions", () => {
|
|
43
|
+
it("should return value correctly", () => {
|
|
44
|
+
expect((0, import_util.connectFactor)("bar", "foo")).toBe("bar-foo");
|
|
45
|
+
expect((0, import_util.fname)(1)).toBe("f1");
|
|
46
|
+
expect((0, import_util.namespaceHash)("modern", "!@#$%^&")).toBe("modern/!@#$%^&");
|
|
16
47
|
});
|
|
17
|
-
it(
|
|
18
|
-
const ins1 = (0,
|
|
19
|
-
const ins2 = (0,
|
|
48
|
+
it("should create or destroy instance correctly", () => {
|
|
49
|
+
const ins1 = (0, import_spr.createCache)();
|
|
50
|
+
const ins2 = (0, import_spr.createCache)();
|
|
20
51
|
expect(ins1 === ins2).toBe(true);
|
|
21
|
-
(0,
|
|
22
|
-
const ins3 = (0,
|
|
52
|
+
(0, import_spr.destroyCache)();
|
|
53
|
+
const ins3 = (0, import_spr.createCache)();
|
|
23
54
|
expect(ins1 === ins3).toBe(false);
|
|
24
55
|
expect(ins2 === ins3).toBe(false);
|
|
25
56
|
});
|
|
26
|
-
it(
|
|
27
|
-
const urlParams = (() => new
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
const getHeader = (0, _util.valueFactory)(headers);
|
|
36
|
-
expect(getHeader('age')).toBe('12345');
|
|
57
|
+
it("should return function correctly", () => {
|
|
58
|
+
const urlParams = (() => new import_url.default.URLSearchParams())();
|
|
59
|
+
urlParams.set("name", "modern");
|
|
60
|
+
const getParam = (0, import_util.valueFactory)(urlParams);
|
|
61
|
+
expect(getParam("name")).toBe("modern");
|
|
62
|
+
const headers = { age: "12345" };
|
|
63
|
+
const getHeader = (0, import_util.valueFactory)(headers);
|
|
64
|
+
expect(getHeader("age")).toBe("12345");
|
|
37
65
|
});
|
|
38
|
-
it(
|
|
39
|
-
const contentNoHead =
|
|
40
|
-
const html = (0,
|
|
66
|
+
it("should add target html content", () => {
|
|
67
|
+
const contentNoHead = "<div>123</div>";
|
|
68
|
+
const html = (0, import_util.cacheAddition)(contentNoHead, Math.random().toString());
|
|
41
69
|
expect(html).toBe(contentNoHead);
|
|
42
|
-
const contentWithHead =
|
|
70
|
+
const contentWithHead = "<head></head><div>123</div>";
|
|
43
71
|
const hash = Math.random().toString();
|
|
44
|
-
const htmlWithHead = (0,
|
|
45
|
-
expect(htmlWithHead).toBe(
|
|
72
|
+
const htmlWithHead = (0, import_util.cacheAddition)(contentWithHead, hash);
|
|
73
|
+
expect(htmlWithHead).toBe(
|
|
74
|
+
`<head><meta name="x-moden-spr" content="${hash}"></head><div>123</div>`
|
|
75
|
+
);
|
|
46
76
|
});
|
|
47
|
-
it(
|
|
77
|
+
it("should only invoke func one time", () => __async(exports, null, function* () {
|
|
48
78
|
let index = 0;
|
|
49
|
-
const fn = (0,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
79
|
+
const fn = (0, import_util.withCoalescedInvoke)(
|
|
80
|
+
() => __async(exports, null, function* () {
|
|
81
|
+
return new Promise((resolve) => {
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
index += 1;
|
|
84
|
+
resolve(index);
|
|
85
|
+
}, 500);
|
|
86
|
+
});
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
const key = "test";
|
|
90
|
+
const [res1, res2] = yield Promise.all([fn(key, []), fn(key, [])]);
|
|
57
91
|
expect(res1.isOrigin && res2.isOrigin).toBe(false);
|
|
58
92
|
expect(res1.isOrigin || res2.isOrigin).toBe(true);
|
|
59
93
|
expect(res1.value).toBe(1);
|
|
60
94
|
expect(res2.value).toBe(1);
|
|
61
|
-
});
|
|
62
|
-
it(
|
|
63
|
-
const foo =
|
|
64
|
-
const async =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
95
|
+
}));
|
|
96
|
+
it("should invoke sync or async", () => __async(exports, null, function* () {
|
|
97
|
+
const foo = "";
|
|
98
|
+
const async = yield (0, import_util.maybeSync)(
|
|
99
|
+
() => new Promise((resolve) => {
|
|
100
|
+
setTimeout(() => {
|
|
101
|
+
resolve(foo);
|
|
102
|
+
}, 100);
|
|
103
|
+
})
|
|
104
|
+
)(false);
|
|
69
105
|
expect(async).toBeUndefined();
|
|
70
|
-
const sync =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
106
|
+
const sync = yield (0, import_util.maybeSync)(
|
|
107
|
+
() => new Promise((resolve) => {
|
|
108
|
+
setTimeout(() => {
|
|
109
|
+
resolve(foo);
|
|
110
|
+
}, 100);
|
|
111
|
+
})
|
|
112
|
+
)(true);
|
|
75
113
|
expect(sync).toBe(foo);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
114
|
+
}));
|
|
115
|
+
});
|
|
@@ -1,20 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
var import_spr = require("../spr");
|
|
38
|
+
var import_error_configuration = require("./error-configuration");
|
|
39
|
+
var import_cacheable = require("./cacheable");
|
|
40
|
+
var import_matched_cache = require("./matched-cache");
|
|
41
|
+
const createCacheConfig = (config = {}) => __spreadValues({
|
|
18
42
|
excludes: null,
|
|
19
43
|
includes: null,
|
|
20
44
|
interval: 10,
|
|
@@ -23,198 +47,181 @@ const createCacheConfig = (config = {}) => _objectSpread({
|
|
|
23
47
|
fallback: false,
|
|
24
48
|
matches: null
|
|
25
49
|
}, config);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
(0,
|
|
31
|
-
const cache = (0, _spr.createCache)();
|
|
50
|
+
jest.setTimeout(6e4);
|
|
51
|
+
describe("cache", () => {
|
|
52
|
+
it("should cache correctly", () => __async(exports, null, function* () {
|
|
53
|
+
(0, import_spr.destroyCache)();
|
|
54
|
+
const cache = (0, import_spr.createCache)();
|
|
32
55
|
const context = {
|
|
33
|
-
entry:
|
|
34
|
-
pathname:
|
|
56
|
+
entry: "",
|
|
57
|
+
pathname: "",
|
|
35
58
|
query: {},
|
|
36
59
|
headers: {}
|
|
37
60
|
};
|
|
38
|
-
const content =
|
|
61
|
+
const content = "hello";
|
|
39
62
|
const cacheConfig = createCacheConfig();
|
|
40
|
-
|
|
41
|
-
const cacheResult =
|
|
63
|
+
yield cache.set(context, content, cacheConfig, true);
|
|
64
|
+
const cacheResult = yield cache.get(context);
|
|
42
65
|
expect(cacheResult).not.toBe(null);
|
|
43
|
-
expect(cacheResult
|
|
44
|
-
});
|
|
45
|
-
it(
|
|
46
|
-
(0,
|
|
47
|
-
(0,
|
|
48
|
-
const cache = (0,
|
|
66
|
+
expect(cacheResult == null ? void 0 : cacheResult.content).toBe("hello");
|
|
67
|
+
}));
|
|
68
|
+
it("should ignore cache set when cache config not exist", () => __async(exports, null, function* () {
|
|
69
|
+
(0, import_spr.destroyCache)();
|
|
70
|
+
(0, import_spr.destroyCache)();
|
|
71
|
+
const cache = (0, import_spr.createCache)();
|
|
49
72
|
const context = {
|
|
50
|
-
entry:
|
|
51
|
-
pathname:
|
|
73
|
+
entry: "",
|
|
74
|
+
pathname: "",
|
|
52
75
|
query: {},
|
|
53
76
|
headers: {}
|
|
54
77
|
};
|
|
55
|
-
const content =
|
|
56
|
-
const shouldCache =
|
|
78
|
+
const content = "hello";
|
|
79
|
+
const shouldCache = yield cache.set(context, content, null, true);
|
|
57
80
|
expect(shouldCache).toBe(false);
|
|
58
|
-
});
|
|
59
|
-
it(
|
|
60
|
-
(0,
|
|
61
|
-
const cache = (0,
|
|
62
|
-
const content =
|
|
63
|
-
|
|
64
|
-
for (const config of _errorConfiguration.errorConfiguration) {
|
|
81
|
+
}));
|
|
82
|
+
it("should calcual cache key error", () => __async(exports, null, function* () {
|
|
83
|
+
(0, import_spr.destroyCache)();
|
|
84
|
+
const cache = (0, import_spr.createCache)();
|
|
85
|
+
const content = "hello";
|
|
86
|
+
for (const config of import_error_configuration.errorConfiguration) {
|
|
65
87
|
const cacheConfig = createCacheConfig(config);
|
|
66
88
|
const tmpEntry = Math.random().toString();
|
|
67
89
|
const context = {
|
|
68
90
|
entry: tmpEntry,
|
|
69
|
-
pathname:
|
|
91
|
+
pathname: "",
|
|
70
92
|
query: {},
|
|
71
93
|
headers: {}
|
|
72
94
|
};
|
|
73
|
-
const shouldCache =
|
|
95
|
+
const shouldCache = yield cache.set(context, content, cacheConfig);
|
|
74
96
|
expect(shouldCache).toBe(false);
|
|
75
97
|
}
|
|
76
|
-
});
|
|
77
|
-
it(
|
|
78
|
-
(0,
|
|
79
|
-
const cache = (0,
|
|
98
|
+
}));
|
|
99
|
+
it("should get nothing for diff requestKey", () => __async(exports, null, function* () {
|
|
100
|
+
(0, import_spr.destroyCache)();
|
|
101
|
+
const cache = (0, import_spr.createCache)();
|
|
80
102
|
const context = {
|
|
81
|
-
entry:
|
|
82
|
-
pathname:
|
|
103
|
+
entry: "",
|
|
104
|
+
pathname: "",
|
|
83
105
|
query: {},
|
|
84
106
|
headers: {}
|
|
85
107
|
};
|
|
86
|
-
const content =
|
|
108
|
+
const content = "hello";
|
|
87
109
|
const cacheConfig = createCacheConfig({
|
|
88
110
|
level: 1,
|
|
89
|
-
includes: {
|
|
90
|
-
query: ['name']
|
|
91
|
-
}
|
|
111
|
+
includes: { query: ["name"] }
|
|
92
112
|
});
|
|
93
|
-
|
|
113
|
+
yield cache.set(context, content, cacheConfig, true);
|
|
94
114
|
const context_req = {
|
|
95
|
-
entry:
|
|
96
|
-
pathname:
|
|
115
|
+
entry: "",
|
|
116
|
+
pathname: "/home",
|
|
97
117
|
query: {},
|
|
98
118
|
headers: {}
|
|
99
119
|
};
|
|
100
|
-
const cacheResult =
|
|
120
|
+
const cacheResult = yield cache.get(context_req);
|
|
101
121
|
expect(cacheResult).toBe(null);
|
|
102
|
-
});
|
|
103
|
-
it(
|
|
104
|
-
(0,
|
|
105
|
-
const cache = (0,
|
|
122
|
+
}));
|
|
123
|
+
it("should get nothing for diff cacheHash", () => __async(exports, null, function* () {
|
|
124
|
+
(0, import_spr.destroyCache)();
|
|
125
|
+
const cache = (0, import_spr.createCache)();
|
|
106
126
|
const context = {
|
|
107
|
-
entry:
|
|
108
|
-
pathname:
|
|
127
|
+
entry: "",
|
|
128
|
+
pathname: "",
|
|
109
129
|
query: {},
|
|
110
130
|
headers: {}
|
|
111
131
|
};
|
|
112
|
-
const content =
|
|
132
|
+
const content = "hello";
|
|
113
133
|
const cacheConfig = createCacheConfig({
|
|
114
134
|
level: 1,
|
|
115
|
-
includes: {
|
|
116
|
-
query: ['name']
|
|
117
|
-
}
|
|
135
|
+
includes: { query: ["name"] }
|
|
118
136
|
});
|
|
119
|
-
|
|
137
|
+
yield cache.set(context, content, cacheConfig, true);
|
|
120
138
|
const context_req = {
|
|
121
|
-
entry:
|
|
122
|
-
pathname:
|
|
123
|
-
query: {
|
|
124
|
-
name: 'zll'
|
|
125
|
-
},
|
|
139
|
+
entry: "",
|
|
140
|
+
pathname: "",
|
|
141
|
+
query: { name: "zll" },
|
|
126
142
|
headers: {}
|
|
127
143
|
};
|
|
128
|
-
const cacheResult =
|
|
144
|
+
const cacheResult = yield cache.get(context_req);
|
|
129
145
|
expect(cacheResult).toBe(null);
|
|
130
|
-
});
|
|
131
|
-
it(
|
|
132
|
-
(0,
|
|
133
|
-
const cache = (0,
|
|
134
|
-
|
|
135
|
-
for (const cacheable of _cacheable.cacheabelAry) {
|
|
146
|
+
}));
|
|
147
|
+
it("should get cache correctly", () => __async(exports, null, function* () {
|
|
148
|
+
(0, import_spr.destroyCache)();
|
|
149
|
+
const cache = (0, import_spr.createCache)();
|
|
150
|
+
for (const cacheable of import_cacheable.cacheabelAry) {
|
|
136
151
|
const context = {
|
|
137
|
-
entry:
|
|
152
|
+
entry: "",
|
|
138
153
|
pathname: cacheable.requestOpt.url,
|
|
139
154
|
query: cacheable.requestOpt.query || {},
|
|
140
155
|
headers: cacheable.requestOpt.headers || {}
|
|
141
156
|
};
|
|
142
157
|
const cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
|
|
143
|
-
|
|
144
|
-
const cacheResult =
|
|
145
|
-
expect(cacheResult
|
|
158
|
+
yield cache.set(context, cacheable.content, cacheConfig, true);
|
|
159
|
+
const cacheResult = yield cache.get(context);
|
|
160
|
+
expect(cacheResult == null ? void 0 : cacheResult.content).toBe(cacheable.content);
|
|
146
161
|
}
|
|
147
|
-
});
|
|
148
|
-
it(
|
|
149
|
-
(0,
|
|
150
|
-
const cache = (0,
|
|
151
|
-
|
|
152
|
-
for (const cacheable of _matchedCache.matchedCacheableAry) {
|
|
162
|
+
}));
|
|
163
|
+
it("should match cache correctly", () => __async(exports, null, function* () {
|
|
164
|
+
(0, import_spr.destroyCache)();
|
|
165
|
+
const cache = (0, import_spr.createCache)();
|
|
166
|
+
for (const cacheable of import_matched_cache.matchedCacheableAry) {
|
|
153
167
|
const [baseCacheable, matchOne, ...other] = cacheable;
|
|
154
|
-
const {
|
|
155
|
-
requestOpt = {},
|
|
156
|
-
cacheConfig,
|
|
157
|
-
content
|
|
158
|
-
} = baseCacheable;
|
|
168
|
+
const { requestOpt = {}, cacheConfig, content } = baseCacheable;
|
|
159
169
|
const context = {
|
|
160
|
-
entry:
|
|
170
|
+
entry: "",
|
|
161
171
|
pathname: requestOpt.url,
|
|
162
172
|
query: requestOpt.query,
|
|
163
173
|
headers: requestOpt.headers
|
|
164
174
|
};
|
|
165
|
-
|
|
175
|
+
yield cache.set(context, content, createCacheConfig(cacheConfig), true);
|
|
166
176
|
const matchContext = {
|
|
167
|
-
entry:
|
|
177
|
+
entry: "",
|
|
168
178
|
pathname: matchOne.url,
|
|
169
179
|
query: matchOne.query,
|
|
170
180
|
headers: matchOne.headers
|
|
171
181
|
};
|
|
172
|
-
const cacheResult =
|
|
173
|
-
expect(cacheResult
|
|
174
|
-
|
|
182
|
+
const cacheResult = yield cache.get(matchContext);
|
|
183
|
+
expect(cacheResult == null ? void 0 : cacheResult.content).toBe(content);
|
|
175
184
|
for (const notMatch of other) {
|
|
176
185
|
const notMatchContext = {
|
|
177
|
-
entry:
|
|
186
|
+
entry: "",
|
|
178
187
|
pathname: notMatch.url,
|
|
179
188
|
query: notMatch.query,
|
|
180
189
|
headers: notMatch.headers
|
|
181
190
|
};
|
|
182
|
-
const nothing =
|
|
191
|
+
const nothing = yield cache.get(notMatchContext);
|
|
183
192
|
expect(nothing).toBe(null);
|
|
184
193
|
}
|
|
185
194
|
}
|
|
186
|
-
});
|
|
187
|
-
it(
|
|
188
|
-
(0,
|
|
189
|
-
const cache = (0,
|
|
195
|
+
}));
|
|
196
|
+
it("should stale cache correctly", () => __async(exports, null, function* () {
|
|
197
|
+
(0, import_spr.destroyCache)();
|
|
198
|
+
const cache = (0, import_spr.createCache)();
|
|
190
199
|
const context = {
|
|
191
|
-
entry:
|
|
192
|
-
pathname:
|
|
200
|
+
entry: "",
|
|
201
|
+
pathname: "",
|
|
193
202
|
query: {},
|
|
194
203
|
headers: {}
|
|
195
204
|
};
|
|
196
|
-
const config = createCacheConfig({
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const content = 'hello';
|
|
200
|
-
const shouldCache = await cache.set(context, content, config, true);
|
|
205
|
+
const config = createCacheConfig({ interval: 5 });
|
|
206
|
+
const content = "hello";
|
|
207
|
+
const shouldCache = yield cache.set(context, content, config, true);
|
|
201
208
|
expect(shouldCache.value).toBe(true);
|
|
202
|
-
const freshResult =
|
|
203
|
-
expect(freshResult
|
|
204
|
-
|
|
209
|
+
const freshResult = yield cache.get(context);
|
|
210
|
+
expect(freshResult == null ? void 0 : freshResult.isStale).toBe(false);
|
|
211
|
+
yield new Promise((resolve) => {
|
|
205
212
|
setTimeout(() => {
|
|
206
213
|
resolve();
|
|
207
|
-
},
|
|
214
|
+
}, 6e3);
|
|
208
215
|
});
|
|
209
|
-
const staleResult =
|
|
210
|
-
expect(staleResult
|
|
211
|
-
});
|
|
212
|
-
it(
|
|
213
|
-
(0,
|
|
214
|
-
const cache = (0,
|
|
216
|
+
const staleResult = yield cache.get(context);
|
|
217
|
+
expect(staleResult == null ? void 0 : staleResult.isStale).toBe(true);
|
|
218
|
+
}));
|
|
219
|
+
it("should garbage cache correctly", () => __async(exports, null, function* () {
|
|
220
|
+
(0, import_spr.destroyCache)();
|
|
221
|
+
const cache = (0, import_spr.createCache)();
|
|
215
222
|
const context = {
|
|
216
|
-
entry:
|
|
217
|
-
pathname:
|
|
223
|
+
entry: "",
|
|
224
|
+
pathname: "",
|
|
218
225
|
query: {},
|
|
219
226
|
headers: {}
|
|
220
227
|
};
|
|
@@ -222,17 +229,17 @@ describe('cache', () => {
|
|
|
222
229
|
interval: 3,
|
|
223
230
|
staleLimit: 8
|
|
224
231
|
});
|
|
225
|
-
const content =
|
|
226
|
-
const shouldCache =
|
|
232
|
+
const content = "hello";
|
|
233
|
+
const shouldCache = yield cache.set(context, content, config, true);
|
|
227
234
|
expect(shouldCache.value).toBe(true);
|
|
228
|
-
const freshResult =
|
|
229
|
-
expect(freshResult
|
|
230
|
-
|
|
235
|
+
const freshResult = yield cache.get(context);
|
|
236
|
+
expect(freshResult == null ? void 0 : freshResult.isGarbage).toBe(false);
|
|
237
|
+
yield new Promise((resolve) => {
|
|
231
238
|
setTimeout(() => {
|
|
232
239
|
resolve();
|
|
233
|
-
},
|
|
240
|
+
}, 1e4);
|
|
234
241
|
});
|
|
235
|
-
const staleResult =
|
|
236
|
-
expect(staleResult
|
|
237
|
-
});
|
|
238
|
-
});
|
|
242
|
+
const staleResult = yield cache.get(context);
|
|
243
|
+
expect(staleResult == null ? void 0 : staleResult.isGarbage).toBe(true);
|
|
244
|
+
}));
|
|
245
|
+
});
|