jcc-express-mvc 1.8.7 → 1.8.21
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/Core/index.d.ts +4 -0
- package/Core/index.d.ts.map +1 -1
- package/Core/index.js +5 -0
- package/__tests__/Job.test.d.ts +2 -0
- package/__tests__/Job.test.d.ts.map +1 -0
- package/__tests__/Job.test.js +205 -0
- package/__tests__/MySqlSchemaBlueprint.test.d.ts +2 -0
- package/__tests__/MySqlSchemaBlueprint.test.d.ts.map +1 -0
- package/__tests__/MySqlSchemaBlueprint.test.js +55 -0
- package/__tests__/PostgresTranslator.test.d.ts +2 -0
- package/__tests__/PostgresTranslator.test.d.ts.map +1 -0
- package/__tests__/PostgresTranslator.test.js +82 -0
- package/__tests__/SQLiteTranslator.test.d.ts +2 -0
- package/__tests__/SQLiteTranslator.test.d.ts.map +1 -0
- package/__tests__/SQLiteTranslator.test.js +125 -0
- package/__tests__/SchemaAlterBlueprint.test.d.ts +2 -0
- package/__tests__/SchemaAlterBlueprint.test.d.ts.map +1 -0
- package/__tests__/SchemaAlterBlueprint.test.js +35 -0
- package/global.d.ts +3 -1
- package/index.d.ts +28 -3
- package/index.d.ts.map +1 -1
- package/index.js +33 -75
- package/lib/Application/Application.d.ts.map +1 -1
- package/lib/Application/Application.js +2 -2
- package/lib/Application/ApplicationBuilder.d.ts.map +1 -1
- package/lib/Application/ApplicationBuilder.js +22 -11
- package/lib/Auth/AuthMiddleware.d.ts.map +1 -1
- package/lib/Auth/AuthMiddleware.js +29 -12
- package/lib/Auth/index.d.ts +17 -3
- package/lib/Auth/index.d.ts.map +1 -1
- package/lib/Auth/index.js +128 -26
- package/lib/Auth/loginRateLimit.d.ts +6 -0
- package/lib/Auth/loginRateLimit.d.ts.map +1 -0
- package/lib/Auth/loginRateLimit.js +25 -0
- package/lib/Auth/refreshTokenStore.d.ts +24 -0
- package/lib/Auth/refreshTokenStore.d.ts.map +1 -0
- package/lib/Auth/refreshTokenStore.js +46 -0
- package/lib/Command-Line/DBCommand.d.ts.map +1 -1
- package/lib/Command-Line/DBCommand.js +9 -3
- package/lib/Command-Line/KeyGenerateCommand.d.ts +6 -0
- package/lib/Command-Line/KeyGenerateCommand.d.ts.map +1 -0
- package/lib/Command-Line/KeyGenerateCommand.js +47 -0
- package/lib/Command-Line/MakeCommand.d.ts +1 -0
- package/lib/Command-Line/MakeCommand.d.ts.map +1 -1
- package/lib/Command-Line/MakeCommand.js +36 -32
- package/lib/Command-Line/NodeArtisanCommand.d.ts +2 -0
- package/lib/Command-Line/NodeArtisanCommand.d.ts.map +1 -1
- package/lib/Command-Line/NodeArtisanCommand.js +24 -6
- package/lib/Command-Line/NodeTinker/Tinker.d.ts +5 -2
- package/lib/Command-Line/NodeTinker/Tinker.d.ts.map +1 -1
- package/lib/Command-Line/NodeTinker/Tinker.js +13 -3
- package/lib/Command-Line/WatchCommand.d.ts +29 -0
- package/lib/Command-Line/WatchCommand.d.ts.map +1 -0
- package/lib/Command-Line/WatchCommand.js +234 -0
- package/lib/Command-Line/files/Models.d.ts.map +1 -1
- package/lib/Command-Line/files/Models.js +67 -0
- package/lib/Console/Command.d.ts +18 -0
- package/lib/Console/Command.d.ts.map +1 -1
- package/lib/Console/Command.js +29 -0
- package/lib/Container/index.d.ts.map +1 -1
- package/lib/Container/index.js +22 -8
- package/lib/Database/Database.d.ts +21 -0
- package/lib/Database/Database.d.ts.map +1 -0
- package/lib/Database/Database.js +55 -0
- package/lib/Database/DatabaseServiceProvider.d.ts +22 -0
- package/lib/Database/DatabaseServiceProvider.d.ts.map +1 -0
- package/lib/Database/DatabaseServiceProvider.js +50 -0
- package/lib/Database/Drivers/KnexDriver.d.ts +13 -0
- package/lib/Database/Drivers/KnexDriver.d.ts.map +1 -0
- package/lib/Database/Drivers/KnexDriver.js +29 -0
- package/lib/Database/Drivers/MongooseDriver.d.ts +20 -0
- package/lib/Database/Drivers/MongooseDriver.d.ts.map +1 -0
- package/lib/Database/Drivers/MongooseDriver.js +57 -0
- package/lib/Database/Drivers/SequelizeDriver.d.ts +24 -0
- package/lib/Database/Drivers/SequelizeDriver.d.ts.map +1 -0
- package/lib/Database/Drivers/SequelizeDriver.js +82 -0
- package/lib/Database/index.d.ts +7 -0
- package/lib/Database/index.d.ts.map +1 -0
- package/lib/Database/index.js +11 -0
- package/lib/Database/interface.d.ts +14 -0
- package/lib/Database/interface.d.ts.map +1 -0
- package/lib/Database/interface.js +2 -0
- package/lib/Database/type.d.ts +18 -0
- package/lib/Database/type.d.ts.map +1 -0
- package/lib/Database/type.js +2 -0
- package/lib/Error/DisplayErrorCode.d.ts.map +1 -1
- package/lib/Error/DisplayErrorCode.js +27 -17
- package/lib/Error/MissMatchTokenException/index.d.ts +4 -0
- package/lib/Error/MissMatchTokenException/index.d.ts.map +1 -0
- package/lib/Error/MissMatchTokenException/index.js +9 -0
- package/lib/Error/SocialiteAuthError/SocialiteAuthError.d.ts +9 -0
- package/lib/Error/SocialiteAuthError/SocialiteAuthError.d.ts.map +1 -0
- package/lib/Error/SocialiteAuthError/SocialiteAuthError.js +17 -0
- package/lib/Global/helpers.d.ts.map +1 -1
- package/lib/Global/helpers.js +7 -6
- package/lib/Http/index.d.ts +3 -1
- package/lib/Http/index.d.ts.map +1 -1
- package/lib/Http/index.js +26 -5
- package/lib/Interface/index.d.ts +17 -3
- package/lib/Interface/index.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Builder.d.ts +12 -1
- package/lib/Jcc-eloquent/lib/Builder.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Builder.js +119 -5
- package/lib/Jcc-eloquent/lib/Database/index.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Database/index.js +2 -1
- package/lib/Jcc-eloquent/lib/Interfaces/index.d.ts +37 -2
- package/lib/Jcc-eloquent/lib/Interfaces/index.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Migration.d.ts +6 -0
- package/lib/Jcc-eloquent/lib/Migration.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Migration.js +24 -2
- package/lib/Jcc-eloquent/lib/Model.d.ts +24 -7
- package/lib/Jcc-eloquent/lib/Model.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Model.js +35 -2
- package/lib/Jcc-eloquent/lib/QueryBuilder.d.ts +2 -1
- package/lib/Jcc-eloquent/lib/QueryBuilder.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/QueryBuilder.js +10 -1
- package/lib/Jcc-eloquent/lib/Rollback.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Rollback.js +9 -2
- package/lib/Jcc-eloquent/lib/Schema/BaseSchemaEntity/index.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Schema/BaseSchemaEntity/index.js +3 -3
- package/lib/Jcc-eloquent/lib/Schema/BluePrint/index.d.ts +6 -2
- package/lib/Jcc-eloquent/lib/Schema/BluePrint/index.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Schema/BluePrint/index.js +41 -12
- package/lib/Jcc-eloquent/lib/Schema/Translator/Sqlite.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Schema/Translator/Sqlite.js +21 -3
- package/lib/Jcc-eloquent/lib/Schema/Translator/postgres.d.ts +1 -0
- package/lib/Jcc-eloquent/lib/Schema/Translator/postgres.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Schema/Translator/postgres.js +70 -14
- package/lib/Jcc-eloquent/lib/Schema/index.d.ts +12 -0
- package/lib/Jcc-eloquent/lib/Schema/index.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Schema/index.js +27 -6
- package/lib/Jcc-eloquent/lib/utils/index.d.ts +13 -0
- package/lib/Jcc-eloquent/lib/utils/index.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/utils/index.js +62 -0
- package/lib/Middleware/index.d.ts +1 -0
- package/lib/Middleware/index.d.ts.map +1 -1
- package/lib/Middleware/index.js +20 -8
- package/lib/Model/Sequelize.d.ts +3 -0
- package/lib/Model/Sequelize.d.ts.map +1 -0
- package/lib/Model/Sequelize.js +6 -0
- package/lib/Providers/RouteServiceProvider.d.ts.map +1 -1
- package/lib/Providers/RouteServiceProvider.js +3 -0
- package/lib/Providers/SessionServiceProvider.d.ts +12 -0
- package/lib/Providers/SessionServiceProvider.d.ts.map +1 -0
- package/lib/Providers/SessionServiceProvider.js +47 -0
- package/lib/Queue/Controllers/QueueControllers.d.ts +31 -0
- package/lib/Queue/Controllers/QueueControllers.d.ts.map +1 -0
- package/lib/Queue/Controllers/QueueControllers.js +126 -0
- package/lib/Queue/Drivers/DatabaseDriver.d.ts +6 -1
- package/lib/Queue/Drivers/DatabaseDriver.d.ts.map +1 -1
- package/lib/Queue/Drivers/DatabaseDriver.js +76 -21
- package/lib/Queue/Drivers/MemoryDriver.d.ts +17 -6
- package/lib/Queue/Drivers/MemoryDriver.d.ts.map +1 -1
- package/lib/Queue/Drivers/MemoryDriver.js +323 -14
- package/lib/Queue/Drivers/RedisDriver.d.ts +48 -0
- package/lib/Queue/Drivers/RedisDriver.d.ts.map +1 -0
- package/lib/Queue/Drivers/RedisDriver.js +533 -0
- package/lib/Queue/Job.d.ts +8 -0
- package/lib/Queue/Job.d.ts.map +1 -1
- package/lib/Queue/Job.js +25 -1
- package/lib/Queue/JobsLogger.d.ts.map +1 -1
- package/lib/Queue/JobsLogger.js +6 -3
- package/lib/Queue/Queue.d.ts +17 -0
- package/lib/Queue/Queue.d.ts.map +1 -1
- package/lib/Queue/Queue.js +146 -11
- package/lib/Queue/QueueServiceProvider.d.ts +6 -0
- package/lib/Queue/QueueServiceProvider.d.ts.map +1 -0
- package/lib/Queue/QueueServiceProvider.js +18 -0
- package/lib/Queue/Route/web.d.ts +2 -0
- package/lib/Queue/Route/web.d.ts.map +1 -0
- package/lib/Queue/Route/web.js +16 -0
- package/lib/Queue/index.d.ts +1 -0
- package/lib/Queue/index.d.ts.map +1 -1
- package/lib/Queue/index.js +3 -0
- package/lib/Queue/interface.d.ts +25 -0
- package/lib/Queue/interface.d.ts.map +1 -1
- package/lib/Queue/middleware/queueDashboardGuard.d.ts +7 -0
- package/lib/Queue/middleware/queueDashboardGuard.d.ts.map +1 -0
- package/lib/Queue/middleware/queueDashboardGuard.js +43 -0
- package/lib/Queue/type.d.ts +12 -1
- package/lib/Queue/type.d.ts.map +1 -1
- package/lib/Response/index.d.ts.map +1 -1
- package/lib/Response/index.js +6 -1
- package/lib/Routes/Route.d.ts +2 -2
- package/lib/Routes/Route.d.ts.map +1 -1
- package/lib/Routes/RouteBuilder.d.ts +2 -2
- package/lib/Routes/RouteBuilder.d.ts.map +1 -1
- package/lib/Security/CsrfMiddleware.d.ts +37 -0
- package/lib/Security/CsrfMiddleware.d.ts.map +1 -0
- package/lib/Security/CsrfMiddleware.js +85 -0
- package/lib/Security/MethodSpoofingMiddleware.d.ts +36 -0
- package/lib/Security/MethodSpoofingMiddleware.d.ts.map +1 -0
- package/lib/Security/MethodSpoofingMiddleware.js +51 -0
- package/lib/Security/index.d.ts +5 -0
- package/lib/Security/index.d.ts.map +1 -0
- package/lib/Security/index.js +7 -0
- package/lib/Session/DatabaseSession.d.ts +9 -3
- package/lib/Session/DatabaseSession.d.ts.map +1 -1
- package/lib/Session/DatabaseSession.js +38 -36
- package/lib/Session/ExpressJccSession.d.ts +23 -0
- package/lib/Session/ExpressJccSession.d.ts.map +1 -0
- package/lib/Session/ExpressJccSession.js +110 -0
- package/lib/Session/RedisSession.d.ts +2 -2
- package/lib/Session/RedisSession.d.ts.map +1 -1
- package/lib/Session/RedisSession.js +19 -5
- package/lib/Session/SessionManager.d.ts +18 -4
- package/lib/Session/SessionManager.d.ts.map +1 -1
- package/lib/Session/SessionManager.js +53 -17
- package/lib/Socialite/AbstractProvider.d.ts +60 -0
- package/lib/Socialite/AbstractProvider.d.ts.map +1 -0
- package/lib/Socialite/AbstractProvider.js +136 -0
- package/lib/Socialite/Drivers/facebook/FacebookDriver.d.ts +9 -0
- package/lib/Socialite/Drivers/facebook/FacebookDriver.d.ts.map +1 -0
- package/lib/Socialite/Drivers/facebook/FacebookDriver.js +40 -0
- package/lib/Socialite/Drivers/facebook/FacebookProvider.d.ts +15 -0
- package/lib/Socialite/Drivers/facebook/FacebookProvider.d.ts.map +1 -0
- package/lib/Socialite/Drivers/facebook/FacebookProvider.js +28 -0
- package/lib/Socialite/Drivers/github/GitHubDriver.d.ts +9 -0
- package/lib/Socialite/Drivers/github/GitHubDriver.d.ts.map +1 -0
- package/lib/Socialite/Drivers/github/GitHubDriver.js +54 -0
- package/lib/Socialite/Drivers/github/GitHubProvider.d.ts +15 -0
- package/lib/Socialite/Drivers/github/GitHubProvider.d.ts.map +1 -0
- package/lib/Socialite/Drivers/github/GitHubProvider.js +28 -0
- package/lib/Socialite/Drivers/gitlab/GitLabDriver.d.ts +10 -0
- package/lib/Socialite/Drivers/gitlab/GitLabDriver.d.ts.map +1 -0
- package/lib/Socialite/Drivers/gitlab/GitLabDriver.js +37 -0
- package/lib/Socialite/Drivers/gitlab/GitLabProvider.d.ts +15 -0
- package/lib/Socialite/Drivers/gitlab/GitLabProvider.d.ts.map +1 -0
- package/lib/Socialite/Drivers/gitlab/GitLabProvider.js +28 -0
- package/lib/Socialite/Drivers/google/GoogleDriver.d.ts +9 -0
- package/lib/Socialite/Drivers/google/GoogleDriver.d.ts.map +1 -0
- package/lib/Socialite/Drivers/google/GoogleDriver.js +39 -0
- package/lib/Socialite/Drivers/google/GoogleProvider.d.ts +15 -0
- package/lib/Socialite/Drivers/google/GoogleProvider.d.ts.map +1 -0
- package/lib/Socialite/Drivers/google/GoogleProvider.js +28 -0
- package/lib/Socialite/Drivers/slack/SlackDriver.d.ts +9 -0
- package/lib/Socialite/Drivers/slack/SlackDriver.d.ts.map +1 -0
- package/lib/Socialite/Drivers/slack/SlackDriver.js +41 -0
- package/lib/Socialite/Drivers/slack/SlackProvider.d.ts +16 -0
- package/lib/Socialite/Drivers/slack/SlackProvider.d.ts.map +1 -0
- package/lib/Socialite/Drivers/slack/SlackProvider.js +37 -0
- package/lib/Socialite/Drivers/twitter/TwitterDriver.d.ts +9 -0
- package/lib/Socialite/Drivers/twitter/TwitterDriver.d.ts.map +1 -0
- package/lib/Socialite/Drivers/twitter/TwitterDriver.js +57 -0
- package/lib/Socialite/Drivers/twitter/TwitterProvider.d.ts +16 -0
- package/lib/Socialite/Drivers/twitter/TwitterProvider.d.ts.map +1 -0
- package/lib/Socialite/Drivers/twitter/TwitterProvider.js +38 -0
- package/lib/Socialite/SocialUser.d.ts +42 -0
- package/lib/Socialite/SocialUser.d.ts.map +1 -0
- package/lib/Socialite/SocialUser.js +116 -0
- package/lib/Socialite/Socialite.d.ts +13 -0
- package/lib/Socialite/Socialite.d.ts.map +1 -0
- package/lib/Socialite/Socialite.js +41 -0
- package/lib/Socialite/SocialiteProvider.d.ts +9 -0
- package/lib/Socialite/SocialiteProvider.d.ts.map +1 -0
- package/lib/Socialite/SocialiteProvider.js +15 -0
- package/lib/Socialite/config.d.ts +7 -0
- package/lib/Socialite/config.d.ts.map +1 -0
- package/lib/Socialite/config.js +44 -0
- package/lib/Socialite/constant.d.ts +18 -0
- package/lib/Socialite/constant.d.ts.map +1 -0
- package/lib/Socialite/constant.js +20 -0
- package/lib/Socialite/index.d.ts +13 -0
- package/lib/Socialite/index.d.ts.map +1 -0
- package/lib/Socialite/index.js +25 -0
- package/lib/Socialite/types.d.ts +13 -0
- package/lib/Socialite/types.d.ts.map +1 -0
- package/lib/Socialite/types.js +2 -0
- package/lib/Templating-engine/benchmark.d.ts +7 -0
- package/lib/Templating-engine/benchmark.d.ts.map +1 -0
- package/lib/Templating-engine/benchmark.js +44 -0
- package/lib/Templating-engine/engineHelper.d.ts +37 -8
- package/lib/Templating-engine/engineHelper.d.ts.map +1 -1
- package/lib/Templating-engine/engineHelper.js +203 -26
- package/lib/Templating-engine/errors.d.ts +15 -0
- package/lib/Templating-engine/errors.d.ts.map +1 -0
- package/lib/Templating-engine/errors.js +35 -0
- package/lib/Templating-engine/expressions.d.ts +24 -0
- package/lib/Templating-engine/expressions.d.ts.map +1 -1
- package/lib/Templating-engine/expressions.js +27 -5
- package/lib/Templating-engine/index.d.ts +87 -17
- package/lib/Templating-engine/index.d.ts.map +1 -1
- package/lib/Templating-engine/index.js +701 -96
- package/lib/Templating-engine/plugins.d.ts +30 -0
- package/lib/Templating-engine/plugins.d.ts.map +1 -0
- package/lib/Templating-engine/plugins.js +47 -0
- package/lib/Type/index.d.ts +1 -0
- package/lib/Type/index.d.ts.map +1 -1
- package/lib/Validation/Validator/CustomValidation.d.ts.map +1 -1
- package/lib/Validation/Validator/CustomValidation.js +2 -2
- package/lib/Validation/Validator/helper.d.ts.map +1 -1
- package/lib/Validation/Validator/helper.js +8 -1
- package/lib/util/index.d.ts +42 -1
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +154 -17
- package/package.json +1 -1
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WatchCommand = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const child_process_1 = require("child_process");
|
|
10
|
+
const readline_1 = __importDefault(require("readline"));
|
|
11
|
+
const colors_1 = __importDefault(require("colors"));
|
|
12
|
+
const app_root_path_1 = __importDefault(require("app-root-path"));
|
|
13
|
+
class WatchCommand {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.rootPath = app_root_path_1.default.path;
|
|
16
|
+
this.ignoredDirs = new Set([
|
|
17
|
+
"node_modules",
|
|
18
|
+
"build",
|
|
19
|
+
"dist",
|
|
20
|
+
".git",
|
|
21
|
+
".idea",
|
|
22
|
+
".vscode",
|
|
23
|
+
"storage",
|
|
24
|
+
]);
|
|
25
|
+
this.defaultWatchTargets = [
|
|
26
|
+
"app",
|
|
27
|
+
"bootstrap",
|
|
28
|
+
"config",
|
|
29
|
+
"database",
|
|
30
|
+
"jcc-express-mvc",
|
|
31
|
+
"resources",
|
|
32
|
+
"routes",
|
|
33
|
+
"server.ts",
|
|
34
|
+
];
|
|
35
|
+
this.rootFilesToWatch = new Set([".env"]);
|
|
36
|
+
this.watchers = [];
|
|
37
|
+
this.child = null;
|
|
38
|
+
this.restartTimer = null;
|
|
39
|
+
this.isRestarting = false;
|
|
40
|
+
this.suppressNextExitLog = false;
|
|
41
|
+
this.pendingChanges = new Set();
|
|
42
|
+
this.lastRestartAt = 0;
|
|
43
|
+
this.minRestartGapMs = 800;
|
|
44
|
+
this.entryFile = "server.ts";
|
|
45
|
+
}
|
|
46
|
+
async run(entryFile = "server.ts") {
|
|
47
|
+
const resolvedEntry = path_1.default.resolve(this.rootPath, entryFile);
|
|
48
|
+
if (!fs_1.default.existsSync(resolvedEntry)) {
|
|
49
|
+
throw new Error(`Entry file not found: ${entryFile}`);
|
|
50
|
+
}
|
|
51
|
+
this.entryFile = entryFile;
|
|
52
|
+
this.installSignalHandlers();
|
|
53
|
+
this.refreshWatchers();
|
|
54
|
+
this.renderServeHeader(path_1.default.relative(this.rootPath, resolvedEntry));
|
|
55
|
+
this.startServer(resolvedEntry);
|
|
56
|
+
}
|
|
57
|
+
refreshWatchers() {
|
|
58
|
+
this.closeWatchers();
|
|
59
|
+
const directories = this.collectWatchDirectories();
|
|
60
|
+
for (const dir of directories) {
|
|
61
|
+
try {
|
|
62
|
+
const watcher = fs_1.default.watch(dir, (_eventType, filename) => {
|
|
63
|
+
const changed = filename ? path_1.default.join(dir, filename.toString()) : dir;
|
|
64
|
+
this.onFileChanged(changed);
|
|
65
|
+
});
|
|
66
|
+
this.watchers.push(watcher);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Ignore inaccessible directories
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Watch specific root-level files (like .env) without broadly reacting to all root changes.
|
|
73
|
+
try {
|
|
74
|
+
const rootWatcher = fs_1.default.watch(this.rootPath, (_eventType, filename) => {
|
|
75
|
+
const name = filename?.toString();
|
|
76
|
+
if (!name)
|
|
77
|
+
return;
|
|
78
|
+
const comparableName = process.platform === "win32" ? name.toLowerCase() : name;
|
|
79
|
+
if (!this.rootFilesToWatch.has(comparableName))
|
|
80
|
+
return;
|
|
81
|
+
this.onFileChanged(path_1.default.join(this.rootPath, name));
|
|
82
|
+
});
|
|
83
|
+
this.watchers.push(rootWatcher);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Ignore root watcher failures
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
collectWatchDirectories() {
|
|
90
|
+
const dirs = [];
|
|
91
|
+
for (const target of this.defaultWatchTargets) {
|
|
92
|
+
const absolutePath = path_1.default.join(this.rootPath, target);
|
|
93
|
+
if (!fs_1.default.existsSync(absolutePath))
|
|
94
|
+
continue;
|
|
95
|
+
const stat = fs_1.default.statSync(absolutePath);
|
|
96
|
+
if (stat.isDirectory()) {
|
|
97
|
+
this.walkDirectories(absolutePath, dirs);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
dirs.push(path_1.default.dirname(absolutePath));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return Array.from(new Set(dirs));
|
|
104
|
+
}
|
|
105
|
+
walkDirectories(startDir, result) {
|
|
106
|
+
const baseName = path_1.default.basename(startDir);
|
|
107
|
+
if (this.ignoredDirs.has(baseName))
|
|
108
|
+
return;
|
|
109
|
+
result.push(startDir);
|
|
110
|
+
let entries = [];
|
|
111
|
+
try {
|
|
112
|
+
entries = fs_1.default.readdirSync(startDir, { withFileTypes: true });
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
for (const entry of entries) {
|
|
118
|
+
if (!entry.isDirectory())
|
|
119
|
+
continue;
|
|
120
|
+
if (this.ignoredDirs.has(entry.name))
|
|
121
|
+
continue;
|
|
122
|
+
this.walkDirectories(path_1.default.join(startDir, entry.name), result);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
onFileChanged(filePath) {
|
|
126
|
+
if (this.shouldIgnore(filePath))
|
|
127
|
+
return;
|
|
128
|
+
const relative = path_1.default.relative(this.rootPath, filePath) || filePath;
|
|
129
|
+
this.pendingChanges.add(relative);
|
|
130
|
+
if (this.restartTimer)
|
|
131
|
+
clearTimeout(this.restartTimer);
|
|
132
|
+
this.restartTimer = setTimeout(() => {
|
|
133
|
+
this.restartTimer = null;
|
|
134
|
+
this.restartServer();
|
|
135
|
+
}, 250);
|
|
136
|
+
}
|
|
137
|
+
shouldIgnore(filePath) {
|
|
138
|
+
const relativePath = path_1.default.relative(this.rootPath, filePath);
|
|
139
|
+
const normalizedPath = relativePath.split(path_1.default.sep).join("/").toLowerCase();
|
|
140
|
+
if (normalizedPath.startsWith("storage/session") ||
|
|
141
|
+
normalizedPath.startsWith("storage/sessions") ||
|
|
142
|
+
normalizedPath.startsWith("storage/framework/sessions")) {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
const normalized = filePath.split(path_1.default.sep);
|
|
146
|
+
return normalized.some((part) => this.ignoredDirs.has(part));
|
|
147
|
+
}
|
|
148
|
+
startServer(entryFile) {
|
|
149
|
+
this.child = (0, child_process_1.spawn)("bun", [entryFile], {
|
|
150
|
+
cwd: this.rootPath,
|
|
151
|
+
stdio: "inherit",
|
|
152
|
+
env: process.env,
|
|
153
|
+
});
|
|
154
|
+
this.child.on("exit", (code, signal) => {
|
|
155
|
+
if (this.suppressNextExitLog) {
|
|
156
|
+
this.suppressNextExitLog = false;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (!this.isRestarting) {
|
|
160
|
+
const reason = signal ? `signal ${signal}` : `code ${code ?? 0}`;
|
|
161
|
+
console.log(colors_1.default.yellow(`\nServer exited (${reason}).`));
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
restartServer() {
|
|
166
|
+
const now = Date.now();
|
|
167
|
+
const elapsed = now - this.lastRestartAt;
|
|
168
|
+
if (elapsed < this.minRestartGapMs) {
|
|
169
|
+
this.restartTimer = setTimeout(() => {
|
|
170
|
+
this.restartTimer = null;
|
|
171
|
+
this.restartServer();
|
|
172
|
+
}, this.minRestartGapMs - elapsed);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const changedPreview = Array.from(this.pendingChanges).slice(0, 3);
|
|
176
|
+
const extraCount = this.pendingChanges.size - changedPreview.length;
|
|
177
|
+
this.pendingChanges.clear();
|
|
178
|
+
const changedText = changedPreview.length === 0
|
|
179
|
+
? "unknown"
|
|
180
|
+
: `${changedPreview.join(", ")}${extraCount > 0 ? ` (+${extraCount} more)` : ""}`;
|
|
181
|
+
this.isRestarting = true;
|
|
182
|
+
this.lastRestartAt = Date.now();
|
|
183
|
+
this.refreshWatchers();
|
|
184
|
+
this.stopServer();
|
|
185
|
+
this.renderServeHeader(this.entryFile, changedText);
|
|
186
|
+
this.startServer(path_1.default.resolve(this.rootPath, this.entryFile));
|
|
187
|
+
this.isRestarting = false;
|
|
188
|
+
}
|
|
189
|
+
stopServer() {
|
|
190
|
+
if (!this.child)
|
|
191
|
+
return;
|
|
192
|
+
this.suppressNextExitLog = true;
|
|
193
|
+
if (process.platform === "win32") {
|
|
194
|
+
this.child.kill();
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
this.child.kill("SIGTERM");
|
|
198
|
+
}
|
|
199
|
+
this.child = null;
|
|
200
|
+
}
|
|
201
|
+
closeWatchers() {
|
|
202
|
+
for (const watcher of this.watchers)
|
|
203
|
+
watcher.close();
|
|
204
|
+
this.watchers = [];
|
|
205
|
+
}
|
|
206
|
+
installSignalHandlers() {
|
|
207
|
+
const shutdown = () => {
|
|
208
|
+
this.closeWatchers();
|
|
209
|
+
this.stopServer();
|
|
210
|
+
process.exit(0);
|
|
211
|
+
};
|
|
212
|
+
process.once("SIGINT", shutdown);
|
|
213
|
+
process.once("SIGTERM", shutdown);
|
|
214
|
+
}
|
|
215
|
+
renderServeHeader(entryLabel, changedText) {
|
|
216
|
+
this.clearTerminal();
|
|
217
|
+
if (changedText) {
|
|
218
|
+
console.log(colors_1.default.gray(`↻ Change detected: ${changedText}`));
|
|
219
|
+
console.log();
|
|
220
|
+
}
|
|
221
|
+
console.log(colors_1.default.green("👀 Watching project for changes..."));
|
|
222
|
+
console.log(colors_1.default.cyan(`→ Entry: ${entryLabel}`));
|
|
223
|
+
console.log();
|
|
224
|
+
}
|
|
225
|
+
clearTerminal() {
|
|
226
|
+
if (process.stdout.isTTY) {
|
|
227
|
+
readline_1.default.cursorTo(process.stdout, 0, 0);
|
|
228
|
+
readline_1.default.clearScreenDown(process.stdout);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
console.clear();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
exports.WatchCommand = WatchCommand;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Models.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Command-Line/files/Models.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Models.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Command-Line/files/Models.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAEH,QAAA,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,MASnC,CAAC;AA0EF,eAAe,WAAW,CAAC"}
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Config_1 = require("../../Config/Config");
|
|
3
4
|
/**
|
|
4
5
|
* Function to create a model file
|
|
5
6
|
* @param name - string
|
|
6
7
|
* @returns string
|
|
7
8
|
*/
|
|
8
9
|
const createModel = (name) => {
|
|
10
|
+
const dbOrm = Config_1.config.get("DB_ORM").toLowerCase();
|
|
11
|
+
if (dbOrm === "mongoose") {
|
|
12
|
+
return createMongooseModel(name);
|
|
13
|
+
}
|
|
14
|
+
if (dbOrm === "sequelize") {
|
|
15
|
+
return createSequelizeModel(name);
|
|
16
|
+
}
|
|
17
|
+
return createJccModel(name);
|
|
18
|
+
};
|
|
19
|
+
const createJccModel = (name) => {
|
|
9
20
|
return `
|
|
10
21
|
import {Model} from "jcc-express-mvc/Eloquent"
|
|
11
22
|
|
|
@@ -18,4 +29,60 @@ const createModel = (name) => {
|
|
|
18
29
|
|
|
19
30
|
`;
|
|
20
31
|
};
|
|
32
|
+
const createMongooseModel = (name) => {
|
|
33
|
+
return `
|
|
34
|
+
import mongoose, { HydratedDocument, InferSchemaType, Model, Schema } from "mongoose";
|
|
35
|
+
|
|
36
|
+
const ${name}Schema = new Schema(
|
|
37
|
+
{
|
|
38
|
+
//
|
|
39
|
+
},
|
|
40
|
+
{ timestamps: true }
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
type ${name}Attrs = InferSchemaType<typeof ${name}Schema>;
|
|
44
|
+
|
|
45
|
+
export const ${name}: Model<${name}Attrs> =
|
|
46
|
+
(mongoose.models.${name} as Model<${name}Attrs>) ||
|
|
47
|
+
mongoose.model<${name}Attrs>("${name}", ${name}Schema);
|
|
48
|
+
|
|
49
|
+
export type ${name}Document = HydratedDocument<${name}Attrs>;
|
|
50
|
+
`;
|
|
51
|
+
};
|
|
52
|
+
const createSequelizeModel = (name) => {
|
|
53
|
+
return `
|
|
54
|
+
import { Model, DataTypes, Sequelize } from "sequelize";
|
|
55
|
+
const sequelize = app.resolve<Sequelize>("sequelize");
|
|
56
|
+
//
|
|
57
|
+
export class ${name} extends Model {
|
|
58
|
+
declare id: number;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Define relationships between models
|
|
62
|
+
* @param models - Record<string, any>
|
|
63
|
+
*/
|
|
64
|
+
static associate(models: any) {
|
|
65
|
+
//
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
${name}.init(
|
|
71
|
+
{
|
|
72
|
+
id: {
|
|
73
|
+
type: DataTypes.INTEGER,
|
|
74
|
+
primaryKey: true,
|
|
75
|
+
autoIncrement: true,
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
sequelize,
|
|
81
|
+
tableName: "${name}",
|
|
82
|
+
timestamps: true,
|
|
83
|
+
modelName: "${name}",
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
`;
|
|
87
|
+
};
|
|
21
88
|
exports.default = createModel;
|
package/lib/Console/Command.d.ts
CHANGED
|
@@ -14,9 +14,27 @@ export declare abstract class Command {
|
|
|
14
14
|
/**
|
|
15
15
|
* Execute the console command.
|
|
16
16
|
*/
|
|
17
|
+
/**
|
|
18
|
+
* Log an info message.
|
|
19
|
+
* @param message - The message to log.
|
|
20
|
+
*/
|
|
17
21
|
protected info(message: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Log an error message.
|
|
24
|
+
* @param message - The message to log.
|
|
25
|
+
*/
|
|
18
26
|
protected error(message: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Log a success message.
|
|
29
|
+
* @param message - The message to log.
|
|
30
|
+
*/
|
|
19
31
|
protected success(message: string): void;
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param file - The file path to create.
|
|
35
|
+
* @param content - The content to write to the file.
|
|
36
|
+
*/
|
|
37
|
+
protected createFile(file: string, content: string): void;
|
|
20
38
|
abstract handle(...args: any[]): void | Promise<void>;
|
|
21
39
|
}
|
|
22
40
|
//# sourceMappingURL=Command.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Command.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Console/Command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Command.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Console/Command.ts"],"names":[],"mappings":"AAMA,8BAAsB,OAAO;IAC3B;;;;OAIG;IACH,SAAS,SAAM;IAEf;;;;OAIG;IACH,WAAW,SAAM;IAEjB;;OAEG;IAEH;;;OAGG;IACH,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIrC;;;OAGG;IACH,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAItC;;;OAGG;IACH,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIxC;;;;OAIG;IACH,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAWlD,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CACtD"}
|
package/lib/Console/Command.js
CHANGED
|
@@ -5,6 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Command = void 0;
|
|
7
7
|
const colors_1 = __importDefault(require("colors"));
|
|
8
|
+
const app_root_path_1 = __importDefault(require("app-root-path"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const rootPath = app_root_path_1.default.path;
|
|
8
12
|
class Command {
|
|
9
13
|
constructor() {
|
|
10
14
|
/**
|
|
@@ -23,14 +27,39 @@ class Command {
|
|
|
23
27
|
/**
|
|
24
28
|
* Execute the console command.
|
|
25
29
|
*/
|
|
30
|
+
/**
|
|
31
|
+
* Log an info message.
|
|
32
|
+
* @param message - The message to log.
|
|
33
|
+
*/
|
|
26
34
|
info(message) {
|
|
27
35
|
console.log(colors_1.default.blue(message));
|
|
28
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Log an error message.
|
|
39
|
+
* @param message - The message to log.
|
|
40
|
+
*/
|
|
29
41
|
error(message) {
|
|
30
42
|
console.log(colors_1.default.red(message));
|
|
31
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Log a success message.
|
|
46
|
+
* @param message - The message to log.
|
|
47
|
+
*/
|
|
32
48
|
success(message) {
|
|
33
49
|
console.log(colors_1.default.green(message));
|
|
34
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param file - The file path to create.
|
|
54
|
+
* @param content - The content to write to the file.
|
|
55
|
+
*/
|
|
56
|
+
createFile(file, content) {
|
|
57
|
+
const filePath = path_1.default.resolve(rootPath, file);
|
|
58
|
+
const dir = path_1.default.dirname(filePath);
|
|
59
|
+
if (!fs_1.default.existsSync(dir)) {
|
|
60
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
61
|
+
}
|
|
62
|
+
fs_1.default.writeFileSync(filePath, content);
|
|
63
|
+
}
|
|
35
64
|
}
|
|
36
65
|
exports.Command = Command;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Container/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Container/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKhE,8BAAsB,SAAS;IAC7B,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,SAAS,CAA+B;IAChD,OAAO,CAAC,OAAO,CAAkC;IAEjD,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAE,OAAe,GAAG,IAAI;IAI7D,IAAI,CAAC,CAAC,EACX,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EACjC,MAAM,GAAE,GAAG,EAAO,GACjB,CAAC,GAAG,SAAS;IAMhB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,UAAO,GAAG,IAAI;IAM/D,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI;IAQ/C,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAI5C,OAAO,CAAC,CAAC,EACP,QAAQ,EAAE,MAAM,EAChB,UAAU,GAAE,GAAG,EAAO,EACtB,WAAW,GAAE,OAAc,GAC1B,CAAC;IAsCJ,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,iBAAiB;IAazB,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,GAAE,GAAG,EAAO,GAAG,CAAC;IA2ClD;;;;;OAKG;IACG,oBAAoB,CAAC,CAAC,EAC1B,QAAQ,EAAE,GAAG,EACb,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,UAAU,EACf,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,CAAC,CAAC;IA+Cb,UAAU,CAAC,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;IAkD5D;;;OAGG;IACH,OAAO,CAAC,aAAa;IAMrB,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAQ9B,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAW9B,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI;CAKjC"}
|
package/lib/Container/index.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Container = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
|
-
const Jcc_eloquent_1 = require("../Jcc-eloquent");
|
|
6
5
|
const FormRequest_1 = require("../Request/FormRequest");
|
|
7
6
|
const util_1 = require("../util");
|
|
8
7
|
const AppError_1 = require("../Error/AppError");
|
|
@@ -143,7 +142,7 @@ class Container {
|
|
|
143
142
|
return requestInstance;
|
|
144
143
|
}
|
|
145
144
|
const resolved = this.resolve(dep.type);
|
|
146
|
-
if (
|
|
145
|
+
if ((0, util_1.isModelInstance)(resolved)) {
|
|
147
146
|
return await (0, util_1.resolveModelBinding)(req, dep.type, resolved);
|
|
148
147
|
}
|
|
149
148
|
return resolved;
|
|
@@ -161,13 +160,28 @@ class Container {
|
|
|
161
160
|
const methodDeps = Reflect.getMetadata("inject:method:deps", instance, methodName);
|
|
162
161
|
if (methodDeps && Array.isArray(methodDeps) && methodDeps.length > 0) {
|
|
163
162
|
const resolvedDeps = [];
|
|
164
|
-
for (const method of methodDeps) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
163
|
+
// for (const method of methodDeps) {
|
|
164
|
+
// if (
|
|
165
|
+
// !method.type ||
|
|
166
|
+
// !method.type.name ||
|
|
167
|
+
// method.type.name === "Object"
|
|
168
|
+
// ) {
|
|
169
|
+
// continue;
|
|
170
|
+
// }
|
|
171
|
+
// if(){
|
|
172
|
+
// }
|
|
173
|
+
// resolvedDeps.push(this.resolve(method.type));
|
|
174
|
+
// }
|
|
175
|
+
for (let index = 0; index < methodDeps.length; index++) {
|
|
176
|
+
const method = methodDeps[index];
|
|
177
|
+
if (method.type &&
|
|
178
|
+
method.type.name &&
|
|
179
|
+
(0, util_1.JSInBuilTClass)(method.type.name)) {
|
|
180
|
+
resolvedDeps.push(args[index] || null);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
resolvedDeps.push(this.resolve(method.type));
|
|
169
184
|
}
|
|
170
|
-
resolvedDeps.push(this.resolve(method.type));
|
|
171
185
|
}
|
|
172
186
|
return instance[methodName].apply(instance, resolvedDeps);
|
|
173
187
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DatabaseConfig } from "./type";
|
|
2
|
+
/**
|
|
3
|
+
* Database manager that resolves the appropriate driver based on config.
|
|
4
|
+
* Drivers: knex (Jcc-eloquent), sequelize, mongoose
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* const db = new Database(config);
|
|
8
|
+
* await db.connect();
|
|
9
|
+
* const client = db.getConnection(); // Knex | Sequelize | Mongoose
|
|
10
|
+
*/
|
|
11
|
+
export declare class Database {
|
|
12
|
+
private readonly app?;
|
|
13
|
+
private driver;
|
|
14
|
+
constructor(dbConfig?: Partial<DatabaseConfig>, app?: any | undefined);
|
|
15
|
+
private resolveDriverName;
|
|
16
|
+
private resolveDriver;
|
|
17
|
+
connect(): Promise<void>;
|
|
18
|
+
getConnection(): unknown;
|
|
19
|
+
disconnect(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=Database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Database.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Database/Database.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAMxC;;;;;;;;GAQG;AACH,qBAAa,QAAQ;IAKjB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;IAJvB,OAAO,CAAC,MAAM,CAAiB;gBAG7B,QAAQ,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,EACjB,GAAG,CAAC,EAAE,GAAG,YAAA;IAM5B,OAAO,CAAC,iBAAiB;IAgBzB,OAAO,CAAC,aAAa;IAef,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,aAAa,IAAI,OAAO;IAIlB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAGlC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Database = void 0;
|
|
4
|
+
const KnexDriver_1 = require("./Drivers/KnexDriver");
|
|
5
|
+
const SequelizeDriver_1 = require("./Drivers/SequelizeDriver");
|
|
6
|
+
const MongooseDriver_1 = require("./Drivers/MongooseDriver");
|
|
7
|
+
const Config_1 = require("../Config/Config");
|
|
8
|
+
/**
|
|
9
|
+
* Database manager that resolves the appropriate driver based on config.
|
|
10
|
+
* Drivers: knex (Jcc-eloquent), sequelize, mongoose
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* const db = new Database(config);
|
|
14
|
+
* await db.connect();
|
|
15
|
+
* const client = db.getConnection(); // Knex | Sequelize | Mongoose
|
|
16
|
+
*/
|
|
17
|
+
class Database {
|
|
18
|
+
constructor(dbConfig, app) {
|
|
19
|
+
this.app = app;
|
|
20
|
+
const driverName = this.resolveDriverName(dbConfig);
|
|
21
|
+
this.driver = this.resolveDriver(driverName, app);
|
|
22
|
+
}
|
|
23
|
+
resolveDriverName(dbConfig) {
|
|
24
|
+
if (dbConfig?.driver)
|
|
25
|
+
return dbConfig.driver;
|
|
26
|
+
const connection = Config_1.config.get("DB_CONNECTION", "mysql2").toLowerCase();
|
|
27
|
+
const orm = Config_1.config.get("DB_ORM", "jcc").toLowerCase();
|
|
28
|
+
if (connection === "mongodb" || orm === "mongoose")
|
|
29
|
+
return "mongoose";
|
|
30
|
+
if (connection === "sequelize" || orm === "sequelize")
|
|
31
|
+
return "sequelize";
|
|
32
|
+
return "knex"; // Default: Knex / Jcc-eloquent
|
|
33
|
+
}
|
|
34
|
+
resolveDriver(driverName, app) {
|
|
35
|
+
switch (driverName) {
|
|
36
|
+
case "sequelize":
|
|
37
|
+
return new SequelizeDriver_1.SequelizeDriver(app?.config?.database?.sequelize);
|
|
38
|
+
case "mongoose":
|
|
39
|
+
return new MongooseDriver_1.MongooseDriver(app?.config?.database?.mongoose);
|
|
40
|
+
case "knex":
|
|
41
|
+
default:
|
|
42
|
+
return new KnexDriver_1.KnexDriver();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async connect() {
|
|
46
|
+
await this.driver.connect();
|
|
47
|
+
}
|
|
48
|
+
getConnection() {
|
|
49
|
+
return this.driver.getConnection();
|
|
50
|
+
}
|
|
51
|
+
async disconnect() {
|
|
52
|
+
await this.driver.disconnect();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.Database = Database;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Application } from "../Application/Application";
|
|
2
|
+
import { ServiceProvider } from "../Providers/ServiceProvider";
|
|
3
|
+
/**
|
|
4
|
+
* Database service provider.
|
|
5
|
+
* Registers the database connection and loads models for Sequelize/Mongoose.
|
|
6
|
+
*/
|
|
7
|
+
export declare class DatabaseServiceProvider extends ServiceProvider {
|
|
8
|
+
constructor(app: Application);
|
|
9
|
+
/**
|
|
10
|
+
* Register the database service
|
|
11
|
+
*/
|
|
12
|
+
register(): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Boot the database service (load Sequelize models, etc.)
|
|
15
|
+
*/
|
|
16
|
+
boot(): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* True when using Sequelize or Mongoose instead of Jcc-eloquent (Knex)
|
|
19
|
+
*/
|
|
20
|
+
externalSupportedORM(): boolean;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=DatabaseServiceProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DatabaseServiceProvider.d.ts","sourceRoot":"","sources":["../../../jcc-express-mvc/lib/Database/DatabaseServiceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAG/D;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,eAAe;gBAC9C,GAAG,EAAE,WAAW;IAI5B;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAc/B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAE3B;;OAEG;IACH,oBAAoB,IAAI,OAAO;CAWhC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseServiceProvider = void 0;
|
|
4
|
+
const Database_1 = require("./Database");
|
|
5
|
+
const ServiceProvider_1 = require("../Providers/ServiceProvider");
|
|
6
|
+
const Config_1 = require("../Config/Config");
|
|
7
|
+
/**
|
|
8
|
+
* Database service provider.
|
|
9
|
+
* Registers the database connection and loads models for Sequelize/Mongoose.
|
|
10
|
+
*/
|
|
11
|
+
class DatabaseServiceProvider extends ServiceProvider_1.ServiceProvider {
|
|
12
|
+
constructor(app) {
|
|
13
|
+
super(app);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Register the database service
|
|
17
|
+
*/
|
|
18
|
+
async register() {
|
|
19
|
+
if (!this.externalSupportedORM())
|
|
20
|
+
return;
|
|
21
|
+
const db = this.app.make(Database_1.Database, [undefined, this.app]);
|
|
22
|
+
db.connect();
|
|
23
|
+
this.app.singleton("database.connection", () => db.getConnection());
|
|
24
|
+
if (Config_1.config.get("DB_ORM") === "sequelize") {
|
|
25
|
+
this.app.alias("database.connection", "sequelize");
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.app.alias("database.connection", "mongoose");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Boot the database service (load Sequelize models, etc.)
|
|
33
|
+
*/
|
|
34
|
+
async boot() { }
|
|
35
|
+
/**
|
|
36
|
+
* True when using Sequelize or Mongoose instead of Jcc-eloquent (Knex)
|
|
37
|
+
*/
|
|
38
|
+
externalSupportedORM() {
|
|
39
|
+
const dbConnection = Config_1.config.get("DB_CONNECTION");
|
|
40
|
+
const dbOrm = Config_1.config.get("DB_ORM");
|
|
41
|
+
const supportedConnections = [
|
|
42
|
+
"mysql2",
|
|
43
|
+
"postgres",
|
|
44
|
+
"sqlite",
|
|
45
|
+
"better-sqlite3",
|
|
46
|
+
];
|
|
47
|
+
return dbOrm !== "jcc" || !supportedConnections.includes(dbConnection);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.DatabaseServiceProvider = DatabaseServiceProvider;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DatabaseDriver } from "../interface";
|
|
2
|
+
import type { Knex } from "knex";
|
|
3
|
+
/**
|
|
4
|
+
* Knex driver wrapping Jcc-eloquent (your ORM built on Knex).
|
|
5
|
+
* Uses DB_CONNECTION, DB_HOST, DB_PORT, etc. from config.
|
|
6
|
+
*/
|
|
7
|
+
export declare class KnexDriver implements DatabaseDriver {
|
|
8
|
+
private connected;
|
|
9
|
+
connect(): Promise<void>;
|
|
10
|
+
getConnection(): Knex;
|
|
11
|
+
disconnect(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=KnexDriver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnexDriver.d.ts","sourceRoot":"","sources":["../../../../jcc-express-mvc/lib/Database/Drivers/KnexDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAEjC;;;GAGG;AACH,qBAAa,UAAW,YAAW,cAAc;IAC/C,OAAO,CAAC,SAAS,CAAS;IAEpB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAM9B,aAAa,IAAI,IAAI;IAIf,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAKlC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KnexDriver = void 0;
|
|
4
|
+
const Database_1 = require("../../Jcc-eloquent/lib/Database");
|
|
5
|
+
/**
|
|
6
|
+
* Knex driver wrapping Jcc-eloquent (your ORM built on Knex).
|
|
7
|
+
* Uses DB_CONNECTION, DB_HOST, DB_PORT, etc. from config.
|
|
8
|
+
*/
|
|
9
|
+
class KnexDriver {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.connected = false;
|
|
12
|
+
}
|
|
13
|
+
async connect() {
|
|
14
|
+
if (this.connected)
|
|
15
|
+
return;
|
|
16
|
+
Database_1.Database.connect();
|
|
17
|
+
this.connected = true;
|
|
18
|
+
}
|
|
19
|
+
getConnection() {
|
|
20
|
+
return Database_1.Database.connection();
|
|
21
|
+
}
|
|
22
|
+
async disconnect() {
|
|
23
|
+
if (!this.connected)
|
|
24
|
+
return;
|
|
25
|
+
await Database_1.Database.disconnect();
|
|
26
|
+
this.connected = false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.KnexDriver = KnexDriver;
|