mythix 1.2.0 → 2.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/package.json +6 -13
- package/src/application.js +5 -2
- package/src/cli/migrations/makemigrations-command.js +1 -2
- package/src/cli/migrations/migrate-command.js +4 -4
- package/src/cli/shell-command.js +0 -2
- package/src/controllers/controller-module.js +0 -9
- package/src/http-server/http-server.js +0 -5
- package/src/models/index.js +0 -4
- package/src/models/migration-model.js +2 -2
- package/src/models/model-module.js +19 -32
- package/src/models/model-utils.js +24 -374
- package/src/models/model.js +29 -150
- package/src/modules/database-module.js +23 -18
- package/src/tasks/task-module.js +1 -11
- package/src/tasks/task-utils.js +1 -2
- package/src/utils/test-utils.js +38 -50
- package/.eslintrc.js +0 -94
- package/.vscode/settings.json +0 -7
- package/spec/controllers/controller-utils-spec.js +0 -145
- package/spec/controllers/generate-client-api-interface-spec.js +0 -156
- package/spec/controllers/generateClientAPIInterface01.snapshot +0 -552
- package/spec/controllers/generateClientAPIInterface02.snapshot +0 -465
- package/spec/controllers/generateClientAPIInterface03.snapshot +0 -418
- package/spec/controllers/generateClientAPIInterface04.snapshot +0 -552
- package/spec/controllers/generateClientAPIInterface05.snapshot +0 -552
- package/spec/support/application.js +0 -50
- package/spec/support/config/index.js +0 -3
- package/spec/support/jasmine.json +0 -13
- package/spec/support/snapshots.js +0 -63
- package/spec/utils/crypto-utils-spec.js +0 -28
- package/spec/utils/file-utils-spec.js +0 -14
- package/spec/utils/mime-utils-spec.js +0 -175
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mythix",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Mythix is a NodeJS web-app framework",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,26 +19,19 @@
|
|
|
19
19
|
},
|
|
20
20
|
"homepage": "https://github.com/th317erd/mythix#readme",
|
|
21
21
|
"devDependencies": {
|
|
22
|
+
"@spothero/eslint-plugin-spothero": "github:spothero/eslint-plugin-spothero",
|
|
22
23
|
"colors": "^1.4.0",
|
|
23
24
|
"diff": "^5.1.0",
|
|
25
|
+
"eslint": "^8.13.0",
|
|
24
26
|
"jasmine": "^4.0.2"
|
|
25
27
|
},
|
|
26
28
|
"dependencies": {
|
|
27
|
-
"@spothero/eslint-plugin-spothero": "github:spothero/eslint-plugin-spothero",
|
|
28
29
|
"chokidar": "^3.5.3",
|
|
29
|
-
"deep-diff": "^1.0.2",
|
|
30
|
-
"eslint": "^8.13.0",
|
|
31
30
|
"express": "^4.17.3",
|
|
32
31
|
"express-busboy": "^8.0.2",
|
|
33
32
|
"form-data": "^4.0.0",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"object-hash": "^3.0.0",
|
|
38
|
-
"pg": "^8.7.3",
|
|
39
|
-
"pg-hstore": "^2.3.4",
|
|
40
|
-
"prompts": "^2.4.2",
|
|
41
|
-
"sequelize": "^6.18.0",
|
|
42
|
-
"sqlite3": "^5.0.9"
|
|
33
|
+
"mythix-orm": "^1.0.4",
|
|
34
|
+
"nife": "^1.11.3",
|
|
35
|
+
"prompts": "^2.4.2"
|
|
43
36
|
}
|
|
44
37
|
}
|
package/src/application.js
CHANGED
|
@@ -70,6 +70,7 @@ class Application extends EventEmitter {
|
|
|
70
70
|
let ROOT_PATH = (_opts && _opts.rootPath) ? _opts.rootPath : Path.resolve(__dirname);
|
|
71
71
|
|
|
72
72
|
let opts = Nife.extend(true, {
|
|
73
|
+
environment: (process.env.NODE_ENV || 'development'),
|
|
73
74
|
appName: this.constructor.APP_NAME,
|
|
74
75
|
rootPath: ROOT_PATH,
|
|
75
76
|
configPath: Path.resolve(ROOT_PATH, 'config'),
|
|
@@ -81,7 +82,7 @@ class Application extends EventEmitter {
|
|
|
81
82
|
commandsPath: Path.resolve(ROOT_PATH, 'commands'),
|
|
82
83
|
tasksPath: Path.resolve(ROOT_PATH, 'tasks'),
|
|
83
84
|
modules: this.constructor.getDefaultModules(),
|
|
84
|
-
autoReload: (process.env.NODE_ENV || 'development') === 'development',
|
|
85
|
+
autoReload: ((_opts && _opts.environment) || process.env.NODE_ENV || 'development') === 'development',
|
|
85
86
|
exitOnShutdown: null,
|
|
86
87
|
runTasks: true,
|
|
87
88
|
testMode: false,
|
|
@@ -229,8 +230,10 @@ class Application extends EventEmitter {
|
|
|
229
230
|
|
|
230
231
|
loadConfig(configPath) {
|
|
231
232
|
try {
|
|
233
|
+
let appOptions = this.getOptions();
|
|
234
|
+
|
|
232
235
|
const config = require(configPath);
|
|
233
|
-
return wrapConfig(config);
|
|
236
|
+
return wrapConfig(Object.assign({}, config || {}, { environment: (appOptions.environment || config.environment || 'development')}));
|
|
234
237
|
} catch (error) {
|
|
235
238
|
this.getLogger().error(`Error while trying to load application configuration ${configPath}: `, error);
|
|
236
239
|
throw error;
|
|
@@ -138,7 +138,7 @@ module.exports = defineCommand('makemigrations', ({ Parent }) => {
|
|
|
138
138
|
|
|
139
139
|
// Now build all model information
|
|
140
140
|
connection.modelManager.forEachModel((Model) => {
|
|
141
|
-
let modelName = Model.
|
|
141
|
+
let modelName = Model.getModelName();
|
|
142
142
|
let tableName = Model.getTableName(options);
|
|
143
143
|
|
|
144
144
|
models.push({
|
|
@@ -799,7 +799,6 @@ module.exports = defineCommand('makemigrations', ({ Parent }) => {
|
|
|
799
799
|
|
|
800
800
|
let oldAssertTableHasColumn = queryInterface.assertTableHasColumn;
|
|
801
801
|
try {
|
|
802
|
-
// Tell Sequelize to shut up
|
|
803
802
|
queryInterface.assertTableHasColumn = async () => ({ [oldColumnName]: columnDefinition });
|
|
804
803
|
|
|
805
804
|
return await queryInterface.renameColumn(tableName, oldColumnName, newColumnName, options);
|
|
@@ -61,18 +61,18 @@ module.exports = defineCommand('migrate', ({ Parent }) => {
|
|
|
61
61
|
return migrationFiles.slice((isRollback) ? index : index + 1);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
async executeMigration(dbConnection, migrationFileName, useTransaction, rollback) {
|
|
64
|
+
async executeMigration(application, dbConnection, migrationFileName, useTransaction, rollback) {
|
|
65
65
|
let migration = require(migrationFileName);
|
|
66
66
|
let startTime = Nife.now();
|
|
67
67
|
|
|
68
68
|
if (rollback) {
|
|
69
|
-
await migration.down(dbConnection);
|
|
69
|
+
await migration.down(dbConnection, application);
|
|
70
70
|
await this.removeMigrationFromDB(migration.MIGRATION_ID);
|
|
71
71
|
|
|
72
72
|
let seconds = ((Nife.now() - startTime) / MILLISECONDS_PER_SECOND).toFixed(2);
|
|
73
73
|
console.log(`Rolled back migration ${migrationFileName} successfully in ${seconds} seconds`);
|
|
74
74
|
} else {
|
|
75
|
-
await migration.up(dbConnection);
|
|
75
|
+
await migration.up(dbConnection, application);
|
|
76
76
|
await this.storeSuccessfulMigrationToDB(migration.MIGRATION_ID);
|
|
77
77
|
|
|
78
78
|
let seconds = ((Nife.now() - startTime) / MILLISECONDS_PER_SECOND).toFixed(2);
|
|
@@ -130,7 +130,7 @@ module.exports = defineCommand('migrate', ({ Parent }) => {
|
|
|
130
130
|
else
|
|
131
131
|
console.log(`Running migration ${migrationFileName}...`);
|
|
132
132
|
|
|
133
|
-
this.executeMigration(dbConnection, migrationFileName, useTransaction, rollback).then(
|
|
133
|
+
this.executeMigration(application, dbConnection, migrationFileName, useTransaction, rollback).then(
|
|
134
134
|
() => nextMigration(doneCallback, index + 1),
|
|
135
135
|
(error) => {
|
|
136
136
|
console.error(`Error while running migration ${migrationFileName}: `, error);
|
package/src/cli/shell-command.js
CHANGED
|
@@ -5,7 +5,6 @@ const OS = require('os');
|
|
|
5
5
|
const Path = require('path');
|
|
6
6
|
const REPL = require('repl');
|
|
7
7
|
const UUIDV4 = require('uuid').v4;
|
|
8
|
-
const { Sequelize } = require('sequelize');
|
|
9
8
|
const { defineCommand } = require('./cli-utils');
|
|
10
9
|
const {
|
|
11
10
|
HTTPInterface,
|
|
@@ -55,7 +54,6 @@ module.exports = defineCommand('shell', ({ Parent }) => {
|
|
|
55
54
|
interactiveShell.setupHistory(Path.join(OS.homedir(), `.${appName}-${environment}-history`), () => {});
|
|
56
55
|
|
|
57
56
|
interactiveShell.context.UUIDV4 = UUIDV4;
|
|
58
|
-
interactiveShell.context.Sequelize = Sequelize;
|
|
59
57
|
interactiveShell.context.connection = (typeof application.getDBConnection === 'function') ? application.getDBConnection() : null;
|
|
60
58
|
interactiveShell.context.application = application;
|
|
61
59
|
interactiveShell.context.Nife = Nife;
|
|
@@ -90,15 +90,6 @@ class ControllerModule extends BaseModule {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
Object.defineProperties(controllers, {
|
|
94
|
-
'_files': {
|
|
95
|
-
writable: true,
|
|
96
|
-
enumberable: false,
|
|
97
|
-
configurable: true,
|
|
98
|
-
value: controllerFiles,
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
|
|
102
93
|
return controllers;
|
|
103
94
|
}
|
|
104
95
|
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
/* global process */
|
|
4
4
|
|
|
5
|
-
const OS = require('os');
|
|
6
5
|
const Path = require('path');
|
|
7
6
|
const FileSystem = require('fs');
|
|
8
7
|
const HTTP = require('http');
|
|
@@ -10,7 +9,6 @@ const HTTPS = require('https');
|
|
|
10
9
|
const Nife = require('nife');
|
|
11
10
|
const Express = require('express');
|
|
12
11
|
const ExpressBusBoy = require('express-busboy');
|
|
13
|
-
const Sequelize = require('sequelize');
|
|
14
12
|
|
|
15
13
|
const {
|
|
16
14
|
HTTPBaseError,
|
|
@@ -132,9 +130,6 @@ class HTTPServer {
|
|
|
132
130
|
if (!logger)
|
|
133
131
|
logger = request.mythixLogger = this.createRequestLogger(application, request);
|
|
134
132
|
|
|
135
|
-
if (!request.Sequelize)
|
|
136
|
-
request.Sequelize = Sequelize;
|
|
137
|
-
|
|
138
133
|
request.route = route;
|
|
139
134
|
request.params = params;
|
|
140
135
|
|
package/src/models/index.js
CHANGED
|
@@ -5,14 +5,10 @@ const { ModelModule } = require('./model-module');
|
|
|
5
5
|
|
|
6
6
|
const {
|
|
7
7
|
defineModel,
|
|
8
|
-
getModelPrimaryKeyField,
|
|
9
|
-
buildModelRelations,
|
|
10
8
|
} = require('./model-utils');
|
|
11
9
|
|
|
12
10
|
module.exports = {
|
|
13
|
-
buildModelRelations,
|
|
14
11
|
defineModel,
|
|
15
|
-
getModelPrimaryKeyField,
|
|
16
12
|
Model,
|
|
17
13
|
ModelModule,
|
|
18
14
|
};
|
|
@@ -4,11 +4,11 @@ const { defineModel } = require('./model-utils');
|
|
|
4
4
|
|
|
5
5
|
const ID_STRING_MAX_SIZE = 15;
|
|
6
6
|
|
|
7
|
-
module.exports = defineModel('Migration', ({ Parent,
|
|
7
|
+
module.exports = defineModel('Migration', ({ Parent, Types }) => {
|
|
8
8
|
return class Migration extends Parent {
|
|
9
9
|
static fields = {
|
|
10
10
|
id: {
|
|
11
|
-
type:
|
|
11
|
+
type: Types.STRING(ID_STRING_MAX_SIZE),
|
|
12
12
|
allowNull: false,
|
|
13
13
|
primaryKey: true,
|
|
14
14
|
index: true,
|
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
/* global __dirname */
|
|
4
4
|
|
|
5
|
-
const Path
|
|
6
|
-
const {
|
|
7
|
-
const { BaseModule } = require('../modules/base-module');
|
|
8
|
-
const { buildModelRelations } = require('./model-utils');
|
|
5
|
+
const Path = require('path');
|
|
6
|
+
const { BaseModule } = require('../modules/base-module');
|
|
9
7
|
const {
|
|
10
8
|
fileNameWithoutExtension,
|
|
11
9
|
walkDir,
|
|
@@ -28,15 +26,6 @@ class ModelModule extends BaseModule {
|
|
|
28
26
|
constructor(application) {
|
|
29
27
|
super(application);
|
|
30
28
|
|
|
31
|
-
Object.defineProperties(this, {
|
|
32
|
-
'models': {
|
|
33
|
-
writable: true,
|
|
34
|
-
enumerable: false,
|
|
35
|
-
configurable: true,
|
|
36
|
-
value: {},
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
|
|
40
29
|
// Inject methods into the application
|
|
41
30
|
Object.defineProperties(application, {
|
|
42
31
|
'getModel': {
|
|
@@ -59,8 +48,7 @@ class ModelModule extends BaseModule {
|
|
|
59
48
|
}
|
|
60
49
|
|
|
61
50
|
async fileWatcherHandler(options) {
|
|
62
|
-
|
|
63
|
-
this.models = models;
|
|
51
|
+
await this.loadModels(options.modelsPath);
|
|
64
52
|
}
|
|
65
53
|
|
|
66
54
|
getModelFilePaths(modelsPath) {
|
|
@@ -91,7 +79,7 @@ class ModelModule extends BaseModule {
|
|
|
91
79
|
let dbConfig = (typeof application.getDBConfig === 'function') ? application.getDBConfig() : null;
|
|
92
80
|
let modelFiles = this.getModelFilePaths(modelsPath);
|
|
93
81
|
let models = {};
|
|
94
|
-
let args = { application,
|
|
82
|
+
let args = { application, connection, dbConfig };
|
|
95
83
|
|
|
96
84
|
for (let i = 0, il = modelFiles.length; i < il; i++) {
|
|
97
85
|
let modelFile = modelFiles[i];
|
|
@@ -108,32 +96,31 @@ class ModelModule extends BaseModule {
|
|
|
108
96
|
}
|
|
109
97
|
}
|
|
110
98
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
Object.defineProperties(models, {
|
|
114
|
-
'_files': {
|
|
115
|
-
writable: true,
|
|
116
|
-
enumberable: false,
|
|
117
|
-
configurable: true,
|
|
118
|
-
value: modelFiles,
|
|
119
|
-
},
|
|
120
|
-
});
|
|
99
|
+
models = connection.registerModels(models);
|
|
121
100
|
|
|
122
101
|
return models;
|
|
123
102
|
}
|
|
124
103
|
|
|
125
|
-
getModel(
|
|
126
|
-
let
|
|
127
|
-
|
|
104
|
+
getModel(modelName) {
|
|
105
|
+
let application = this.getApplication();
|
|
106
|
+
let connection = (typeof application.getDBConnection === 'function') ? application.getDBConnection() : null;
|
|
107
|
+
if (!connection)
|
|
108
|
+
return;
|
|
109
|
+
|
|
110
|
+
return connection.getModel(modelName);
|
|
128
111
|
}
|
|
129
112
|
|
|
130
113
|
getModels() {
|
|
131
|
-
|
|
114
|
+
let application = this.getApplication();
|
|
115
|
+
let connection = (typeof application.getDBConnection === 'function') ? application.getDBConnection() : null;
|
|
116
|
+
if (!connection)
|
|
117
|
+
return;
|
|
118
|
+
|
|
119
|
+
return connection.getModels();
|
|
132
120
|
}
|
|
133
121
|
|
|
134
122
|
async start(options) {
|
|
135
|
-
|
|
136
|
-
this.models = models;
|
|
123
|
+
await this.loadModels(options.modelsPath);
|
|
137
124
|
}
|
|
138
125
|
|
|
139
126
|
async stop() {
|