spice-js 2.6.84 → 2.7.0

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.
package/, ADDED
File without changes
@@ -168,8 +168,7 @@ class SpiceModel {
168
168
  }
169
169
 
170
170
  return props;
171
- } //console.log("Applying Overrides to :", this.collection,'||', args.collection)
172
-
171
+ }
173
172
 
174
173
  args.props = applySchemaOverrides(removeDynamicProps(args.props), args.collection);
175
174
  this[_props] = args.props;
@@ -232,7 +231,7 @@ class SpiceModel {
232
231
  that = this;
233
232
  this.createModifiersFromProps();
234
233
  } catch (e) {
235
- console.log(e.stack);
234
+ console.warn(e.stack);
236
235
  } // }
237
236
 
238
237
  }
@@ -682,7 +681,7 @@ class SpiceModel {
682
681
 
683
682
  return yield doGet();
684
683
  } catch (e) {
685
- console.log(e.message, e);
684
+ console.warn(e.message, e);
686
685
  throw e;
687
686
  }
688
687
  })();
@@ -750,7 +749,7 @@ class SpiceModel {
750
749
 
751
750
  return results;
752
751
  } catch (e) {
753
- console.log(e.stack);
752
+ console.warn(e.stack);
754
753
  throw e;
755
754
  }
756
755
  })();
@@ -869,7 +868,7 @@ class SpiceModel {
869
868
 
870
869
  return yield doUpdate();
871
870
  } catch (e) {
872
- console.log("Error on update", e, e.stack);
871
+ console.warn("Error on update", e, e.stack);
873
872
  throw e;
874
873
  }
875
874
  })();
@@ -962,7 +961,7 @@ class SpiceModel {
962
961
 
963
962
  return yield doCreate();
964
963
  } catch (e) {
965
- console.log(e.stack);
964
+ console.warn(e.stack);
966
965
  throw e;
967
966
  }
968
967
  })();
@@ -983,7 +982,7 @@ class SpiceModel {
983
982
  touch_response = yield _this10.database.touch(args.id, args._ttl);
984
983
  return touch_response;
985
984
  } catch (e) {
986
- console.log(e.stack);
985
+ console.warn(e.stack);
987
986
  throw e;
988
987
  }
989
988
  })();
@@ -1063,7 +1062,7 @@ class SpiceModel {
1063
1062
 
1064
1063
  return yield doDelete();
1065
1064
  } catch (e) {
1066
- console.log(e.stack);
1065
+ console.warn(e.stack);
1067
1066
  throw e;
1068
1067
  }
1069
1068
  })();
@@ -1433,7 +1432,7 @@ class SpiceModel {
1433
1432
 
1434
1433
  return yield doList();
1435
1434
  } catch (e) {
1436
- console.log(e.stack);
1435
+ console.warn(e.stack);
1437
1436
  throw e;
1438
1437
  }
1439
1438
  })();
@@ -1781,8 +1780,6 @@ class SpiceModel {
1781
1780
 
1782
1781
  var _loop = function _loop(i) {
1783
1782
  if (properties[i].map) {
1784
- console.log("properties[i].map", properties[i].map);
1785
-
1786
1783
  switch (properties[i].map.type) {
1787
1784
  case _2.MapType.MODEL:
1788
1785
  {
@@ -1918,8 +1915,6 @@ class SpiceModel {
1918
1915
 
1919
1916
 
1920
1917
  if (_this18.type && !_this18[_external_modifier_loaded]) {
1921
- console.trace("adding external modifiers", _this18.type);
1922
-
1923
1918
  _this18.addExternalModifiers(_this18.type);
1924
1919
 
1925
1920
  _this18[_external_modifier_loaded] = true;
@@ -1935,8 +1930,7 @@ class SpiceModel {
1935
1930
  var genericModifiers = [];
1936
1931
 
1937
1932
  for (var modifier of modifiers) {
1938
- console.log("modifier", modifier); // Skip field-specific modifiers if columns specified and neither source nor destination field is requested
1939
-
1933
+ // Skip field-specific modifiers if columns specified and neither source nor destination field is requested
1940
1934
  if (requestedColumns && modifier.field && !requestedColumns.has(modifier.field) && !(modifier.sourceField && requestedColumns.has(modifier.sourceField))) {
1941
1935
  continue;
1942
1936
  } // Field modifiers have a .field property and .execute function - they can run in parallel
@@ -1953,61 +1947,30 @@ class SpiceModel {
1953
1947
  for (var _modifier of genericModifiers) {
1954
1948
  try {
1955
1949
  var executeFn = typeof _modifier === "function" ? _modifier : _modifier.execute;
1956
- data = yield executeFn(data, old_data, _this18[_ctx], _this18.type);
1950
+ var result = yield executeFn(data, old_data, _this18[_ctx], _this18.type); // Only assign if modifier returned a value to prevent data corruption
1951
+
1952
+ if (result !== undefined) {
1953
+ data = result;
1954
+ }
1957
1955
  } catch (error) {
1958
1956
  console.error("Modifier error in do_serialize (generic):", error.stack);
1959
1957
  }
1960
- } // ⚡ OPTIMIZED: Run field-specific modifiers in PARALLEL - each populates a different field
1958
+ } // Run field-specific modifiers SERIALLY to allow proper deduplication
1959
+ // of nested relation lookups (parallel execution causes duplicate fetches
1960
+ // when related entities have circular references like user fields)
1961
1961
 
1962
1962
 
1963
- if (fieldModifiers.length > 0) {
1964
- var _originalIsArray = Array.isArray(data);
1963
+ for (var _modifier2 of fieldModifiers) {
1964
+ try {
1965
+ var _result = yield _modifier2.execute(data, old_data, _this18[_ctx], _this18.type); // Only assign if modifier returned a value to prevent data corruption
1965
1966
 
1966
- var dataArray = _originalIsArray ? data : [data]; // Run all field modifiers in parallel
1967
1967
 
1968
- var fieldResults = yield Promise.allSettled(fieldModifiers.map(
1969
- /*#__PURE__*/
1970
- function () {
1971
- var _ref17 = _asyncToGenerator(function* (modifier) {
1972
- try {
1973
- // Each modifier gets a copy of data and returns its field mappings
1974
- var result = yield modifier.execute(_originalIsArray ? [...dataArray] : dataArray[0], old_data, _this18[_ctx], _this18.type);
1975
- return {
1976
- field: modifier.field,
1977
- result
1978
- };
1979
- } catch (error) {
1980
- console.error("Modifier error for field " + modifier.field + ":", error.stack);
1981
- return {
1982
- field: modifier.field,
1983
- result: null,
1984
- error
1985
- };
1986
- }
1987
- });
1988
-
1989
- return function (_x3) {
1990
- return _ref17.apply(this, arguments);
1991
- };
1992
- }())); // Merge results - each field modifier added its field to the data items
1993
-
1994
- for (var outcome of fieldResults) {
1995
- if (outcome.status === "fulfilled" && outcome.value.result) {
1996
- var {
1997
- field,
1998
- result
1999
- } = outcome.value;
2000
- var resultArray = Array.isArray(result) ? result : [result]; // Copy the mapped field from each result item to the corresponding data item
2001
-
2002
- for (var i = 0; i < dataArray.length && i < resultArray.length; i++) {
2003
- if (resultArray[i] && resultArray[i][field] !== undefined) {
2004
- dataArray[i][field] = resultArray[i][field];
2005
- }
2006
- }
1968
+ if (_result !== undefined) {
1969
+ data = _result;
2007
1970
  }
1971
+ } catch (error) {
1972
+ console.error("Modifier error for field " + _modifier2.field + ":", error.stack);
2008
1973
  }
2009
-
2010
- data = _originalIsArray ? dataArray : dataArray[0];
2011
1974
  } // Ensure data is always an array for consistent processing.
2012
1975
 
2013
1976
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.6.84",
3
+ "version": "2.7.0",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -157,7 +157,6 @@ export default class SpiceModel {
157
157
  }
158
158
  return props;
159
159
  }
160
- //console.log("Applying Overrides to :", this.collection,'||', args.collection)
161
160
  args.props = applySchemaOverrides(
162
161
  removeDynamicProps(args.props),
163
162
  args.collection
@@ -221,7 +220,7 @@ export default class SpiceModel {
221
220
  that = this;
222
221
  this.createModifiersFromProps();
223
222
  } catch (e) {
224
- console.log(e.stack);
223
+ console.warn(e.stack);
225
224
  }
226
225
  // }
227
226
  }
@@ -592,7 +591,7 @@ export default class SpiceModel {
592
591
  }
593
592
  return await doGet();
594
593
  } catch (e) {
595
- console.log(e.message, e);
594
+ console.warn(e.message, e);
596
595
  throw e;
597
596
  }
598
597
  }
@@ -655,7 +654,7 @@ export default class SpiceModel {
655
654
 
656
655
  return results;
657
656
  } catch (e) {
658
- console.log(e.stack);
657
+ console.warn(e.stack);
659
658
  throw e;
660
659
  }
661
660
  }
@@ -763,7 +762,7 @@ export default class SpiceModel {
763
762
  }
764
763
  return await doUpdate();
765
764
  } catch (e) {
766
- console.log("Error on update", e, e.stack);
765
+ console.warn("Error on update", e, e.stack);
767
766
  throw e;
768
767
  }
769
768
  }
@@ -836,7 +835,7 @@ export default class SpiceModel {
836
835
  }
837
836
  return await doCreate();
838
837
  } catch (e) {
839
- console.log(e.stack);
838
+ console.warn(e.stack);
840
839
  throw e;
841
840
  }
842
841
  }
@@ -852,7 +851,7 @@ export default class SpiceModel {
852
851
  touch_response = await this.database.touch(args.id, args._ttl);
853
852
  return touch_response;
854
853
  } catch (e) {
855
- console.log(e.stack);
854
+ console.warn(e.stack);
856
855
  throw e;
857
856
  }
858
857
  }
@@ -902,7 +901,7 @@ export default class SpiceModel {
902
901
  }
903
902
  return await doDelete();
904
903
  } catch (e) {
905
- console.log(e.stack);
904
+ console.warn(e.stack);
906
905
  throw e;
907
906
  }
908
907
  }
@@ -1290,7 +1289,7 @@ export default class SpiceModel {
1290
1289
  }
1291
1290
  return await doList();
1292
1291
  } catch (e) {
1293
- console.log(e.stack);
1292
+ console.warn(e.stack);
1294
1293
  throw e;
1295
1294
  }
1296
1295
  }
@@ -1616,7 +1615,6 @@ export default class SpiceModel {
1616
1615
  createMofifier(properties) {
1617
1616
  for (let i in properties) {
1618
1617
  if (properties[i].map) {
1619
- console.log("properties[i].map", properties[i].map);
1620
1618
  switch (properties[i].map.type) {
1621
1619
  case MapType.MODEL: {
1622
1620
  const destinationField = properties[i].map.destination || i;
@@ -1719,7 +1717,6 @@ export default class SpiceModel {
1719
1717
 
1720
1718
  // Add external modifiers only once.
1721
1719
  if (this.type && !this[_external_modifier_loaded]) {
1722
- console.trace("adding external modifiers", this.type);
1723
1720
  this.addExternalModifiers(this.type);
1724
1721
  this[_external_modifier_loaded] = true;
1725
1722
  }
@@ -1735,7 +1732,6 @@ export default class SpiceModel {
1735
1732
  const genericModifiers = [];
1736
1733
 
1737
1734
  for (const modifier of modifiers) {
1738
- console.log("modifier", modifier);
1739
1735
  // Skip field-specific modifiers if columns specified and neither source nor destination field is requested
1740
1736
  if (
1741
1737
  requestedColumns &&
@@ -1759,7 +1755,11 @@ export default class SpiceModel {
1759
1755
  try {
1760
1756
  const executeFn =
1761
1757
  typeof modifier === "function" ? modifier : modifier.execute;
1762
- data = await executeFn(data, old_data, this[_ctx], this.type);
1758
+ const result = await executeFn(data, old_data, this[_ctx], this.type);
1759
+ // Only assign if modifier returned a value to prevent data corruption
1760
+ if (result !== undefined) {
1761
+ data = result;
1762
+ }
1763
1763
  } catch (error) {
1764
1764
  console.error(
1765
1765
  "Modifier error in do_serialize (generic):",
@@ -1768,53 +1768,27 @@ export default class SpiceModel {
1768
1768
  }
1769
1769
  }
1770
1770
 
1771
- // ⚡ OPTIMIZED: Run field-specific modifiers in PARALLEL - each populates a different field
1772
- if (fieldModifiers.length > 0) {
1773
- const originalIsArray = Array.isArray(data);
1774
- const dataArray = originalIsArray ? data : [data];
1775
-
1776
- // Run all field modifiers in parallel
1777
- const fieldResults = await Promise.allSettled(
1778
- fieldModifiers.map(async (modifier) => {
1779
- try {
1780
- // Each modifier gets a copy of data and returns its field mappings
1781
- const result = await modifier.execute(
1782
- originalIsArray ? [...dataArray] : dataArray[0],
1783
- old_data,
1784
- this[_ctx],
1785
- this.type
1786
- );
1787
- return { field: modifier.field, result };
1788
- } catch (error) {
1789
- console.error(
1790
- `Modifier error for field ${modifier.field}:`,
1791
- error.stack
1792
- );
1793
- return { field: modifier.field, result: null, error };
1794
- }
1795
- })
1796
- );
1797
-
1798
- // Merge results - each field modifier added its field to the data items
1799
- for (const outcome of fieldResults) {
1800
- if (outcome.status === "fulfilled" && outcome.value.result) {
1801
- const { field, result } = outcome.value;
1802
- const resultArray = Array.isArray(result) ? result : [result];
1803
-
1804
- // Copy the mapped field from each result item to the corresponding data item
1805
- for (
1806
- let i = 0;
1807
- i < dataArray.length && i < resultArray.length;
1808
- i++
1809
- ) {
1810
- if (resultArray[i] && resultArray[i][field] !== undefined) {
1811
- dataArray[i][field] = resultArray[i][field];
1812
- }
1813
- }
1771
+ // Run field-specific modifiers SERIALLY to allow proper deduplication
1772
+ // of nested relation lookups (parallel execution causes duplicate fetches
1773
+ // when related entities have circular references like user fields)
1774
+ for (const modifier of fieldModifiers) {
1775
+ try {
1776
+ const result = await modifier.execute(
1777
+ data,
1778
+ old_data,
1779
+ this[_ctx],
1780
+ this.type
1781
+ );
1782
+ // Only assign if modifier returned a value to prevent data corruption
1783
+ if (result !== undefined) {
1784
+ data = result;
1814
1785
  }
1786
+ } catch (error) {
1787
+ console.error(
1788
+ `Modifier error for field ${modifier.field}:`,
1789
+ error.stack
1790
+ );
1815
1791
  }
1816
-
1817
- data = originalIsArray ? dataArray : dataArray[0];
1818
1792
  }
1819
1793
 
1820
1794
  // Ensure data is always an array for consistent processing.