@modern-js/prod-server 2.42.2 → 2.43.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/libs/render/index.js +3 -11
- package/dist/cjs/libs/render/ssr.js +2 -2
- package/dist/cjs/libs/render/{cache/page-caches/lru.js → ssrCache/cacheMod.js} +21 -31
- package/dist/cjs/libs/render/ssrCache/index.js +81 -0
- package/dist/cjs/libs/render/ssrCache/manager.js +104 -0
- package/dist/cjs/libs/render/static.js +5 -5
- package/dist/cjs/server/index.js +2 -0
- package/dist/cjs/server/modernServer.js +2 -9
- package/dist/esm/libs/render/index.js +3 -11
- package/dist/esm/libs/render/ssr.js +2 -2
- package/dist/esm/libs/render/ssrCache/cacheMod.js +33 -0
- package/dist/esm/libs/render/ssrCache/index.js +146 -0
- package/dist/esm/libs/render/ssrCache/manager.js +159 -0
- package/dist/esm/libs/render/static.js +5 -5
- package/dist/esm/server/index.js +14 -4
- package/dist/esm/server/modernServer.js +32 -42
- package/dist/esm-node/libs/render/index.js +3 -11
- package/dist/esm-node/libs/render/ssr.js +2 -2
- package/dist/esm-node/libs/render/ssrCache/cacheMod.js +22 -0
- package/dist/esm-node/libs/render/ssrCache/index.js +57 -0
- package/dist/esm-node/libs/render/ssrCache/manager.js +80 -0
- package/dist/esm-node/libs/render/static.js +5 -5
- package/dist/esm-node/server/index.js +2 -0
- package/dist/esm-node/server/modernServer.js +2 -9
- package/dist/types/libs/context/index.d.ts +2 -0
- package/dist/types/libs/preload/flushServerHeader.d.ts +2 -0
- package/dist/types/libs/proxy.d.ts +2 -0
- package/dist/types/libs/render/ssrCache/cacheMod.d.ts +8 -0
- package/dist/types/libs/render/ssrCache/index.d.ts +7 -0
- package/dist/types/libs/render/ssrCache/manager.d.ts +14 -0
- package/dist/types/renderHtml.d.ts +2 -0
- package/dist/types/server/index.d.ts +2 -0
- package/dist/types/server/modernServer.d.ts +2 -3
- package/dist/types/type.d.ts +2 -0
- package/package.json +8 -11
- package/dist/cjs/libs/render/cache/__tests__/cache.fun.test.js +0 -95
- package/dist/cjs/libs/render/cache/__tests__/cache.test.js +0 -223
- package/dist/cjs/libs/render/cache/__tests__/cacheable.js +0 -93
- package/dist/cjs/libs/render/cache/__tests__/error-configuration.js +0 -71
- package/dist/cjs/libs/render/cache/__tests__/matched-cache.js +0 -173
- package/dist/cjs/libs/render/cache/index.js +0 -92
- package/dist/cjs/libs/render/cache/page-caches/index.js +0 -36
- package/dist/cjs/libs/render/cache/spr.js +0 -247
- package/dist/cjs/libs/render/cache/type.js +0 -16
- package/dist/cjs/libs/render/cache/util.js +0 -121
- package/dist/cjs/libs/render/reader.js +0 -131
- package/dist/esm/libs/render/cache/__tests__/cache.fun.test.js +0 -124
- package/dist/esm/libs/render/cache/__tests__/cache.test.js +0 -612
- package/dist/esm/libs/render/cache/__tests__/cacheable.js +0 -69
- package/dist/esm/libs/render/cache/__tests__/error-configuration.js +0 -47
- package/dist/esm/libs/render/cache/__tests__/matched-cache.js +0 -149
- package/dist/esm/libs/render/cache/index.js +0 -204
- package/dist/esm/libs/render/cache/page-caches/index.js +0 -34
- package/dist/esm/libs/render/cache/page-caches/lru.js +0 -57
- package/dist/esm/libs/render/cache/spr.js +0 -345
- package/dist/esm/libs/render/cache/type.js +0 -0
- package/dist/esm/libs/render/cache/util.js +0 -105
- package/dist/esm/libs/render/reader.js +0 -196
- package/dist/esm-node/libs/render/cache/__tests__/cache.fun.test.js +0 -72
- package/dist/esm-node/libs/render/cache/__tests__/cache.test.js +0 -222
- package/dist/esm-node/libs/render/cache/__tests__/cacheable.js +0 -69
- package/dist/esm-node/libs/render/cache/__tests__/error-configuration.js +0 -47
- package/dist/esm-node/libs/render/cache/__tests__/matched-cache.js +0 -149
- package/dist/esm-node/libs/render/cache/index.js +0 -72
- package/dist/esm-node/libs/render/cache/page-caches/index.js +0 -12
- package/dist/esm-node/libs/render/cache/page-caches/lru.js +0 -32
- package/dist/esm-node/libs/render/cache/spr.js +0 -212
- package/dist/esm-node/libs/render/cache/type.js +0 -0
- package/dist/esm-node/libs/render/cache/util.js +0 -80
- package/dist/esm-node/libs/render/reader.js +0 -93
- package/dist/types/libs/render/cache/__tests__/cache.fun.test.d.ts +0 -1
- package/dist/types/libs/render/cache/__tests__/cache.test.d.ts +0 -1
- package/dist/types/libs/render/cache/__tests__/cacheable.d.ts +0 -62
- package/dist/types/libs/render/cache/__tests__/error-configuration.d.ts +0 -28
- package/dist/types/libs/render/cache/__tests__/matched-cache.d.ts +0 -124
- package/dist/types/libs/render/cache/index.d.ts +0 -6
- package/dist/types/libs/render/cache/page-caches/index.d.ts +0 -2
- package/dist/types/libs/render/cache/page-caches/lru.d.ts +0 -15
- package/dist/types/libs/render/cache/spr.d.ts +0 -22
- package/dist/types/libs/render/cache/type.d.ts +0 -48
- package/dist/types/libs/render/cache/util.d.ts +0 -18
- package/dist/types/libs/render/reader.d.ts +0 -20
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node/http" />
|
|
3
|
+
/// <reference types="dist/types/type" />
|
|
4
|
+
import { IncomingMessage } from 'http';
|
|
5
|
+
import { type Readable } from 'stream';
|
|
6
|
+
import { RenderFunction, SSRServerContext } from '../type';
|
|
7
|
+
export declare function ssrCache(req: IncomingMessage, render: RenderFunction, ssrContext: SSRServerContext): Promise<string | Readable>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node/http" />
|
|
3
|
+
/// <reference types="dist/types/type" />
|
|
4
|
+
import { IncomingMessage } from 'http';
|
|
5
|
+
import { Readable } from 'stream';
|
|
6
|
+
import { CacheControl, Container } from '@modern-js/types';
|
|
7
|
+
import { RenderFunction, SSRServerContext } from '../type';
|
|
8
|
+
export declare class CacheManager {
|
|
9
|
+
private containter;
|
|
10
|
+
constructor(containter: Container<string, string>);
|
|
11
|
+
getCacheResult(req: IncomingMessage, cacheControl: CacheControl, render: RenderFunction, ssrContext: SSRServerContext): Promise<string | Readable>;
|
|
12
|
+
private processCache;
|
|
13
|
+
private computedKey;
|
|
14
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
/// <reference path="../type.d.ts" />
|
|
1
2
|
/// <reference types="node" />
|
|
2
3
|
/// <reference types="node" />
|
|
3
4
|
/// <reference types="node" />
|
|
5
|
+
/// <reference types="node/http" />
|
|
4
6
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
5
7
|
import type { ListenOptions } from 'net';
|
|
6
8
|
import { ModernServerOptions, ServerConstructor } from '../type';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/// <reference path="../type.d.ts" />
|
|
1
2
|
/// <reference types="node" />
|
|
2
3
|
/// <reference types="node" />
|
|
4
|
+
/// <reference types="node/http" />
|
|
3
5
|
import { IncomingMessage, ServerResponse, Server } from 'http';
|
|
4
6
|
import { Adapter, WebAdapter, APIServerStartInput, ServerOptions } from '@modern-js/server-core';
|
|
5
7
|
import { type ModernServerContext, type ServerRoute } from '@modern-js/types';
|
|
@@ -8,7 +10,6 @@ import { ModernServerOptions, NextFunction, ServerHookRunner, Metrics, Logger, M
|
|
|
8
10
|
import { RouteMatchManager, ModernRouteInterface, ModernRoute } from '../libs/route';
|
|
9
11
|
import { RenderHandler } from '../libs/render';
|
|
10
12
|
import { mergeExtension } from '../utils';
|
|
11
|
-
import * as reader from '../libs/render/reader';
|
|
12
13
|
type ModernServerAsyncHandler = (context: ModernServerContext, next: NextFunction) => Promise<void>;
|
|
13
14
|
export declare class ModernServer implements ModernServerInterface {
|
|
14
15
|
pwd: string;
|
|
@@ -22,7 +23,6 @@ export declare class ModernServer implements ModernServerInterface {
|
|
|
22
23
|
protected readonly logger: Logger;
|
|
23
24
|
protected readonly metrics: Metrics;
|
|
24
25
|
protected readonly runMode: string;
|
|
25
|
-
protected reader: typeof reader;
|
|
26
26
|
protected readonly proxyTarget: ModernServerOptions['proxyTarget'];
|
|
27
27
|
protected routeRenderHandler: RenderHandler;
|
|
28
28
|
protected readonly staticGenerate: boolean;
|
|
@@ -38,7 +38,6 @@ export declare class ModernServer implements ModernServerInterface {
|
|
|
38
38
|
getRequestHandler(): (req: IncomingMessage, res: ServerResponse, next?: () => void) => void | ServerResponse;
|
|
39
39
|
render(req: IncomingMessage, res: ServerResponse, url?: string): Promise<string | import("stream").Readable | null>;
|
|
40
40
|
createHTTPServer(handler: (req: IncomingMessage, res: ServerResponse, next?: () => void) => void): Promise<Server<typeof IncomingMessage, typeof ServerResponse>>;
|
|
41
|
-
protected initReader(): void;
|
|
42
41
|
protected onServerChange({ filepath }: {
|
|
43
42
|
filepath: string;
|
|
44
43
|
}): Promise<void>;
|
package/dist/types/type.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
+
/// <reference types="node/http" />
|
|
4
5
|
import { IncomingMessage, Server, ServerResponse } from 'http';
|
|
5
6
|
import { Readable } from 'stream';
|
|
6
7
|
import { serverManager, ServerOptions } from '@modern-js/server-core';
|
|
@@ -69,6 +70,7 @@ export interface ModernServerInterface {
|
|
|
69
70
|
getRequestHandler: () => (req: IncomingMessage, res: ServerResponse, next?: () => void) => void;
|
|
70
71
|
createHTTPServer: (handler: (req: IncomingMessage, res: ServerResponse, next?: () => void) => void) => Promise<Server>;
|
|
71
72
|
render: (req: IncomingMessage, res: ServerResponse, url?: string) => Promise<string | Readable | null>;
|
|
73
|
+
close?: () => Promise<void>;
|
|
72
74
|
}
|
|
73
75
|
export type ServerConstructor = (options: ModernServerOptions) => ModernServerInterface;
|
|
74
76
|
export type ModernServerHandler = (context: ModernServerContext, next: NextFunction) => Promise<void> | void;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.43.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -69,22 +69,20 @@
|
|
|
69
69
|
"fresh": "^0.5.2",
|
|
70
70
|
"http-proxy-middleware": "^2.0.4",
|
|
71
71
|
"ignore-styles": "^5.0.1",
|
|
72
|
-
"lru-cache": "^6.0.0",
|
|
73
72
|
"merge-deep": "^3.0.3",
|
|
74
73
|
"node-html-parser": "^6.1.5",
|
|
75
74
|
"path-to-regexp": "^6.2.0",
|
|
76
75
|
"serve-static": "^1.14.1",
|
|
77
|
-
"@modern-js/
|
|
78
|
-
"@modern-js/
|
|
79
|
-
"@modern-js/utils": "2.
|
|
80
|
-
"@modern-js/
|
|
76
|
+
"@modern-js/server-core": "2.43.0",
|
|
77
|
+
"@modern-js/utils": "2.43.0",
|
|
78
|
+
"@modern-js/runtime-utils": "2.43.0",
|
|
79
|
+
"@modern-js/plugin": "2.43.0"
|
|
81
80
|
},
|
|
82
81
|
"devDependencies": {
|
|
83
82
|
"@types/cookie": "0.5.1",
|
|
84
83
|
"@types/etag": "^1.8.1",
|
|
85
84
|
"@types/fresh": "^0.5.0",
|
|
86
85
|
"@types/jest": "^29",
|
|
87
|
-
"@types/lru-cache": "^5.1.1",
|
|
88
86
|
"@types/merge-deep": "^3.0.0",
|
|
89
87
|
"@types/node": "^14",
|
|
90
88
|
"@types/serve-static": "^1.13.10",
|
|
@@ -96,10 +94,9 @@
|
|
|
96
94
|
"portfinder": "^1.0.28",
|
|
97
95
|
"typescript": "^5",
|
|
98
96
|
"ws": "^8.13.0",
|
|
99
|
-
"@modern-js/
|
|
100
|
-
"@
|
|
101
|
-
"@scripts/build": "2.
|
|
102
|
-
"@scripts/jest-config": "2.42.2"
|
|
97
|
+
"@modern-js/types": "2.43.0",
|
|
98
|
+
"@scripts/jest-config": "2.43.0",
|
|
99
|
+
"@scripts/build": "2.43.0"
|
|
103
100
|
},
|
|
104
101
|
"sideEffects": false,
|
|
105
102
|
"publishConfig": {
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
var import_url = __toESM(require("url"));
|
|
25
|
-
var import_spr = require("../spr");
|
|
26
|
-
var import_util = require("../util");
|
|
27
|
-
describe("test spr util functions", () => {
|
|
28
|
-
it("should return value correctly", () => {
|
|
29
|
-
expect((0, import_util.connectFactor)("bar", "foo")).toBe("bar-foo");
|
|
30
|
-
expect((0, import_util.fname)(1)).toBe("f1");
|
|
31
|
-
expect((0, import_util.namespaceHash)("modern", "!@#$%^&")).toBe("modern/!@#$%^&");
|
|
32
|
-
});
|
|
33
|
-
it("should create or destroy instance correctly", () => {
|
|
34
|
-
const ins1 = (0, import_spr.createCache)();
|
|
35
|
-
const ins2 = (0, import_spr.createCache)();
|
|
36
|
-
expect(ins1 === ins2).toBe(true);
|
|
37
|
-
(0, import_spr.destroyCache)();
|
|
38
|
-
const ins3 = (0, import_spr.createCache)();
|
|
39
|
-
expect(ins1 === ins3).toBe(false);
|
|
40
|
-
expect(ins2 === ins3).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
it("should return function correctly", () => {
|
|
43
|
-
const urlParams = (() => new import_url.default.URLSearchParams())();
|
|
44
|
-
urlParams.set("name", "modern");
|
|
45
|
-
const getParam = (0, import_util.valueFactory)(urlParams);
|
|
46
|
-
expect(getParam("name")).toBe("modern");
|
|
47
|
-
const headers = {
|
|
48
|
-
age: "12345"
|
|
49
|
-
};
|
|
50
|
-
const getHeader = (0, import_util.valueFactory)(headers);
|
|
51
|
-
expect(getHeader("age")).toBe("12345");
|
|
52
|
-
});
|
|
53
|
-
it("should add target html content", () => {
|
|
54
|
-
const contentNoHead = "<div>123</div>";
|
|
55
|
-
const html = (0, import_util.cacheAddition)(contentNoHead, Math.random().toString());
|
|
56
|
-
expect(html).toBe(contentNoHead);
|
|
57
|
-
const contentWithHead = "<head></head><div>123</div>";
|
|
58
|
-
const hash = Math.random().toString();
|
|
59
|
-
const htmlWithHead = (0, import_util.cacheAddition)(contentWithHead, hash);
|
|
60
|
-
expect(htmlWithHead).toBe(`<head><meta name="x-moden-spr" content="${hash}"></head><div>123</div>`);
|
|
61
|
-
});
|
|
62
|
-
it("should only invoke func one time", async () => {
|
|
63
|
-
let index = 0;
|
|
64
|
-
const fn = (0, import_util.withCoalescedInvoke)(async () => new Promise((resolve) => {
|
|
65
|
-
setTimeout(() => {
|
|
66
|
-
index += 1;
|
|
67
|
-
resolve(index);
|
|
68
|
-
}, 500);
|
|
69
|
-
}));
|
|
70
|
-
const key = "test";
|
|
71
|
-
const [res1, res2] = await Promise.all([
|
|
72
|
-
fn(key, []),
|
|
73
|
-
fn(key, [])
|
|
74
|
-
]);
|
|
75
|
-
expect(res1.isOrigin && res2.isOrigin).toBe(false);
|
|
76
|
-
expect(res1.isOrigin || res2.isOrigin).toBe(true);
|
|
77
|
-
expect(res1.value).toBe(1);
|
|
78
|
-
expect(res2.value).toBe(1);
|
|
79
|
-
});
|
|
80
|
-
it("should invoke sync or async", async () => {
|
|
81
|
-
const foo = "";
|
|
82
|
-
const async = await (0, import_util.maybeSync)(() => new Promise((resolve) => {
|
|
83
|
-
setTimeout(() => {
|
|
84
|
-
resolve(foo);
|
|
85
|
-
}, 100);
|
|
86
|
-
}))(false);
|
|
87
|
-
expect(async).toBeUndefined();
|
|
88
|
-
const sync = await (0, import_util.maybeSync)(() => new Promise((resolve) => {
|
|
89
|
-
setTimeout(() => {
|
|
90
|
-
resolve(foo);
|
|
91
|
-
}, 100);
|
|
92
|
-
}))(true);
|
|
93
|
-
expect(sync).toBe(foo);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var import_spr = require("../spr");
|
|
3
|
-
var import_error_configuration = require("./error-configuration");
|
|
4
|
-
var import_cacheable = require("./cacheable");
|
|
5
|
-
var import_matched_cache = require("./matched-cache");
|
|
6
|
-
const createCacheConfig = (config = {}) => ({
|
|
7
|
-
excludes: null,
|
|
8
|
-
includes: null,
|
|
9
|
-
interval: 10,
|
|
10
|
-
staleLimit: false,
|
|
11
|
-
level: 0,
|
|
12
|
-
fallback: false,
|
|
13
|
-
matches: null,
|
|
14
|
-
...config
|
|
15
|
-
});
|
|
16
|
-
jest.setTimeout(6e4);
|
|
17
|
-
describe("cache", () => {
|
|
18
|
-
it("should cache correctly", async () => {
|
|
19
|
-
(0, import_spr.destroyCache)();
|
|
20
|
-
const cache = (0, import_spr.createCache)();
|
|
21
|
-
const context = {
|
|
22
|
-
entry: "",
|
|
23
|
-
pathname: "",
|
|
24
|
-
query: {},
|
|
25
|
-
headers: {}
|
|
26
|
-
};
|
|
27
|
-
const content = "hello";
|
|
28
|
-
const cacheConfig = createCacheConfig();
|
|
29
|
-
await cache.set(context, content, cacheConfig, true);
|
|
30
|
-
const cacheResult = await cache.get(context);
|
|
31
|
-
expect(cacheResult).not.toBe(null);
|
|
32
|
-
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe("hello");
|
|
33
|
-
});
|
|
34
|
-
it("should ignore cache set when cache config not exist", async () => {
|
|
35
|
-
(0, import_spr.destroyCache)();
|
|
36
|
-
(0, import_spr.destroyCache)();
|
|
37
|
-
const cache = (0, import_spr.createCache)();
|
|
38
|
-
const context = {
|
|
39
|
-
entry: "",
|
|
40
|
-
pathname: "",
|
|
41
|
-
query: {},
|
|
42
|
-
headers: {}
|
|
43
|
-
};
|
|
44
|
-
const content = "hello";
|
|
45
|
-
const shouldCache = await cache.set(context, content, null, true);
|
|
46
|
-
expect(shouldCache).toBe(false);
|
|
47
|
-
});
|
|
48
|
-
it("should calcual cache key error", async () => {
|
|
49
|
-
(0, import_spr.destroyCache)();
|
|
50
|
-
const cache = (0, import_spr.createCache)();
|
|
51
|
-
const content = "hello";
|
|
52
|
-
for (const config of import_error_configuration.errorConfiguration) {
|
|
53
|
-
const cacheConfig = createCacheConfig(config);
|
|
54
|
-
const tmpEntry = Math.random().toString();
|
|
55
|
-
const context = {
|
|
56
|
-
entry: tmpEntry,
|
|
57
|
-
pathname: "",
|
|
58
|
-
query: {},
|
|
59
|
-
headers: {}
|
|
60
|
-
};
|
|
61
|
-
const shouldCache = await cache.set(context, content, cacheConfig);
|
|
62
|
-
expect(shouldCache).toBe(false);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
it("should get nothing for diff requestKey", async () => {
|
|
66
|
-
(0, import_spr.destroyCache)();
|
|
67
|
-
const cache = (0, import_spr.createCache)();
|
|
68
|
-
const context = {
|
|
69
|
-
entry: "",
|
|
70
|
-
pathname: "",
|
|
71
|
-
query: {},
|
|
72
|
-
headers: {}
|
|
73
|
-
};
|
|
74
|
-
const content = "hello";
|
|
75
|
-
const cacheConfig = createCacheConfig({
|
|
76
|
-
level: 1,
|
|
77
|
-
includes: {
|
|
78
|
-
query: [
|
|
79
|
-
"name"
|
|
80
|
-
]
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
await cache.set(context, content, cacheConfig, true);
|
|
84
|
-
const context_req = {
|
|
85
|
-
entry: "",
|
|
86
|
-
pathname: "/home",
|
|
87
|
-
query: {},
|
|
88
|
-
headers: {}
|
|
89
|
-
};
|
|
90
|
-
const cacheResult = await cache.get(context_req);
|
|
91
|
-
expect(cacheResult).toBe(null);
|
|
92
|
-
});
|
|
93
|
-
it("should get nothing for diff cacheHash", async () => {
|
|
94
|
-
(0, import_spr.destroyCache)();
|
|
95
|
-
const cache = (0, import_spr.createCache)();
|
|
96
|
-
const context = {
|
|
97
|
-
entry: "",
|
|
98
|
-
pathname: "",
|
|
99
|
-
query: {},
|
|
100
|
-
headers: {}
|
|
101
|
-
};
|
|
102
|
-
const content = "hello";
|
|
103
|
-
const cacheConfig = createCacheConfig({
|
|
104
|
-
level: 1,
|
|
105
|
-
includes: {
|
|
106
|
-
query: [
|
|
107
|
-
"name"
|
|
108
|
-
]
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
await cache.set(context, content, cacheConfig, true);
|
|
112
|
-
const context_req = {
|
|
113
|
-
entry: "",
|
|
114
|
-
pathname: "",
|
|
115
|
-
query: {
|
|
116
|
-
name: "zll"
|
|
117
|
-
},
|
|
118
|
-
headers: {}
|
|
119
|
-
};
|
|
120
|
-
const cacheResult = await cache.get(context_req);
|
|
121
|
-
expect(cacheResult).toBe(null);
|
|
122
|
-
});
|
|
123
|
-
it("should get cache correctly", async () => {
|
|
124
|
-
(0, import_spr.destroyCache)();
|
|
125
|
-
const cache = (0, import_spr.createCache)();
|
|
126
|
-
for (const cacheable of import_cacheable.cacheabelAry) {
|
|
127
|
-
const context = {
|
|
128
|
-
entry: "",
|
|
129
|
-
pathname: cacheable.requestOpt.url,
|
|
130
|
-
query: cacheable.requestOpt.query || {},
|
|
131
|
-
headers: cacheable.requestOpt.headers || {}
|
|
132
|
-
};
|
|
133
|
-
const cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
|
|
134
|
-
await cache.set(context, cacheable.content, cacheConfig, true);
|
|
135
|
-
const cacheResult = await cache.get(context);
|
|
136
|
-
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(cacheable.content);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
it("should match cache correctly", async () => {
|
|
140
|
-
(0, import_spr.destroyCache)();
|
|
141
|
-
const cache = (0, import_spr.createCache)();
|
|
142
|
-
for (const cacheable of import_matched_cache.matchedCacheableAry) {
|
|
143
|
-
const [baseCacheable, matchOne, ...other] = cacheable;
|
|
144
|
-
const { requestOpt = {}, cacheConfig, content } = baseCacheable;
|
|
145
|
-
const context = {
|
|
146
|
-
entry: "",
|
|
147
|
-
pathname: requestOpt.url,
|
|
148
|
-
query: requestOpt.query,
|
|
149
|
-
headers: requestOpt.headers
|
|
150
|
-
};
|
|
151
|
-
await cache.set(context, content, createCacheConfig(cacheConfig), true);
|
|
152
|
-
const matchContext = {
|
|
153
|
-
entry: "",
|
|
154
|
-
pathname: matchOne.url,
|
|
155
|
-
query: matchOne.query,
|
|
156
|
-
headers: matchOne.headers
|
|
157
|
-
};
|
|
158
|
-
const cacheResult = await cache.get(matchContext);
|
|
159
|
-
expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(content);
|
|
160
|
-
for (const notMatch of other) {
|
|
161
|
-
const notMatchContext = {
|
|
162
|
-
entry: "",
|
|
163
|
-
pathname: notMatch.url,
|
|
164
|
-
query: notMatch.query,
|
|
165
|
-
headers: notMatch.headers
|
|
166
|
-
};
|
|
167
|
-
const nothing = await cache.get(notMatchContext);
|
|
168
|
-
expect(nothing).toBe(null);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
it("should stale cache correctly", async () => {
|
|
173
|
-
(0, import_spr.destroyCache)();
|
|
174
|
-
const cache = (0, import_spr.createCache)();
|
|
175
|
-
const context = {
|
|
176
|
-
entry: "",
|
|
177
|
-
pathname: "",
|
|
178
|
-
query: {},
|
|
179
|
-
headers: {}
|
|
180
|
-
};
|
|
181
|
-
const config = createCacheConfig({
|
|
182
|
-
interval: 5
|
|
183
|
-
});
|
|
184
|
-
const content = "hello";
|
|
185
|
-
const shouldCache = await cache.set(context, content, config, true);
|
|
186
|
-
expect(shouldCache.value).toBe(true);
|
|
187
|
-
const freshResult = await cache.get(context);
|
|
188
|
-
expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isStale).toBe(false);
|
|
189
|
-
await new Promise((resolve) => {
|
|
190
|
-
setTimeout(() => {
|
|
191
|
-
resolve();
|
|
192
|
-
}, 6e3);
|
|
193
|
-
});
|
|
194
|
-
const staleResult = await cache.get(context);
|
|
195
|
-
expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isStale).toBe(true);
|
|
196
|
-
});
|
|
197
|
-
it("should garbage cache correctly", async () => {
|
|
198
|
-
(0, import_spr.destroyCache)();
|
|
199
|
-
const cache = (0, import_spr.createCache)();
|
|
200
|
-
const context = {
|
|
201
|
-
entry: "",
|
|
202
|
-
pathname: "",
|
|
203
|
-
query: {},
|
|
204
|
-
headers: {}
|
|
205
|
-
};
|
|
206
|
-
const config = createCacheConfig({
|
|
207
|
-
interval: 3,
|
|
208
|
-
staleLimit: 8
|
|
209
|
-
});
|
|
210
|
-
const content = "hello";
|
|
211
|
-
const shouldCache = await cache.set(context, content, config, true);
|
|
212
|
-
expect(shouldCache.value).toBe(true);
|
|
213
|
-
const freshResult = await cache.get(context);
|
|
214
|
-
expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isGarbage).toBe(false);
|
|
215
|
-
await new Promise((resolve) => {
|
|
216
|
-
setTimeout(() => {
|
|
217
|
-
resolve();
|
|
218
|
-
}, 1e4);
|
|
219
|
-
});
|
|
220
|
-
const staleResult = await cache.get(context);
|
|
221
|
-
expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isGarbage).toBe(true);
|
|
222
|
-
});
|
|
223
|
-
});
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var cacheable_exports = {};
|
|
20
|
-
__export(cacheable_exports, {
|
|
21
|
-
cacheabelAry: () => cacheabelAry
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(cacheable_exports);
|
|
24
|
-
const cacheabelAry = [
|
|
25
|
-
{
|
|
26
|
-
requestOpt: {
|
|
27
|
-
url: "/"
|
|
28
|
-
},
|
|
29
|
-
cacheConfig: {},
|
|
30
|
-
content: "level0"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
requestOpt: {
|
|
34
|
-
url: "/level-one",
|
|
35
|
-
query: {
|
|
36
|
-
name: "modern"
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
cacheConfig: {
|
|
40
|
-
level: 1,
|
|
41
|
-
includes: {
|
|
42
|
-
query: [
|
|
43
|
-
"name"
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
content: "level1"
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
requestOpt: {
|
|
51
|
-
url: "/level-two",
|
|
52
|
-
headers: {
|
|
53
|
-
age: "18"
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
cacheConfig: {
|
|
57
|
-
level: 2,
|
|
58
|
-
includes: {
|
|
59
|
-
header: [
|
|
60
|
-
"age"
|
|
61
|
-
]
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
content: "level2"
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
requestOpt: {
|
|
68
|
-
url: "/level-three",
|
|
69
|
-
query: {
|
|
70
|
-
name: "modern"
|
|
71
|
-
},
|
|
72
|
-
headers: {
|
|
73
|
-
age: "18"
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
cacheConfig: {
|
|
77
|
-
level: 3,
|
|
78
|
-
includes: {
|
|
79
|
-
query: [
|
|
80
|
-
"name"
|
|
81
|
-
],
|
|
82
|
-
header: [
|
|
83
|
-
"age"
|
|
84
|
-
]
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
content: "level3"
|
|
88
|
-
}
|
|
89
|
-
];
|
|
90
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
-
0 && (module.exports = {
|
|
92
|
-
cacheabelAry
|
|
93
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var error_configuration_exports = {};
|
|
20
|
-
__export(error_configuration_exports, {
|
|
21
|
-
errorConfiguration: () => errorConfiguration
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(error_configuration_exports);
|
|
24
|
-
const errorConfiguration = [
|
|
25
|
-
{
|
|
26
|
-
level: 1
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
level: 1,
|
|
30
|
-
includes: {}
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
level: 1,
|
|
34
|
-
includes: {
|
|
35
|
-
query: []
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
level: 2,
|
|
40
|
-
includes: {}
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
level: 2,
|
|
44
|
-
includes: {
|
|
45
|
-
header: []
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
level: 3,
|
|
50
|
-
includes: {
|
|
51
|
-
header: []
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
level: 3,
|
|
56
|
-
includes: {
|
|
57
|
-
query: []
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
level: 3,
|
|
62
|
-
includes: {
|
|
63
|
-
query: [],
|
|
64
|
-
header: []
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
];
|
|
68
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
-
0 && (module.exports = {
|
|
70
|
-
errorConfiguration
|
|
71
|
-
});
|