alchemymvc 1.4.0-alpha.4 → 1.4.0-alpha.6

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.
@@ -131,7 +131,11 @@ Mongo.setMethod(function castToBigInt(value) {
131
131
  }
132
132
 
133
133
  if (typeof value == 'object') {
134
- return value.toBigInt();
134
+ if (value.toBigInt) {
135
+ return value.toBigInt();
136
+ }
137
+
138
+ return null;
135
139
  }
136
140
 
137
141
  return BigInt(value);
@@ -487,9 +491,21 @@ Mongo.setMethod(function _create(context) {
487
491
  this.collection(model.table),
488
492
  collection => {
489
493
 
490
- const data = context.getConvertedData();
494
+ const converted_data = context.getConvertedData();
491
495
  const pledge = new Swift();
492
496
 
497
+ let data = {};
498
+
499
+ for (let key in converted_data) {
500
+ let val = converted_data[key];
501
+
502
+ if (val == null) {
503
+ continue;
504
+ }
505
+
506
+ data[key] = val;
507
+ }
508
+
493
509
  Pledge.done(collection.insertOne(data, {w: 1, fullResult: true}), function afterInsert(err, result) {
494
510
 
495
511
  // Clear the cache
@@ -541,110 +557,125 @@ Mongo.setMethod(function _create(context) {
541
557
  */
542
558
  Mongo.setMethod(function _update(context) {
543
559
 
544
- const model = context.getModel(),
545
- options = context.getSaveOptions();
560
+ const model = context.getModel();
546
561
 
547
562
  return Swift.waterfall(
548
563
  this.collection(model.table),
549
564
  collection => {
565
+ return performUpdate(collection, model, context);
566
+ }
567
+ );
568
+ });
550
569
 
551
- let key;
570
+ /**
571
+ * Perform the update
572
+ *
573
+ * @author Jelle De Loecker <jelle@elevenways.be>
574
+ * @since 1.4.0
575
+ * @version 1.4.0
576
+ *
577
+ * @return {Pledge}
578
+ */
579
+ const performUpdate = (collection, model, context) => {
552
580
 
553
- // Get the converted data
554
- const data = context.getConvertedData();
581
+ const options = context.getSaveOptions();
555
582
 
556
- // Get the id to update, it should always be inside the given data
557
- let id = data._id;
583
+ let key;
558
584
 
559
- // Clone the data object
560
- let doc = {...data};
585
+ // Get the converted data
586
+ const data = context.getConvertedData();
561
587
 
562
- // Values that will get flattened
563
- let to_flatten = {};
588
+ // Get the id to update, it should always be inside the given data
589
+ let id = data._id;
564
590
 
565
- // Field names that won't get flattened
566
- let no_flatten = {};
591
+ // Clone the data object
592
+ let doc = {...data};
567
593
 
568
- // Remove the id
569
- delete doc._id;
594
+ // Values that will get flattened
595
+ let to_flatten = {};
570
596
 
571
- if (!options.override_created) {
572
- delete doc.created;
573
- }
597
+ // Field names that won't get flattened
598
+ let no_flatten = {};
574
599
 
575
- // Iterate over the fields
576
- for (key in doc) {
577
- let field = model.getField(key);
600
+ // Remove the id
601
+ delete doc._id;
578
602
 
579
- if (field && (field.is_self_contained || field.is_translatable)) {
580
- no_flatten[key] = doc[key];
581
- } else {
582
- to_flatten[key] = doc[key];
583
- }
584
- }
603
+ if (!options.override_created) {
604
+ delete doc.created;
605
+ }
585
606
 
586
- // Flatten the object, using periods & NOT flattening arrays
587
- let flat = Object.flatten(to_flatten, '.', false);
607
+ // Iterate over the fields
608
+ for (key in doc) {
609
+ let field = model.getField(key);
588
610
 
589
- // Assign the no-flatten values, too
590
- Object.assign(flat, no_flatten);
611
+ if (field && (field.is_self_contained || field.is_translatable || typeof doc[key] == 'object')) {
612
+ no_flatten[key] = doc[key];
613
+ } else {
614
+ to_flatten[key] = doc[key];
615
+ }
616
+ }
591
617
 
592
- let unset = {};
618
+ // Flatten the object, using periods & NOT flattening arrays
619
+ let flat = Object.flatten(to_flatten, '.', false);
593
620
 
594
- for (key in flat) {
595
- // Undefined or null means we want to delete the value
596
- // We can't set null, because that could interfere with dot notation updates
597
- if (flat[key] == null) {
621
+ // Assign the no-flatten values, too
622
+ Object.assign(flat, no_flatten);
598
623
 
599
- // Add the key to the unset object
600
- unset[key] = '';
624
+ let unset = {};
601
625
 
602
- // Remove it from the flat object
603
- delete flat[key];
604
- }
605
- }
626
+ for (key in flat) {
627
+ // Undefined or null means we want to delete the value
628
+ // We can't set null, because that could interfere with dot notation updates
629
+ if (flat[key] == null) {
606
630
 
607
- let update_object = {
608
- $set: flat
609
- };
631
+ // Add the key to the unset object
632
+ unset[key] = '';
610
633
 
611
- if (!Object.isEmpty(unset)) {
612
- update_object.$unset = unset;
613
- }
634
+ // Remove it from the flat object
635
+ delete flat[key];
636
+ }
637
+ }
614
638
 
615
- if (options.debug) {
616
- console.log('Updating with obj', id, update_object);
617
- }
639
+ let update_object = {
640
+ $set: flat
641
+ };
618
642
 
619
- let promise;
643
+ if (!Object.isEmpty(unset)) {
644
+ update_object.$unset = unset;
645
+ }
620
646
 
621
- if (collection.findOneAndUpdate) {
622
- promise = collection.findOneAndUpdate({_id: id}, update_object, {upsert: true});
623
- } else if (collection.findAndModify) {
624
- promise = collection.findAndModify({_id: id}, [['_id', 1]], update_object, {upsert: true});
625
- } else {
626
- // If it's not available (like nedb)
627
- promise = collection.update({_id: ''+id}, update_object, {upsert: true});
628
- }
647
+ if (options.debug) {
648
+ console.log('Updating with obj', id, update_object);
649
+ }
629
650
 
630
- let pledge = new Swift();
651
+ let promise;
631
652
 
632
- Pledge.done(promise, function afterUpdate(err, result) {
653
+ if (collection.findOneAndUpdate) {
654
+ promise = collection.findOneAndUpdate({_id: id}, update_object, {upsert: true});
655
+ } else if (collection.findAndModify) {
656
+ promise = collection.findAndModify({_id: id}, [['_id', 1]], update_object, {upsert: true});
657
+ } else {
658
+ // If it's not available (like nedb)
659
+ promise = collection.update({_id: ''+id}, update_object, {upsert: true});
660
+ }
633
661
 
634
- // Clear the cache
635
- model.nukeCache();
662
+ let pledge = new Swift();
636
663
 
637
- if (err != null) {
638
- return pledge.reject(err);
639
- }
664
+ Pledge.done(promise, function afterUpdate(err, result) {
640
665
 
641
- pledge.resolve(Object.assign({}, data));
642
- });
666
+ // Clear the cache
667
+ model.nukeCache();
643
668
 
644
- return pledge;
669
+ if (err != null) {
670
+ return pledge.reject(err);
645
671
  }
646
- );
647
- });
672
+
673
+ pledge.resolve(Object.assign({}, data));
674
+ });
675
+
676
+ return pledge;
677
+
678
+ };
648
679
 
649
680
  /**
650
681
  * Remove a record from the database
@@ -477,6 +477,11 @@ Group.setStatic(function unDry(obj, cloned) {
477
477
  child;
478
478
 
479
479
  for (child of children) {
480
+
481
+ if (!child) {
482
+ continue;
483
+ }
484
+
480
485
  result.children.set(child.name, child);
481
486
  child.group = result;
482
487
  }
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.4",
4
+ "version": "1.4.0-alpha.6",
5
5
  "author": "Jelle De Loecker <jelle@elevenways.be>",
6
6
  "keywords": [
7
7
  "alchemy",
@@ -14,29 +14,29 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "ansi-256-colors" : "~1.1.0",
17
- "autoprefixer" : "~10.4.16",
17
+ "autoprefixer" : "~10.4.20",
18
18
  "bcrypt" : "~5.1.1",
19
19
  "body" : "~5.1.0",
20
20
  "body-parser" : "~1.20.2",
21
- "bson" : "~6.1.0",
22
- "chokidar" : "~3.5.3",
21
+ "bson" : "~6.8.0",
22
+ "chokidar" : "~3.6.0",
23
23
  "formidable" : "~3.5.1",
24
24
  "graceful-fs" : "~4.2.11",
25
- "hawkejs" : "~2.3.17",
25
+ "hawkejs" : "~2.4.0",
26
26
  "jsondiffpatch" : "~0.5.0",
27
27
  "mime" : "~3.0.0",
28
- "minimist" : "~1.2.5",
28
+ "minimist" : "~1.2.8",
29
29
  "mkdirp" : "~3.0.1",
30
30
  "@picturae/mmmagic": "0.5.3",
31
- "mongodb" : "~6.1.0",
31
+ "mongodb" : "~6.8.0",
32
32
  "ncp" : "~2.0.0",
33
- "postcss" : "~8.4.31",
33
+ "postcss" : "~8.4.41",
34
34
  "postcss-prune-var": "~1.1.2",
35
- "protoblast" : "~0.9.1",
36
- "semver" : "~7.5.4",
37
- "socket.io" : "~4.7.2",
35
+ "protoblast" : "~0.9.3",
36
+ "semver" : "~7.6.3",
37
+ "socket.io" : "~4.7.5",
38
38
  "@11ways/socket.io-stream" : "~0.9.2",
39
- "terser" : "~5.31.0",
39
+ "terser" : "~5.31.5",
40
40
  "toobusy-js" : "~0.5.1",
41
41
  "useragent" : "~2.3.0"
42
42
  },
@@ -47,10 +47,10 @@
47
47
  "optionalDependencies": {
48
48
  "janeway" : "~0.4.4",
49
49
  "less" : "~4.2.0",
50
- "sass" : "~1.71.1",
51
- "sass-embedded" : "~1.71.1",
50
+ "sass" : "~1.77.8",
51
+ "sass-embedded" : "~1.77.8",
52
52
  "nodent-compiler" : "~3.2.13",
53
- "socket.io-client" : "~4.7.2",
53
+ "socket.io-client" : "~4.7.5",
54
54
  "socket.io-msgpack-parser": "~3.0.2"
55
55
  },
56
56
  "devDependencies": {