alchemymvc 1.2.2 → 1.2.3
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/helper_model/criteria.js +42 -15
- package/lib/app/helper_model/document_list.js +19 -2
- package/lib/app/helper_model/field_config.js +13 -3
- package/lib/app/helper_model/model.js +19 -3
- package/lib/class/document.js +32 -11
- package/lib/class/document_list.js +11 -1
- package/lib/core/client_alchemy.js +11 -0
- package/lib/init/requirements.js +1 -1
- package/package.json +3 -3
|
@@ -59,7 +59,7 @@ Criteria.setStatic(function isCriteria(instance) {
|
|
|
59
59
|
*
|
|
60
60
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
61
61
|
* @since 1.1.0
|
|
62
|
-
* @version 1.
|
|
62
|
+
* @version 1.2.3
|
|
63
63
|
*
|
|
64
64
|
* @param {Object} data
|
|
65
65
|
*
|
|
@@ -81,10 +81,14 @@ Criteria.setStatic(function unDry(data) {
|
|
|
81
81
|
// Revive the group instance
|
|
82
82
|
criteria.group = Group.revive(data.group, criteria);
|
|
83
83
|
|
|
84
|
+
if(!data.options) {
|
|
85
|
+
data.options = {};
|
|
86
|
+
}
|
|
87
|
+
|
|
84
88
|
// Revive the select
|
|
85
89
|
data.options.select = Select.revive(data.options.select, criteria);
|
|
86
90
|
|
|
87
|
-
criteria.options = data.options;
|
|
91
|
+
criteria.options = data.options || {};
|
|
88
92
|
|
|
89
93
|
return criteria;
|
|
90
94
|
});
|
|
@@ -248,7 +252,7 @@ Criteria.setProperty(function recursive_level() {
|
|
|
248
252
|
*
|
|
249
253
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
250
254
|
* @since 1.1.0
|
|
251
|
-
* @version 1.
|
|
255
|
+
* @version 1.2.3
|
|
252
256
|
*/
|
|
253
257
|
Criteria.setMethod(Blast.checksumSymbol, function toChecksum() {
|
|
254
258
|
|
|
@@ -259,7 +263,7 @@ Criteria.setMethod(Blast.checksumSymbol, function toChecksum() {
|
|
|
259
263
|
|
|
260
264
|
for (key in this.options) {
|
|
261
265
|
|
|
262
|
-
if (key == 'init_model' || key == 'init_record') {
|
|
266
|
+
if (key == 'init_model' || key == 'init_record' || key == 'assoc_cache') {
|
|
263
267
|
continue;
|
|
264
268
|
}
|
|
265
269
|
|
|
@@ -319,21 +323,30 @@ Criteria.setMethod(Symbol.asyncIterator, function asyncIterator() {
|
|
|
319
323
|
*
|
|
320
324
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
321
325
|
* @since 1.1.0
|
|
322
|
-
* @version 1.
|
|
326
|
+
* @version 1.2.3
|
|
323
327
|
*
|
|
324
328
|
* @return {Object}
|
|
325
329
|
*/
|
|
326
330
|
Criteria.setMethod(function toJSON() {
|
|
327
331
|
|
|
328
|
-
|
|
329
|
-
options
|
|
332
|
+
let result = {},
|
|
333
|
+
options;
|
|
330
334
|
|
|
331
335
|
if (this.model && this.model.name) {
|
|
332
336
|
result.model = this.model.name;
|
|
333
337
|
}
|
|
334
338
|
|
|
335
|
-
if (options
|
|
336
|
-
|
|
339
|
+
if (this.options) {
|
|
340
|
+
let key;
|
|
341
|
+
options = {};
|
|
342
|
+
|
|
343
|
+
for (key in this.options) {
|
|
344
|
+
if (key == 'assoc_cache' || key == 'init_record') {
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
options[key] = this.options[key];
|
|
349
|
+
}
|
|
337
350
|
}
|
|
338
351
|
|
|
339
352
|
result.group = this.group;
|
|
@@ -388,7 +401,7 @@ Criteria.setMethod(function clone() {
|
|
|
388
401
|
*
|
|
389
402
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
390
403
|
* @since 1.1.0
|
|
391
|
-
* @version 1.2.
|
|
404
|
+
* @version 1.2.3
|
|
392
405
|
*
|
|
393
406
|
* @return {String[]}
|
|
394
407
|
*/
|
|
@@ -396,14 +409,14 @@ Criteria.setMethod(function getFieldsToSelect() {
|
|
|
396
409
|
|
|
397
410
|
let result;
|
|
398
411
|
|
|
399
|
-
if (this.options
|
|
412
|
+
if (this.options?.select?.fields?.length) {
|
|
400
413
|
result = this.options.select.fields.slice(0);
|
|
401
414
|
}
|
|
402
415
|
|
|
403
416
|
// Fields can sometimes be required for a query (like in a join) but they
|
|
404
417
|
// won't be selected if other fields are explicitly set.
|
|
405
418
|
// So in that case: add these special fields to the projection
|
|
406
|
-
if (result && this.options
|
|
419
|
+
if (result && this.options?.select?.query_fields) {
|
|
407
420
|
result.push(...this.options.select.query_fields);
|
|
408
421
|
}
|
|
409
422
|
|
|
@@ -479,7 +492,7 @@ Criteria.setMethod(function getAssociationConfiguration(alias) {
|
|
|
479
492
|
*
|
|
480
493
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
481
494
|
* @since 1.1.0
|
|
482
|
-
* @version 1.
|
|
495
|
+
* @version 1.2.3
|
|
483
496
|
*
|
|
484
497
|
* @param {String} name
|
|
485
498
|
* @param {Object} item
|
|
@@ -524,6 +537,16 @@ Criteria.setMethod(function getCriteriaForAssociation(name, item) {
|
|
|
524
537
|
assoc_crit.setOption('assoc_key', assoc_key);
|
|
525
538
|
assoc_crit.setOption('assoc_value', value);
|
|
526
539
|
|
|
540
|
+
// Make the assoc_cache if it doesn't exist yet
|
|
541
|
+
if (options.create_references !== false && !options.assoc_cache) {
|
|
542
|
+
options.assoc_cache = {};
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// Add the assoc_cache
|
|
546
|
+
if (options.assoc_cache) {
|
|
547
|
+
assoc_crit.setOption('assoc_cache', options.assoc_cache);
|
|
548
|
+
}
|
|
549
|
+
|
|
527
550
|
// Take over the locale option
|
|
528
551
|
if (options.locale) {
|
|
529
552
|
assoc_crit.setOption('locale', options.locale);
|
|
@@ -1310,13 +1333,17 @@ var Select = Function.inherits('Alchemy.Base', 'Alchemy.Criteria', function Sele
|
|
|
1310
1333
|
*
|
|
1311
1334
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
1312
1335
|
* @since 1.1.0
|
|
1313
|
-
* @version 1.
|
|
1336
|
+
* @version 1.2.3
|
|
1314
1337
|
*
|
|
1315
1338
|
* @return {Select}
|
|
1316
1339
|
*/
|
|
1317
1340
|
Select.setStatic(function revive(data, criteria) {
|
|
1318
1341
|
|
|
1319
|
-
|
|
1342
|
+
if (!data) {
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
let result = new Select(criteria),
|
|
1320
1347
|
key;
|
|
1321
1348
|
|
|
1322
1349
|
result.fields = data.fields;
|
|
@@ -143,14 +143,31 @@ DocumentList.setMethod(function createIterator() {
|
|
|
143
143
|
*
|
|
144
144
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
145
145
|
* @since 1.0.0
|
|
146
|
-
* @version 1.
|
|
146
|
+
* @version 1.2.3
|
|
147
147
|
*
|
|
148
148
|
* @return {Object}
|
|
149
149
|
*/
|
|
150
150
|
DocumentList.setMethod(function toDry() {
|
|
151
|
+
|
|
152
|
+
let options;
|
|
153
|
+
|
|
154
|
+
if (this.options) {
|
|
155
|
+
let key;
|
|
156
|
+
|
|
157
|
+
options = {};
|
|
158
|
+
|
|
159
|
+
for (key in this.options) {
|
|
160
|
+
if (key == 'options' || key == 'assoc_cache') {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
options[key] = this.options[key];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
151
168
|
return {
|
|
152
169
|
value: {
|
|
153
|
-
options :
|
|
170
|
+
options : options,
|
|
154
171
|
records : this.records,
|
|
155
172
|
available : this.available,
|
|
156
173
|
}
|
|
@@ -44,15 +44,24 @@ const FieldConfig = Fn.inherits('Alchemy.Base', 'Alchemy.Criteria', function Fie
|
|
|
44
44
|
*
|
|
45
45
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
46
46
|
* @since 1.1.3
|
|
47
|
-
* @version 1.
|
|
47
|
+
* @version 1.2.3
|
|
48
48
|
*
|
|
49
49
|
* @param {Object} obj
|
|
50
50
|
*
|
|
51
51
|
* @return {Alchemy.Form.FieldConfig}
|
|
52
52
|
*/
|
|
53
53
|
FieldConfig.setStatic(function unDry(obj) {
|
|
54
|
-
let
|
|
55
|
-
|
|
54
|
+
let result = new FieldConfig(obj.path, obj.options);
|
|
55
|
+
|
|
56
|
+
if (obj.association) {
|
|
57
|
+
result.association = obj.association;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (obj.model) {
|
|
61
|
+
result.model = obj.model;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return result;
|
|
56
65
|
});
|
|
57
66
|
|
|
58
67
|
/**
|
|
@@ -194,6 +203,7 @@ FieldConfig.setMethod(function toJSON() {
|
|
|
194
203
|
local_path : this.local_path,
|
|
195
204
|
association : this.association,
|
|
196
205
|
options : this.options,
|
|
206
|
+
model : this.model,
|
|
197
207
|
};
|
|
198
208
|
});
|
|
199
209
|
|
|
@@ -1103,13 +1103,20 @@ Model.setMethod(function addAssociatedDataToRecord(criteria, item, callback) {
|
|
|
1103
1103
|
|
|
1104
1104
|
aliases[alias] = function aliasRecordTask(nextAlias) {
|
|
1105
1105
|
|
|
1106
|
-
|
|
1106
|
+
let pledge,
|
|
1107
|
+
key;
|
|
1107
1108
|
|
|
1108
1109
|
if (options.create_references !== false) {
|
|
1109
1110
|
key = alchemy.checksum(assoc_crit);
|
|
1110
1111
|
|
|
1111
|
-
if (key != null
|
|
1112
|
-
|
|
1112
|
+
if (key != null) {
|
|
1113
|
+
if (options.assoc_cache[key]) {
|
|
1114
|
+
Pledge.done(options.assoc_cache[key], nextAlias);
|
|
1115
|
+
return;
|
|
1116
|
+
} else {
|
|
1117
|
+
pledge = new Pledge();
|
|
1118
|
+
options.assoc_cache[key] = pledge;
|
|
1119
|
+
}
|
|
1113
1120
|
}
|
|
1114
1121
|
}
|
|
1115
1122
|
|
|
@@ -1125,6 +1132,11 @@ Model.setMethod(function addAssociatedDataToRecord(criteria, item, callback) {
|
|
|
1125
1132
|
}
|
|
1126
1133
|
|
|
1127
1134
|
if (err != null) {
|
|
1135
|
+
|
|
1136
|
+
if (pledge) {
|
|
1137
|
+
pledge.reject(err);
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1128
1140
|
return nextAlias(err);
|
|
1129
1141
|
}
|
|
1130
1142
|
|
|
@@ -1140,6 +1152,10 @@ Model.setMethod(function addAssociatedDataToRecord(criteria, item, callback) {
|
|
|
1140
1152
|
|
|
1141
1153
|
if (key) {
|
|
1142
1154
|
options.assoc_cache[key] = result;
|
|
1155
|
+
|
|
1156
|
+
if (pledge) {
|
|
1157
|
+
pledge.resolve(result);
|
|
1158
|
+
}
|
|
1143
1159
|
}
|
|
1144
1160
|
|
|
1145
1161
|
nextAlias(null, result);
|
package/lib/class/document.js
CHANGED
|
@@ -536,27 +536,24 @@ Document.setMethod(function remove(callback) {
|
|
|
536
536
|
/**
|
|
537
537
|
* Add associated data to this record
|
|
538
538
|
*
|
|
539
|
-
* @author Jelle De Loecker <jelle@
|
|
540
|
-
* @since
|
|
541
|
-
* @version 1.
|
|
539
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
540
|
+
* @since 1.2.3
|
|
541
|
+
* @version 1.2.3
|
|
542
542
|
*
|
|
543
|
-
* @param {Criteria} criteria
|
|
544
|
-
* @param {Function} callback
|
|
543
|
+
* @param {Criteria|String} criteria
|
|
545
544
|
*
|
|
546
|
-
* @return {
|
|
545
|
+
* @return {Criteria}
|
|
547
546
|
*/
|
|
548
|
-
Document.setMethod(
|
|
547
|
+
Document.setMethod(function preparePopulationCriteria(criteria) {
|
|
549
548
|
|
|
550
|
-
|
|
549
|
+
let type = typeof criteria,
|
|
551
550
|
model = this.$model,
|
|
552
|
-
type = typeof criteria,
|
|
553
551
|
selects;
|
|
554
552
|
|
|
555
553
|
if (type == 'string') {
|
|
556
554
|
selects = [criteria];
|
|
557
555
|
criteria = {};
|
|
558
556
|
} else if (type == 'function') {
|
|
559
|
-
callback = criteria;
|
|
560
557
|
criteria = {};
|
|
561
558
|
} else if (Array.isArray(criteria)) {
|
|
562
559
|
selects = criteria;
|
|
@@ -583,7 +580,31 @@ Document.setMethod(['populate', 'addAssociatedData'], function addAssociatedData
|
|
|
583
580
|
}
|
|
584
581
|
}
|
|
585
582
|
|
|
586
|
-
return
|
|
583
|
+
return criteria;
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Add associated data to this record
|
|
588
|
+
*
|
|
589
|
+
* @author Jelle De Loecker <jelle@develry.be>
|
|
590
|
+
* @since 0.2.0
|
|
591
|
+
* @version 1.2.3
|
|
592
|
+
*
|
|
593
|
+
* @param {Criteria} criteria
|
|
594
|
+
* @param {Function} callback
|
|
595
|
+
*
|
|
596
|
+
* @return {Pledge}
|
|
597
|
+
*/
|
|
598
|
+
Document.setMethod(['populate', 'addAssociatedData'], function addAssociatedData(criteria, callback) {
|
|
599
|
+
|
|
600
|
+
if (typeof criteria == 'function') {
|
|
601
|
+
callback = criteria;
|
|
602
|
+
criteria = null;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
criteria = this.preparePopulationCriteria(criteria);
|
|
606
|
+
|
|
607
|
+
return this.$model.addAssociatedDataToRecord(criteria, this.$record, callback);
|
|
587
608
|
});
|
|
588
609
|
|
|
589
610
|
/**
|
|
@@ -63,13 +63,23 @@ DocumentList.setMethod(function clone() {
|
|
|
63
63
|
*
|
|
64
64
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
65
65
|
* @since 1.1.0
|
|
66
|
-
* @version 1.
|
|
66
|
+
* @version 1.2.3
|
|
67
67
|
*
|
|
68
68
|
* @param {Criteria} criteria
|
|
69
69
|
*
|
|
70
70
|
* @return {Pledge}
|
|
71
71
|
*/
|
|
72
72
|
DocumentList.setMethod(['populate', 'addAssociatedData'], function addAssociatedData(criteria) {
|
|
73
|
+
|
|
74
|
+
if (!this.records?.length) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let doc = this.records[0];
|
|
79
|
+
|
|
80
|
+
// Use the first doc to prepare the population criteria
|
|
81
|
+
criteria = doc.preparePopulationCriteria(criteria);
|
|
82
|
+
|
|
73
83
|
return Function.forEach.parallel(this.records, function eachDoc(doc, key, next) {
|
|
74
84
|
doc.populate(criteria).done(next);
|
|
75
85
|
});
|
|
@@ -24,6 +24,17 @@ var Alchemy = Function.inherits('Alchemy.Client.Base', function Alchemy() {
|
|
|
24
24
|
this.sent_subscriptions = [];
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* A reference to the main hawkejs instance
|
|
29
|
+
*
|
|
30
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
31
|
+
* @since 1.2.3
|
|
32
|
+
* @version 1.2.3
|
|
33
|
+
*/
|
|
34
|
+
Alchemy.setProperty(function hawkejs() {
|
|
35
|
+
return window.hawkejs;
|
|
36
|
+
});
|
|
37
|
+
|
|
27
38
|
/**
|
|
28
39
|
* Called in the onScene static method of the Alchemy helper
|
|
29
40
|
*
|
package/lib/init/requirements.js
CHANGED
|
@@ -50,7 +50,7 @@ alchemy.use('less', 'less');
|
|
|
50
50
|
* @link https://npmjs.org/package/hawkejs
|
|
51
51
|
*/
|
|
52
52
|
alchemy.use('hawkejs', 'hawkejs');
|
|
53
|
-
alchemy.hawkejs =
|
|
53
|
+
alchemy.hawkejs = Classes.Hawkejs.Hawkejs.getInstance();
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* The function to detect when everything is too busy
|
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.2.
|
|
4
|
+
"version": "1.2.3",
|
|
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" : "~1.2.2",
|
|
24
24
|
"graceful-fs" : "~4.2.9",
|
|
25
|
-
"hawkejs" : "~2.2.
|
|
25
|
+
"hawkejs" : "~2.2.9",
|
|
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.7.
|
|
34
|
+
"protoblast" : "~0.7.20",
|
|
35
35
|
"semver" : "~7.3.5",
|
|
36
36
|
"socket.io" : "~2.4.0",
|
|
37
37
|
"@11ways/socket.io-stream" : "~0.9.2",
|