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.
Files changed (128) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +27 -30
  3. package/{src → lib}/application.d.ts +25 -39
  4. package/{src/application.js → lib/application.mjs} +110 -135
  5. package/lib/cli/cli-utils.d.ts +21 -0
  6. package/lib/cli/cli-utils.mjs +319 -0
  7. package/lib/cli/command-base.d.ts +33 -0
  8. package/lib/cli/command-base.mjs +118 -0
  9. package/lib/cli/command-executor.mjs +14 -0
  10. package/lib/cli/commands/deploy-command.mjs +1010 -0
  11. package/lib/cli/commands/generators/generate-command.mjs +117 -0
  12. package/lib/cli/commands/generators/index.mjs +2 -0
  13. package/{src/cli/generators/migration-generator.js → lib/cli/commands/generators/migration-generator.mjs} +11 -13
  14. package/lib/cli/commands/index.mjs +22 -0
  15. package/lib/cli/commands/migrate-command.mjs +184 -0
  16. package/lib/cli/commands/routes-command.mjs +40 -0
  17. package/lib/cli/commands/serve-command.mjs +63 -0
  18. package/lib/cli/commands/shell-command.mjs +95 -0
  19. package/lib/cli/index.mjs +3 -0
  20. package/{src → lib}/controllers/controller-base.d.ts +1 -1
  21. package/{src/controllers/controller-base.js → lib/controllers/controller-base.mjs} +3 -9
  22. package/{src → lib}/controllers/controller-module.d.ts +3 -3
  23. package/lib/controllers/controller-module.mjs +70 -0
  24. package/lib/controllers/generate-client-api-interface-spec.mjs +44 -0
  25. package/{src → lib}/controllers/generate-client-api-interface.d.ts +1 -0
  26. package/{src/controllers/generate-client-api-interface.js → lib/controllers/generate-client-api-interface.mjs} +39 -16
  27. package/{src → lib}/controllers/index.d.ts +2 -3
  28. package/lib/controllers/index.mjs +4 -0
  29. package/lib/controllers/routes/index.mjs +4 -0
  30. package/{src/controllers/routes/route-capture.js → lib/controllers/routes/route-capture.mjs} +2 -8
  31. package/{src/controllers/routes/route-endpoint.js → lib/controllers/routes/route-endpoint.mjs} +8 -8
  32. package/{src/controllers/routes/route-scope-base.js → lib/controllers/routes/route-scope-base.mjs} +19 -15
  33. package/{src/controllers/routes/route-scope.js → lib/controllers/routes/route-scope.mjs} +10 -12
  34. package/{src/http-server/http-errors.js → lib/http/http-errors.mjs} +9 -20
  35. package/{src/utils/http-interface.js → lib/http/http-interface.mjs} +6 -14
  36. package/{src/http-server → lib/http}/http-server-module.d.ts +2 -2
  37. package/{src/http-server/http-server-module.js → lib/http/http-server-module.mjs} +7 -11
  38. package/{src/http-server/http-server.js → lib/http/http-server.mjs} +17 -21
  39. package/lib/http/index.d.ts +4 -0
  40. package/lib/http/index.mjs +5 -0
  41. package/lib/index.d.ts +30 -0
  42. package/lib/index.mjs +31 -0
  43. package/lib/logger-spec.mjs +121 -0
  44. package/{src → lib}/logger.d.ts +1 -3
  45. package/{src/logger.js → lib/logger.mjs} +10 -24
  46. package/lib/models/index.d.ts +2 -0
  47. package/lib/models/index.mjs +2 -0
  48. package/{src/models/migration-model.js → lib/models/migration-model.mjs} +3 -11
  49. package/lib/models/model.d.ts +10 -0
  50. package/lib/models/model.mjs +28 -0
  51. package/{src → lib}/modules/database-module.d.ts +2 -2
  52. package/{src/modules/database-module.js → lib/modules/database-module.mjs} +19 -14
  53. package/lib/modules/index.d.ts +2 -0
  54. package/lib/modules/index.mjs +2 -0
  55. package/{src/modules/base-module.d.ts → lib/modules/module-base.d.ts} +3 -10
  56. package/{src/modules/base-module.js → lib/modules/module-base.mjs} +16 -6
  57. package/lib/tasks/index.d.ts +2 -0
  58. package/lib/tasks/index.mjs +2 -0
  59. package/{src → lib}/tasks/task-base.d.ts +4 -14
  60. package/lib/tasks/task-base.mjs +73 -0
  61. package/{src → lib}/tasks/task-module.d.ts +3 -3
  62. package/{src/tasks/task-module.js → lib/tasks/task-module.mjs} +43 -98
  63. package/{src/utils/config-utils.js → lib/utils/config-utils.mjs} +2 -10
  64. package/lib/utils/crypto-utils-spec.mjs +24 -0
  65. package/{src/utils/crypto-utils.js → lib/utils/crypto-utils.mjs} +16 -38
  66. package/lib/utils/file-utils-spec.mjs +10 -0
  67. package/{src/utils/file-utils.js → lib/utils/file-utils.mjs} +4 -11
  68. package/{src/utils/http-utils.js → lib/utils/http-utils.mjs} +3 -10
  69. package/{src → lib}/utils/index.d.ts +1 -1
  70. package/lib/utils/index.mjs +6 -0
  71. package/lib/utils/mime-utils-spec.mjs +171 -0
  72. package/{src/utils/mime-utils.js → lib/utils/mime-utils.mjs} +5 -14
  73. package/{src/utils/test-utils.js → lib/utils/test-utils.mjs} +14 -42
  74. package/package.json +5 -5
  75. package/src/cli/cli-utils.d.ts +0 -80
  76. package/src/cli/cli-utils.js +0 -547
  77. package/src/cli/command-executor.js +0 -31
  78. package/src/cli/deploy-command.js +0 -1010
  79. package/src/cli/generators/generate-command.js +0 -149
  80. package/src/cli/index.js +0 -5
  81. package/src/cli/migrate-command.js +0 -181
  82. package/src/cli/routes-command.js +0 -40
  83. package/src/cli/serve-command.js +0 -63
  84. package/src/cli/shell-command.js +0 -96
  85. package/src/controllers/controller-module.js +0 -126
  86. package/src/controllers/controller-utils.d.ts +0 -19
  87. package/src/controllers/controller-utils.js +0 -24
  88. package/src/controllers/index.js +0 -19
  89. package/src/controllers/routes/index.js +0 -31
  90. package/src/http-server/index.d.ts +0 -3
  91. package/src/http-server/index.js +0 -16
  92. package/src/index.d.ts +0 -49
  93. package/src/index.js +0 -47
  94. package/src/models/index.d.ts +0 -4
  95. package/src/models/index.js +0 -17
  96. package/src/models/model-module.d.ts +0 -9
  97. package/src/models/model-module.js +0 -130
  98. package/src/models/model-utils.d.ts +0 -20
  99. package/src/models/model-utils.js +0 -46
  100. package/src/models/model.d.ts +0 -20
  101. package/src/models/model.js +0 -65
  102. package/src/modules/file-watcher-module.d.ts +0 -13
  103. package/src/modules/file-watcher-module.js +0 -220
  104. package/src/modules/index.d.ts +0 -3
  105. package/src/modules/index.js +0 -11
  106. package/src/tasks/index.d.ts +0 -3
  107. package/src/tasks/index.js +0 -11
  108. package/src/tasks/task-base.js +0 -117
  109. package/src/tasks/task-utils.d.ts +0 -46
  110. package/src/tasks/task-utils.js +0 -130
  111. package/src/utils/index.js +0 -25
  112. /package/{src → lib}/cli/index.d.ts +0 -0
  113. /package/{src → lib}/controllers/routes/index.d.ts +0 -0
  114. /package/{src → lib}/controllers/routes/route-capture.d.ts +0 -0
  115. /package/{src → lib}/controllers/routes/route-endpoint.d.ts +0 -0
  116. /package/{src → lib}/controllers/routes/route-scope-base.d.ts +0 -0
  117. /package/{src → lib}/controllers/routes/route-scope.d.ts +0 -0
  118. /package/{src/http-server → lib/http}/http-errors.d.ts +0 -0
  119. /package/{src/utils → lib/http}/http-interface.d.ts +0 -0
  120. /package/{src/http-server → lib/http}/http-server.d.ts +0 -0
  121. /package/{src → lib}/interfaces/common.ts +0 -0
  122. /package/{src → lib}/models/migration-model.d.ts +0 -0
  123. /package/{src → lib}/utils/config-utils.d.ts +0 -0
  124. /package/{src → lib}/utils/crypto-utils.d.ts +0 -0
  125. /package/{src → lib}/utils/file-utils.d.ts +0 -0
  126. /package/{src → lib}/utils/http-utils.d.ts +0 -0
  127. /package/{src → lib}/utils/mime-utils.d.ts +0 -0
  128. /package/{src → lib}/utils/test-utils.d.ts +0 -0
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- const Nife = require('nife');
1
+ import Nife from 'nife';
4
2
 
5
3
  const MIME_TYPES = {
6
4
  '3g2': 'video/3gpp2',
@@ -88,19 +86,19 @@ const MIME_EXTENSION_EXCEPTIONS = {
88
86
  'tif': 'tiff',
89
87
  };
90
88
 
91
- function getFilenameExtension(fileName) {
89
+ export function getFilenameExtension(fileName) {
92
90
  if (Nife.isEmpty(fileName))
93
91
  return;
94
92
 
95
93
  return (!fileName.match(/\.[^./\\]+$/)) ? null : fileName.replace(/^.*?([^./]+)$/, '$1');
96
94
  }
97
95
 
98
- function getMimeTypeFromFileExtension(extension) {
96
+ export function getMimeTypeFromFileExtension(extension) {
99
97
  let ext = ('' + extension).toLowerCase();
100
98
  return MIME_TYPES[ext];
101
99
  }
102
100
 
103
- function getFileExtensionFromMimeType(_mimeType) {
101
+ export function getFileExtensionFromMimeType(_mimeType) {
104
102
  let mimeType = ('' + _mimeType).toLowerCase();
105
103
  let extensions = Object.keys(MIME_TYPES).sort();
106
104
 
@@ -117,13 +115,6 @@ function getFileExtensionFromMimeType(_mimeType) {
117
115
  }
118
116
  }
119
117
 
120
- function getMimeTypeFromFilename(fileName) {
118
+ export function getMimeTypeFromFilename(fileName) {
121
119
  return getMimeTypeFromFileExtension(getFilenameExtension(fileName));
122
120
  }
123
-
124
- module.exports = {
125
- getFileExtensionFromMimeType,
126
- getFilenameExtension,
127
- getMimeTypeFromFileExtension,
128
- getMimeTypeFromFilename,
129
- };
@@ -1,13 +1,9 @@
1
- 'use strict';
2
-
3
- /* global process */
4
-
5
- const Nife = require('nife');
6
- const { Utils } = require('mythix-orm');
7
- const { Logger } = require('../logger');
8
- const { DatabaseModule } = require('../modules/database-module');
9
- const { HTTPInterface } = require('./http-interface');
10
- const { HTTPServerModule } = require('../http-server/http-server-module');
1
+ import Nife from 'nife';
2
+ import { Utils } from 'mythix-orm';
3
+ import { Logger } from '../logger.mjs';
4
+ import { DatabaseModule } from '../modules/database-module.mjs';
5
+ import { HTTPServerModule } from '../http/http-server-module.mjs';
6
+ import { HTTPInterface } from '../http/http-interface.mjs';
11
7
 
12
8
  class TestDatabaseModule extends DatabaseModule {
13
9
  getTablePrefix() {
@@ -52,31 +48,25 @@ class TestHTTPServerModule extends HTTPServerModule {
52
48
  }
53
49
  }
54
50
 
55
- function createTestApplication(ApplicationClass) {
51
+ export function createTestApplication(ApplicationClass) {
56
52
  const Klass = class TestApplication extends ApplicationClass {
57
53
  // Swap out modules for test config
58
- static getDefaultModules() {
59
- let defaultModules = ApplicationClass.getDefaultModules();
60
-
61
- defaultModules = ApplicationClass.replaceModule(defaultModules, DatabaseModule, TestDatabaseModule);
62
- defaultModules = ApplicationClass.replaceModule(defaultModules, HTTPServerModule, TestHTTPServerModule);
63
-
64
- return defaultModules;
54
+ static getModules() {
55
+ return {
56
+ ...super.getModules(),
57
+ database: TestDatabaseModule,
58
+ httpServer: TestHTTPServerModule,
59
+ };
65
60
  }
66
61
 
67
62
  constructor(_opts) {
68
63
  let opts = Nife.extend(true, {
69
64
  environment: 'test',
70
- autoReload: false,
71
- runTasks: false,
72
- testMode: true,
73
- appName: `${(Nife.isNotEmpty(ApplicationClass.APP_NAME)) ? ApplicationClass.APP_NAME : 'mythix'}_test`,
65
+ tasks: false,
74
66
  }, _opts || {});
75
67
 
76
68
  super(opts);
77
69
 
78
- process.setMaxListeners(0);
79
-
80
70
  Object.defineProperties(this, {
81
71
  'httpInterface': {
82
72
  writable: true,
@@ -166,22 +156,6 @@ function createTestApplication(ApplicationClass) {
166
156
  }
167
157
  }
168
158
 
169
- async hijackModel(modelName, callback, runner) {
170
- let models = this.getModels();
171
- let OriginalModel = models[modelName];
172
-
173
- try {
174
- let Klass = callback.call(this, OriginalModel);
175
-
176
- let connection = this.getConnection();
177
- connection.registerModel(Klass);
178
-
179
- return await runner.call(this, Klass);
180
- } finally {
181
- models[modelName] = OriginalModel;
182
- }
183
- }
184
-
185
159
  getDefaultURL(...args) {
186
160
  return this.httpInterface.getDefaultURL(...args);
187
161
  }
@@ -241,5 +215,3 @@ function createTestApplication(ApplicationClass) {
241
215
 
242
216
  return Klass;
243
217
  }
244
-
245
- module.exports = { createTestApplication };
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "mythix",
3
- "version": "3.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "Mythix is a NodeJS web-app framework",
5
- "main": "src/index",
5
+ "main": "lib/index.mjs",
6
+ "type": "module",
6
7
  "scripts": {
7
8
  "test": "node ./node_modules/.bin/jasmine",
8
9
  "test-watch": "watch 'clear ; node --trace-warnings ./node_modules/.bin/jasmine' . --wait=3 --interval=1"
@@ -20,15 +21,14 @@
20
21
  "homepage": "https://github.com/th317erd/mythix#readme",
21
22
  "devDependencies": {
22
23
  "@spothero/eslint-plugin-spothero": "github:spothero/eslint-plugin-spothero",
23
- "@types/node": "^20.2.5",
24
+ "@types/node": "^20.3.1",
24
25
  "colors": "^1.4.0",
25
26
  "diff": "^5.1.0",
26
27
  "eslint": "^8.42.0",
27
28
  "jasmine": "^5.0.1"
28
29
  },
29
30
  "dependencies": {
30
- "@types/events": "^3.0.0",
31
- "chokidar": "^3.5.3",
31
+ "@types/express": "^4.17.17",
32
32
  "cmded": "^1.2.5",
33
33
  "express": "^4.18.2",
34
34
  "express-busboy": "github:th317erd/express-busboy#0754a570d7979097b31e48655b80d3fcd628d4e4",
@@ -1,80 +0,0 @@
1
- import { HelpInterface, Runner } from 'cmded';
2
- import { Stats } from 'fs';
3
- import { ConnectionBase } from 'mythix-orm';
4
- import { Application, ApplicationClass, ApplicationOptions } from '../application';
5
- import { GenericObject } from '../interfaces/common';
6
- import { Logger } from '../logger';
7
-
8
- export declare type CommandClass = typeof CommandBase;
9
-
10
- export declare type CommandClasses = { [key: string]: CommandClass };
11
-
12
- export declare type FileFilterCallback = (fullFileName: string, fileName: string, stats?: Stats) => boolean;
13
-
14
- export declare class CommandBase {
15
- declare public static commands: GenericObject;
16
- declare public static commandName: string;
17
- declare public static applicationConfig?: GenericObject | (() => GenericObject);
18
- declare public static commandArguments?: () => { help: HelpInterface, runner: Runner };
19
- declare public static runtimeArguments?: { [key: string]: Array<string> };
20
- public static execute(): Promise<void>;
21
-
22
- declare public application: Application;
23
- declare public options: GenericObject;
24
-
25
- constructor(application: Application, options?: GenericObject);
26
- getOptions(): GenericObject;
27
- getApplication(): Application;
28
- getLogger(): Logger;
29
- getConnection(connection?: ConnectionBase): ConnectionBase;
30
-
31
- // Deprecated
32
- getDBConnection(connection?: ConnectionBase): ConnectionBase;
33
-
34
- spawnCommand(
35
- command: string,
36
- args: Array<string>,
37
- options?: GenericObject
38
- ): Promise<{ stdout: string, stderr: string, error: any, code: number }>;
39
-
40
- getCommandFiles(filterFunc?: FileFilterCallback): Array<string>;
41
- }
42
-
43
- export declare interface DefineCommandContext {
44
- Parent: CommandClass;
45
- commandName: string;
46
- }
47
-
48
- export declare function loadMythixConfig(
49
- mythixConfigPath: string,
50
- appRootPath: string
51
- ): GenericObject;
52
-
53
- export declare function loadCommand(name: string): CommandClass;
54
-
55
- export declare function loadCommands(
56
- applicationCommandsPath: string,
57
- skip: Array<string>
58
- ): CommandClasses;
59
-
60
- export declare function defineCommand(
61
- commandName: string,
62
- definer: (context: DefineCommandContext) => CommandClass,
63
- parent?: string | CommandClass,
64
- ): CommandClass;
65
-
66
- export declare function createApplication(
67
- applicationClass: ApplicationClass,
68
- options?: ApplicationOptions
69
- ): Application;
70
-
71
- export declare function executeCommand(
72
- config: GenericObject,
73
- appOptions: ApplicationOptions,
74
- commandContext: GenericObject,
75
- CommandKlass: CommandClass,
76
- argv: Array<string>
77
- ): void;
78
-
79
- export declare function getInternalCommandsPath(): string;
80
- export declare function getCommandFiles(commandsPath: string, filterFunc?: FileFilterCallback): Array<string>;