mythix 2.4.14 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -7
- package/src/application.d.ts +88 -0
- package/src/application.js +5 -4
- package/src/cli/cli-utils.d.ts +63 -0
- package/src/cli/cli-utils.js +6 -3
- package/src/cli/index.d.ts +1 -0
- package/src/cli/routes-command.js +1 -1
- package/src/controllers/controller-base.d.ts +59 -0
- package/src/controllers/controller-base.js +7 -6
- package/src/controllers/controller-module.d.ts +11 -0
- package/src/controllers/controller-module.js +1 -1
- package/src/controllers/controller-utils.d.ts +51 -0
- package/src/controllers/controller-utils.js +3 -16
- package/src/controllers/generate-client-api-interface.d.ts +13 -0
- package/src/controllers/generate-client-api-interface.js +1 -1
- package/src/controllers/index.d.ts +4 -0
- package/src/http-server/http-errors.d.ts +17 -0
- package/src/http-server/http-server-module.d.ts +9 -0
- package/src/http-server/http-server-module.js +1 -3
- package/src/http-server/http-server.d.ts +33 -0
- package/src/http-server/http-server.js +7 -1
- package/src/http-server/index.d.ts +3 -0
- package/src/http-server/index.js +1 -6
- package/src/index.d.ts +49 -0
- package/src/index.js +9 -8
- package/src/interfaces/common.ts +3 -0
- package/src/logger.d.ts +53 -0
- package/src/logger.js +1 -3
- package/src/models/index.d.ts +4 -0
- package/src/models/index.js +4 -1
- package/src/models/migration-model.d.ts +8 -0
- package/src/models/migration-model.js +29 -12
- package/src/models/model-module.d.ts +9 -0
- package/src/models/model-module.js +2 -4
- package/src/models/model-utils.d.ts +20 -0
- package/src/models/model-utils.js +32 -27
- package/src/models/model.d.ts +17 -0
- package/src/models/model.js +5 -34
- package/src/modules/base-module.d.ts +27 -0
- package/src/modules/base-module.js +5 -3
- package/src/modules/database-module.d.ts +14 -0
- package/src/modules/database-module.js +1 -3
- package/src/modules/file-watcher-module.d.ts +13 -0
- package/src/modules/file-watcher-module.js +1 -3
- package/src/modules/index.d.ts +3 -0
- package/src/modules/index.js +5 -5
- package/src/tasks/index.d.ts +3 -0
- package/src/tasks/task-base.d.ts +43 -0
- package/src/tasks/task-base.js +41 -46
- package/src/tasks/task-module.d.ts +17 -0
- package/src/tasks/task-module.js +2 -4
- package/src/tasks/task-utils.d.ts +46 -0
- package/src/tasks/task-utils.js +13 -13
- package/src/utils/config-utils.d.ts +3 -0
- package/src/utils/crypto-utils.d.ts +6 -0
- package/src/utils/file-utils.d.ts +10 -0
- package/src/utils/http-interface.d.ts +25 -0
- package/src/utils/http-utils.d.ts +3 -0
- package/src/utils/index.d.ts +7 -0
- package/src/utils/index.js +2 -2
- package/src/utils/mime-utils.d.ts +5 -0
- package/src/utils/test-utils.d.ts +3 -0
- package/src/utils/test-utils.js +9 -11
- package/src/http-server/middleware/default-middleware.js +0 -120
- package/src/http-server/middleware/index.js +0 -7
package/src/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const HTTPServerScope = require('./http-server');
|
|
|
6
6
|
const ControllerScope = require('./controllers');
|
|
7
7
|
const CLIUtilsScope = require('./cli');
|
|
8
8
|
const TasksScope = require('./tasks');
|
|
9
|
-
const
|
|
9
|
+
const Logger = require('./logger');
|
|
10
10
|
const Utils = require('./utils');
|
|
11
11
|
const Modules = require('./modules');
|
|
12
12
|
|
|
@@ -14,8 +14,8 @@ module.exports = {
|
|
|
14
14
|
defineCommand: CLIUtilsScope.defineCommand,
|
|
15
15
|
defineController: ControllerScope.defineController,
|
|
16
16
|
defineModel: ModelScope.defineModel,
|
|
17
|
+
registerModel: ModelScope.registerModel,
|
|
17
18
|
defineTask: TasksScope.defineTask,
|
|
18
|
-
createTestApplication: Utils.TestUtils.createTestApplication,
|
|
19
19
|
|
|
20
20
|
CLI: CLIUtilsScope,
|
|
21
21
|
ControllerBase: ControllerScope.ControllerBase,
|
|
@@ -25,18 +25,19 @@ module.exports = {
|
|
|
25
25
|
HTTPErrors: HTTPServerScope.HTTPErrors,
|
|
26
26
|
HTTPServer: HTTPServerScope.HTTPServer,
|
|
27
27
|
HTTPUtils: Utils.HTTPUtils,
|
|
28
|
-
Middleware: HTTPServerScope.Middleware,
|
|
29
28
|
TaskBase: TasksScope.TaskBase,
|
|
30
29
|
Tasks: TasksScope,
|
|
31
30
|
TestUtils: Utils.TestUtils,
|
|
32
31
|
MimeUtils: Utils.MimeUtils,
|
|
33
32
|
Model: ModelScope.Model,
|
|
34
33
|
Modules: {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
BaseModule: Modules.BaseModule,
|
|
35
|
+
DatabaseModule: Modules.DatabaseModule,
|
|
36
|
+
FileWatcherModule: Modules.FileWatcherModule,
|
|
37
|
+
HTTPServerModule: HTTPServerScope.HTTPServerModule,
|
|
38
|
+
ModelModule: ModelScope.ModelModule,
|
|
39
|
+
TaskModule: TasksScope.TaskModule,
|
|
40
|
+
ControllerModule: ControllerScope.ControllerModule,
|
|
40
41
|
},
|
|
41
42
|
|
|
42
43
|
Application,
|
package/src/logger.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare interface LoggerWriter {
|
|
2
|
+
error: (...args: Array<any>) => void;
|
|
3
|
+
warn: (...args: Array<any>) => void;
|
|
4
|
+
info: (...args: Array<any>) => void;
|
|
5
|
+
debug: (...args: Array<any>) => void;
|
|
6
|
+
log: (...args: Array<any>) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export declare type ErrorStackFormatterMethod = (rootPath: string, error: Error) => void;
|
|
10
|
+
|
|
11
|
+
export declare type LoggerClass = typeof Logger;
|
|
12
|
+
|
|
13
|
+
export declare interface LoggerOptions {
|
|
14
|
+
level?: number;
|
|
15
|
+
writer?: string | LoggerWriter | null;
|
|
16
|
+
rootPath?: string;
|
|
17
|
+
errorStackFormatter?: ErrorStackFormatterMethod;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare class Logger {
|
|
21
|
+
public static LEVEL_ERROR: number;
|
|
22
|
+
public static LEVEL_LOG: number;
|
|
23
|
+
public static LEVEL_WARN: number;
|
|
24
|
+
public static LEVEL_INFO: number;
|
|
25
|
+
public static LEVEL_DEBUG: number;
|
|
26
|
+
|
|
27
|
+
declare protected _level: number;
|
|
28
|
+
declare protected _writer: string;
|
|
29
|
+
declare protected _customWriter: string;
|
|
30
|
+
declare protected _pid: string;
|
|
31
|
+
declare protected _formatter: string;
|
|
32
|
+
declare protected _rootPath: string;
|
|
33
|
+
declare protected _errorStackFormatter: string;
|
|
34
|
+
|
|
35
|
+
constructor(options?: LoggerOptions);
|
|
36
|
+
|
|
37
|
+
public getLevel(): number;
|
|
38
|
+
public setLevel(level: number): void;
|
|
39
|
+
public clone(extraOpts?: LoggerOptions): Logger;
|
|
40
|
+
public isErrorLevel(): boolean;
|
|
41
|
+
public isLogLevel(): boolean;
|
|
42
|
+
public isWarningLevel(): boolean;
|
|
43
|
+
public isInfoLevel(): boolean;
|
|
44
|
+
public isDebugLevel(): boolean;
|
|
45
|
+
|
|
46
|
+
public error(...args: Array<any>): void;
|
|
47
|
+
public warn(...args: Array<any>): void;
|
|
48
|
+
public info(...args: Array<any>): void;
|
|
49
|
+
public debug(...args: Array<any>): void;
|
|
50
|
+
public log(...args: Array<any>): void;
|
|
51
|
+
|
|
52
|
+
public stop(): Promise<any>;
|
|
53
|
+
}
|
package/src/logger.js
CHANGED
package/src/models/index.js
CHANGED
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
const { Model } = require('./model');
|
|
4
4
|
const { ModelModule } = require('./model-module');
|
|
5
|
-
|
|
5
|
+
const { MigrationModel } = require('./migration-model');
|
|
6
6
|
const {
|
|
7
7
|
defineModel,
|
|
8
|
+
registerModel,
|
|
8
9
|
} = require('./model-utils');
|
|
9
10
|
|
|
10
11
|
module.exports = {
|
|
11
12
|
defineModel,
|
|
13
|
+
registerModel,
|
|
12
14
|
Model,
|
|
13
15
|
ModelModule,
|
|
16
|
+
MigrationModel,
|
|
14
17
|
};
|
|
@@ -1,18 +1,35 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { Types } = require('mythix-orm');
|
|
4
|
+
const { registerModel } = require('./model-utils');
|
|
5
|
+
const { Model } = require('./model');
|
|
4
6
|
|
|
5
7
|
const ID_STRING_MAX_SIZE = 15;
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
class Migration extends Model {
|
|
10
|
+
static fields = {
|
|
11
|
+
id: {
|
|
12
|
+
type: Types.STRING(ID_STRING_MAX_SIZE),
|
|
13
|
+
allowNull: false,
|
|
14
|
+
primaryKey: true,
|
|
15
|
+
index: true,
|
|
16
|
+
},
|
|
17
|
+
createdAt: {
|
|
18
|
+
type: Types.DATETIME,
|
|
19
|
+
defaultValue: Types.DATETIME.Default.NOW,
|
|
20
|
+
allowNull: false,
|
|
21
|
+
index: true,
|
|
22
|
+
},
|
|
23
|
+
updatedAt: {
|
|
24
|
+
type: Types.DATETIME,
|
|
25
|
+
defaultValue: Types.DATETIME.Default.NOW.UPDATE,
|
|
26
|
+
allowNull: false,
|
|
27
|
+
index: true,
|
|
28
|
+
},
|
|
17
29
|
};
|
|
18
|
-
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const modelRegisterFactory = registerModel(Migration);
|
|
33
|
+
modelRegisterFactory.MigrationModel = Migration;
|
|
34
|
+
|
|
35
|
+
module.exports = modelRegisterFactory;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModelClass, Models } from 'mythix-orm';
|
|
2
|
+
import { BaseModule } from '../modules/base-module';
|
|
3
|
+
|
|
4
|
+
export declare class ModelModule extends BaseModule {
|
|
5
|
+
getModelFilePaths(modelsPath: string): Array<string>;
|
|
6
|
+
loadModels(modelsPath: string): Models;
|
|
7
|
+
getModel(modelName?: string): ModelClass | undefined;
|
|
8
|
+
getModels(): Models;
|
|
9
|
+
}
|
|
@@ -86,7 +86,7 @@ class ModelModule extends BaseModule {
|
|
|
86
86
|
|
|
87
87
|
try {
|
|
88
88
|
let modelGenerator = require(modelFile);
|
|
89
|
-
if (modelGenerator
|
|
89
|
+
if (modelGenerator.__esModule)
|
|
90
90
|
modelGenerator = modelGenerator['default'];
|
|
91
91
|
|
|
92
92
|
Object.assign(models, modelGenerator(args));
|
|
@@ -127,6 +127,4 @@ class ModelModule extends BaseModule {
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
module.exports = {
|
|
131
|
-
ModelModule,
|
|
132
|
-
};
|
|
130
|
+
module.exports = { ModelModule };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ConnectionBase, Types } from 'mythix-orm';
|
|
2
|
+
import { Application } from '../application';
|
|
3
|
+
|
|
4
|
+
export declare interface DefineModelContext<T> {
|
|
5
|
+
Parent: T;
|
|
6
|
+
Types: typeof Types;
|
|
7
|
+
connection: ConnectionBase;
|
|
8
|
+
modelName: string;
|
|
9
|
+
application: Application;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export declare function registerModel<T>(
|
|
13
|
+
Model: T,
|
|
14
|
+
): (context: { application: Application, connection: ConnectionBase }) => T;
|
|
15
|
+
|
|
16
|
+
export declare function defineModel<T>(
|
|
17
|
+
modelName: string,
|
|
18
|
+
definer: (context: DefineModelContext<T>) => T,
|
|
19
|
+
parent?: T,
|
|
20
|
+
): (context: { application: Application, connection: ConnectionBase }) => T;
|
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const {
|
|
5
|
-
|
|
3
|
+
const { Types } = require('mythix-orm');
|
|
4
|
+
const { Model: ModelBase } = require('./model');
|
|
5
|
+
|
|
6
|
+
function _setupModel(modelName, _Model, { application, connection }) {
|
|
7
|
+
let Model = _Model;
|
|
8
|
+
let tableName = Model.getTableName();
|
|
9
|
+
let tablePrefix = application.getDBTablePrefix();
|
|
10
|
+
|
|
11
|
+
if (tablePrefix)
|
|
12
|
+
tableName = (`${tablePrefix}${tableName}`);
|
|
13
|
+
|
|
14
|
+
Model.getTableName = () => tableName;
|
|
15
|
+
Model.getModelName = () => modelName;
|
|
16
|
+
Model.getApplication = () => application;
|
|
17
|
+
Model.getLogger = () => application.getLogger();
|
|
18
|
+
Model._getConnection = (_connection) => {
|
|
19
|
+
if (_connection)
|
|
20
|
+
return _connection;
|
|
21
|
+
|
|
22
|
+
return connection;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return { [modelName]: Model };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function registerModel(Model) {
|
|
29
|
+
return function({ application, connection }) {
|
|
30
|
+
return _setupModel(Model.getModelName(), Model, { application, connection });
|
|
31
|
+
};
|
|
32
|
+
}
|
|
6
33
|
|
|
7
34
|
function defineModel(modelName, definer, _parent) {
|
|
8
35
|
return function({ application, connection }) {
|
|
@@ -19,30 +46,8 @@ function defineModel(modelName, definer, _parent) {
|
|
|
19
46
|
if (typeof Model.onModelClassCreate === 'function')
|
|
20
47
|
Model = Model.onModelClassCreate(Model, definerArgs);
|
|
21
48
|
|
|
22
|
-
|
|
23
|
-
let tablePrefix = application.getDBTablePrefix();
|
|
24
|
-
|
|
25
|
-
if (tablePrefix)
|
|
26
|
-
tableName = (`${tablePrefix}${tableName}`);
|
|
27
|
-
|
|
28
|
-
Model.getTableName = () => tableName;
|
|
29
|
-
Model.getModelName = () => modelName;
|
|
30
|
-
Model.getApplication = () => application;
|
|
31
|
-
Model.getLogger = () => application.getLogger();
|
|
32
|
-
Model._getConnection = (_connection) => {
|
|
33
|
-
if (_connection)
|
|
34
|
-
return _connection;
|
|
35
|
-
|
|
36
|
-
return connection;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
if (typeof Model.onModelClassFinalized === 'function')
|
|
40
|
-
Model = Model.onModelClassFinalized(Model, definerArgs);
|
|
41
|
-
|
|
42
|
-
return { [modelName]: Model };
|
|
49
|
+
return _setupModel(modelName, Model, { application, connection });
|
|
43
50
|
};
|
|
44
51
|
}
|
|
45
52
|
|
|
46
|
-
module.exports = {
|
|
47
|
-
defineModel,
|
|
48
|
-
};
|
|
53
|
+
module.exports = { defineModel, registerModel };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Application } from '../application';
|
|
2
|
+
import { Logger } from '../logger';
|
|
3
|
+
import { ConnectionBase, Model as _Model, ModelClass } from 'mythix-orm';
|
|
4
|
+
import { DefineModelContext } from './model-utils';
|
|
5
|
+
|
|
6
|
+
export declare class Model extends _Model {
|
|
7
|
+
declare public static getTableName: () => string;
|
|
8
|
+
declare public static getModelName: () => string;
|
|
9
|
+
declare public static getApplication: () => Application;
|
|
10
|
+
declare public static getLogger: () => Logger;
|
|
11
|
+
declare public static _getConnection: (connection?: ConnectionBase) => ConnectionBase;
|
|
12
|
+
declare public static onModelClassFinalized?: (Model: ModelClass, definerArgs: DefineModelContext<Model>) => ModelClass;
|
|
13
|
+
|
|
14
|
+
public getApplication(): Application;
|
|
15
|
+
public getLogger(): Logger;
|
|
16
|
+
public getDBConnection(connection): ConnectionBase;
|
|
17
|
+
}
|
package/src/models/model.js
CHANGED
|
@@ -21,6 +21,10 @@ class Model extends _Model {
|
|
|
21
21
|
return this.constructor.getModel(modelName);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
getModels() {
|
|
25
|
+
return this.constructor.getModels();
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
getApplication() {
|
|
25
29
|
return this.constructor.getApplication();
|
|
26
30
|
}
|
|
@@ -50,39 +54,6 @@ class Model extends _Model {
|
|
|
50
54
|
|
|
51
55
|
return this.getDBConnection();
|
|
52
56
|
}
|
|
53
|
-
|
|
54
|
-
overrideMethod(name, newMethod) {
|
|
55
|
-
let originalMethod = this[name];
|
|
56
|
-
if (typeof originalMethod !== 'function')
|
|
57
|
-
throw new TypeError(`Model: Error while attempting to override method "${name}: No such method found"`);
|
|
58
|
-
|
|
59
|
-
let boundMethod = newMethod.bind(this, originalMethod.bind(this));
|
|
60
|
-
boundMethod.unbound = newMethod;
|
|
61
|
-
boundMethod.super = originalMethod;
|
|
62
|
-
|
|
63
|
-
Object.defineProperties(this, {
|
|
64
|
-
[name]: {
|
|
65
|
-
writable: true,
|
|
66
|
-
enumerable: false,
|
|
67
|
-
configurable: true,
|
|
68
|
-
value: boundMethod,
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
return originalMethod;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
overrideMethods(methodsObj) {
|
|
76
|
-
let keys = Object.keys(methodsObj);
|
|
77
|
-
for (let i = 0, il = keys.length; i < il; i++) {
|
|
78
|
-
let name = keys[i];
|
|
79
|
-
let method = methodsObj[name];
|
|
80
|
-
|
|
81
|
-
this.overrideMethod(name, method);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
57
|
}
|
|
85
58
|
|
|
86
|
-
module.exports = {
|
|
87
|
-
Model,
|
|
88
|
-
};
|
|
59
|
+
module.exports = { Model };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { GenericObject } from '../interfaces/common';
|
|
2
|
+
import { Application } from '../application';
|
|
3
|
+
import { Logger } from '../logger';
|
|
4
|
+
|
|
5
|
+
export declare type BaseModuleClass = typeof BaseModule;
|
|
6
|
+
|
|
7
|
+
export declare type ModuleClasses = Array<BaseModuleClass>;
|
|
8
|
+
export declare type Modules = Array<BaseModule>;
|
|
9
|
+
|
|
10
|
+
export declare class BaseModule {
|
|
11
|
+
public declare static fileWatcherQueueName: string;
|
|
12
|
+
|
|
13
|
+
public static getModuleName(): string;
|
|
14
|
+
public static shouldUse(options?: GenericObject): boolean;
|
|
15
|
+
|
|
16
|
+
public fileWatcherGetMonitorPaths(options?: GenericObject): Array<string>;
|
|
17
|
+
public fileWatcherHandler(options?: GenericObject): Promise<void>;
|
|
18
|
+
|
|
19
|
+
public constructor(application: Application);
|
|
20
|
+
public getApplication(): Application;
|
|
21
|
+
public getLogger(): Logger;
|
|
22
|
+
public getConfigValue(...args: Array<any>): any;
|
|
23
|
+
public start(options?: GenericObject): Promise<any>;
|
|
24
|
+
public stop(): Promise<any>;
|
|
25
|
+
|
|
26
|
+
declare public application: Application;
|
|
27
|
+
}
|
|
@@ -5,6 +5,10 @@ class BaseModule {
|
|
|
5
5
|
throw new Error('BaseModule::getModuleName: Should not have been called. Child module must implement "static getModuleName(){}"');
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
static shouldUse() {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
constructor(application) {
|
|
9
13
|
Object.defineProperties(this, {
|
|
10
14
|
'application': {
|
|
@@ -36,6 +40,4 @@ class BaseModule {
|
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
module.exports = {
|
|
40
|
-
BaseModule,
|
|
41
|
-
};
|
|
43
|
+
module.exports = { BaseModule };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ConnectionBase } from 'mythix-orm';
|
|
2
|
+
import { GenericObject } from '../interfaces/common';
|
|
3
|
+
import { BaseModule } from './base-module';
|
|
4
|
+
|
|
5
|
+
export declare class DatabaseModule extends BaseModule {
|
|
6
|
+
public getDatabaseConfig(): GenericObject;
|
|
7
|
+
public getConfig(): GenericObject;
|
|
8
|
+
public getTablePrefix(): string | null;
|
|
9
|
+
public getConnection(): ConnectionBase;
|
|
10
|
+
public connectToDatabase(databaseConfig: GenericObject): Promise<ConnectionBase>;
|
|
11
|
+
|
|
12
|
+
declare public connection: ConnectionBase;
|
|
13
|
+
declare public databaseConfig: GenericObject;
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GenericObject } from '../interfaces/common';
|
|
2
|
+
import { BaseModule } from './base-module';
|
|
3
|
+
|
|
4
|
+
export declare class FileWatcherModule extends BaseModule {
|
|
5
|
+
public getMonitoredPaths(options?: GenericObject): Array<string>;
|
|
6
|
+
public isWatchedFile(monitoredPaths: Array<string>, filePath: string): boolean;
|
|
7
|
+
public getFileScope(options: GenericObject, filePath: string): string;
|
|
8
|
+
public autoReload(enable?: boolean, shuttingDown?: boolean): Promise<void>;
|
|
9
|
+
public watchedFilesChanged(files: GenericObject): Promise<void>;
|
|
10
|
+
|
|
11
|
+
declare public fileWatcher: any;
|
|
12
|
+
declare public watchedPathsCache: Array<string>;
|
|
13
|
+
}
|
package/src/modules/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const BaseModule = require('./base-module');
|
|
4
|
-
const DatabaseModule = require('./database-module');
|
|
5
|
-
const FileWatcherModule = require('./file-watcher-module');
|
|
3
|
+
const { BaseModule } = require('./base-module');
|
|
4
|
+
const { DatabaseModule } = require('./database-module');
|
|
5
|
+
const { FileWatcherModule } = require('./file-watcher-module');
|
|
6
6
|
|
|
7
|
-
module.exports =
|
|
7
|
+
module.exports = {
|
|
8
8
|
BaseModule,
|
|
9
9
|
DatabaseModule,
|
|
10
10
|
FileWatcherModule,
|
|
11
|
-
|
|
11
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { GenericObject } from '../interfaces/common';
|
|
2
|
+
import { Application } from '../application';
|
|
3
|
+
import { Logger } from '../logger';
|
|
4
|
+
import { ConnectionBase, ModelClass, Models } from 'mythix-orm';
|
|
5
|
+
|
|
6
|
+
export declare type Tasks = { [ key: string ]: TaskBase };
|
|
7
|
+
|
|
8
|
+
export declare type TaskClass = typeof TaskBase;
|
|
9
|
+
|
|
10
|
+
export declare interface TaskInfo {
|
|
11
|
+
_startTime: number;
|
|
12
|
+
lastTime: number;
|
|
13
|
+
failedCount: number;
|
|
14
|
+
taskInstance: TaskBase;
|
|
15
|
+
runID: string;
|
|
16
|
+
promise: Promise<any>;
|
|
17
|
+
stop: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare class TaskBase {
|
|
21
|
+
public static onTaskClassCreate(Klass: TaskClass): TaskClass;
|
|
22
|
+
|
|
23
|
+
public static getFrequency(taskIndex?: number): number;
|
|
24
|
+
public static getStartDelay(taskIndex?: number): number;
|
|
25
|
+
public static shouldRun(taskIndex: number, lastTime: number | null, currentTime: number, diff: number): boolean;
|
|
26
|
+
|
|
27
|
+
declare public application: Application;
|
|
28
|
+
declare public logger: Logger;
|
|
29
|
+
declare public runID: string;
|
|
30
|
+
|
|
31
|
+
public constructor(application: Application, logger: Logger, runID: string);
|
|
32
|
+
public start(options?: GenericObject): Promise<any>;
|
|
33
|
+
public stop(): Promise<any>;
|
|
34
|
+
public getApplication(): Application;
|
|
35
|
+
public getLogger(): Logger;
|
|
36
|
+
public getRunID(): string;
|
|
37
|
+
public getNumberOfWorkers(): number;
|
|
38
|
+
public getModel(name: string): ModelClass;
|
|
39
|
+
public getModels(): Models;
|
|
40
|
+
public getDBConnection(): ConnectionBase;
|
|
41
|
+
public getFrequency(taskIndex?: number): number;
|
|
42
|
+
public getStartDelay(taskIndex?: number): number;
|
|
43
|
+
}
|
package/src/tasks/task-base.js
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
class TaskBase {
|
|
4
|
+
static onTaskClassCreate(Klass) {
|
|
5
|
+
return Klass;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line no-unused-vars
|
|
9
|
+
static getFrequency(taskIndex) {
|
|
10
|
+
return this._frequency || 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static getStartDelay(taskIndex) {
|
|
14
|
+
let workers = this.workers || 1;
|
|
15
|
+
let frequency = this.getFrequency(taskIndex);
|
|
16
|
+
let startDelay = this._startDelay || 0;
|
|
17
|
+
|
|
18
|
+
if (workers > 1) {
|
|
19
|
+
let shift = (frequency / workers);
|
|
20
|
+
startDelay = startDelay + (shift * taskIndex);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return startDelay;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static shouldRun(taskIndex, lastTime, currentTime, diff) {
|
|
27
|
+
if (!lastTime) {
|
|
28
|
+
if (diff >= this.getStartDelay(taskIndex))
|
|
29
|
+
return true;
|
|
30
|
+
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (diff >= this.getFrequency(taskIndex))
|
|
35
|
+
return true;
|
|
36
|
+
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
4
40
|
constructor(application, logger, runID) {
|
|
5
41
|
Object.defineProperties(this, {
|
|
6
42
|
'application': {
|
|
@@ -69,54 +105,13 @@ class TaskBase {
|
|
|
69
105
|
return application.getDBConnection();
|
|
70
106
|
}
|
|
71
107
|
|
|
72
|
-
getFrequency() {
|
|
73
|
-
return this.constructor.getFrequency();
|
|
108
|
+
getFrequency(taskIndex) {
|
|
109
|
+
return this.constructor.getFrequency(taskIndex);
|
|
74
110
|
}
|
|
75
111
|
|
|
76
|
-
getStartDelay() {
|
|
77
|
-
return this.constructor.getStartDelay();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
static onTaskClassCreate(Klass) {
|
|
81
|
-
Klass.getFrequency = Klass.getFrequency.bind(this, Klass);
|
|
82
|
-
Klass.getStartDelay = Klass.getStartDelay.bind(this, Klass);
|
|
83
|
-
Klass.shouldRun = Klass.shouldRun.bind(this, Klass);
|
|
84
|
-
|
|
85
|
-
return Klass;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
static getFrequency(Task /*, taskIndex */) {
|
|
89
|
-
return Task._frequency || 0;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
static getStartDelay(Task, taskIndex) {
|
|
93
|
-
let workers = Task.workers || 1;
|
|
94
|
-
let frequency = Task.getFrequency(taskIndex);
|
|
95
|
-
let startDelay = Task._startDelay || 0;
|
|
96
|
-
|
|
97
|
-
if (workers > 1) {
|
|
98
|
-
let shift = (frequency / workers);
|
|
99
|
-
startDelay = startDelay + (shift * taskIndex);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return startDelay;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
static shouldRun(Task, taskIndex, lastTime, currentTime, diff) {
|
|
106
|
-
if (!lastTime) {
|
|
107
|
-
if (diff >= Task.getStartDelay(taskIndex))
|
|
108
|
-
return true;
|
|
109
|
-
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (diff >= Task.getFrequency(taskIndex))
|
|
114
|
-
return true;
|
|
115
|
-
|
|
116
|
-
return false;
|
|
112
|
+
getStartDelay(taskIndex) {
|
|
113
|
+
return this.constructor.getStartDelay(taskIndex);
|
|
117
114
|
}
|
|
118
115
|
}
|
|
119
116
|
|
|
120
|
-
module.exports = {
|
|
121
|
-
TaskBase,
|
|
122
|
-
};
|
|
117
|
+
module.exports = { TaskBase };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseModule } from '../modules/base-module';
|
|
2
|
+
import { Tasks, TaskInfo } from './task-base';
|
|
3
|
+
|
|
4
|
+
export declare class TaskModule extends BaseModule {
|
|
5
|
+
public getTaskFilePaths(tasksPath: string): Array<string>;
|
|
6
|
+
public loadTasks(tasksPath: string): Tasks;
|
|
7
|
+
public runTasks(): Promise<void>;
|
|
8
|
+
public stopTasks(): void;
|
|
9
|
+
public startTasks(flushTaskInfo): Promise<void>;
|
|
10
|
+
public stopAllTasks(): Promise<void>
|
|
11
|
+
public iterateAllTaskInfos(callback: (taskInfo: TaskInfo, index: number, taskName: string) => void): void;
|
|
12
|
+
public getAllTaskPromises(): Array<Promise<any>>;
|
|
13
|
+
public waitForAllTasksToFinish(): Promise<void>;
|
|
14
|
+
|
|
15
|
+
declare public tasks: Tasks;
|
|
16
|
+
declare public taskInfo: { [ key: string ]: TaskInfo };
|
|
17
|
+
}
|