alchemymvc 1.3.3 → 1.3.4
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 +2 -2
- package/lib/app/helper_component/paginate_component.js +3 -3
- package/lib/app/helper_model/criteria.js +19 -9
- package/lib/app/helper_model/document_list.js +4 -2
- package/lib/app/helper_model/model.js +9 -11
- package/lib/class/conduit.js +3 -3
- package/lib/class/document.js +4 -4
- package/lib/class/schema.js +33 -175
- package/lib/class/schema_client.js +157 -1
- package/lib/class/sitemap.js +57 -0
- package/lib/core/middleware.js +11 -2
- package/package.json +2 -2
|
@@ -151,7 +151,7 @@ HttpConduit.setMethod(async function initHttp(req, res, router) {
|
|
|
151
151
|
/**
|
|
152
152
|
* Get the original url path
|
|
153
153
|
*
|
|
154
|
-
* @author Jelle De Loecker <jelle@
|
|
154
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
155
155
|
* @since 1.1.0
|
|
156
156
|
* @version 1.1.0
|
|
157
157
|
*
|
|
@@ -166,7 +166,7 @@ HttpConduit.setProperty(function original_path() {
|
|
|
166
166
|
/**
|
|
167
167
|
* Get the original url pathname
|
|
168
168
|
*
|
|
169
|
-
* @author Jelle De Loecker <jelle@
|
|
169
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
170
170
|
* @since 1.1.0
|
|
171
171
|
* @version 1.1.0
|
|
172
172
|
*
|
|
@@ -15,7 +15,7 @@ const Paginate = Function.inherits('Alchemy.Client.Component', 'Paginate');
|
|
|
15
15
|
*
|
|
16
16
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
17
17
|
* @since 0.0.1
|
|
18
|
-
* @version 1.
|
|
18
|
+
* @version 1.3.4
|
|
19
19
|
*
|
|
20
20
|
* @param {Model} model
|
|
21
21
|
* @param {Criteria} criteria
|
|
@@ -26,13 +26,13 @@ Paginate.setMethod(function find(model, criteria) {
|
|
|
26
26
|
|
|
27
27
|
const conduit = this.controller.conduit;
|
|
28
28
|
|
|
29
|
-
criteria = Blast.Classes.Alchemy.Criteria.Criteria.cast(criteria);
|
|
30
|
-
|
|
31
29
|
// Get the model if a name has been given
|
|
32
30
|
if (typeof model == 'string') {
|
|
33
31
|
model = this.getModel(model);
|
|
34
32
|
}
|
|
35
33
|
|
|
34
|
+
criteria = Blast.Classes.Alchemy.Criteria.Criteria.cast(criteria, model);
|
|
35
|
+
|
|
36
36
|
let page_size = criteria.options.page_size || 10,
|
|
37
37
|
skipless = criteria.options.skipless,
|
|
38
38
|
last_id,
|
|
@@ -3,15 +3,20 @@ const AUGMENTED = Symbol('AUGMENTED');
|
|
|
3
3
|
/**
|
|
4
4
|
* The Criteria class
|
|
5
5
|
*
|
|
6
|
-
* @author Jelle De Loecker <jelle@
|
|
6
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
7
7
|
* @since 1.1.0
|
|
8
|
-
* @version 1.
|
|
8
|
+
* @version 1.3.4
|
|
9
|
+
*
|
|
10
|
+
* @param {Model} model
|
|
9
11
|
*/
|
|
10
|
-
var Criteria = Function.inherits('Alchemy.Base', 'Alchemy.Criteria', function Criteria() {
|
|
12
|
+
var Criteria = Function.inherits('Alchemy.Base', 'Alchemy.Criteria', function Criteria(model) {
|
|
11
13
|
|
|
12
14
|
// The current active group
|
|
13
15
|
this.group = null;
|
|
14
16
|
|
|
17
|
+
// The model
|
|
18
|
+
this.model = model;
|
|
19
|
+
|
|
15
20
|
// All the created expressions
|
|
16
21
|
this.all_expressions = [];
|
|
17
22
|
|
|
@@ -58,19 +63,20 @@ Criteria.setStatic(function isCriteria(instance) {
|
|
|
58
63
|
*
|
|
59
64
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
60
65
|
* @since 1.2.5
|
|
61
|
-
* @version 1.
|
|
66
|
+
* @version 1.3.4
|
|
62
67
|
*
|
|
63
|
-
* @param {Object} obj
|
|
68
|
+
* @param {Object} obj The thing that should be a criteria
|
|
69
|
+
* @param {Model} model The model that it probably belongs to
|
|
64
70
|
*
|
|
65
71
|
* @return {Criteria}
|
|
66
72
|
*/
|
|
67
|
-
Criteria.setStatic(function cast(obj) {
|
|
73
|
+
Criteria.setStatic(function cast(obj, model) {
|
|
68
74
|
|
|
69
75
|
if (Criteria.isCriteria(obj)) {
|
|
70
76
|
return obj;
|
|
71
77
|
}
|
|
72
78
|
|
|
73
|
-
let instance = new Criteria();
|
|
79
|
+
let instance = new Criteria(model);
|
|
74
80
|
|
|
75
81
|
if (obj) {
|
|
76
82
|
instance.applyOldOptions(obj);
|
|
@@ -1456,9 +1462,9 @@ Select.setMethod(Blast.checksumSymbol, function toChecksum() {
|
|
|
1456
1462
|
/**
|
|
1457
1463
|
* Add an association
|
|
1458
1464
|
*
|
|
1459
|
-
* @author Jelle De Loecker <jelle@
|
|
1465
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1460
1466
|
* @since 1.1.0
|
|
1461
|
-
* @version 1.
|
|
1467
|
+
* @version 1.3.4
|
|
1462
1468
|
*
|
|
1463
1469
|
* @param {String} name
|
|
1464
1470
|
*
|
|
@@ -1466,6 +1472,10 @@ Select.setMethod(Blast.checksumSymbol, function toChecksum() {
|
|
|
1466
1472
|
*/
|
|
1467
1473
|
Select.setMethod(function addAssociation(name) {
|
|
1468
1474
|
|
|
1475
|
+
if (!this.criteria?.model) {
|
|
1476
|
+
throw new Error('Unable to select an association: this Criteria has no model info');
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1469
1479
|
var pieces;
|
|
1470
1480
|
|
|
1471
1481
|
if (!this.associations) {
|
|
@@ -183,9 +183,9 @@ DocumentList.setMethod(function toDry() {
|
|
|
183
183
|
/**
|
|
184
184
|
* Simplify the object for Hawkejs
|
|
185
185
|
*
|
|
186
|
-
* @author Jelle De Loecker <jelle@
|
|
186
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
187
187
|
* @since 1.0.0
|
|
188
|
-
* @version 1.
|
|
188
|
+
* @version 1.3.4
|
|
189
189
|
*
|
|
190
190
|
* @param {WeakMap} wm
|
|
191
191
|
*
|
|
@@ -196,6 +196,8 @@ DocumentList.setMethod(function toHawkejs(wm) {
|
|
|
196
196
|
let records = JSON.clone(this.records, 'toHawkejs', wm),
|
|
197
197
|
result = new Blast.Classes.Alchemy.Client.DocumentList(records);
|
|
198
198
|
|
|
199
|
+
result.available = this.available;
|
|
200
|
+
|
|
199
201
|
if (this.options && this.options.options) {
|
|
200
202
|
let options = JSON.clone(this.options.options, 'toHawkejs', wm);
|
|
201
203
|
result.options = {options: options};
|
|
@@ -599,7 +599,7 @@ Model.setMethod(function getAliasModel(alias) {
|
|
|
599
599
|
*
|
|
600
600
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
601
601
|
* @since 0.0.1
|
|
602
|
-
* @version 1.3.
|
|
602
|
+
* @version 1.3.4
|
|
603
603
|
*
|
|
604
604
|
* @param {String} type The type of find (first, all)
|
|
605
605
|
* @param {Criteria} criteria The criteria object
|
|
@@ -610,9 +610,7 @@ Model.setMethod(function getAliasModel(alias) {
|
|
|
610
610
|
Model.setMethod(function find(type, criteria, callback) {
|
|
611
611
|
|
|
612
612
|
if (arguments.length == 0) {
|
|
613
|
-
|
|
614
|
-
criteria.model = this;
|
|
615
|
-
return criteria;
|
|
613
|
+
return new Blast.Classes.Alchemy.Criteria(this);
|
|
616
614
|
}
|
|
617
615
|
|
|
618
616
|
let skip_type,
|
|
@@ -645,7 +643,7 @@ Model.setMethod(function find(type, criteria, callback) {
|
|
|
645
643
|
}
|
|
646
644
|
|
|
647
645
|
try {
|
|
648
|
-
criteria = Blast.Classes.Alchemy.Criteria.Criteria.cast(criteria);
|
|
646
|
+
criteria = Blast.Classes.Alchemy.Criteria.Criteria.cast(criteria, this);
|
|
649
647
|
} catch (err) {
|
|
650
648
|
error = err;
|
|
651
649
|
}
|
|
@@ -826,7 +824,7 @@ Model.setMethod(function findById(id, options, callback) {
|
|
|
826
824
|
*
|
|
827
825
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
828
826
|
* @since 0.0.1
|
|
829
|
-
* @version 1.
|
|
827
|
+
* @version 1.3.4
|
|
830
828
|
*
|
|
831
829
|
* @param {String|ObjectId} pk The primary key value
|
|
832
830
|
* @param {Object} options Optional options object
|
|
@@ -842,7 +840,7 @@ Model.setMethod(function findByPk(pk, options, callback) {
|
|
|
842
840
|
return pledge;
|
|
843
841
|
}
|
|
844
842
|
|
|
845
|
-
let criteria = new Blast.Classes.Alchemy.Criteria();
|
|
843
|
+
let criteria = new Blast.Classes.Alchemy.Criteria(this);
|
|
846
844
|
|
|
847
845
|
criteria.where(this.primary_key).equals(pk);
|
|
848
846
|
|
|
@@ -860,7 +858,7 @@ Model.setMethod(function findByPk(pk, options, callback) {
|
|
|
860
858
|
*
|
|
861
859
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
862
860
|
* @since 1.1.0
|
|
863
|
-
* @version 1.
|
|
861
|
+
* @version 1.3.4
|
|
864
862
|
*
|
|
865
863
|
* @param {Object} values The values to look for
|
|
866
864
|
* @param {Object} options Optional options object
|
|
@@ -869,7 +867,7 @@ Model.setMethod(function findByPk(pk, options, callback) {
|
|
|
869
867
|
*/
|
|
870
868
|
Model.setMethod(function findByValues(values, options) {
|
|
871
869
|
|
|
872
|
-
var criteria = new Blast.Classes.Alchemy.Criteria(),
|
|
870
|
+
var criteria = new Blast.Classes.Alchemy.Criteria(this),
|
|
873
871
|
key;
|
|
874
872
|
|
|
875
873
|
if (options) {
|
|
@@ -888,7 +886,7 @@ Model.setMethod(function findByValues(values, options) {
|
|
|
888
886
|
*
|
|
889
887
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
890
888
|
* @since 1.1.0
|
|
891
|
-
* @version 1.
|
|
889
|
+
* @version 1.3.4
|
|
892
890
|
*
|
|
893
891
|
* @param {Object} values The values to look for
|
|
894
892
|
* @param {Object} options Optional options object
|
|
@@ -897,7 +895,7 @@ Model.setMethod(function findByValues(values, options) {
|
|
|
897
895
|
*/
|
|
898
896
|
Model.setMethod(function findAllByValues(values, options) {
|
|
899
897
|
|
|
900
|
-
var criteria = new Blast.Classes.Alchemy.Criteria(),
|
|
898
|
+
var criteria = new Blast.Classes.Alchemy.Criteria(this),
|
|
901
899
|
key;
|
|
902
900
|
|
|
903
901
|
if (options) {
|
package/lib/class/conduit.js
CHANGED
|
@@ -1505,7 +1505,7 @@ Conduit.setMethod(function redirect(status, options) {
|
|
|
1505
1505
|
*
|
|
1506
1506
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1507
1507
|
* @since 0.2.0
|
|
1508
|
-
* @version 1.3.
|
|
1508
|
+
* @version 1.3.4
|
|
1509
1509
|
*
|
|
1510
1510
|
* @param {Nulber} status Response statuscode
|
|
1511
1511
|
* @param {Error} message Optional error to send
|
|
@@ -1551,7 +1551,7 @@ Conduit.setMethod(function error(status, message, print_error) {
|
|
|
1551
1551
|
|
|
1552
1552
|
if (print_dev) {
|
|
1553
1553
|
let subject = 'Error found on ' + this.original_path + '';
|
|
1554
|
-
log.error(subject
|
|
1554
|
+
log.error(subject, message, this);
|
|
1555
1555
|
} else if (print_error) {
|
|
1556
1556
|
let subject = 'Error found on ' + this.original_path + '';
|
|
1557
1557
|
|
|
@@ -1646,7 +1646,7 @@ Conduit.setMethod(function notAuthorized(tried_auth) {
|
|
|
1646
1646
|
* The current user is authenticated, but not allowed
|
|
1647
1647
|
* (Default implementation, is overriden by the acl plugin)
|
|
1648
1648
|
*
|
|
1649
|
-
* @author Jelle De Loecker <jelle@
|
|
1649
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1650
1650
|
* @since 1.0.7
|
|
1651
1651
|
* @version 1.1.0
|
|
1652
1652
|
*/
|
package/lib/class/document.js
CHANGED
|
@@ -573,7 +573,7 @@ Document.setMethod(function remove(callback) {
|
|
|
573
573
|
*
|
|
574
574
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
575
575
|
* @since 1.2.3
|
|
576
|
-
* @version 1.
|
|
576
|
+
* @version 1.3.4
|
|
577
577
|
*
|
|
578
578
|
* @param {Criteria|String} criteria
|
|
579
579
|
*
|
|
@@ -598,7 +598,7 @@ Document.setMethod(function preparePopulationCriteria(criteria) {
|
|
|
598
598
|
}
|
|
599
599
|
|
|
600
600
|
if (!Classes.Alchemy.Criteria.Criteria.isCriteria(criteria)) {
|
|
601
|
-
let new_criteria = new Classes.Alchemy.Criteria();
|
|
601
|
+
let new_criteria = new Classes.Alchemy.Criteria(model);
|
|
602
602
|
new_criteria.model = model;
|
|
603
603
|
new_criteria.applyOldConditions(criteria);
|
|
604
604
|
criteria = new_criteria;
|
|
@@ -780,7 +780,7 @@ Document.setMethod(async function revertTo(revision_id) {
|
|
|
780
780
|
*
|
|
781
781
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
782
782
|
* @since 1.0.3
|
|
783
|
-
* @version 1.
|
|
783
|
+
* @version 1.3.4
|
|
784
784
|
*
|
|
785
785
|
* @param {Number} revisions
|
|
786
786
|
*
|
|
@@ -813,7 +813,7 @@ Document.setMethod(function revert(revisions) {
|
|
|
813
813
|
record,
|
|
814
814
|
i;
|
|
815
815
|
|
|
816
|
-
criteria =
|
|
816
|
+
criteria = revision_model.find();
|
|
817
817
|
criteria.where('record_id', that.$pk);
|
|
818
818
|
criteria.where('revision').gt(target_revision).lte(that.__r);
|
|
819
819
|
criteria.sort({revision: -1});
|
package/lib/class/schema.js
CHANGED
|
@@ -35,6 +35,24 @@ var Schema = Function.inherits(['Deck', 'Alchemy.Base'], function Schema(parent)
|
|
|
35
35
|
this.init();
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Add a relation creator method
|
|
40
|
+
*
|
|
41
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
42
|
+
* @since 1.3.4
|
|
43
|
+
* @version 1.3.4
|
|
44
|
+
*
|
|
45
|
+
* @param {String} relation_type
|
|
46
|
+
*/
|
|
47
|
+
Schema.setStatic(function addRelationCreator(relation_type, relation_config) {
|
|
48
|
+
|
|
49
|
+
let method_name = relation_type[0].toLowerCase() + relation_type.slice(1);
|
|
50
|
+
|
|
51
|
+
this.setMethod(method_name, function _addAssociation(alias, model_name, options) {
|
|
52
|
+
this.addAssociation(relation_type, relation_config, alias, model_name, options);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
38
56
|
/**
|
|
39
57
|
* Revive a dried schema
|
|
40
58
|
*
|
|
@@ -224,129 +242,44 @@ Schema.setMethod(function getDatasource() {
|
|
|
224
242
|
});
|
|
225
243
|
});
|
|
226
244
|
|
|
227
|
-
/**
|
|
228
|
-
* Conform association arguments
|
|
229
|
-
*
|
|
230
|
-
* @author Jelle De Loecker <jelle@develry.be>
|
|
231
|
-
* @since 0.2.0
|
|
232
|
-
* @version 1.1.0
|
|
233
|
-
*
|
|
234
|
-
* @param {String} locality internal or external
|
|
235
|
-
* @param {String} _alias
|
|
236
|
-
* @param {String} _modelname
|
|
237
|
-
* @param {Object} _options
|
|
238
|
-
*/
|
|
239
|
-
Schema.setMethod(function getAssociationArguments(locality, alias, modelName, options) {
|
|
240
|
-
|
|
241
|
-
if (Object.isObject(modelName)) {
|
|
242
|
-
options = modelName;
|
|
243
|
-
modelName = undefined;
|
|
244
|
-
} else if (!Object.isObject(options)) {
|
|
245
|
-
options = {};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (typeof modelName === 'undefined') {
|
|
249
|
-
modelName = alias;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (options.localKey && typeof options.localKey == 'object') {
|
|
253
|
-
throw new Error('Local key for ' + alias + ' association can not be an object');
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (options.foreignKey && typeof options.foreignKey == 'object') {
|
|
257
|
-
throw new Error('Foreign key for ' + alias + ' association can not be an object');
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (locality == 'internal') {
|
|
261
|
-
|
|
262
|
-
if (!options.localKey) {
|
|
263
|
-
options.localKey = alias.foreign_key();
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (!options.foreignKey) {
|
|
267
|
-
let model = this.getModel(modelName);
|
|
268
|
-
options.foreignKey = model.primary_key || '_id';
|
|
269
|
-
}
|
|
270
|
-
} else {
|
|
271
|
-
|
|
272
|
-
if (!options.localKey) {
|
|
273
|
-
let model = this.getModel(modelName);
|
|
274
|
-
options.localKey = model.primary_key || '_id';
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (!options.foreignKey) {
|
|
278
|
-
options.foreignKey = this.name.foreign_key();
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return {alias: alias, modelName: modelName, options: options}
|
|
283
|
-
});
|
|
284
|
-
|
|
285
245
|
/**
|
|
286
246
|
* Add an association
|
|
287
247
|
*
|
|
288
248
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
289
249
|
* @since 0.2.0
|
|
290
|
-
* @version 1.
|
|
250
|
+
* @version 1.3.4
|
|
291
251
|
*
|
|
292
252
|
* @param {String} alias
|
|
253
|
+
* @param {Object} relation_config
|
|
293
254
|
* @param {String} modelname
|
|
294
255
|
* @param {Object} options
|
|
295
256
|
*
|
|
296
257
|
* @return {Object}
|
|
297
258
|
*/
|
|
298
|
-
Schema.setMethod(function addAssociation(type, alias, modelName, options) {
|
|
299
|
-
|
|
300
|
-
var constructor,
|
|
301
|
-
client_doc,
|
|
302
|
-
doc_class,
|
|
303
|
-
className,
|
|
304
|
-
locality,
|
|
305
|
-
singular,
|
|
306
|
-
path,
|
|
307
|
-
args;
|
|
259
|
+
Schema.setMethod(function addAssociation(type, relation_config, alias, modelName, options) {
|
|
308
260
|
|
|
309
261
|
if (this.name === alias) {
|
|
310
262
|
throw new Error('Can\'t add association with the same name as current model');
|
|
311
263
|
}
|
|
312
264
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
case 'HasOneParent':
|
|
316
|
-
case 'HasAndBelongsToMany':
|
|
317
|
-
case 'BelongsTo':
|
|
318
|
-
locality = 'internal';
|
|
319
|
-
break;
|
|
320
|
-
|
|
321
|
-
case 'HasMany':
|
|
322
|
-
case 'HasOneChild':
|
|
323
|
-
locality = 'external';
|
|
324
|
-
break;
|
|
325
|
-
|
|
326
|
-
default:
|
|
327
|
-
throw new TypeError('Association type "' + type + '" does not exist');
|
|
328
|
-
}
|
|
265
|
+
let is_internal = relation_config.internal === true,
|
|
266
|
+
is_singular = relation_config.singular === true;
|
|
329
267
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
break;
|
|
338
|
-
|
|
339
|
-
default:
|
|
340
|
-
singular = false;
|
|
341
|
-
}
|
|
268
|
+
let constructor,
|
|
269
|
+
client_doc,
|
|
270
|
+
doc_class,
|
|
271
|
+
className,
|
|
272
|
+
locality,
|
|
273
|
+
singular,
|
|
274
|
+
path;
|
|
342
275
|
|
|
343
|
-
args = this.getAssociationArguments(
|
|
276
|
+
let args = this.getAssociationArguments(is_internal, alias, modelName, options);
|
|
344
277
|
args.type = type;
|
|
345
278
|
|
|
346
279
|
alias = args.alias;
|
|
347
280
|
modelName = args.modelName;
|
|
348
281
|
options = args.options;
|
|
349
|
-
options.singular =
|
|
282
|
+
options.singular = is_singular;
|
|
350
283
|
className = this.model_name;
|
|
351
284
|
|
|
352
285
|
if (this.namespace) {
|
|
@@ -366,7 +299,7 @@ Schema.setMethod(function addAssociation(type, alias, modelName, options) {
|
|
|
366
299
|
}
|
|
367
300
|
|
|
368
301
|
// If the key is part of this model, make sure the field is added
|
|
369
|
-
if (
|
|
302
|
+
if (is_internal) {
|
|
370
303
|
|
|
371
304
|
if (!this.getField(options.localKey)) {
|
|
372
305
|
let field_options = Object.assign({}, args);
|
|
@@ -441,81 +374,6 @@ Schema.setMethod(function setEnumValues(name, values) {
|
|
|
441
374
|
this.enum_values[name] = values;
|
|
442
375
|
});
|
|
443
376
|
|
|
444
|
-
/**
|
|
445
|
-
* Add a belongsTo association
|
|
446
|
-
*
|
|
447
|
-
* @author Jelle De Loecker <jelle@develry.be>
|
|
448
|
-
* @since 0.2.0
|
|
449
|
-
* @version 0.2.0
|
|
450
|
-
*
|
|
451
|
-
* @param {String} alias
|
|
452
|
-
* @param {String} modelname
|
|
453
|
-
* @param {Object} options
|
|
454
|
-
*/
|
|
455
|
-
Schema.setMethod(function belongsTo(alias, modelName, options) {
|
|
456
|
-
this.addAssociation('BelongsTo', alias, modelName, options);
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* Add a hasOneParent association
|
|
461
|
-
*
|
|
462
|
-
* @author Jelle De Loecker <jelle@develry.be>
|
|
463
|
-
* @since 0.2.0
|
|
464
|
-
* @version 0.2.0
|
|
465
|
-
*
|
|
466
|
-
* @param {String} alias
|
|
467
|
-
* @param {String} modelname
|
|
468
|
-
* @param {Object} options
|
|
469
|
-
*/
|
|
470
|
-
Schema.setMethod(function hasOneParent(alias, modelName, options) {
|
|
471
|
-
this.addAssociation('HasOneParent', alias, modelName, options);
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* Add a HABTM association
|
|
476
|
-
*
|
|
477
|
-
* @author Jelle De Loecker <jelle@develry.be>
|
|
478
|
-
* @since 0.2.0
|
|
479
|
-
* @version 0.2.0
|
|
480
|
-
*
|
|
481
|
-
* @param {String} alias
|
|
482
|
-
* @param {String} modelname
|
|
483
|
-
* @param {Object} options
|
|
484
|
-
*/
|
|
485
|
-
Schema.setMethod(function hasAndBelongsToMany(alias, modelName, options) {
|
|
486
|
-
this.addAssociation('HasAndBelongsToMany', alias, modelName, options);
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* Add a hasMany association
|
|
491
|
-
*
|
|
492
|
-
* @author Jelle De Loecker <jelle@develry.be>
|
|
493
|
-
* @since 0.2.0
|
|
494
|
-
* @version 0.2.0
|
|
495
|
-
*
|
|
496
|
-
* @param {String} alias
|
|
497
|
-
* @param {String} modelname
|
|
498
|
-
* @param {Object} options
|
|
499
|
-
*/
|
|
500
|
-
Schema.setMethod(function hasMany(alias, modelName, options) {
|
|
501
|
-
this.addAssociation('HasMany', alias, modelName, options);
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Add a hasOneChild association
|
|
506
|
-
*
|
|
507
|
-
* @author Jelle De Loecker <jelle@develry.be>
|
|
508
|
-
* @since 0.2.0
|
|
509
|
-
* @version 0.2.0
|
|
510
|
-
*
|
|
511
|
-
* @param {String} alias
|
|
512
|
-
* @param {String} modelname
|
|
513
|
-
* @param {Object} options
|
|
514
|
-
*/
|
|
515
|
-
Schema.setMethod(function hasOneChild(alias, modelName, options) {
|
|
516
|
-
this.addAssociation('HasOneChild', alias, modelName, options);
|
|
517
|
-
});
|
|
518
|
-
|
|
519
377
|
/**
|
|
520
378
|
* Clone
|
|
521
379
|
*
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @param {Schema} parent
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
const Schema = Function.inherits(['Deck', 'Alchemy.Client.Base'], 'Alchemy.Client', function Schema(parent) {
|
|
14
14
|
|
|
15
15
|
Blast.Classes.Deck.call(this);
|
|
16
16
|
Schema.super.call(this);
|
|
@@ -18,6 +18,24 @@ var Schema = Function.inherits(['Deck', 'Alchemy.Client.Base'], 'Alchemy.Client'
|
|
|
18
18
|
this.init();
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Add a relation creator method
|
|
23
|
+
*
|
|
24
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
25
|
+
* @since 1.3.4
|
|
26
|
+
* @version 1.3.4
|
|
27
|
+
*
|
|
28
|
+
* @param {String} relation_type
|
|
29
|
+
*/
|
|
30
|
+
Schema.setStatic(function addRelationCreator(relation_type, relation_config) {
|
|
31
|
+
|
|
32
|
+
let method_name = relation_type[0].toLowerCase() + relation_type.slice(1);
|
|
33
|
+
|
|
34
|
+
this.setMethod(method_name, function _addAssociation(alias, model_name, options) {
|
|
35
|
+
this.addAssociation(relation_type, relation_config, alias, model_name, options);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
21
39
|
/**
|
|
22
40
|
* Is the given variable a schema?
|
|
23
41
|
*
|
|
@@ -147,6 +165,144 @@ Schema.setProperty(function has_translatable_fields() {
|
|
|
147
165
|
return this.has_translations;
|
|
148
166
|
});
|
|
149
167
|
|
|
168
|
+
/**
|
|
169
|
+
* Add the relationships
|
|
170
|
+
*
|
|
171
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
172
|
+
* @since 0.2.0
|
|
173
|
+
* @version 1.3.4
|
|
174
|
+
*/
|
|
175
|
+
Schema.addRelationCreator('BelongsTo', {internal: true, singular: true});
|
|
176
|
+
Schema.addRelationCreator('HasOneParent', {internal: true, singular: true});
|
|
177
|
+
Schema.addRelationCreator('HasAndBelongsToMany', {internal: true, singular: false});
|
|
178
|
+
Schema.addRelationCreator('HasMany', {internal: false, singular: false});
|
|
179
|
+
Schema.addRelationCreator('HasOneChild', {internal: false, singular: true});
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Browser-side association adder
|
|
183
|
+
*
|
|
184
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
185
|
+
* @since 1.3.4
|
|
186
|
+
* @version 1.3.4
|
|
187
|
+
*
|
|
188
|
+
* @param {String} alias
|
|
189
|
+
* @param {String} modelname
|
|
190
|
+
* @param {Object} options
|
|
191
|
+
*
|
|
192
|
+
* @return {Object}
|
|
193
|
+
*/
|
|
194
|
+
Schema.setMethod(function addAssociation(relation_type, relation_config, alias, model_name, options) {
|
|
195
|
+
|
|
196
|
+
if (!options) {
|
|
197
|
+
options = {};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
let is_internal = relation_config.internal === true,
|
|
201
|
+
is_singular = relation_config.singular === true;
|
|
202
|
+
|
|
203
|
+
let args = this.getAssociationArguments(is_internal, alias, model_name, options);
|
|
204
|
+
alias = args.alias;
|
|
205
|
+
model_name = args.model_name;
|
|
206
|
+
|
|
207
|
+
let class_name = this.model_name || model_name,
|
|
208
|
+
client_doc,
|
|
209
|
+
path;
|
|
210
|
+
|
|
211
|
+
if (this.namespace) {
|
|
212
|
+
path = this.namespace + '.' + class_name;
|
|
213
|
+
} else {
|
|
214
|
+
path = class_name;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
client_doc = Classes.Alchemy.Client.Document.Document.getDocumentClass(class_name);
|
|
218
|
+
|
|
219
|
+
if (is_internal) {
|
|
220
|
+
if (!this.getField(options.local_key)) {
|
|
221
|
+
let field_options = {...args};
|
|
222
|
+
|
|
223
|
+
if (options && options.field_options) {
|
|
224
|
+
Object.assign(field_options, options.field_options);
|
|
225
|
+
field_options.field_options = undefined;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
this.addField(options.local_key, relation_type, field_options);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (client_doc) {
|
|
233
|
+
client_doc.setAliasGetter(alias);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Conform association arguments
|
|
239
|
+
*
|
|
240
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
241
|
+
* @since 0.2.0
|
|
242
|
+
* @version 1.3.4
|
|
243
|
+
*
|
|
244
|
+
* @param {Boolean} is_internal Is this internal (A remote record's id is stored inside this record)
|
|
245
|
+
* @param {String} alias
|
|
246
|
+
* @param {String} model_name
|
|
247
|
+
* @param {Object} options
|
|
248
|
+
*/
|
|
249
|
+
Schema.setMethod(function getAssociationArguments(is_internal, alias, model_name, options) {
|
|
250
|
+
|
|
251
|
+
if (Object.isObject(model_name)) {
|
|
252
|
+
options = model_name;
|
|
253
|
+
model_name = undefined;
|
|
254
|
+
} else if (!Object.isObject(options)) {
|
|
255
|
+
options = {};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (typeof model_name === 'undefined') {
|
|
259
|
+
model_name = alias;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
let local_key = options.local_key || options.localKey || false,
|
|
263
|
+
foreign_key = options.foreign_key || options.foreignKey || false;
|
|
264
|
+
|
|
265
|
+
if (typeof local_key == 'object') {
|
|
266
|
+
throw new Error('Local key for ' + alias + ' association can not be an object');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (typeof foreign_key == 'object') {
|
|
270
|
+
throw new Error('Foreign key for ' + alias + ' association can not be an object');
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (is_internal) {
|
|
274
|
+
|
|
275
|
+
if (!local_key) {
|
|
276
|
+
local_key = alias.foreign_key();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (!foreign_key) {
|
|
280
|
+
let model = this.getModel(model_name);
|
|
281
|
+
foreign_key = model.primary_key || '_id';
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
|
|
285
|
+
if (!local_key) {
|
|
286
|
+
let model = this.getModel(model_name);
|
|
287
|
+
local_key = model.primary_key || '_id';
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (!foreign_key) {
|
|
291
|
+
foreign_key = this.name.foreign_key();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
options.local_key = options.localKey = local_key;
|
|
296
|
+
options.foreign_key = options.foreignKey = foreign_key;
|
|
297
|
+
|
|
298
|
+
return {
|
|
299
|
+
alias : alias,
|
|
300
|
+
model_name,
|
|
301
|
+
modelName : model_name,
|
|
302
|
+
options : options
|
|
303
|
+
};
|
|
304
|
+
});
|
|
305
|
+
|
|
150
306
|
/**
|
|
151
307
|
* Clone for JSON-Dry (JSON.clone())
|
|
152
308
|
*
|
package/lib/class/sitemap.js
CHANGED
|
@@ -346,4 +346,61 @@ Sitemap.setMethod(function addRouteWithParameters(route, config, parameters, for
|
|
|
346
346
|
|
|
347
347
|
this.addUrl(config.category, url, route_config, prefix);
|
|
348
348
|
}
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Create an XML builder
|
|
353
|
+
*
|
|
354
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
355
|
+
* @since 1.3.4
|
|
356
|
+
* @version 1.3.4
|
|
357
|
+
*
|
|
358
|
+
* @return {Hawkejs.Builder}
|
|
359
|
+
*/
|
|
360
|
+
Sitemap.setMethod(function getXmlBuilder() {
|
|
361
|
+
|
|
362
|
+
let xml = Classes.Hawkejs.Builder.create({xml: true}),
|
|
363
|
+
urlset = xml.ele('urlset');
|
|
364
|
+
|
|
365
|
+
urlset.att('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance')
|
|
366
|
+
.att('xmlns:image', 'http://www.google.com/schemas/sitemap-image/1.1')
|
|
367
|
+
.att('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd')
|
|
368
|
+
.att('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
|
|
369
|
+
|
|
370
|
+
let categories = this.getCategories();
|
|
371
|
+
|
|
372
|
+
for (let category of categories) {
|
|
373
|
+
for (let info of category) {
|
|
374
|
+
let url = urlset.ele(url);
|
|
375
|
+
|
|
376
|
+
url.ele('loc').txt(info.url);
|
|
377
|
+
|
|
378
|
+
if (info.lastmod) {
|
|
379
|
+
url.ele('lastmod').txt(info.lastmod);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (info.changefreq) {
|
|
383
|
+
url.ele('changefreq').txt(info.changefreq);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (info.priority) {
|
|
387
|
+
url.ele('priority').txt(info.priority);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return xml;
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Get the XML representation
|
|
397
|
+
*
|
|
398
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
399
|
+
* @since 1.3.4
|
|
400
|
+
* @version 1.3.4
|
|
401
|
+
*
|
|
402
|
+
* @return {String}
|
|
403
|
+
*/
|
|
404
|
+
Sitemap.setMethod(function getXml() {
|
|
405
|
+
return this.getXmlBuilder().end();
|
|
349
406
|
});
|
package/lib/core/middleware.js
CHANGED
|
@@ -311,7 +311,7 @@ Alchemy.setMethod(function sourcemapMiddleware(req, res, nextMiddleware) {
|
|
|
311
311
|
*
|
|
312
312
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
313
313
|
* @since 0.2.0
|
|
314
|
-
* @version 1.3.
|
|
314
|
+
* @version 1.3.4
|
|
315
315
|
*
|
|
316
316
|
* @param {String} path
|
|
317
317
|
* @param {Object} options
|
|
@@ -407,9 +407,18 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
|
|
|
407
407
|
|
|
408
408
|
async function serveCode(data) {
|
|
409
409
|
|
|
410
|
-
|
|
410
|
+
let result;
|
|
411
|
+
let should_minify = false;
|
|
411
412
|
|
|
412
413
|
if (alchemy.settings.minify_js) {
|
|
414
|
+
let index = data.indexOf('@alchemy.minify.false');
|
|
415
|
+
|
|
416
|
+
if (index == -1 || index > 50) {
|
|
417
|
+
should_minify = true;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (should_minify) {
|
|
413
422
|
|
|
414
423
|
// Force Blast.isNode & Blast.isBrowser to be replaced later
|
|
415
424
|
data = data.replaceAll('Blast.isNode', '__BLAST_IS_NODE');
|
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.4",
|
|
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.3.
|
|
25
|
+
"hawkejs" : "~2.3.4",
|
|
26
26
|
"jsondiffpatch" : "~0.4.1",
|
|
27
27
|
"mime" : "~3.0.0",
|
|
28
28
|
"minimist" : "~1.2.5",
|