jcc-express-mvc 1.2.6 → 1.2.8

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.
Files changed (112) hide show
  1. package/{dist/index.js → index.js} +5 -3
  2. package/lib/Command-Line/NodeArtisanCommand.js +69 -0
  3. package/lib/Command-Line/command.js +111 -0
  4. package/{Command-Line → lib/Command-Line}/files/Controller.js +4 -3
  5. package/{Command-Line → lib/Command-Line}/files/Migration.js +5 -4
  6. package/{Command-Line → lib/Command-Line}/files/Models.js +4 -3
  7. package/{Command-Line → lib/Command-Line}/files/Request.js +5 -4
  8. package/{Command-Line → lib/Command-Line}/files/ResourcesController.js +5 -5
  9. package/lib/Command-Line/utils.js +14 -0
  10. package/package.json +2 -2
  11. package/Command-Line/NodeArtisanCommand.js +0 -93
  12. package/Command-Line/NodeTinker/db/index.js +0 -17
  13. package/Command-Line/NodeTinker/getInput.js +0 -7
  14. package/Command-Line/NodeTinker/index.js +0 -53
  15. package/Command-Line/NodeTinker/repl.js +0 -28
  16. package/Command-Line/command.js +0 -134
  17. package/Command-Line/utils.js +0 -11
  18. package/Database/src/BaseEntity.ts +0 -247
  19. package/Database/src/BaseModel.ts +0 -51
  20. package/Database/src/Builder.ts +0 -498
  21. package/Database/src/Cast/index.ts +0 -126
  22. package/Database/src/Cast/types.ts +0 -24
  23. package/Database/src/Date/index.ts +0 -52
  24. package/Database/src/Model.ts +0 -55
  25. package/Database/src/Query.ts +0 -13
  26. package/Database/src/QueryBuilder.ts +0 -426
  27. package/Database/src/QueryInstance.ts +0 -28
  28. package/Database/src/RelationBuilder.ts +0 -119
  29. package/Database/src/Schema/BaseSchemaEntity/index.ts +0 -32
  30. package/Database/src/Schema/BluePrint/index.ts +0 -287
  31. package/Database/src/Schema/index.ts +0 -15
  32. package/Database/src/Schema/migrationContent.js +0 -19
  33. package/Database/src/db/connection.ts +0 -17
  34. package/Database/src/type.ts +0 -18
  35. package/Database/src/utils/index.ts +0 -122
  36. package/index.ts +0 -36
  37. package/lib/App.ts +0 -46
  38. package/lib/Auth/AuthMiddleware.ts +0 -47
  39. package/lib/Auth/index.ts +0 -110
  40. package/lib/Config/Config.ts +0 -17
  41. package/lib/Error/AppError.ts +0 -11
  42. package/lib/Error/AppErrorHandler.ts +0 -41
  43. package/lib/Error/Constants/error.ts +0 -23
  44. package/lib/Error/Constants/index.ts +0 -5
  45. package/lib/Error/public/pageNotFound.html +0 -28
  46. package/lib/HttpKernel/HttpKernel.ts +0 -12
  47. package/lib/Interface/index.ts +0 -39
  48. package/lib/Middlewares/index.ts +0 -125
  49. package/lib/Middlewares/isLogin.ts +0 -29
  50. package/lib/Passport/config.ts +0 -74
  51. package/lib/Request/FormRequest.ts +0 -58
  52. package/lib/Request/request.ts +0 -44
  53. package/lib/Response/index.ts +0 -52
  54. package/lib/Routes/RouteBuilder.ts +0 -133
  55. package/lib/Routes/Router.ts +0 -145
  56. package/lib/Server/index.ts +0 -40
  57. package/lib/Services/ServiceContainer.ts +0 -34
  58. package/lib/Services/ServiceProvider.ts +0 -58
  59. package/lib/Templating-engine/engineHelper.ts +0 -138
  60. package/lib/Templating-engine/expressions.ts +0 -18
  61. package/lib/Templating-engine/index.ts +0 -242
  62. package/lib/Type/index.ts +0 -28
  63. package/lib/Validation/index.ts +0 -96
  64. package/lib/Validation/rules.ts +0 -107
  65. package/lib/Validation/validate.ts +0 -370
  66. package/lib/util/index.ts +0 -179
  67. /package/{dist/lib → lib}/App.js +0 -0
  68. /package/{dist/lib → lib}/Auth/AuthMiddleware.js +0 -0
  69. /package/{dist/lib → lib}/Auth/index.js +0 -0
  70. /package/{dist/lib → lib}/Config/Config.js +0 -0
  71. /package/{dist → lib}/Database/src/BaseEntity.js +0 -0
  72. /package/{dist → lib}/Database/src/BaseModel.js +0 -0
  73. /package/{dist → lib}/Database/src/Builder.js +0 -0
  74. /package/{dist → lib}/Database/src/Cast/index.js +0 -0
  75. /package/{dist → lib}/Database/src/Cast/types.js +0 -0
  76. /package/{dist → lib}/Database/src/Date/index.js +0 -0
  77. /package/{dist → lib}/Database/src/Model.js +0 -0
  78. /package/{dist → lib}/Database/src/Query.js +0 -0
  79. /package/{dist → lib}/Database/src/QueryBuilder.js +0 -0
  80. /package/{dist → lib}/Database/src/QueryInstance.js +0 -0
  81. /package/{dist → lib}/Database/src/RelationBuilder.js +0 -0
  82. /package/{dist → lib}/Database/src/Schema/BaseSchemaEntity/index.js +0 -0
  83. /package/{dist → lib}/Database/src/Schema/BluePrint/index.js +0 -0
  84. /package/{dist → lib}/Database/src/Schema/index.js +0 -0
  85. /package/{dist → lib}/Database/src/db/connection.js +0 -0
  86. /package/{dist → lib}/Database/src/type.js +0 -0
  87. /package/{dist → lib}/Database/src/utils/index.js +0 -0
  88. /package/{dist/lib → lib}/Error/AppError.js +0 -0
  89. /package/{dist/lib → lib}/Error/AppErrorHandler.js +0 -0
  90. /package/{dist/lib → lib}/Error/Constants/error.js +0 -0
  91. /package/{dist/lib → lib}/Error/Constants/index.js +0 -0
  92. /package/{dist/lib → lib}/HttpKernel/HttpKernel.js +0 -0
  93. /package/{dist/lib → lib}/Interface/index.js +0 -0
  94. /package/{dist/lib → lib}/Middlewares/index.js +0 -0
  95. /package/{dist/lib → lib}/Middlewares/isLogin.js +0 -0
  96. /package/{dist/lib → lib}/Passport/config.js +0 -0
  97. /package/{dist/lib → lib}/Request/FormRequest.js +0 -0
  98. /package/{dist/lib → lib}/Request/request.js +0 -0
  99. /package/{dist/lib → lib}/Response/index.js +0 -0
  100. /package/{dist/lib → lib}/Routes/RouteBuilder.js +0 -0
  101. /package/{dist/lib → lib}/Routes/Router.js +0 -0
  102. /package/{dist/lib → lib}/Server/index.js +0 -0
  103. /package/{dist/lib → lib}/Services/ServiceContainer.js +0 -0
  104. /package/{dist/lib → lib}/Services/ServiceProvider.js +0 -0
  105. /package/{dist/lib → lib}/Templating-engine/engineHelper.js +0 -0
  106. /package/{dist/lib → lib}/Templating-engine/expressions.js +0 -0
  107. /package/{dist/lib → lib}/Templating-engine/index.js +0 -0
  108. /package/{dist/lib → lib}/Type/index.js +0 -0
  109. /package/{dist/lib → lib}/Validation/index.js +0 -0
  110. /package/{dist/lib → lib}/Validation/rules.js +0 -0
  111. /package/{dist/lib → lib}/Validation/validate.js +0 -0
  112. /package/{dist/lib → lib}/util/index.js +0 -0
@@ -1,134 +0,0 @@
1
- const path = require("path");
2
- const fs = require("fs");
3
- const appRootPath = require("app-root-path");
4
- const createController = require("./files/Controller");
5
- const createModel = require("./files/Models");
6
- const resourceController = require("./files/ResourcesController");
7
- const createRequest = require("./files/Request");
8
- const createMigration = require("./files/Migration");
9
- const colors = require("colors"); // Module for adding color to console output
10
- const { formatDate } = require("./utils");
11
-
12
- const rootPath = appRootPath.path;
13
-
14
- class Command {
15
- // Method to add a web controller
16
- addWeb(controllerName, modelName = false) {
17
- try {
18
- let webControllerPath = path.resolve(`${rootPath}/app/Http/Controllers`); // Resolve path to web controllers directory
19
- if (fs.existsSync(`${webControllerPath}/${controllerName}.ts`)) {
20
- // Check if controller file already exists
21
- return console.log(`${controllerName} already exist`.yellow); // Log a warning if controller already exists
22
- }
23
- if (modelName && typeof modelName === "string") {
24
- // If model name is provided, create a resource controller
25
- fs.writeFileSync(
26
- `${webControllerPath}/${controllerName}.ts`,
27
- resourceController(controllerName, modelName),
28
- );
29
- return console.log(`${controllerName} added successfully`.green); // Log success message
30
- }
31
- fs.writeFileSync(
32
- `${webControllerPath}/${controllerName}.ts`,
33
- createController(controllerName), // Create a basic controller file
34
- );
35
-
36
- return console.log(`${controllerName} added successfully`.green); // Log success message
37
- } catch (err) {
38
- console.log(`${controllerName} admin controller not added`.red); // Log error if controller addition fails
39
- }
40
- }
41
-
42
- // Method to add an API controller
43
- addApi(controllerName, modelName = false) {
44
- try {
45
- let apiPath = path.resolve(`${rootPath}/app/Http/ApiControllers`); // Resolve path to API controllers directory
46
- if (fs.existsSync(`${apiPath}/${controllerName}.ts`)) {
47
- // Check if API controller file already exists
48
- return console.log(
49
- `${controllerName} api controller already exist`.yellow,
50
- ); // Log a warning if API controller already exists
51
- }
52
- if (modelName && typeof modelName === "string") {
53
- // If model name is provided, create a resource controller
54
- fs.writeFileSync(
55
- `${apiPath}/${controllerName}.ts`,
56
- resourceController(controllerName, modelName),
57
- );
58
- return console.log(`${controllerName} added successfully`.green); // Log success message
59
- }
60
- fs.writeFileSync(
61
- `${apiPath}/${controllerName}.ts`,
62
- createController(controllerName), // Create a basic controller file
63
- );
64
- return console.log(`${controllerName} added successfully`.green); // Log success message
65
- } catch (err) {
66
- console.log(err.message);
67
- console.log(`${controllerName} api controller not added`.red); // Log error if controller addition fails
68
- }
69
- }
70
-
71
- // Method to add a model
72
- addModel(modelName) {
73
- try {
74
- let modelPath = path.resolve(`${rootPath}/app/Models`); // Resolve path to models directory
75
- if (fs.existsSync(`${modelPath}/${modelName}.ts`)) {
76
- // Check if model file already exists
77
- return console.log(`${modelName} model already exist`.yellow); // Log a warning if model already exists
78
- }
79
- fs.writeFileSync(`${modelPath}/${modelName}.ts`, createModel(modelName)); // Create a model file
80
- return console.log(`${modelName} model added successfully`.green); // Log success message
81
- } catch (err) {
82
- return console.log(`${modelName} model not added`.red); // Log error if model addition fails
83
- }
84
- }
85
-
86
- // Method to add a request file
87
- addRequest(requestName) {
88
- try {
89
- let requestPath = path.resolve(`${rootPath}/app/Http/Requests`); // Resolve path to request files directory
90
- if (fs.existsSync(`${requestPath}/${requestName}.ts`)) {
91
- // Check if request file already exists
92
- return console.log(`${requestName} already exist`.yellow); // Log a warning if request file already exists
93
- }
94
-
95
- fs.writeFileSync(
96
- `${requestPath}/${requestName}.ts`,
97
- createRequest(requestName), // Create a request file
98
- );
99
- return console.log(`${requestName} added successfully`.green); // Log success message
100
- } catch (err) {
101
- return console.log(`${requestName} request not added`.red, { err }); // Log error if request addition fails
102
- }
103
- }
104
-
105
- // Method to add a request file
106
- addMigration(migrationName) {
107
- try {
108
- const tableName = migrationName.replace(/(create_|_table)/g, "");
109
-
110
- let migrationPath = path.resolve(`${rootPath}/database/migrations`);
111
- // Resolve path to request files directory
112
- const fullName = `${formatDate()}_${migrationName}`;
113
- if (fs.existsSync(`${migrationPath}/${fullName}.ts`)) {
114
- // Check if request file already exists
115
- return console.log(`${tableName} already exist`.yellow); // Log a warning if request file already exists
116
- }
117
-
118
- fs.writeFileSync(
119
- `${migrationPath}/${fullName}.ts`,
120
- createMigration(tableName), // Create a request file
121
- );
122
- return console.log(`${fullName} added successfully`.green); // Log success message
123
- } catch (err) {
124
- return console.log(`${fullName} request not added`.red, { err }); // Log error if request addition fails
125
- }
126
- }
127
-
128
- // Method to handle a command not found
129
- notFound() {
130
- return console.log(`Command not found`.bgRed); // Log a message indicating the command was not found
131
- }
132
- }
133
-
134
- module.exports = new Command(); // Export an instance of the Command class
@@ -1,11 +0,0 @@
1
- exports.formatDate = () => {
2
- const date = new Date();
3
- const year = date.getFullYear();
4
- const month = String(date.getMonth() + 1).padStart(2, "0");
5
- const day = String(date.getDate()).padStart(2, "0");
6
- const hours = String(date.getHours()).padStart(2, "0");
7
- const minutes = String(date.getMinutes()).padStart(2, "0");
8
- const seconds = String(date.getSeconds()).padStart(2, "0");
9
-
10
- return `${year}_${month}_${day}_${hours}_${minutes}_${seconds}`;
11
- };
@@ -1,247 +0,0 @@
1
- import { objType } from "./type";
2
- import { Database } from "./db/connection";
3
- import { QueryInstance } from "./QueryInstance";
4
- import { Cast } from "./Cast";
5
-
6
- export class BaseEntity extends Database {
7
- protected attributes: objType = {};
8
- protected _select: string | Array<string> = "*";
9
- protected _tableName: string = "";
10
- protected _where: Array<any> = [];
11
- protected _joins: Array<any> = [];
12
- protected _orderBy?: string;
13
- protected _limit?: string | number;
14
- protected _offset?: string | number;
15
- protected _groupBy?: string;
16
- protected _having?: string;
17
- protected _distinct: boolean = false;
18
- protected _insertData: { keys: Array<any>; values: Array<any> } = {
19
- keys: [],
20
- values: [],
21
- };
22
- protected _updateData: objType = {}; //{ keys: Array<any>; values: Array<any> };
23
- protected _delete?: boolean;
24
- protected _count?: boolean;
25
- protected _relationships: Array<any> = [];
26
- protected fillable: Array<string> = [];
27
- protected guard: Array<string> = [];
28
- protected hidden: Array<string> = [];
29
- protected casts?: object;
30
- protected _max: string = "";
31
- protected _min: string = "";
32
- protected _sum: string = "";
33
- protected _avg: string = "";
34
- protected sqlQuery: string = "";
35
-
36
- /**
37
- * Resets all query builder state variables to their default values.
38
- */
39
- public _resetQuery() {
40
- this._select = "*";
41
- this._tableName = "";
42
- this._where = [];
43
- this._joins = [];
44
- this._orderBy = "";
45
- this._limit = "";
46
- this._offset = "";
47
- this._groupBy = "";
48
- this._having = "";
49
- this._distinct = false;
50
- this._insertData = { keys: [], values: [] };
51
- this._updateData = {};
52
- this._delete = false;
53
- this._count = false;
54
- this._relationships = [];
55
- this._max = "";
56
- this._min = "";
57
- this._sum = "";
58
- this._avg = "";
59
- return;
60
- }
61
-
62
- /**
63
- * Constructs and returns the SQL query based on the current query builder state.
64
- *
65
- * @returns {string} The generated SQL query.
66
- */
67
- private compileToSql(): void {
68
- if (this._count) {
69
- this.sqlQuery += this.buildCount();
70
- } else if (this._sum) {
71
- this.sqlQuery += this.buildSum();
72
- } else if (this._avg) {
73
- this.sqlQuery += this.buildAvg();
74
- } else if (this._max) {
75
- this.sqlQuery += this.buildMax();
76
- } else if (this._min) {
77
- this.sqlQuery += this.buildMin();
78
- } else if (Object.values(this._insertData.keys).length > 1) {
79
- this.sqlQuery += this.buidInsert();
80
- } else if (Object.values(this._updateData).length > 1) {
81
- this.sqlQuery += this.buildUpdate();
82
- } else if (this._delete) {
83
- this.sqlQuery += this.buildDelete();
84
- } else {
85
- this.sqlQuery += this.buildselect();
86
- }
87
-
88
- if (this._joins.length > 0) {
89
- this.sqlQuery += this.buildJoin();
90
- }
91
-
92
- if (this._where.length > 0) {
93
- this.sqlQuery += this.buildWhere();
94
- }
95
-
96
- if (this._groupBy) {
97
- this.sqlQuery += this.buildGroup();
98
- }
99
-
100
- if (this._having) {
101
- this.sqlQuery += this.buildHaving();
102
- }
103
-
104
- if (this._orderBy) {
105
- this.sqlQuery += this.buildOrderBy();
106
- }
107
-
108
- if (this._limit) {
109
- this.sqlQuery += this.buildLimit();
110
- }
111
-
112
- if (this._offset) {
113
- this.sqlQuery += this.buildOffset();
114
- }
115
- }
116
-
117
- private buidInsert(): string {
118
- return `INSERT INTO ${this._tableName} (${this._insertData.keys.join(
119
- ",",
120
- )}) VALUES (${this._insertData.values.join(", ")})`;
121
- }
122
-
123
- private buildUpdate(): string {
124
- let updateString = Object.keys(this._updateData)
125
- .map((key: string) => `${key}='${this._updateData[key]}'`)
126
- .join(", ");
127
- return `UPDATE ${this._tableName} SET ${updateString}`;
128
- }
129
-
130
- private buildJoin(): string {
131
- return this._joins
132
- .map((join) => {
133
- ` ${join.type} JOIN ${join.table} ON ${join.firstColumn} ${join.operator} ${join.secondColumn}`;
134
- })
135
- .join();
136
- }
137
- // private buildSelect(): string {}
138
-
139
- private buildOffset(): string {
140
- return ` OFFSET ${this._offset}`;
141
- }
142
-
143
- private buildselect(): string {
144
- return `SELECT ${this._distinct ? "DISTINCT " : ""}${this._select} FROM ${
145
- this._tableName
146
- }`;
147
- }
148
-
149
- private buildDelete(): string {
150
- return `DELETE FROM ${this._tableName}`;
151
- }
152
-
153
- private buildWhere(): string {
154
- return (
155
- " WHERE " +
156
- this._where
157
- .map((condition, index) => {
158
- const connector =
159
- index > 0 && condition.connector
160
- ? ` ${condition.connector} `
161
- : index > 0
162
- ? " AND "
163
- : "";
164
- return `${connector}${condition.column} ${condition.operator} '${condition.value}'`;
165
- })
166
- .join("")
167
- );
168
- }
169
-
170
- private buildCount(): string {
171
- return `SELECT COUNT(*) as count FROM ${this._tableName}`;
172
- }
173
-
174
- private buildMin(): string {
175
- return `SELECT MIN(${this._min}) FROM ${this._tableName}`;
176
- }
177
-
178
- private buildMax(): string {
179
- return `SELECT MAX(${this._max}) FROM ${this._tableName} `;
180
- }
181
-
182
- private buildAvg(): string {
183
- return `SELECT MAX(${this._avg}) FROM ${this._tableName} `;
184
- }
185
-
186
- private buildSum(): string {
187
- return `SELECT SUM(${this._sum}) FROM ${this._tableName} `;
188
- }
189
-
190
- private buildHaving(): string {
191
- return ` HAVING ${this._having}`;
192
- }
193
-
194
- private buildGroup(): string {
195
- return ` GROUP BY ${this._groupBy}`;
196
- }
197
-
198
- private buildOrderBy(): string {
199
- return ` ORDER BY ${this._orderBy}`;
200
- }
201
-
202
- private buildLimit(): string {
203
- return ` LIMIT ${this._limit}`;
204
- }
205
-
206
- protected getCompileSqlCode(): string {
207
- this.compileToSql();
208
- // this._resetQuery();
209
- let sql = this.sqlQuery;
210
- this.sqlQuery = "";
211
- return sql;
212
- }
213
-
214
- public setGuard(values: Array<string>): void {
215
- this.guard = values;
216
- }
217
-
218
- public setFillable(values: Array<string>): void {
219
- this.fillable = values;
220
- }
221
-
222
- public setHidden(values: Array<string>): void {
223
- this.hidden = values;
224
- }
225
-
226
- public setCasts(values: objType): void {
227
- this.casts = values;
228
- }
229
-
230
- private removeHiddenValues(item: any): objType {
231
- const keysSet = new Set(this.hidden);
232
- const newItem = { ...item };
233
- for (const key of keysSet) {
234
- delete newItem[key as keyof typeof item];
235
- }
236
- return newItem;
237
- }
238
-
239
- protected newInstance<T>(results: objType): QueryInstance<T> {
240
- return results.map(
241
- (result: T) =>
242
- new QueryInstance<T>(
243
- Cast.getCastType(this.casts || {}, this.removeHiddenValues(result)),
244
- ),
245
- );
246
- }
247
- }
@@ -1,51 +0,0 @@
1
- import { objType } from "./type";
2
- import { QueryBuilder } from "./QueryBuilder";
3
- import { extractFirst } from "./utils";
4
-
5
- export class BaseModel extends QueryBuilder {
6
- /**
7
- * Defines a hasMany relationship between the current model and another model.
8
- *
9
- * @param {string} relatedModel - The name of the related model.
10
- * @param {string} foreingKey - The foreign key in the related model (defaults to id).
11
- * @param {string} localKey - The local key in the current model (defaults to 'id').
12
- * @returns {Function} A function that retrieves the related data based on the relationship.
13
- */
14
- protected hasMany(
15
- relatedModel: string,
16
- foreingKey: string,
17
- localKey: string = "id",
18
- ): any {
19
- return async (query: objType | Array<objType> = {}) => {
20
- const result = extractFirst(query);
21
- const value = result[localKey];
22
- return {
23
- results: this.select().table(relatedModel).where(foreingKey, value),
24
- type: "hasMany",
25
- };
26
- };
27
- }
28
-
29
- /**
30
- * Defines a belongsTo relationship between the current model and another model.
31
- *
32
- * @param {string} relatedModel - The name of the related model.
33
- * @param {string} foreingKey - The foreign key in the related model (defaults to id).
34
- * @param {string} localKey - The local key in the current model (defaults to 'id').
35
- * @returns {Function} A function that retrieves the related data based on the relationship.
36
- */
37
- protected belongsTo(
38
- relatedModel: string,
39
- foreingKey: string,
40
- localKey: string = "id",
41
- ): any {
42
- return async (query: objType | Array<objType> = {}) => {
43
- const result = extractFirst(query);
44
- const value = result[foreingKey];
45
- return {
46
- results: this.select().table(relatedModel).where(localKey, value),
47
- type: "belongsTo",
48
- };
49
- };
50
- }
51
- }