@seip/bluebird-js 0.1.7 → 0.2.1
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/AGENTS.md +727 -620
- package/README.md +670 -607
- package/app/models/user.js +19 -0
- package/app/resources/html/home.html +137 -0
- package/app/resources/html/layouts/main.html +55 -0
- package/app/resources/html/notFound.html +14 -0
- package/app/resources/html/table.html +15 -0
- package/app/resources/html/terms.html +46 -0
- package/app/resources/index.html +27 -0
- package/app/resources/layouts/AppLayout.jsx +92 -0
- package/app/resources/main.jsx +18 -0
- package/app/resources/pages/Dashboard.jsx +93 -0
- package/app/resources/pages/Home.jsx +140 -0
- package/app/resources/pages/Login.jsx +35 -0
- package/app/resources/pages/NotFound.jsx +16 -0
- package/app/resources/pages/Register.jsx +55 -0
- package/app/resources/pages/TableDemo.jsx +85 -0
- package/app/resources/routes.jsx +59 -0
- package/app/resources/spa.js +73 -0
- package/app/resources/styles.css +9 -0
- package/app/routes/api.js +129 -50
- package/app/routes/auth.js +209 -0
- package/app/routes/web.js +89 -47
- package/core/ai.js +30 -10
- package/core/app.d.ts +2 -18
- package/core/app.js +987 -801
- package/core/auth.d.ts +2 -13
- package/core/auth.js +444 -326
- package/core/cli/build.js +37 -0
- package/core/cli/dev.js +155 -0
- package/core/cli/doctor.js +37 -2
- package/core/cli/export.js +191 -0
- package/core/cli/init.js +91 -322
- package/core/cli/nginx.js +1 -1
- package/core/cli/templates.js +139 -0
- package/core/cli/view.js +98 -161
- package/core/config.js +44 -2
- package/core/csrf.js +156 -24
- package/core/database.js +1184 -1131
- package/core/debug.js +1 -1
- package/core/html.js +8 -1
- package/core/index.d.ts +126 -310
- package/core/paths.js +55 -0
- package/core/ratelimit.js +10 -1
- package/core/react/client/api.js +239 -0
- package/core/react/client/auth.js +236 -0
- package/core/react/client/components.js +1321 -0
- package/core/react/client/datatable.js +595 -0
- package/core/react/client/i18n.js +440 -0
- package/core/react/client/index.d.ts +314 -0
- package/core/react/client/index.js +50 -0
- package/core/react/client/router.js +26 -0
- package/core/react/client/theme.css +512 -0
- package/core/render-cache.js +250 -212
- package/core/render.d.ts +25 -21
- package/core/render.js +738 -736
- package/core/router.d.ts +2 -3
- package/core/router.js +171 -171
- package/core/seo.js +10 -0
- package/core/spa.js +599 -0
- package/core/view-loader.js +155 -613
- package/core/vite-plugin.d.ts +18 -0
- package/core/vite-plugin.js +162 -0
- package/core/vite.js +250 -145
- package/index.js +22 -18
- package/jsconfig.json +5 -3
- package/package.json +114 -92
- package/production.md +8 -3
- package/public/js/bluebird.js +1886 -0
- package/templates/_auth/app/database.js +19 -0
- package/templates/_auth/app/models/user.js +22 -0
- package/templates/_auth/app/routes/auth-router.js +304 -0
- package/templates/_base/app/resources/html/layouts/main.html +55 -0
- package/templates/_base/app/resources/html/notFound.html +14 -0
- package/templates/_base/app/resources/index.html +27 -0
- package/templates/_base/app/resources/styles.css +9 -0
- package/templates/api/app/models/note.js +18 -0
- package/templates/api/app/routes/api.js +82 -0
- package/templates/api/app/routes/auth.js +11 -0
- package/templates/api/index.js +19 -0
- package/templates/api/template.json +13 -0
- package/templates/auth/app/mail.js +11 -0
- package/templates/auth/app/models/password_reset.js +18 -0
- package/templates/auth/app/resources/html/home.html +21 -0
- package/templates/auth/app/resources/html/partials/nav.html +2 -0
- package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
- package/templates/auth/app/resources/main.jsx +18 -0
- package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
- package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
- package/templates/auth/app/resources/pages/Login.jsx +36 -0
- package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
- package/templates/auth/app/resources/pages/Profile.jsx +99 -0
- package/templates/auth/app/resources/pages/Register.jsx +50 -0
- package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
- package/templates/auth/app/resources/routes.jsx +54 -0
- package/templates/auth/app/resources/spa.js +29 -0
- package/templates/auth/app/routes/api.js +17 -0
- package/templates/auth/app/routes/auth.js +13 -0
- package/templates/auth/app/routes/web.js +21 -0
- package/templates/auth/index.js +19 -0
- package/templates/auth/template.json +15 -0
- package/templates/blank/app/models/.gitkeep +0 -0
- package/templates/blank/app/resources/html/home.html +27 -0
- package/templates/blank/app/resources/html/partials/nav.html +1 -0
- package/templates/blank/app/resources/main.jsx +16 -0
- package/templates/blank/app/resources/pages/Home.jsx +42 -0
- package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
- package/templates/blank/app/resources/routes.jsx +15 -0
- package/templates/blank/app/resources/spa.js +24 -0
- package/templates/blank/app/routes/api.js +11 -0
- package/templates/blank/app/routes/web.js +21 -0
- package/templates/blank/index.js +13 -0
- package/templates/blank/template.json +12 -0
- package/templates/blog/app/lib/blog.js +149 -0
- package/templates/blog/app/models/post.js +22 -0
- package/templates/blog/app/resources/html/home.html +28 -0
- package/templates/blog/app/resources/html/not-found.html +5 -0
- package/templates/blog/app/resources/html/partials/nav.html +2 -0
- package/templates/blog/app/resources/html/partials/post-card.html +9 -0
- package/templates/blog/app/resources/html/post.html +8 -0
- package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
- package/templates/blog/app/resources/main.jsx +18 -0
- package/templates/blog/app/resources/pages/Login.jsx +31 -0
- package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
- package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
- package/templates/blog/app/resources/pages/Posts.jsx +83 -0
- package/templates/blog/app/resources/pages/Register.jsx +43 -0
- package/templates/blog/app/resources/routes.jsx +51 -0
- package/templates/blog/app/resources/spa.js +25 -0
- package/templates/blog/app/resources/styles.css +40 -0
- package/templates/blog/app/routes/api.js +77 -0
- package/templates/blog/app/routes/auth.js +10 -0
- package/templates/blog/app/routes/web.js +114 -0
- package/templates/blog/index.js +21 -0
- package/templates/blog/template.json +14 -0
- package/vite.config.js +11 -0
- package/app/views/components/Header.jsx +0 -42
- package/app/views/components/LiveCounter.jsx +0 -67
- package/app/views/layouts/main/view.jsx +0 -201
- package/app/views/legal/terms.html +0 -29
- package/app/views/pages/about.jsx +0 -98
- package/app/views/pages/dashboard.jsx +0 -278
- package/app/views/pages/index.jsx +0 -123
- package/app/views/pages/login.jsx +0 -141
- package/core/actions.d.ts +0 -4
- package/core/actions.js +0 -355
- package/core/jsx.d.ts +0 -38
- package/core/jsx.js +0 -1597
- package/core/vite.d.ts +0 -3
- package/public/js/bluebird-client.js +0 -3265
- package/public/js/tailwind.js +0 -8
package/core/render-cache.js
CHANGED
|
@@ -1,212 +1,250 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { getRedisClient } from "./cache.js";
|
|
4
|
-
import Config from "./config.js";
|
|
5
|
-
|
|
6
|
-
const props = Config.props();
|
|
7
|
-
const DEBUG = props.debug;
|
|
8
|
-
const PM2_INSTANCES = parseInt(process.env.PM2_INSTANCES || "1", 10);
|
|
9
|
-
const RENDER_CACHE_MAX = parseInt(process.env.RENDER_CACHE_MAX || "500", 10);
|
|
10
|
-
const RENDER_CACHE_TTL = parseInt(process.env.RENDER_CACHE_TTL || "300", 10);
|
|
11
|
-
|
|
12
|
-
const isMultiInstance = PM2_INSTANCES > 1;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Resolves the writable render file cache directory.
|
|
16
|
-
* @returns {string}
|
|
17
|
-
*/
|
|
18
|
-
function getFileCacheDir() {
|
|
19
|
-
return path.join(Config.userDataDir(), "app/cache");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let fileCacheEnabled = false;
|
|
23
|
-
|
|
24
|
-
if (!DEBUG) {
|
|
25
|
-
try {
|
|
26
|
-
const cacheDir = getFileCacheDir();
|
|
27
|
-
fs.mkdirSync(cacheDir, { recursive: true });
|
|
28
|
-
fs.accessSync(cacheDir, fs.constants.W_OK);
|
|
29
|
-
fileCacheEnabled = true;
|
|
30
|
-
} catch {
|
|
31
|
-
console.warn("[RENDER CACHE] app/cache/ is not writable — file cache disabled.");
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
*
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
lru.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { getRedisClient } from "./cache.js";
|
|
4
|
+
import Config from "./config.js";
|
|
5
|
+
|
|
6
|
+
const props = Config.props();
|
|
7
|
+
const DEBUG = props.debug;
|
|
8
|
+
const PM2_INSTANCES = parseInt(process.env.PM2_INSTANCES || "1", 10);
|
|
9
|
+
const RENDER_CACHE_MAX = parseInt(process.env.RENDER_CACHE_MAX || "500", 10);
|
|
10
|
+
const RENDER_CACHE_TTL = parseInt(process.env.RENDER_CACHE_TTL || "300", 10);
|
|
11
|
+
|
|
12
|
+
const isMultiInstance = PM2_INSTANCES > 1;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Resolves the writable render file cache directory.
|
|
16
|
+
* @returns {string}
|
|
17
|
+
*/
|
|
18
|
+
function getFileCacheDir() {
|
|
19
|
+
return path.join(Config.userDataDir(), "app/cache");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let fileCacheEnabled = false;
|
|
23
|
+
|
|
24
|
+
if (!DEBUG) {
|
|
25
|
+
try {
|
|
26
|
+
const cacheDir = getFileCacheDir();
|
|
27
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
28
|
+
fs.accessSync(cacheDir, fs.constants.W_OK);
|
|
29
|
+
fileCacheEnabled = true;
|
|
30
|
+
} catch {
|
|
31
|
+
console.warn("[RENDER CACHE] app/cache/ is not writable — file cache disabled.");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const lru = new Map();
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Evicts the oldest LRU entry when the cap is exceeded.
|
|
39
|
+
*/
|
|
40
|
+
function evictLru() {
|
|
41
|
+
if (lru.size >= RENDER_CACHE_MAX) {
|
|
42
|
+
const key = lru.keys().next().value;
|
|
43
|
+
if (key !== undefined) lru.delete(key);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns a safe filesystem key derived from the cache key string.
|
|
49
|
+
* @param {string} key
|
|
50
|
+
* @returns {string}
|
|
51
|
+
*/
|
|
52
|
+
function toCacheFileName(key) {
|
|
53
|
+
return key.replace(/[^a-z0-9_-]/gi, "_").substring(0, 200) + ".html";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Reads a cached string from the file cache, respecting custom or default TTL.
|
|
58
|
+
* @param {string} key
|
|
59
|
+
* @returns {{ value: string, expiry: number } | null}
|
|
60
|
+
*/
|
|
61
|
+
function readFileCache(key) {
|
|
62
|
+
if (!fileCacheEnabled) return null;
|
|
63
|
+
const file = path.join(getFileCacheDir(), toCacheFileName(key));
|
|
64
|
+
try {
|
|
65
|
+
const stats = fs.statSync(file);
|
|
66
|
+
const raw = fs.readFileSync(file, "utf8");
|
|
67
|
+
const match = raw.match(/^<!--bb-exp:(\d+)-->\n/);
|
|
68
|
+
if (match) {
|
|
69
|
+
const expiry = parseInt(match[1], 10);
|
|
70
|
+
if (Date.now() > expiry) {
|
|
71
|
+
try {
|
|
72
|
+
fs.unlinkSync(file);
|
|
73
|
+
} catch {}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
return { value: raw.slice(match[0].length), expiry };
|
|
77
|
+
}
|
|
78
|
+
const age = (Date.now() - stats.mtimeMs) / 1000;
|
|
79
|
+
if (age > RENDER_CACHE_TTL) return null;
|
|
80
|
+
return { value: raw, expiry: stats.mtimeMs + RENDER_CACHE_TTL * 1000 };
|
|
81
|
+
} catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Writes a string to the file cache with embedded expiration metadata.
|
|
88
|
+
* @param {string} key
|
|
89
|
+
* @param {string} value
|
|
90
|
+
* @param {number} [expiry]
|
|
91
|
+
*/
|
|
92
|
+
function writeFileCache(key, value, expiry) {
|
|
93
|
+
if (!fileCacheEnabled) return;
|
|
94
|
+
try {
|
|
95
|
+
const file = path.join(getFileCacheDir(), toCacheFileName(key));
|
|
96
|
+
const exp = expiry || Date.now() + RENDER_CACHE_TTL * 1000;
|
|
97
|
+
fs.writeFileSync(file, `<!--bb-exp:${exp}-->\n${value}`, "utf8");
|
|
98
|
+
} catch {}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Multi-layer rendering cache manager.
|
|
103
|
+
* Provides L1 (In-Memory LRU), L2 (Redis), and L3 (File) caching layers.
|
|
104
|
+
*/
|
|
105
|
+
export class RenderCache {
|
|
106
|
+
/**
|
|
107
|
+
* Looks up a cached HTML string across memory, Redis, and file cache.
|
|
108
|
+
* @param {string} key - Cache key.
|
|
109
|
+
* @returns {Promise<string|null>}
|
|
110
|
+
*/
|
|
111
|
+
static async lookup(key) {
|
|
112
|
+
const entry = lru.get(key);
|
|
113
|
+
if (entry && entry.expiry > Date.now()) {
|
|
114
|
+
lru.delete(key);
|
|
115
|
+
lru.set(key, entry);
|
|
116
|
+
return entry.value;
|
|
117
|
+
}
|
|
118
|
+
if (entry) lru.delete(key);
|
|
119
|
+
|
|
120
|
+
if (isMultiInstance) {
|
|
121
|
+
const redis = getRedisClient();
|
|
122
|
+
if (redis) {
|
|
123
|
+
try {
|
|
124
|
+
const val = await redis.get(`render:${key}`);
|
|
125
|
+
if (val) {
|
|
126
|
+
evictLru();
|
|
127
|
+
lru.set(key, { value: val, expiry: Date.now() + RENDER_CACHE_TTL * 1000 });
|
|
128
|
+
return val;
|
|
129
|
+
}
|
|
130
|
+
} catch {}
|
|
131
|
+
} else {
|
|
132
|
+
const fromFile = readFileCache(key);
|
|
133
|
+
if (fromFile) {
|
|
134
|
+
evictLru();
|
|
135
|
+
lru.set(key, fromFile);
|
|
136
|
+
return fromFile.value;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Stores a rendered string in all active cache layers.
|
|
146
|
+
* @param {string} key - Cache key.
|
|
147
|
+
* @param {string} value - HTML string to store.
|
|
148
|
+
* @param {number} [ttl=RENDER_CACHE_TTL] - Time to live in seconds.
|
|
149
|
+
* @returns {Promise<void>}
|
|
150
|
+
*/
|
|
151
|
+
static async store(key, value, ttl = RENDER_CACHE_TTL) {
|
|
152
|
+
const expiry = Date.now() + ttl * 1000;
|
|
153
|
+
evictLru();
|
|
154
|
+
lru.set(key, { value, expiry });
|
|
155
|
+
|
|
156
|
+
if (isMultiInstance) {
|
|
157
|
+
const redis = getRedisClient();
|
|
158
|
+
if (redis) {
|
|
159
|
+
try {
|
|
160
|
+
await redis.set(`render:${key}`, value, { EX: ttl });
|
|
161
|
+
return;
|
|
162
|
+
} catch {}
|
|
163
|
+
}
|
|
164
|
+
writeFileCache(key, value, expiry);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Clears in-memory LRU cache.
|
|
170
|
+
*/
|
|
171
|
+
static clearMemory() {
|
|
172
|
+
lru.clear();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Invalidates one or more keys across all cache layers, including query/URL variants.
|
|
177
|
+
* @param {string|string[]} [keys]
|
|
178
|
+
* @returns {Promise<void>}
|
|
179
|
+
*/
|
|
180
|
+
static async invalidate(keys) {
|
|
181
|
+
if (!keys) {
|
|
182
|
+
lru.clear();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const list = Array.isArray(keys) ? keys : [keys];
|
|
187
|
+
const redis = getRedisClient();
|
|
188
|
+
const cacheDir = fileCacheEnabled ? getFileCacheDir() : null;
|
|
189
|
+
let cacheFiles = null;
|
|
190
|
+
if (cacheDir) {
|
|
191
|
+
try {
|
|
192
|
+
cacheFiles = fs.readdirSync(cacheDir);
|
|
193
|
+
} catch {
|
|
194
|
+
cacheFiles = [];
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
for (const key of list) {
|
|
199
|
+
const prefixes = [
|
|
200
|
+
key,
|
|
201
|
+
`view:${key}`,
|
|
202
|
+
`route:${key}`,
|
|
203
|
+
`spa:${key}`,
|
|
204
|
+
`fragment:${key}`,
|
|
205
|
+
];
|
|
206
|
+
const matches = (existingKey) =>
|
|
207
|
+
prefixes.some(
|
|
208
|
+
(p) =>
|
|
209
|
+
existingKey === p ||
|
|
210
|
+
existingKey.startsWith(`${p}:`) ||
|
|
211
|
+
existingKey.startsWith(`${p}?`) ||
|
|
212
|
+
existingKey.startsWith(`${p}#`)
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
for (const existingKey of Array.from(lru.keys())) {
|
|
216
|
+
if (matches(existingKey)) lru.delete(existingKey);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (redis) {
|
|
220
|
+
try {
|
|
221
|
+
for (const p of prefixes) {
|
|
222
|
+
await redis.del(`render:${p}`);
|
|
223
|
+
if (typeof redis.scanIterator === "function") {
|
|
224
|
+
for (const sep of [":", "?", "#"]) {
|
|
225
|
+
const pattern = `render:${p.replace(/[*?[\]\\]/g, "\\$&")}${sep === "?" ? "\\?" : sep}*`;
|
|
226
|
+
for await (const found of redis.scanIterator({ MATCH: pattern, COUNT: 200 })) {
|
|
227
|
+
const batch = Array.isArray(found) ? found : [found];
|
|
228
|
+
if (batch.length > 0) await redis.del(batch);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
} catch {}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (cacheDir && cacheFiles) {
|
|
237
|
+
const fileStems = prefixes.map((p) => toCacheFileName(p).slice(0, -".html".length));
|
|
238
|
+
for (const file of cacheFiles) {
|
|
239
|
+
const stem = file.slice(0, -".html".length);
|
|
240
|
+
if (!fileStems.some((f) => stem === f || stem.startsWith(`${f}_`))) continue;
|
|
241
|
+
try {
|
|
242
|
+
fs.unlinkSync(path.join(cacheDir, file));
|
|
243
|
+
} catch {}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export default RenderCache;
|
package/core/render.d.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import type { NextFunction, Request, RequestHandler, Response } from "express";
|
|
2
|
+
|
|
3
|
+
export interface RenderOptions {
|
|
4
|
+
layout?: string | false;
|
|
5
|
+
cache?: number;
|
|
6
|
+
ttl?: number;
|
|
7
|
+
query?: string[];
|
|
8
|
+
cacheQuery?: string[];
|
|
9
|
+
raw?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class Render {
|
|
13
|
+
static renderString(template: string, data?: Record<string, any>, ctx?: Record<string, any>): Promise<string>;
|
|
14
|
+
static component(viewName: string, data?: Record<string, any>, ctx?: Record<string, any>): Promise<string>;
|
|
15
|
+
static html(res: Response, viewName: string, data?: Record<string, any>, options?: number | RenderOptions): Promise<any>;
|
|
16
|
+
static send(res: Response, viewName: string, data?: Record<string, any>, ttlOrOptions?: number | RenderOptions): Promise<any>;
|
|
17
|
+
static partial(res: Response, partialName: string, data?: Record<string, any>): Promise<any>;
|
|
18
|
+
static view(viewName: string, dataOrFn?: Record<string, any> | ((req: Request, res: Response) => any), options?: number | RenderOptions): RequestHandler;
|
|
19
|
+
static cache(seconds?: number, options?: { allowAuthenticated?: boolean; query?: string[] }): (req: Request, res: Response, next: NextFunction) => Promise<any>;
|
|
20
|
+
static redirect(req: Request, res: Response, url: string, status?: number): void;
|
|
21
|
+
static clearTemplateCache(): void;
|
|
22
|
+
static invalidate(keys?: string | string[]): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default Render;
|