mythix 1.0.1

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 (37) hide show
  1. package/.vscode/settings.json +7 -0
  2. package/LICENSE +21 -0
  3. package/README.md +716 -0
  4. package/package.json +34 -0
  5. package/spec/controller-utils-spec.js +141 -0
  6. package/spec/support/jasmine.json +13 -0
  7. package/spec/utils-spec.js +10 -0
  8. package/src/application.js +934 -0
  9. package/src/cli/cli-utils.js +388 -0
  10. package/src/cli/index.js +3 -0
  11. package/src/cli/migrations/makemigrations-command.js +94 -0
  12. package/src/cli/migrations/migrate-command.js +105 -0
  13. package/src/cli/migrations/migration-utils.js +952 -0
  14. package/src/cli/serve-command.js +32 -0
  15. package/src/cli/shell-command.js +82 -0
  16. package/src/controllers/controller-base.js +83 -0
  17. package/src/controllers/controller-utils.js +415 -0
  18. package/src/controllers/index.js +20 -0
  19. package/src/http-server/http-errors.js +68 -0
  20. package/src/http-server/http-server.js +359 -0
  21. package/src/http-server/http-utils.js +23 -0
  22. package/src/http-server/index.js +17 -0
  23. package/src/http-server/middleware/default-middleware.js +106 -0
  24. package/src/http-server/middleware/index.js +5 -0
  25. package/src/index.js +32 -0
  26. package/src/logger.js +211 -0
  27. package/src/models/index.js +14 -0
  28. package/src/models/model-utils.js +259 -0
  29. package/src/models/model.js +85 -0
  30. package/src/tasks/index.js +7 -0
  31. package/src/tasks/task-base.js +120 -0
  32. package/src/tasks/task-utils.js +127 -0
  33. package/src/utils/config-utils.js +35 -0
  34. package/src/utils/crypto-utils.js +36 -0
  35. package/src/utils/file-utils.js +43 -0
  36. package/src/utils/http-utils.js +191 -0
  37. package/src/utils/index.js +17 -0
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "mythix",
3
+ "version": "1.0.1",
4
+ "description": "Mythix is a NodeJS web-app framework",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "node ./node_modules/.bin/jasmine"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/th317erd/mythix.git"
12
+ },
13
+ "keywords": [],
14
+ "author": "Wyatt Greenway",
15
+ "license": "MIT",
16
+ "bugs": {
17
+ "url": "https://github.com/th317erd/mythix/issues"
18
+ },
19
+ "homepage": "https://github.com/th317erd/mythix#readme",
20
+ "devDependencies": {
21
+ "jasmine": "^4.0.2"
22
+ },
23
+ "dependencies": {
24
+ "chokidar": "^3.5.3",
25
+ "deep-diff": "^1.0.2",
26
+ "express": "^4.17.2",
27
+ "express-busboy": "^8.0.0",
28
+ "inflection": "^1.13.1",
29
+ "lodash": "^4.17.21",
30
+ "nife": "^1.2.2",
31
+ "object-hash": "^2.2.0",
32
+ "sequelize": "^6.13.0"
33
+ }
34
+ }
@@ -0,0 +1,141 @@
1
+ const ControllerUtils = require('../src/controllers/controller-utils');
2
+
3
+ describe('controller-utils', function() {
4
+ describe('buildMethodMatcher', function() {
5
+ it('should be able to create a method matcher', function() {
6
+ var matchFunc = ControllerUtils.buildMethodMatcher('*');
7
+ expect(matchFunc(null)).toBe(true);
8
+ expect(matchFunc('')).toBe(true);
9
+ expect(matchFunc('GET')).toBe(true);
10
+ expect(matchFunc('get')).toBe(true);
11
+ expect(matchFunc('Post')).toBe(true);
12
+
13
+ var matchFunc = ControllerUtils.buildMethodMatcher([ 'GET', '*' ]);
14
+ expect(matchFunc('')).toBe(true);
15
+ expect(matchFunc('GET')).toBe(true);
16
+ expect(matchFunc('get')).toBe(true);
17
+ expect(matchFunc('Post')).toBe(true);
18
+
19
+ var matchFunc = ControllerUtils.buildMethodMatcher('GET');
20
+ expect(matchFunc('GET')).toBe(true);
21
+ expect(matchFunc('get')).toBe(true);
22
+ expect(matchFunc('GETs')).toBe(false);
23
+ expect(matchFunc('post')).toBe(false);
24
+
25
+ var matchFunc = ControllerUtils.buildMethodMatcher([ 'get', 'POST' ]);
26
+ expect(matchFunc('GET')).toBe(true);
27
+ expect(matchFunc('get')).toBe(true);
28
+ expect(matchFunc('POST')).toBe(true);
29
+ expect(matchFunc('head')).toBe(false);
30
+
31
+ var matchFunc = ControllerUtils.buildMethodMatcher(/(get|post)/i);
32
+ expect(matchFunc('GET')).toBe(true);
33
+ expect(matchFunc('get')).toBe(true);
34
+ expect(matchFunc('gets')).toBe(true);
35
+ expect(matchFunc('POST')).toBe(true);
36
+ expect(matchFunc('POSTs')).toBe(true);
37
+ expect(matchFunc('head')).toBe(false);
38
+ });
39
+ });
40
+
41
+ describe('buildContentTypeMatcher', function() {
42
+ it('should be able to create a content-type matcher', function() {
43
+ var matcher = ControllerUtils.buildContentTypeMatcher('*');
44
+ expect(matcher.regexp.toString()).toBe('/.*/i');
45
+ expect(matcher('application/json')).toBe(true);
46
+ expect(matcher('anything')).toBe(true);
47
+ expect(matcher()).toBe(true);
48
+
49
+ var matcher = ControllerUtils.buildContentTypeMatcher('application/json');
50
+ expect(matcher.regexp.toString()).toBe('/(application\\/json)/i');
51
+ expect(matcher('application/json')).toBe(true);
52
+ expect(matcher('application/json; charset=UTF-8')).toBe(true);
53
+ expect(matcher('text/plain')).toBe(false);
54
+
55
+ var matcher = ControllerUtils.buildContentTypeMatcher(/^(application\/json|text\/plain)$/i);
56
+ expect(matcher.regexp.toString()).toBe('/^(application\\/json|text\\/plain)$/i');
57
+ expect(matcher('application/json')).toBe(true);
58
+ expect(matcher('application/json; charset=UTF-8')).toBe(false);
59
+ expect(matcher('text/plain')).toBe(true);
60
+ expect(matcher('text/plain;')).toBe(false);
61
+ });
62
+ });
63
+
64
+ describe('buildPathMatcher', function() {
65
+ it('should be able to build a parser from a route name', function() {
66
+ var matchFunc = ControllerUtils.buildPathMatcher('person<id?:integer = 0>_stuff');
67
+ expect(matchFunc('person120_stuff')).toEqual({ id: 120 });
68
+ expect(matchFunc('person_stuff')).toEqual({});
69
+
70
+ var matchFunc = ControllerUtils.buildPathMatcher('objects/<id>');
71
+ expect(matchFunc('objects')).toBe(undefined);
72
+ expect(matchFunc('objects/')).toBe(undefined);
73
+ expect(matchFunc('objects/1')).toEqual({ id: 1 });
74
+
75
+ var matchFunc = ControllerUtils.buildPathMatcher('objects/<id?>');
76
+ expect(matchFunc('objects')).toEqual({});
77
+ expect(matchFunc('objects/')).toEqual({});
78
+ expect(matchFunc('objects/1')).toEqual({ id: 1 });
79
+
80
+ var matchFunc = ControllerUtils.buildPathMatcher('values/<truthy:boolean>');
81
+ expect(matchFunc('values')).toBe(undefined);
82
+ expect(matchFunc('values/')).toBe(undefined);
83
+ expect(matchFunc('values/1')).toBe(undefined);
84
+ expect(matchFunc('values/derp')).toBe(undefined);
85
+ expect(matchFunc('values/true')).toEqual({ truthy: true });
86
+ expect(matchFunc('values/True')).toEqual({ truthy: true });
87
+ expect(matchFunc('values/TRUE')).toEqual({ truthy: true });
88
+ expect(matchFunc('values/false')).toEqual({ truthy: false });
89
+ expect(matchFunc('values/False')).toEqual({ truthy: false });
90
+ expect(matchFunc('values/FALSE')).toEqual({ truthy: false });
91
+
92
+ var matchFunc = ControllerUtils.buildPathMatcher('values/<str:magic>', { magic: (part) => `MAGIC:${part}!!!`});
93
+ expect(matchFunc('values')).toBe(undefined);
94
+ expect(matchFunc('values/')).toBe(undefined);
95
+ expect(matchFunc('values/1')).toEqual({ str: 'MAGIC:1!!!' });
96
+ expect(matchFunc('values/derp')).toEqual({ str: 'MAGIC:derp!!!' });
97
+ });
98
+ });
99
+
100
+ describe('buildRoutes', function() {
101
+ it('should be able to compile routes', function() {
102
+ var allRoutes = ControllerUtils.buildRoutes({
103
+ 'api': {
104
+ 'v1': {
105
+ 'test': {
106
+ methods: [ 'GET', 'POST' ],
107
+ accept: 'application/json',
108
+ controller: 'Something.test',
109
+ children: [
110
+ {
111
+ priority: 10,
112
+ methods: 'GET',
113
+ controller: 'Something.children.get',
114
+ },
115
+ {
116
+ priority: 11,
117
+ methods: 'POST',
118
+ controller: 'Something.children.post',
119
+ },
120
+ {
121
+ 'do-something/<id:int>': {
122
+ priority: 10,
123
+ methods: 'GET',
124
+ controller: 'Something.children.get.doSomething',
125
+ }
126
+ }
127
+ ],
128
+ },
129
+ 'test2': {
130
+ priority: 0,
131
+ methods: [ 'POST', '*' ],
132
+ controller: 'Something.test2',
133
+ },
134
+ },
135
+ },
136
+ });
137
+
138
+ console.log('ALL ROUTES: ', allRoutes);
139
+ });
140
+ });
141
+ });
@@ -0,0 +1,13 @@
1
+ {
2
+ "spec_dir": "spec",
3
+ "spec_files": [
4
+ "**/*[sS]pec.?(m)js"
5
+ ],
6
+ "helpers": [
7
+ "helpers/**/*.?(m)js"
8
+ ],
9
+ "env": {
10
+ "stopSpecOnExpectationFailure": false,
11
+ "random": true
12
+ }
13
+ }
@@ -0,0 +1,10 @@
1
+ const Utils = require('../src/utils');
2
+
3
+ describe('file-utils', function() {
4
+ describe('fileNameWithoutExtension', function() {
5
+ it('should be able to remove the extension from a file name', function() {
6
+ expect(Utils.fileNameWithoutExtension('test.txt')).toEqual('test');
7
+ expect(Utils.fileNameWithoutExtension('test.txt.bin')).toEqual('test.txt');
8
+ });
9
+ });
10
+ });