spice-js 2.6.6 → 2.6.7

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.
@@ -29,6 +29,7 @@ var SDate = require("sonover-date"),
29
29
  _hooks = Symbol(),
30
30
  _disable_lifecycle_events = Symbol(),
31
31
  _external_modifier_loaded = Symbol(),
32
+ _skip_cache = Symbol(),
32
33
  _serializers = Symbol(); //const _type = Symbol("type");
33
34
 
34
35
 
@@ -51,7 +52,7 @@ class SpiceModel {
51
52
  }
52
53
 
53
54
  try {
54
- var _args$args, _args2, _args2$args;
55
+ var _args$args, _args2, _args2$args, _args3, _args3$args;
55
56
 
56
57
  var dbtype = spice.config.database.connections[args.connection].type || "couchbase";
57
58
 
@@ -63,6 +64,7 @@ class SpiceModel {
63
64
  this[_external_modifier_loaded] = false;
64
65
  this[_disable_lifecycle_events] = ((_args$args = args.args) == null ? void 0 : _args$args.disable_lifecycle_events) || false;
65
66
  this[_ctx] = (_args2 = args) == null ? void 0 : (_args2$args = _args2.args) == null ? void 0 : _args2$args.ctx;
67
+ this[_skip_cache] = ((_args3 = args) == null ? void 0 : (_args3$args = _args3.args) == null ? void 0 : _args3$args.skip_cache) || false;
66
68
  this[_hooks] = {
67
69
  create: {
68
70
  before: [],
@@ -432,10 +434,23 @@ class SpiceModel {
432
434
  return return_string;
433
435
  }
434
436
 
435
- shouldCache(resource_type) {
436
- var _spice$systemconfig, _spice$systemconfig$c;
437
+ shouldUseCache(resource_type) {
438
+ var _spice$config$cache;
437
439
 
438
- return spice.cache[resource_type] != undefined || ((_spice$systemconfig = spice.systemconfig) == null ? void 0 : (_spice$systemconfig$c = _spice$systemconfig.cache) == null ? void 0 : _spice$systemconfig$c.status) == "disable";
440
+ // If '_skip_cache' property of this object is true, then we shouldn't cache.
441
+ if (this[_skip_cache] == true) {
442
+ return false;
443
+ } // If the system configuration for spice has a cache status set to "disable",
444
+ // then we shouldn't cache, so return false.
445
+
446
+
447
+ if (((_spice$config$cache = spice.config.cache) == null ? void 0 : _spice$config$cache.status) == "disabled") {
448
+ return false;
449
+ } // If 'spice.cache[resource_type]' is not undefined,
450
+ // it implies that this resource type is already in the cache or is cacheable.
451
+
452
+
453
+ return spice.cache[resource_type] != undefined;
439
454
  }
440
455
 
441
456
  getCacheConfig(resource_type) {
@@ -501,7 +516,7 @@ class SpiceModel {
501
516
  var key = _this4.type + "::" + args.id;
502
517
  var results = {};
503
518
 
504
- if (_this4.shouldCache(_this4.type)) {
519
+ if (_this4.shouldUseCache(_this4.type)) {
505
520
  var cached_results = yield _this4.getCacheProviderObject(_this4.type).get(key);
506
521
  results = cached_results == null ? void 0 : cached_results.value;
507
522
 
@@ -569,7 +584,7 @@ class SpiceModel {
569
584
  var results = [];
570
585
 
571
586
  if (args.ids.length > 0) {
572
- if (_this6.shouldCache(_this6.type)) {
587
+ if (_this6.shouldUseCache(_this6.type)) {
573
588
  var cached_results = yield _this6.getCacheProviderObject(_this6.type).get(key);
574
589
  results = cached_results == null ? void 0 : cached_results.value;
575
590
 
@@ -830,7 +845,7 @@ class SpiceModel {
830
845
 
831
846
  if (args.is_custom_query && args.is_custom_query === "true") {
832
847
  if (args.ids.length > 0) {
833
- if (_this11.shouldCache(_this11.type)) {
848
+ if (_this11.shouldUseCache(_this11.type)) {
834
849
  var cached_results = yield _this11.getCacheProviderObject(_this11.type).get(key);
835
850
  results = cached_results == null ? void 0 : cached_results.value;
836
851
 
@@ -848,7 +863,7 @@ class SpiceModel {
848
863
  }
849
864
  } else {
850
865
  if (args.is_full_text && args.is_full_text === "true") {
851
- if (_this11.shouldCache(_this11.type)) {
866
+ if (_this11.shouldUseCache(_this11.type)) {
852
867
  var _cached_results = yield _this11.getCacheProviderObject(_this11.type).get(key);
853
868
 
854
869
  results = _cached_results == null ? void 0 : _cached_results.value;
@@ -865,7 +880,7 @@ class SpiceModel {
865
880
  results = yield _this11.database.full_text_search(_this11.type, query || "", args.limit, args.offset);
866
881
  }
867
882
  } else {
868
- if (_this11.shouldCache(_this11.type)) {
883
+ if (_this11.shouldUseCache(_this11.type)) {
869
884
  var _cached_results2 = yield _this11.getCacheProviderObject(_this11.type).get(key);
870
885
 
871
886
  results = _cached_results2 == null ? void 0 : _cached_results2.value;
@@ -997,7 +1012,9 @@ class SpiceModel {
997
1012
  });
998
1013
 
999
1014
  var returned_all = yield Promise.allSettled(_.map(classes, obj => {
1000
- return new obj(_this13[_args]).getMulti({
1015
+ return new obj(_extends({}, _this13[_args], {
1016
+ skip_cache: _this13[_skip_cache]
1017
+ })).getMulti({
1001
1018
  ids: ids
1002
1019
  });
1003
1020
  }));
@@ -1048,7 +1065,9 @@ class SpiceModel {
1048
1065
 
1049
1066
  var classes = _.isArray(Class) ? Class : [Class];
1050
1067
  var returned_all = yield Promise.allSettled(_.map(classes, obj => {
1051
- return new obj(_this14[_args]).getMulti({
1068
+ return new obj(_extends({}, _this14[_args], {
1069
+ skip_cache: _this14[_skip_cache]
1070
+ })).getMulti({
1052
1071
  ids: ids
1053
1072
  });
1054
1073
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.6.6",
3
+ "version": "2.6.7",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -15,6 +15,7 @@ var SDate = require("sonover-date"),
15
15
  _hooks = Symbol(),
16
16
  _disable_lifecycle_events = Symbol(),
17
17
  _external_modifier_loaded = Symbol(),
18
+ _skip_cache = Symbol(),
18
19
  _serializers = Symbol();
19
20
 
20
21
  //const _type = Symbol("type");
@@ -48,6 +49,7 @@ export default class SpiceModel {
48
49
  this[_disable_lifecycle_events] =
49
50
  args.args?.disable_lifecycle_events || false;
50
51
  this[_ctx] = args?.args?.ctx;
52
+ this[_skip_cache] = args?.args?.skip_cache || false;
51
53
  this[_hooks] = {
52
54
  create: {
53
55
  before: [],
@@ -365,11 +367,21 @@ export default class SpiceModel {
365
367
  return return_string;
366
368
  }
367
369
 
368
- shouldCache(resource_type) {
369
- return (
370
- spice.cache[resource_type] != undefined ||
371
- spice.systemconfig?.cache?.status == "disable"
372
- );
370
+ shouldUseCache(resource_type) {
371
+ // If '_skip_cache' property of this object is true, then we shouldn't cache.
372
+ if (this[_skip_cache] == true) {
373
+ return false;
374
+ }
375
+
376
+ // If the system configuration for spice has a cache status set to "disable",
377
+ // then we shouldn't cache, so return false.
378
+ if (spice.config.cache?.status == "disabled") {
379
+ return false;
380
+ }
381
+
382
+ // If 'spice.cache[resource_type]' is not undefined,
383
+ // it implies that this resource type is already in the cache or is cacheable.
384
+ return spice.cache[resource_type] != undefined;
373
385
  }
374
386
 
375
387
  getCacheConfig(resource_type) {
@@ -418,7 +430,7 @@ export default class SpiceModel {
418
430
  await this.run_hook(args, "get", "before");
419
431
  let key = `${this.type}::${args.id}`;
420
432
  let results = {};
421
- if (this.shouldCache(this.type)) {
433
+ if (this.shouldUseCache(this.type)) {
422
434
  let cached_results = await this.getCacheProviderObject(this.type).get(
423
435
  key
424
436
  );
@@ -487,7 +499,7 @@ export default class SpiceModel {
487
499
  let key = `${this.type}::${_.join(args.ids, "|")}`;
488
500
  let results = [];
489
501
  if (args.ids.length > 0) {
490
- if (this.shouldCache(this.type)) {
502
+ if (this.shouldUseCache(this.type)) {
491
503
  let cached_results = await this.getCacheProviderObject(this.type).get(
492
504
  key
493
505
  );
@@ -742,7 +754,7 @@ export default class SpiceModel {
742
754
  let results;
743
755
  if (args.is_custom_query && args.is_custom_query === "true") {
744
756
  if (args.ids.length > 0) {
745
- if (this.shouldCache(this.type)) {
757
+ if (this.shouldUseCache(this.type)) {
746
758
  let cached_results = await this.getCacheProviderObject(
747
759
  this.type
748
760
  ).get(key);
@@ -764,7 +776,7 @@ export default class SpiceModel {
764
776
  }
765
777
  } else {
766
778
  if (args.is_full_text && args.is_full_text === "true") {
767
- if (this.shouldCache(this.type)) {
779
+ if (this.shouldUseCache(this.type)) {
768
780
  let cached_results = await this.getCacheProviderObject(
769
781
  this.type
770
782
  ).get(key);
@@ -794,7 +806,7 @@ export default class SpiceModel {
794
806
  );
795
807
  }
796
808
  } else {
797
- if (this.shouldCache(this.type)) {
809
+ if (this.shouldUseCache(this.type)) {
798
810
  let cached_results = await this.getCacheProviderObject(
799
811
  this.type
800
812
  ).get(key);
@@ -931,7 +943,10 @@ export default class SpiceModel {
931
943
 
932
944
  var returned_all = await Promise.allSettled(
933
945
  _.map(classes, (obj) => {
934
- return new obj(this[_args]).getMulti({
946
+ return new obj({
947
+ ...this[_args],
948
+ skip_cache: this[_skip_cache],
949
+ }).getMulti({
935
950
  ids: ids,
936
951
  });
937
952
  })
@@ -986,7 +1001,10 @@ export default class SpiceModel {
986
1001
  let classes = _.isArray(Class) ? Class : [Class];
987
1002
  var returned_all = await Promise.allSettled(
988
1003
  _.map(classes, (obj) => {
989
- return new obj(this[_args]).getMulti({
1004
+ return new obj({
1005
+ ...this[_args],
1006
+ skip_cache: this[_skip_cache],
1007
+ }).getMulti({
990
1008
  ids: ids,
991
1009
  });
992
1010
  })