mythix 3.0.0 → 4.0.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/LICENSE +1 -1
- package/README.md +27 -30
- package/{src → lib}/application.d.ts +25 -39
- package/{src/application.js → lib/application.mjs} +110 -135
- package/lib/cli/cli-utils.d.ts +21 -0
- package/lib/cli/cli-utils.mjs +319 -0
- package/lib/cli/command-base.d.ts +33 -0
- package/lib/cli/command-base.mjs +118 -0
- package/lib/cli/command-executor.mjs +14 -0
- package/lib/cli/commands/deploy-command.mjs +1010 -0
- package/lib/cli/commands/generators/generate-command.mjs +117 -0
- package/lib/cli/commands/generators/index.mjs +2 -0
- package/{src/cli/generators/migration-generator.js → lib/cli/commands/generators/migration-generator.mjs} +11 -13
- package/lib/cli/commands/index.mjs +22 -0
- package/lib/cli/commands/migrate-command.mjs +184 -0
- package/lib/cli/commands/routes-command.mjs +40 -0
- package/lib/cli/commands/serve-command.mjs +63 -0
- package/lib/cli/commands/shell-command.mjs +95 -0
- package/lib/cli/index.mjs +3 -0
- package/{src → lib}/controllers/controller-base.d.ts +1 -1
- package/{src/controllers/controller-base.js → lib/controllers/controller-base.mjs} +3 -9
- package/{src → lib}/controllers/controller-module.d.ts +3 -3
- package/lib/controllers/controller-module.mjs +70 -0
- package/lib/controllers/generate-client-api-interface-spec.mjs +44 -0
- package/{src → lib}/controllers/generate-client-api-interface.d.ts +1 -0
- package/{src/controllers/generate-client-api-interface.js → lib/controllers/generate-client-api-interface.mjs} +39 -16
- package/{src → lib}/controllers/index.d.ts +2 -3
- package/lib/controllers/index.mjs +4 -0
- package/lib/controllers/routes/index.mjs +4 -0
- package/{src/controllers/routes/route-capture.js → lib/controllers/routes/route-capture.mjs} +2 -8
- package/{src/controllers/routes/route-endpoint.js → lib/controllers/routes/route-endpoint.mjs} +8 -8
- package/{src/controllers/routes/route-scope-base.js → lib/controllers/routes/route-scope-base.mjs} +19 -15
- package/{src/controllers/routes/route-scope.js → lib/controllers/routes/route-scope.mjs} +10 -12
- package/{src/http-server/http-errors.js → lib/http/http-errors.mjs} +9 -20
- package/{src/utils/http-interface.js → lib/http/http-interface.mjs} +6 -14
- package/{src/http-server → lib/http}/http-server-module.d.ts +2 -2
- package/{src/http-server/http-server-module.js → lib/http/http-server-module.mjs} +7 -11
- package/{src/http-server/http-server.js → lib/http/http-server.mjs} +17 -21
- package/lib/http/index.d.ts +4 -0
- package/lib/http/index.mjs +5 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.mjs +31 -0
- package/lib/logger-spec.mjs +121 -0
- package/{src → lib}/logger.d.ts +1 -3
- package/{src/logger.js → lib/logger.mjs} +10 -24
- package/lib/models/index.d.ts +2 -0
- package/lib/models/index.mjs +2 -0
- package/{src/models/migration-model.js → lib/models/migration-model.mjs} +3 -11
- package/lib/models/model.d.ts +10 -0
- package/lib/models/model.mjs +28 -0
- package/{src → lib}/modules/database-module.d.ts +2 -2
- package/{src/modules/database-module.js → lib/modules/database-module.mjs} +19 -14
- package/lib/modules/index.d.ts +2 -0
- package/lib/modules/index.mjs +2 -0
- package/{src/modules/base-module.d.ts → lib/modules/module-base.d.ts} +3 -10
- package/{src/modules/base-module.js → lib/modules/module-base.mjs} +16 -6
- package/lib/tasks/index.d.ts +2 -0
- package/lib/tasks/index.mjs +2 -0
- package/{src → lib}/tasks/task-base.d.ts +4 -14
- package/lib/tasks/task-base.mjs +73 -0
- package/{src → lib}/tasks/task-module.d.ts +3 -3
- package/{src/tasks/task-module.js → lib/tasks/task-module.mjs} +43 -98
- package/{src/utils/config-utils.js → lib/utils/config-utils.mjs} +2 -10
- package/lib/utils/crypto-utils-spec.mjs +24 -0
- package/{src/utils/crypto-utils.js → lib/utils/crypto-utils.mjs} +16 -38
- package/lib/utils/file-utils-spec.mjs +10 -0
- package/{src/utils/file-utils.js → lib/utils/file-utils.mjs} +4 -11
- package/{src/utils/http-utils.js → lib/utils/http-utils.mjs} +3 -10
- package/{src → lib}/utils/index.d.ts +1 -1
- package/lib/utils/index.mjs +6 -0
- package/lib/utils/mime-utils-spec.mjs +171 -0
- package/{src/utils/mime-utils.js → lib/utils/mime-utils.mjs} +5 -14
- package/{src/utils/test-utils.js → lib/utils/test-utils.mjs} +14 -42
- package/package.json +5 -5
- package/src/cli/cli-utils.d.ts +0 -80
- package/src/cli/cli-utils.js +0 -547
- package/src/cli/command-executor.js +0 -31
- package/src/cli/deploy-command.js +0 -1010
- package/src/cli/generators/generate-command.js +0 -149
- package/src/cli/index.js +0 -5
- package/src/cli/migrate-command.js +0 -181
- package/src/cli/routes-command.js +0 -40
- package/src/cli/serve-command.js +0 -63
- package/src/cli/shell-command.js +0 -96
- package/src/controllers/controller-module.js +0 -126
- package/src/controllers/controller-utils.d.ts +0 -19
- package/src/controllers/controller-utils.js +0 -24
- package/src/controllers/index.js +0 -19
- package/src/controllers/routes/index.js +0 -31
- package/src/http-server/index.d.ts +0 -3
- package/src/http-server/index.js +0 -16
- package/src/index.d.ts +0 -49
- package/src/index.js +0 -47
- package/src/models/index.d.ts +0 -4
- package/src/models/index.js +0 -17
- package/src/models/model-module.d.ts +0 -9
- package/src/models/model-module.js +0 -130
- package/src/models/model-utils.d.ts +0 -20
- package/src/models/model-utils.js +0 -46
- package/src/models/model.d.ts +0 -20
- package/src/models/model.js +0 -65
- package/src/modules/file-watcher-module.d.ts +0 -13
- package/src/modules/file-watcher-module.js +0 -220
- package/src/modules/index.d.ts +0 -3
- package/src/modules/index.js +0 -11
- package/src/tasks/index.d.ts +0 -3
- package/src/tasks/index.js +0 -11
- package/src/tasks/task-base.js +0 -117
- package/src/tasks/task-utils.d.ts +0 -46
- package/src/tasks/task-utils.js +0 -130
- package/src/utils/index.js +0 -25
- /package/{src → lib}/cli/index.d.ts +0 -0
- /package/{src → lib}/controllers/routes/index.d.ts +0 -0
- /package/{src → lib}/controllers/routes/route-capture.d.ts +0 -0
- /package/{src → lib}/controllers/routes/route-endpoint.d.ts +0 -0
- /package/{src → lib}/controllers/routes/route-scope-base.d.ts +0 -0
- /package/{src → lib}/controllers/routes/route-scope.d.ts +0 -0
- /package/{src/http-server → lib/http}/http-errors.d.ts +0 -0
- /package/{src/utils → lib/http}/http-interface.d.ts +0 -0
- /package/{src/http-server → lib/http}/http-server.d.ts +0 -0
- /package/{src → lib}/interfaces/common.ts +0 -0
- /package/{src → lib}/models/migration-model.d.ts +0 -0
- /package/{src → lib}/utils/config-utils.d.ts +0 -0
- /package/{src → lib}/utils/crypto-utils.d.ts +0 -0
- /package/{src → lib}/utils/file-utils.d.ts +0 -0
- /package/{src → lib}/utils/http-utils.d.ts +0 -0
- /package/{src → lib}/utils/mime-utils.d.ts +0 -0
- /package/{src → lib}/utils/test-utils.d.ts +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import Nife from 'nife';
|
|
2
|
+
import { ModuleBase } from '../modules/module-base.mjs';
|
|
3
|
+
|
|
4
|
+
export class ControllerModule extends ModuleBase {
|
|
5
|
+
static getOptionsScopeName() {
|
|
6
|
+
return 'controllers';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static shouldUse(application, options) {
|
|
10
|
+
if (options.httpServer === false)
|
|
11
|
+
return false;
|
|
12
|
+
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
constructor(application, opts) {
|
|
17
|
+
super(application, opts);
|
|
18
|
+
|
|
19
|
+
let _controllers;
|
|
20
|
+
|
|
21
|
+
Object.defineProperties(this, {
|
|
22
|
+
'controllers': {
|
|
23
|
+
enumerable: false,
|
|
24
|
+
configurable: true,
|
|
25
|
+
get: () => {
|
|
26
|
+
if (!_controllers)
|
|
27
|
+
_controllers = application.getAppControllerClasses();
|
|
28
|
+
|
|
29
|
+
return _controllers;
|
|
30
|
+
},
|
|
31
|
+
set: () => {},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Inject methods into the application
|
|
36
|
+
Object.defineProperties(application, {
|
|
37
|
+
'getController': {
|
|
38
|
+
writable: true,
|
|
39
|
+
enumerable: false,
|
|
40
|
+
configurable: true,
|
|
41
|
+
value: this.getController.bind(this),
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getController(name) {
|
|
47
|
+
let controllers = this.controllers;
|
|
48
|
+
let controllerName = name.replace(/(.*?)\b\w+$/, '$1');
|
|
49
|
+
let methodName = name.substring(controllerName.length);
|
|
50
|
+
if (!methodName)
|
|
51
|
+
methodName = undefined;
|
|
52
|
+
|
|
53
|
+
controllerName = controllerName.replace(/\W+$/g, '');
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
controller: Nife.get(controllers, controllerName),
|
|
57
|
+
controllerMethod: methodName,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async start() {
|
|
62
|
+
let application = this.getApplication();
|
|
63
|
+
let httpServer = (typeof application.getHTTPServer === 'function') ? application.getHTTPServer() : null;
|
|
64
|
+
|
|
65
|
+
httpServer.setRoutes(application._getRoutes());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async stop() {
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { generateClientAPIInterface } from './generate-client-api-interface.mjs';
|
|
2
|
+
import { newTestApplication } from '../../spec/support/application.mjs';
|
|
3
|
+
import { matchesSnapshot } from '../../spec/support/snapshots.mjs';
|
|
4
|
+
|
|
5
|
+
function getRoutes() {
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
describe('generateClientAPIInterface', () => {
|
|
9
|
+
let app;
|
|
10
|
+
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
try {
|
|
13
|
+
app = await newTestApplication();
|
|
14
|
+
app.getRoutes = getRoutes.bind(app);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.error('Error in beforeAll: ', error);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should be able to generate an interface using route definitions', () => {
|
|
21
|
+
let result = generateClientAPIInterface(app);
|
|
22
|
+
expect(matchesSnapshot(result)).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should be able to generate an interface for node', () => {
|
|
26
|
+
let result = generateClientAPIInterface(app, { environment: 'node' });
|
|
27
|
+
expect(matchesSnapshot(result)).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should be able to generate an interface for the browser', () => {
|
|
31
|
+
let result = generateClientAPIInterface(app, { environment: 'browser' });
|
|
32
|
+
expect(matchesSnapshot(result)).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should be able to export a global', () => {
|
|
36
|
+
let result = generateClientAPIInterface(app, { globalName: 'API' });
|
|
37
|
+
expect(matchesSnapshot(result)).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should be able to specify a domain', () => {
|
|
41
|
+
let result = generateClientAPIInterface(app, { domain: 'http://localhost:8080' });
|
|
42
|
+
expect(matchesSnapshot(result)).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -8,6 +8,7 @@ export declare interface GenerateClientInterfaceOptions {
|
|
|
8
8
|
mode?: string;
|
|
9
9
|
domain?: string;
|
|
10
10
|
routeFilter?: ((value: any, index?: number) => boolean) | RegExp | string;
|
|
11
|
+
type?: 'module' | 'commonjs';
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export declare function generateClientAPIInterface(application: Application, options?: GenerateClientInterfaceOptions): string;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-magic-numbers */
|
|
2
|
+
/* global Utils, globalScope, HTTP */
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Nife = require('nife');
|
|
6
|
-
const HTTPUtils = require('../utils/http-utils');
|
|
4
|
+
import Nife from 'nife';
|
|
5
|
+
import * as HTTPUtils from '../utils/http-utils.mjs';
|
|
7
6
|
|
|
8
7
|
function tabIn(str, amount) {
|
|
9
8
|
var padding = ''.padStart((amount || 1) * 2, ' ');
|
|
@@ -26,11 +25,11 @@ function nodeRequestHandler(routeName, requestOptions) {
|
|
|
26
25
|
return;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
var
|
|
30
|
-
var
|
|
28
|
+
var HTTPModule = (requestOptions.httpModule) ? requestOptions.httpModule : HTTP;
|
|
29
|
+
var URLModule = (requestOptions.urlModule) ? requestOptions.urlModule : URL;
|
|
31
30
|
|
|
32
31
|
var method = (requestOptions.method || 'GET').toUpperCase();
|
|
33
|
-
var url = new
|
|
32
|
+
var url = new URLModule.URL(requestOptions.url);
|
|
34
33
|
var data = requestOptions.data;
|
|
35
34
|
var extraConfig = {};
|
|
36
35
|
var headers = Object.assign({}, Utils.keysToLowerCase(this.defaultHeaders || {}), Utils.keysToLowerCase(requestOptions.headers || {}));
|
|
@@ -54,7 +53,7 @@ function nodeRequestHandler(routeName, requestOptions) {
|
|
|
54
53
|
} else {
|
|
55
54
|
var queryString = Utils.dataToQueryString(data);
|
|
56
55
|
if (queryString) {
|
|
57
|
-
var newParams = new
|
|
56
|
+
var newParams = new URLModule.URLSearchParams(queryString);
|
|
58
57
|
var keys = Array.from(newParams.keys());
|
|
59
58
|
|
|
60
59
|
for (var i = 0, il = keys.length; i < il; i++) {
|
|
@@ -88,7 +87,7 @@ function nodeRequestHandler(routeName, requestOptions) {
|
|
|
88
87
|
|
|
89
88
|
delete options.data;
|
|
90
89
|
|
|
91
|
-
var thisRequest =
|
|
90
|
+
var thisRequest = HTTPModule.request(Utils.cleanObjectProperties(options), function(response) {
|
|
92
91
|
var responseData = Buffer.alloc(0);
|
|
93
92
|
|
|
94
93
|
response.on('data', function(chunk) {
|
|
@@ -616,6 +615,7 @@ function generateAPIInterface(routes, _options) {
|
|
|
616
615
|
}
|
|
617
616
|
|
|
618
617
|
var apiInterface = Object.create({
|
|
618
|
+
${(environment === 'node') ? 'loaded: () => Promise.all(_loadingPromises).then(() => true)' : 'loaded: () => Promise.resolve(true)'},
|
|
619
619
|
defaultHeaders: {},
|
|
620
620
|
makeRequest,
|
|
621
621
|
getDefaultHeader,
|
|
@@ -632,17 +632,44 @@ function generateAPIInterface(routes, _options) {
|
|
|
632
632
|
}`;
|
|
633
633
|
}
|
|
634
634
|
|
|
635
|
-
function generateClientAPIInterface(application, _options) {
|
|
635
|
+
export function generateClientAPIInterface(application, _options) {
|
|
636
636
|
var options = _options || {};
|
|
637
637
|
var routes = application._getRoutes();
|
|
638
638
|
var globalName = (Object.prototype.hasOwnProperty.call(options, 'globalName')) ? options.globalName : '';
|
|
639
|
+
var environment = options.environment;
|
|
639
640
|
|
|
640
641
|
if (Nife.isNotEmpty(globalName))
|
|
641
642
|
globalName = `globalScope['${globalName}'] = APIInterface`;
|
|
642
643
|
else
|
|
643
644
|
globalName = '';
|
|
644
645
|
|
|
645
|
-
|
|
646
|
+
var preamble;
|
|
647
|
+
if (options.type === 'commonjs') {
|
|
648
|
+
preamble = [ '\'use strict\';\n' ];
|
|
649
|
+
|
|
650
|
+
if (environment === 'node') {
|
|
651
|
+
preamble = preamble.concat([
|
|
652
|
+
'var HTTP = require(\'node:http\');',
|
|
653
|
+
'var URL = require(\'node:url\');',
|
|
654
|
+
'var _loadingPromises = [ Promise.resolve() ];',
|
|
655
|
+
]);
|
|
656
|
+
}
|
|
657
|
+
} else {
|
|
658
|
+
if (environment === 'node') {
|
|
659
|
+
preamble = [
|
|
660
|
+
'var HTTP;',
|
|
661
|
+
'var URL;',
|
|
662
|
+
'var _loadingPromises = [',
|
|
663
|
+
' import(\'node:http\').then((M) => (HTTP = M), (error) => { throw error }),',
|
|
664
|
+
' import(\'node:url\').then((M) => (URL = M), (error) => { throw error }),',
|
|
665
|
+
'];',
|
|
666
|
+
];
|
|
667
|
+
} else {
|
|
668
|
+
preamble = [ '\'use strict\';\n' ];
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
return `${preamble.join('\n')}
|
|
646
673
|
(function(globalScope, environmentType) {
|
|
647
674
|
${generateUtils()}\n
|
|
648
675
|
${tabIn(generateAPIInterface(routes, options), 1)}\n
|
|
@@ -655,7 +682,3 @@ function generateClientAPIInterface(application, _options) {
|
|
|
655
682
|
}).call(this, (typeof window === 'undefined') ? global : window, (typeof window !== 'undefined') ? 'browser' : 'node');
|
|
656
683
|
`;
|
|
657
684
|
}
|
|
658
|
-
|
|
659
|
-
module.exports = {
|
|
660
|
-
generateClientAPIInterface,
|
|
661
|
-
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from './controller-base';
|
|
2
|
-
export *
|
|
3
|
-
export * as ControllerUtils from './controller-utils';
|
|
4
|
-
export { defineController } from './controller-utils';
|
|
2
|
+
export * from './controller-module';
|
|
5
3
|
export * from './generate-client-api-interface';
|
|
4
|
+
export * as Routes from './routes';
|
package/{src/controllers/routes/route-capture.js → lib/controllers/routes/route-capture.mjs}
RENAMED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import Nife from 'nife';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class RouteCapture {
|
|
3
|
+
export class RouteCapture {
|
|
6
4
|
constructor(parentScope, paramName, _helperOrOptions, _options) {
|
|
7
5
|
let helper;
|
|
8
6
|
let options;
|
|
@@ -93,7 +91,3 @@ class RouteCapture {
|
|
|
93
91
|
return `<<${paramName}${(optional) ? '?' : ''}>>`;
|
|
94
92
|
}
|
|
95
93
|
}
|
|
96
|
-
|
|
97
|
-
module.exports = {
|
|
98
|
-
RouteCapture,
|
|
99
|
-
};
|
package/{src/controllers/routes/route-endpoint.js → lib/controllers/routes/route-endpoint.mjs}
RENAMED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import Nife from 'nife';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class RouteEndpoint {
|
|
3
|
+
export class RouteEndpoint {
|
|
6
4
|
constructor(parentScope, attributes) {
|
|
7
5
|
const mapMethods = (methods) => {
|
|
8
6
|
return Nife.arrayFlatten(Nife.toArray(methods || []).filter(Boolean).map((method) => {
|
|
@@ -26,6 +24,12 @@ class RouteEndpoint {
|
|
|
26
24
|
configurable: true,
|
|
27
25
|
value: false,
|
|
28
26
|
},
|
|
27
|
+
'isEndpoint': {
|
|
28
|
+
writable: true,
|
|
29
|
+
enumerable: false,
|
|
30
|
+
configurable: true,
|
|
31
|
+
value: true,
|
|
32
|
+
},
|
|
29
33
|
});
|
|
30
34
|
|
|
31
35
|
Object.assign(
|
|
@@ -90,7 +94,3 @@ class RouteEndpoint {
|
|
|
90
94
|
return this._parentScope;
|
|
91
95
|
};
|
|
92
96
|
}
|
|
93
|
-
|
|
94
|
-
module.exports = {
|
|
95
|
-
RouteEndpoint,
|
|
96
|
-
};
|
package/{src/controllers/routes/route-scope-base.js → lib/controllers/routes/route-scope-base.mjs}
RENAMED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import Nife from 'nife';
|
|
2
|
+
import { RouteCapture } from './route-capture.mjs';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
const { RouteCapture } = require('./route-capture');
|
|
5
|
-
const { RouteEndpoint } = require('./route-endpoint');
|
|
6
|
-
|
|
7
|
-
class RouteScopeBase {
|
|
4
|
+
export class RouteScopeBase {
|
|
8
5
|
constructor(parentScope, pathParts, options) {
|
|
9
6
|
Object.defineProperties(this, {
|
|
10
7
|
'_parentScope': {
|
|
@@ -43,6 +40,12 @@ class RouteScopeBase {
|
|
|
43
40
|
configurable: true,
|
|
44
41
|
value: false,
|
|
45
42
|
},
|
|
43
|
+
'isEndpoint': {
|
|
44
|
+
writable: true,
|
|
45
|
+
enumerable: false,
|
|
46
|
+
configurable: true,
|
|
47
|
+
value: false,
|
|
48
|
+
},
|
|
46
49
|
});
|
|
47
50
|
}
|
|
48
51
|
|
|
@@ -56,7 +59,7 @@ class RouteScopeBase {
|
|
|
56
59
|
|
|
57
60
|
updateOptions = (newOptions) => {
|
|
58
61
|
let options = this.getOptions();
|
|
59
|
-
this._options = Nife.extend(true, {}, (newOptions || {}));
|
|
62
|
+
this._options = Nife.extend(true, {}, options, (newOptions || {}));
|
|
60
63
|
};
|
|
61
64
|
|
|
62
65
|
addRoute(pathPart, route) {
|
|
@@ -101,7 +104,7 @@ class RouteScopeBase {
|
|
|
101
104
|
|
|
102
105
|
let newPathParts = pathParts.concat(pathPart);
|
|
103
106
|
for (let child of children) {
|
|
104
|
-
if (child
|
|
107
|
+
if (child.isEndpoint)
|
|
105
108
|
callback({ endpoint: child, pathParts: newPathParts, stop, scope: routeScope });
|
|
106
109
|
else
|
|
107
110
|
walk(child, newPathParts);
|
|
@@ -137,7 +140,7 @@ class RouteScopeBase {
|
|
|
137
140
|
if (routeMatch)
|
|
138
141
|
return routeMatch;
|
|
139
142
|
|
|
140
|
-
const matchesPathParts = (pathParts) => {
|
|
143
|
+
const matchesPathParts = (pathParts, endpoint) => {
|
|
141
144
|
let params = {};
|
|
142
145
|
|
|
143
146
|
for (let i = 0, il = pathParts.length; i < il; i++) {
|
|
@@ -160,6 +163,11 @@ class RouteScopeBase {
|
|
|
160
163
|
}
|
|
161
164
|
}
|
|
162
165
|
|
|
166
|
+
// If this is a wild endpoint, then grab the remaining path
|
|
167
|
+
// and store it as a param named "_relativePath"
|
|
168
|
+
if (endpoint.wild && pathParts[pathParts.length - 1] === incomingPathParts[pathParts.length - 1])
|
|
169
|
+
params['_relativePath'] = incomingPathParts.slice(pathParts.length).join('/');
|
|
170
|
+
|
|
163
171
|
return params;
|
|
164
172
|
};
|
|
165
173
|
|
|
@@ -188,7 +196,7 @@ class RouteScopeBase {
|
|
|
188
196
|
|
|
189
197
|
// Because of optional capture groups, it is possible
|
|
190
198
|
// that the length could deviate by one.
|
|
191
|
-
if (pathParts.length !== incomingPathParts.length) {
|
|
199
|
+
if (pathParts.length !== incomingPathParts.length && endpoint.wild !== true) {
|
|
192
200
|
if (Math.abs(pathParts.length - incomingPathParts.length) > 1)
|
|
193
201
|
return;
|
|
194
202
|
|
|
@@ -197,7 +205,7 @@ class RouteScopeBase {
|
|
|
197
205
|
return;
|
|
198
206
|
}
|
|
199
207
|
|
|
200
|
-
let params = matchesPathParts(pathParts);
|
|
208
|
+
let params = matchesPathParts(pathParts, endpoint);
|
|
201
209
|
if (params) {
|
|
202
210
|
// Does the contentType match?
|
|
203
211
|
if ((method !== 'GET' && method !== 'HEAD') && !contentTypeMatches(endpoint.contentType)) {
|
|
@@ -222,7 +230,3 @@ class RouteScopeBase {
|
|
|
222
230
|
return result;
|
|
223
231
|
}
|
|
224
232
|
}
|
|
225
|
-
|
|
226
|
-
module.exports = {
|
|
227
|
-
RouteScopeBase,
|
|
228
|
-
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import Nife from 'nife';
|
|
2
|
+
import { RouteCapture } from './route-capture.mjs';
|
|
3
|
+
import { RouteScopeBase } from './route-scope-base.mjs';
|
|
4
|
+
import { RouteEndpoint } from './route-endpoint.mjs';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
const { RouteCapture } = require('./route-capture');
|
|
5
|
-
const { RouteScopeBase } = require('./route-scope-base');
|
|
6
|
-
const { RouteEndpoint } = require('./route-endpoint');
|
|
7
|
-
|
|
8
|
-
class RouteScope extends RouteScopeBase {
|
|
6
|
+
export class RouteScope extends RouteScopeBase {
|
|
9
7
|
path = (_pathPart, callback, options) => {
|
|
8
|
+
if (typeof callback !== 'function')
|
|
9
|
+
return this.endpoint(_pathPart, { ...(options || {}), wild: true });
|
|
10
|
+
|
|
10
11
|
let pathPart = _pathPart;
|
|
11
12
|
if (!Nife.instanceOf(pathPart, 'string') && !(pathPart instanceof RouteCapture))
|
|
12
13
|
throw new TypeError('RouteScope::path: First argument must be a string or a capture.');
|
|
@@ -23,7 +24,8 @@ class RouteScope extends RouteScopeBase {
|
|
|
23
24
|
routeScope.updateOptions(options);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
callback
|
|
27
|
+
if (typeof callback === 'function')
|
|
28
|
+
callback(routeScope);
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
endpoint = (pathPart, _options) => {
|
|
@@ -47,7 +49,3 @@ class RouteScope extends RouteScopeBase {
|
|
|
47
49
|
return new RouteCapture(this, ...args);
|
|
48
50
|
};
|
|
49
51
|
}
|
|
50
|
-
|
|
51
|
-
module.exports = {
|
|
52
|
-
RouteScope,
|
|
53
|
-
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
/* eslint-disable no-magic-numbers */
|
|
1
2
|
/* eslint-disable max-classes-per-file */
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import { statusCodeToMessage } from '../utils/http-utils.mjs';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class HTTPBaseError extends Error {
|
|
6
|
+
export class HTTPBaseError extends Error {
|
|
8
7
|
constructor(route, message, _statusCode) {
|
|
9
8
|
let statusCode = _statusCode || 500;
|
|
10
9
|
|
|
@@ -20,19 +19,19 @@ class HTTPBaseError extends Error {
|
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
class HTTPNotFoundError extends HTTPBaseError {
|
|
22
|
+
export class HTTPNotFoundError extends HTTPBaseError {
|
|
24
23
|
constructor(route, message) {
|
|
25
24
|
super(route, message, 404);
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
class HTTPBadRequestError extends HTTPBaseError {
|
|
28
|
+
export class HTTPBadRequestError extends HTTPBaseError {
|
|
30
29
|
constructor(route, message) {
|
|
31
30
|
super(route, message, 400);
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
class HTTPBadContentTypeError extends HTTPBaseError {
|
|
34
|
+
export class HTTPBadContentTypeError extends HTTPBaseError {
|
|
36
35
|
constructor(route, message) {
|
|
37
36
|
super(route, message, 400);
|
|
38
37
|
}
|
|
@@ -64,30 +63,20 @@ class HTTPBadContentTypeError extends HTTPBaseError {
|
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
class HTTPUnauthorizedError extends HTTPBaseError {
|
|
66
|
+
export class HTTPUnauthorizedError extends HTTPBaseError {
|
|
68
67
|
constructor(route, message) {
|
|
69
68
|
super(route, message, 401);
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
71
|
|
|
73
|
-
class HTTPForbiddenError extends HTTPBaseError {
|
|
72
|
+
export class HTTPForbiddenError extends HTTPBaseError {
|
|
74
73
|
constructor(route, message) {
|
|
75
74
|
super(route, message, 403);
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
class HTTPInternalServerError extends HTTPBaseError {
|
|
78
|
+
export class HTTPInternalServerError extends HTTPBaseError {
|
|
80
79
|
constructor(route, message) {
|
|
81
80
|
super(route, message, 500);
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
|
-
|
|
85
|
-
module.exports = {
|
|
86
|
-
HTTPBadContentTypeError,
|
|
87
|
-
HTTPBadRequestError,
|
|
88
|
-
HTTPBaseError,
|
|
89
|
-
HTTPForbiddenError,
|
|
90
|
-
HTTPInternalServerError,
|
|
91
|
-
HTTPNotFoundError,
|
|
92
|
-
HTTPUnauthorizedError,
|
|
93
|
-
};
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import https from 'node:https';
|
|
3
|
+
import { URL, URLSearchParams } from 'node:url';
|
|
4
|
+
import Nife from 'nife';
|
|
5
|
+
import { dataToQueryString } from '../utils/http-utils.mjs';
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Nife = require('nife');
|
|
6
|
-
const http = require('node:http');
|
|
7
|
-
const https = require('node:https');
|
|
8
|
-
const { URL, URLSearchParams } = require('node:url');
|
|
9
|
-
const { dataToQueryString } = require('./http-utils');
|
|
10
|
-
|
|
11
|
-
class HTTPInterface {
|
|
7
|
+
export class HTTPInterface {
|
|
12
8
|
constructor() {
|
|
13
9
|
Object.defineProperties(this, {
|
|
14
10
|
'defaultURL': {
|
|
@@ -236,7 +232,3 @@ class HTTPInterface {
|
|
|
236
232
|
return this.makeRequest(this.getRequestOptions(url, options, 'OPTIONS'));
|
|
237
233
|
}
|
|
238
234
|
}
|
|
239
|
-
|
|
240
|
-
module.exports = {
|
|
241
|
-
HTTPInterface,
|
|
242
|
-
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModuleBase } from '../modules/module-base';
|
|
2
2
|
import { GenericObject } from '../interfaces/common';
|
|
3
3
|
import { HTTPServer } from './http-server';
|
|
4
4
|
|
|
5
|
-
export declare class HTTPServerModule extends
|
|
5
|
+
export declare class HTTPServerModule extends ModuleBase {
|
|
6
6
|
public getHTTPServer(): HTTPServer | null;
|
|
7
7
|
public getHTTPServerConfig(): GenericObject;
|
|
8
8
|
public createHTTPServer(httpServerConfig: GenericObject): HTTPServer;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import Nife from 'nife';
|
|
2
|
+
import { ModuleBase } from '../modules/module-base.mjs';
|
|
3
|
+
import { HTTPServer } from './http-server.mjs';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
export class HTTPServerModule extends ModuleBase {
|
|
6
|
+
static getOptionsScopeName() {
|
|
7
|
+
return 'httpServer';
|
|
8
|
+
}
|
|
6
9
|
|
|
7
|
-
class HTTPServerModule extends BaseModule {
|
|
8
10
|
static shouldUse(application, options) {
|
|
9
11
|
if (options.httpServer === false)
|
|
10
12
|
return false;
|
|
@@ -12,10 +14,6 @@ class HTTPServerModule extends BaseModule {
|
|
|
12
14
|
return true;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
static getModuleName() {
|
|
16
|
-
return 'HTTPServerModule';
|
|
17
|
-
}
|
|
18
|
-
|
|
19
17
|
constructor(application) {
|
|
20
18
|
super(application);
|
|
21
19
|
|
|
@@ -102,5 +100,3 @@ class HTTPServerModule extends BaseModule {
|
|
|
102
100
|
this.getLogger().info('HTTP server stopped successfully!');
|
|
103
101
|
}
|
|
104
102
|
}
|
|
105
|
-
|
|
106
|
-
module.exports = { HTTPServerModule };
|
|
@@ -1,34 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const Express = require('express');
|
|
11
|
-
const ExpressBusBoy = require('express-busboy');
|
|
12
|
-
|
|
13
|
-
const {
|
|
1
|
+
import Path from 'node:path';
|
|
2
|
+
import FileSystem from 'node:fs';
|
|
3
|
+
import HTTP from 'node:http';
|
|
4
|
+
import HTTPS from 'node:https';
|
|
5
|
+
import Nife from 'nife';
|
|
6
|
+
import Express from 'express';
|
|
7
|
+
import ExpressBusBoy from 'express-busboy';
|
|
8
|
+
|
|
9
|
+
import {
|
|
14
10
|
HTTPBaseError,
|
|
15
11
|
HTTPNotFoundError,
|
|
16
12
|
HTTPBadRequestError,
|
|
17
13
|
HTTPBadContentTypeError,
|
|
18
14
|
HTTPInternalServerError,
|
|
19
|
-
}
|
|
15
|
+
} from './http-errors.mjs';
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
import {
|
|
22
18
|
statusCodeToMessage,
|
|
23
|
-
}
|
|
19
|
+
} from '../utils/http-utils.mjs';
|
|
24
20
|
|
|
25
21
|
const REQUEST_ID_POSTFIX_LENGTH = 4;
|
|
26
22
|
const REQUEST_TIME_RESOLUTION = 3;
|
|
27
23
|
|
|
28
24
|
const DEFAULT_FILE_UPLOAD_BUFFER_SIZE = 2 * (1024 * 1024); // 2mb
|
|
25
|
+
|
|
26
|
+
// eslint-disable-next-line no-magic-numbers
|
|
29
27
|
const DEFAULT_FILE_UPLOAD_SIZE_LIMIT = 10 * (1024 * 1024); // 10mb
|
|
30
28
|
|
|
31
|
-
class HTTPServer {
|
|
29
|
+
export class HTTPServer {
|
|
32
30
|
constructor(application, _opts) {
|
|
33
31
|
let uploadPath = Path.resolve(application.getTempPath(), 'uploads');
|
|
34
32
|
|
|
@@ -333,6 +331,8 @@ class HTTPServer {
|
|
|
333
331
|
let cors = endpoint.cors;
|
|
334
332
|
if (!cors && requestMethod === 'OPTIONS') {
|
|
335
333
|
response.header('Content-Type', 'text/plain; charset=UTF-8');
|
|
334
|
+
|
|
335
|
+
// eslint-disable-next-line no-magic-numbers
|
|
336
336
|
response.status(403);
|
|
337
337
|
response.end();
|
|
338
338
|
|
|
@@ -535,7 +535,3 @@ class HTTPServer {
|
|
|
535
535
|
}
|
|
536
536
|
}
|
|
537
537
|
}
|
|
538
|
-
|
|
539
|
-
module.exports = {
|
|
540
|
-
HTTPServer,
|
|
541
|
-
};
|