evaengine 0.11.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/.ai/analysis.md +657 -0
  2. package/.ai/architecture/runtime.md +504 -0
  3. package/.ai/contracts/public-api.md +447 -0
  4. package/.ai/external-project-guide.md +248 -0
  5. package/.ai/vision.md +314 -0
  6. package/README.md +51 -62
  7. package/bin/engine +15 -21
  8. package/index.js +2 -18
  9. package/package.json +60 -64
  10. package/src/commands/index.js +12 -0
  11. package/{lib → src}/commands/interface.js +5 -11
  12. package/src/commands/make_entity.js +490 -0
  13. package/src/commands/tramp.js +34 -0
  14. package/{lib → src}/config/index.js +7 -9
  15. package/{lib → src}/di.js +11 -26
  16. package/src/engine.js +551 -0
  17. package/{lib → src}/entities/index.js +72 -82
  18. package/{lib → src}/exceptions/index.js +71 -92
  19. package/src/index.js +57 -0
  20. package/src/middlewares/auth.js +67 -0
  21. package/src/middlewares/auth_kong.js +28 -0
  22. package/src/middlewares/debug.js +88 -0
  23. package/src/middlewares/index.js +18 -0
  24. package/src/middlewares/providers.js +73 -0
  25. package/src/middlewares/session.js +58 -0
  26. package/{lib → src}/middlewares/trace.js +74 -86
  27. package/src/middlewares/validator.js +50 -0
  28. package/src/middlewares/view_cache.js +127 -0
  29. package/{lib → src}/services/cache.js +45 -56
  30. package/src/services/config.js +111 -0
  31. package/src/services/env.js +28 -0
  32. package/src/services/event_manager.js +84 -0
  33. package/src/services/http_client.js +160 -0
  34. package/src/services/index.js +27 -0
  35. package/src/services/interface.js +5 -0
  36. package/src/services/joi.js +13 -0
  37. package/src/services/jwt_token.js +89 -0
  38. package/src/services/jwt_token_kong.js +75 -0
  39. package/src/services/logger.js +148 -0
  40. package/src/services/namespace.js +176 -0
  41. package/src/services/now.js +49 -0
  42. package/src/services/providers.js +158 -0
  43. package/src/services/redis.js +55 -0
  44. package/src/services/rest_client.js +112 -0
  45. package/src/swagger/index.js +668 -0
  46. package/{lib → src}/utils/api_scaffold.js +26 -39
  47. package/src/utils/case_converter.js +33 -0
  48. package/src/utils/crc32.js +44 -0
  49. package/src/utils/datetime.js +13 -0
  50. package/src/utils/host.js +39 -0
  51. package/src/utils/index.js +35 -0
  52. package/{lib → src}/utils/pagination.js +22 -31
  53. package/src/utils/random.js +23 -0
  54. package/{lib → src}/utils/smart_query.js +27 -27
  55. package/src/utils/test.js +48 -0
  56. package/src/utils/wrapper.js +8 -0
  57. package/bin/engine-babel +0 -38
  58. package/lib/commands/index.js +0 -25
  59. package/lib/commands/index.js.map +0 -1
  60. package/lib/commands/interface.js.map +0 -1
  61. package/lib/commands/make_entity.js +0 -549
  62. package/lib/commands/make_entity.js.map +0 -1
  63. package/lib/commands/tramp.js +0 -53
  64. package/lib/commands/tramp.js.map +0 -1
  65. package/lib/config/index.js.map +0 -1
  66. package/lib/di.js.map +0 -1
  67. package/lib/engine.js +0 -558
  68. package/lib/engine.js.map +0 -1
  69. package/lib/entities/index.js.map +0 -1
  70. package/lib/exceptions/index.js.map +0 -1
  71. package/lib/index.js +0 -105
  72. package/lib/index.js.map +0 -1
  73. package/lib/middlewares/auth.js +0 -97
  74. package/lib/middlewares/auth.js.map +0 -1
  75. package/lib/middlewares/auth_kong.js +0 -48
  76. package/lib/middlewares/auth_kong.js.map +0 -1
  77. package/lib/middlewares/debug.js +0 -68
  78. package/lib/middlewares/debug.js.map +0 -1
  79. package/lib/middlewares/index.js +0 -45
  80. package/lib/middlewares/index.js.map +0 -1
  81. package/lib/middlewares/providers.js +0 -102
  82. package/lib/middlewares/providers.js.map +0 -1
  83. package/lib/middlewares/session.js +0 -76
  84. package/lib/middlewares/session.js.map +0 -1
  85. package/lib/middlewares/trace.js.map +0 -1
  86. package/lib/middlewares/validator.js +0 -71
  87. package/lib/middlewares/validator.js.map +0 -1
  88. package/lib/middlewares/view_cache.js +0 -160
  89. package/lib/middlewares/view_cache.js.map +0 -1
  90. package/lib/services/cache.js.map +0 -1
  91. package/lib/services/config.js +0 -140
  92. package/lib/services/config.js.map +0 -1
  93. package/lib/services/env.js +0 -40
  94. package/lib/services/env.js.map +0 -1
  95. package/lib/services/event_manager.js +0 -110
  96. package/lib/services/event_manager.js.map +0 -1
  97. package/lib/services/http_client.js +0 -178
  98. package/lib/services/http_client.js.map +0 -1
  99. package/lib/services/index.js +0 -70
  100. package/lib/services/index.js.map +0 -1
  101. package/lib/services/interface.js +0 -12
  102. package/lib/services/interface.js.map +0 -1
  103. package/lib/services/joi.js +0 -28
  104. package/lib/services/joi.js.map +0 -1
  105. package/lib/services/jwt_token.js +0 -120
  106. package/lib/services/jwt_token.js.map +0 -1
  107. package/lib/services/jwt_token_kong.js +0 -111
  108. package/lib/services/jwt_token_kong.js.map +0 -1
  109. package/lib/services/logger.js +0 -172
  110. package/lib/services/logger.js.map +0 -1
  111. package/lib/services/namespace.js +0 -188
  112. package/lib/services/namespace.js.map +0 -1
  113. package/lib/services/now.js +0 -69
  114. package/lib/services/now.js.map +0 -1
  115. package/lib/services/providers.js +0 -195
  116. package/lib/services/providers.js.map +0 -1
  117. package/lib/services/redis.js +0 -77
  118. package/lib/services/redis.js.map +0 -1
  119. package/lib/services/rest_client.js +0 -136
  120. package/lib/services/rest_client.js.map +0 -1
  121. package/lib/swagger/index.js +0 -684
  122. package/lib/swagger/index.js.map +0 -1
  123. package/lib/utils/api_scaffold.js.map +0 -1
  124. package/lib/utils/case_converter.js +0 -48
  125. package/lib/utils/case_converter.js.map +0 -1
  126. package/lib/utils/crc32.js +0 -22
  127. package/lib/utils/crc32.js.map +0 -1
  128. package/lib/utils/datetime.js +0 -21
  129. package/lib/utils/datetime.js.map +0 -1
  130. package/lib/utils/host.js +0 -48
  131. package/lib/utils/host.js.map +0 -1
  132. package/lib/utils/index.js +0 -61
  133. package/lib/utils/index.js.map +0 -1
  134. package/lib/utils/pagination.js.map +0 -1
  135. package/lib/utils/random.js +0 -33
  136. package/lib/utils/random.js.map +0 -1
  137. package/lib/utils/smart_query.js.map +0 -1
  138. package/lib/utils/test.js +0 -62
  139. package/lib/utils/test.js.map +0 -1
  140. package/lib/utils/wrapper.js +0 -9
  141. package/lib/utils/wrapper.js.map +0 -1
@@ -0,0 +1,490 @@
1
+ import _ from 'lodash';
2
+ import Sequelize from 'sequelize';
3
+ import fs from 'fs';
4
+ import * as mkdirp from 'mkdirp';
5
+ import Command from './interface.js';
6
+ import DI from '../di.js';
7
+ import Entities from '../entities/index.js';
8
+
9
+
10
+ export class MakeDbView extends Command {
11
+ static getName() {
12
+ return 'make:dbview';
13
+ }
14
+
15
+ static getDescription() {
16
+ return 'Generate db views';
17
+ }
18
+
19
+ static getSpec() {
20
+ return {
21
+ entity_path: {
22
+ required: false,
23
+ description: 'Entity path'
24
+ },
25
+ dir: {
26
+ required: false,
27
+ description: 'Where view.sql to be generated'
28
+ }
29
+ };
30
+ }
31
+
32
+ getSql(tableName, attributes) {
33
+ const attrs = attributes.map((attr) => {
34
+ const { fieldName } = attr;
35
+ if (fieldName.endsWith('At')) {
36
+ return ` FROM_UNIXTIME(IF(${fieldName} > 0, ${fieldName}, NULL)) AS ${fieldName}`;
37
+ }
38
+ return ` \`${fieldName}\` AS \`${fieldName}\``;
39
+ });
40
+ return `DROP VIEW IF EXISTS view_${tableName};
41
+ CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW view_${tableName}
42
+ AS SELECT
43
+ ${attrs.join(',\n ')}
44
+ FROM ${tableName};
45
+
46
+ `;
47
+ }
48
+
49
+ async run() {
50
+ const logger = DI.get('logger');
51
+ const { dir, entity_path: entityPath = `${process.cwd()}/build/entities` } = this.getArgv();
52
+ const path = dir ? `${process.cwd()}/${dir}` : `${process.cwd()}/sql`;
53
+ const file = [path, 'views.sql'].join('/');
54
+ logger.info('Scan entity files under %s', entityPath);
55
+ const entities = new Entities(entityPath);
56
+
57
+ logger.info('Start generate db views to %s', file);
58
+ mkdirp.sync(path);
59
+ const models = Object.values(entities.getInstance().models);
60
+ const sql = [];
61
+ models.forEach((model) => {
62
+ logger.info(`Creating ${model.getTableName()} view`);
63
+ sql.push(this.getSql(model.getTableName(), Object.values(model.attributes)));
64
+ });
65
+
66
+ fs.writeFileSync(file, sql.join(''));
67
+ logger.info('Views created');
68
+ }
69
+ }
70
+
71
+ export class MakeEntity extends Command {
72
+ static getName() {
73
+ return 'make:entity';
74
+ }
75
+
76
+ static getDescription() {
77
+ return 'Generate entities';
78
+ }
79
+
80
+ static getSpec() {
81
+ return {
82
+ timestamp: {
83
+ required: false,
84
+ description: 'Sequelize timestamp enabled'
85
+ },
86
+ dir: {
87
+ required: false,
88
+ description: 'Where entity files to be generated'
89
+ },
90
+ prefix: {
91
+ required: false,
92
+ description: 'Table prefix'
93
+ }
94
+ };
95
+ }
96
+
97
+ static typeMapping(_type) {
98
+ const type = _type.toLowerCase();
99
+ if (type === 'tinyint(1)' || type === 'boolean' || type === 'bit(1)') {
100
+ return 'DataTypes.BOOLEAN';
101
+ }
102
+
103
+ if (type.match(/^(smallint|mediumint|tinyint|int)/)) {
104
+ const length = type.match(/\(\d+\)/) || '';
105
+ return `DataTypes.INTEGER${length}`;
106
+ }
107
+
108
+ if (type.startsWith('bigint')) {
109
+ return 'DataTypes.BIGINT';
110
+ }
111
+ if (type.startsWith('enum')) {
112
+ return type.replace('enum', 'DataTypes.ENUM').replace(/,/g, ', ');
113
+ }
114
+
115
+ if (type.match(/^string|varchar|varying|nvarchar/)) {
116
+ const length = type.match(/\(\d+\)/) || '';
117
+ return length ? `DataTypes.STRING${length}` : 'DataTypes.STRING';
118
+ }
119
+
120
+ if (type.startsWith('char')) {
121
+ const length = type.match(/\(\d+\)/) || '';
122
+ return `DataTypes.CHAR${length}`;
123
+ }
124
+
125
+ if (type.match(/text|ntext$/)) {
126
+ return 'DataTypes.TEXT';
127
+ }
128
+
129
+ if (type.startsWith('year')) {
130
+ return 'DataTypes.INTEGER(4)';
131
+ }
132
+
133
+ if (type.startsWith('datetime')) {
134
+ return 'DataTypes.DATE';
135
+ }
136
+
137
+ if (type.startsWith('date')) {
138
+ return 'DataTypes.DATEONLY';
139
+ }
140
+
141
+ if (type.startsWith('time')) {
142
+ return 'DataTypes.TIME';
143
+ }
144
+
145
+ if (type.match(/^(float8|double precision)/)) {
146
+ return 'DataTypes.DOUBLE';
147
+ }
148
+
149
+ if (type.match(/^(float|float4)/)) {
150
+ return 'DataTypes.FLOAT';
151
+ }
152
+
153
+ if (type.startsWith('decimal')) {
154
+ const [, length, bits] = /\((\d+),(\d+)\)/g.exec(type) || [];
155
+ return length ? `DataTypes.DECIMAL(${length}, ${bits})` : 'DataTypes.DECIMAL';
156
+ }
157
+
158
+ if (type.match(/^uuid|uniqueidentifier/)) {
159
+ return 'DataTypes.UUIDV4';
160
+ }
161
+
162
+ if (type.startsWith('jsonb')) {
163
+ return 'DataTypes.JSONB';
164
+ }
165
+ if (type.startsWith('json')) {
166
+ return 'DataTypes.JSON';
167
+ }
168
+
169
+ if (type.startsWith('geometry')) {
170
+ return 'DataTypes.GEOMETRY';
171
+ }
172
+
173
+ return type;
174
+ }
175
+
176
+ static typeAdditional(_type, sequlizeType, rawColumn) {
177
+ const type = _type.toLowerCase();
178
+ let finalType = sequlizeType;
179
+
180
+ if (type.match(/unsigned/)) {
181
+ finalType += '.UNSIGNED';
182
+ }
183
+
184
+ if (type.match(/zerofill/)) {
185
+ finalType += '.ZEROFILL';
186
+ }
187
+
188
+ if (rawColumn.Collation === 'utf8_bin') {
189
+ finalType += '.BINARY';
190
+ }
191
+ return finalType;
192
+ }
193
+
194
+ static async getIndexes(tableName, sequelize) {
195
+ let rawIndexes = await sequelize.query(
196
+ `SHOW INDEX FROM ${tableName}`,
197
+ {
198
+ type: sequelize.QueryTypes.SELECT,
199
+ raw: true
200
+ }
201
+ );
202
+ if (!rawIndexes) {
203
+ return [];
204
+ }
205
+ rawIndexes = _.groupBy(rawIndexes, 'Key_name');
206
+ return Object.entries(rawIndexes).filter(([key]) => key !== 'PRIMARY').map(([name, columns]) => {
207
+ const index = columns[0].Non_unique !== 1 ? { name, unique: true } : { name };
208
+ index.fields = columns.map(c => c.Column_name);
209
+ return index;
210
+ });
211
+ }
212
+
213
+ async run() {
214
+ const config = DI.get('config').get();
215
+ const logger = DI.get('logger');
216
+ const sequelize = new Sequelize(
217
+ config.db.database,
218
+ null,
219
+ null,
220
+ Object.assign({}, config.sequelize, config.db, { logging: logger.getInstance().verbose })
221
+ );
222
+ const query = sequelize.getQueryInterface();
223
+
224
+ let tables = await query.showAllTables();
225
+ const views = await sequelize.query(`SHOW FULL TABLES IN ${config.db.database} WHERE TABLE_TYPE LIKE 'VIEW'`, {
226
+ type: sequelize.QueryTypes.SELECT,
227
+ raw: true
228
+ });
229
+ if (views) {
230
+ const viewNames = views.map(v => Object.values(v)[0]);
231
+ tables = tables.filter(t => !viewNames.includes(t));
232
+ }
233
+ const { dir, timestamp = true, prefix } = this.getArgv();
234
+ if (prefix) {
235
+ tables = tables.filter(t => t.startsWith(prefix));
236
+ }
237
+
238
+ const path = dir ? `${process.cwd()}/${dir}` : `${process.cwd()}/src/entities`;
239
+ const schemaPath = `${path}/schemas`;
240
+ const entityTemplate = fs.readFileSync(`${import.meta.dirname}/../../template/entity.ejs`, 'utf8');
241
+ const schemaTemplate = fs.readFileSync(`${import.meta.dirname}/../../template/schema.ejs`, 'utf8');
242
+ mkdirp.sync(path);
243
+ mkdirp.sync(schemaPath);
244
+
245
+ logger.info('Start generate DB schemas to dir %s', path);
246
+
247
+ const tableHandler = async (table) => {
248
+ const columns = await query.describeTable(table);
249
+ const rawColumns = await sequelize.query(`SHOW FULL COLUMNS FROM ${table}`, {
250
+ type: sequelize.QueryTypes.SELECT,
251
+ raw: true
252
+ });
253
+ Object.values(rawColumns).forEach((rawColumn) => {
254
+ const columnName = rawColumn.Field;
255
+ columns[columnName].type = MakeEntity.typeAdditional(
256
+ columns[columnName].type,
257
+ MakeEntity.typeMapping(columns[columnName].type),
258
+ rawColumn
259
+ );
260
+ columns[columnName].unique = rawColumn.Key === 'UNI';
261
+ columns[columnName].comment = rawColumn.Comment;
262
+ columns[columnName].autoIncrement = rawColumn.Extra.startsWith('auto_increment') === true;
263
+ });
264
+
265
+ const indexes = await MakeEntity.getIndexes(table, sequelize);
266
+ const entityFile = `${path}/${table}.js`;
267
+ const schemaFile = `${schemaPath}/${table}.js`;
268
+ try {
269
+ fs.accessSync(entityFile);
270
+ logger.info('Entity file %s generate skipped, already exists by %s', table, entityFile);
271
+ } catch {
272
+ fs.writeFileSync(entityFile, _.template(entityTemplate)({ table }));
273
+ logger.info('Entity file %s generated as %s', table, entityFile);
274
+ }
275
+
276
+ try {
277
+ fs.accessSync(schemaFile);
278
+ logger.info('Schema file %s generate override, already exists by %s', table, schemaFile);
279
+ } catch {
280
+ logger.info('Schema file %s generated as %s', table, schemaFile);
281
+ }
282
+ fs.writeFileSync(schemaFile, _.template(schemaTemplate)({
283
+ columns,
284
+ table,
285
+ indexes,
286
+ timestamp: parseInt(timestamp, 10) > 0
287
+ }));
288
+ };
289
+
290
+ //Skip sequelize migrate table
291
+ await Promise.all(Object.values(tables).filter(t => !['sequelizemeta', 'tramp_migrations'].includes(t)).map(tableHandler));
292
+ logger.info('All DB schemas generated');
293
+ }
294
+ }
295
+
296
+ export class MakeGraphql extends Command {
297
+ static getName() {
298
+ return 'make:graphql';
299
+ }
300
+
301
+ static getDescription() {
302
+ return 'Generate graphql schema';
303
+ }
304
+
305
+ static getSpec() {
306
+ return {
307
+ dir: {
308
+ required: false,
309
+ description: 'Where entity files to be generated'
310
+ },
311
+ prefix: {
312
+ required: false,
313
+ description: 'Table prefix'
314
+ },
315
+ mapping: {
316
+ required: false,
317
+ description: 'Mapping file path'
318
+ }
319
+ };
320
+ }
321
+
322
+ static typeMapping(_type) {
323
+ const type = _type.toLowerCase();
324
+ if (type === 'tinyint(1)' || type === 'boolean' || type === 'bit(1)') {
325
+ return 'Boolean';
326
+ }
327
+
328
+ if (type.match(/^(smallint|mediumint|tinyint|int)/)) {
329
+ return 'Int';
330
+ }
331
+
332
+ if (type.startsWith('bigint')) {
333
+ return 'Int';
334
+ }
335
+
336
+ if (type.startsWith('enum')) {
337
+ return 'Enum';
338
+ }
339
+
340
+ if (type.match(/^string|varchar|varying|nvarchar/)) {
341
+ return 'String';
342
+ }
343
+
344
+ if (type.startsWith('char')) {
345
+ return 'String';
346
+ }
347
+
348
+ if (type.match(/text|ntext$/)) {
349
+ return 'String';
350
+ }
351
+
352
+ if (type.startsWith('year')) {
353
+ return 'Int';
354
+ }
355
+
356
+ if (type.startsWith('datetime')) {
357
+ return 'String';
358
+ }
359
+
360
+ if (type.startsWith('date')) {
361
+ return 'String';
362
+ }
363
+
364
+ if (type.startsWith('time')) {
365
+ return 'String';
366
+ }
367
+
368
+ if (type.match(/^(float8|double precision)/)) {
369
+ return 'Float';
370
+ }
371
+
372
+ if (type.match(/^(float|float4)/)) {
373
+ return 'Float';
374
+ }
375
+
376
+ if (type.startsWith('decimal')) {
377
+ return 'Float';
378
+ }
379
+
380
+ if (type.match(/^uuid|uniqueidentifier/)) {
381
+ return 'String';
382
+ }
383
+
384
+ if (type.startsWith('jsonb')) {
385
+ return 'JSON';
386
+ }
387
+ if (type.startsWith('json')) {
388
+ return 'JSON';
389
+ }
390
+
391
+ if (type.startsWith('geometry')) {
392
+ return 'String';
393
+ }
394
+
395
+ return type;
396
+ }
397
+
398
+ getEnums(_type, columnName, tableName) {
399
+ const type = _type.toLowerCase();
400
+ const values = type.slice(5, -1).split(',').map(v => v.slice(1, -1));
401
+ return {
402
+ name: `ENUM_${tableName}_${columnName}`,
403
+ values
404
+ };
405
+ }
406
+
407
+ async run() {
408
+ const config = DI.get('config').get();
409
+ const logger = DI.get('logger');
410
+ const sequelize = new Sequelize(
411
+ config.db.database,
412
+ null,
413
+ null,
414
+ Object.assign({}, config.sequelize, config.db, { logging: logger.getInstance().verbose })
415
+ );
416
+ const query = sequelize.getQueryInterface();
417
+
418
+ let tables = await query.showAllTables();
419
+ const views = await sequelize.query(`SHOW FULL TABLES IN ${config.db.database} WHERE TABLE_TYPE LIKE 'VIEW'`, {
420
+ type: sequelize.QueryTypes.SELECT,
421
+ raw: true
422
+ });
423
+ if (views) {
424
+ const viewNames = views.map(v => Object.values(v)[0]);
425
+ tables = tables.filter(t => !viewNames.includes(t));
426
+ }
427
+ const {
428
+ dir, prefix, mapping
429
+ } = this.getArgv();
430
+ if (prefix) {
431
+ tables = tables.filter(t => t.startsWith(prefix));
432
+ }
433
+
434
+ const path = dir ? `${process.cwd()}/${dir}` : `${process.cwd()}/src/graphql`;
435
+ const schemaPath = `${path}/entities`;
436
+ const schemaTemplate = fs.readFileSync(`${import.meta.dirname}/../../template/graphql.ejs`, 'utf8');
437
+ const mappingFile = mapping ? `${process.cwd()}/${mapping}` : `${process.cwd()}/src/graphql/mapping.json`;
438
+ const mappingContent = JSON.parse(fs.readFileSync(mappingFile, 'utf8'));
439
+ const getMappedTableName = tableName =>
440
+ (mappingContent[tableName] ? mappingContent[tableName] : tableName);
441
+ mkdirp.sync(path);
442
+ mkdirp.sync(schemaPath);
443
+
444
+ logger.info('Start generate GraphQL schemas to dir %s', path);
445
+
446
+ const tableHandler = async (tableName) => {
447
+ const enums = [];
448
+ const columns = await query.describeTable(tableName);
449
+ const rawColumns = await sequelize.query(`SHOW FULL COLUMNS FROM ${tableName}`, {
450
+ type: sequelize.QueryTypes.SELECT,
451
+ raw: true
452
+ });
453
+ const mappedTableName = getMappedTableName(tableName);
454
+ Object.values(rawColumns).forEach((rawColumn) => {
455
+ const columnName = rawColumn.Field;
456
+ let type = MakeGraphql.typeMapping(columns[columnName].type, mappedTableName);
457
+ if (type === 'Enum') {
458
+ const enumObj = this.getEnums(columns[columnName].type, columnName, mappedTableName);
459
+ type = enumObj.name;
460
+ enums.push(enumObj);
461
+ }
462
+
463
+ columns[columnName].type = type;
464
+ columns[columnName].unique = rawColumn.Key === 'UNI';
465
+ columns[columnName].comment = rawColumn.Comment;
466
+ columns[columnName].autoIncrement = rawColumn.Extra.startsWith('auto_increment') === true;
467
+ });
468
+
469
+ const indexes = await MakeEntity.getIndexes(tableName, sequelize);
470
+ const schemaFile = `${schemaPath}/${tableName}.graphqls`;
471
+ try {
472
+ fs.accessSync(schemaFile);
473
+ logger.info('Graphql schema file %s generate override, already exists by %s', tableName, schemaFile);
474
+ } catch {
475
+ logger.info('Graphql schema file %s generated as %s', tableName, schemaFile);
476
+ }
477
+ fs.writeFileSync(schemaFile, _.template(schemaTemplate)({
478
+ tableName,
479
+ mappedTableName,
480
+ columns,
481
+ indexes,
482
+ enums
483
+ }));
484
+ };
485
+
486
+ //Skip sequelize migrate table
487
+ await Promise.all(Object.values(tables).filter(t => !['sequelizemeta', 'tramp_migrations'].includes(t)).map(tableHandler));
488
+ logger.info('All DB schemas generated');
489
+ }
490
+ }
@@ -0,0 +1,34 @@
1
+ import Command from './interface.js';
2
+ import DI from '../di.js';
3
+
4
+ export default class TrampConfig extends Command {
5
+ static getName() {
6
+ return 'tramp:dump-config';
7
+ }
8
+
9
+ static getDescription() {
10
+ return 'Print tramp cli required config json';
11
+ }
12
+
13
+ static getSpec() {
14
+ return {};
15
+ }
16
+
17
+ async run() {
18
+ const config = DI.get('config');
19
+ const dbConfig = config.get('db');
20
+
21
+ console.log(JSON.stringify({
22
+ connection: {
23
+ host: dbConfig.replication.write.host,
24
+ user: dbConfig.replication.write.username,
25
+ password: dbConfig.replication.write.password,
26
+ database: dbConfig.database,
27
+ port: dbConfig.port
28
+ },
29
+ editor: config.get('dev.editor') || 'webstorm',
30
+ paths: dbConfig.migrationPaths
31
+ }));
32
+ }
33
+ }
34
+
@@ -1,9 +1,4 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = {
1
+ export default {
7
2
  app: {
8
3
  name: 'evaengine'
9
4
  },
@@ -77,10 +72,14 @@ exports.default = {
77
72
  description: '',
78
73
  version: ''
79
74
  },
80
- produces: ['application/json'],
75
+ produces: [
76
+ 'application/json'
77
+ ],
81
78
  host: '',
82
79
  basePath: '/',
83
- schemes: ['http'],
80
+ schemes: [
81
+ 'http'
82
+ ],
84
83
  securityDefinitions: {
85
84
  api_key: {
86
85
  type: 'apiKey',
@@ -95,4 +94,3 @@ exports.default = {
95
94
  definitions: {}
96
95
  }
97
96
  };
98
- //# sourceMappingURL=index.js.map
@@ -1,24 +1,11 @@
1
- 'use strict';
1
+ import constitute from 'constitute';
2
+ import { RuntimeException } from './exceptions/index.js';
3
+ import { ServiceProvider } from './services/providers.js';
2
4
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = undefined;
7
-
8
- var _constitute = require('constitute');
9
-
10
- var _constitute2 = _interopRequireDefault(_constitute);
11
-
12
- var _exceptions = require('./exceptions');
13
-
14
- var _providers = require('./services/providers');
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- let container = new _constitute2.default.Container();
5
+ let container = new constitute.Container();
19
6
  let bound = {};
20
7
 
21
- let DI = class DI {
8
+ export default class DI {
22
9
  static getContainer() {
23
10
  return container;
24
11
  }
@@ -33,7 +20,7 @@ let DI = class DI {
33
20
  }
34
21
 
35
22
  if (!bound[service]) {
36
- throw new _exceptions.RuntimeException(`Service ${service} not bound yet`);
23
+ throw new RuntimeException(`Service ${service} not bound yet`);
37
24
  }
38
25
  return container.constitute(bound[service]);
39
26
  }
@@ -54,13 +41,13 @@ let DI = class DI {
54
41
 
55
42
  static bindMethod(...args) {
56
43
  if (typeof args[0] === 'string') {
57
- [, bound[args[0]]] = args;
44
+ bound[args[0]] = args[0];
58
45
  }
59
46
  return container.bindMethod(...args);
60
47
  }
61
48
 
62
49
  static reset() {
63
- container = new _constitute2.default.Container();
50
+ container = new constitute.Container();
64
51
  bound = {};
65
52
  }
66
53
 
@@ -80,8 +67,8 @@ let DI = class DI {
80
67
  */
81
68
  static registerService(ProviderClass, engine) {
82
69
  const provider = new ProviderClass(engine);
83
- if (!(provider instanceof _providers.ServiceProvider)) {
84
- throw new _exceptions.RuntimeException(`Input provider ${provider.name} not service provider`);
70
+ if (!(provider instanceof ServiceProvider)) {
71
+ throw new RuntimeException(`Input provider ${provider.name} not service provider`);
85
72
  }
86
73
  provider.register();
87
74
  }
@@ -94,6 +81,4 @@ let DI = class DI {
94
81
  };
95
82
  DI.registerServiceProviders(providers, mockEngine);
96
83
  }
97
- };
98
- exports.default = DI;
99
- //# sourceMappingURL=di.js.map
84
+ }