beech-api 3.9.0-beta.9-rc → 3.9.75

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 (59) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1715 -1649
  3. package/index.js +2 -2
  4. package/package.json +92 -84
  5. package/packages/cli/beech +9 -10
  6. package/packages/cli/bin/beech-app.js +390 -390
  7. package/packages/cli/bin/beech-service.js +263 -170
  8. package/packages/cli/core/auth/Credentials.js +174 -174
  9. package/packages/cli/core/auth/Passport.js +664 -664
  10. package/packages/cli/core/auth/_Request.js +12 -12
  11. package/packages/cli/core/configure/_gitignore +16 -15
  12. package/packages/cli/core/configure/_sequelizerc +9 -9
  13. package/packages/cli/core/configure/app.config-basic.js +55 -55
  14. package/packages/cli/core/configure/app.config-sequelize.js +88 -88
  15. package/packages/cli/core/configure/beech.config.js +9 -9
  16. package/packages/cli/core/configure/global.config-basic.js +8 -8
  17. package/packages/cli/core/configure/global.config-sequelize.js +8 -8
  18. package/packages/cli/core/configure/jest.config.js +6 -6
  19. package/packages/cli/core/configure/jsconfig.json +8 -7
  20. package/packages/cli/core/configure/passport.config.js +97 -97
  21. package/packages/cli/core/databases/mysql.js +94 -95
  22. package/packages/cli/core/databases/sequelize.js +187 -188
  23. package/packages/cli/core/databases/test.js +250 -255
  24. package/packages/cli/core/file-walk/file-walk.js +35 -35
  25. package/packages/cli/core/generator/_endpoints +15 -15
  26. package/packages/cli/core/generator/_endpoints_basic +42 -42
  27. package/packages/cli/core/generator/_help +26 -18
  28. package/packages/cli/core/generator/_help_create +10 -10
  29. package/packages/cli/core/generator/_help_service +10 -10
  30. package/packages/cli/core/generator/_helpers +9 -9
  31. package/packages/cli/core/generator/_helpers_basic +22 -22
  32. package/packages/cli/core/generator/_models +6 -6
  33. package/packages/cli/core/generator/_models_basic +13 -13
  34. package/packages/cli/core/generator/_package +23 -19
  35. package/packages/cli/core/generator/_scheduler +32 -32
  36. package/packages/cli/core/generator/_spec +29 -29
  37. package/packages/cli/core/generator/index.js +1081 -992
  38. package/packages/cli/core/helpers/2fa.js +106 -106
  39. package/packages/cli/core/helpers/math.js +115 -115
  40. package/packages/cli/core/helpers/poolEntity.js +103 -103
  41. package/packages/cli/core/index.js +264 -266
  42. package/packages/cli/core/middleware/express/duplicateRequest.js +16 -16
  43. package/packages/cli/core/middleware/express/jwtCheckAllow.js +85 -85
  44. package/packages/cli/core/middleware/express/rateLimit.js +29 -29
  45. package/packages/cli/core/middleware/express/slowDown.js +2 -2
  46. package/packages/cli/core/middleware/index.js +6 -6
  47. package/packages/cli/core/middleware/origin/guard/advance.js +75 -75
  48. package/packages/cli/core/middleware/origin/whitelist/cors.js +94 -94
  49. package/packages/cli/core/services/http.express.js +481 -481
  50. package/packages/cli/core/test/check-node.js +21 -21
  51. package/packages/cli/core/test/utils.js +7 -7
  52. package/packages/cli/entry +10 -0
  53. package/packages/lib/index.js +6 -6
  54. package/packages/lib/src/endpoint.js +947 -885
  55. package/packages/lib/src/guard.js +60 -60
  56. package/packages/lib/src/salt.js +3 -3
  57. package/packages/lib/src/schema.js +96 -96
  58. package/packages/lib/src/specificExpress.js +7 -7
  59. package/packages/lib/src/user.js +271 -271
@@ -1,256 +1,251 @@
1
- const logUpdate = require("log-update");
2
- const emoji = require('node-emoji')
3
- const { DeHashIt, M, X } = require(__dirname + "/../helpers/math");
4
- const Sequelize = require('sequelize');
5
- const fs = require("fs");
6
- let testSql = {};
7
-
8
- function filterDbIsTrue(dbConfig, cb) {
9
- try {
10
- let dbIsTrue = [];
11
- dbConfig.filter((e, k) => {
12
- if (e.is_connect) {
13
- dbIsTrue.push(e);
14
- }
15
- if (dbConfig.length == k + 1) {
16
- if(dbIsTrue.length) {
17
- console.log('\n Pre-Flight  Testing Database connection:');
18
- }
19
- setTimeout(() => {
20
- cb(null, dbIsTrue);
21
- }, 200);
22
- }
23
- });
24
- } catch (error) {
25
- cb(error, null);
26
- }
27
- }
28
-
29
- function testConnectInProcess(database_config, dbConnTotal, cb) {
30
- try {
31
- // Recursive test connection
32
- let val = database_config.shift();
33
- if (val) {
34
- initSequelize(val, true, async (err, sq) => {
35
- if (err) {
36
- //console.log(" Failed  Can't connect to connection name:", val.name, "\n", err);
37
- return cb(err, null, null);
38
- } else {
39
- // Test connection
40
- await sq.authenticate()
41
- .then(() => {
42
- // Database some is true perfectly.
43
- if (database_config.length == 0) {
44
- if (sq) {
45
- testSql[ val.name ] = sq;
46
- //console.log("DB true, Perfectly.", val.name);
47
- return cb(null, true, testSql);
48
- }
49
- } else {
50
- testSql[ val.name ] = sq;
51
- testConnectInProcess(database_config, dbConnTotal, cb);
52
- }
53
- })
54
- .catch(err => {
55
- console.log(" Failed  Unable to connect to the database:", val.name, "\n", err);
56
- return cb(err, null, null);
57
- });
58
- }
59
- });
60
- } else if (!dbConnTotal) {
61
- // All Database is falsly perfectly.
62
- //console.log("DB all false, Perfectly.");
63
- return cb(null, true, testSql);
64
- }
65
- } catch (error) {
66
- return cb(error, null, null);
67
- }
68
- }
69
-
70
- function disConnectTestDB(dbConfigTruthy, dbs, cb) {
71
- try {
72
- dbConfigTruthy.map((e, k) => {
73
- // Closing database
74
- if (dbs[ e.name ].close()) {
75
- if (dbConfigTruthy.length == k + 1) {
76
- cb(null, dbConfigTruthy);
77
- }
78
- } else {
79
- cb(`Close database failed, ${e.name}`, null);
80
- }
81
- });
82
- } catch (error) {
83
- cb(error, null);
84
- }
85
- }
86
-
87
- function logit(msg, next = false) {
88
- logUpdate(msg);
89
- if(next) {
90
- logUpdate.done();
91
- }
92
- }
93
-
94
- function initSequelize(val, testConn = true, cb) {
95
- try {
96
- const promise = new Promise((resolve) => {
97
- // check hash ?
98
- if(val.username && val.password) {
99
- if(val.username.length < 55 || val.password < 55) {
100
- return cb("ERR: Incorrect Hash access for connect to database, Please Hashing your access by command `beech hash:<your_access>`\n", null);
101
- }
102
- let accessDb = [];
103
- [val.username, val.password].map(async (e, k) => {
104
- await DeHashIt(e.toString(), null, (17).toString().slice(0,-1).length, async (err, d) => {
105
- if(err) {
106
- cb("ERR: Hash access error,", err);
107
- throw err;
108
- }
109
- accessDb.push(d.split("sh,")[1].split(M(X).toString().slice(0,2)+M(X).toString())[0].slice(0,-1));
110
- // Finally username & password
111
- if(k+1==2) {
112
- // Last push dialect connection
113
- accessDb.push(val.dialect);
114
- // resolve it
115
- resolve(accessDb);
116
- }
117
- });
118
- });
119
- } else {
120
- resolve([null, null]);
121
- }
122
- });
123
- Promise.all([promise]).then(final => {
124
- /**
125
- * The final callback variable : [['hashed', 'hashed', 'dialect']]
126
- *
127
- * final[0][0] : username hashed
128
- * final[0][1] : password hashed
129
- * final[0][2] : dialect
130
- *
131
- */
132
-
133
- // Check test connection for stdout pre-flight
134
- if(testConn) {
135
- // stdout pre-flight connection
136
- logit(`- [${val.dialect}] ${val.name}`);
137
- logit(emoji.get('heavy_multiplication_x') + ` [${val.dialect}] ${val.name}`);
138
- }
139
- fs.readFile("./global.config.js", 'utf8', (err, data) => {
140
- if (err) {
141
- console.log("\n Faltal  Can't read `global.config.js` file.\n", err);
142
- return; // break;
143
- } else {
144
- let buffer = Buffer.from(data);
145
- let buf2str = buffer.toString();
146
- let buf2json = JSON.parse(JSON.stringify(buf2str));
147
- let pool_base = /global.pool_base\s+=\s+(?:"|')([^"]+)(?:"|')(?:\r|\n|$|;|\r)/i.exec(buf2json);
148
- if (pool_base) {
149
- if(pool_base == "basic") {
150
- if(final[0][2] != "mysql") {
151
- return cb(`The Basic pool engine not support with: ${val.dialect}, Please use Sequelize engine.`, null);
152
- }
153
- }
154
- }
155
- }
156
- });
157
- // create connection
158
- const sq = new Sequelize({
159
- dialect: val.dialect || "mysql",
160
- host: (val.host == "localhost" || val.host == "http://localhost") ? "127.0.0.1" : val.host,
161
- username: final[0][0],
162
- password: final[0][1],
163
- database: val.database,
164
- port: val.port,
165
- storage: val.storage || ":memory:",
166
- protocol: val.protocol || null,
167
- logging: val.logging || false,
168
- dialectOptions: {
169
- socketPath: ((val.dialectOptions) ? ((val.dialectOptions.socketPath) ? val.dialectOptions.socketPath : "") : ""), //Applications/MAMP/tmp/mysql/mysql.sock
170
- supportBigNumbers: ((val.dialectOptions) ? ((val.dialectOptions.supportBigNumbers) ? val.dialectOptions.supportBigNumbers : false) : false),
171
- bigNumberStrings: ((val.dialectOptions) ? ((val.dialectOptions.bigNumberStrings) ? val.dialectOptions.bigNumberStrings : false) : false),
172
- options: ((val.dialectOptions) ? ((val.dialectOptions.options) ? ({ encrypt: false, ...val.dialectOptions.options }) : { encrypt: false }) : { encrypt: false }),
173
- },
174
- omitNull: val.omitNull || false,
175
- native: val.native || false,
176
- define: {
177
- underscored: ((val.define) ? ((val.define.underscored) ? val.define.underscored : false) : false),
178
- freezeTableName: ((val.define) ? ((val.define.freezeTableName === false) ? val.define.freezeTableName : true) : true),
179
- charset: ((val.define) ? ((val.define.charset) ? val.define.charset : "utf8") : "utf8"),
180
- dialectOptions: {
181
- collate: ((val.define) ? ((val.define.dialectOptions) ? ((val.define.dialectOptions.timestamps) ? val.define.dialectOptions.timestamps : "utf8_general_ci") : "utf8_general_ci") : "utf8_general_ci"),
182
- },
183
- timestamps: ((val.define) ? ((val.define.timestamps) ? val.define.timestamps : false) : false),
184
- },
185
- sync: {
186
- force: ((val.sync) ? ((val.sync.force) ? val.sync.force : false) : false),
187
- },
188
- pool: {
189
- max: ((val.pool) ? ((val.pool.max) ? val.pool.max : 5) : 5),
190
- idle: ((val.pool) ? ((val.pool.idle) ? val.pool.idle : 30000) : 30000),
191
- acquire: ((val.pool) ? ((val.pool.acquire) ? val.pool.acquire : 60000) : 60000),
192
- },
193
- isolationLevel: val.isolationLevel || "Transaction.ISOLATION_LEVELS.REPEATABLE_READ",
194
- query: {
195
- raw: ((val.query) ? ((val.query.raw) ? val.query.raw : true) : true),
196
- nest: ((val.query) ? ((val.query.nest) ? val.query.nest : true) : true),
197
- }
198
- });
199
- // Check test connection for stdout pre-flight (mark)
200
- if(testConn) {
201
- logit(emoji.get('heavy_check_mark') + ` [${val.dialect}] ${val.name}`, true);
202
- }
203
- cb(false, sq);
204
- }).catch(err => {
205
- console.log(` Warning  Connection name \`${val.name}\``, err);
206
- });
207
- } catch (error) {
208
- cb(error, null);
209
- }
210
- }
211
-
212
- function connectForGenerateModel(dbConnectName, tableName, databaseConfig, cb) {
213
- /**
214
- * Callback
215
- *
216
- * err String : Error message
217
- * tableSchema Object : Schema of table
218
- * tableName String : table name
219
- *
220
- */
221
- const connectionChoose = databaseConfig.filter((e) => e.name == dbConnectName)[0];
222
- initSequelize(connectionChoose, false, async (err, sq) => {
223
- if (err) {
224
- cb(err, null, null);
225
- }
226
- // Connection
227
- await sq.authenticate()
228
- .then(() => {
229
- getTableSchema(sq, tableName, (errSchema, tableSchema) => {
230
- if(errSchema) {
231
- cb(errSchema, null, null);
232
- } else {
233
- // Closing database
234
- sq.close();
235
- // Callback
236
- cb(null, tableSchema, tableName);
237
- }
238
- });
239
- })
240
- .catch(err => {
241
- cb(err, null, null);
242
- });
243
- });
244
- }
245
-
246
- async function getTableSchema(sq, tableName, cb) {
247
- try {
248
- const queryInterface = sq.getQueryInterface();
249
- const schema = await queryInterface.describeTable(tableName);
250
- cb(null, schema);
251
- } catch (error) {
252
- cb("Fetching table schema " + error, null);
253
- }
254
- }
255
-
1
+ const logUpdate = require("log-update");
2
+ const { DeHashIt, M, X } = require(__dirname + "/../helpers/math");
3
+ const Sequelize = require('sequelize');
4
+ const fs = require("fs");
5
+ let testSql = {};
6
+
7
+ function filterDbIsTrue(dbConfig, cb) {
8
+ try {
9
+ let dbIsTrue = [];
10
+ dbConfig.filter((e, k) => {
11
+ if (e.is_connect) {
12
+ dbIsTrue.push(e);
13
+ }
14
+ if (dbConfig.length == k + 1) {
15
+ if(dbIsTrue.length) {
16
+ console.log('\n Pre-Flight  Testing Database connection:');
17
+ }
18
+ setTimeout(() => {
19
+ cb(null, dbIsTrue);
20
+ }, 200);
21
+ }
22
+ });
23
+ } catch (error) {
24
+ cb(error, null);
25
+ }
26
+ }
27
+
28
+ function testConnectInProcess(database_config, dbConnTotal, cb) {
29
+ try {
30
+ // Recursive test connection
31
+ let val = database_config.shift();
32
+ if (val) {
33
+ initSequelize(val, true, async (err, sq) => {
34
+ if (err) {
35
+ //console.log(" Failed  Can't connect to connection name:", val.name, "\n", err);
36
+ return cb(err, null, null);
37
+ } else {
38
+ // Test connection
39
+ await sq.authenticate()
40
+ .then(() => {
41
+ // Database some is true perfectly.
42
+ if (database_config.length == 0) {
43
+ if (sq) {
44
+ testSql[ val.name ] = sq;
45
+ //console.log("DB true, Perfectly.", val.name);
46
+ return cb(null, true, testSql);
47
+ }
48
+ } else {
49
+ testSql[ val.name ] = sq;
50
+ testConnectInProcess(database_config, dbConnTotal, cb);
51
+ }
52
+ })
53
+ .catch(err => {
54
+ logit(`[X] [${val.dialect}] ${val.name}`);
55
+ console.log(" Failed  Unable to connect to the database:", val.name, "\n", err);
56
+ return cb(err, null, null);
57
+ });
58
+ }
59
+ });
60
+ } else if (!dbConnTotal) {
61
+ // All Database is falsly perfectly.
62
+ //console.log("DB all false, Perfectly.");
63
+ return cb(null, true, testSql);
64
+ }
65
+ } catch (error) {
66
+ return cb(error, null, null);
67
+ }
68
+ }
69
+
70
+ function disConnectTestDB(dbConfigTruthy, dbs, cb) {
71
+ try {
72
+ dbConfigTruthy.map((e, k) => {
73
+ // Closing database
74
+ if (dbs[ e.name ].close()) {
75
+ if (dbConfigTruthy.length == k + 1) {
76
+ cb(null, dbConfigTruthy);
77
+ }
78
+ } else {
79
+ cb(`Close database failed, ${e.name}`, null);
80
+ }
81
+ });
82
+ } catch (error) {
83
+ cb(error, null);
84
+ }
85
+ }
86
+
87
+ function logit(msg, next = false) {
88
+ logUpdate(msg);
89
+ if(next) {
90
+ logUpdate.done();
91
+ }
92
+ }
93
+
94
+ function initSequelize(val, testConn = true, cb) {
95
+ try {
96
+ const promise = new Promise((resolve) => {
97
+ // check hash ?
98
+ if(val.username && val.password) {
99
+ if(val.username.length < 55 || val.password < 55) {
100
+ return cb("ERR: Incorrect Hash access for connect to database, Please Hashing your access by command `beech hash:<your_access>`\n", null);
101
+ }
102
+ let accessDb = [];
103
+ [val.username, val.password].forEach((e, k) => {
104
+ DeHashIt(e.toString(), null, (17).toString().slice(0,-1).length, (err, d) => {
105
+ if (err) {
106
+ return cb("Hash access error", err);
107
+ }
108
+ accessDb[k] = d.split("sh,")[1].split(M(X).toString().slice(0,2) + M(X).toString())[0].slice(0,-1);
109
+ if (accessDb[0] && accessDb[1]) {
110
+ accessDb[2] = val.dialect;
111
+ resolve(accessDb);
112
+ }
113
+ });
114
+ });
115
+ } else {
116
+ resolve([null, null]);
117
+ }
118
+ });
119
+ Promise.all([promise]).then(final => {
120
+ /**
121
+ * The final callback variable : [['hashed', 'hashed', 'dialect']]
122
+ *
123
+ * final[0][0] : username hashed
124
+ * final[0][1] : password hashed
125
+ * final[0][2] : dialect
126
+ *
127
+ */
128
+
129
+ // Check test connection for stdout pre-flight
130
+ if(testConn) {
131
+ // stdout pre-flight connection
132
+ logit(`[+] [${val.dialect}] ${val.name}`);
133
+ }
134
+ fs.readFile("./global.config.js", 'utf8', (err, data) => {
135
+ if (err) {
136
+ console.log("\n Fatal  Can't read `global.config.js` file.\n", err);
137
+ return; // break;
138
+ } else {
139
+ let buffer = Buffer.from(data);
140
+ let buf2str = buffer.toString();
141
+ let buf2json = JSON.parse(JSON.stringify(buf2str));
142
+ let pool_base = /global.pool_base\s+=\s+(?:"|')([^"]+)(?:"|')(?:\r|\n|$|;|\r)/i.exec(buf2json);
143
+ if (pool_base) {
144
+ if(pool_base == "basic") {
145
+ if(final[0][2] != "mysql") {
146
+ return cb(`The Basic pool engine not support with: ${val.dialect}, Please use Sequelize engine.`, null);
147
+ }
148
+ }
149
+ }
150
+ }
151
+ });
152
+ // create connection
153
+ const sq = new Sequelize({
154
+ dialect: val.dialect || "mysql",
155
+ host: (val.host == "localhost" || val.host == "http://localhost") ? "127.0.0.1" : val.host,
156
+ username: final[0][0],
157
+ password: final[0][1],
158
+ database: val.database,
159
+ port: val.port,
160
+ storage: val.storage || ":memory:",
161
+ protocol: val.protocol || null,
162
+ logging: val.logging || false,
163
+ dialectOptions: {
164
+ socketPath: ((val.dialectOptions) ? ((val.dialectOptions.socketPath) ? val.dialectOptions.socketPath : "") : ""), //Applications/MAMP/tmp/mysql/mysql.sock
165
+ supportBigNumbers: ((val.dialectOptions) ? ((val.dialectOptions.supportBigNumbers) ? val.dialectOptions.supportBigNumbers : false) : false),
166
+ bigNumberStrings: ((val.dialectOptions) ? ((val.dialectOptions.bigNumberStrings) ? val.dialectOptions.bigNumberStrings : false) : false),
167
+ options: ((val.dialectOptions) ? ((val.dialectOptions.options) ? ({ encrypt: false, ...val.dialectOptions.options }) : { encrypt: false }) : { encrypt: false }),
168
+ },
169
+ omitNull: val.omitNull || false,
170
+ native: val.native || false,
171
+ define: {
172
+ underscored: ((val.define) ? ((val.define.underscored) ? val.define.underscored : false) : false),
173
+ freezeTableName: ((val.define) ? ((val.define.freezeTableName === false) ? val.define.freezeTableName : true) : true),
174
+ charset: ((val.define) ? ((val.define.charset) ? val.define.charset : "utf8") : "utf8"),
175
+ dialectOptions: {
176
+ collate: ((val.define) ? ((val.define.dialectOptions) ? ((val.define.dialectOptions.timestamps) ? val.define.dialectOptions.timestamps : "utf8_general_ci") : "utf8_general_ci") : "utf8_general_ci"),
177
+ },
178
+ timestamps: ((val.define) ? ((val.define.timestamps) ? val.define.timestamps : false) : false),
179
+ },
180
+ sync: {
181
+ force: ((val.sync) ? ((val.sync.force) ? val.sync.force : false) : false),
182
+ },
183
+ pool: {
184
+ max: ((val.pool) ? ((val.pool.max) ? val.pool.max : 5) : 5),
185
+ idle: ((val.pool) ? ((val.pool.idle) ? val.pool.idle : 30000) : 30000),
186
+ acquire: ((val.pool) ? ((val.pool.acquire) ? val.pool.acquire : 60000) : 60000),
187
+ },
188
+ isolationLevel: val.isolationLevel || "Transaction.ISOLATION_LEVELS.REPEATABLE_READ",
189
+ query: {
190
+ raw: ((val.query) ? ((val.query.raw) ? val.query.raw : true) : true),
191
+ nest: ((val.query) ? ((val.query.nest) ? val.query.nest : true) : true),
192
+ }
193
+ });
194
+ // Check test connection for stdout pre-flight (mark)
195
+ if(testConn) {
196
+ logit(`[/] [${val.dialect}] ${val.name}`, true);
197
+ }
198
+ cb(false, sq);
199
+ }).catch(err => {
200
+ console.log(` Warning  Connection name \`${val.name}\``, err);
201
+ });
202
+ } catch (error) {
203
+ cb(error, null);
204
+ }
205
+ }
206
+
207
+ function connectForGenerateModel(dbConnectName, tableName, databaseConfig, cb) {
208
+ /**
209
+ * Callback
210
+ *
211
+ * err String : Error message
212
+ * tableSchema Object : Schema of table
213
+ * tableName String : table name
214
+ *
215
+ */
216
+ const connectionChoose = databaseConfig.find(e => e.name === dbConnectName);
217
+ initSequelize(connectionChoose, false, async (err, sq) => {
218
+ if (err) {
219
+ return cb(err, null, null);
220
+ }
221
+ // Connection
222
+ await sq.authenticate()
223
+ .then(() => {
224
+ getTableSchema(sq, tableName, (errSchema, tableSchema) => {
225
+ if(errSchema) {
226
+ cb(errSchema, null, null);
227
+ } else {
228
+ // Closing database
229
+ sq.close();
230
+ // Callback
231
+ cb(null, tableSchema, tableName);
232
+ }
233
+ });
234
+ })
235
+ .catch(err => {
236
+ cb(err, null, null);
237
+ });
238
+ });
239
+ }
240
+
241
+ async function getTableSchema(sq, tableName, cb) {
242
+ try {
243
+ const queryInterface = sq.getQueryInterface();
244
+ const schema = await queryInterface.describeTable(tableName);
245
+ cb(null, schema);
246
+ } catch (error) {
247
+ cb("Fetching table schema " + error, null);
248
+ }
249
+ }
250
+
256
251
  module.exports = { filterDbIsTrue, testConnectInProcess, disConnectTestDB, connectForGenerateModel }
@@ -1,35 +1,35 @@
1
- /**
2
- * file walk autoload all file
3
- *
4
- */
5
- exports.fileWalk = (files) => {
6
- return new Promise((resolve, reject) => {
7
- try {
8
- if (files.length) {
9
- let route;
10
- files.map((val, key) => {
11
- let endpointFile = val.replace(".js", "");
12
- try {
13
- route = require(endpointFile);
14
- if (route instanceof Error) {
15
- console.log(out.message);
16
- reject(error);
17
- }
18
- route.init();
19
- if (files.length == key + 1) {
20
- resolve(true);
21
- }
22
- } catch (error) {
23
- console.log(error);
24
- reject(error);
25
- }
26
- });
27
- } else {
28
- resolve(true);
29
- }
30
- } catch (error) {
31
- console.log(error);
32
- reject(error);
33
- }
34
- });
35
- };
1
+ /**
2
+ * file walk autoload all file
3
+ *
4
+ */
5
+ exports.fileWalk = (files) => {
6
+ return new Promise((resolve, reject) => {
7
+ try {
8
+ if (files.length) {
9
+ let route;
10
+ files.map((val, key) => {
11
+ let endpointFile = val.replace(".js", "");
12
+ try {
13
+ route = require(endpointFile);
14
+ if (route instanceof Error) {
15
+ console.log(out.message);
16
+ reject(error);
17
+ }
18
+ route.init();
19
+ if (files.length == key + 1) {
20
+ resolve(true);
21
+ }
22
+ } catch (error) {
23
+ console.log(error);
24
+ reject(error);
25
+ }
26
+ });
27
+ } else {
28
+ resolve(true);
29
+ }
30
+ } catch (error) {
31
+ console.log(error);
32
+ reject(error);
33
+ }
34
+ });
35
+ };
@@ -1,15 +1,15 @@
1
- {{requireSomething}}
2
- exports.init = () => {
3
- // GET request
4
- endpoint.get("/{{endpoint}}", Credentials, (req, res) => {
5
- // @response
6
- res.json({
7
- code: 200,
8
- status: "SUCCESS",
9
- message: "GET request at /{{endpoint}}",
10
- });
11
- });
12
-
13
- // Create new Endpoints, Learn more: https://github.com/bombkiml/beech-api?tab=readme-ov-file#part-of-generate-file
14
-
15
- };
1
+ {{requireSomething}}
2
+ exports.init = () => {
3
+ // GET request
4
+ endpoint.get("/{{endpoint}}", Credentials, (req, res) => {
5
+ // @response
6
+ res.json({
7
+ code: 200,
8
+ status: "SUCCESS",
9
+ message: "GET request at /{{endpoint}}",
10
+ });
11
+ });
12
+
13
+ // Create new Endpoints, Learn more: https://github.com/bombkiml/beech-api?tab=readme-ov-file#part-of-generate-file
14
+
15
+ };