alchemymvc 1.3.21 → 1.4.0-alpha.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.
- package/LICENSE +1 -1
- package/README.md +3 -3
- package/lib/app/behaviour/publishable_behaviour.js +5 -5
- package/lib/app/behaviour/revision_behaviour.js +10 -10
- package/lib/app/behaviour/sluggable_behaviour.js +14 -14
- package/lib/app/conduit/electron_conduit.js +9 -9
- package/lib/app/conduit/http_conduit.js +13 -13
- package/lib/app/conduit/loopback_conduit.js +15 -15
- package/lib/app/conduit/socket_conduit.js +43 -43
- package/lib/app/config/routes.js +26 -0
- package/lib/app/controller/00-default_app_controller.js +21 -0
- package/lib/app/controller/alchemy_info_controller.js +12 -12
- package/lib/app/datasource/mongo_datasource.js +16 -16
- package/lib/app/element/00-default_app_element.js +19 -0
- package/lib/app/element/time_ago.js +5 -5
- package/lib/app/helper/00-default_app_helper.js +11 -0
- package/lib/app/helper/alchemy_helper.js +22 -22
- package/lib/app/helper/backed_map.js +1 -1
- package/lib/app/helper/breadcrumb.js +10 -10
- package/lib/app/helper/client_collection.js +3 -3
- package/lib/app/helper/cron.js +29 -29
- package/lib/app/helper/enum_values.js +6 -6
- package/lib/app/helper/pagination_helper.js +36 -36
- package/lib/app/helper/router_helper.js +35 -35
- package/lib/app/helper/socket_helper.js +57 -57
- package/lib/app/helper/syncable.js +84 -59
- package/lib/app/helper_component/paginate_component.js +9 -9
- package/lib/app/helper_controller/component.js +1 -1
- package/lib/app/helper_controller/conduit.js +31 -31
- package/lib/app/helper_controller/controller.js +54 -39
- package/lib/app/helper_datasource/00-nosql_datasource.js +624 -70
- package/lib/app/helper_datasource/05-fallback_datasource.js +10 -10
- package/lib/app/helper_datasource/idb_datasource.js +6 -6
- package/lib/app/helper_datasource/indexed_db.js +22 -22
- package/lib/app/helper_datasource/remote_datasource.js +5 -5
- package/lib/app/helper_error/http_error.js +4 -4
- package/lib/app/helper_error/model_error.js +2 -2
- package/lib/app/helper_error/validation_error.js +12 -12
- package/lib/app/helper_field/00-objectid_field.js +7 -7
- package/lib/app/helper_field/05-string_field.js +16 -12
- package/lib/app/helper_field/06-text_field.js +2 -4
- package/lib/app/helper_field/10-number_field.js +9 -12
- package/lib/app/helper_field/11-date_field.js +15 -15
- package/lib/app/helper_field/15-local_temporal_field.js +10 -10
- package/lib/app/helper_field/20-decimal_field.js +8 -9
- package/lib/app/helper_field/belongsto_field.js +1 -1
- package/lib/app/helper_field/big_int_field.js +8 -8
- package/lib/app/helper_field/boolean_field.js +9 -11
- package/lib/app/helper_field/datetime_field.js +3 -3
- package/lib/app/helper_field/enum_field.js +13 -8
- package/lib/app/helper_field/fixed_decimal_field.js +6 -7
- package/lib/app/helper_field/geopoint_field.js +9 -10
- package/lib/app/helper_field/habtm_field.js +3 -3
- package/lib/app/helper_field/hasoneparent_field.js +1 -1
- package/lib/app/helper_field/html_field.js +2 -4
- package/lib/app/helper_field/integer_field.js +8 -11
- package/lib/app/helper_field/local_date_field.js +5 -5
- package/lib/app/helper_field/local_date_time_field.js +5 -5
- package/lib/app/helper_field/local_time_field.js +5 -5
- package/lib/app/helper_field/mixed_field.js +5 -5
- package/lib/app/helper_field/object_field.js +8 -8
- package/lib/app/helper_field/password_field.js +3 -3
- package/lib/app/helper_field/regexp_field.js +7 -9
- package/lib/app/helper_field/schema_field.js +91 -88
- package/lib/app/helper_field/settings_field.js +92 -0
- package/lib/app/helper_field/time_field.js +6 -6
- package/lib/app/helper_field/url_field.js +2 -4
- package/lib/app/helper_model/00-base_criteria.js +662 -0
- package/lib/app/helper_model/05-criteria_expressions.js +605 -0
- package/lib/app/helper_model/10-model_criteria.js +1182 -0
- package/lib/app/helper_model/data_provider.js +2 -2
- package/lib/app/helper_model/document.js +103 -92
- package/lib/app/helper_model/document_list.js +14 -14
- package/lib/app/helper_model/field_config.js +11 -11
- package/lib/app/helper_model/field_set.js +17 -17
- package/lib/app/helper_model/model.js +203 -124
- package/lib/app/helper_model/remote_data_provider.js +2 -2
- package/lib/app/helper_validator/00_validator.js +16 -16
- package/lib/app/helper_validator/not_empty_validator.js +9 -9
- package/lib/app/model/00-default_app_model.js +18 -0
- package/lib/app/model/05-system_model.js +27 -0
- package/lib/app/model/{alchemy_migration_model.js → system_migration_model.js} +4 -4
- package/lib/app/model/system_setting_model.js +154 -0
- package/lib/app/model/{alchemy_task_history_model.js → system_task_history_model.js} +7 -7
- package/lib/app/model/{alchemy_task_model.js → system_task_model.js} +11 -11
- package/lib/bootstrap.js +22 -312
- package/lib/class/accumulator.js +5 -5
- package/lib/class/behaviour.js +5 -5
- package/lib/class/component.js +3 -3
- package/lib/class/conduit.js +203 -163
- package/lib/class/controller.js +42 -42
- package/lib/class/datasource.js +74 -79
- package/lib/class/document.js +74 -95
- package/lib/class/document_list.js +5 -5
- package/lib/class/element.js +17 -17
- package/lib/class/error.js +3 -3
- package/lib/class/field.js +169 -91
- package/lib/class/field_value.js +6 -6
- package/lib/class/helper.js +3 -3
- package/lib/class/inode.js +17 -17
- package/lib/class/inode_dir.js +12 -12
- package/lib/class/inode_file.js +50 -25
- package/lib/class/inode_list.js +4 -4
- package/lib/class/migration.js +4 -4
- package/lib/class/model.js +182 -168
- package/lib/class/path_definition.js +22 -22
- package/lib/class/path_evaluator.js +5 -5
- package/lib/class/path_param_definition.js +7 -7
- package/lib/class/plugin.js +312 -0
- package/lib/class/postponement.js +29 -29
- package/lib/class/reciprocal.js +8 -8
- package/lib/class/route.js +33 -33
- package/lib/class/router.js +73 -73
- package/lib/class/schema.js +21 -21
- package/lib/class/schema_client.js +73 -67
- package/lib/class/session.js +63 -29
- package/lib/class/session_scene.js +4 -4
- package/lib/class/sitemap.js +16 -16
- package/lib/class/task.js +39 -39
- package/lib/class/task_service.js +43 -47
- package/lib/{init → core}/alchemy.js +413 -374
- package/lib/{init/functions.js → core/alchemy_functions.js} +171 -108
- package/lib/core/alchemy_load_functions.js +715 -0
- package/lib/core/base.js +50 -62
- package/lib/core/client_alchemy.js +144 -152
- package/lib/core/client_base.js +39 -52
- package/lib/core/discovery.js +16 -18
- package/lib/core/middleware.js +54 -43
- package/lib/core/{routing.js → prefix.js} +14 -16
- package/lib/core/setting.js +1684 -0
- package/lib/core/stage.js +758 -0
- package/lib/scripts/create_constants.js +119 -0
- package/lib/{init/languages.js → scripts/create_languages.js} +5 -5
- package/lib/scripts/create_settings.js +449 -0
- package/lib/scripts/create_shared_constants.js +95 -0
- package/lib/scripts/create_stages.js +55 -0
- package/lib/scripts/init_alchemy.js +51 -0
- package/lib/{init/requirements.js → scripts/preload_modules.js} +15 -2
- package/lib/scripts/setup_devwatch.js +238 -0
- package/lib/stages/00-load_core.js +342 -0
- package/lib/stages/05-load_app.js +57 -0
- package/lib/stages/10-datasource.js +61 -0
- package/lib/stages/15-tasks.js +27 -0
- package/lib/stages/20-settings.js +68 -0
- package/lib/stages/50-routes.js +218 -0
- package/lib/stages/90-server.js +347 -0
- package/package.json +5 -7
- package/lib/app/helper_model/criteria.js +0 -2294
- package/lib/app/helper_model/db_query.js +0 -1488
- package/lib/app/routes.js +0 -11
- package/lib/core/socket.js +0 -171
- package/lib/init/constants.js +0 -158
- package/lib/init/devwatch.js +0 -238
- package/lib/init/load_functions.js +0 -973
- package/lib/stages.js +0 -513
package/lib/core/client_base.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Alchemy's Client Base class
|
|
5
3
|
*
|
|
6
|
-
* @author Jelle De Loecker
|
|
4
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
7
5
|
* @since 1.0.0
|
|
8
6
|
* @version 1.0.0
|
|
9
7
|
*/
|
|
10
|
-
|
|
8
|
+
const ClientBase = Function.inherits('Alchemy.Base', 'Alchemy.Client', function Base() {});
|
|
11
9
|
|
|
12
10
|
// PROTOBLAST START CUT
|
|
13
11
|
/**
|
|
14
12
|
* Get the server implementation of this class
|
|
15
13
|
*
|
|
16
|
-
* @author Jelle De Loecker <jelle@
|
|
14
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
17
15
|
* @since 1.0.0
|
|
18
16
|
* @version 1.1.2
|
|
19
17
|
*
|
|
@@ -45,7 +43,7 @@ ClientBase.setStatic(function getServerClass() {
|
|
|
45
43
|
*
|
|
46
44
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
47
45
|
* @since 1.1.2
|
|
48
|
-
* @version 1.
|
|
46
|
+
* @version 1.4.0
|
|
49
47
|
*
|
|
50
48
|
* @param {Function}
|
|
51
49
|
*/
|
|
@@ -63,7 +61,7 @@ ClientBase.setStatic(function callbackWithServerClass(callback) {
|
|
|
63
61
|
|
|
64
62
|
const that = this;
|
|
65
63
|
|
|
66
|
-
|
|
64
|
+
STAGES.afterStages('load_app.plugins', function loadedPlugins() {
|
|
67
65
|
|
|
68
66
|
server_class = that.getServerClass();
|
|
69
67
|
|
|
@@ -77,14 +75,14 @@ ClientBase.setStatic(function callbackWithServerClass(callback) {
|
|
|
77
75
|
/**
|
|
78
76
|
* Set a property
|
|
79
77
|
*
|
|
80
|
-
* @author Jelle De Loecker <jelle@
|
|
78
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
81
79
|
* @since 1.0.0
|
|
82
80
|
* @version 1.1.2
|
|
83
81
|
*
|
|
84
|
-
* @param {
|
|
82
|
+
* @param {string} key Name of the property
|
|
85
83
|
* @param {Function} getter Optional getter function
|
|
86
84
|
* @param {Function} setter Optional setter function
|
|
87
|
-
* @param {
|
|
85
|
+
* @param {boolean} on_server Also set on the server implementation
|
|
88
86
|
*/
|
|
89
87
|
ClientBase.setStatic(function setProperty(key, getter, setter, on_server) {
|
|
90
88
|
|
|
@@ -122,13 +120,13 @@ ClientBase.setStatic(function setProperty(key, getter, setter, on_server) {
|
|
|
122
120
|
/**
|
|
123
121
|
* Prepare a property
|
|
124
122
|
*
|
|
125
|
-
* @author Jelle De Loecker <jelle@
|
|
123
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
126
124
|
* @since 1.0.5
|
|
127
125
|
* @version 1.1.2
|
|
128
126
|
*
|
|
129
|
-
* @param {
|
|
127
|
+
* @param {string} key Name of the property
|
|
130
128
|
* @param {Function} getter Optional getter function
|
|
131
|
-
* @param {
|
|
129
|
+
* @param {boolean} on_server Also set on the server implementation
|
|
132
130
|
*/
|
|
133
131
|
ClientBase.setStatic(function prepareProperty(key, getter, on_server) {
|
|
134
132
|
|
|
@@ -161,13 +159,13 @@ ClientBase.setStatic(function prepareProperty(key, getter, on_server) {
|
|
|
161
159
|
/**
|
|
162
160
|
* Set a method
|
|
163
161
|
*
|
|
164
|
-
* @author Jelle De Loecker <jelle@
|
|
162
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
165
163
|
* @since 1.0.0
|
|
166
164
|
* @version 1.1.2
|
|
167
165
|
*
|
|
168
|
-
* @param {
|
|
166
|
+
* @param {string} key Name of the property
|
|
169
167
|
* @param {Function} method The method to set
|
|
170
|
-
* @param {
|
|
168
|
+
* @param {boolean} on_server Also set on the server implementation
|
|
171
169
|
*/
|
|
172
170
|
ClientBase.setStatic(function setMethod(key, method, on_server) {
|
|
173
171
|
|
|
@@ -195,12 +193,12 @@ ClientBase.setStatic(function setMethod(key, method, on_server) {
|
|
|
195
193
|
* @since 1.1.1
|
|
196
194
|
* @version 1.1.2
|
|
197
195
|
*
|
|
198
|
-
* @param {
|
|
199
|
-
* @param {
|
|
196
|
+
* @param {string} event_name
|
|
197
|
+
* @param {string} method_name
|
|
200
198
|
*/
|
|
201
199
|
ClientBase.setStatic(function mapEventToMethod(event_name, method_name) {
|
|
202
200
|
|
|
203
|
-
function
|
|
201
|
+
function addEventMap() {
|
|
204
202
|
|
|
205
203
|
if (!this.event_to_method_map) {
|
|
206
204
|
this.setStatic('event_to_method_map', new Map(), false);
|
|
@@ -219,11 +217,11 @@ ClientBase.setStatic(function mapEventToMethod(event_name, method_name) {
|
|
|
219
217
|
}
|
|
220
218
|
}
|
|
221
219
|
|
|
222
|
-
this.constitute(
|
|
220
|
+
this.constitute(addEventMap);
|
|
223
221
|
|
|
224
222
|
if (Blast.isNode) {
|
|
225
223
|
this.callbackWithServerClass(function gotClass(ServerClass) {
|
|
226
|
-
ServerClass.constitute(
|
|
224
|
+
ServerClass.constitute(addEventMap);
|
|
227
225
|
});
|
|
228
226
|
}
|
|
229
227
|
});
|
|
@@ -231,44 +229,23 @@ ClientBase.setStatic(function mapEventToMethod(event_name, method_name) {
|
|
|
231
229
|
/**
|
|
232
230
|
* Get a client model
|
|
233
231
|
*
|
|
234
|
-
* @author Jelle De Loecker
|
|
232
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
235
233
|
* @since 1.0.0
|
|
236
|
-
* @version 1.
|
|
234
|
+
* @version 1.4.0
|
|
237
235
|
*
|
|
238
|
-
* @param
|
|
239
|
-
* @param
|
|
236
|
+
* @param {string} name
|
|
237
|
+
* @param {Object} options
|
|
240
238
|
*
|
|
241
|
-
* @return
|
|
239
|
+
* @return {Model}
|
|
242
240
|
*/
|
|
243
241
|
ClientBase.setMethod(function getModel(name, init, options) {
|
|
244
242
|
|
|
245
|
-
var constructor,
|
|
246
|
-
instance;
|
|
247
|
-
|
|
248
243
|
if (typeof init != 'boolean') {
|
|
249
244
|
options = init;
|
|
250
245
|
init = true;
|
|
251
246
|
}
|
|
252
247
|
|
|
253
|
-
|
|
254
|
-
name = name.modelName();
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (Blast.isBrowser) {
|
|
258
|
-
|
|
259
|
-
if (name == '') {
|
|
260
|
-
constructor = Hawkejs.Model;
|
|
261
|
-
} else {
|
|
262
|
-
constructor = Hawkejs.Model.getClass(name, false);
|
|
263
|
-
}
|
|
264
|
-
} else {
|
|
265
|
-
|
|
266
|
-
if (name == '') {
|
|
267
|
-
constructor = Blast.Classes.Hawkejs.Model;
|
|
268
|
-
} else {
|
|
269
|
-
constructor = Blast.Classes.Hawkejs.Model.getClass(name);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
248
|
+
let constructor = Classes.Alchemy.Client.Model.Model.getClass(name);
|
|
272
249
|
|
|
273
250
|
if (!constructor) {
|
|
274
251
|
throw new Error('Model "' + name + '" could not be found');
|
|
@@ -278,7 +255,7 @@ ClientBase.setMethod(function getModel(name, init, options) {
|
|
|
278
255
|
return constructor;
|
|
279
256
|
}
|
|
280
257
|
|
|
281
|
-
instance = new constructor(options);
|
|
258
|
+
let instance = new constructor(options);
|
|
282
259
|
|
|
283
260
|
let conduit = this.conduit;
|
|
284
261
|
|
|
@@ -294,9 +271,9 @@ ClientBase.setMethod(function getModel(name, init, options) {
|
|
|
294
271
|
*
|
|
295
272
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
296
273
|
* @since 1.1.1
|
|
297
|
-
* @version 1.3.
|
|
274
|
+
* @version 1.3.22
|
|
298
275
|
*
|
|
299
|
-
* @param {
|
|
276
|
+
* @param {string} name The name of the event to emit
|
|
300
277
|
* @param {Array} args The parameters to pass to the event
|
|
301
278
|
* @param {Function} next The optional callback
|
|
302
279
|
*
|
|
@@ -323,7 +300,17 @@ ClientBase.setMethod(function issueEvent(name, args, next) {
|
|
|
323
300
|
}
|
|
324
301
|
|
|
325
302
|
if (method_name && typeof this[method_name] == 'function') {
|
|
326
|
-
|
|
303
|
+
try {
|
|
304
|
+
promise = this[method_name].apply(this, args);
|
|
305
|
+
} catch (err) {
|
|
306
|
+
pledge.reject(err);
|
|
307
|
+
|
|
308
|
+
if (next) {
|
|
309
|
+
next(err);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return pledge;
|
|
313
|
+
}
|
|
327
314
|
}
|
|
328
315
|
|
|
329
316
|
Pledge.done(promise, function doneEventPromise(err, result) {
|
package/lib/core/discovery.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
var bson = alchemy.use('bson'),
|
|
4
2
|
emitter = alchemy.use('events').EventEmitter,
|
|
5
3
|
maxSize = 65536,
|
|
6
4
|
mevents = new emitter(),
|
|
7
|
-
udpIp = alchemy.settings.multicast_ipv4,
|
|
5
|
+
udpIp = alchemy.settings.network.multicast_ipv4,
|
|
8
6
|
udpPort = 4002,
|
|
9
7
|
callbacks = {},
|
|
10
8
|
services = alchemy.shared('alchemy.services'),
|
|
@@ -18,7 +16,7 @@ var bson = alchemy.use('bson'),
|
|
|
18
16
|
/**
|
|
19
17
|
* Submit data
|
|
20
18
|
*
|
|
21
|
-
* @author Jelle De Loecker
|
|
19
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
22
20
|
* @since 0.1.0
|
|
23
21
|
* @version 0.4.3
|
|
24
22
|
*
|
|
@@ -44,7 +42,7 @@ function submit(packet) {
|
|
|
44
42
|
packet.origin = alchemy.discovery_id;
|
|
45
43
|
|
|
46
44
|
// Set the server http port
|
|
47
|
-
packet.http_port = alchemy.settings.port;
|
|
45
|
+
packet.http_port = alchemy.settings.network.port;
|
|
48
46
|
|
|
49
47
|
// Serialize the buffer
|
|
50
48
|
buffer = bson.serialize(packet);
|
|
@@ -67,7 +65,7 @@ function submit(packet) {
|
|
|
67
65
|
/**
|
|
68
66
|
* Listen for messages
|
|
69
67
|
*
|
|
70
|
-
* @author Jelle De Loecker
|
|
68
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
71
69
|
* @since 0.1.0
|
|
72
70
|
* @version 0.4.3
|
|
73
71
|
*/
|
|
@@ -121,7 +119,7 @@ function onServerMessage(message, rinfo) {
|
|
|
121
119
|
/**
|
|
122
120
|
* Prepare multicast
|
|
123
121
|
*
|
|
124
|
-
* @author Jelle De Loecker
|
|
122
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
125
123
|
* @since 0.4.1
|
|
126
124
|
* @version 0.4.3
|
|
127
125
|
*
|
|
@@ -186,7 +184,7 @@ Alchemy.setMethod(function initMulticast(callback) {
|
|
|
186
184
|
/**
|
|
187
185
|
* Bind to the UDP server port
|
|
188
186
|
*
|
|
189
|
-
* @author Jelle De Loecker
|
|
187
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
190
188
|
* @since 0.1.0
|
|
191
189
|
* @version 0.2.0
|
|
192
190
|
*/
|
|
@@ -230,13 +228,13 @@ Alchemy.setMethod(function initMulticast(callback) {
|
|
|
230
228
|
/**
|
|
231
229
|
* Multicast a message to other alchemy instances
|
|
232
230
|
*
|
|
233
|
-
* @author Jelle De Loecker
|
|
231
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
234
232
|
* @since 0.1.0
|
|
235
233
|
* @version 0.1.0
|
|
236
234
|
*
|
|
237
|
-
* @param {
|
|
235
|
+
* @param {string} type
|
|
238
236
|
* @param {Object} data The data to broadcast
|
|
239
|
-
* @param {
|
|
237
|
+
* @param {boolean} accumulate Group response data
|
|
240
238
|
* @param {Function} callback
|
|
241
239
|
*/
|
|
242
240
|
Alchemy.setMethod(function multicast(type, data, accumulate, callback) {
|
|
@@ -279,11 +277,11 @@ Alchemy.setMethod(function multicast(type, data, accumulate, callback) {
|
|
|
279
277
|
/**
|
|
280
278
|
* Listen for multicast messages
|
|
281
279
|
*
|
|
282
|
-
* @author Jelle De Loecker
|
|
280
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
283
281
|
* @since 0.1.0
|
|
284
282
|
* @version 0.4.0
|
|
285
283
|
*
|
|
286
|
-
* @param {
|
|
284
|
+
* @param {string} type
|
|
287
285
|
* @param {Function} callback
|
|
288
286
|
*/
|
|
289
287
|
Alchemy.setMethod(function onMulticast(type, callback) {
|
|
@@ -293,7 +291,7 @@ Alchemy.setMethod(function onMulticast(type, callback) {
|
|
|
293
291
|
/**
|
|
294
292
|
* Respond to discovery requests
|
|
295
293
|
*
|
|
296
|
-
* @author Jelle De Loecker
|
|
294
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
297
295
|
* @since 0.2.0
|
|
298
296
|
* @version 0.2.0
|
|
299
297
|
*/
|
|
@@ -317,7 +315,7 @@ mevents.on('discover_services', function gotDiscoverRequest(_requirements, packe
|
|
|
317
315
|
/**
|
|
318
316
|
* Detect instances with optional required services
|
|
319
317
|
*
|
|
320
|
-
* @author Jelle De Loecker
|
|
318
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
321
319
|
* @since 0.2.0
|
|
322
320
|
* @version 0.4.0
|
|
323
321
|
*
|
|
@@ -339,11 +337,11 @@ Alchemy.setMethod(function discover(requirements, callback) {
|
|
|
339
337
|
/**
|
|
340
338
|
* Configure a service
|
|
341
339
|
*
|
|
342
|
-
* @author Jelle De Loecker
|
|
340
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
343
341
|
* @since 0.2.0
|
|
344
342
|
* @version 0.4.0
|
|
345
343
|
*
|
|
346
|
-
* @param {
|
|
344
|
+
* @param {string} service_name
|
|
347
345
|
* @param {Object} config
|
|
348
346
|
*/
|
|
349
347
|
Alchemy.setMethod(function configureService(service_name, config) {
|
|
@@ -370,6 +368,6 @@ Alchemy.setMethod(function configureService(service_name, config) {
|
|
|
370
368
|
log.info('Service ' + JSON.stringify(service_name) + ' has been ' + status);
|
|
371
369
|
});
|
|
372
370
|
|
|
373
|
-
if (alchemy.settings.multicast_on_boot) {
|
|
371
|
+
if (alchemy.settings.network.multicast_on_boot) {
|
|
374
372
|
alchemy.initMulticast();
|
|
375
373
|
}
|
package/lib/core/middleware.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
var publicDirs = alchemy.shared('public.directories', new Deck()),
|
|
4
2
|
scriptDirs = alchemy.shared('script.directories', new Deck()),
|
|
5
3
|
assetDirs = alchemy.shared('asset.directories', new Deck()),
|
|
@@ -9,7 +7,7 @@ var publicDirs = alchemy.shared('public.directories', new Deck()),
|
|
|
9
7
|
fontDirs = alchemy.shared('font.directories', new Deck()),
|
|
10
8
|
asset_cache= alchemy.getCache('files.assets'),
|
|
11
9
|
fileCache = alchemy.shared('files.fileCache'),
|
|
12
|
-
|
|
10
|
+
minify_map = alchemy.shared('files.minifyMap', new Map()),
|
|
13
11
|
Nodent = alchemy.use('nodent-compiler'),
|
|
14
12
|
Terser = alchemy.use('terser'),
|
|
15
13
|
libpath = alchemy.use('path'),
|
|
@@ -26,11 +24,11 @@ var publicDirs = alchemy.shared('public.directories', new Deck()),
|
|
|
26
24
|
less,
|
|
27
25
|
fs = alchemy.use('fs');
|
|
28
26
|
|
|
29
|
-
if (alchemy.settings.
|
|
27
|
+
if (alchemy.settings.frontend.stylesheet.enable_less !== false) {
|
|
30
28
|
less = alchemy.use('less');
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
if (alchemy.settings.
|
|
31
|
+
if (alchemy.settings.frontend.stylesheet.enable_scss) {
|
|
34
32
|
|
|
35
33
|
// Try to use the embedded DART sass
|
|
36
34
|
sass = alchemy.use('sass-embedded');
|
|
@@ -88,12 +86,12 @@ if (alchemy.settings.css_sass) {
|
|
|
88
86
|
};
|
|
89
87
|
}
|
|
90
88
|
|
|
91
|
-
if (alchemy.settings.
|
|
89
|
+
if (alchemy.settings.frontend.stylesheet.enable_post !== false) {
|
|
92
90
|
postcss = alchemy.use('postcss');
|
|
93
91
|
autoprefixer = alchemy.use('autoprefixer');
|
|
94
92
|
}
|
|
95
93
|
|
|
96
|
-
if (alchemy.settings.
|
|
94
|
+
if (alchemy.settings.frontend.javascript.enable_babel) {
|
|
97
95
|
babel = alchemy.use('@babel/core');
|
|
98
96
|
babel_polyfill = alchemy.use('@babel/polyfill');
|
|
99
97
|
babel_preset = alchemy.use('@babel/preset-env');
|
|
@@ -104,7 +102,7 @@ if (alchemy.settings.babel) {
|
|
|
104
102
|
/**
|
|
105
103
|
* Get an array of paths, optionally replace text
|
|
106
104
|
*
|
|
107
|
-
* @author Jelle De Loecker
|
|
105
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
108
106
|
* @since 0.2.3
|
|
109
107
|
* @version 0.2.3
|
|
110
108
|
*/
|
|
@@ -126,7 +124,7 @@ function getMiddlePaths(paths, ext, new_ext) {
|
|
|
126
124
|
/**
|
|
127
125
|
* Less middleware
|
|
128
126
|
*
|
|
129
|
-
* @author Jelle De Loecker
|
|
127
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
130
128
|
* @since 0.2.0
|
|
131
129
|
* @version 1.3.0
|
|
132
130
|
*/
|
|
@@ -267,13 +265,13 @@ Alchemy.setMethod(function styleMiddleware(req, res, nextMiddleware) {
|
|
|
267
265
|
* Sourcemap middleware:
|
|
268
266
|
* Serve the original source files
|
|
269
267
|
*
|
|
270
|
-
* @author Jelle De Loecker
|
|
268
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
271
269
|
* @since 1.1.0
|
|
272
270
|
* @version 1.3.0
|
|
273
271
|
*/
|
|
274
272
|
Alchemy.setMethod(function sourcemapMiddleware(req, res, nextMiddleware) {
|
|
275
273
|
|
|
276
|
-
if (!alchemy.settings.debug) {
|
|
274
|
+
if (!alchemy.settings.debugging.debug) {
|
|
277
275
|
return nextMiddleware();
|
|
278
276
|
}
|
|
279
277
|
|
|
@@ -309,11 +307,11 @@ Alchemy.setMethod(function sourcemapMiddleware(req, res, nextMiddleware) {
|
|
|
309
307
|
/**
|
|
310
308
|
* Minify the given path, return a temp path
|
|
311
309
|
*
|
|
312
|
-
* @author Jelle De Loecker
|
|
310
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
313
311
|
* @since 0.2.0
|
|
314
|
-
* @version 1.
|
|
312
|
+
* @version 1.4.0
|
|
315
313
|
*
|
|
316
|
-
* @param {
|
|
314
|
+
* @param {string} path
|
|
317
315
|
* @param {Object} options
|
|
318
316
|
* @param {Function} callback
|
|
319
317
|
*/
|
|
@@ -325,13 +323,15 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
|
|
|
325
323
|
}
|
|
326
324
|
|
|
327
325
|
// Leave early if minify_js is false en nodent is falsy
|
|
328
|
-
if (!alchemy.settings.
|
|
326
|
+
if (!alchemy.settings.frontend.javascript.minify && !options.add_async_support) {
|
|
329
327
|
return callback();
|
|
330
328
|
}
|
|
331
329
|
|
|
330
|
+
let cached = minify_map.get(path);
|
|
331
|
+
|
|
332
332
|
// @TODO: take options.add_async_support into account
|
|
333
|
-
if (
|
|
334
|
-
return callback(null,
|
|
333
|
+
if (cached) {
|
|
334
|
+
return callback(null, cached.path, cached);
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
fs.readFile(path, {encoding: 'utf8'}, function gotSource(err, data) {
|
|
@@ -406,11 +406,19 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
|
|
|
406
406
|
}
|
|
407
407
|
|
|
408
408
|
async function serveCode(data) {
|
|
409
|
+
try {
|
|
410
|
+
await _serveCode(data);
|
|
411
|
+
} catch (err) {
|
|
412
|
+
return callback(err);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
async function _serveCode(data) {
|
|
409
417
|
|
|
410
418
|
let result;
|
|
411
419
|
let should_minify = false;
|
|
412
420
|
|
|
413
|
-
if (alchemy.settings.
|
|
421
|
+
if (alchemy.settings.frontend.javascript.minify) {
|
|
414
422
|
let index = data.indexOf('@alchemy.minify.false');
|
|
415
423
|
|
|
416
424
|
if (index == -1 || index > 50) {
|
|
@@ -421,6 +429,7 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
|
|
|
421
429
|
if (should_minify && typeof Terser?.minify == 'function') {
|
|
422
430
|
|
|
423
431
|
// Force Blast.isNode & Blast.isBrowser to be replaced later
|
|
432
|
+
data = data.replaceAll('Blast.isServer', '__BLAST_IS_SERVER');
|
|
424
433
|
data = data.replaceAll('Blast.isNode', '__BLAST_IS_NODE');
|
|
425
434
|
data = data.replaceAll('Blast.isBrowser', '__BLAST_IS_BROWSER');
|
|
426
435
|
|
|
@@ -439,7 +448,7 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
|
|
|
439
448
|
hoist_funs : false,
|
|
440
449
|
|
|
441
450
|
// Only drop console calls when not debugging
|
|
442
|
-
drop_console : !alchemy.settings.debug,
|
|
451
|
+
drop_console : !alchemy.settings.debugging.debug,
|
|
443
452
|
|
|
444
453
|
// Remove dead code
|
|
445
454
|
dead_code : true,
|
|
@@ -450,6 +459,7 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
|
|
|
450
459
|
// Provide it some info on global definitions
|
|
451
460
|
global_defs : {
|
|
452
461
|
'__BLAST_IS_NODE' : false,
|
|
462
|
+
'__BLAST_IS_SERVER' : false,
|
|
453
463
|
'__BLAST_IS_BROWSER' : true
|
|
454
464
|
}
|
|
455
465
|
},
|
|
@@ -463,8 +473,8 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
|
|
|
463
473
|
},
|
|
464
474
|
};
|
|
465
475
|
|
|
466
|
-
if (alchemy.settings.debug && alchemy.settings.
|
|
467
|
-
console.warn('Source maps have been disabled because alchemy.settings.
|
|
476
|
+
if (alchemy.settings.debugging.debug && alchemy.settings.debugging.create_source_map) {
|
|
477
|
+
console.warn('Source maps have been disabled because alchemy.settings.frontend.javascript.minify is true');
|
|
468
478
|
/*minify_options.sourceMap = {
|
|
469
479
|
url: 'inline'
|
|
470
480
|
};*/
|
|
@@ -487,6 +497,7 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
|
|
|
487
497
|
if (result.code.indexOf('__BLAST_IS_') > -1) {
|
|
488
498
|
// Restore some instances in case these weren't removed by Terser
|
|
489
499
|
// (Maybe because they're part of another variable or a string)
|
|
500
|
+
result = result.code.replaceAll('__BLAST_IS_SERVER', 'Blast.isServer');
|
|
490
501
|
result = result.code.replaceAll('__BLAST_IS_NODE', 'Blast.isNode');
|
|
491
502
|
result = result.replaceAll('__BLAST_IS_BROWSER', 'Blast.isBrowser');
|
|
492
503
|
} else {
|
|
@@ -522,7 +533,7 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
|
|
|
522
533
|
return callback(err);
|
|
523
534
|
}
|
|
524
535
|
|
|
525
|
-
|
|
536
|
+
minify_map.set(path, info);
|
|
526
537
|
|
|
527
538
|
// Callback with the path and the full info object
|
|
528
539
|
// of the temporary file
|
|
@@ -536,7 +547,7 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
|
|
|
536
547
|
/**
|
|
537
548
|
* Script middleware
|
|
538
549
|
*
|
|
539
|
-
* @author Jelle De Loecker
|
|
550
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
540
551
|
* @since 0.2.0
|
|
541
552
|
* @version 1.3.0
|
|
542
553
|
*/
|
|
@@ -613,8 +624,8 @@ Alchemy.setMethod(function scriptMiddleware(req, res, nextMiddleware) {
|
|
|
613
624
|
asset_cache.remove(req.url);
|
|
614
625
|
}
|
|
615
626
|
|
|
616
|
-
if (source &&
|
|
617
|
-
|
|
627
|
+
if (source && minify_map.has(source.path)) {
|
|
628
|
+
minify_map.delete(source.path);
|
|
618
629
|
}
|
|
619
630
|
|
|
620
631
|
alchemy.scriptMiddleware(req, res, nextMiddleware);
|
|
@@ -626,7 +637,7 @@ Alchemy.setMethod(function scriptMiddleware(req, res, nextMiddleware) {
|
|
|
626
637
|
/**
|
|
627
638
|
* Font middleware
|
|
628
639
|
*
|
|
629
|
-
* @author Jelle De Loecker
|
|
640
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
630
641
|
* @since 1.1.3
|
|
631
642
|
* @version 1.1.3
|
|
632
643
|
*/
|
|
@@ -638,7 +649,7 @@ Alchemy.setMethod(function fontMiddleware(req, res, nextMiddleware) {
|
|
|
638
649
|
/**
|
|
639
650
|
* Public files middleware
|
|
640
651
|
*
|
|
641
|
-
* @author Jelle De Loecker
|
|
652
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
642
653
|
* @since 0.2.0
|
|
643
654
|
* @version 1.1.0
|
|
644
655
|
*/
|
|
@@ -650,7 +661,7 @@ Alchemy.setMethod(function publicMiddleware(req, res, nextMiddleware) {
|
|
|
650
661
|
/**
|
|
651
662
|
* Generic asset middleware
|
|
652
663
|
*
|
|
653
|
-
* @author Jelle De Loecker
|
|
664
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
654
665
|
* @since 1.1.3
|
|
655
666
|
* @version 1.1.3
|
|
656
667
|
*/
|
|
@@ -690,7 +701,7 @@ Alchemy.setMethod(function assetInDirsMiddleware(req, res, directories, nextMidd
|
|
|
690
701
|
/**
|
|
691
702
|
* Root files middleware
|
|
692
703
|
*
|
|
693
|
-
* @author Jelle De Loecker
|
|
704
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
694
705
|
* @since 0.2.0
|
|
695
706
|
* @version 1.3.0
|
|
696
707
|
*/
|
|
@@ -743,11 +754,11 @@ Alchemy.setMethod(function rootMiddleware(req, res, nextMiddleware) {
|
|
|
743
754
|
/**
|
|
744
755
|
* Look for assetFile in the given directories
|
|
745
756
|
*
|
|
746
|
-
* @author Jelle De Loecker
|
|
757
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
747
758
|
* @since 0.2.0
|
|
748
759
|
* @version 1.3.0
|
|
749
760
|
*
|
|
750
|
-
* @param {
|
|
761
|
+
* @param {string} image_path
|
|
751
762
|
* @param {Function} callback
|
|
752
763
|
*
|
|
753
764
|
* @return {Pledge}
|
|
@@ -764,7 +775,7 @@ Alchemy.setMethod(function findImagePath(image_path, callback) {
|
|
|
764
775
|
|
|
765
776
|
let id = 'image-' + image_path;
|
|
766
777
|
|
|
767
|
-
if (alchemy.settings.cache && asset_cache.has(id)) {
|
|
778
|
+
if (alchemy.settings.performance.cache && asset_cache.has(id)) {
|
|
768
779
|
pledge.resolve(asset_cache.get(id).path);
|
|
769
780
|
} else {
|
|
770
781
|
|
|
@@ -786,12 +797,12 @@ Alchemy.setMethod(function findImagePath(image_path, callback) {
|
|
|
786
797
|
/**
|
|
787
798
|
* Look for assetFile in the given directories
|
|
788
799
|
*
|
|
789
|
-
* @author Jelle De Loecker
|
|
800
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
790
801
|
* @since 0.2.0
|
|
791
802
|
* @version 0.4.2
|
|
792
803
|
*
|
|
793
|
-
* @param {
|
|
794
|
-
* @param {Deck|
|
|
804
|
+
* @param {string} assetFile The full filename to look for
|
|
805
|
+
* @param {Deck|string} directories The directories to look in (or subdir of "assets")
|
|
795
806
|
* @param {Function} callback
|
|
796
807
|
*/
|
|
797
808
|
Alchemy.setMethod(function findAssetPath(assetFile, directories, callback) {
|
|
@@ -923,11 +934,11 @@ Alchemy.setMethod(function findAssetPath(assetFile, directories, callback) {
|
|
|
923
934
|
/**
|
|
924
935
|
* Apply postCss
|
|
925
936
|
*
|
|
926
|
-
* @author Jelle De Loecker
|
|
937
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
927
938
|
* @since 0.5.0
|
|
928
939
|
* @version 1.0.5
|
|
929
940
|
*
|
|
930
|
-
* @param {
|
|
941
|
+
* @param {string} css
|
|
931
942
|
* @param {Function} callback
|
|
932
943
|
*/
|
|
933
944
|
function doPostCss(css, callback) {
|
|
@@ -941,7 +952,7 @@ function doPostCss(css, callback) {
|
|
|
941
952
|
/**
|
|
942
953
|
* Callback with the compiled CSS filepath
|
|
943
954
|
*
|
|
944
|
-
* @author Jelle De Loecker
|
|
955
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
945
956
|
* @since 0.2.0
|
|
946
957
|
* @version 1.0.0
|
|
947
958
|
*/
|
|
@@ -949,7 +960,7 @@ Alchemy.setMethod(function getCompiledLessPath(lessPath, options, callback) {
|
|
|
949
960
|
|
|
950
961
|
// If it has been compiled before, return that
|
|
951
962
|
// @todo: check timestamps on dev. Not-founds are not cached
|
|
952
|
-
if (alchemy.settings.cache && fileCache[lessPath]) {
|
|
963
|
+
if (alchemy.settings.performance.cache && fileCache[lessPath]) {
|
|
953
964
|
return setImmediate(function lessCache(){callback(null, fileCache[lessPath])});
|
|
954
965
|
}
|
|
955
966
|
|
|
@@ -974,7 +985,7 @@ Alchemy.setMethod(function getCompiledLessPath(lessPath, options, callback) {
|
|
|
974
985
|
|
|
975
986
|
render_options = {
|
|
976
987
|
paths: import_paths,
|
|
977
|
-
compress: alchemy.settings.
|
|
988
|
+
compress: alchemy.settings.frontend.stylesheet.minify,
|
|
978
989
|
};
|
|
979
990
|
|
|
980
991
|
// @todo: source maps. Compression. Everything
|
|
@@ -1041,7 +1052,7 @@ Alchemy.setMethod(function getCompiledLessPath(lessPath, options, callback) {
|
|
|
1041
1052
|
/**
|
|
1042
1053
|
* Callback with the compiled CSS filepath
|
|
1043
1054
|
*
|
|
1044
|
-
* @author Jelle De Loecker
|
|
1055
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1045
1056
|
* @since 0.2.0
|
|
1046
1057
|
* @version 1.2.5
|
|
1047
1058
|
*/
|
|
@@ -1049,7 +1060,7 @@ Alchemy.setMethod(function getCompiledSassPath(sassPath, options, callback) {
|
|
|
1049
1060
|
|
|
1050
1061
|
// If it has been compiled before, return that
|
|
1051
1062
|
// @todo: check timestamps on dev. Not-founds are not cached
|
|
1052
|
-
if (alchemy.settings.cache && fileCache[sassPath]) {
|
|
1063
|
+
if (alchemy.settings.performance.cache && fileCache[sassPath]) {
|
|
1053
1064
|
return setImmediate(function lessCache(){callback(null, fileCache[sassPath])});
|
|
1054
1065
|
}
|
|
1055
1066
|
|
|
@@ -1072,7 +1083,7 @@ Alchemy.setMethod(function getCompiledSassPath(sassPath, options, callback) {
|
|
|
1072
1083
|
functions : sass_functions,
|
|
1073
1084
|
};
|
|
1074
1085
|
|
|
1075
|
-
if (alchemy.settings.debug) {
|
|
1086
|
+
if (alchemy.settings.debugging.debug) {
|
|
1076
1087
|
render_options.file = sassPath;
|
|
1077
1088
|
render_options.sourceMap = 'out.css.map';
|
|
1078
1089
|
render_options.sourceMapContents = true;
|