spice-js 2.5.28 → 2.5.30

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.
@@ -201,6 +201,23 @@ class SpiceModel {
201
201
  return item.length > 27 && item.indexOf("|") > -1;
202
202
  }
203
203
 
204
+ propsToBeRemoved(data) {
205
+ var _this = this;
206
+
207
+ return _asyncToGenerator(function* () {
208
+ if (!_.isArray(data)) {
209
+ data = Array.of(data);
210
+ }
211
+
212
+ if (_this[_ctx]) {
213
+ var returned = yield new _this[_ctx].state.process_fields().process(_this[_ctx], data, _this.type);
214
+ return returned;
215
+ }
216
+
217
+ return [];
218
+ })();
219
+ }
220
+
204
221
  createValidationString(_ref) {
205
222
  var {
206
223
  property_name,
@@ -418,7 +435,7 @@ class SpiceModel {
418
435
  }
419
436
 
420
437
  get(args) {
421
- var _this = this;
438
+ var _this2 = this;
422
439
 
423
440
  return _asyncToGenerator(function* () {
424
441
  try {
@@ -427,19 +444,19 @@ class SpiceModel {
427
444
  }
428
445
 
429
446
  if (_.isString(args.id)) {
430
- yield _this.run_hook(args, "get", "before");
431
- var results = yield _this.database.get(args.id);
447
+ yield _this2.run_hook(args, "get", "before");
448
+ var results = yield _this2.database.get(args.id);
432
449
 
433
- if (results.type != _this.type) {
434
- throw new Error(_this.type + " does not exist");
450
+ if (results.type != _this2.type) {
451
+ throw new Error(_this2.type + " does not exist");
435
452
  }
436
453
 
437
454
  if (results.deleted == undefined || results.deleted == false) {
438
- yield _this.run_hook(results, "get", "after");
439
- results = yield _this.do_serialize(results, "read", {}, args);
455
+ yield _this2.run_hook(results, "get", "after");
456
+ results = yield _this2.do_serialize(results, "read", {}, args, (yield _this2.propsToBeRemoved(results)));
440
457
  return results;
441
458
  } else {
442
- throw new Error(_this.type + " does not exist");
459
+ throw new Error(_this2.type + " does not exist");
443
460
  }
444
461
  }
445
462
  } catch (e) {
@@ -449,11 +466,11 @@ class SpiceModel {
449
466
  }
450
467
 
451
468
  query(query, scope) {
452
- var _this2 = this;
469
+ var _this3 = this;
453
470
 
454
471
  return _asyncToGenerator(function* () {
455
472
  try {
456
- var results = yield _this2.database.query(query, scope);
473
+ var results = yield _this3.database.query(query, scope);
457
474
  return results;
458
475
  } catch (error) {
459
476
  throw error;
@@ -462,7 +479,7 @@ class SpiceModel {
462
479
  }
463
480
 
464
481
  getMulti(args) {
465
- var _this3 = this;
482
+ var _this4 = this;
466
483
 
467
484
  return _asyncToGenerator(function* () {
468
485
  try {
@@ -470,20 +487,20 @@ class SpiceModel {
470
487
  args = {};
471
488
  }
472
489
 
473
- yield _this3.run_hook(_this3, "list", "before");
490
+ yield _this4.run_hook(_this4, "list", "before");
474
491
 
475
492
  _.remove(args.ids, o => o == undefined);
476
493
 
477
494
  var results = [];
478
495
 
479
496
  if (args.ids.length > 0) {
480
- results = yield _this3.database.multi_get(args.ids, true);
497
+ results = yield _this4.database.multi_get(args.ids, true);
481
498
  }
482
499
 
483
- _.remove(results, o => o.type != _this3.type);
500
+ _.remove(results, o => o.type != _this4.type);
484
501
 
485
- yield _this3.run_hook(results, "list", "after", args.context);
486
- results = yield _this3.do_serialize(results, "read", {}, args);
502
+ yield _this4.run_hook(results, "list", "after", args.context);
503
+ results = yield _this4.do_serialize(results, "read", {}, args, (yield _this4.propsToBeRemoved(results)));
487
504
  return results;
488
505
  } catch (e) {
489
506
  console.log(e.stack);
@@ -493,18 +510,18 @@ class SpiceModel {
493
510
  }
494
511
 
495
512
  exist(data) {
496
- var _this4 = this;
513
+ var _this5 = this;
497
514
 
498
515
  return _asyncToGenerator(function* () {
499
516
  try {
500
517
  if (_.isString(data)) {
501
- var result = yield _this4.database.get(data);
518
+ var result = yield _this5.database.get(data);
502
519
 
503
- if (result.type != _this4.type) {
520
+ if (result.type != _this5.type) {
504
521
  return false;
505
522
  }
506
523
  } else {
507
- if (data.type != _this4.type) {
524
+ if (data.type != _this5.type) {
508
525
  return false;
509
526
  }
510
527
  }
@@ -517,51 +534,51 @@ class SpiceModel {
517
534
  }
518
535
 
519
536
  update(args) {
520
- var _this5 = this;
537
+ var _this6 = this;
521
538
 
522
539
  return _asyncToGenerator(function* () {
523
540
  try {
524
- _this5.updated_at = new SDate().now();
525
- var results = yield _this5.database.get(args.id);
526
- var item_exist = yield _this5.exist(results);
541
+ _this6.updated_at = new SDate().now();
542
+ var results = yield _this6.database.get(args.id);
543
+ var item_exist = yield _this6.exist(results);
527
544
 
528
545
  if (!item_exist) {
529
- throw new Error(_this5.type + " does not exist.");
546
+ throw new Error(_this6.type + " does not exist.");
530
547
  }
531
548
 
532
549
  delete results["id"];
533
550
 
534
- _.defaults(_this5, results);
551
+ _.defaults(_this6, results);
535
552
 
536
553
  var cover_obj = {
537
554
  old: results,
538
- new: _this5,
555
+ new: _this6,
539
556
  id: args.id
540
557
  };
541
558
 
542
559
  if (args.skip_hooks != true) {
543
- yield _this5.run_hook(cover_obj, "update", "before");
560
+ yield _this6.run_hook(cover_obj, "update", "before");
544
561
  }
545
562
 
546
563
  var form;
547
564
 
548
565
  if (args.skip_write_serialize != true && args.skip_serialize != true) {
549
- form = yield _this5.do_serialize(_this5, "write", cover_obj.new, args);
566
+ form = yield _this6.do_serialize(_this6, "write", cover_obj.new, args);
550
567
  }
551
568
 
552
- yield _this5.database.update(args.id, form || _this5);
569
+ yield _this6.database.update(args.id, form || _this6);
553
570
 
554
571
  if (args.skip_hooks != true) {
555
- yield _this5.run_hook(_extends({}, _this5, {
572
+ yield _this6.run_hook(_extends({}, _this6, {
556
573
  id: args.id
557
574
  }), "update", "after");
558
575
  }
559
576
 
560
577
  if (args.skip_read_serialize != true && args.skip_serialize != true) {
561
- form = yield _this5.do_serialize(form, "read", {}, args);
578
+ form = yield _this6.do_serialize(form, "read", {}, args, (yield _this6.propsToBeRemoved(form)));
562
579
  }
563
580
 
564
- _this5.id = args.id;
581
+ _this6.id = args.id;
565
582
  return _extends({}, form, {
566
583
  id: args.id
567
584
  });
@@ -573,35 +590,35 @@ class SpiceModel {
573
590
  }
574
591
 
575
592
  create(args) {
576
- var _this6 = this;
593
+ var _this7 = this;
577
594
 
578
595
  return _asyncToGenerator(function* () {
579
596
  try {
580
597
  var form;
581
- _this6.created_at = new SDate().now();
598
+ _this7.created_at = new SDate().now();
582
599
 
583
600
  if (args.body) {
584
601
  form = _.defaults({}, args.body);
585
- form.created_at = _this6.created_at;
586
- form.updated_at = _this6.created_at;
602
+ form.created_at = _this7.created_at;
603
+ form.updated_at = _this7.created_at;
587
604
  delete form["bucket"];
588
605
  }
589
606
 
590
- var workingForm = form || _this6;
591
- _this6.updated_at = new SDate().now();
607
+ var workingForm = form || _this7;
608
+ _this7.updated_at = new SDate().now();
592
609
  var id = args.id_prefix + "-" + UUID.v4();
593
610
 
594
611
  if (args && args.id) {
595
612
  id = args.id;
596
613
  }
597
614
 
598
- yield _this6.run_hook(workingForm, "create", "before");
599
- workingForm = yield _this6.do_serialize(workingForm, "write", {}, args);
600
- var results = yield _this6.database.insert(id, workingForm, args.expiry);
601
- yield _this6.run_hook(_extends({}, results, {
615
+ yield _this7.run_hook(workingForm, "create", "before");
616
+ workingForm = yield _this7.do_serialize(workingForm, "write", {}, args);
617
+ var results = yield _this7.database.insert(id, workingForm, args.expiry);
618
+ yield _this7.run_hook(_extends({}, results, {
602
619
  id
603
620
  }), "create", "after");
604
- results = yield _this6.do_serialize(results, "read", {}, args);
621
+ results = yield _this7.do_serialize(results, "read", {}, args, (yield _this7.propsToBeRemoved(results)));
605
622
  return _extends({}, results, {
606
623
  id
607
624
  });
@@ -613,29 +630,29 @@ class SpiceModel {
613
630
  }
614
631
 
615
632
  delete(args) {
616
- var _this7 = this;
633
+ var _this8 = this;
617
634
 
618
635
  return _asyncToGenerator(function* () {
619
- var item_exist = yield _this7.exist(args.id);
636
+ var item_exist = yield _this8.exist(args.id);
620
637
 
621
638
  if (!item_exist) {
622
- throw new Error(_this7.type + " does not exist.");
639
+ throw new Error(_this8.type + " does not exist.");
623
640
  }
624
641
 
625
642
  try {
626
- yield _this7.run_hook(args, "delete", "before");
643
+ yield _this8.run_hook(args, "delete", "before");
627
644
  var delete_response = {};
628
645
 
629
646
  if (args.hard) {
630
- delete_response = yield _this7.database.delete(args.id);
647
+ delete_response = yield _this8.database.delete(args.id);
631
648
  } else {
632
- var results = yield _this7.database.get(args.id);
649
+ var results = yield _this8.database.get(args.id);
633
650
  delete results["id"];
634
651
  results.deleted = true;
635
- delete_response = yield _this7.database.update(args.id, "");
652
+ delete_response = yield _this8.database.update(args.id, "");
636
653
  }
637
654
 
638
- yield _this7.run_hook(args, "delete", "after");
655
+ yield _this8.run_hook(args, "delete", "after");
639
656
  return {};
640
657
  } catch (e) {
641
658
  console.log(e.stack);
@@ -649,7 +666,7 @@ class SpiceModel {
649
666
  }
650
667
 
651
668
  list(args) {
652
- var _this8 = this;
669
+ var _this9 = this;
653
670
 
654
671
  return _asyncToGenerator(function* () {
655
672
  try {
@@ -663,7 +680,7 @@ class SpiceModel {
663
680
  query = args.query;
664
681
  } else {
665
682
  if (args.filters) {
666
- query = yield _this8.makeQueryFromFilter(args.filters);
683
+ query = yield _this9.makeQueryFromFilter(args.filters);
667
684
  } else {
668
685
  if (args.query) {
669
686
  query = args.query + " AND (deleted = false OR deleted IS MISSING) ";
@@ -685,22 +702,22 @@ class SpiceModel {
685
702
  args.sort = "created_at DESC";
686
703
  }
687
704
 
688
- yield _this8.run_hook(_this8, "list", "before");
705
+ yield _this9.run_hook(_this9, "list", "before");
689
706
  var results;
690
707
 
691
708
  if (args.is_custom_query && args.is_custom_query === "true") {
692
- results = yield _this8.database.query(query);
709
+ results = yield _this9.database.query(query);
693
710
  } else {
694
711
  if (args.is_full_text && args.is_full_text === "true") {
695
- results = yield _this8.database.full_text_search(_this8.type, query || "", args.limit, args.offset);
712
+ results = yield _this9.database.full_text_search(_this9.type, query || "", args.limit, args.offset);
696
713
  } else {
697
- results = yield _this8.database.search(_this8.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent);
714
+ results = yield _this9.database.search(_this9.type, args.columns || "", query || "", args.limit, args.offset, args.sort, args.do_count, args.statement_consistent);
698
715
  }
699
716
  }
700
717
 
701
718
  try {
702
- yield _this8.run_hook(results.data, "list", "after");
703
- results.data = yield _this8.do_serialize(results.data, "read", {}, args);
719
+ yield _this9.run_hook(results.data, "list", "after");
720
+ results.data = yield _this9.do_serialize(results.data, "read", {}, args, (yield _this9.propsToBeRemoved(results.data)));
704
721
  } catch (e) {
705
722
  console.log(e);
706
723
  }
@@ -724,26 +741,26 @@ class SpiceModel {
724
741
  }
725
742
 
726
743
  run_hook(data, op, when, old_data) {
727
- var _this9 = this;
744
+ var _this10 = this;
728
745
 
729
746
  return _asyncToGenerator(function* () {
730
747
  try {
731
- if (_this9[_disable_lifecycle_events] == false) {
748
+ if (_this10[_disable_lifecycle_events] == false) {
732
749
  var resourceLifecycleTriggered = new _ResourceLifecycleTriggered.default({
733
750
  data: {
734
751
  data,
735
752
  operation: op,
736
753
  when,
737
754
  old_data,
738
- resource: _this9.type,
739
- ctx: _this9[_ctx]
755
+ resource: _this10.type,
756
+ ctx: _this10[_ctx]
740
757
  }
741
758
  });
742
759
  resourceLifecycleTriggered.dispatch();
743
760
  }
744
761
 
745
- if (_this9[_hooks] && _this9[_hooks][op] && _this9[_hooks][op][when]) {
746
- for (var i of _this9[_hooks][op][when]) {
762
+ if (_this10[_hooks] && _this10[_hooks][op] && _this10[_hooks][op][when]) {
763
+ for (var i of _this10[_hooks][op][when]) {
747
764
  data = yield i(data, old_data);
748
765
  }
749
766
  }
@@ -776,7 +793,7 @@ class SpiceModel {
776
793
  }
777
794
 
778
795
  mapToObject(data, Class, source_property, store_property, property) {
779
- var _this10 = this;
796
+ var _this11 = this;
780
797
 
781
798
  return _asyncToGenerator(function* () {
782
799
  var original_is_array = _.isArray(data);
@@ -795,7 +812,7 @@ class SpiceModel {
795
812
  });
796
813
 
797
814
  var returned_all = yield Promise.allSettled(_.map(classes, obj => {
798
- return new obj(_this10[_args]).getMulti({
815
+ return new obj(_this11[_args]).getMulti({
799
816
  ids: ids
800
817
  });
801
818
  }));
@@ -813,7 +830,7 @@ class SpiceModel {
813
830
  }
814
831
 
815
832
  mapToObjectArray(data, Class, source_property, store_property, property) {
816
- var _this11 = this;
833
+ var _this12 = this;
817
834
 
818
835
  return _asyncToGenerator(function* () {
819
836
  var original_is_array = _.isArray(data);
@@ -842,7 +859,7 @@ class SpiceModel {
842
859
 
843
860
  var classes = _.isArray(Class) ? Class : [Class];
844
861
  var returned_all = yield Promise.allSettled(_.map(classes, obj => {
845
- return new obj(_this11[_args]).getMulti({
862
+ return new obj(_this12[_args]).getMulti({
846
863
  ids: ids
847
864
  });
848
865
  }));
@@ -889,7 +906,7 @@ class SpiceModel {
889
906
  }
890
907
 
891
908
  createMofifier(properties) {
892
- var _this12 = this;
909
+ var _this13 = this;
893
910
 
894
911
  var _loop = function _loop(i) {
895
912
  if (properties[i].map) {
@@ -900,11 +917,11 @@ class SpiceModel {
900
917
  case String:
901
918
  case "string":
902
919
  {
903
- _this12.addModifier({
920
+ _this13.addModifier({
904
921
  when: properties[i].map.when || "read",
905
922
  execute: function () {
906
923
  var _execute = _asyncToGenerator(function* (data) {
907
- return yield _this12.mapToObject(data, _.isString(properties[i].map.reference) ? spice.models[properties[i].map.reference] : properties[i].map.reference, i, properties[i].map.destination || i, properties[i]);
924
+ return yield _this13.mapToObject(data, _.isString(properties[i].map.reference) ? spice.models[properties[i].map.reference] : properties[i].map.reference, i, properties[i].map.destination || i, properties[i]);
908
925
  });
909
926
 
910
927
  function execute(_x) {
@@ -921,11 +938,11 @@ class SpiceModel {
921
938
  case Array:
922
939
  case "array":
923
940
  {
924
- _this12.addModifier({
941
+ _this13.addModifier({
925
942
  when: properties[i].map.when || "read",
926
943
  execute: function () {
927
944
  var _execute2 = _asyncToGenerator(function* (data) {
928
- return yield _this12.mapToObjectArray(data, _.isString(properties[i].map.reference) ? spice.models[properties[i].map.reference] : properties[i].map.reference, i, properties[i].map.destination || i, properties[i]);
945
+ return yield _this13.mapToObjectArray(data, _.isString(properties[i].map.reference) ? spice.models[properties[i].map.reference] : properties[i].map.reference, i, properties[i].map.destination || i, properties[i]);
929
946
  });
930
947
 
931
948
  function execute(_x2) {
@@ -956,14 +973,18 @@ class SpiceModel {
956
973
  }
957
974
  }
958
975
 
959
- do_serialize(data, type, old_data, args) {
960
- var _this13 = this;
976
+ do_serialize(data, type, old_data, args, path_to_be_removed) {
977
+ var _this14 = this;
961
978
 
962
979
  return _asyncToGenerator(function* () {
963
980
  try {
964
981
  // run serializers
965
- if (_this13.shouldSerializerRun(args, type)) {
966
- for (var i of _this13[_serializers][type]["modifiers"]) {
982
+ if (!path_to_be_removed) {
983
+ path_to_be_removed = [];
984
+ }
985
+
986
+ if (_this14.shouldSerializerRun(args, type)) {
987
+ for (var i of _this14[_serializers][type]["modifiers"]) {
967
988
  try {
968
989
  data = yield i(data, old_data);
969
990
  } catch (e) {
@@ -981,12 +1002,12 @@ class SpiceModel {
981
1002
 
982
1003
  var defaults = {};
983
1004
 
984
- for (var _i in _this13.props) {
985
- if (_this13.props[_i].defaults != undefined && _this13.props[_i].defaults[type] != undefined && _this13.props[_i].defaults[type] != undefined) {
986
- defaults[_i] = _.isFunction(_this13.props[_i].defaults[type]) ? _this13.props[_i].defaults[type]({
1005
+ for (var _i in _this14.props) {
1006
+ if (_this14.props[_i].defaults != undefined && _this14.props[_i].defaults[type] != undefined && _this14.props[_i].defaults[type] != undefined) {
1007
+ defaults[_i] = _.isFunction(_this14.props[_i].defaults[type]) ? _this14.props[_i].defaults[type]({
987
1008
  old_data: data,
988
1009
  new_data: old_data
989
- }) : _this13.props[_i].defaults[type];
1010
+ }) : _this14.props[_i].defaults[type];
990
1011
  }
991
1012
  } // apply defaults
992
1013
 
@@ -997,10 +1018,10 @@ class SpiceModel {
997
1018
 
998
1019
 
999
1020
  if (type == "read") {
1000
- var props_to_clean = ["deleted", "type"];
1021
+ var props_to_clean = ["deleted", "type", ...path_to_be_removed];
1001
1022
 
1002
- for (var _i3 in _this13.props) {
1003
- if (_this13.props[_i3].hide) {
1023
+ for (var _i3 in _this14.props) {
1024
+ if (_this14.props[_i3].hide) {
1004
1025
  props_to_clean.push(_i3);
1005
1026
  }
1006
1027
  }
@@ -1008,7 +1029,7 @@ class SpiceModel {
1008
1029
  data = _.map(data, obj => _.omit(obj, props_to_clean));
1009
1030
  }
1010
1031
 
1011
- return original_is_array ? data : data[0];
1032
+ return original_is_array ? data : _.first(data);
1012
1033
  }
1013
1034
  } catch (e) {
1014
1035
  console.log(e.stack);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.5.28",
3
+ "version": "2.5.30",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -123,8 +123,8 @@ export default class SpiceModel {
123
123
  this[i] = _.isBoolean(args.args[i])
124
124
  ? args.args[i]
125
125
  : args.args[i] == "true" ||
126
- args.args[i] == 1 ||
127
- args.args[i] == "True";
126
+ args.args[i] == 1 ||
127
+ args.args[i] == "True";
128
128
  break;
129
129
  }
130
130
  case Date:
@@ -180,6 +180,20 @@ export default class SpiceModel {
180
180
  return item.length > 27 && item.indexOf("|") > -1;
181
181
  }
182
182
 
183
+ async propsToBeRemoved(data) {
184
+
185
+ if (!_.isArray(data)) {
186
+ data = Array.of(data)
187
+ }
188
+
189
+ if (this[_ctx]) {
190
+ let returned = await new this[_ctx].state.process_fields().process(this[_ctx], data, this.type);
191
+ return returned;
192
+
193
+ }
194
+ return []
195
+ }
196
+
183
197
  createValidationString({ property_name, props, operation, complete }) {
184
198
  let operationExempt = {
185
199
  PUT: ["required", "unique"],
@@ -364,7 +378,13 @@ export default class SpiceModel {
364
378
  }
365
379
  if (results.deleted == undefined || results.deleted == false) {
366
380
  await this.run_hook(results, "get", "after");
367
- results = await this.do_serialize(results, "read", {}, args);
381
+ results = await this.do_serialize(
382
+ results,
383
+ "read",
384
+ {},
385
+ args,
386
+ await this.propsToBeRemoved(results)
387
+ );
368
388
  return results;
369
389
  } else {
370
390
  throw new Error(`${this.type} does not exist`);
@@ -399,7 +419,13 @@ export default class SpiceModel {
399
419
  _.remove(results, (o) => o.type != this.type);
400
420
 
401
421
  await this.run_hook(results, "list", "after", args.context);
402
- results = await this.do_serialize(results, "read", {}, args);
422
+ results = await this.do_serialize(
423
+ results,
424
+ "read",
425
+ {},
426
+ args,
427
+ await this.propsToBeRemoved(results)
428
+ );
403
429
 
404
430
  return results;
405
431
  } catch (e) {
@@ -461,7 +487,13 @@ export default class SpiceModel {
461
487
  );
462
488
  }
463
489
  if (args.skip_read_serialize != true && args.skip_serialize != true) {
464
- form = await this.do_serialize(form, "read", {}, args);
490
+ form = await this.do_serialize(
491
+ form,
492
+ "read",
493
+ {},
494
+ args,
495
+ await this.propsToBeRemoved(form)
496
+ );
465
497
  }
466
498
  this.id = args.id;
467
499
  return { ...form, id: args.id };
@@ -500,7 +532,13 @@ export default class SpiceModel {
500
532
  "create",
501
533
  "after"
502
534
  );
503
- results = await this.do_serialize(results, "read", {}, args);
535
+ results = await this.do_serialize(
536
+ results,
537
+ "read",
538
+ {},
539
+ args,
540
+ await this.propsToBeRemoved(results)
541
+ );
504
542
  return { ...results, id };
505
543
  } catch (e) {
506
544
  console.log(e.stack);
@@ -601,7 +639,13 @@ export default class SpiceModel {
601
639
  }
602
640
  try {
603
641
  await this.run_hook(results.data, "list", "after");
604
- results.data = await this.do_serialize(results.data, "read", {}, args);
642
+ results.data = await this.do_serialize(
643
+ results.data,
644
+ "read",
645
+ {},
646
+ args,
647
+ await this.propsToBeRemoved(results.data)
648
+ );
605
649
  } catch (e) {
606
650
  console.log(e);
607
651
  }
@@ -830,10 +874,14 @@ export default class SpiceModel {
830
874
  }
831
875
  }
832
876
 
833
- async do_serialize(data, type, old_data, args) {
877
+ async do_serialize(data, type, old_data, args, path_to_be_removed) {
834
878
  try {
835
879
  // run serializers
836
-
880
+
881
+ if(!path_to_be_removed){
882
+ path_to_be_removed =[]
883
+ }
884
+
837
885
  if (this.shouldSerializerRun(args, type)) {
838
886
  for (let i of this[_serializers][type]["modifiers"]) {
839
887
  try {
@@ -860,9 +908,9 @@ export default class SpiceModel {
860
908
  ) {
861
909
  defaults[i] = _.isFunction(this.props[i].defaults[type])
862
910
  ? this.props[i].defaults[type]({
863
- old_data: data,
864
- new_data: old_data,
865
- })
911
+ old_data: data,
912
+ new_data: old_data,
913
+ })
866
914
  : this.props[i].defaults[type];
867
915
  }
868
916
  }
@@ -873,7 +921,8 @@ export default class SpiceModel {
873
921
 
874
922
  // apply cleaners
875
923
  if (type == "read") {
876
- let props_to_clean = ["deleted", "type"];
924
+
925
+ let props_to_clean = ["deleted", "type", ...path_to_be_removed];
877
926
  for (let i in this.props) {
878
927
  if (this.props[i].hide) {
879
928
  props_to_clean.push(i);
@@ -882,7 +931,7 @@ export default class SpiceModel {
882
931
  data = _.map(data, (obj) => _.omit(obj, props_to_clean));
883
932
  }
884
933
 
885
- return original_is_array ? data : data[0];
934
+ return original_is_array ? data : _.first(data);
886
935
  }
887
936
  } catch (e) {
888
937
  console.log(e.stack);