mythix 1.0.3 → 1.0.6
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/.eslintrc.js +94 -0
- package/package.json +12 -8
- package/spec/controller-utils-spec.js +52 -48
- package/spec/utils-spec.js +4 -0
- package/src/application.js +85 -738
- package/src/cli/cli-utils.js +75 -66
- package/src/cli/index.js +2 -0
- package/src/cli/migrations/makemigrations-command.js +24 -17
- package/src/cli/migrations/migrate-command.js +29 -20
- package/src/cli/migrations/migration-utils.js +249 -249
- package/src/cli/routes-command.js +13 -8
- package/src/cli/serve-command.js +19 -12
- package/src/cli/shell-command.js +9 -8
- package/src/controllers/controller-base.js +11 -9
- package/src/controllers/controller-module.js +144 -0
- package/src/controllers/controller-utils.js +82 -79
- package/src/controllers/index.js +2 -0
- package/src/http-server/http-errors.js +16 -12
- package/src/http-server/http-server-module.js +101 -0
- package/src/http-server/http-server.js +105 -86
- package/src/http-server/http-utils.js +4 -2
- package/src/http-server/index.js +2 -0
- package/src/http-server/middleware/default-middleware.js +26 -24
- package/src/http-server/middleware/index.js +2 -0
- package/src/logger.js +23 -20
- package/src/models/index.js +2 -0
- package/src/models/model-module.js +134 -0
- package/src/models/model-utils.js +113 -74
- package/src/models/model.js +49 -47
- package/src/modules/base-module.js +37 -0
- package/src/modules/database-module.js +142 -0
- package/src/modules/file-watcher-module.js +217 -0
- package/src/tasks/index.js +2 -0
- package/src/tasks/task-base.js +13 -11
- package/src/tasks/task-module.js +369 -0
- package/src/tasks/task-utils.js +14 -10
- package/src/utils/config-utils.js +3 -3
- package/src/utils/crypto-utils.js +5 -5
- package/src/utils/file-utils.js +13 -13
- package/src/utils/http-utils.js +19 -19
- package/src/utils/test-utils.js +17 -15
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-magic-numbers */
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
'env': {
|
|
7
|
+
'browser': true,
|
|
8
|
+
'commonjs': true,
|
|
9
|
+
'es2021': true,
|
|
10
|
+
},
|
|
11
|
+
'extends': [
|
|
12
|
+
'eslint:recommended',
|
|
13
|
+
],
|
|
14
|
+
'parserOptions': {
|
|
15
|
+
'ecmaVersion': 'latest',
|
|
16
|
+
},
|
|
17
|
+
'plugins': [
|
|
18
|
+
'@spothero/eslint-plugin-spothero',
|
|
19
|
+
],
|
|
20
|
+
'rules': {
|
|
21
|
+
'@spothero/spothero/ternary-parentheses': 'error',
|
|
22
|
+
'arrow-parens': 'error',
|
|
23
|
+
'arrow-spacing': [ 'error', { before: true, after: true } ],
|
|
24
|
+
'block-scoped-var': 'warn',
|
|
25
|
+
'block-spacing': 'error',
|
|
26
|
+
'brace-style': [ 'error', '1tbs' ],
|
|
27
|
+
'camelcase': 'warn',
|
|
28
|
+
'comma-dangle': [ 'error', 'always-multiline' ],
|
|
29
|
+
'comma-spacing': [ 'error', { before: false, after: true } ],
|
|
30
|
+
'comma-style': [ 'error', 'last' ],
|
|
31
|
+
'curly': [ 'error', 'multi-or-nest' ],
|
|
32
|
+
'default-case-last': 'error',
|
|
33
|
+
'default-param-last': 'error',
|
|
34
|
+
'eqeqeq': [ 'error', 'smart' ],
|
|
35
|
+
'func-call-spacing': [ 'error', 'never' ],
|
|
36
|
+
'guard-for-in': 'error',
|
|
37
|
+
'implicit-arrow-linebreak': [ 'error', 'beside' ],
|
|
38
|
+
'indent': [ 'error', 2 ],
|
|
39
|
+
'jsx-quotes': [ 'error', 'prefer-double' ],
|
|
40
|
+
'key-spacing': [ 'error', { beforeColon: false, afterColon: true, mode: 'minimum', 'align': 'value' } ],
|
|
41
|
+
'keyword-spacing': [ 'error', { before: true, after: true } ],
|
|
42
|
+
'linebreak-style': [ 'error', 'unix' ],
|
|
43
|
+
'lines-between-class-members': 'error',
|
|
44
|
+
'max-classes-per-file': [ 'error', 3 ],
|
|
45
|
+
'new-cap': [ 'error', { 'properties': false } ],
|
|
46
|
+
'new-parens': 'error',
|
|
47
|
+
'no-array-constructor': 'warn',
|
|
48
|
+
'no-caller': 'error',
|
|
49
|
+
'no-confusing-arrow': 'error',
|
|
50
|
+
'no-empty': 'warn',
|
|
51
|
+
'no-eq-null': 0,
|
|
52
|
+
'no-eval': 'error',
|
|
53
|
+
'no-extend-native': 'error',
|
|
54
|
+
'no-extra-label': 'error',
|
|
55
|
+
'no-floating-decimal': 'error',
|
|
56
|
+
'no-global-assign': 'error',
|
|
57
|
+
'no-implied-eval': 'error',
|
|
58
|
+
'no-labels': 'error',
|
|
59
|
+
'no-lone-blocks': 'warn',
|
|
60
|
+
'no-loop-func': 'warn',
|
|
61
|
+
'no-magic-numbers': [ 'warn', { ignoreArrayIndexes: true, ignoreDefaultValues: true, ignore: [ -1, 0, 1, 2, 16, 32, 64, 128, 256, 1024, 2048, 200, 301, 302, 400, 401, 404, 500 ] } ],
|
|
62
|
+
'no-nested-ternary': 'error',
|
|
63
|
+
'no-param-reassign': 'error',
|
|
64
|
+
'no-promise-executor-return': 'error',
|
|
65
|
+
'no-return-assign': 'error',
|
|
66
|
+
'no-sequences': 'error',
|
|
67
|
+
'no-shadow': 'warn',
|
|
68
|
+
'no-throw-literal': 'warn',
|
|
69
|
+
'no-trailing-spaces': 'error',
|
|
70
|
+
'no-unmodified-loop-condition': 'warn',
|
|
71
|
+
'no-unreachable-loop': 'warn',
|
|
72
|
+
'no-unreachable': 'warn',
|
|
73
|
+
'no-unused-private-class-members': 'warn',
|
|
74
|
+
'no-unused-vars': 'warn',
|
|
75
|
+
'no-whitespace-before-property': 'error',
|
|
76
|
+
'nonblock-statement-body-position': [ 'error', 'below' ],
|
|
77
|
+
'one-var': [ 'error', 'never' ],
|
|
78
|
+
'quotes': [ 'error', 'single' ],
|
|
79
|
+
'radix': 'error',
|
|
80
|
+
'rest-spread-spacing': [ 'error', 'never' ],
|
|
81
|
+
'semi-spacing': [ 'error', { before: false, after: true } ],
|
|
82
|
+
'semi-style': [ 'error', 'last' ],
|
|
83
|
+
'semi': 'error',
|
|
84
|
+
'space-before-blocks': 'error',
|
|
85
|
+
'space-infix-ops': 'error',
|
|
86
|
+
'space-unary-ops': [ 'error', { words: false, nonwords: false } ],
|
|
87
|
+
'strict': 'error',
|
|
88
|
+
'switch-colon-spacing': [ 'error', { before: false, after: true } ],
|
|
89
|
+
'template-curly-spacing': 'error',
|
|
90
|
+
'template-tag-spacing': 'error',
|
|
91
|
+
'wrap-iife': [ 'error', 'inside' ],
|
|
92
|
+
'yoda': 'error',
|
|
93
|
+
},
|
|
94
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mythix",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Mythix is a NodeJS web-app framework",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,13 +23,17 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"chokidar": "^3.5.3",
|
|
25
25
|
"deep-diff": "^1.0.2",
|
|
26
|
-
"express": "^4.17.
|
|
27
|
-
"express-busboy": "^8.0.
|
|
28
|
-
"inflection": "^1.13.
|
|
26
|
+
"express": "^4.17.3",
|
|
27
|
+
"express-busboy": "^8.0.2",
|
|
28
|
+
"inflection": "^1.13.2",
|
|
29
29
|
"lodash": "^4.17.21",
|
|
30
|
-
"nife": "^1.
|
|
31
|
-
"object-hash": "^
|
|
32
|
-
"sequelize": "^6.
|
|
33
|
-
"sqlite3": "^
|
|
30
|
+
"nife": "^1.6.0",
|
|
31
|
+
"object-hash": "^3.0.0",
|
|
32
|
+
"sequelize": "^6.18.0",
|
|
33
|
+
"sqlite3": "^4.2.0",
|
|
34
|
+
"pg": "^8.7.3",
|
|
35
|
+
"pg-hstore": "^2.3.4",
|
|
36
|
+
"@spothero/eslint-plugin-spothero": "github:spothero/eslint-plugin-spothero",
|
|
37
|
+
"eslint": "^8.13.0"
|
|
34
38
|
}
|
|
35
39
|
}
|
|
@@ -1,34 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* global describe, it, expect */
|
|
4
|
+
|
|
1
5
|
const ControllerUtils = require('../src/controllers/controller-utils');
|
|
2
6
|
|
|
3
7
|
describe('controller-utils', function() {
|
|
4
8
|
describe('buildMethodMatcher', function() {
|
|
5
9
|
it('should be able to create a method matcher', function() {
|
|
6
|
-
|
|
10
|
+
let matchFunc = ControllerUtils.buildMethodMatcher('*');
|
|
7
11
|
expect(matchFunc(null)).toBe(true);
|
|
8
12
|
expect(matchFunc('')).toBe(true);
|
|
9
13
|
expect(matchFunc('GET')).toBe(true);
|
|
10
14
|
expect(matchFunc('get')).toBe(true);
|
|
11
15
|
expect(matchFunc('Post')).toBe(true);
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
matchFunc = ControllerUtils.buildMethodMatcher([ 'GET', '*' ]);
|
|
14
18
|
expect(matchFunc('')).toBe(true);
|
|
15
19
|
expect(matchFunc('GET')).toBe(true);
|
|
16
20
|
expect(matchFunc('get')).toBe(true);
|
|
17
21
|
expect(matchFunc('Post')).toBe(true);
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
matchFunc = ControllerUtils.buildMethodMatcher('GET');
|
|
20
24
|
expect(matchFunc('GET')).toBe(true);
|
|
21
25
|
expect(matchFunc('get')).toBe(true);
|
|
22
26
|
expect(matchFunc('GETs')).toBe(false);
|
|
23
27
|
expect(matchFunc('post')).toBe(false);
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
matchFunc = ControllerUtils.buildMethodMatcher([ 'get', 'POST' ]);
|
|
26
30
|
expect(matchFunc('GET')).toBe(true);
|
|
27
31
|
expect(matchFunc('get')).toBe(true);
|
|
28
32
|
expect(matchFunc('POST')).toBe(true);
|
|
29
33
|
expect(matchFunc('head')).toBe(false);
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
matchFunc = ControllerUtils.buildMethodMatcher(/(get|post)/i);
|
|
32
36
|
expect(matchFunc('GET')).toBe(true);
|
|
33
37
|
expect(matchFunc('get')).toBe(true);
|
|
34
38
|
expect(matchFunc('gets')).toBe(true);
|
|
@@ -40,19 +44,19 @@ describe('controller-utils', function() {
|
|
|
40
44
|
|
|
41
45
|
describe('buildContentTypeMatcher', function() {
|
|
42
46
|
it('should be able to create a content-type matcher', function() {
|
|
43
|
-
|
|
47
|
+
let matcher = ControllerUtils.buildContentTypeMatcher('*');
|
|
44
48
|
expect(matcher.regexp.toString()).toBe('/.*/i');
|
|
45
49
|
expect(matcher('application/json')).toBe(true);
|
|
46
50
|
expect(matcher('anything')).toBe(true);
|
|
47
51
|
expect(matcher()).toBe(true);
|
|
48
52
|
|
|
49
|
-
|
|
53
|
+
matcher = ControllerUtils.buildContentTypeMatcher('application/json');
|
|
50
54
|
expect(matcher.regexp.toString()).toBe('/(application\\/json)/i');
|
|
51
55
|
expect(matcher('application/json')).toBe(true);
|
|
52
56
|
expect(matcher('application/json; charset=UTF-8')).toBe(true);
|
|
53
57
|
expect(matcher('text/plain')).toBe(false);
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
matcher = ControllerUtils.buildContentTypeMatcher(/^(application\/json|text\/plain)$/i);
|
|
56
60
|
expect(matcher.regexp.toString()).toBe('/^(application\\/json|text\\/plain)$/i');
|
|
57
61
|
expect(matcher('application/json')).toBe(true);
|
|
58
62
|
expect(matcher('application/json; charset=UTF-8')).toBe(false);
|
|
@@ -63,21 +67,21 @@ describe('controller-utils', function() {
|
|
|
63
67
|
|
|
64
68
|
describe('buildPathMatcher', function() {
|
|
65
69
|
it('should be able to build a parser from a route name', function() {
|
|
66
|
-
|
|
70
|
+
let matchFunc = ControllerUtils.buildPathMatcher('person<id?:integer = 0>_stuff');
|
|
67
71
|
expect(matchFunc('person120_stuff')).toEqual({ id: 120 });
|
|
68
72
|
expect(matchFunc('person_stuff')).toEqual({});
|
|
69
73
|
|
|
70
|
-
|
|
74
|
+
matchFunc = ControllerUtils.buildPathMatcher('objects/<id>');
|
|
71
75
|
expect(matchFunc('objects')).toBe(undefined);
|
|
72
76
|
expect(matchFunc('objects/')).toBe(undefined);
|
|
73
77
|
expect(matchFunc('objects/1')).toEqual({ id: 1 });
|
|
74
78
|
|
|
75
|
-
|
|
79
|
+
matchFunc = ControllerUtils.buildPathMatcher('objects/<id?>');
|
|
76
80
|
expect(matchFunc('objects')).toEqual({});
|
|
77
81
|
expect(matchFunc('objects/')).toEqual({});
|
|
78
82
|
expect(matchFunc('objects/1')).toEqual({ id: 1 });
|
|
79
83
|
|
|
80
|
-
|
|
84
|
+
matchFunc = ControllerUtils.buildPathMatcher('values/<truthy:boolean>');
|
|
81
85
|
expect(matchFunc('values')).toBe(undefined);
|
|
82
86
|
expect(matchFunc('values/')).toBe(undefined);
|
|
83
87
|
expect(matchFunc('values/1')).toBe(undefined);
|
|
@@ -89,7 +93,7 @@ describe('controller-utils', function() {
|
|
|
89
93
|
expect(matchFunc('values/False')).toEqual({ truthy: false });
|
|
90
94
|
expect(matchFunc('values/FALSE')).toEqual({ truthy: false });
|
|
91
95
|
|
|
92
|
-
|
|
96
|
+
matchFunc = ControllerUtils.buildPathMatcher('values/<str:magic>', { magic: (part) => `MAGIC:${part}!!!`});
|
|
93
97
|
expect(matchFunc('values')).toBe(undefined);
|
|
94
98
|
expect(matchFunc('values/')).toBe(undefined);
|
|
95
99
|
expect(matchFunc('values/1')).toEqual({ str: 'MAGIC:1!!!' });
|
|
@@ -99,41 +103,41 @@ describe('controller-utils', function() {
|
|
|
99
103
|
|
|
100
104
|
describe('buildRoutes', function() {
|
|
101
105
|
it('should be able to compile routes', function() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
});
|
|
106
|
+
// let allRoutes = ControllerUtils.buildRoutes({
|
|
107
|
+
// 'api': {
|
|
108
|
+
// 'v1': {
|
|
109
|
+
// 'test': {
|
|
110
|
+
// methods: [ 'GET', 'POST' ],
|
|
111
|
+
// accept: 'application/json',
|
|
112
|
+
// controller: 'Something.test',
|
|
113
|
+
// children: [
|
|
114
|
+
// {
|
|
115
|
+
// priority: 10,
|
|
116
|
+
// methods: 'GET',
|
|
117
|
+
// controller: 'Something.children.get',
|
|
118
|
+
// },
|
|
119
|
+
// {
|
|
120
|
+
// priority: 11,
|
|
121
|
+
// methods: 'POST',
|
|
122
|
+
// controller: 'Something.children.post',
|
|
123
|
+
// },
|
|
124
|
+
// {
|
|
125
|
+
// 'do-something/<id:int>': {
|
|
126
|
+
// priority: 10,
|
|
127
|
+
// methods: 'GET',
|
|
128
|
+
// controller: 'Something.children.get.doSomething',
|
|
129
|
+
// },
|
|
130
|
+
// },
|
|
131
|
+
// ],
|
|
132
|
+
// },
|
|
133
|
+
// 'test2': {
|
|
134
|
+
// priority: 0,
|
|
135
|
+
// methods: [ 'POST', '*' ],
|
|
136
|
+
// controller: 'Something.test2',
|
|
137
|
+
// },
|
|
138
|
+
// },
|
|
139
|
+
// },
|
|
140
|
+
// });
|
|
137
141
|
|
|
138
142
|
// console.log('ALL ROUTES: ', allRoutes);
|
|
139
143
|
});
|