alchemymvc 1.4.0-alpha.7 → 1.4.0-alpha.9

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.
@@ -680,6 +680,11 @@ Model.setMethod(function getAliasModel(alias) {
680
680
  config = this.schema.associations[alias];
681
681
  }
682
682
 
683
+ // @TODO: associated fields with an alias name inside a nested schema
684
+ // somehow breaks! Should be looked in to?
685
+ // Workaround: set `recursive: 0` on the root schema field
686
+ // console.log('Alias:', alias, 'config:', config, this.schema);
687
+
683
688
  if (config) {
684
689
  result = this.getModel(config.modelName);
685
690
  } else {
@@ -144,11 +144,19 @@ SystemSetting.setDocumentMethod(function applySetting(do_actions = true) {
144
144
 
145
145
  if (!existing_value) {
146
146
  existing_value = setting.generateValue();
147
+ alchemy.system_settings.forceValueInstanceAtPath(this.setting_id, existing_value);
147
148
  }
148
149
 
150
+ let result;
151
+
149
152
  if (do_actions) {
150
- return existing_value.setValue(this.configuration.value);
153
+ result = existing_value.setValue(this.configuration.value);
151
154
  } else {
152
- return existing_value.setValueSilently(this.configuration.value);
155
+ result = existing_value.setValueSilently(this.configuration.value);
153
156
  }
157
+
158
+ // And now force the settings to update!
159
+ alchemy.refreshSettingsObject();
160
+
161
+ return result;
154
162
  });
@@ -511,7 +511,7 @@ Conduit.setMethod(function time() {
511
511
  *
512
512
  * @author Jelle De Loecker <jelle@elevenways.be>
513
513
  * @since 0.2.0
514
- * @version 1.3.18
514
+ * @version 1.4.0
515
515
  *
516
516
  * @param {IncomingMessage} req
517
517
  * @param {ServerResponse} res
@@ -541,7 +541,7 @@ Conduit.setMethod(async function parseRequest() {
541
541
  }
542
542
 
543
543
  if (this.rewritten_request_route_param) {
544
- let params = Object.assign({}, this.route_string_parameters, this.rewritten_request_route_param);
544
+ let params = Object.assign({...this.url.query}, this.route_string_parameters, this.rewritten_request_route_param);
545
545
  let new_url = this.route.generateUrl(params, this);
546
546
  this.overrideResponseUrl(new_url);
547
547
  }
@@ -679,21 +679,26 @@ Model.setMethod(function disableTranslations() {
679
679
  *
680
680
  * @author Jelle De Loecker <jelle@elevenways.be>
681
681
  * @since 0.5.0
682
- * @version 0.5.0
682
+ * @version 1.4.0
683
683
  *
684
684
  * @param {Array} pipeline
685
685
  * @param {Function} callback
686
686
  */
687
- Model.setMethod(function aggregate(pipeline, callback) {
687
+ Model.setMethod(async function aggregate(pipeline, callback) {
688
688
 
689
- this.datasource.collection(this.table, function gotCollection(err, collection) {
689
+ let collection = await this.datasource.collection(this.table);
690
690
 
691
- if (err) {
692
- return callback(err);
693
- }
691
+ if (err) {
692
+ return pledge.reject(err);
693
+ }
694
694
 
695
- collection.aggregate(pipeline, callback);
696
- });
695
+ let cursor = collection.aggregate(pipeline);
696
+
697
+ if (typeof callback == 'function') {
698
+ callback(null, cursor);
699
+ }
700
+
701
+ return cursor;
697
702
  });
698
703
 
699
704
  /**
@@ -17,7 +17,7 @@ let shared_objects = {},
17
17
  *
18
18
  * @author Jelle De Loecker <jelle@elevenways.be>
19
19
  * @since 0.0.1
20
- * @version 1.3.21
20
+ * @version 1.4.0
21
21
  */
22
22
  global.Alchemy = Function.inherits('Alchemy.Base', function Alchemy() {
23
23
 
@@ -147,7 +147,6 @@ global.Alchemy = Function.inherits('Alchemy.Base', function Alchemy() {
147
147
  this.text_body = this.use('body');
148
148
  this.formidable = this.use('formidable');
149
149
  this.body_parser = this.use('body-parser');
150
- this.url_form_body = this.body_parser.urlencoded({extended: true});
151
150
  });
152
151
 
153
152
  /**
@@ -581,10 +580,21 @@ Alchemy.setMethod(function setSetting(path, value) {
581
580
  this.system_settings.setPathSilently(path, value);
582
581
 
583
582
  if (this.started) {
584
- this.settings = this.system_settings.toObject();
583
+ this.refreshSettingsObject();
585
584
  }
586
585
  });
587
586
 
587
+ /**
588
+ * Refresh the settings object
589
+ *
590
+ * @author Jelle De Loecker <jelle@elevenways.be>
591
+ * @since 1.4.0
592
+ * @version 1.4.0
593
+ */
594
+ Alchemy.setMethod(function refreshSettingsObject() {
595
+ this.settings = this.system_settings.toObject();
596
+ });
597
+
588
598
  /**
589
599
  * Get a setting value
590
600
  *
@@ -1879,7 +1889,12 @@ Alchemy.setMethod(function parseRequestBody(req, res, callback) {
1879
1889
  // Regular form-encoded data
1880
1890
  if (content_type && content_type.indexOf('form-urlencoded') > -1) {
1881
1891
 
1882
- this.url_form_body(req, res, {limit: request_body_size_limit}, function parsedBody(err) {
1892
+ let url_form_body = this.body_parser.urlencoded({
1893
+ limit: request_body_size_limit,
1894
+ extended: true,
1895
+ });
1896
+
1897
+ url_form_body(req, res, function parsedBody(err) {
1883
1898
 
1884
1899
  if (err) {
1885
1900
 
@@ -1159,7 +1159,7 @@ function convertDataUriToFile(data_uri) {
1159
1159
  *
1160
1160
  * @author Jelle De Loecker <jelle@elevenways.be>
1161
1161
  * @since 1.3.0
1162
- * @version 1.3.0
1162
+ * @version 1.4.0
1163
1163
  *
1164
1164
  * @param {string} url
1165
1165
  *
@@ -1226,10 +1226,14 @@ Alchemy.setMethod(function download(url, options) {
1226
1226
  }
1227
1227
 
1228
1228
  if (!name) {
1229
- name = alchemy.ObjectId();
1229
+ name = alchemy.ObjectId() + '';
1230
1230
  }
1231
1231
  }
1232
1232
 
1233
+ if (!name || typeof name != 'string') {
1234
+ name = alchemy.ObjectId() + '';
1235
+ }
1236
+
1233
1237
  if (name.indexOf('/') > -1) {
1234
1238
  name = name.replaceAll('/', '-');
1235
1239
  }
package/lib/core/base.js CHANGED
@@ -564,7 +564,7 @@ Base.setMethod(function attachConduit(conduit) {
564
564
  *
565
565
  * @author Jelle De Loecker <jelle@elevenways.be>
566
566
  * @since 0.3.0
567
- * @version 1.1.8
567
+ * @version 1.4.0
568
568
  *
569
569
  * @param {string} name The name of the model to get
570
570
  * @param {boolean} init Initialize the class [true]
@@ -597,9 +597,9 @@ Base.setMethod(function getModel(name, init, options) {
597
597
 
598
598
  if (options.cache !== false) {
599
599
  if (!this._modelInstances) {
600
- this._modelInstances = {};
600
+ this._modelInstances = new Map();
601
601
  } else {
602
- instance = this._modelInstances[name];
602
+ instance = this._modelInstances.get(name);
603
603
  }
604
604
  }
605
605
 
@@ -622,7 +622,7 @@ Base.setMethod(function getModel(name, init, options) {
622
622
  }
623
623
 
624
624
  if (options.cache !== false) {
625
- this._modelInstances[name] = instance;
625
+ this._modelInstances.set(name, instance);
626
626
  }
627
627
 
628
628
  return instance;
@@ -452,6 +452,9 @@ const Group = Function.inherits('Alchemy.Setting.Base', function Group(name, con
452
452
 
453
453
  // All the children
454
454
  this.children = new Map();
455
+
456
+ // Weak references to existing values
457
+ this.weak_values = new Blast.Classes.WeakValueSet();
455
458
  });
456
459
 
457
460
  /**
@@ -583,6 +586,14 @@ Group.setMethod(function createGroup(name) {
583
586
  let group = new Group(name, this);
584
587
  this.children.set(name, group);
585
588
 
589
+ if (this.weak_values.size) {
590
+ let group_value = group.generateValue();
591
+
592
+ for (let existing of this.weak_values) {
593
+ this.setDefaultValue(existing, {[name]: group_value});
594
+ }
595
+ }
596
+
586
597
  return group;
587
598
  });
588
599
 
@@ -633,6 +644,8 @@ Group.setMethod(function generateValue() {
633
644
 
634
645
  this.setDefaultValue(result, object);
635
646
 
647
+ this.weak_values.add(result);
648
+
636
649
  return result;
637
650
  });
638
651
 
@@ -1344,6 +1357,38 @@ GroupValue.setMethod(function _setPath(silent, path, raw_value) {
1344
1357
  return this.getPath(path);
1345
1358
  });
1346
1359
 
1360
+ /**
1361
+ * Force a value at the given path
1362
+ *
1363
+ * @author Jelle De Loecker <jelle@elevenways.be>
1364
+ * @since 1.4.0
1365
+ * @version 1.4.0
1366
+ *
1367
+ * @param {string|Array} path
1368
+ * @param {Value}
1369
+ */
1370
+ GroupValue.setMethod(function forceValueInstanceAtPath(path, value) {
1371
+
1372
+ if (typeof path == 'string') {
1373
+ path = path.split('.');
1374
+ }
1375
+
1376
+ if (this.definition.group == null && path[0] == this.definition.name) {
1377
+ path.shift();
1378
+ }
1379
+
1380
+ let last = path.pop();
1381
+
1382
+ let current = this;
1383
+
1384
+ while (path.length && current) {
1385
+ let next = path.shift();
1386
+ current = current.get(next);
1387
+ }
1388
+
1389
+ current[VALUE][last] = value;
1390
+ });
1391
+
1347
1392
  /**
1348
1393
  * Convert to a datasource array
1349
1394
  *
@@ -1584,6 +1629,20 @@ Value.setMethod(function getPath(path) {
1584
1629
  return current;
1585
1630
  });
1586
1631
 
1632
+ /**
1633
+ * Force a value at the given path
1634
+ *
1635
+ * @author Jelle De Loecker <jelle@elevenways.be>
1636
+ * @since 1.4.0
1637
+ * @version 1.4.0
1638
+ *
1639
+ * @param {string|Array} path
1640
+ * @param {Value}
1641
+ */
1642
+ Value.setMethod(function forceValueInstanceAtPath(path, value) {
1643
+ throw new Error('Unable to perform on a simple Value instance');
1644
+ });
1645
+
1587
1646
  if (Blast.isBrowser) {
1588
1647
  return;
1589
1648
  }
@@ -1675,15 +1734,61 @@ const MagicGroupValue = Function.inherits('Magic', 'Alchemy.Setting', function M
1675
1734
  */
1676
1735
  MagicGroupValue.setMethod(function __get(key) {
1677
1736
 
1678
- let result = this[VALUE].get(key);
1737
+ let result = this[key];
1738
+
1739
+ if (result != null) {
1740
+ return result;
1741
+ }
1742
+
1743
+ result = this[VALUE].get(key);
1744
+
1745
+ if (result == null) {
1746
+ return this[VALUE][key];
1747
+ }
1679
1748
 
1680
1749
  if (!result) {
1681
- return;
1750
+ return result;
1682
1751
  }
1683
1752
 
1684
1753
  if (result.is_group) {
1685
1754
  return result.toProxyObject();
1686
1755
  }
1687
1756
 
1757
+ if (!result.get) {
1758
+ return result;
1759
+ }
1760
+
1688
1761
  return result.get();
1762
+ });
1763
+
1764
+ /**
1765
+ * The magic getter
1766
+ *
1767
+ * @author Jelle De Loecker <jelle@elevenways.be>
1768
+ * @since 1.4.0
1769
+ * @version 1.4.0
1770
+ *
1771
+ * @param {string} key
1772
+ */
1773
+ MagicGroupValue.setMethod(function __ownKeys() {
1774
+ return Object.keys(this[VALUE].toObject())
1775
+ });
1776
+
1777
+ /**
1778
+ * The magic getter
1779
+ *
1780
+ * @author Jelle De Loecker <jelle@elevenways.be>
1781
+ * @since 1.4.0
1782
+ * @version 1.4.0
1783
+ *
1784
+ * @param {string} key
1785
+ */
1786
+ MagicGroupValue.setMethod(function __describe(key) {
1787
+ let result = Object.getOwnPropertyDescriptor(this[VALUE], key);
1788
+
1789
+ if (result == null) {
1790
+ result = Object.getOwnPropertyDescriptor(this, key);
1791
+ }
1792
+
1793
+ return result;
1689
1794
  });
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.4.0-alpha.7",
4
+ "version": "1.4.0-alpha.9",
5
5
  "author": "Jelle De Loecker <jelle@elevenways.be>",
6
6
  "keywords": [
7
7
  "alchemy",