mythix 2.4.9 → 2.4.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mythix",
3
- "version": "2.4.9",
3
+ "version": "2.4.12",
4
4
  "description": "Mythix is a NodeJS web-app framework",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -30,7 +30,7 @@
30
30
  "express": "^4.17.3",
31
31
  "express-busboy": "github:th317erd/express-busboy#0754a570d7979097b31e48655b80d3fcd628d4e4",
32
32
  "form-data": "^4.0.0",
33
- "mythix-orm": "^1.5.2",
33
+ "mythix-orm": "^1.5.5",
34
34
  "nife": "^1.11.3",
35
35
  "prompts": "^2.4.2"
36
36
  }
@@ -308,7 +308,7 @@ function loadMythixConfig(_mythixConfigPath, _appRootPath) {
308
308
 
309
309
  let defaultConfig = {
310
310
  runtime: process.env.MYTHIX_RUNTIME || 'node',
311
- runtimeArgs: (process.env.MYTHIX_RUNTIME_ARGS || '').split(/\s+/g),
311
+ runtimeArgs: (process.env.MYTHIX_RUNTIME_ARGS || '').split(/\s+/g).filter(Boolean),
312
312
  applicationPath: (config) => Path.resolve(config.appRootPath, 'application.js'),
313
313
  getApplicationClass: (config) => {
314
314
  let Application = require(config.applicationPath);
@@ -347,7 +347,7 @@ function spawnCommand(args, options, _config) {
347
347
  try {
348
348
  let childProcess = spawn(
349
349
  config.runtime || 'node',
350
- (config.runtimeArgs || []).concat(args),
350
+ (config.runtimeArgs || []).concat(args).filter(Boolean),
351
351
  Object.assign({}, options || {}, {
352
352
  env: Object.assign({}, process.env, (options || {}).env || {}),
353
353
  stdio: 'inherit',
@@ -83,12 +83,18 @@ function nodeRequestHandler(routeName, requestOptions) {
83
83
  },
84
84
  requestOptions,
85
85
  extraConfig,
86
- { headers: Object.assign({}, headers, Utils.keysToLowerCase(extraConfig.headers || {})) },
86
+ {
87
+ headers: Utils.cleanObjectProperties(Object.assign(
88
+ {},
89
+ headers,
90
+ Utils.keysToLowerCase(extraConfig.headers || {}),
91
+ )),
92
+ },
87
93
  );
88
94
 
89
95
  delete options.data;
90
96
 
91
- var thisRequest = HTTP.request(options, function(response) {
97
+ var thisRequest = HTTP.request(Utils.cleanObjectProperties(options), function(response) {
92
98
  var responseData = Buffer.alloc(0);
93
99
 
94
100
  response.on('data', function(chunk) {
@@ -172,7 +178,7 @@ function browserRequestHandler(routeName, requestOptions) {
172
178
  var url = requestOptions.url;
173
179
  var data = requestOptions.data;
174
180
  var extraConfig = {};
175
- var headers = Object.assign({ 'content-type': 'application/json; charset=UTF-8' }, Utils.keysToLowerCase(this.defaultHeaders || {}), Utils.keysToLowerCase(requestOptions.headers || {}));
181
+ var headers = Object.assign(Utils.keysToLowerCase(this.defaultHeaders || {}), Utils.keysToLowerCase(requestOptions.headers || {}));
176
182
 
177
183
  if (data) {
178
184
  if (!method.match(/^(GET|HEAD)$/i)) {
@@ -193,12 +199,18 @@ function browserRequestHandler(routeName, requestOptions) {
193
199
  { method },
194
200
  requestOptions,
195
201
  extraConfig,
196
- { headers: Object.assign({}, headers, Utils.keysToLowerCase(extraConfig.headers || {})) },
202
+ {
203
+ headers: Utils.cleanObjectProperties(Object.assign(
204
+ {},
205
+ headers,
206
+ Utils.keysToLowerCase(extraConfig.headers || {}),
207
+ )),
208
+ },
197
209
  );
198
210
 
199
211
  delete options.data;
200
212
 
201
- globalScope.fetch(url, options).then(
213
+ globalScope.fetch(url, Utils.cleanObjectProperties(options)).then(
202
214
  function(response) {
203
215
  if (typeof requestOptions.responseHandler === 'function')
204
216
  return requestOptions.responseHandler(response);
@@ -271,6 +283,22 @@ function generateUtils() {
271
283
  return newObj;
272
284
  }
273
285
 
286
+ function cleanObjectProperties(obj) {
287
+ var keys = Object.keys(obj || {});
288
+ var newObj = {};
289
+
290
+ for (var i = 0, il = keys.length; i < il; i++) {
291
+ var key = keys[i];
292
+ var value = obj[key];
293
+ if (value == null || value == '')
294
+ continue;
295
+
296
+ newObj[key] = value;
297
+ }
298
+
299
+ return newObj;
300
+ }
301
+
274
302
  function injectURLParams(routeName, _options) {
275
303
  var options = _options || {};
276
304
  var params = options.params || {};
@@ -299,6 +327,7 @@ function generateUtils() {
299
327
  isEmpty,
300
328
  dataToQueryString,
301
329
  keysToLowerCase,
330
+ cleanObjectProperties,
302
331
  injectURLParams,
303
332
  };
304
333
  })();
@@ -350,11 +379,15 @@ function generateRoutes(_routes, _options) {
350
379
  contentType = contentType[0];
351
380
 
352
381
  clientOptions = {
353
- credentials: 'same-origin',
354
- headers: {
355
- 'Content-Type': contentType,
356
- },
382
+ credentials: 'same-origin',
357
383
  };
384
+
385
+ // Don't set content type for multipart/form-data
386
+ if (!(/multipart\/form-data/i).test(contentType)) {
387
+ clientOptions.headers = {
388
+ 'Content-Type': contentType,
389
+ };
390
+ }
358
391
  }
359
392
 
360
393
  clientOptions = JSON.stringify(clientOptions, (key, value) => {
@@ -114,7 +114,7 @@ class ModelModule extends BaseModule {
114
114
  let application = this.getApplication();
115
115
  let connection = (typeof application.getDBConnection === 'function') ? application.getDBConnection() : null;
116
116
  if (!connection)
117
- return;
117
+ return {};
118
118
 
119
119
  return connection.getModels();
120
120
  }
@@ -55,17 +55,17 @@ class TaskBase {
55
55
  }
56
56
 
57
57
  getModel(name) {
58
- let application = this.application;
58
+ let application = this.getApplication();
59
59
  return application.getModel(name);
60
60
  }
61
61
 
62
62
  getModels() {
63
- let application = this.application;
63
+ let application = this.getApplication();
64
64
  return application.getModels();
65
65
  }
66
66
 
67
67
  getDBConnection() {
68
- let application = this.application;
68
+ let application = this.getApplication();
69
69
  return application.getDBConnection();
70
70
  }
71
71
 
@@ -84,7 +84,7 @@ class TaskModule extends BaseModule {
84
84
  let connection = (typeof application.getDBConnection === 'function') ? application.getDBConnection() : null;
85
85
  let dbConfig = (typeof application.getDBConfig === 'function') ? application.getDBConfig() : null;
86
86
  let tasks = {};
87
- let args = { application: this, connection, dbConfig };
87
+ let args = { application, connection, dbConfig };
88
88
 
89
89
  for (let i = 0, il = taskFiles.length; i < il; i++) {
90
90
  let taskFile = taskFiles[i];
@@ -160,7 +160,7 @@ class TaskModule extends BaseModule {
160
160
  try {
161
161
  if (!TaskKlass.keepAlive || !taskInstance) {
162
162
  logger = createTaskLogger();
163
- taskInstance = new TaskKlass(this, logger, runID, { lastTime, currentTime, diff });
163
+ taskInstance = new TaskKlass(this.getApplication(), logger, runID, { lastTime, currentTime, diff });
164
164
 
165
165
  taskInfo.taskInstance = taskInstance;
166
166