@modern-js/prod-server 2.6.0 → 2.6.1-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/dist/cjs/index.js +2 -2
- package/dist/cjs/libs/{serve-file.js → serveFile.js} +3 -3
- package/dist/cjs/server/index.js +6 -4
- package/dist/cjs/server/{modern-server.js → modernServer.js} +8 -9
- package/dist/cjs/server/{modern-server-split.js → modernServerSplit.js} +8 -8
- package/dist/cjs/{worker-server.js → workerServer.js} +3 -3
- package/dist/esm/index.js +1 -1
- package/dist/esm/server/index.js +5 -3
- package/dist/esm/server/{modern-server.js → modernServer.js} +4 -5
- package/dist/esm/server/modernServerSplit.js +360 -0
- package/dist/esm-node/index.js +1 -1
- package/dist/esm-node/server/index.js +5 -3
- package/dist/esm-node/server/{modern-server.js → modernServer.js} +3 -4
- package/dist/esm-node/server/{modern-server-split.js → modernServerSplit.js} +1 -1
- package/dist/js/modern/constants.js +35 -0
- package/dist/js/modern/index.js +18 -0
- package/dist/js/modern/libs/context/context.js +160 -0
- package/dist/js/modern/libs/context/index.js +6 -0
- package/dist/js/modern/libs/hook-api/index.js +134 -0
- package/dist/js/modern/libs/hook-api/route.js +20 -0
- package/dist/js/modern/libs/hook-api/template.js +73 -0
- package/dist/js/modern/libs/loadConfig.js +62 -0
- package/dist/js/modern/libs/logger.js +111 -0
- package/dist/js/modern/libs/metrics.js +11 -0
- package/dist/js/modern/libs/proxy.js +92 -0
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +114 -0
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +254 -0
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +47 -0
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +37 -0
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +91 -0
- package/dist/js/modern/libs/render/cache/index.js +115 -0
- package/dist/js/modern/libs/render/cache/page-caches/index.js +32 -0
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +29 -0
- package/dist/js/modern/libs/render/cache/spr.js +248 -0
- package/dist/js/modern/libs/render/cache/type.js +0 -0
- package/dist/js/modern/libs/render/cache/util.js +102 -0
- package/dist/js/modern/libs/render/index.js +86 -0
- package/dist/js/modern/libs/render/measure.js +68 -0
- package/dist/js/modern/libs/render/reader.js +107 -0
- package/dist/js/modern/libs/render/ssr.js +100 -0
- package/dist/js/modern/libs/render/static.js +60 -0
- package/dist/js/modern/libs/render/type.js +9 -0
- package/dist/js/modern/libs/route/index.js +54 -0
- package/dist/js/modern/libs/route/matcher.js +87 -0
- package/dist/js/modern/libs/route/route.js +16 -0
- package/dist/js/modern/libs/serve-file.js +67 -0
- package/dist/js/modern/server/index.js +208 -0
- package/dist/js/modern/server/modern-server-split.js +74 -0
- package/dist/js/modern/server/modern-server.js +554 -0
- package/dist/js/modern/type.js +0 -0
- package/dist/js/modern/utils.js +136 -0
- package/dist/js/modern/worker-server.js +89 -0
- package/dist/js/node/constants.js +62 -0
- package/dist/js/node/index.js +44 -0
- package/dist/js/node/libs/context/context.js +189 -0
- package/dist/js/node/libs/context/index.js +30 -0
- package/dist/js/node/libs/hook-api/index.js +164 -0
- package/dist/js/node/libs/hook-api/route.js +43 -0
- package/dist/js/node/libs/hook-api/template.js +97 -0
- package/dist/js/node/libs/loadConfig.js +91 -0
- package/dist/js/node/libs/logger.js +133 -0
- package/dist/js/node/libs/metrics.js +34 -0
- package/dist/js/node/libs/proxy.js +114 -0
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +115 -0
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +245 -0
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +70 -0
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +60 -0
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +114 -0
- package/dist/js/node/libs/render/cache/index.js +134 -0
- package/dist/js/node/libs/render/cache/page-caches/index.js +55 -0
- package/dist/js/node/libs/render/cache/page-caches/lru.js +58 -0
- package/dist/js/node/libs/render/cache/spr.js +270 -0
- package/dist/js/node/libs/render/cache/type.js +15 -0
- package/dist/js/node/libs/render/cache/util.js +138 -0
- package/dist/js/node/libs/render/index.js +115 -0
- package/dist/js/node/libs/render/measure.js +90 -0
- package/dist/js/node/libs/render/reader.js +140 -0
- package/dist/js/node/libs/render/ssr.js +123 -0
- package/dist/js/node/libs/render/static.js +89 -0
- package/dist/js/node/libs/render/type.js +32 -0
- package/dist/js/node/libs/route/index.js +78 -0
- package/dist/js/node/libs/route/matcher.js +106 -0
- package/dist/js/node/libs/route/route.js +39 -0
- package/dist/js/node/libs/serve-file.js +97 -0
- package/dist/js/node/server/index.js +219 -0
- package/dist/js/node/server/modern-server-split.js +97 -0
- package/dist/js/node/server/modern-server.js +559 -0
- package/dist/js/node/type.js +15 -0
- package/dist/js/node/utils.js +166 -0
- package/dist/js/node/worker-server.js +113 -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/logger.js +205 -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 +234 -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 +143 -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.js +1089 -0
- package/dist/js/treeshaking/type.js +1 -0
- package/dist/js/treeshaking/utils.js +147 -0
- package/dist/js/treeshaking/worker-server.js +233 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/type.d.ts +8 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +14 -14
- /package/dist/esm/libs/{serve-file.js → serveFile.js} +0 -0
- /package/dist/esm/{worker-server.js → workerServer.js} +0 -0
- /package/dist/esm-node/libs/{serve-file.js → serveFile.js} +0 -0
- /package/dist/esm-node/{worker-server.js → workerServer.js} +0 -0
- /package/dist/{esm → js/treeshaking}/server/modern-server-split.js +0 -0
- /package/dist/types/libs/{serve-file.d.ts → serveFile.d.ts} +0 -0
- /package/dist/types/server/{modern-server.d.ts → modernServer.d.ts} +0 -0
- /package/dist/types/server/{modern-server-split.d.ts → modernServerSplit.d.ts} +0 -0
- /package/dist/types/{worker-server.d.ts → workerServer.d.ts} +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
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/!@#$%^&");
|
|
47
|
+
});
|
|
48
|
+
it("should create or destroy instance correctly", () => {
|
|
49
|
+
const ins1 = (0, import_spr.createCache)();
|
|
50
|
+
const ins2 = (0, import_spr.createCache)();
|
|
51
|
+
expect(ins1 === ins2).toBe(true);
|
|
52
|
+
(0, import_spr.destroyCache)();
|
|
53
|
+
const ins3 = (0, import_spr.createCache)();
|
|
54
|
+
expect(ins1 === ins3).toBe(false);
|
|
55
|
+
expect(ins2 === ins3).toBe(false);
|
|
56
|
+
});
|
|
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");
|
|
65
|
+
});
|
|
66
|
+
it("should add target html content", () => {
|
|
67
|
+
const contentNoHead = "<div>123</div>";
|
|
68
|
+
const html = (0, import_util.cacheAddition)(contentNoHead, Math.random().toString());
|
|
69
|
+
expect(html).toBe(contentNoHead);
|
|
70
|
+
const contentWithHead = "<head></head><div>123</div>";
|
|
71
|
+
const hash = Math.random().toString();
|
|
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
|
+
);
|
|
76
|
+
});
|
|
77
|
+
it("should only invoke func one time", () => __async(exports, null, function* () {
|
|
78
|
+
let index = 0;
|
|
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, [])]);
|
|
91
|
+
expect(res1.isOrigin && res2.isOrigin).toBe(false);
|
|
92
|
+
expect(res1.isOrigin || res2.isOrigin).toBe(true);
|
|
93
|
+
expect(res1.value).toBe(1);
|
|
94
|
+
expect(res2.value).toBe(1);
|
|
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);
|
|
105
|
+
expect(async).toBeUndefined();
|
|
106
|
+
const sync = yield (0, import_util.maybeSync)(
|
|
107
|
+
() => new Promise((resolve) => {
|
|
108
|
+
setTimeout(() => {
|
|
109
|
+
resolve(foo);
|
|
110
|
+
}, 100);
|
|
111
|
+
})
|
|
112
|
+
)(true);
|
|
113
|
+
expect(sync).toBe(foo);
|
|
114
|
+
}));
|
|
115
|
+
});
|
|
@@ -0,0 +1,245 @@
|
|
|
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({
|
|
42
|
+
excludes: null,
|
|
43
|
+
includes: null,
|
|
44
|
+
interval: 10,
|
|
45
|
+
staleLimit: false,
|
|
46
|
+
level: 0,
|
|
47
|
+
fallback: false,
|
|
48
|
+
matches: null
|
|
49
|
+
}, config);
|
|
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)();
|
|
55
|
+
const context = {
|
|
56
|
+
entry: "",
|
|
57
|
+
pathname: "",
|
|
58
|
+
query: {},
|
|
59
|
+
headers: {}
|
|
60
|
+
};
|
|
61
|
+
const content = "hello";
|
|
62
|
+
const cacheConfig = createCacheConfig();
|
|
63
|
+
yield cache.set(context, content, cacheConfig, true);
|
|
64
|
+
const cacheResult = yield cache.get(context);
|
|
65
|
+
expect(cacheResult).not.toBe(null);
|
|
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)();
|
|
72
|
+
const context = {
|
|
73
|
+
entry: "",
|
|
74
|
+
pathname: "",
|
|
75
|
+
query: {},
|
|
76
|
+
headers: {}
|
|
77
|
+
};
|
|
78
|
+
const content = "hello";
|
|
79
|
+
const shouldCache = yield cache.set(context, content, null, true);
|
|
80
|
+
expect(shouldCache).toBe(false);
|
|
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) {
|
|
87
|
+
const cacheConfig = createCacheConfig(config);
|
|
88
|
+
const tmpEntry = Math.random().toString();
|
|
89
|
+
const context = {
|
|
90
|
+
entry: tmpEntry,
|
|
91
|
+
pathname: "",
|
|
92
|
+
query: {},
|
|
93
|
+
headers: {}
|
|
94
|
+
};
|
|
95
|
+
const shouldCache = yield cache.set(context, content, cacheConfig);
|
|
96
|
+
expect(shouldCache).toBe(false);
|
|
97
|
+
}
|
|
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)();
|
|
102
|
+
const context = {
|
|
103
|
+
entry: "",
|
|
104
|
+
pathname: "",
|
|
105
|
+
query: {},
|
|
106
|
+
headers: {}
|
|
107
|
+
};
|
|
108
|
+
const content = "hello";
|
|
109
|
+
const cacheConfig = createCacheConfig({
|
|
110
|
+
level: 1,
|
|
111
|
+
includes: { query: ["name"] }
|
|
112
|
+
});
|
|
113
|
+
yield cache.set(context, content, cacheConfig, true);
|
|
114
|
+
const context_req = {
|
|
115
|
+
entry: "",
|
|
116
|
+
pathname: "/home",
|
|
117
|
+
query: {},
|
|
118
|
+
headers: {}
|
|
119
|
+
};
|
|
120
|
+
const cacheResult = yield cache.get(context_req);
|
|
121
|
+
expect(cacheResult).toBe(null);
|
|
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)();
|
|
126
|
+
const context = {
|
|
127
|
+
entry: "",
|
|
128
|
+
pathname: "",
|
|
129
|
+
query: {},
|
|
130
|
+
headers: {}
|
|
131
|
+
};
|
|
132
|
+
const content = "hello";
|
|
133
|
+
const cacheConfig = createCacheConfig({
|
|
134
|
+
level: 1,
|
|
135
|
+
includes: { query: ["name"] }
|
|
136
|
+
});
|
|
137
|
+
yield cache.set(context, content, cacheConfig, true);
|
|
138
|
+
const context_req = {
|
|
139
|
+
entry: "",
|
|
140
|
+
pathname: "",
|
|
141
|
+
query: { name: "zll" },
|
|
142
|
+
headers: {}
|
|
143
|
+
};
|
|
144
|
+
const cacheResult = yield cache.get(context_req);
|
|
145
|
+
expect(cacheResult).toBe(null);
|
|
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) {
|
|
151
|
+
const context = {
|
|
152
|
+
entry: "",
|
|
153
|
+
pathname: cacheable.requestOpt.url,
|
|
154
|
+
query: cacheable.requestOpt.query || {},
|
|
155
|
+
headers: cacheable.requestOpt.headers || {}
|
|
156
|
+
};
|
|
157
|
+
const cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
|
|
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);
|
|
161
|
+
}
|
|
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) {
|
|
167
|
+
const [baseCacheable, matchOne, ...other] = cacheable;
|
|
168
|
+
const { requestOpt = {}, cacheConfig, content } = baseCacheable;
|
|
169
|
+
const context = {
|
|
170
|
+
entry: "",
|
|
171
|
+
pathname: requestOpt.url,
|
|
172
|
+
query: requestOpt.query,
|
|
173
|
+
headers: requestOpt.headers
|
|
174
|
+
};
|
|
175
|
+
yield cache.set(context, content, createCacheConfig(cacheConfig), true);
|
|
176
|
+
const matchContext = {
|
|
177
|
+
entry: "",
|
|
178
|
+
pathname: matchOne.url,
|
|
179
|
+
query: matchOne.query,
|
|
180
|
+
headers: matchOne.headers
|
|
181
|
+
};
|
|
182
|
+
const cacheResult = yield cache.get(matchContext);
|
|
183
|
+
expect(cacheResult == null ? void 0 : cacheResult.content).toBe(content);
|
|
184
|
+
for (const notMatch of other) {
|
|
185
|
+
const notMatchContext = {
|
|
186
|
+
entry: "",
|
|
187
|
+
pathname: notMatch.url,
|
|
188
|
+
query: notMatch.query,
|
|
189
|
+
headers: notMatch.headers
|
|
190
|
+
};
|
|
191
|
+
const nothing = yield cache.get(notMatchContext);
|
|
192
|
+
expect(nothing).toBe(null);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}));
|
|
196
|
+
it("should stale cache correctly", () => __async(exports, null, function* () {
|
|
197
|
+
(0, import_spr.destroyCache)();
|
|
198
|
+
const cache = (0, import_spr.createCache)();
|
|
199
|
+
const context = {
|
|
200
|
+
entry: "",
|
|
201
|
+
pathname: "",
|
|
202
|
+
query: {},
|
|
203
|
+
headers: {}
|
|
204
|
+
};
|
|
205
|
+
const config = createCacheConfig({ interval: 5 });
|
|
206
|
+
const content = "hello";
|
|
207
|
+
const shouldCache = yield cache.set(context, content, config, true);
|
|
208
|
+
expect(shouldCache.value).toBe(true);
|
|
209
|
+
const freshResult = yield cache.get(context);
|
|
210
|
+
expect(freshResult == null ? void 0 : freshResult.isStale).toBe(false);
|
|
211
|
+
yield new Promise((resolve) => {
|
|
212
|
+
setTimeout(() => {
|
|
213
|
+
resolve();
|
|
214
|
+
}, 6e3);
|
|
215
|
+
});
|
|
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)();
|
|
222
|
+
const context = {
|
|
223
|
+
entry: "",
|
|
224
|
+
pathname: "",
|
|
225
|
+
query: {},
|
|
226
|
+
headers: {}
|
|
227
|
+
};
|
|
228
|
+
const config = createCacheConfig({
|
|
229
|
+
interval: 3,
|
|
230
|
+
staleLimit: 8
|
|
231
|
+
});
|
|
232
|
+
const content = "hello";
|
|
233
|
+
const shouldCache = yield cache.set(context, content, config, true);
|
|
234
|
+
expect(shouldCache.value).toBe(true);
|
|
235
|
+
const freshResult = yield cache.get(context);
|
|
236
|
+
expect(freshResult == null ? void 0 : freshResult.isGarbage).toBe(false);
|
|
237
|
+
yield new Promise((resolve) => {
|
|
238
|
+
setTimeout(() => {
|
|
239
|
+
resolve();
|
|
240
|
+
}, 1e4);
|
|
241
|
+
});
|
|
242
|
+
const staleResult = yield cache.get(context);
|
|
243
|
+
expect(staleResult == null ? void 0 : staleResult.isGarbage).toBe(true);
|
|
244
|
+
}));
|
|
245
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var cacheable_exports = {};
|
|
19
|
+
__export(cacheable_exports, {
|
|
20
|
+
cacheabelAry: () => cacheabelAry
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(cacheable_exports);
|
|
23
|
+
const cacheabelAry = [
|
|
24
|
+
{
|
|
25
|
+
requestOpt: { url: "/" },
|
|
26
|
+
cacheConfig: {},
|
|
27
|
+
content: "level0"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
requestOpt: {
|
|
31
|
+
url: "/level-one",
|
|
32
|
+
query: { name: "modern" }
|
|
33
|
+
},
|
|
34
|
+
cacheConfig: {
|
|
35
|
+
level: 1,
|
|
36
|
+
includes: { query: ["name"] }
|
|
37
|
+
},
|
|
38
|
+
content: "level1"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
requestOpt: {
|
|
42
|
+
url: "/level-two",
|
|
43
|
+
headers: { age: "18" }
|
|
44
|
+
},
|
|
45
|
+
cacheConfig: {
|
|
46
|
+
level: 2,
|
|
47
|
+
includes: { header: ["age"] }
|
|
48
|
+
},
|
|
49
|
+
content: "level2"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
requestOpt: {
|
|
53
|
+
url: "/level-three",
|
|
54
|
+
query: { name: "modern" },
|
|
55
|
+
headers: { age: "18" }
|
|
56
|
+
},
|
|
57
|
+
cacheConfig: {
|
|
58
|
+
level: 3,
|
|
59
|
+
includes: {
|
|
60
|
+
query: ["name"],
|
|
61
|
+
header: ["age"]
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
content: "level3"
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
cacheabelAry
|
|
70
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var error_configuration_exports = {};
|
|
19
|
+
__export(error_configuration_exports, {
|
|
20
|
+
errorConfiguration: () => errorConfiguration
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(error_configuration_exports);
|
|
23
|
+
const errorConfiguration = [
|
|
24
|
+
{ level: 1 },
|
|
25
|
+
{
|
|
26
|
+
level: 1,
|
|
27
|
+
includes: {}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
level: 1,
|
|
31
|
+
includes: { query: [] }
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
level: 2,
|
|
35
|
+
includes: {}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
level: 2,
|
|
39
|
+
includes: { header: [] }
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
level: 3,
|
|
43
|
+
includes: { header: [] }
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
level: 3,
|
|
47
|
+
includes: { query: [] }
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
level: 3,
|
|
51
|
+
includes: {
|
|
52
|
+
query: [],
|
|
53
|
+
header: []
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
errorConfiguration
|
|
60
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var matched_cache_exports = {};
|
|
19
|
+
__export(matched_cache_exports, {
|
|
20
|
+
matchedCacheableAry: () => matchedCacheableAry
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(matched_cache_exports);
|
|
23
|
+
const matchedCacheableAry = [
|
|
24
|
+
[
|
|
25
|
+
{
|
|
26
|
+
requestOpt: {
|
|
27
|
+
url: "/level-one",
|
|
28
|
+
headers: {},
|
|
29
|
+
query: { name: "byted" }
|
|
30
|
+
},
|
|
31
|
+
cacheConfig: {
|
|
32
|
+
level: 1,
|
|
33
|
+
includes: { query: ["name"] },
|
|
34
|
+
matches: { query: { name: { weixin: "^byted" } } }
|
|
35
|
+
},
|
|
36
|
+
content: "level1"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
url: "/level-one",
|
|
40
|
+
headers: {},
|
|
41
|
+
query: { name: "byted_likely" }
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
url: "/level-one",
|
|
45
|
+
headers: {},
|
|
46
|
+
query: { name: "not_byted" }
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
{
|
|
51
|
+
requestOpt: {
|
|
52
|
+
url: "/level-two",
|
|
53
|
+
query: {},
|
|
54
|
+
headers: { age: "17" }
|
|
55
|
+
},
|
|
56
|
+
cacheConfig: {
|
|
57
|
+
level: 2,
|
|
58
|
+
includes: { header: ["age"] },
|
|
59
|
+
matches: { header: { age: { one: "^1" } } }
|
|
60
|
+
},
|
|
61
|
+
content: "level2"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
url: "/level-two",
|
|
65
|
+
query: {},
|
|
66
|
+
headers: { age: "11" }
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
url: "/level-two",
|
|
70
|
+
query: {},
|
|
71
|
+
headers: { age: "22" }
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
{
|
|
76
|
+
requestOpt: {
|
|
77
|
+
url: "/level-three",
|
|
78
|
+
headers: { age: "17" },
|
|
79
|
+
query: { name: "byted" }
|
|
80
|
+
},
|
|
81
|
+
cacheConfig: {
|
|
82
|
+
level: 3,
|
|
83
|
+
includes: {
|
|
84
|
+
query: ["name"],
|
|
85
|
+
header: ["age"]
|
|
86
|
+
},
|
|
87
|
+
matches: {
|
|
88
|
+
query: { name: { weixin: "^byted" } },
|
|
89
|
+
header: { age: { one: "^1" } }
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
content: "level3"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
url: "/level-three",
|
|
96
|
+
query: { name: "byted_likely" },
|
|
97
|
+
headers: { age: "19" }
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
url: "/level-three",
|
|
101
|
+
query: { name: "byted_likely" },
|
|
102
|
+
headers: {}
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
url: "/level-three",
|
|
106
|
+
query: { name: "not_byted" },
|
|
107
|
+
headers: { age: "19" }
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
];
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {
|
|
113
|
+
matchedCacheableAry
|
|
114
|
+
});
|