alchemymvc 1.3.0 → 1.3.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.
- package/lib/app/conduit/http_conduit.js +7 -2
- package/lib/app/conduit/socket_conduit.js +20 -5
- package/lib/app/controller/alchemy_info_controller.js +4 -8
- package/lib/app/helper/backed_map.js +2 -2
- package/lib/app/helper/router_helper.js +16 -7
- package/lib/app/helper_field/schema_field.js +44 -30
- package/lib/app/helper_model/document.js +40 -36
- package/lib/app/helper_model/model.js +72 -43
- package/lib/app/helper_validator/00_validator.js +38 -6
- package/lib/app/helper_validator/not_empty_validator.js +1 -3
- package/lib/app/routes.js +7 -1
- package/lib/class/conduit.js +207 -46
- package/lib/class/controller.js +18 -15
- package/lib/class/datasource.js +14 -7
- package/lib/class/field.js +21 -3
- package/lib/class/migration.js +2 -1
- package/lib/class/model.js +12 -1
- package/lib/class/postponement.js +593 -0
- package/lib/class/route.js +18 -2
- package/lib/class/router.js +6 -2
- package/lib/class/schema.js +36 -0
- package/lib/class/schema_client.js +16 -19
- package/lib/class/session.js +138 -12
- package/lib/core/base.js +7 -1
- package/lib/core/client_alchemy.js +3 -1
- package/lib/core/client_base.js +7 -2
- package/lib/init/alchemy.js +150 -2
- package/lib/init/functions.js +30 -4
- package/lib/init/requirements.js +4 -2
- package/lib/stages.js +18 -3
- package/package.json +4 -4
|
@@ -152,12 +152,16 @@ Schema.setProperty(function has_translatable_fields() {
|
|
|
152
152
|
*
|
|
153
153
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
154
154
|
* @since 1.1.3
|
|
155
|
-
* @version 1.1
|
|
155
|
+
* @version 1.3.1
|
|
156
156
|
*
|
|
157
157
|
* @return {Object}
|
|
158
158
|
*/
|
|
159
|
-
Schema.setMethod(function dryClone() {
|
|
160
|
-
|
|
159
|
+
Schema.setMethod(function dryClone(wm, custom_method) {
|
|
160
|
+
|
|
161
|
+
let obj = JSON.toDryObject(this),
|
|
162
|
+
cloned = JSON.undry(obj);
|
|
163
|
+
|
|
164
|
+
return cloned;
|
|
161
165
|
});
|
|
162
166
|
|
|
163
167
|
/**
|
|
@@ -166,16 +170,12 @@ Schema.setMethod(function dryClone() {
|
|
|
166
170
|
*
|
|
167
171
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
168
172
|
* @since 1.1.3
|
|
169
|
-
* @version 1.1
|
|
173
|
+
* @version 1.3.1
|
|
170
174
|
*
|
|
171
175
|
* @return {Object}
|
|
172
176
|
*/
|
|
173
177
|
Schema.setMethod(function clone() {
|
|
174
|
-
|
|
175
|
-
let obj = JSON.toDryObject(this),
|
|
176
|
-
cloned = JSON.undry(obj);
|
|
177
|
-
|
|
178
|
-
return cloned;
|
|
178
|
+
return this.dryClone();
|
|
179
179
|
});
|
|
180
180
|
|
|
181
181
|
/**
|
|
@@ -183,7 +183,7 @@ Schema.setMethod(function clone() {
|
|
|
183
183
|
*
|
|
184
184
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
185
185
|
* @since 1.1.0
|
|
186
|
-
* @version 1.3.
|
|
186
|
+
* @version 1.3.1
|
|
187
187
|
*
|
|
188
188
|
* @return {Object}
|
|
189
189
|
*/
|
|
@@ -210,10 +210,6 @@ Schema.setMethod(function toDry() {
|
|
|
210
210
|
value.rules.set(key, entry);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
if (this.parent) {
|
|
214
|
-
value.parent = this.parent;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
213
|
if (this.model_name) {
|
|
218
214
|
value.model_name = this.model_name;
|
|
219
215
|
|
|
@@ -224,24 +220,25 @@ Schema.setMethod(function toDry() {
|
|
|
224
220
|
|
|
225
221
|
value.options = this.options;
|
|
226
222
|
|
|
223
|
+
let result = {value};
|
|
224
|
+
|
|
227
225
|
// Get the sorted fields
|
|
228
|
-
let
|
|
229
|
-
fields = this.getSorted(false),
|
|
226
|
+
let fields = this.getSorted(false),
|
|
230
227
|
field,
|
|
231
228
|
i;
|
|
232
|
-
|
|
229
|
+
|
|
233
230
|
for (i = 0; i < fields.length; i++) {
|
|
234
231
|
field = fields[i];
|
|
235
232
|
|
|
236
233
|
value.fields.push({
|
|
237
234
|
name : field.name,
|
|
238
|
-
options : field.
|
|
235
|
+
options : field.getOptionsForDrying(),
|
|
239
236
|
class_name : field.constructor.name,
|
|
240
237
|
namespace : field.constructor.namespace,
|
|
241
238
|
});
|
|
242
239
|
}
|
|
243
240
|
|
|
244
|
-
return
|
|
241
|
+
return result;
|
|
245
242
|
});
|
|
246
243
|
|
|
247
244
|
/**
|
package/lib/class/session.js
CHANGED
|
@@ -5,7 +5,7 @@ var data_listeners = alchemy.shared('data_binding_listeners');
|
|
|
5
5
|
*
|
|
6
6
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
7
7
|
* @since 0.2.0
|
|
8
|
-
* @version 1.1
|
|
8
|
+
* @version 1.3.1
|
|
9
9
|
*
|
|
10
10
|
* @param {Conduit} conduit The initializing conduit
|
|
11
11
|
*/
|
|
@@ -36,10 +36,19 @@ var Session = Function.inherits('Alchemy.Base', function ClientSession(conduit)
|
|
|
36
36
|
this.data_listener_ids = {};
|
|
37
37
|
|
|
38
38
|
// Postponed requests
|
|
39
|
-
this.
|
|
39
|
+
this.postponements = new Classes.Develry.Cache();
|
|
40
|
+
|
|
41
|
+
// Postponed requests are invalidated after 3 hours
|
|
42
|
+
this.postponements.max_age = 3 * 60 * 60 * 1000;
|
|
43
|
+
|
|
44
|
+
// Time spent in the queue
|
|
45
|
+
this.queued_time = 0;
|
|
40
46
|
|
|
41
|
-
//
|
|
42
|
-
this.
|
|
47
|
+
// Any postponements that have happened already
|
|
48
|
+
this.postponement_counter = 0;
|
|
49
|
+
|
|
50
|
+
// The amount of renders that have happened during this session
|
|
51
|
+
this.render_counter = 0;
|
|
43
52
|
|
|
44
53
|
// Increment the alchemy session count
|
|
45
54
|
alchemy.session_count++;
|
|
@@ -103,6 +112,56 @@ Session.setProperty(function idle_time() {
|
|
|
103
112
|
return result;
|
|
104
113
|
});
|
|
105
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Is this an active session?
|
|
117
|
+
* When no activity happens for 5 minutes, the session becomes inactive.
|
|
118
|
+
*
|
|
119
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
120
|
+
* @since 1.3.1
|
|
121
|
+
* @version 1.3.1
|
|
122
|
+
*
|
|
123
|
+
* @type {Boolean}
|
|
124
|
+
*/
|
|
125
|
+
Session.setProperty(function is_active() {
|
|
126
|
+
|
|
127
|
+
if (this.idle_time < 5 * 60 * 1000) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return false;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Add the amount of time this client has been in the queue
|
|
136
|
+
*
|
|
137
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
138
|
+
* @since 1.3.1
|
|
139
|
+
* @version 1.3.1
|
|
140
|
+
*
|
|
141
|
+
* @return {Boolean}
|
|
142
|
+
*/
|
|
143
|
+
Session.setMethod(function addFinishedQueueDuration(ms) {
|
|
144
|
+
this.queued_time += ms;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Has this client already been in the queue?
|
|
149
|
+
*
|
|
150
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
151
|
+
* @since 1.3.1
|
|
152
|
+
* @version 1.3.1
|
|
153
|
+
*
|
|
154
|
+
* @return {Boolean}
|
|
155
|
+
*/
|
|
156
|
+
Session.setMethod(function hasAlreadyQueued() {
|
|
157
|
+
|
|
158
|
+
if (this.queued_time > 0) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return false;
|
|
163
|
+
});
|
|
164
|
+
|
|
106
165
|
/**
|
|
107
166
|
* Register a conduit
|
|
108
167
|
*
|
|
@@ -134,21 +193,84 @@ Session.setMethod(function createMenuItem(conduit) {
|
|
|
134
193
|
/**
|
|
135
194
|
* Postpone the result
|
|
136
195
|
*
|
|
137
|
-
* @author Jelle De Loecker <jelle@
|
|
196
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
138
197
|
* @since 0.2.0
|
|
139
|
-
* @version
|
|
198
|
+
* @version 1.3.1
|
|
140
199
|
*
|
|
141
200
|
* @param {Conduit} conduit The conduit to postpone
|
|
201
|
+
* @param {Object} options
|
|
142
202
|
*
|
|
143
|
-
* @return {
|
|
203
|
+
* @return {Alchemy.Conduit.Postponement} The postponement
|
|
204
|
+
*/
|
|
205
|
+
Session.setMethod(function postpone(conduit, options) {
|
|
206
|
+
|
|
207
|
+
let id = Crypto.uid();
|
|
208
|
+
|
|
209
|
+
let postponement = new Classes.Alchemy.Conduit.Postponement(conduit, id, options);
|
|
210
|
+
|
|
211
|
+
this.postponements.set(id, postponement);
|
|
212
|
+
|
|
213
|
+
this.postponement_counter++;
|
|
214
|
+
|
|
215
|
+
return postponement;
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Increment the render count
|
|
220
|
+
*
|
|
221
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
222
|
+
* @since 1.3.1
|
|
223
|
+
* @version 1.3.1
|
|
224
|
+
*
|
|
225
|
+
* @return {Number} The amount of renders
|
|
144
226
|
*/
|
|
145
|
-
Session.setMethod(function
|
|
227
|
+
Session.setMethod(function incrementRenderCount() {
|
|
228
|
+
return ++this.render_counter;
|
|
229
|
+
});
|
|
146
230
|
|
|
147
|
-
|
|
231
|
+
/**
|
|
232
|
+
* Get a postponement by its id
|
|
233
|
+
*
|
|
234
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
235
|
+
* @since 1.3.1
|
|
236
|
+
* @version 1.3.1
|
|
237
|
+
*
|
|
238
|
+
* @param {String} id The postponement id
|
|
239
|
+
*
|
|
240
|
+
* @return {Alchemy.Conduit.Postponement} The postponement
|
|
241
|
+
*/
|
|
242
|
+
Session.setMethod(function getPostponement(id) {
|
|
243
|
+
return this.postponements.get(id);
|
|
244
|
+
});
|
|
148
245
|
|
|
149
|
-
|
|
246
|
+
/**
|
|
247
|
+
* See if a postponement already exists for the given conduit
|
|
248
|
+
*
|
|
249
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
250
|
+
* @since 1.3.1
|
|
251
|
+
* @version 1.3.1
|
|
252
|
+
*
|
|
253
|
+
* @param {Conduit} conduit
|
|
254
|
+
*
|
|
255
|
+
* @return {Alchemy.Conduit.Postponement} The postponement
|
|
256
|
+
*/
|
|
257
|
+
Session.setMethod(function getExistingPostponement(conduit) {
|
|
258
|
+
|
|
259
|
+
if (!this.postponement_counter) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (!this.postponements.length) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
150
266
|
|
|
151
|
-
|
|
267
|
+
let postponement;
|
|
268
|
+
|
|
269
|
+
for (postponement of this.postponements) {
|
|
270
|
+
if (postponement.original_path === conduit.path) {
|
|
271
|
+
return postponement;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
152
274
|
});
|
|
153
275
|
|
|
154
276
|
/**
|
|
@@ -156,7 +278,7 @@ Session.setMethod(function postpone(conduit) {
|
|
|
156
278
|
*
|
|
157
279
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
158
280
|
* @since 0.2.0
|
|
159
|
-
* @version 1.1
|
|
281
|
+
* @version 1.3.1
|
|
160
282
|
*
|
|
161
283
|
* @param {Boolean} expired True if removed because time ran out
|
|
162
284
|
*/
|
|
@@ -180,6 +302,10 @@ Session.setMethod(function removed(expired) {
|
|
|
180
302
|
this.menu_item.remove();
|
|
181
303
|
}
|
|
182
304
|
|
|
305
|
+
for (let postponement of this.postponements) {
|
|
306
|
+
postponement.expire();
|
|
307
|
+
}
|
|
308
|
+
|
|
183
309
|
this.emit('removed', expired);
|
|
184
310
|
});
|
|
185
311
|
|
package/lib/core/base.js
CHANGED
|
@@ -717,4 +717,10 @@ Base.setMethod(function debugMark(message) {
|
|
|
717
717
|
*/
|
|
718
718
|
alchemy.getClassGroup = __Protoblast.getGroup;
|
|
719
719
|
|
|
720
|
-
// PROTOBLAST END CUT
|
|
720
|
+
// PROTOBLAST END CUT
|
|
721
|
+
|
|
722
|
+
// @TODO: put this somewhere else
|
|
723
|
+
if (Blast.isBrowser) {
|
|
724
|
+
window.Types = Blast.Types;
|
|
725
|
+
window.Classes = Blast.Classes;
|
|
726
|
+
}
|
|
@@ -133,7 +133,7 @@ Alchemy.setMethod(function initScene(scene, options) {
|
|
|
133
133
|
*
|
|
134
134
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
135
135
|
* @since 1.3.0
|
|
136
|
-
* @version 1.3.
|
|
136
|
+
* @version 1.3.1
|
|
137
137
|
*
|
|
138
138
|
* @param {String} id
|
|
139
139
|
* @param {String} message
|
|
@@ -167,6 +167,8 @@ Alchemy.setMethod(function distinctProblem(id, message, options = {}) {
|
|
|
167
167
|
|
|
168
168
|
if (now >= wait_until) {
|
|
169
169
|
do_log = true;
|
|
170
|
+
} else {
|
|
171
|
+
do_log = false;
|
|
170
172
|
}
|
|
171
173
|
} else {
|
|
172
174
|
do_log = false;
|
package/lib/core/client_base.js
CHANGED
|
@@ -294,7 +294,7 @@ ClientBase.setMethod(function getModel(name, init, options) {
|
|
|
294
294
|
*
|
|
295
295
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
296
296
|
* @since 1.1.1
|
|
297
|
-
* @version 1.3.
|
|
297
|
+
* @version 1.3.2
|
|
298
298
|
*
|
|
299
299
|
* @param {String} name The name of the event to emit
|
|
300
300
|
* @param {Array} args The parameters to pass to the event
|
|
@@ -330,7 +330,12 @@ ClientBase.setMethod(function issueEvent(name, args, next) {
|
|
|
330
330
|
|
|
331
331
|
if (err) {
|
|
332
332
|
pledge.reject(err);
|
|
333
|
-
|
|
333
|
+
|
|
334
|
+
if (next) {
|
|
335
|
+
next(err);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return;
|
|
334
339
|
}
|
|
335
340
|
|
|
336
341
|
if (result !== false) {
|
package/lib/init/alchemy.js
CHANGED
|
@@ -9,7 +9,8 @@ var shared_objects = {},
|
|
|
9
9
|
parseArgs = require('minimist'),
|
|
10
10
|
libpath = require('path'),
|
|
11
11
|
colors = require('ansi-256-colors'),
|
|
12
|
-
fs = require('fs')
|
|
12
|
+
fs = require('fs'),
|
|
13
|
+
os = require('os');
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* The Alchemy class
|
|
@@ -60,6 +61,9 @@ global.Alchemy = Function.inherits('Informer', 'Alchemy', function Alchemy() {
|
|
|
60
61
|
// Link to failed modules
|
|
61
62
|
this.modules_error = useErrors;
|
|
62
63
|
|
|
64
|
+
// How many CPUs are available?
|
|
65
|
+
this.cpu_core_count = os.cpus().length;
|
|
66
|
+
|
|
63
67
|
// Try getting the app package.json file
|
|
64
68
|
try {
|
|
65
69
|
package_json = require(libpath.resolve(PATH_ROOT, 'package.json'));
|
|
@@ -86,6 +90,9 @@ global.Alchemy = Function.inherits('Informer', 'Alchemy', function Alchemy() {
|
|
|
86
90
|
// All caches
|
|
87
91
|
this.caches = {};
|
|
88
92
|
|
|
93
|
+
// Extra toobusy checks
|
|
94
|
+
this.extra_toobusy_checks = [];
|
|
95
|
+
|
|
89
96
|
// Also store the version in the process versions object
|
|
90
97
|
process.versions.alchemy = this.version;
|
|
91
98
|
|
|
@@ -214,12 +221,142 @@ Alchemy.setProperty(function environment() {
|
|
|
214
221
|
return alchemy.settings.environment;
|
|
215
222
|
});
|
|
216
223
|
|
|
224
|
+
/**
|
|
225
|
+
* Get the current lag in ms
|
|
226
|
+
*
|
|
227
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
228
|
+
* @since 1.3.1
|
|
229
|
+
* @version 1.3.1
|
|
230
|
+
*
|
|
231
|
+
* @return {Number}
|
|
232
|
+
*/
|
|
233
|
+
Alchemy.setMethod(function lagInMs() {
|
|
234
|
+
return this.toobusy.lag();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Get the system load as percentage points
|
|
239
|
+
*
|
|
240
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
241
|
+
* @since 1.3.1
|
|
242
|
+
* @version 1.3.1
|
|
243
|
+
*
|
|
244
|
+
* @return {Number}
|
|
245
|
+
*/
|
|
246
|
+
Alchemy.setMethod(function systemLoad() {
|
|
247
|
+
|
|
248
|
+
let load_average = os.loadavg();
|
|
249
|
+
|
|
250
|
+
const percentage = ~~((load_average[0] / this.cpu_core_count) * 100);
|
|
251
|
+
|
|
252
|
+
return percentage;
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Register an extra toobusy check method.
|
|
257
|
+
* These will be checked after event loop lag & system load are deemed OK.
|
|
258
|
+
*
|
|
259
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
260
|
+
* @since 1.3.2
|
|
261
|
+
* @version 1.3.2
|
|
262
|
+
*/
|
|
263
|
+
Alchemy.setMethod(function addToobusyCheck(fnc) {
|
|
264
|
+
this.extra_toobusy_checks.push(fnc);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Is the server currently too busy, overloaded in some way?
|
|
269
|
+
*
|
|
270
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
271
|
+
* @since 1.3.1
|
|
272
|
+
* @version 1.3.2
|
|
273
|
+
*
|
|
274
|
+
* @return {Boolean}
|
|
275
|
+
*/
|
|
276
|
+
Alchemy.setMethod(function isTooBusy() {
|
|
277
|
+
|
|
278
|
+
// First check if it's too busy because of event loop lag
|
|
279
|
+
if (this.toobusy()) {
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (this.settings.max_system_load > 0) {
|
|
284
|
+
// Then check the load average
|
|
285
|
+
if (this.systemLoad() > this.settings.max_system_load) {
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (this.extra_toobusy_checks.length > 0) {
|
|
291
|
+
|
|
292
|
+
for (let fnc of this.extra_toobusy_checks) {
|
|
293
|
+
try {
|
|
294
|
+
if (fnc()) {
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
} catch (err) {
|
|
298
|
+
alchemy.distinctProblem('error-extra-toobusy-check', 'Extra toobusy check failed', {error: err});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return false;
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Is the server too busy for requests?
|
|
308
|
+
*
|
|
309
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
310
|
+
* @since 1.3.1
|
|
311
|
+
* @version 1.3.1
|
|
312
|
+
*
|
|
313
|
+
* @return {Boolean}
|
|
314
|
+
*/
|
|
315
|
+
Alchemy.setMethod(function isTooBusyForRequests() {
|
|
316
|
+
|
|
317
|
+
// If a queue already exists, the server's lag might be quite good
|
|
318
|
+
// BECAUSE requests are being queued.
|
|
319
|
+
if (Classes.Alchemy.Conduit.Postponement.queue_length > 5) {
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return this.isTooBusy();
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Is the server too busy for AJAX too?
|
|
328
|
+
*
|
|
329
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
330
|
+
* @since 1.3.1
|
|
331
|
+
* @version 1.3.2
|
|
332
|
+
*
|
|
333
|
+
* @return {Boolean}
|
|
334
|
+
*/
|
|
335
|
+
Alchemy.setMethod(function isTooBusyForAjax() {
|
|
336
|
+
|
|
337
|
+
if (!this.isTooBusyForRequests()) {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
let lag = this.lagInMs();
|
|
342
|
+
|
|
343
|
+
let max_event_loop_lag = alchemy.settings.max_event_loop_lag || alchemy.settings.toobusy;
|
|
344
|
+
|
|
345
|
+
if (max_event_loop_lag) {
|
|
346
|
+
if (lag > (max_event_loop_lag * 3)) {
|
|
347
|
+
return true;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return false;
|
|
352
|
+
});
|
|
353
|
+
|
|
217
354
|
/**
|
|
218
355
|
* Start janeway
|
|
219
356
|
*
|
|
220
357
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
221
358
|
* @since 0.5.0
|
|
222
|
-
* @version 1.
|
|
359
|
+
* @version 1.3.1
|
|
223
360
|
*
|
|
224
361
|
* @param {Object} options
|
|
225
362
|
*/
|
|
@@ -301,6 +438,17 @@ Alchemy.setMethod(function startJaneway(options) {
|
|
|
301
438
|
this.Janeway.session_menu = session_menu;
|
|
302
439
|
}
|
|
303
440
|
|
|
441
|
+
if (this.settings.lag_menu) {
|
|
442
|
+
let lag_menu = this.Janeway.addIndicator('0 ms');
|
|
443
|
+
|
|
444
|
+
setInterval(() => {
|
|
445
|
+
lag_menu.setIcon(this.lagInMs() + ' ms');
|
|
446
|
+
this.Janeway.redraw();
|
|
447
|
+
}, 900).unref();
|
|
448
|
+
|
|
449
|
+
this.Janeway.lag_menu = lag_menu;
|
|
450
|
+
}
|
|
451
|
+
|
|
304
452
|
});
|
|
305
453
|
|
|
306
454
|
/**
|
package/lib/init/functions.js
CHANGED
|
@@ -1344,24 +1344,47 @@ Alchemy.setMethod(function exposeStatic(name, value) {
|
|
|
1344
1344
|
/**
|
|
1345
1345
|
* Expose the default static variables
|
|
1346
1346
|
*
|
|
1347
|
-
* @author Jelle De Loecker <jelle@
|
|
1347
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1348
1348
|
* @since 1.1.0
|
|
1349
|
-
* @version 1.
|
|
1349
|
+
* @version 1.3.1
|
|
1350
1350
|
*/
|
|
1351
1351
|
Alchemy.setMethod(function exposeDefaultStaticVariables() {
|
|
1352
1352
|
|
|
1353
|
-
let model_info =
|
|
1353
|
+
let model_info = [],
|
|
1354
|
+
model_code = '',
|
|
1354
1355
|
hawkejs = alchemy.hawkejs,
|
|
1355
1356
|
models = Model.getAllChildren(),
|
|
1357
|
+
info,
|
|
1356
1358
|
i;
|
|
1357
1359
|
|
|
1358
1360
|
for (i = 0; i < models.length; i++) {
|
|
1359
|
-
|
|
1361
|
+
info = models[i].getClientConfig();
|
|
1362
|
+
model_info.push(info);
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
// Sort the models by their ancestor count
|
|
1366
|
+
model_info.sortByPath(1, 'ancestors');
|
|
1367
|
+
|
|
1368
|
+
model_code = `function inheritModel(parent, child) {
|
|
1369
|
+
return Classes.Hawkejs.Model.getClass(child, true, parent);
|
|
1370
|
+
}\n`;
|
|
1371
|
+
|
|
1372
|
+
for (let info of model_info) {
|
|
1373
|
+
model_code += 'inheritModel(' + JSON.stringify(info.parent) + ', ' + JSON.stringify(info.name) + ')\n';
|
|
1360
1374
|
}
|
|
1361
1375
|
|
|
1362
1376
|
// Expose the model configuration
|
|
1363
1377
|
hawkejs.exposeStatic('model_info', model_info);
|
|
1364
1378
|
|
|
1379
|
+
Blast.require('client_models', {
|
|
1380
|
+
after : 'helper_model/model',
|
|
1381
|
+
resolver : async function getExportedFunction() {
|
|
1382
|
+
return model_code;
|
|
1383
|
+
},
|
|
1384
|
+
client : true,
|
|
1385
|
+
server : false,
|
|
1386
|
+
});
|
|
1387
|
+
|
|
1365
1388
|
this.exposeRouteData();
|
|
1366
1389
|
|
|
1367
1390
|
// Expose breadcrumb info
|
|
@@ -1377,6 +1400,9 @@ Alchemy.setMethod(function exposeDefaultStaticVariables() {
|
|
|
1377
1400
|
hawkejs.exposeStatic('enable_websockets', true);
|
|
1378
1401
|
}
|
|
1379
1402
|
|
|
1403
|
+
// Expose the layout settings
|
|
1404
|
+
hawkejs.exposeStatic('alchemy_layout', alchemy.settings.layout);
|
|
1405
|
+
|
|
1380
1406
|
let app_version = alchemy.package.version;
|
|
1381
1407
|
|
|
1382
1408
|
// The current app version
|
package/lib/init/requirements.js
CHANGED
|
@@ -57,9 +57,11 @@ alchemy.hawkejs = Classes.Hawkejs.Hawkejs.getInstance();
|
|
|
57
57
|
*/
|
|
58
58
|
alchemy.toobusy = alchemy.use('toobusy-js', 'toobusy');
|
|
59
59
|
|
|
60
|
+
let max_event_loop_lag = alchemy.settings.max_event_loop_lag || alchemy.settings.toobusy;
|
|
61
|
+
|
|
60
62
|
// If the config is a number, use that as the lag threshold
|
|
61
|
-
if (typeof
|
|
62
|
-
alchemy.toobusy.maxLag(
|
|
63
|
+
if (typeof max_event_loop_lag === 'number') {
|
|
64
|
+
alchemy.toobusy.maxLag(max_event_loop_lag);
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
/**
|
package/lib/stages.js
CHANGED
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
* @since 0.0.1
|
|
14
14
|
* @version 1.1.0
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
let path = alchemy.modules.path,
|
|
17
17
|
settings = alchemy.settings,
|
|
18
18
|
http = alchemy.modules.http,
|
|
19
19
|
hawkejs = alchemy.hawkejs,
|
|
20
|
-
fs = alchemy.use('fs')
|
|
20
|
+
fs = alchemy.use('fs'),
|
|
21
|
+
total_http_requests = 0;
|
|
21
22
|
|
|
22
23
|
if (alchemy.settings.debug) {
|
|
23
24
|
alchemy.sputnik.on('launching', function onLaunch(stage) {
|
|
@@ -38,13 +39,26 @@ if (alchemy.settings.debug) {
|
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Add a getter for the total amount of http requests
|
|
44
|
+
*
|
|
45
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
46
|
+
* @since 1.3.1
|
|
47
|
+
* @version 1.3.1
|
|
48
|
+
*
|
|
49
|
+
* @type {Number}
|
|
50
|
+
*/
|
|
51
|
+
Alchemy.setProperty(function http_request_counter() {
|
|
52
|
+
return total_http_requests;
|
|
53
|
+
});
|
|
54
|
+
|
|
41
55
|
/**
|
|
42
56
|
* The "http" stage:
|
|
43
57
|
* Create the server and listen to requests
|
|
44
58
|
*
|
|
45
59
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
46
60
|
* @since 0.0.1
|
|
47
|
-
* @version 1.1
|
|
61
|
+
* @version 1.3.1
|
|
48
62
|
*/
|
|
49
63
|
alchemy.sputnik.add(function http() {
|
|
50
64
|
|
|
@@ -54,6 +68,7 @@ alchemy.sputnik.add(function http() {
|
|
|
54
68
|
// Listen for requests
|
|
55
69
|
alchemy.server.on('request', function onRequest(request, response) {
|
|
56
70
|
Router.resolve(request, response);
|
|
71
|
+
total_http_requests++;
|
|
57
72
|
});
|
|
58
73
|
});
|
|
59
74
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alchemymvc",
|
|
3
3
|
"description": "MVC framework for Node.js",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.2",
|
|
5
5
|
"author": "Jelle De Loecker <jelle@elevenways.be>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"alchemy",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"chokidar" : "~3.5.3",
|
|
23
23
|
"formidable" : "~2.0.1",
|
|
24
24
|
"graceful-fs" : "~4.2.9",
|
|
25
|
-
"hawkejs" : "~2.2
|
|
25
|
+
"hawkejs" : "~2.3.2",
|
|
26
26
|
"jsondiffpatch" : "~0.4.1",
|
|
27
27
|
"mime" : "~3.0.0",
|
|
28
28
|
"minimist" : "~1.2.5",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"mongodb" : "~3.6.6",
|
|
32
32
|
"ncp" : "~2.0.0",
|
|
33
33
|
"postcss" : "~8.4.6",
|
|
34
|
-
"protoblast" : "~0.
|
|
34
|
+
"protoblast" : "~0.8.2",
|
|
35
35
|
"semver" : "~7.3.5",
|
|
36
36
|
"socket.io" : "~2.4.0",
|
|
37
37
|
"@11ways/socket.io-stream" : "~0.9.2",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"index.js"
|
|
46
46
|
],
|
|
47
47
|
"optionalDependencies": {
|
|
48
|
-
"janeway" : "~0.
|
|
48
|
+
"janeway" : "~0.4.0",
|
|
49
49
|
"less" : "~4.1.1",
|
|
50
50
|
"sass" : "~1.53.0",
|
|
51
51
|
"sass-embedded" : "~1.53.0",
|