alchemymvc 1.2.0 → 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.
@@ -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@develry.be>
540
- * @since 0.2.0
541
- * @version 1.1.0
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 {Pledge}
545
+ * @return {Criteria}
547
546
  */
548
- Document.setMethod(['populate', 'addAssociatedData'], function addAssociatedData(criteria, callback) {
547
+ Document.setMethod(function preparePopulationCriteria(criteria) {
549
548
 
550
- var that = this,
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 model.addAssociatedDataToRecord(criteria, this.$record, callback);
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.1.0
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
  });
@@ -23,12 +23,17 @@ Function.getNamespace('Alchemy.Element').setStatic('default_element_prefix', 'al
23
23
  *
24
24
  * @author Jelle De Loecker <jelle@elevenways.be>
25
25
  * @since 1.1.3
26
- * @version 1.1.3
26
+ * @version 1.2.1
27
27
  *
28
28
  * @return {RURL}
29
29
  */
30
30
  Element.setMethod(function getCurrentUrl() {
31
31
  if (Blast.isBrowser) {
32
+
33
+ if (hawkejs.scene.opening_url && hawkejs.scene.opening_url.url) {
34
+ return Blast.Classes.RURL.parse(hawkejs.scene.opening_url.url);
35
+ }
36
+
32
37
  return Blast.Classes.RURL.parse(window.location);
33
38
  } else if (this.hawkejs_renderer && this.hawkejs_renderer.variables && this.hawkejs_renderer.variables.__url) {
34
39
  return this.hawkejs_renderer.variables.__url.clone();
@@ -287,7 +287,7 @@ Schema.setMethod(function getAssociationArguments(locality, alias, modelName, op
287
287
  *
288
288
  * @author Jelle De Loecker <jelle@develry.be>
289
289
  * @since 0.2.0
290
- * @version 1.1.0
290
+ * @version 1.2.2
291
291
  *
292
292
  * @param {String} alias
293
293
  * @param {String} modelname
@@ -369,7 +369,14 @@ Schema.setMethod(function addAssociation(type, alias, modelName, options) {
369
369
  if (locality == 'internal') {
370
370
 
371
371
  if (!this.getField(options.localKey)) {
372
- this.addField(options.localKey, type, args);
372
+ let field_options = Object.assign({}, args);
373
+
374
+ if (options && options.field_options) {
375
+ Object.assign(field_options, options.field_options);
376
+ field_options.field_options = undefined;
377
+ }
378
+
379
+ this.addField(options.localKey, type, field_options);
373
380
 
374
381
  if (constructor) {
375
382
  doc_class.setFieldGetter(options.localKey);
package/lib/core/base.js CHANGED
@@ -416,19 +416,28 @@ Base.setMethod(function getClassPathAfter(after) {
416
416
  /**
417
417
  * Call a method if it exists or do the callback
418
418
  *
419
- * @author Jelle De Loecker <jelle@develry.be>
419
+ * @author Jelle De Loecker <jelle@elevenways.be>
420
420
  * @since 1.0.0
421
- * @version 1.0.0
421
+ * @version 1.2.2
422
422
  */
423
423
  Base.setMethod(function callOrNext(name, args, next) {
424
424
 
425
+ if (arguments.length == 2 && typeof args == 'function') {
426
+ next = args;
427
+ args = [];
428
+ }
429
+
425
430
  if (typeof this[name] == 'function') {
426
431
 
427
432
  if (next) {
428
433
  args.push(next);
429
434
  }
430
435
 
431
- this[name].apply(this, args);
436
+ try {
437
+ this[name].apply(this, args);
438
+ } catch (err) {
439
+ next(err);
440
+ }
432
441
  } else if (next) {
433
442
  next();
434
443
 
@@ -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
  *
@@ -1066,4 +1077,18 @@ Alchemy.setMethod(function syncDataWithServer() {
1066
1077
  });
1067
1078
 
1068
1079
  return Function.parallel(tasks);
1080
+ });
1081
+
1082
+ /**
1083
+ * Create a new schema on the client
1084
+ *
1085
+ * @author Jelle De Loecker <jelle@elevenways.be>
1086
+ * @since 1.2.1
1087
+ * @version 1.2.1
1088
+ *
1089
+ * @param {*} parent
1090
+ */
1091
+ Alchemy.setMethod(function createSchema(parent) {
1092
+ let schema = new Classes.Alchemy.Client.Schema(parent);
1093
+ return schema;
1069
1094
  });
@@ -751,7 +751,6 @@ Alchemy.setMethod(function use(module_name, register_as, options) {
751
751
  return module;
752
752
  });
753
753
 
754
-
755
754
  /**
756
755
  * Look for a module by traversing the filesystem
757
756
  *
@@ -878,7 +877,7 @@ Alchemy.setMethod(function searchModule(startPath, moduleName, recurse) {
878
877
  *
879
878
  * @author Jelle De Loecker <jelle@develry.be>
880
879
  * @since 0.0.1
881
- * @version 1.1.0
880
+ * @version 1.2.2
882
881
  *
883
882
  * @param {String} moduleName
884
883
  * @param {Object} options
@@ -949,20 +948,26 @@ Alchemy.setMethod(function findModule(moduleName, options) {
949
948
  // If the module_path was found, actually require the module
950
949
  if (module_path) {
951
950
 
952
- // Modules are required by default
953
- if (options.require) {
954
- module = require(module_path);
955
- }
956
-
957
951
  // Get the package.json file
958
952
  if (~module_path.indexOf(libpath.sep)) {
959
953
  internal = false;
960
954
 
955
+ let last_piece = moduleName.split(libpath.sep).last(),
956
+ package_path;
957
+
961
958
  let module_dir = libpath.dirname(module_path);
962
959
  result.module_dir = module_dir;
963
960
 
961
+ // If the path doesn't end with the module name, look for it
962
+ if (!module_path.endsWith(last_piece)) {
963
+ package_path = module_path.beforeLast(last_piece) + last_piece;
964
+ package_path = libpath.resolve(package_path, 'package.json');
965
+ } else {
966
+ package_path = libpath.resolve(module_dir, 'package.json');
967
+ }
968
+
964
969
  try {
965
- package_json = require(libpath.resolve(module_dir, 'package.json'));
970
+ package_json = require(package_path);
966
971
  } catch (err) {
967
972
  package_json = false;
968
973
  }
@@ -972,6 +977,15 @@ Alchemy.setMethod(function findModule(moduleName, options) {
972
977
  version: process.versions.node
973
978
  };
974
979
  }
980
+
981
+ // Modules are required by default
982
+ if (options.require) {
983
+ if (package_json && package_json.type == 'module' && !(package_json.main && package_json.module)) {
984
+ module = doImport(module_path)
985
+ } else {
986
+ module = require(module_path);
987
+ }
988
+ }
975
989
  }
976
990
 
977
991
  if (!options.require || module) {
@@ -1721,6 +1735,20 @@ Alchemy.setMethod(function importFromStream(input, options) {
1721
1735
  return pledge;
1722
1736
  });
1723
1737
 
1738
+ /**
1739
+ * Create a new schema
1740
+ *
1741
+ * @author Jelle De Loecker <jelle@elevenways.be>
1742
+ * @since 1.2.1
1743
+ * @version 1.2.1
1744
+ *
1745
+ * @param {*} parent
1746
+ */
1747
+ Alchemy.setMethod(function createSchema(parent) {
1748
+ let schema = new Classes.Alchemy.Schema(parent);
1749
+ return schema;
1750
+ });
1751
+
1724
1752
  /**
1725
1753
  * The alchemy global, where everything will be stored
1726
1754
  *
@@ -1082,7 +1082,7 @@ Alchemy.setMethod(function downloadFile(url, options, callback) {
1082
1082
  file = fs.createWriteStream(filepath);
1083
1083
 
1084
1084
  if (res.statusCode == 404) {
1085
- err = new Error('Path does not exist');
1085
+ err = new Error('Path "' + url + '" does not exist');
1086
1086
  err.number = 404;
1087
1087
 
1088
1088
  return callback(err);
@@ -1325,7 +1325,7 @@ Alchemy.setMethod(function exposeStatic(name, value) {
1325
1325
  *
1326
1326
  * @author Jelle De Loecker <jelle@develry.be>
1327
1327
  * @since 1.1.0
1328
- * @version 1.1.0
1328
+ * @version 1.2.1
1329
1329
  */
1330
1330
  Alchemy.setMethod(function exposeDefaultStaticVariables() {
1331
1331
 
@@ -1372,6 +1372,9 @@ Alchemy.setMethod(function exposeDefaultStaticVariables() {
1372
1372
 
1373
1373
  hawkejs.exposeStatic('app_version', app_version);
1374
1374
  hawkejs.app_version = app_version;
1375
+
1376
+ // Emit as a global event so plugins can also expose their data
1377
+ this.emit('generate_static_variables', hawkejs);
1375
1378
  });
1376
1379
 
1377
1380
  /**
@@ -813,7 +813,7 @@ Alchemy.setMethod(function startPlugins(names) {
813
813
  *
814
814
  * @author Jelle De Loecker <jelle@develry.be>
815
815
  * @since 0.0.1
816
- * @version 1.1.0
816
+ * @version 1.2.2
817
817
  *
818
818
  * @param {String|Array} names
819
819
  * @param {Boolean} attempt_require
@@ -844,8 +844,13 @@ Alchemy.setMethod(function requirePlugin(names, attempt_require) {
844
844
  temp = alchemy.usePlugin(name);
845
845
 
846
846
  if (temp) {
847
- // Also start the plugin!
848
- alchemy.startPlugins(name);
847
+ let plugin_stage = alchemy.sputnik.get('plugins');
848
+
849
+ if (!plugin_stage || plugin_stage.started) {
850
+ // If the plugin stage has already started,
851
+ // manually start this plugin now
852
+ alchemy.startPlugins(name);
853
+ }
849
854
  continue;
850
855
  }
851
856
  }
@@ -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 = new Classes.Hawkejs.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.0",
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.0",
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.10",
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",