jcc-express-mvc 1.9.2 → 1.9.3
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/lib/Auth/AuthMiddleware.d.ts.map +1 -1
- package/lib/Auth/AuthMiddleware.js +13 -6
- package/lib/Cache/index.d.ts +2 -0
- package/lib/Cache/index.d.ts.map +1 -1
- package/lib/Cache/index.js +101 -6
- package/lib/Command-Line/NodeArtisanCommand.d.ts +5 -0
- package/lib/Command-Line/NodeArtisanCommand.d.ts.map +1 -1
- package/lib/Command-Line/NodeArtisanCommand.js +52 -1
- package/lib/Command-Line/WatchCommand.d.ts +12 -2
- package/lib/Command-Line/WatchCommand.d.ts.map +1 -1
- package/lib/Command-Line/WatchCommand.js +186 -45
- package/lib/Error/AppErrorHandler.d.ts.map +1 -1
- package/lib/Error/AppErrorHandler.js +4 -0
- package/lib/Error/ModelExceptions/ModelTokenError.d.ts +4 -0
- package/lib/Error/ModelExceptions/ModelTokenError.d.ts.map +1 -0
- package/lib/Error/ModelExceptions/ModelTokenError.js +10 -0
- package/lib/Http/index.d.ts +3 -0
- package/lib/Http/index.d.ts.map +1 -1
- package/lib/Http/index.js +46 -10
- package/lib/Jcc-eloquent/lib/Model.d.ts +2 -0
- package/lib/Jcc-eloquent/lib/Model.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Model.js +13 -1
- package/lib/Mail/Manager.d.ts +2 -0
- package/lib/Mail/Manager.d.ts.map +1 -1
- package/lib/Mail/Manager.js +39 -2
- package/lib/Monitor/Collectors/CacheCollector.d.ts +2 -4
- package/lib/Monitor/Collectors/CacheCollector.d.ts.map +1 -1
- package/lib/Monitor/Collectors/CacheCollector.js +4 -63
- package/lib/Monitor/Collectors/CommandCollector.d.ts +3 -4
- package/lib/Monitor/Collectors/CommandCollector.d.ts.map +1 -1
- package/lib/Monitor/Collectors/CommandCollector.js +3 -4
- package/lib/Monitor/Collectors/DatabaseCollector.d.ts +2 -0
- package/lib/Monitor/Collectors/DatabaseCollector.d.ts.map +1 -1
- package/lib/Monitor/Collectors/DatabaseCollector.js +8 -1
- package/lib/Monitor/Collectors/MailCollector.d.ts +2 -4
- package/lib/Monitor/Collectors/MailCollector.d.ts.map +1 -1
- package/lib/Monitor/Collectors/MailCollector.js +5 -58
- package/lib/Monitor/Collectors/OutgoingRequestCollector.d.ts +3 -4
- package/lib/Monitor/Collectors/OutgoingRequestCollector.d.ts.map +1 -1
- package/lib/Monitor/Collectors/OutgoingRequestCollector.js +6 -8
- package/lib/Monitor/Collectors/ScheduleCollector.d.ts +2 -3
- package/lib/Monitor/Collectors/ScheduleCollector.d.ts.map +1 -1
- package/lib/Monitor/Collectors/ScheduleCollector.js +2 -3
- package/lib/Monitor/Controllers/MonitorController.d.ts +1 -0
- package/lib/Monitor/Controllers/MonitorController.d.ts.map +1 -1
- package/lib/Monitor/Controllers/MonitorController.js +15 -8
- package/lib/Monitor/MonitorManager.d.ts +10 -1
- package/lib/Monitor/MonitorManager.d.ts.map +1 -1
- package/lib/Monitor/MonitorManager.js +39 -1
- package/lib/Monitor/MonitorServiceProvider.d.ts.map +1 -1
- package/lib/Monitor/MonitorServiceProvider.js +3 -1
- package/lib/Monitor/index.d.ts +1 -0
- package/lib/Monitor/index.d.ts.map +1 -1
- package/lib/Monitor/index.js +1 -0
- package/lib/Monitor/types.d.ts +3 -1
- package/lib/Monitor/types.d.ts.map +1 -1
- package/lib/Monitor/types.js +13 -2
- package/lib/Queue/Queue.d.ts +4 -0
- package/lib/Queue/Queue.d.ts.map +1 -1
- package/lib/Queue/Queue.js +55 -0
- package/lib/Schedule/Scheduler.d.ts +2 -0
- package/lib/Schedule/Scheduler.d.ts.map +1 -1
- package/lib/Schedule/Scheduler.js +28 -1
- package/lib/Server/index.d.ts +2 -0
- package/lib/Server/index.d.ts.map +1 -1
- package/lib/Server/index.js +12 -1
- package/lib/Templating-engine/engineHelper.d.ts +2 -2
- package/lib/Templating-engine/engineHelper.d.ts.map +1 -1
- package/lib/Templating-engine/engineHelper.js +5 -2
- package/package.json +1 -1
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.WatchCommand = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const net_1 = __importDefault(require("net"));
|
|
9
10
|
const child_process_1 = require("child_process");
|
|
10
|
-
const readline_1 = __importDefault(require("readline"));
|
|
11
11
|
const colors_1 = __importDefault(require("colors"));
|
|
12
12
|
const app_root_path_1 = __importDefault(require("app-root-path"));
|
|
13
13
|
class WatchCommand {
|
|
@@ -31,6 +31,7 @@ class WatchCommand {
|
|
|
31
31
|
"config",
|
|
32
32
|
"database",
|
|
33
33
|
"jcc-express-mvc",
|
|
34
|
+
"public",
|
|
34
35
|
"resources",
|
|
35
36
|
"routes",
|
|
36
37
|
"route",
|
|
@@ -40,6 +41,9 @@ class WatchCommand {
|
|
|
40
41
|
this.watchers = [];
|
|
41
42
|
this.child = null;
|
|
42
43
|
this.restartTimer = null;
|
|
44
|
+
this.hotPollTimer = null;
|
|
45
|
+
this.hotFileActive = false;
|
|
46
|
+
this.hotWasPresent = false;
|
|
43
47
|
this.isRestarting = false;
|
|
44
48
|
this.suppressNextExitLog = false;
|
|
45
49
|
this.pendingChanges = new Set();
|
|
@@ -55,8 +59,8 @@ class WatchCommand {
|
|
|
55
59
|
this.entryFile = entryFile;
|
|
56
60
|
this.installSignalHandlers();
|
|
57
61
|
this.refreshWatchers();
|
|
58
|
-
this.
|
|
59
|
-
this.startServer(resolvedEntry);
|
|
62
|
+
this.renderInitialHeader(path_1.default.relative(this.rootPath, resolvedEntry));
|
|
63
|
+
this.startServer(resolvedEntry, { silent: false });
|
|
60
64
|
}
|
|
61
65
|
refreshWatchers() {
|
|
62
66
|
this.closeWatchers();
|
|
@@ -107,6 +111,66 @@ class WatchCommand {
|
|
|
107
111
|
catch {
|
|
108
112
|
// Ignore root watcher failures
|
|
109
113
|
}
|
|
114
|
+
this.watchPublicHot();
|
|
115
|
+
}
|
|
116
|
+
/** Vite writes public/hot when the dev server starts — watch it reliably. */
|
|
117
|
+
watchPublicHot() {
|
|
118
|
+
const publicDir = path_1.default.join(this.rootPath, "public");
|
|
119
|
+
const hotPath = path_1.default.join(publicDir, "hot");
|
|
120
|
+
if (!fs_1.default.existsSync(publicDir))
|
|
121
|
+
return;
|
|
122
|
+
this.hotWasPresent = fs_1.default.existsSync(hotPath);
|
|
123
|
+
try {
|
|
124
|
+
const dirWatcher = fs_1.default.watch(publicDir, (_eventType, filename) => {
|
|
125
|
+
const name = filename?.toString().toLowerCase();
|
|
126
|
+
if (!name || name === "hot") {
|
|
127
|
+
this.onPublicHotChanged(hotPath);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
this.watchers.push(dirWatcher);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
/* unreadable */
|
|
134
|
+
}
|
|
135
|
+
this.syncHotFileWatcher(hotPath);
|
|
136
|
+
}
|
|
137
|
+
syncHotFileWatcher(hotPath) {
|
|
138
|
+
if (this.hotPollTimer) {
|
|
139
|
+
clearInterval(this.hotPollTimer);
|
|
140
|
+
this.hotPollTimer = null;
|
|
141
|
+
}
|
|
142
|
+
if (this.hotFileActive) {
|
|
143
|
+
try {
|
|
144
|
+
fs_1.default.unwatchFile(hotPath);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
/* already unwatched */
|
|
148
|
+
}
|
|
149
|
+
this.hotFileActive = false;
|
|
150
|
+
}
|
|
151
|
+
if (fs_1.default.existsSync(hotPath)) {
|
|
152
|
+
this.hotWasPresent = true;
|
|
153
|
+
this.hotFileActive = true;
|
|
154
|
+
fs_1.default.watchFile(hotPath, { interval: 200 }, () => {
|
|
155
|
+
this.onPublicHotChanged(hotPath);
|
|
156
|
+
});
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
this.hotWasPresent = false;
|
|
160
|
+
// Vite may create public/hot after serve starts — poll until it appears.
|
|
161
|
+
this.hotPollTimer = setInterval(() => {
|
|
162
|
+
if (!fs_1.default.existsSync(hotPath))
|
|
163
|
+
return;
|
|
164
|
+
this.onPublicHotChanged(hotPath);
|
|
165
|
+
this.syncHotFileWatcher(hotPath);
|
|
166
|
+
}, 500);
|
|
167
|
+
}
|
|
168
|
+
onPublicHotChanged(hotPath) {
|
|
169
|
+
const exists = fs_1.default.existsSync(hotPath);
|
|
170
|
+
if (exists === this.hotWasPresent)
|
|
171
|
+
return;
|
|
172
|
+
this.hotWasPresent = exists;
|
|
173
|
+
this.onFileChanged(hotPath);
|
|
110
174
|
}
|
|
111
175
|
collectWatchDirectories() {
|
|
112
176
|
const dirs = [];
|
|
@@ -177,25 +241,42 @@ class WatchCommand {
|
|
|
177
241
|
clearTimeout(this.restartTimer);
|
|
178
242
|
this.restartTimer = setTimeout(() => {
|
|
179
243
|
this.restartTimer = null;
|
|
180
|
-
this.restartServer();
|
|
244
|
+
void this.restartServer();
|
|
181
245
|
}, 250);
|
|
182
246
|
}
|
|
183
247
|
shouldIgnore(filePath) {
|
|
184
248
|
const relativePath = path_1.default.relative(this.rootPath, filePath);
|
|
185
249
|
const normalizedPath = relativePath.split(path_1.default.sep).join("/").toLowerCase();
|
|
250
|
+
if (normalizedPath === "public/hot" || normalizedPath === "public") {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
186
253
|
if (normalizedPath.startsWith("storage/session") ||
|
|
187
254
|
normalizedPath.startsWith("storage/sessions") ||
|
|
188
|
-
normalizedPath.startsWith("storage/framework/sessions")
|
|
255
|
+
normalizedPath.startsWith("storage/framework/sessions") ||
|
|
256
|
+
(normalizedPath.startsWith("public/") && normalizedPath !== "public/hot") ||
|
|
257
|
+
normalizedPath.startsWith("resources/js/") ||
|
|
258
|
+
normalizedPath.startsWith("resources/css/") ||
|
|
259
|
+
normalizedPath.startsWith("resources/sass/")) {
|
|
189
260
|
return true;
|
|
190
261
|
}
|
|
191
262
|
const normalized = filePath.split(path_1.default.sep);
|
|
192
263
|
return normalized.some((part) => this.ignoredDirs.has(part));
|
|
193
264
|
}
|
|
194
|
-
startServer(entryFile) {
|
|
265
|
+
startServer(entryFile, options) {
|
|
266
|
+
const env = {
|
|
267
|
+
...process.env,
|
|
268
|
+
JCC_SERVE_STRICT_PORT: "1",
|
|
269
|
+
};
|
|
270
|
+
if (options.silent) {
|
|
271
|
+
env.JCC_SERVE_SILENT_RELOAD = "1";
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
delete env.JCC_SERVE_SILENT_RELOAD;
|
|
275
|
+
}
|
|
195
276
|
this.child = (0, child_process_1.spawn)("bun", [entryFile], {
|
|
196
277
|
cwd: this.rootPath,
|
|
197
278
|
stdio: "inherit",
|
|
198
|
-
env
|
|
279
|
+
env,
|
|
199
280
|
});
|
|
200
281
|
this.child.on("exit", (code, signal) => {
|
|
201
282
|
if (this.suppressNextExitLog) {
|
|
@@ -208,73 +289,133 @@ class WatchCommand {
|
|
|
208
289
|
}
|
|
209
290
|
});
|
|
210
291
|
}
|
|
211
|
-
restartServer() {
|
|
292
|
+
async restartServer() {
|
|
212
293
|
const now = Date.now();
|
|
213
294
|
const elapsed = now - this.lastRestartAt;
|
|
214
295
|
if (elapsed < this.minRestartGapMs) {
|
|
215
296
|
this.restartTimer = setTimeout(() => {
|
|
216
297
|
this.restartTimer = null;
|
|
217
|
-
this.restartServer();
|
|
298
|
+
void this.restartServer();
|
|
218
299
|
}, this.minRestartGapMs - elapsed);
|
|
219
300
|
return;
|
|
220
301
|
}
|
|
221
|
-
const changedPreview = Array.from(this.pendingChanges).slice(0, 3);
|
|
222
|
-
const extraCount = this.pendingChanges.size - changedPreview.length;
|
|
223
302
|
this.pendingChanges.clear();
|
|
224
|
-
const changedText = changedPreview.length === 0
|
|
225
|
-
? "unknown"
|
|
226
|
-
: `${changedPreview.join(", ")}${extraCount > 0 ? ` (+${extraCount} more)` : ""}`;
|
|
227
303
|
this.isRestarting = true;
|
|
228
304
|
this.lastRestartAt = Date.now();
|
|
305
|
+
await this.stopServer();
|
|
306
|
+
await this.waitForPortFree(this.getConfiguredPort());
|
|
307
|
+
this.startServer(path_1.default.resolve(this.rootPath, this.entryFile), {
|
|
308
|
+
silent: true,
|
|
309
|
+
});
|
|
229
310
|
this.refreshWatchers();
|
|
230
|
-
this.stopServer();
|
|
231
|
-
this.renderServeHeader(this.entryFile, changedText);
|
|
232
|
-
this.startServer(path_1.default.resolve(this.rootPath, this.entryFile));
|
|
233
311
|
this.isRestarting = false;
|
|
234
312
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
313
|
+
getConfiguredPort() {
|
|
314
|
+
const raw = process.env.PORT ?? "5500";
|
|
315
|
+
const port = Number.parseInt(String(raw), 10);
|
|
316
|
+
return Number.isFinite(port) && port > 0 ? port : 5500;
|
|
317
|
+
}
|
|
318
|
+
isPortFree(port) {
|
|
319
|
+
return new Promise((resolve) => {
|
|
320
|
+
const tester = net_1.default.createServer();
|
|
321
|
+
tester.once("error", () => resolve(false));
|
|
322
|
+
tester.once("listening", () => {
|
|
323
|
+
tester.close(() => resolve(true));
|
|
324
|
+
});
|
|
325
|
+
tester.listen(port, "127.0.0.1");
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
async waitForPortFree(port, timeoutMs = 5000) {
|
|
329
|
+
const deadline = Date.now() + timeoutMs;
|
|
330
|
+
while (Date.now() < deadline) {
|
|
331
|
+
if (await this.isPortFree(port))
|
|
332
|
+
return;
|
|
333
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
241
334
|
}
|
|
242
|
-
|
|
243
|
-
|
|
335
|
+
}
|
|
336
|
+
stopServer() {
|
|
337
|
+
const child = this.child;
|
|
338
|
+
if (!child?.pid) {
|
|
339
|
+
this.child = null;
|
|
340
|
+
return Promise.resolve();
|
|
244
341
|
}
|
|
245
|
-
this.
|
|
342
|
+
this.suppressNextExitLog = true;
|
|
343
|
+
return new Promise((resolve) => {
|
|
344
|
+
const forceTimer = setTimeout(() => {
|
|
345
|
+
try {
|
|
346
|
+
if (process.platform === "win32") {
|
|
347
|
+
child.kill();
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
child.kill("SIGKILL");
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
catch {
|
|
354
|
+
/* already dead */
|
|
355
|
+
}
|
|
356
|
+
this.child = null;
|
|
357
|
+
setTimeout(resolve, 150);
|
|
358
|
+
}, 3000);
|
|
359
|
+
child.once("exit", () => {
|
|
360
|
+
clearTimeout(forceTimer);
|
|
361
|
+
this.child = null;
|
|
362
|
+
setTimeout(resolve, 150);
|
|
363
|
+
});
|
|
364
|
+
try {
|
|
365
|
+
if (process.platform === "win32") {
|
|
366
|
+
child.kill();
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
child.kill("SIGTERM");
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
catch {
|
|
373
|
+
clearTimeout(forceTimer);
|
|
374
|
+
this.child = null;
|
|
375
|
+
this.suppressNextExitLog = false;
|
|
376
|
+
resolve();
|
|
377
|
+
}
|
|
378
|
+
});
|
|
246
379
|
}
|
|
247
380
|
closeWatchers() {
|
|
248
381
|
for (const watcher of this.watchers)
|
|
249
382
|
watcher.close();
|
|
250
383
|
this.watchers = [];
|
|
384
|
+
this.teardownHotWatcher();
|
|
385
|
+
}
|
|
386
|
+
teardownHotWatcher() {
|
|
387
|
+
const hotPath = path_1.default.join(this.rootPath, "public", "hot");
|
|
388
|
+
if (this.hotPollTimer) {
|
|
389
|
+
clearInterval(this.hotPollTimer);
|
|
390
|
+
this.hotPollTimer = null;
|
|
391
|
+
}
|
|
392
|
+
if (this.hotFileActive) {
|
|
393
|
+
try {
|
|
394
|
+
fs_1.default.unwatchFile(hotPath);
|
|
395
|
+
}
|
|
396
|
+
catch {
|
|
397
|
+
/* already unwatched */
|
|
398
|
+
}
|
|
399
|
+
this.hotFileActive = false;
|
|
400
|
+
}
|
|
251
401
|
}
|
|
252
402
|
installSignalHandlers() {
|
|
253
|
-
const shutdown = () => {
|
|
403
|
+
const shutdown = async () => {
|
|
254
404
|
this.closeWatchers();
|
|
255
|
-
this.stopServer();
|
|
405
|
+
await this.stopServer();
|
|
256
406
|
process.exit(0);
|
|
257
407
|
};
|
|
258
|
-
process.once("SIGINT",
|
|
259
|
-
|
|
408
|
+
process.once("SIGINT", () => {
|
|
409
|
+
void shutdown();
|
|
410
|
+
});
|
|
411
|
+
process.once("SIGTERM", () => {
|
|
412
|
+
void shutdown();
|
|
413
|
+
});
|
|
260
414
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (changedText) {
|
|
264
|
-
console.log(colors_1.default.gray(`↻ Change detected: ${changedText}`));
|
|
265
|
-
console.log();
|
|
266
|
-
}
|
|
267
|
-
console.log(colors_1.default.green("👀 Watching project for changes..."));
|
|
415
|
+
renderInitialHeader(entryLabel) {
|
|
416
|
+
console.log(colors_1.default.green("👀 Serve started (file changes reload silently)."));
|
|
268
417
|
console.log(colors_1.default.cyan(`→ Entry: ${entryLabel}`));
|
|
269
418
|
console.log();
|
|
270
419
|
}
|
|
271
|
-
clearTerminal() {
|
|
272
|
-
if (process.stdout.isTTY) {
|
|
273
|
-
readline_1.default.cursorTo(process.stdout, 0, 0);
|
|
274
|
-
readline_1.default.clearScreenDown(process.stdout);
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
console.clear();
|
|
278
|
-
}
|
|
279
420
|
}
|
|
280
421
|
exports.WatchCommand = WatchCommand;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppErrorHandler.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Error/AppErrorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"AppErrorHandler.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Error/AppErrorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAUtC,qBAAa,eAAe;IAC1B,OAAO,CAAC,GAAG,CAAc;gBACb,GAAG,EAAE,WAAW;IAI5B;;;;OAIG;IACI,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI5B,kBAAkB;IAMzB,OAAO,CAAC,gBAAgB;IAyBxB,OAAO,CAAC,GAAG,EAAE,GAAG;CA4CjB"}
|
|
@@ -11,6 +11,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
11
11
|
const ValidationException_v2_1 = require("./ValidationException-v2");
|
|
12
12
|
const AuthorizationException_1 = require("./AuthorizationException");
|
|
13
13
|
const MissMatchTokenException_1 = require("./MissMatchTokenException");
|
|
14
|
+
const ModelTokenError_1 = require("./ModelExceptions/ModelTokenError");
|
|
14
15
|
class AppErrorHandler {
|
|
15
16
|
constructor(app) {
|
|
16
17
|
this.app = app;
|
|
@@ -54,6 +55,9 @@ class AppErrorHandler {
|
|
|
54
55
|
}
|
|
55
56
|
return res.with("Forbidden", "error").status(403).redirectBack();
|
|
56
57
|
}
|
|
58
|
+
if (err instanceof ModelTokenError_1.ModelTokenError) {
|
|
59
|
+
return res.status(500).json({ error: err.message });
|
|
60
|
+
}
|
|
57
61
|
//
|
|
58
62
|
if (err.type === error_1.VALIDATION_ERROR || err instanceof ValidationException_v2_1.ValidationException) {
|
|
59
63
|
//
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelTokenError.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Error/ModelExceptions/ModelTokenError.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelTokenError = void 0;
|
|
4
|
+
class ModelTokenError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "ModelTokenError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.ModelTokenError = ModelTokenError;
|
package/lib/Http/index.d.ts
CHANGED
|
@@ -6,6 +6,9 @@ export declare class Http extends HttpHeaders {
|
|
|
6
6
|
private static headers;
|
|
7
7
|
private static body;
|
|
8
8
|
private static resolveParam;
|
|
9
|
+
private static monitorOutgoingEnabled;
|
|
10
|
+
private static recordOutgoing;
|
|
11
|
+
private static trackedRequest;
|
|
9
12
|
static get(url: string, params?: Record<string, any>): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
10
13
|
static post(url: string, data?: Record<string, any> | string): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
11
14
|
static withQueryParameters(params?: Record<string, any>): typeof Http;
|
package/lib/Http/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Http/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Http/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,qBAAa,IAAK,SAAQ,WAAW;IAEnC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAuB;IAG3C,OAAO,CAAC,MAAM,CAAC,WAAW,CAA2B;IAGrD,OAAO,CAAC,MAAM,CAAC,OAAO,CAA2B;IAGjD,OAAO,CAAC,MAAM,CAAC,IAAI,CAA2B;IAG9C,OAAO,CAAC,MAAM,CAAC,YAAY;IAO3B,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAKrC,OAAO,CAAC,MAAM,CAAC,cAAc;IAW7B,OAAO,CAAC,MAAM,CAAC,cAAc;IA6B7B,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;IAUxD,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAW;IAUhE,MAAM,CAAC,mBAAmB,CAAC,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;IAK3D,MAAM,CAAC,QAAQ,CACb,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EAC9B,WAAW,SAA2B;IAOxC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;IAUxD,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAK/C,MAAM,CAAC,MAAM;IAIb,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;IAUtD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM;IAUzB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM;IAK7B,MAAM,CAAC,UAAU;IAKjB,oFAAoF;IACpF,MAAM,CAAC,KAAK,IAAI,OAAO,IAAI;CAM5B"}
|
package/lib/Http/index.js
CHANGED
|
@@ -5,6 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Http = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
9
|
+
const Monitor_1 = require("../Monitor");
|
|
10
|
+
const MonitorManager_1 = require("../Monitor/MonitorManager");
|
|
8
11
|
const HttpHeader_1 = require("./HttpHeader");
|
|
9
12
|
class Http extends HttpHeader_1.HttpHeaders {
|
|
10
13
|
//
|
|
@@ -14,17 +17,50 @@ class Http extends HttpHeader_1.HttpHeaders {
|
|
|
14
17
|
}
|
|
15
18
|
return url;
|
|
16
19
|
}
|
|
20
|
+
static monitorOutgoingEnabled() {
|
|
21
|
+
const mgr = MonitorManager_1.MonitorManager.getInstance();
|
|
22
|
+
return mgr.config.enabled && mgr.config.collectors.outgoing.enabled;
|
|
23
|
+
}
|
|
24
|
+
static recordOutgoing(payload) {
|
|
25
|
+
if (!this.monitorOutgoingEnabled())
|
|
26
|
+
return;
|
|
27
|
+
Monitor_1.Monitor.recordOutgoingRequest({ ...payload, timestamp: Date.now() });
|
|
28
|
+
}
|
|
29
|
+
static trackedRequest(method, url, run) {
|
|
30
|
+
const resolvedUrl = this.resolveParam(url);
|
|
31
|
+
const startedAt = perf_hooks_1.performance.now();
|
|
32
|
+
return run()
|
|
33
|
+
.then((result) => {
|
|
34
|
+
this.recordOutgoing({
|
|
35
|
+
method,
|
|
36
|
+
url: resolvedUrl,
|
|
37
|
+
status: result?.status ?? 0,
|
|
38
|
+
durationMs: Number((perf_hooks_1.performance.now() - startedAt).toFixed(2)),
|
|
39
|
+
});
|
|
40
|
+
return result;
|
|
41
|
+
})
|
|
42
|
+
.catch((error) => {
|
|
43
|
+
this.recordOutgoing({
|
|
44
|
+
method,
|
|
45
|
+
url: resolvedUrl,
|
|
46
|
+
status: error?.response?.status ?? 0,
|
|
47
|
+
durationMs: Number((perf_hooks_1.performance.now() - startedAt).toFixed(2)),
|
|
48
|
+
error: error?.message ?? String(error ?? ""),
|
|
49
|
+
});
|
|
50
|
+
throw error;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
17
53
|
static get(url, params = {}) {
|
|
18
|
-
const response = this.axios.get(this.resolveParam(url), {
|
|
54
|
+
const response = this.trackedRequest("GET", url, () => this.axios.get(this.resolveParam(url), {
|
|
19
55
|
headers: this.headers,
|
|
20
|
-
});
|
|
56
|
+
}));
|
|
21
57
|
this.reset();
|
|
22
58
|
return response;
|
|
23
59
|
}
|
|
24
60
|
static post(url, data = {}) {
|
|
25
|
-
const response = this.axios.post(this.resolveParam(url), data, {
|
|
61
|
+
const response = this.trackedRequest("POST", url, () => this.axios.post(this.resolveParam(url), data, {
|
|
26
62
|
headers: this.headers,
|
|
27
|
-
});
|
|
63
|
+
}));
|
|
28
64
|
this.reset();
|
|
29
65
|
return response;
|
|
30
66
|
}
|
|
@@ -38,9 +74,9 @@ class Http extends HttpHeader_1.HttpHeaders {
|
|
|
38
74
|
return this;
|
|
39
75
|
}
|
|
40
76
|
static patch(url, data = {}) {
|
|
41
|
-
const response = this.axios.patch(this.resolveParam(url), data, {
|
|
77
|
+
const response = this.trackedRequest("PATCH", url, () => this.axios.patch(this.resolveParam(url), data, {
|
|
42
78
|
headers: this.headers,
|
|
43
|
-
});
|
|
79
|
+
}));
|
|
44
80
|
this.reset();
|
|
45
81
|
return response;
|
|
46
82
|
}
|
|
@@ -52,16 +88,16 @@ class Http extends HttpHeader_1.HttpHeaders {
|
|
|
52
88
|
return this.withHeaders({ "Content-Type": this.HttpHeaders["form-data"] });
|
|
53
89
|
}
|
|
54
90
|
static put(url, data = {}) {
|
|
55
|
-
const response = this.axios.put(this.resolveParam(url), data, {
|
|
91
|
+
const response = this.trackedRequest("PUT", url, () => this.axios.put(this.resolveParam(url), data, {
|
|
56
92
|
headers: this.headers,
|
|
57
|
-
});
|
|
93
|
+
}));
|
|
58
94
|
this.reset();
|
|
59
95
|
return response;
|
|
60
96
|
}
|
|
61
97
|
static delete(url) {
|
|
62
|
-
const response = this.axios.delete(this.resolveParam(url), {
|
|
98
|
+
const response = this.trackedRequest("DELETE", url, () => this.axios.delete(this.resolveParam(url), {
|
|
63
99
|
headers: this.headers,
|
|
64
|
-
});
|
|
100
|
+
}));
|
|
65
101
|
this.reset();
|
|
66
102
|
return response;
|
|
67
103
|
}
|
|
@@ -6,6 +6,7 @@ import { Request } from "express";
|
|
|
6
6
|
import { CursorPagination, Pagination, SimplePagination } from "./Interfaces";
|
|
7
7
|
export declare class Model extends BaseModel {
|
|
8
8
|
relations: Record<string, any>;
|
|
9
|
+
protected hasToken: boolean;
|
|
9
10
|
constructor(attributes?: Record<string, any>);
|
|
10
11
|
getTable(): string;
|
|
11
12
|
getKeyName(): string;
|
|
@@ -71,5 +72,6 @@ export declare class Model extends BaseModel {
|
|
|
71
72
|
load(relations: string | string[] | Record<string, Function>): Promise<this>;
|
|
72
73
|
static eventType(): any;
|
|
73
74
|
private static fireEventOnStaticMethod;
|
|
75
|
+
createToken(payload?: Record<string, any>): any;
|
|
74
76
|
}
|
|
75
77
|
//# sourceMappingURL=Model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Jcc-eloquent/lib/Model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Jcc-eloquent/lib/Model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAKL,OAAO,EAGR,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAE1E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAK9E,qBAAa,KAAM,SAAQ,SAAS;IAC3B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;IAC3C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O,KAAK,EACrB,UAAU,CAAC,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,MAAM,EACxB,eAAe,CAAC,EAAE,MAAM,EACxB,SAAS,GAAE,MAAa,EACxB,UAAU,GAAE,MAAa,GACxB,wBAAwB;IAgC3B,SAAS,CAAC,QAAQ,CAChB,OAAO,EAAE,OAAO,KAAK,EACrB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,MAAM,GACZ,wBAAwB;IAe3B,SAAS,CAAC,SAAS,CACjB,OAAO,EAAE,OAAO,KAAK,EACrB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,MAAM,GACZ,wBAAwB;IAe3B,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,KAAK,GAAG,OAAO;IAW7D;;OAEG;WACW,IAAI,CAChB,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GACtD,OAAO;IAIH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG;IAWpC,WAAW,CAAC,IAAI,EAAE,MAAM;IAI/B;;OAEG;IACU,IAAI,CACf,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GACtD,OAAO,CAAC,IAAI,CAAC;IAahB,MAAM,CAAC,SAAS;IAIhB,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAO/B,WAAW,CAAC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAyB;CAQxE"}
|
|
@@ -7,10 +7,14 @@ const utils_1 = require("./utils");
|
|
|
7
7
|
const ModelEvent_1 = require("./Event/ModelEvent");
|
|
8
8
|
const Relations_1 = require("./Relations");
|
|
9
9
|
const EagerLoading_1 = require("./Relations/EagerLoading");
|
|
10
|
+
const util_1 = require("../../util");
|
|
11
|
+
const ModelTokenError_1 = require("../../Error/ModelExceptions/ModelTokenError");
|
|
12
|
+
//
|
|
10
13
|
class Model extends BaseModel_1.BaseModel {
|
|
11
14
|
constructor(attributes = {}) {
|
|
12
15
|
super();
|
|
13
16
|
this.relations = {};
|
|
17
|
+
this.hasToken = false;
|
|
14
18
|
this.fill(attributes);
|
|
15
19
|
this.syncOriginal();
|
|
16
20
|
return this.proxy();
|
|
@@ -130,7 +134,9 @@ class Model extends BaseModel_1.BaseModel {
|
|
|
130
134
|
* Executes the query and loads specified relations.
|
|
131
135
|
*/
|
|
132
136
|
static async find(id) {
|
|
133
|
-
return this.query()
|
|
137
|
+
return this.query()
|
|
138
|
+
.where("id", id || "")
|
|
139
|
+
.first();
|
|
134
140
|
}
|
|
135
141
|
static async all() {
|
|
136
142
|
return this.query().get();
|
|
@@ -380,5 +386,11 @@ class Model extends BaseModel_1.BaseModel {
|
|
|
380
386
|
}
|
|
381
387
|
return ModelEvent_1.ModelEvent.fireEvent(this.eventType(), event, instance);
|
|
382
388
|
}
|
|
389
|
+
createToken(payload = { id: this.getKey() }) {
|
|
390
|
+
if (!this.hasToken) {
|
|
391
|
+
throw new ModelTokenError_1.ModelTokenError(`${this.constructor.name} Missing required token. Please set 'protected hasToken = true' .`);
|
|
392
|
+
}
|
|
393
|
+
return (0, util_1.jwtSign)(payload, { expiresIn: "22h" });
|
|
394
|
+
}
|
|
383
395
|
}
|
|
384
396
|
exports.Model = Model;
|
package/lib/Mail/Manager.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Mail/Manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Mail/Manager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAM5C,qBAAa,WAAW;IACtB,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,aAAa,CAAgB;IAErC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IAMrC,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW;IAM3C,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW;IAM5C,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKvB,EAAE,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI;IAK7B,GAAG,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI;IAK9B,OAAO,CAAC,SAAS;IAmBX,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IA6BxC,OAAO,CAAC,kBAAkB;YAKZ,aAAa;CAY5B"}
|
package/lib/Mail/Manager.js
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MailManager = void 0;
|
|
4
4
|
const Config_1 = require("../Config/Config");
|
|
5
|
+
const Monitor_1 = require("../Monitor");
|
|
6
|
+
const MonitorManager_1 = require("../Monitor/MonitorManager");
|
|
5
7
|
const Nodemailer_1 = require("./Drivers/Nodemailer");
|
|
6
8
|
const Resend_1 = require("./Drivers/Resend");
|
|
9
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
7
10
|
class MailManager {
|
|
8
11
|
constructor() {
|
|
9
12
|
this.recipient = "";
|
|
@@ -46,8 +49,42 @@ class MailManager {
|
|
|
46
49
|
return new Nodemailer_1.Nodemailer(this.ccRecipients, this.bccRecipients, this.recipient);
|
|
47
50
|
}
|
|
48
51
|
async send(mailer) {
|
|
49
|
-
const
|
|
50
|
-
|
|
52
|
+
const driverName = Config_1.config.get("MAIL_DRIVER", "smtp").toLowerCase();
|
|
53
|
+
const startedAt = perf_hooks_1.performance.now();
|
|
54
|
+
const subject = mailer.subject;
|
|
55
|
+
try {
|
|
56
|
+
const driver = this.getDriver();
|
|
57
|
+
const result = await driver.send(mailer);
|
|
58
|
+
await this.recordMailRun({
|
|
59
|
+
to: this.recipient,
|
|
60
|
+
subject,
|
|
61
|
+
driver: driverName,
|
|
62
|
+
status: "sent",
|
|
63
|
+
durationMs: Number((perf_hooks_1.performance.now() - startedAt).toFixed(2)),
|
|
64
|
+
});
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
await this.recordMailRun({
|
|
69
|
+
to: this.recipient,
|
|
70
|
+
subject,
|
|
71
|
+
driver: driverName,
|
|
72
|
+
status: "failed",
|
|
73
|
+
durationMs: Number((perf_hooks_1.performance.now() - startedAt).toFixed(2)),
|
|
74
|
+
error: error instanceof Error ? error.message : String(error ?? ""),
|
|
75
|
+
});
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
monitorMailEnabled() {
|
|
80
|
+
const mgr = MonitorManager_1.MonitorManager.getInstance();
|
|
81
|
+
return mgr.config.enabled && mgr.config.collectors.mail.enabled;
|
|
82
|
+
}
|
|
83
|
+
async recordMailRun(payload) {
|
|
84
|
+
if (!this.monitorMailEnabled())
|
|
85
|
+
return;
|
|
86
|
+
Monitor_1.Monitor.recordMail({ ...payload, timestamp: Date.now() });
|
|
87
|
+
await MonitorManager_1.MonitorManager.getInstance().flush();
|
|
51
88
|
}
|
|
52
89
|
}
|
|
53
90
|
exports.MailManager = MailManager;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type { Collector } from "../interfaces";
|
|
2
2
|
import type { MonitorManager } from "../MonitorManager";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* idempotent.
|
|
4
|
+
* Metrics registration for cache operations. The framework Cache class
|
|
5
|
+
* records hits / misses / writes / forgets via `Monitor.recordCacheOp()`.
|
|
7
6
|
*/
|
|
8
7
|
export declare class CacheCollector implements Collector {
|
|
9
8
|
private manager;
|
|
10
9
|
readonly name = "cache";
|
|
11
|
-
private restore;
|
|
12
10
|
constructor(manager: MonitorManager);
|
|
13
11
|
start(): void;
|
|
14
12
|
stop(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CacheCollector.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Monitor/Collectors/CacheCollector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD
|
|
1
|
+
{"version":3,"file":"CacheCollector.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Monitor/Collectors/CacheCollector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD;;;GAGG;AACH,qBAAa,cAAe,YAAW,SAAS;IAElC,OAAO,CAAC,OAAO;IAD3B,QAAQ,CAAC,IAAI,WAAW;gBACJ,OAAO,EAAE,cAAc;IAE3C,KAAK,IAAI,IAAI;IAKb,IAAI,IAAI,IAAI;CACb"}
|