spice-js 2.5.30 → 2.5.32

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.
@@ -92,12 +92,6 @@ class SpiceModel {
92
92
  }
93
93
  };
94
94
  this.deleted = false;
95
- /*
96
- if (args.args) {
97
- delete args.args["ctx"];
98
- }
99
- */
100
-
101
95
  this[_database] = new Database(args.connection || "default", {
102
96
  collection: args.collection,
103
97
  scope: args.scope
@@ -802,11 +796,21 @@ class SpiceModel {
802
796
  data = Array.of(data);
803
797
  }
804
798
 
799
+ function log() {
800
+ if (source_property === "entity") {
801
+ for (var _len = arguments.length, message = new Array(_len), _key = 0; _key < _len; _key++) {
802
+ message[_key] = arguments[_key];
803
+ }
804
+
805
+ console.log(message);
806
+ }
807
+ }
808
+
805
809
  var classes = _.isArray(Class) ? Class : [Class];
806
810
  var ids = [];
807
811
 
808
812
  _.each(data, result => {
809
- if (_.isString(result[source_property])) {
813
+ if (_.isString(result[source_property]) && result[source_property] != "") {
810
814
  ids = _.union(ids, [result[source_property]]);
811
815
  }
812
816
  });
@@ -822,7 +826,11 @@ class SpiceModel {
822
826
  })));
823
827
 
824
828
  data = _.map(data, result => {
825
- result[store_property] = _.find(ug, g => g.id === result[source_property]) || {};
829
+ var result_found = _.find(ug, g => {
830
+ return g.id == result[source_property];
831
+ }) || {};
832
+ log(result[source_property], result_found.id);
833
+ result[store_property] = result_found;
826
834
  return result;
827
835
  });
828
836
  return original_is_array ? data : data[0];
@@ -852,7 +860,7 @@ class SpiceModel {
852
860
  value = [result[source_property]];
853
861
  }
854
862
 
855
- var items = _.filter(value, obj => _.isString(obj));
863
+ var items = _.filter(value, obj => _.isString(obj) && obj != "");
856
864
 
857
865
  ids = _.union(ids, items);
858
866
  });
@@ -52,6 +52,28 @@ class Storage {
52
52
  })();
53
53
  }
54
54
 
55
+ download(_ref2) {
56
+ var _this2 = this;
57
+
58
+ return _asyncToGenerator(function* () {
59
+ var {
60
+ file,
61
+ bucket,
62
+ options
63
+ } = _ref2;
64
+
65
+ if (options) {
66
+ _this2.driver_options = _lodash.default.merge(_this2.driver_options, options);
67
+ }
68
+
69
+ var driver = new _this2.Driver(_this2.driver_options);
70
+ return yield driver.download({
71
+ file,
72
+ bucket
73
+ });
74
+ })();
75
+ }
76
+
55
77
  }
56
78
 
57
79
  exports.default = Storage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.5.30",
3
+ "version": "2.5.32",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -77,12 +77,6 @@ export default class SpiceModel {
77
77
  };
78
78
 
79
79
  this.deleted = false;
80
-
81
- /*
82
- if (args.args) {
83
- delete args.args["ctx"];
84
- }
85
- */
86
80
  this[_database] = new Database(args.connection || "default", {
87
81
  collection: args.collection,
88
82
  scope: args.scope,
@@ -123,8 +117,8 @@ export default class SpiceModel {
123
117
  this[i] = _.isBoolean(args.args[i])
124
118
  ? args.args[i]
125
119
  : args.args[i] == "true" ||
126
- args.args[i] == 1 ||
127
- args.args[i] == "True";
120
+ args.args[i] == 1 ||
121
+ args.args[i] == "True";
128
122
  break;
129
123
  }
130
124
  case Date:
@@ -181,17 +175,19 @@ export default class SpiceModel {
181
175
  }
182
176
 
183
177
  async propsToBeRemoved(data) {
184
-
185
178
  if (!_.isArray(data)) {
186
- data = Array.of(data)
179
+ data = Array.of(data);
187
180
  }
188
181
 
189
182
  if (this[_ctx]) {
190
- let returned = await new this[_ctx].state.process_fields().process(this[_ctx], data, this.type);
183
+ let returned = await new this[_ctx].state.process_fields().process(
184
+ this[_ctx],
185
+ data,
186
+ this.type
187
+ );
191
188
  return returned;
192
-
193
189
  }
194
- return []
190
+ return [];
195
191
  }
196
192
 
197
193
  createValidationString({ property_name, props, operation, complete }) {
@@ -711,11 +707,20 @@ export default class SpiceModel {
711
707
  data = Array.of(data);
712
708
  }
713
709
 
710
+ function log(...message) {
711
+ if (source_property === "entity") {
712
+ console.log(message);
713
+ }
714
+ }
715
+
714
716
  let classes = _.isArray(Class) ? Class : [Class];
715
717
 
716
718
  let ids = [];
717
719
  _.each(data, (result) => {
718
- if (_.isString(result[source_property])) {
720
+ if (
721
+ _.isString(result[source_property]) &&
722
+ result[source_property] != ""
723
+ ) {
719
724
  ids = _.union(ids, [result[source_property]]);
720
725
  }
721
726
  });
@@ -736,8 +741,12 @@ export default class SpiceModel {
736
741
  );
737
742
 
738
743
  data = _.map(data, (result) => {
739
- result[store_property] =
740
- _.find(ug, (g) => g.id === result[source_property]) || {};
744
+ let result_found =
745
+ _.find(ug, (g) => {
746
+ return g.id == result[source_property];
747
+ }) || {};
748
+ log(result[source_property], result_found.id);
749
+ result[store_property] = result_found;
741
750
  return result;
742
751
  });
743
752
  return original_is_array ? data : data[0];
@@ -766,7 +775,7 @@ export default class SpiceModel {
766
775
  value = [result[source_property]];
767
776
  }
768
777
 
769
- let items = _.filter(value, (obj) => _.isString(obj));
778
+ let items = _.filter(value, (obj) => _.isString(obj) && obj != "");
770
779
  ids = _.union(ids, items);
771
780
  });
772
781
 
@@ -877,11 +886,11 @@ export default class SpiceModel {
877
886
  async do_serialize(data, type, old_data, args, path_to_be_removed) {
878
887
  try {
879
888
  // run serializers
880
-
881
- if(!path_to_be_removed){
882
- path_to_be_removed =[]
889
+
890
+ if (!path_to_be_removed) {
891
+ path_to_be_removed = [];
883
892
  }
884
-
893
+
885
894
  if (this.shouldSerializerRun(args, type)) {
886
895
  for (let i of this[_serializers][type]["modifiers"]) {
887
896
  try {
@@ -908,9 +917,9 @@ export default class SpiceModel {
908
917
  ) {
909
918
  defaults[i] = _.isFunction(this.props[i].defaults[type])
910
919
  ? this.props[i].defaults[type]({
911
- old_data: data,
912
- new_data: old_data,
913
- })
920
+ old_data: data,
921
+ new_data: old_data,
922
+ })
914
923
  : this.props[i].defaults[type];
915
924
  }
916
925
  }
@@ -921,7 +930,6 @@ export default class SpiceModel {
921
930
 
922
931
  // apply cleaners
923
932
  if (type == "read") {
924
-
925
933
  let props_to_clean = ["deleted", "type", ...path_to_be_removed];
926
934
  for (let i in this.props) {
927
935
  if (this.props[i].hide) {
@@ -27,4 +27,15 @@ export default class Storage {
27
27
  : path,
28
28
  });
29
29
  }
30
+
31
+ async download({ file, bucket, options }) {
32
+ if (options) {
33
+ this.driver_options = _.merge(this.driver_options, options);
34
+ }
35
+ let driver = new this.Driver(this.driver_options);
36
+ return await driver.download({
37
+ file,
38
+ bucket,
39
+ });
40
+ }
30
41
  }