mythix 2.12.2 → 4.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 (127) hide show
  1. package/README.md +183 -190
  2. package/{src → lib}/application.d.ts +25 -39
  3. package/{src/application.js → lib/application.mjs} +110 -135
  4. package/lib/cli/cli-utils.d.ts +21 -0
  5. package/lib/cli/cli-utils.mjs +318 -0
  6. package/lib/cli/command-base.d.ts +33 -0
  7. package/lib/cli/command-base.mjs +114 -0
  8. package/lib/cli/command-executor.mjs +14 -0
  9. package/lib/cli/commands/deploy-command.mjs +1010 -0
  10. package/lib/cli/commands/generators/generate-command.mjs +117 -0
  11. package/lib/cli/commands/generators/index.mjs +2 -0
  12. package/{src/cli/generators/migration-generator.js → lib/cli/commands/generators/migration-generator.mjs} +19 -14
  13. package/lib/cli/commands/index.mjs +22 -0
  14. package/lib/cli/commands/migrate-command.mjs +181 -0
  15. package/lib/cli/commands/routes-command.mjs +40 -0
  16. package/lib/cli/commands/serve-command.mjs +63 -0
  17. package/lib/cli/commands/shell-command.mjs +95 -0
  18. package/lib/cli/index.mjs +3 -0
  19. package/{src → lib}/controllers/controller-base.d.ts +1 -1
  20. package/{src/controllers/controller-base.js → lib/controllers/controller-base.mjs} +3 -9
  21. package/{src → lib}/controllers/controller-module.d.ts +3 -3
  22. package/lib/controllers/controller-module.mjs +70 -0
  23. package/lib/controllers/generate-client-api-interface-spec.mjs +44 -0
  24. package/{src → lib}/controllers/generate-client-api-interface.d.ts +1 -0
  25. package/{src/controllers/generate-client-api-interface.js → lib/controllers/generate-client-api-interface.mjs} +39 -16
  26. package/{src → lib}/controllers/index.d.ts +2 -3
  27. package/lib/controllers/index.mjs +4 -0
  28. package/lib/controllers/routes/index.mjs +4 -0
  29. package/{src/controllers/routes/route-capture.js → lib/controllers/routes/route-capture.mjs} +2 -8
  30. package/{src/controllers/routes/route-endpoint.js → lib/controllers/routes/route-endpoint.mjs} +8 -8
  31. package/{src/controllers/routes/route-scope-base.js → lib/controllers/routes/route-scope-base.mjs} +19 -15
  32. package/{src/controllers/routes/route-scope.js → lib/controllers/routes/route-scope.mjs} +10 -12
  33. package/{src/http-server/http-errors.js → lib/http/http-errors.mjs} +9 -20
  34. package/{src/utils/http-interface.js → lib/http/http-interface.mjs} +6 -14
  35. package/{src/http-server → lib/http}/http-server-module.d.ts +2 -2
  36. package/{src/http-server/http-server-module.js → lib/http/http-server-module.mjs} +7 -11
  37. package/{src/http-server/http-server.js → lib/http/http-server.mjs} +17 -21
  38. package/lib/http/index.d.ts +4 -0
  39. package/lib/http/index.mjs +5 -0
  40. package/lib/index.d.ts +30 -0
  41. package/lib/index.mjs +31 -0
  42. package/lib/logger-spec.mjs +121 -0
  43. package/{src → lib}/logger.d.ts +1 -3
  44. package/{src/logger.js → lib/logger.mjs} +10 -24
  45. package/lib/models/index.d.ts +2 -0
  46. package/lib/models/index.mjs +2 -0
  47. package/{src/models/migration-model.js → lib/models/migration-model.mjs} +3 -11
  48. package/lib/models/model.d.ts +10 -0
  49. package/lib/models/model.mjs +28 -0
  50. package/{src → lib}/modules/database-module.d.ts +2 -2
  51. package/{src/modules/database-module.js → lib/modules/database-module.mjs} +19 -14
  52. package/lib/modules/index.d.ts +2 -0
  53. package/lib/modules/index.mjs +2 -0
  54. package/{src/modules/base-module.d.ts → lib/modules/module-base.d.ts} +3 -10
  55. package/{src/modules/base-module.js → lib/modules/module-base.mjs} +16 -6
  56. package/lib/tasks/index.d.ts +2 -0
  57. package/lib/tasks/index.mjs +2 -0
  58. package/{src → lib}/tasks/task-base.d.ts +4 -14
  59. package/lib/tasks/task-base.mjs +73 -0
  60. package/{src → lib}/tasks/task-module.d.ts +3 -3
  61. package/{src/tasks/task-module.js → lib/tasks/task-module.mjs} +45 -97
  62. package/{src/utils/config-utils.js → lib/utils/config-utils.mjs} +2 -10
  63. package/lib/utils/crypto-utils-spec.mjs +24 -0
  64. package/{src/utils/crypto-utils.js → lib/utils/crypto-utils.mjs} +16 -38
  65. package/lib/utils/file-utils-spec.mjs +10 -0
  66. package/{src/utils/file-utils.js → lib/utils/file-utils.mjs} +4 -11
  67. package/{src/utils/http-utils.js → lib/utils/http-utils.mjs} +3 -10
  68. package/{src → lib}/utils/index.d.ts +1 -1
  69. package/lib/utils/index.mjs +6 -0
  70. package/lib/utils/mime-utils-spec.mjs +171 -0
  71. package/{src/utils/mime-utils.js → lib/utils/mime-utils.mjs} +5 -14
  72. package/{src/utils/test-utils.js → lib/utils/test-utils.mjs} +14 -42
  73. package/package.json +9 -9
  74. package/src/cli/cli-utils.d.ts +0 -80
  75. package/src/cli/cli-utils.js +0 -547
  76. package/src/cli/command-executor.js +0 -31
  77. package/src/cli/deploy-command.js +0 -1010
  78. package/src/cli/generators/generate-command.js +0 -149
  79. package/src/cli/index.js +0 -5
  80. package/src/cli/migrate-command.js +0 -181
  81. package/src/cli/routes-command.js +0 -40
  82. package/src/cli/serve-command.js +0 -63
  83. package/src/cli/shell-command.js +0 -96
  84. package/src/controllers/controller-module.js +0 -126
  85. package/src/controllers/controller-utils.d.ts +0 -19
  86. package/src/controllers/controller-utils.js +0 -24
  87. package/src/controllers/index.js +0 -19
  88. package/src/controllers/routes/index.js +0 -31
  89. package/src/http-server/index.d.ts +0 -3
  90. package/src/http-server/index.js +0 -16
  91. package/src/index.d.ts +0 -49
  92. package/src/index.js +0 -47
  93. package/src/models/index.d.ts +0 -4
  94. package/src/models/index.js +0 -17
  95. package/src/models/model-module.d.ts +0 -9
  96. package/src/models/model-module.js +0 -130
  97. package/src/models/model-utils.d.ts +0 -20
  98. package/src/models/model-utils.js +0 -46
  99. package/src/models/model.d.ts +0 -20
  100. package/src/models/model.js +0 -65
  101. package/src/modules/file-watcher-module.d.ts +0 -13
  102. package/src/modules/file-watcher-module.js +0 -220
  103. package/src/modules/index.d.ts +0 -3
  104. package/src/modules/index.js +0 -11
  105. package/src/tasks/index.d.ts +0 -3
  106. package/src/tasks/index.js +0 -11
  107. package/src/tasks/task-base.js +0 -122
  108. package/src/tasks/task-utils.d.ts +0 -46
  109. package/src/tasks/task-utils.js +0 -130
  110. package/src/utils/index.js +0 -25
  111. /package/{src → lib}/cli/index.d.ts +0 -0
  112. /package/{src → lib}/controllers/routes/index.d.ts +0 -0
  113. /package/{src → lib}/controllers/routes/route-capture.d.ts +0 -0
  114. /package/{src → lib}/controllers/routes/route-endpoint.d.ts +0 -0
  115. /package/{src → lib}/controllers/routes/route-scope-base.d.ts +0 -0
  116. /package/{src → lib}/controllers/routes/route-scope.d.ts +0 -0
  117. /package/{src/http-server → lib/http}/http-errors.d.ts +0 -0
  118. /package/{src/utils → lib/http}/http-interface.d.ts +0 -0
  119. /package/{src/http-server → lib/http}/http-server.d.ts +0 -0
  120. /package/{src → lib}/interfaces/common.ts +0 -0
  121. /package/{src → lib}/models/migration-model.d.ts +0 -0
  122. /package/{src → lib}/utils/config-utils.d.ts +0 -0
  123. /package/{src → lib}/utils/crypto-utils.d.ts +0 -0
  124. /package/{src → lib}/utils/file-utils.d.ts +0 -0
  125. /package/{src → lib}/utils/http-utils.d.ts +0 -0
  126. /package/{src → lib}/utils/mime-utils.d.ts +0 -0
  127. /package/{src → lib}/utils/test-utils.d.ts +0 -0
@@ -1,50 +1,39 @@
1
1
  import { ConnectionBase, ModelClass, Models } from 'mythix-orm';
2
2
  import { ControllerClass } from './controllers/controller-base';
3
3
  import { RouteScope } from './controllers/routes/route-scope';
4
- import { HTTPServer } from './http-server/http-server';
4
+ import { HTTPServer } from './http/http-server';
5
5
  import { GenericObject } from './interfaces/common';
6
6
  import { Logger, LoggerClass, LoggerOptions } from './logger';
7
- import { Modules, ModuleClasses, BaseModuleClass } from './modules/base-module';
7
+ import { ModuleBase } from './modules/module-base';
8
+ import { TaskBase } from './tasks/task-base';
9
+ import { CommandClasses } from './cli/command-base';
8
10
 
9
11
  export declare type ApplicationClass = typeof Application;
10
12
 
13
+ export declare interface ModuleDictionary {
14
+ [key: string]: typeof ModuleBase;
15
+ }
16
+
11
17
  export declare interface ApplicationOptions {
12
- cli: boolean;
13
- environment: string;
14
- appName: string;
15
- rootPath: string;
16
- configPath: string;
17
- migrationsPath: string;
18
- modelsPath: string;
19
- seedersPath: string;
20
- controllersPath: string;
21
- templatesPath: string;
22
- commandsPath: string;
23
- tasksPath: string;
24
- modules: ModuleClasses;
25
- autoReload: boolean;
26
- exitOnShutdown: number | null;
27
- runTasks: boolean;
28
- testMode: boolean;
29
- noInternalMigrationTable: boolean;
30
- logger: LoggerOptions;
31
- database: boolean | GenericObject;
32
- httpServer: boolean | GenericObject;
33
- tempPath: string;
34
- routeParserTypes: { [key: string]: (value: string, param: GenericObject, index?: number) => any };
18
+ bindToProcessSignals?: boolean;
19
+ cli?: boolean;
20
+ database?: boolean | GenericObject;
21
+ environment?: string;
22
+ exitOnShutdown?: number | null;
23
+ httpServer?: boolean | GenericObject;
24
+ logger?: LoggerOptions;
25
+ tasks?: boolean | { [key: string]: TaskBase } | Array<TaskBase>;
26
+ tempPath?: string;
35
27
  }
36
28
 
37
29
  export declare class Application {
38
- declare public static APP_NAME: string;
39
-
40
- public static getDefaultModules(): ModuleClasses;
41
- public static findModuleIndex(modules: ModuleClasses, moduleKlass: BaseModuleClass): number;
42
- public static replaceModule(modules: ModuleClasses, moduleKlass: BaseModuleClass, replacementModuleKlass: BaseModuleClass): ModuleClasses;
30
+ public static getName(): string;
31
+ public static getCommandList(): CommandClasses;
32
+ public static getModules(): ModuleDictionary;
43
33
 
44
34
  public constructor(options?: ApplicationOptions);
45
35
  public getTempPath(): string | null;
46
- public getModules(): Modules;
47
- public initializeModules(modules: ModuleClasses): Promise<void>;
36
+ public initializeModules(modules: ModuleDictionary): Promise<void>;
48
37
  public startAllModules(options: ApplicationOptions): Promise<void>;
49
38
  public stopAllModules(options: ApplicationOptions): Promise<Array<Error>>;
50
39
  public bindToProcessSignals(): void;
@@ -68,17 +57,14 @@ export declare class Application {
68
57
  public getDBTablePrefix(): string | null;
69
58
  public getConnection(connection?: ConnectionBase): ConnectionBase;
70
59
 
71
- // Deprecated
72
- public getDBConnection(connection?: ConnectionBase): ConnectionBase;
73
-
74
- // From FileWatcherModule
75
- public autoReload(enable?: boolean, shuttingDown?: boolean): Promise<void>;
76
-
77
60
  // From ModelModule
78
61
  public getModel(modelName?: string): ModelClass | undefined;
79
62
  public getModels(): Models;
63
+ public getAppModelClasses(connection: ConnectionBase): { [key: string]: ModelClass };
64
+ public bindModels(connection: ConnectionBase, models: { [key: string]: ModelClass }): { [key: string]: ModelClass };
80
65
 
81
66
  // From ControllerModule
67
+ public getAppControllerClasses(): { [key: string]: ControllerClass };
82
68
  public getController(name: string): { controller: ControllerClass, controllerMethod: string | undefined };
83
69
 
84
70
  // From HTTPServerModule
@@ -88,7 +74,7 @@ export declare class Application {
88
74
  declare public isStarted: boolean;
89
75
  declare public isStopping: boolean;
90
76
  declare public options: ApplicationOptions;
91
- declare public moduleInstances: Modules;
77
+ declare public moduleInstances: Array<ModuleBase>;
92
78
  declare public config: GenericObject;
93
79
  declare public logger: Logger;
94
80
  }
@@ -1,100 +1,39 @@
1
- 'use strict';
2
-
3
- /* global process, __dirname */
4
-
5
- const Nife = require('nife');
6
- const Path = require('path');
7
- const FileSystem = require('fs');
8
- const EventEmitter = require('events');
9
- const OS = require('os');
10
- const { Logger } = require('./logger');
11
- const { DatabaseModule } = require('./modules/database-module');
12
- const { ModelModule } = require('./models/model-module');
13
- const { HTTPServerModule } = require('./http-server/http-server-module');
14
- const { ControllerModule } = require('./controllers/controller-module');
15
- const { TaskModule } = require('./tasks/task-module');
16
- const { FileWatcherModule } = require('./modules/file-watcher-module');
17
- const { wrapConfig } = require('./utils');
18
- const ControllerRoutes = require('./controllers/routes');
19
-
20
- // Trace what is requesting the application exit
21
-
22
- // (function doExit(_exit) {
23
- // process.exit = function() {
24
- // console.trace('EXIT');
25
- // return _exit.apply(process, arguments);
26
- // };
27
- // })(process.exit);
28
-
29
- class Application extends EventEmitter {
30
- static APP_NAME = 'mythix';
31
-
32
- static getDefaultModules() {
33
- return [
34
- DatabaseModule,
35
- ModelModule,
36
- HTTPServerModule,
37
- ControllerModule,
38
- TaskModule,
39
- FileWatcherModule,
40
- ];
1
+ import Path from 'node:path';
2
+ import FileSystem from 'node:fs';
3
+ import OS from 'node:os';
4
+ import Nife from 'nife';
5
+ import { Logger } from './logger.mjs';
6
+ import { DatabaseModule } from './modules/database-module.mjs';
7
+ import { HTTPServerModule } from './http/http-server-module.mjs';
8
+ import { ControllerModule } from './controllers/controller-module.mjs';
9
+ import { TaskModule } from './tasks/task-module.mjs';
10
+ import { wrapConfig } from './utils/config-utils.mjs';
11
+ import * as ControllerRoutes from './controllers/routes/index.mjs';
12
+ import { COMMANDS } from './cli/commands/index.mjs';
13
+ import { Migration } from './models/migration-model.mjs';
14
+
15
+ export class Application {
16
+ static getName() {
17
+ return 'mythix';
41
18
  }
42
19
 
43
- static findModuleIndex(modules, moduleKlass) {
44
- let index = -1;
45
-
46
- if (typeof moduleKlass.getModuleName === 'function') {
47
- let moduleKlassName = moduleKlass.getModuleName();
48
- index = modules.findIndex((thisModuleClass) => {
49
- return (thisModuleClass.getModuleName() === moduleKlassName);
50
- });
51
- } else {
52
- index = modules.findIndex((thisModuleClass) => thisModuleClass === moduleKlass);
53
- }
54
-
55
- return index;
20
+ static getCommandList() {
21
+ return COMMANDS;
56
22
  }
57
23
 
58
- static replaceModule(modules, moduleKlass, replacementModuleKlass) {
59
- let index = this.findModuleIndex(modules, moduleKlass);
60
- if (index >= 0)
61
- modules[index] = replacementModuleKlass;
62
- else
63
- throw new Error('Application::replaceModule: Unable to find and replace requested module');
64
-
65
- return modules;
24
+ static getModules() {
25
+ return {
26
+ database: DatabaseModule,
27
+ httpServer: HTTPServerModule,
28
+ controllers: ControllerModule,
29
+ tasks: TaskModule,
30
+ };
66
31
  }
67
32
 
68
33
  constructor(_opts) {
69
- super();
70
-
71
- let ROOT_PATH = (_opts && _opts.rootPath) ? _opts.rootPath : Path.resolve(__dirname);
72
-
73
34
  let opts = Nife.extend(true, {
74
- environment: (process.env.NODE_ENV || 'development'),
75
- appName: this.constructor.APP_NAME,
76
- rootPath: ROOT_PATH,
77
- configPath: Path.resolve(ROOT_PATH, 'config'),
78
- migrationsPath: Path.resolve(ROOT_PATH, 'migrations'),
79
- modelsPath: Path.resolve(ROOT_PATH, 'models'),
80
- seedersPath: Path.resolve(ROOT_PATH, 'seeders'),
81
- controllersPath: Path.resolve(ROOT_PATH, 'controllers'),
82
- templatesPath: Path.resolve(ROOT_PATH, 'templates'),
83
- commandsPath: Path.resolve(ROOT_PATH, 'commands'),
84
- tasksPath: Path.resolve(ROOT_PATH, 'tasks'),
85
- autoReload: ((_opts && _opts.environment) || process.env.NODE_ENV || 'development') === 'development',
86
- exitOnShutdown: null,
87
- runTasks: true,
88
- testMode: false,
89
- noInternalMigrationTable: false,
90
- logger: {
91
- rootPath: ROOT_PATH,
92
- },
93
- database: {},
94
- httpServer: {
95
- routeParserTypes: undefined,
96
- middleware: null,
97
- },
35
+ environment: (process.env.NODE_ENV || 'development'),
36
+ exitOnShutdown: null,
98
37
  }, _opts || {});
99
38
 
100
39
  Object.defineProperties(this, {
@@ -129,7 +68,7 @@ class Application extends EventEmitter {
129
68
  writable: false,
130
69
  enumerable: false,
131
70
  configurable: true,
132
- value: this.loadConfig(opts.configPath),
71
+ value: wrapConfig(Object.assign({}, opts.config || {}, { environment: opts.environment })),
133
72
  },
134
73
  });
135
74
 
@@ -145,17 +84,15 @@ class Application extends EventEmitter {
145
84
  },
146
85
  });
147
86
 
148
- this.bindToProcessSignals();
87
+ if (opts.bindToProcessSignals !== false)
88
+ this.bindToProcessSignals();
149
89
 
150
90
  if (Nife.isEmpty(opts.tempPath))
151
91
  opts.tempPath = Path.resolve(OS.tmpdir(), this.getApplicationName().replace(/[^\w-]/g, ''), ('' + process.pid));
152
-
153
- opts.modules = this.constructor.getDefaultModules(this, opts);
154
92
  }
155
93
 
156
94
  getApplicationName() {
157
- let options = this.getOptions();
158
- return options.appName || this.constructor.APP_NAME;
95
+ return this.constructor.getName();
159
96
  }
160
97
 
161
98
  getTempPath() {
@@ -163,21 +100,25 @@ class Application extends EventEmitter {
163
100
  return options.tempPath;
164
101
  }
165
102
 
166
- getModules() {
103
+ getModuleInstances() {
167
104
  return this.moduleInstances || [];
168
105
  }
169
106
 
170
107
  async initializeModules(_modules) {
171
108
  // Shutdown modules, if any are active
172
- let stopPromises = this.getModules().map((moduleInstance) => moduleInstance.stop());
173
- await Promise.all(stopPromises);
109
+ await this.stopAllModules(this.getOptions());
174
110
 
175
- let modules = _modules || [];
111
+ let modules = _modules || {};
112
+ let moduleNames = Object.keys(modules);
176
113
  let moduleInstances = [];
177
114
  let options = this.getOptions();
178
115
 
179
- for (let i = 0, il = modules.length; i < il; i++) {
180
- let ModuleClass = modules[i];
116
+ for (let i = 0, il = moduleNames.length; i < il; i++) {
117
+ let moduleName = moduleNames[i];
118
+ let ModuleClass = modules[moduleName];
119
+ if (typeof ModuleClass !== 'function')
120
+ throw new TypeError(`Specified module "${moduleName}" is not a module class`);
121
+
181
122
  if (typeof ModuleClass.shouldUse === 'function' && ModuleClass.shouldUse.call(ModuleClass, this, options) === false)
182
123
  continue;
183
124
 
@@ -189,7 +130,7 @@ class Application extends EventEmitter {
189
130
  }
190
131
 
191
132
  async startAllModules(options) {
192
- let moduleInstances = this.getModules();
133
+ let moduleInstances = this.getModuleInstances();
193
134
 
194
135
  for (let i = 0, il = moduleInstances.length; i < il; i++) {
195
136
  let moduleInstance = moduleInstances[i];
@@ -198,7 +139,7 @@ class Application extends EventEmitter {
198
139
  }
199
140
 
200
141
  async stopAllModules(options) {
201
- let moduleInstances = this.getModules();
142
+ let moduleInstances = this.getModuleInstances();
202
143
  let errors = [];
203
144
 
204
145
  for (let i = moduleInstances.length - 1; i >= 0; i--) {
@@ -211,8 +152,11 @@ class Application extends EventEmitter {
211
152
  }
212
153
  }
213
154
 
214
- if (errors.length > 0)
215
- return errors;
155
+ if (errors.length > 0) {
156
+ let error = new AggregateError('Errors were encountered while shutting down modules');
157
+ error.errors = errors;
158
+ throw error;
159
+ }
216
160
  }
217
161
 
218
162
  bindToProcessSignals() {
@@ -235,25 +179,6 @@ class Application extends EventEmitter {
235
179
  return this;
236
180
  }
237
181
 
238
- loadConfig(configPath) {
239
- let appOptions = this.getOptions();
240
- let environment = (appOptions.environment || process.NODE_ENV || 'development');
241
-
242
- if (!configPath)
243
- return wrapConfig(Object.assign({}, { environment }));
244
-
245
- try {
246
- let config = require(configPath);
247
- if (config.__esModule)
248
- config = config['default'];
249
-
250
- return wrapConfig(Object.assign({}, config || {}, { environment }));
251
- } catch (error) {
252
- this.getLogger().error(`Error while trying to load application configuration ${configPath}: `, error);
253
- throw error;
254
- }
255
- }
256
-
257
182
  getConfigValue(key, defaultValue, type) {
258
183
  let result = this.config.ENV(key, defaultValue);
259
184
 
@@ -273,6 +198,49 @@ class Application extends EventEmitter {
273
198
  return this;
274
199
  }
275
200
 
201
+ getAppControllerClasses() {
202
+ return {};
203
+ }
204
+
205
+ getAppModelClasses() {
206
+ return {
207
+ Migration,
208
+ };
209
+ }
210
+
211
+ bindModels(connection, models) {
212
+ const generateBoundModelClass = (connection, modelName, ModelClass) => {
213
+ if (typeof ModelClass !== 'function')
214
+ return;
215
+
216
+ const app = this;
217
+
218
+ return class BoundModel extends ModelClass {
219
+ static getApplication() {
220
+ return app;
221
+ }
222
+
223
+ static getModelName() {
224
+ return modelName;
225
+ }
226
+ };
227
+ };
228
+
229
+ let modelNames = Object.keys(models);
230
+ let boundModels = [];
231
+
232
+ for (let i = 0, il = modelNames.length; i < il; i++) {
233
+ let modelName = modelNames[i];
234
+ let ModelClass = generateBoundModelClass(connection, modelName, models[modelName]);
235
+ if (!ModelClass)
236
+ continue;
237
+
238
+ boundModels[modelName] = ModelClass;
239
+ }
240
+
241
+ return boundModels;
242
+ }
243
+
276
244
  _getRoutes() {
277
245
  let routeScope = new ControllerRoutes.RouteScope();
278
246
  this.getRoutes(routeScope);
@@ -284,8 +252,7 @@ class Application extends EventEmitter {
284
252
  }
285
253
 
286
254
  getCustomRouteParserTypes() {
287
- let options = this.getOptions();
288
- return options.routeParserTypes;
255
+ return [];
289
256
  }
290
257
 
291
258
  createLogger(loggerOpts, LoggerClass) {
@@ -299,21 +266,34 @@ class Application extends EventEmitter {
299
266
  return this.logger;
300
267
  }
301
268
 
269
+ getModel(name) {
270
+ if (typeof this.getConnection !== 'function')
271
+ return;
272
+
273
+ let connection = this.getConnection();
274
+ return connection.getModel(name);
275
+ }
276
+
277
+ getModels() {
278
+ if (typeof this.getConnection !== 'function')
279
+ return {};
280
+
281
+ let connection = this.getConnection();
282
+ return connection.getModels();
283
+ }
284
+
302
285
  async start() {
303
286
  let options = this.getOptions();
304
-
305
287
  let tempDir = this.getTempPath();
306
288
  if (Nife.isNotEmpty(tempDir)) {
307
289
  if (!FileSystem.existsSync(tempDir))
308
290
  FileSystem.mkdirSync(tempDir, { recursive: true });
309
291
  }
310
292
 
311
- await this.initializeModules(options.modules);
293
+ await this.initializeModules(this.constructor.getModules());
312
294
  await this.startAllModules(options);
313
295
 
314
296
  this.isStarted = true;
315
-
316
- this.emit('start');
317
297
  }
318
298
 
319
299
  async stop(exitCode) {
@@ -352,11 +332,8 @@ class Application extends EventEmitter {
352
332
 
353
333
  this.getLogger().info('Shut down complete!');
354
334
 
355
- this.emit('stop');
356
-
357
335
  if (options.exitOnShutdown != null || exitCode != null) {
358
336
  let code = (exitCode != null) ? exitCode : options.exitOnShutdown;
359
- this.emit('exit', code);
360
337
  process.exit(code);
361
338
  }
362
339
  } catch (error) {
@@ -365,5 +342,3 @@ class Application extends EventEmitter {
365
342
  }
366
343
  }
367
344
  }
368
-
369
- module.exports = { Application };
@@ -0,0 +1,21 @@
1
+ import { Application, ApplicationClass, ApplicationOptions } from '../application';
2
+ import { GenericObject } from '../interfaces/common';
3
+ import { CommandClass } from './command-base';
4
+
5
+ export declare function loadMythixConfig(
6
+ mythixConfigPath: string,
7
+ appRootPath: string
8
+ ): Promise<GenericObject>;
9
+
10
+ export declare function createApplication(
11
+ applicationClass: ApplicationClass,
12
+ options?: ApplicationOptions
13
+ ): Application;
14
+
15
+ export declare function executeCommand(
16
+ config: GenericObject,
17
+ appOptions: ApplicationOptions,
18
+ commandContext: GenericObject,
19
+ CommandKlass: CommandClass,
20
+ argv: Array<string>
21
+ ): Promise<undefined>;