mythix 1.2.0 → 2.0.0

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 (31) hide show
  1. package/package.json +4 -12
  2. package/src/application.js +5 -2
  3. package/src/cli/migrations/makemigrations-command.js +1 -2
  4. package/src/cli/shell-command.js +0 -2
  5. package/src/controllers/controller-module.js +0 -9
  6. package/src/http-server/http-server.js +0 -5
  7. package/src/models/index.js +0 -4
  8. package/src/models/migration-model.js +2 -2
  9. package/src/models/model-module.js +19 -32
  10. package/src/models/model-utils.js +24 -374
  11. package/src/models/model.js +29 -150
  12. package/src/modules/database-module.js +23 -18
  13. package/src/tasks/task-module.js +1 -11
  14. package/src/tasks/task-utils.js +1 -2
  15. package/src/utils/test-utils.js +38 -50
  16. package/.eslintrc.js +0 -94
  17. package/.vscode/settings.json +0 -7
  18. package/spec/controllers/controller-utils-spec.js +0 -145
  19. package/spec/controllers/generate-client-api-interface-spec.js +0 -156
  20. package/spec/controllers/generateClientAPIInterface01.snapshot +0 -552
  21. package/spec/controllers/generateClientAPIInterface02.snapshot +0 -465
  22. package/spec/controllers/generateClientAPIInterface03.snapshot +0 -418
  23. package/spec/controllers/generateClientAPIInterface04.snapshot +0 -552
  24. package/spec/controllers/generateClientAPIInterface05.snapshot +0 -552
  25. package/spec/support/application.js +0 -50
  26. package/spec/support/config/index.js +0 -3
  27. package/spec/support/jasmine.json +0 -13
  28. package/spec/support/snapshots.js +0 -63
  29. package/spec/utils/crypto-utils-spec.js +0 -28
  30. package/spec/utils/file-utils-spec.js +0 -14
  31. package/spec/utils/mime-utils-spec.js +0 -175
@@ -1,145 +0,0 @@
1
- 'use strict';
2
-
3
- /* global describe, it, expect */
4
-
5
- const ControllerUtils = require('../../src/controllers/controller-utils');
6
-
7
- describe('controller-utils', function() {
8
- describe('buildMethodMatcher', function() {
9
- it('should be able to create a method matcher', function() {
10
- let matchFunc = ControllerUtils.buildMethodMatcher('*');
11
- expect(matchFunc(null)).toBe(true);
12
- expect(matchFunc('')).toBe(true);
13
- expect(matchFunc('GET')).toBe(true);
14
- expect(matchFunc('get')).toBe(true);
15
- expect(matchFunc('Post')).toBe(true);
16
-
17
- matchFunc = ControllerUtils.buildMethodMatcher([ 'GET', '*' ]);
18
- expect(matchFunc('')).toBe(true);
19
- expect(matchFunc('GET')).toBe(true);
20
- expect(matchFunc('get')).toBe(true);
21
- expect(matchFunc('Post')).toBe(true);
22
-
23
- matchFunc = ControllerUtils.buildMethodMatcher('GET');
24
- expect(matchFunc('GET')).toBe(true);
25
- expect(matchFunc('get')).toBe(true);
26
- expect(matchFunc('GETs')).toBe(false);
27
- expect(matchFunc('post')).toBe(false);
28
-
29
- matchFunc = ControllerUtils.buildMethodMatcher([ 'get', 'POST' ]);
30
- expect(matchFunc('GET')).toBe(true);
31
- expect(matchFunc('get')).toBe(true);
32
- expect(matchFunc('POST')).toBe(true);
33
- expect(matchFunc('head')).toBe(false);
34
-
35
- matchFunc = ControllerUtils.buildMethodMatcher(/(get|post)/i);
36
- expect(matchFunc('GET')).toBe(true);
37
- expect(matchFunc('get')).toBe(true);
38
- expect(matchFunc('gets')).toBe(true);
39
- expect(matchFunc('POST')).toBe(true);
40
- expect(matchFunc('POSTs')).toBe(true);
41
- expect(matchFunc('head')).toBe(false);
42
- });
43
- });
44
-
45
- describe('buildContentTypeMatcher', function() {
46
- it('should be able to create a content-type matcher', function() {
47
- let matcher = ControllerUtils.buildContentTypeMatcher('*');
48
- expect(matcher.regexp.toString()).toBe('/.*/i');
49
- expect(matcher('application/json')).toBe(true);
50
- expect(matcher('anything')).toBe(true);
51
- expect(matcher()).toBe(true);
52
-
53
- matcher = ControllerUtils.buildContentTypeMatcher('application/json');
54
- expect(matcher.regexp.toString()).toBe('/(application\\/json)/i');
55
- expect(matcher('application/json')).toBe(true);
56
- expect(matcher('application/json; charset=UTF-8')).toBe(true);
57
- expect(matcher('text/plain')).toBe(false);
58
-
59
- matcher = ControllerUtils.buildContentTypeMatcher(/^(application\/json|text\/plain)$/i);
60
- expect(matcher.regexp.toString()).toBe('/^(application\\/json|text\\/plain)$/i');
61
- expect(matcher('application/json')).toBe(true);
62
- expect(matcher('application/json; charset=UTF-8')).toBe(false);
63
- expect(matcher('text/plain')).toBe(true);
64
- expect(matcher('text/plain;')).toBe(false);
65
- });
66
- });
67
-
68
- describe('buildPathMatcher', function() {
69
- it('should be able to build a parser from a route name', function() {
70
- let matchFunc = ControllerUtils.buildPathMatcher('person<id?:integer = 0>_stuff');
71
- expect(matchFunc('person120_stuff')).toEqual({ id: 120 });
72
- expect(matchFunc('person_stuff')).toEqual({});
73
-
74
- matchFunc = ControllerUtils.buildPathMatcher('objects/<id>');
75
- expect(matchFunc('objects')).toBe(undefined);
76
- expect(matchFunc('objects/')).toBe(undefined);
77
- expect(matchFunc('objects/1')).toEqual({ id: 1 });
78
-
79
- matchFunc = ControllerUtils.buildPathMatcher('objects/<id?>');
80
- expect(matchFunc('objects')).toEqual({});
81
- expect(matchFunc('objects/')).toEqual({});
82
- expect(matchFunc('objects/1')).toEqual({ id: 1 });
83
-
84
- matchFunc = ControllerUtils.buildPathMatcher('values/<truthy:boolean>');
85
- expect(matchFunc('values')).toBe(undefined);
86
- expect(matchFunc('values/')).toBe(undefined);
87
- expect(matchFunc('values/1')).toBe(undefined);
88
- expect(matchFunc('values/derp')).toBe(undefined);
89
- expect(matchFunc('values/true')).toEqual({ truthy: true });
90
- expect(matchFunc('values/True')).toEqual({ truthy: true });
91
- expect(matchFunc('values/TRUE')).toEqual({ truthy: true });
92
- expect(matchFunc('values/false')).toEqual({ truthy: false });
93
- expect(matchFunc('values/False')).toEqual({ truthy: false });
94
- expect(matchFunc('values/FALSE')).toEqual({ truthy: false });
95
-
96
- matchFunc = ControllerUtils.buildPathMatcher('values/<str:magic>', { magic: (part) => `MAGIC:${part}!!!`});
97
- expect(matchFunc('values')).toBe(undefined);
98
- expect(matchFunc('values/')).toBe(undefined);
99
- expect(matchFunc('values/1')).toEqual({ str: 'MAGIC:1!!!' });
100
- expect(matchFunc('values/derp')).toEqual({ str: 'MAGIC:derp!!!' });
101
- });
102
- });
103
-
104
- describe('buildRoutes', function() {
105
- it('should be able to compile routes', function() {
106
- // let allRoutes = ControllerUtils.buildRoutes({
107
- // 'api': {
108
- // 'v1': {
109
- // 'test': {
110
- // methods: [ 'GET', 'POST' ],
111
- // accept: 'application/json',
112
- // controller: 'Something.test',
113
- // children: [
114
- // {
115
- // priority: 10,
116
- // methods: 'GET',
117
- // controller: 'Something.children.get',
118
- // },
119
- // {
120
- // priority: 11,
121
- // methods: 'POST',
122
- // controller: 'Something.children.post',
123
- // },
124
- // {
125
- // 'do-something/<id:int>': {
126
- // priority: 10,
127
- // methods: 'GET',
128
- // controller: 'Something.children.get.doSomething',
129
- // },
130
- // },
131
- // ],
132
- // },
133
- // 'test2': {
134
- // priority: 0,
135
- // methods: [ 'POST', '*' ],
136
- // controller: 'Something.test2',
137
- // },
138
- // },
139
- // },
140
- // });
141
-
142
- // console.log('ALL ROUTES: ', allRoutes);
143
- });
144
- });
145
- });
@@ -1,156 +0,0 @@
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
- });