mastercontroller 1.1.14 → 1.1.16

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/MasterControl.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // MasterControl - by Alexander rich
2
- // version 1.0.18
2
+ // version 1.0.19
3
3
 
4
4
  var url = require('url');
5
5
  var fileserver = require('fs');
@@ -9,6 +9,7 @@ var fs = require('fs');
9
9
  var url = require('url');
10
10
  var path = require('path');
11
11
 
12
+
12
13
  class MasterControl {
13
14
  controllerList = {}
14
15
  viewList = {}
@@ -16,6 +17,15 @@ class MasterControl {
16
17
  _root = null
17
18
  _environmentType = null
18
19
  _serverProtocol = null
20
+ _scopedList = []
21
+
22
+ #loadTransientListClasses(name, params){
23
+ Object.defineProperty(this.requestList, name, {
24
+ get: function() {
25
+ return new params();
26
+ }
27
+ });
28
+ }
19
29
 
20
30
  get env(){
21
31
  return require(`${this.root}/config/environments/env.${this.environmentType}.json`);
@@ -96,13 +106,48 @@ class MasterControl {
96
106
  };
97
107
  }
98
108
 
99
- // adds your class to the --------- todo
100
- register(name, param){
101
- if(name && param){
102
- this.requestList[name] = param;
109
+ /*
110
+ Services are created each time they are requested.
111
+ It gets a new instance of the injected object, on each request of this object.
112
+ For each time you inject this object is injected in the class, it will create a new instance.
113
+ */
114
+ addTransient(name, params){
115
+ if(name && params){
116
+ this.#loadTransientListClasses(name, params);
103
117
  }
118
+
104
119
  }
105
120
 
121
+ /*
122
+ Services are created on each request (once per request). This is most recommended for WEB applications.
123
+ So for example, if during a request you use the same dependency injection,
124
+ in many places, you will use the same instance of that object,
125
+ it will make reference to the same memory allocation
126
+ */
127
+ addScoped(name, params){
128
+ if(name && params){
129
+ this._scopedList[name] = params;
130
+ }
131
+ }
132
+
133
+ /*
134
+ Services are created once for the lifetime of the application. It uses the same instance for the whole application.
135
+ */
136
+ addSingleton(name, params){
137
+ if(name && params){
138
+ this.requestList[name] = new params();
139
+ }
140
+ }
141
+
142
+ // adds your class instance to the request object.
143
+ register(name, params){
144
+ if(name && params){
145
+ this.requestList[name] = params;
146
+ }
147
+ }
148
+
149
+
150
+
106
151
  // adds all the server settings needed
107
152
  serverSettings(settings){
108
153
 
package/MasterRouter.js CHANGED
@@ -1,6 +1,4 @@
1
-
2
-
3
- // version 1.0.16
1
+ // version 1.0.18
4
2
 
5
3
  var master = require('./MasterControl');
6
4
  var tools = require('./MasterTools');
@@ -86,6 +84,14 @@ const path = require('path')
86
84
  }
87
85
  };
88
86
 
87
+ var loadScopedListClasses = function(){
88
+ for (var key in master._scopedList) {
89
+ var className = master._scopedList[key];
90
+ master.requestList[key] = new className();
91
+ };
92
+ };
93
+
94
+
89
95
  class MasterRouter {
90
96
  currentRouteName = null
91
97
  _routes = {}
@@ -128,7 +134,7 @@ class MasterRouter {
128
134
 
129
135
  var route = {
130
136
  type: type.toLowerCase(),
131
- path: path.replace(/^\/|\/$/g, ''),
137
+ path: path.replace(/^\/|\/$/g, '').toLowerCase(),
132
138
  toController :pathList[0].replace(/^\/|\/$/g, ''),
133
139
  toAction: pathList[1],
134
140
  constraint : constraint
@@ -140,10 +146,10 @@ class MasterRouter {
140
146
 
141
147
  resources: function(routeName){ // function to add to list of routes using resources bulk
142
148
 
143
-
149
+
144
150
  $that._routes[$that.currentRouteName].routes.push({
145
151
  type: "get",
146
- path: routeName,
152
+ path: routeName.toLowerCase(),
147
153
  toController :routeName,
148
154
  toAction: "index",
149
155
  constraint : null
@@ -151,7 +157,7 @@ class MasterRouter {
151
157
 
152
158
  $that._routes[$that.currentRouteName].routes.push({
153
159
  type: "get",
154
- path: routeName,
160
+ path: routeName.toLowerCase(),
155
161
  toController :routeName,
156
162
  toAction: "new",
157
163
  constraint : null
@@ -159,7 +165,7 @@ class MasterRouter {
159
165
 
160
166
  $that._routes[$that.currentRouteName].routes.push({
161
167
  type: "post",
162
- path: routeName,
168
+ path: routeName.toLowerCase(),
163
169
  toController :routeName,
164
170
  toAction: "create",
165
171
  constraint : null
@@ -168,7 +174,7 @@ class MasterRouter {
168
174
  $that._routes[$that.currentRouteName].routes.push({
169
175
  // pages/3
170
176
  type: "get",
171
- path: routeName + "/:id",
177
+ path: routeName.toLowerCase() + "/:id",
172
178
  toController :routeName,
173
179
  toAction: "show",
174
180
  constraint : null
@@ -176,7 +182,7 @@ class MasterRouter {
176
182
 
177
183
  $that._routes[$that.currentRouteName].routes.push({
178
184
  type: "get",
179
- path: routeName + "/:id/" + "edit",
185
+ path: routeName.toLowerCase() + "/:id/" + "edit",
180
186
  toController :routeName,
181
187
  toAction: "edit",
182
188
  constraint : null
@@ -184,7 +190,7 @@ class MasterRouter {
184
190
 
185
191
  $that._routes[$that.currentRouteName].routes.push({
186
192
  type: "put",
187
- path: routeName + "/:id",
193
+ path: routeName.toLowerCase() + "/:id",
188
194
  toController :routeName,
189
195
  toAction: "update",
190
196
  constraint : null
@@ -192,7 +198,7 @@ class MasterRouter {
192
198
 
193
199
  $that._routes[$that.currentRouteName].routes.push({
194
200
  type: "delete",
195
- path: routeName + "/:id",
201
+ path: routeName.toLowerCase() + "/:id",
196
202
  toController :routeName,
197
203
  toAction: "destroy",
198
204
  constraint : null
@@ -236,8 +242,12 @@ class MasterRouter {
236
242
 
237
243
  _call(requestObject){
238
244
 
239
- tools.combineObjects(requestObject, master.requestList);
245
+ tools.combineObjects(master.requestList, requestObject);
246
+ requestObject = master.requestList;
240
247
  var Control = require(`${currentRoute.root}/app/controllers/${tools.firstLetterlowercase(requestObject.toController)}Controller`);
248
+ if(Control === null){
249
+ Control = require(`${currentRoute.root}/app/controllers/${tools.firstLetterUppercase(requestObject.toController)}Controller`);
250
+ }
241
251
  tools.combineObjectPrototype(Control, master.controllerList);
242
252
  Control.prototype.__namespace = Control.name;
243
253
  var control = new Control(requestObject);
@@ -260,9 +270,11 @@ class MasterRouter {
260
270
  }
261
271
 
262
272
  load(rr){ // load the the router
273
+
274
+ loadScopedListClasses();
263
275
  var $that = this;
264
276
  var requestObject = Object.create(rr);
265
- requestObject.pathName = requestObject.pathName.replace(/^\/|\/$/g, '');
277
+ requestObject.pathName = requestObject.pathName.replace(/^\/|\/$/g, '').toLowerCase();
266
278
 
267
279
  var _loadEmit = new EventEmitter();
268
280
 
package/package.json CHANGED
@@ -17,5 +17,5 @@
17
17
  "scripts": {
18
18
  "test": "echo \"Error: no test specified\" && exit 1"
19
19
  },
20
- "version": "1.1.14"
20
+ "version": "1.1.16"
21
21
  }