mythix 2.4.14 → 2.5.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.
- package/package.json +9 -7
- package/src/application.d.ts +88 -0
- package/src/application.js +1 -3
- 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-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/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/index.d.ts +3 -0
- package/src/http-server/index.js +1 -6
- package/src/index.d.ts +49 -0
- package/src/index.js +8 -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 +1 -3
- 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 +1 -3
- 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/tasks/task-utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const Nife
|
|
4
|
-
const
|
|
3
|
+
const Nife = require('nife');
|
|
4
|
+
const TaskBase = require('./task-base');
|
|
5
5
|
|
|
6
6
|
const SECONDS_PER_MINUTE = 60;
|
|
7
7
|
const MINUTES_PER_HOUR = 60;
|
|
@@ -54,20 +54,20 @@ class TimeHelpers {
|
|
|
54
54
|
return new TimeHelpers();
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
days(
|
|
58
|
-
return this.clone(
|
|
57
|
+
days(days) {
|
|
58
|
+
return this.clone(days);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
hours(
|
|
62
|
-
return this.clone(undefined,
|
|
61
|
+
hours(hours) {
|
|
62
|
+
return this.clone(undefined, hours);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
minutes(
|
|
66
|
-
return this.clone(undefined, undefined,
|
|
65
|
+
minutes(minutes) {
|
|
66
|
+
return this.clone(undefined, undefined, minutes);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
seconds(
|
|
70
|
-
return this.clone(undefined, undefined, undefined,
|
|
69
|
+
seconds(seconds) {
|
|
70
|
+
return this.clone(undefined, undefined, undefined, seconds);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
totalSeconds() {
|
|
@@ -125,6 +125,6 @@ function defineTask(taskName, definer, _parent) {
|
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
};
|
|
128
|
+
defineTask.TimeHelpers = TimeHelpers;
|
|
129
|
+
|
|
130
|
+
module.exports = { defineTask };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
|
|
2
|
+
export declare function randomBytes(length: number): Buffer;
|
|
3
|
+
export declare function MD5(data: string): string;
|
|
4
|
+
export declare function SHA256(data: string): string;
|
|
5
|
+
export declare function SHA512(data: string): string;
|
|
6
|
+
export declare function randomHash(type?: string, length?: number): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Stats } from 'fs';
|
|
2
|
+
|
|
3
|
+
export declare interface WalkDirOptions {
|
|
4
|
+
filter: RegExp | ((fullFileName: string, fileName: string, stats: Stats, rootPath: string, depth: number) => boolean);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export declare type WalkDirCallback = () => void;
|
|
8
|
+
|
|
9
|
+
export declare function walkDir(rootPath: string, options?: WalkDirOptions | WalkDirCallback, callback?: WalkDirCallback);
|
|
10
|
+
export declare function fileNameWithoutExtension(fileName: string): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { GenericObject } from '../interfaces/common';
|
|
2
|
+
|
|
3
|
+
export declare class HTTPInterface {
|
|
4
|
+
declare public defaultURL: string | null;
|
|
5
|
+
declare public defaultHeaders: GenericObject;
|
|
6
|
+
|
|
7
|
+
public constructor();
|
|
8
|
+
public getDefaultURL(): string;
|
|
9
|
+
public setDefaultURL(url: string): void;
|
|
10
|
+
public getDefaultHeader(headerName: string): string | undefined;
|
|
11
|
+
public getDefaultHeaders(): GenericObject;
|
|
12
|
+
public setDefaultHeader(headerName: string, value: string): void;
|
|
13
|
+
public setDefaultHeaders(headers: { [ key: string ]: string }): void;
|
|
14
|
+
public keysToLowerCase(obj: { [ key: string ]: string }): { [ key: string ]: string };
|
|
15
|
+
public makeRequest(requestOptions: GenericObject): Promise<any>;
|
|
16
|
+
public getRequestOptions(url: string, options: GenericObject, method: string): GenericObject;
|
|
17
|
+
public request(url: string, options: GenericObject): Promise<any>;
|
|
18
|
+
public getRequest(url: string, options: GenericObject): Promise<any>;
|
|
19
|
+
public postRequest(url: string, options: GenericObject): Promise<any>;
|
|
20
|
+
public patchRequest(url: string, options: GenericObject): Promise<any>;
|
|
21
|
+
public putRequest(url: string, options: GenericObject): Promise<any>;
|
|
22
|
+
public deleteRequest(url: string, options: GenericObject): Promise<any>;
|
|
23
|
+
public headRequest(url: string, options: GenericObject): Promise<any>;
|
|
24
|
+
public optionsRequest(url: string, options: GenericObject): Promise<any>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './file-utils';
|
|
2
|
+
export * from './config-utils';
|
|
3
|
+
export * as HTTPUtils from './http-utils';
|
|
4
|
+
export * as CryptoUtils from './crypto-utils';
|
|
5
|
+
export * as TestUtils from './test-utils';
|
|
6
|
+
export * as MimeUtils from './mime-utils';
|
|
7
|
+
export * from './http-interface';
|
package/src/utils/index.js
CHANGED
|
@@ -15,11 +15,11 @@ const { HTTPInterface } = require('./http-interface');
|
|
|
15
15
|
|
|
16
16
|
module.exports = {
|
|
17
17
|
CryptoUtils,
|
|
18
|
-
fileNameWithoutExtension,
|
|
19
18
|
HTTPUtils,
|
|
20
19
|
MimeUtils,
|
|
21
20
|
TestUtils,
|
|
21
|
+
HTTPInterface,
|
|
22
|
+
fileNameWithoutExtension,
|
|
22
23
|
walkDir,
|
|
23
24
|
wrapConfig,
|
|
24
|
-
HTTPInterface,
|
|
25
25
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
export declare function getFileExtensionFromMimeType(mimeType: string): string | undefined;
|
|
3
|
+
export declare function getFilenameExtension(fileName: string): string | undefined;
|
|
4
|
+
export declare function getMimeTypeFromFileExtension(fileExtension: string): string | undefined;
|
|
5
|
+
export declare function getMimeTypeFromFilename(fileName: string): string | undefined;
|
package/src/utils/test-utils.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
const Nife = require('nife');
|
|
6
6
|
const { Utils } = require('mythix-orm');
|
|
7
|
-
const
|
|
7
|
+
const Logger = require('../logger');
|
|
8
|
+
const DatabaseModule = require('../modules/database-module');
|
|
8
9
|
const { HTTPInterface } = require('./http-interface');
|
|
9
|
-
const { DatabaseModule } = require('../modules/database-module');
|
|
10
10
|
const { HTTPServerModule } = require('../http-server/http-server-module');
|
|
11
11
|
|
|
12
12
|
class TestDatabaseModule extends DatabaseModule {
|
|
@@ -52,16 +52,16 @@ class TestHTTPServerModule extends HTTPServerModule {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
function createTestApplication(
|
|
56
|
-
const Klass = class TestApplication extends
|
|
57
|
-
static APP_NAME = `${(Nife.isNotEmpty(
|
|
55
|
+
function createTestApplication(ApplicationClass) {
|
|
56
|
+
const Klass = class TestApplication extends ApplicationClass {
|
|
57
|
+
static APP_NAME = `${(Nife.isNotEmpty(ApplicationClass.APP_NAME)) ? ApplicationClass.APP_NAME : 'mythix'}_test`;
|
|
58
58
|
|
|
59
59
|
// Swap out modules for test config
|
|
60
60
|
static getDefaultModules() {
|
|
61
|
-
let defaultModules =
|
|
61
|
+
let defaultModules = ApplicationClass.getDefaultModules();
|
|
62
62
|
|
|
63
|
-
defaultModules =
|
|
64
|
-
defaultModules =
|
|
63
|
+
defaultModules = ApplicationClass.replaceModule(defaultModules, DatabaseModule, TestDatabaseModule);
|
|
64
|
+
defaultModules = ApplicationClass.replaceModule(defaultModules, HTTPServerModule, TestHTTPServerModule);
|
|
65
65
|
|
|
66
66
|
return defaultModules;
|
|
67
67
|
}
|
|
@@ -229,6 +229,4 @@ function createTestApplication(Application) {
|
|
|
229
229
|
return Klass;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
module.exports = {
|
|
233
|
-
createTestApplication,
|
|
234
|
-
};
|
|
232
|
+
module.exports = { createTestApplication };
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Nife = require('nife');
|
|
4
|
-
const {
|
|
5
|
-
buildPatternMatcher,
|
|
6
|
-
buildMethodMatcher,
|
|
7
|
-
buildContentTypeMatcher,
|
|
8
|
-
} = require('../../controllers/controller-utils');
|
|
9
|
-
|
|
10
|
-
const CONDITIONAL_OBJECT_HELPERS = {
|
|
11
|
-
'controller': (request) => Nife.get(request, 'routeInfo.controller'),
|
|
12
|
-
'path': (request) => Nife.get(request, 'url'),
|
|
13
|
-
'methods': (request) => Nife.get(request, 'method'),
|
|
14
|
-
'contentType': (request) => Nife.get(request, 'headers.content-type'),
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
function conditional(middleware, conditions) {
|
|
18
|
-
const createConditionsFromObject = (obj) => {
|
|
19
|
-
let helperKeys = Object.keys(CONDITIONAL_OBJECT_HELPERS);
|
|
20
|
-
let keys = Object.keys(obj);
|
|
21
|
-
let matchers = [];
|
|
22
|
-
|
|
23
|
-
for (let i = 0, il = keys.length; i < il; i++) {
|
|
24
|
-
let key = keys[i];
|
|
25
|
-
if (helperKeys.indexOf(key) < 0)
|
|
26
|
-
continue;
|
|
27
|
-
|
|
28
|
-
let helper = CONDITIONAL_OBJECT_HELPERS[key];
|
|
29
|
-
let value = obj[key];
|
|
30
|
-
|
|
31
|
-
if (Nife.instanceOf(value, 'string', 'array', RegExp)) {
|
|
32
|
-
if (key === 'methods')
|
|
33
|
-
value = buildMethodMatcher(value);
|
|
34
|
-
else if (key === 'contentType')
|
|
35
|
-
value = buildContentTypeMatcher(value);
|
|
36
|
-
else
|
|
37
|
-
value = buildPatternMatcher(value);
|
|
38
|
-
} else if (typeof value !== 'function') {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
matchers.push({
|
|
43
|
-
matcher: value,
|
|
44
|
-
helper,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (!matchers.length)
|
|
49
|
-
throw new Error('No matchable patterns found');
|
|
50
|
-
|
|
51
|
-
return function patternMatcher(request) {
|
|
52
|
-
for (let i = 0, il = matchers.length; i < il; i++) {
|
|
53
|
-
let matcher = matchers[i];
|
|
54
|
-
let helper = matcher.helper;
|
|
55
|
-
let value = helper.call(this, request);
|
|
56
|
-
|
|
57
|
-
if (!matcher.matcher.call(this, value))
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return true;
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const createConditionsFromArray = (conditionsToCreate) => {
|
|
66
|
-
let matchers = [];
|
|
67
|
-
for (let i = 0, il = conditionsToCreate.length; i < il; i++) {
|
|
68
|
-
let condition = conditionsToCreate[i];
|
|
69
|
-
|
|
70
|
-
if (typeof condition === 'function')
|
|
71
|
-
matchers.push(condition);
|
|
72
|
-
else if (Nife.instanceOf(condition, 'object'))
|
|
73
|
-
matchers.push(createConditionsFromObject(condition));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return function patternMatcher(request) {
|
|
77
|
-
for (let i = 0, il = matchers.length; i < il; i++) {
|
|
78
|
-
let matcher = matchers[i];
|
|
79
|
-
if (!matcher.call(this, request))
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return true;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
let conditionChecker;
|
|
88
|
-
|
|
89
|
-
if (Nife.instanceOf(conditions, 'object'))
|
|
90
|
-
conditionChecker = createConditionsFromObject(conditions);
|
|
91
|
-
else if (Nife.instanceOf(conditions, 'array'))
|
|
92
|
-
conditionChecker = createConditionsFromArray(conditions);
|
|
93
|
-
else if (Nife.instanceOf(conditions, 'function'))
|
|
94
|
-
conditionChecker = conditions;
|
|
95
|
-
else
|
|
96
|
-
throw new Error('Invalid condition supplied');
|
|
97
|
-
|
|
98
|
-
return function(request, response, next) {
|
|
99
|
-
if (!conditionChecker.call(this, request))
|
|
100
|
-
return next();
|
|
101
|
-
|
|
102
|
-
return middleware.call(this, request, response, next);
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function jsonParser() {
|
|
107
|
-
return function(request, response, next) {
|
|
108
|
-
if (('' + request.headers['content-type']).match(/application\/json/i) && typeof request.body === 'string') {
|
|
109
|
-
request.rawBody = request.body;
|
|
110
|
-
request.body = JSON.parse(request.body);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return next();
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
module.exports = {
|
|
118
|
-
conditional,
|
|
119
|
-
jsonParser,
|
|
120
|
-
};
|