mythix 1.0.6 → 1.1.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/.eslintrc.js +5 -5
- package/package.json +12 -7
- package/spec/{controller-utils-spec.js → controllers/controller-utils-spec.js} +1 -1
- package/spec/controllers/generate-client-api-interface-spec.js +156 -0
- package/spec/controllers/generateClientAPIInterface01.snapshot +552 -0
- package/spec/controllers/generateClientAPIInterface02.snapshot +465 -0
- package/spec/controllers/generateClientAPIInterface03.snapshot +418 -0
- package/spec/controllers/generateClientAPIInterface04.snapshot +552 -0
- package/spec/controllers/generateClientAPIInterface05.snapshot +552 -0
- package/spec/support/application.js +50 -0
- package/spec/support/config/index.js +3 -0
- package/spec/support/snapshots.js +63 -0
- package/spec/utils/crypto-utils-spec.js +28 -0
- package/spec/{utils-spec.js → utils/file-utils-spec.js} +1 -1
- package/spec/utils/mime-utils-spec.js +175 -0
- package/src/application.js +74 -21
- package/src/cli/cli-utils.js +2 -2
- package/src/cli/migrations/makemigrations-command.js +1159 -58
- package/src/cli/migrations/migrate-command.js +73 -12
- package/src/cli/routes-command.js +10 -2
- package/src/cli/shell-command.js +25 -19
- package/src/controllers/controller-base.js +100 -21
- package/src/controllers/controller-module.js +1 -1
- package/src/controllers/controller-utils.js +45 -40
- package/src/controllers/generate-client-api-interface.js +488 -0
- package/src/controllers/index.js +5 -1
- package/src/http-server/http-errors.js +12 -4
- package/src/http-server/http-server-module.js +20 -13
- package/src/http-server/http-server.js +54 -33
- package/src/http-server/index.js +7 -5
- package/src/http-server/middleware/default-middleware.js +12 -2
- package/src/http-server/middleware/index.js +4 -4
- package/src/index.js +15 -4
- package/src/logger.js +15 -12
- package/src/models/index.js +5 -3
- package/src/models/migration-model.js +18 -0
- package/src/models/model-module.js +13 -2
- package/src/models/model-utils.js +21 -7
- package/src/models/model.js +68 -47
- package/src/modules/base-module.js +4 -0
- package/src/modules/database-module.js +34 -20
- package/src/modules/file-watcher-module.js +1 -1
- package/src/modules/index.js +11 -0
- package/src/tasks/index.js +2 -0
- package/src/tasks/task-module.js +6 -2
- package/src/utils/config-utils.js +7 -3
- package/src/utils/crypto-utils.js +11 -0
- package/src/utils/file-utils.js +4 -2
- package/src/utils/http-interface.js +237 -0
- package/src/utils/http-utils.js +80 -164
- package/src/utils/index.js +9 -3
- package/src/utils/mime-utils.js +129 -0
- package/src/utils/test-utils.js +141 -62
- package/src/cli/migrations/migration-utils.js +0 -952
- package/src/http-server/http-utils.js +0 -25
package/.eslintrc.js
CHANGED
|
@@ -28,14 +28,14 @@ module.exports = {
|
|
|
28
28
|
'comma-dangle': [ 'error', 'always-multiline' ],
|
|
29
29
|
'comma-spacing': [ 'error', { before: false, after: true } ],
|
|
30
30
|
'comma-style': [ 'error', 'last' ],
|
|
31
|
-
'curly': [ 'error', 'multi-or-nest' ],
|
|
31
|
+
'curly': [ 'error', 'multi-or-nest', 'consistent' ],
|
|
32
32
|
'default-case-last': 'error',
|
|
33
33
|
'default-param-last': 'error',
|
|
34
34
|
'eqeqeq': [ 'error', 'smart' ],
|
|
35
35
|
'func-call-spacing': [ 'error', 'never' ],
|
|
36
36
|
'guard-for-in': 'error',
|
|
37
37
|
'implicit-arrow-linebreak': [ 'error', 'beside' ],
|
|
38
|
-
'indent': [ 'error', 2 ],
|
|
38
|
+
'indent': [ 'error', 2, { 'SwitchCase': 1 } ],
|
|
39
39
|
'jsx-quotes': [ 'error', 'prefer-double' ],
|
|
40
40
|
'key-spacing': [ 'error', { beforeColon: false, afterColon: true, mode: 'minimum', 'align': 'value' } ],
|
|
41
41
|
'keyword-spacing': [ 'error', { before: true, after: true } ],
|
|
@@ -57,14 +57,14 @@ module.exports = {
|
|
|
57
57
|
'no-implied-eval': 'error',
|
|
58
58
|
'no-labels': 'error',
|
|
59
59
|
'no-lone-blocks': 'warn',
|
|
60
|
-
'no-loop-func':
|
|
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 ] } ],
|
|
60
|
+
'no-loop-func': 0,
|
|
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, 403, 404, 500 ] } ],
|
|
62
62
|
'no-nested-ternary': 'error',
|
|
63
63
|
'no-param-reassign': 'error',
|
|
64
64
|
'no-promise-executor-return': 'error',
|
|
65
65
|
'no-return-assign': 'error',
|
|
66
66
|
'no-sequences': 'error',
|
|
67
|
-
'no-shadow':
|
|
67
|
+
'no-shadow': 0,
|
|
68
68
|
'no-throw-literal': 'warn',
|
|
69
69
|
'no-trailing-spaces': 'error',
|
|
70
70
|
'no-unmodified-loop-condition': 'warn',
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mythix",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Mythix is a NodeJS web-app framework",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "node ./node_modules/.bin/jasmine"
|
|
7
|
+
"test": "node ./node_modules/.bin/jasmine",
|
|
8
|
+
"test-watch": "watch 'clear ; node --trace-warnings ./node_modules/.bin/jasmine' . --wait=3 --interval=1"
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
@@ -18,22 +19,26 @@
|
|
|
18
19
|
},
|
|
19
20
|
"homepage": "https://github.com/th317erd/mythix#readme",
|
|
20
21
|
"devDependencies": {
|
|
22
|
+
"colors": "^1.4.0",
|
|
23
|
+
"diff": "^5.1.0",
|
|
21
24
|
"jasmine": "^4.0.2"
|
|
22
25
|
},
|
|
23
26
|
"dependencies": {
|
|
27
|
+
"@spothero/eslint-plugin-spothero": "github:spothero/eslint-plugin-spothero",
|
|
24
28
|
"chokidar": "^3.5.3",
|
|
25
29
|
"deep-diff": "^1.0.2",
|
|
30
|
+
"eslint": "^8.13.0",
|
|
26
31
|
"express": "^4.17.3",
|
|
27
32
|
"express-busboy": "^8.0.2",
|
|
33
|
+
"form-data": "^4.0.0",
|
|
28
34
|
"inflection": "^1.13.2",
|
|
29
35
|
"lodash": "^4.17.21",
|
|
30
|
-
"nife": "^1.
|
|
36
|
+
"nife": "^1.8.1",
|
|
31
37
|
"object-hash": "^3.0.0",
|
|
32
|
-
"sequelize": "^6.18.0",
|
|
33
|
-
"sqlite3": "^4.2.0",
|
|
34
38
|
"pg": "^8.7.3",
|
|
35
39
|
"pg-hstore": "^2.3.4",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
40
|
+
"prompts": "^2.4.2",
|
|
41
|
+
"sequelize": "^6.18.0",
|
|
42
|
+
"sqlite3": "^4.2.0"
|
|
38
43
|
}
|
|
39
44
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/* global describe, it, expect */
|
|
4
4
|
|
|
5
|
-
const ControllerUtils = require('
|
|
5
|
+
const ControllerUtils = require('../../src/controllers/controller-utils');
|
|
6
6
|
|
|
7
7
|
describe('controller-utils', function() {
|
|
8
8
|
describe('buildMethodMatcher', function() {
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* global describe, it, beforeAll, expect, __dirname */
|
|
4
|
+
|
|
5
|
+
const { generateClientAPIInterface } = require('../../src/controllers/generate-client-api-interface');
|
|
6
|
+
const { newTestApplication } = require('../support/application');
|
|
7
|
+
const { _matchesSnapshot } = require('../support/snapshots');
|
|
8
|
+
|
|
9
|
+
const matchesSnapshot = _matchesSnapshot.bind(this, __dirname);
|
|
10
|
+
|
|
11
|
+
function getRoutes() {
|
|
12
|
+
return {
|
|
13
|
+
'api': {
|
|
14
|
+
'v1': {
|
|
15
|
+
'auth': {
|
|
16
|
+
'authenticate': [
|
|
17
|
+
{
|
|
18
|
+
'methods': [ 'GET' ],
|
|
19
|
+
'controller': 'AuthController.authenticate',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
'name': 'login',
|
|
23
|
+
'methods': [ 'POST' ],
|
|
24
|
+
'accept': [ 'application/json' ],
|
|
25
|
+
'controller': 'AuthController.authenticate',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
'sendMagicLink': [
|
|
29
|
+
{
|
|
30
|
+
'name': 'sendMagicLink',
|
|
31
|
+
'methods': [ 'POST' ],
|
|
32
|
+
'accept': [ 'application/json' ],
|
|
33
|
+
'controller': 'AuthController.sendMagicLink',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
'registerUser': [
|
|
37
|
+
{
|
|
38
|
+
'name': 'registerUser',
|
|
39
|
+
'methods': [ 'POST' ],
|
|
40
|
+
'accept': [ 'application/json' ],
|
|
41
|
+
'controller': 'AuthController.registerUser',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
'user': {
|
|
46
|
+
'/<userID:string>': [
|
|
47
|
+
{
|
|
48
|
+
'name': 'getUser',
|
|
49
|
+
'methods': [ 'GET' ],
|
|
50
|
+
'accept': [ 'application/json' ],
|
|
51
|
+
'controller': 'UserController.show',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
'name': 'updateUser',
|
|
55
|
+
'methods': [ 'POST', 'PATCH' ],
|
|
56
|
+
'accept': [ 'application/json' ],
|
|
57
|
+
'controller': 'UserController.update',
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
'/search': {
|
|
61
|
+
'name': 'searchUsers',
|
|
62
|
+
'methods': [ 'POST' ],
|
|
63
|
+
'accept': [ 'application/json' ],
|
|
64
|
+
'controller': 'UserController.list',
|
|
65
|
+
},
|
|
66
|
+
'/': [
|
|
67
|
+
{
|
|
68
|
+
'name': 'getUsers',
|
|
69
|
+
'methods': [ 'GET' ],
|
|
70
|
+
'accept': [ 'application/json' ],
|
|
71
|
+
'controller': 'UserController.list',
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
'organization': {
|
|
76
|
+
'/<organizationID:string>': [
|
|
77
|
+
{
|
|
78
|
+
'name': 'getOrganization',
|
|
79
|
+
'methods': [ 'GET' ],
|
|
80
|
+
'accept': [ 'application/json' ],
|
|
81
|
+
'controller': 'OrganizationController.show',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
'name': 'updateOrganization',
|
|
85
|
+
'methods': [ 'POST', 'PATCH' ],
|
|
86
|
+
'accept': [ 'application/json' ],
|
|
87
|
+
'controller': 'OrganizationController.update',
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
'/<organizationID:string>/inviteUser': [
|
|
91
|
+
{
|
|
92
|
+
'name': 'inviteUserToOrganization',
|
|
93
|
+
'methods': [ 'POST' ],
|
|
94
|
+
'accept': [ 'application/json' ],
|
|
95
|
+
'controller': 'OrganizationController.inviteUser',
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
'/search': {
|
|
99
|
+
'name': 'searchOrganizations',
|
|
100
|
+
'methods': [ 'POST' ],
|
|
101
|
+
'accept': [ 'application/json' ],
|
|
102
|
+
'controller': 'OrganizationController.list',
|
|
103
|
+
},
|
|
104
|
+
'/': [
|
|
105
|
+
{
|
|
106
|
+
'name': 'getOrganizations',
|
|
107
|
+
'methods': [ 'GET' ],
|
|
108
|
+
'accept': [ 'application/json' ],
|
|
109
|
+
'controller': 'OrganizationController.list',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
'name': 'createOrganization',
|
|
113
|
+
'methods': [ 'PUT' ],
|
|
114
|
+
'accept': [ 'application/json' ],
|
|
115
|
+
'controller': 'OrganizationController.create',
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
describe('generateClientAPIInterface', () => {
|
|
125
|
+
let app;
|
|
126
|
+
|
|
127
|
+
beforeAll(async () => {
|
|
128
|
+
app = await newTestApplication();
|
|
129
|
+
app.getRoutes = getRoutes.bind(app);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should be able to generate an interface using route definitions', () => {
|
|
133
|
+
let result = generateClientAPIInterface(app);
|
|
134
|
+
expect(matchesSnapshot('generateClientAPIInterface01', result)).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should be able to generate an interface for node', () => {
|
|
138
|
+
let result = generateClientAPIInterface(app, { environment: 'node' });
|
|
139
|
+
expect(matchesSnapshot('generateClientAPIInterface02', result)).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should be able to generate an interface for the browser', () => {
|
|
143
|
+
let result = generateClientAPIInterface(app, { environment: 'browser' });
|
|
144
|
+
expect(matchesSnapshot('generateClientAPIInterface03', result)).toBe(true);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('should be able to export a global', () => {
|
|
148
|
+
let result = generateClientAPIInterface(app, { globalName: 'API' });
|
|
149
|
+
expect(matchesSnapshot('generateClientAPIInterface04', result)).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('should be able to specify a domain', () => {
|
|
153
|
+
let result = generateClientAPIInterface(app, { domain: 'http://localhost:8080' });
|
|
154
|
+
expect(matchesSnapshot('generateClientAPIInterface05', result)).toBe(true);
|
|
155
|
+
});
|
|
156
|
+
});
|