spice-js 2.6.81 → 2.6.84

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.
@@ -12,8 +12,7 @@ var crypto = require("crypto");
12
12
 
13
13
  function generateCacheKey(input) {
14
14
  // Create an MD5 hash of the input string and return it in hexadecimal format
15
- //return crypto.createHash("md5").update(input).digest("hex");
16
- return input;
15
+ return crypto.createHash("md5").update(input).digest("hex"); //return input;
17
16
  }
18
17
 
19
18
  module.exports = class SpiceCache {
@@ -67,7 +67,7 @@ class SpiceModel {
67
67
 
68
68
  var Database = require("spice-" + dbtype);
69
69
 
70
- this[_mapping_dept] = ((_args2 = args) == null ? void 0 : (_args2$args = _args2.args) == null ? void 0 : _args2$args.mapping_dept) || 2;
70
+ this[_mapping_dept] = ((_args2 = args) == null ? void 0 : (_args2$args = _args2.args) == null ? void 0 : _args2$args.mapping_dept) || process.env.MAPPING_DEPT || 3;
71
71
  this[_mapping_dept_exempt] = ((_args3 = args) == null ? void 0 : (_args3$args = _args3.args) == null ? void 0 : _args3$args.mapping_dept_exempt) || [];
72
72
  this.type = "";
73
73
  this.collection = args.connection;
@@ -1745,14 +1745,16 @@ class SpiceModel {
1745
1745
  var {
1746
1746
  when,
1747
1747
  execute,
1748
- field = null
1748
+ field = null,
1749
+ sourceField = null
1749
1750
  } = _ref15;
1750
1751
 
1751
1752
  if (this[_serializers][when]) {
1752
1753
  // Store as object with field info for column-based filtering
1753
1754
  this[_serializers][when]["modifiers"].push({
1754
1755
  execute,
1755
- field
1756
+ field,
1757
+ sourceField
1756
1758
  });
1757
1759
  }
1758
1760
  }
@@ -1779,6 +1781,8 @@ class SpiceModel {
1779
1781
 
1780
1782
  var _loop = function _loop(i) {
1781
1783
  if (properties[i].map) {
1784
+ console.log("properties[i].map", properties[i].map);
1785
+
1782
1786
  switch (properties[i].map.type) {
1783
1787
  case _2.MapType.MODEL:
1784
1788
  {
@@ -1792,6 +1796,8 @@ class SpiceModel {
1792
1796
  when: properties[i].map.when || "read",
1793
1797
  field: destinationField,
1794
1798
  // ⚡ Track which field this modifier populates
1799
+ sourceField: i,
1800
+ // ⚡ Track source property for column filtering
1795
1801
  execute: function () {
1796
1802
  var _execute = _asyncToGenerator(function* (data) {
1797
1803
  return yield _this17.mapToObject(data, _.isString(properties[i].map.reference) ? spice.models[properties[i].map.reference] : properties[i].map.reference, i, destinationField, properties[i]);
@@ -1815,6 +1821,8 @@ class SpiceModel {
1815
1821
  when: properties[i].map.when || "read",
1816
1822
  field: destinationField,
1817
1823
  // ⚡ Track which field this modifier populates
1824
+ sourceField: i,
1825
+ // ⚡ Track source property for column filtering
1818
1826
  execute: function () {
1819
1827
  var _execute2 = _asyncToGenerator(function* (data) {
1820
1828
  return yield _this17.mapToObjectArray(data, _.isString(properties[i].map.reference) ? spice.models[properties[i].map.reference] : properties[i].map.reference, i, destinationField, properties[i]);
@@ -1910,6 +1918,8 @@ class SpiceModel {
1910
1918
 
1911
1919
 
1912
1920
  if (_this18.type && !_this18[_external_modifier_loaded]) {
1921
+ console.trace("adding external modifiers", _this18.type);
1922
+
1913
1923
  _this18.addExternalModifiers(_this18.type);
1914
1924
 
1915
1925
  _this18[_external_modifier_loaded] = true;
@@ -1925,8 +1935,9 @@ class SpiceModel {
1925
1935
  var genericModifiers = [];
1926
1936
 
1927
1937
  for (var modifier of modifiers) {
1928
- // Skip field-specific modifiers if columns specified and field not requested
1929
- if (requestedColumns && modifier.field && !requestedColumns.has(modifier.field)) {
1938
+ console.log("modifier", modifier); // Skip field-specific modifiers if columns specified and neither source nor destination field is requested
1939
+
1940
+ if (requestedColumns && modifier.field && !requestedColumns.has(modifier.field) && !(modifier.sourceField && requestedColumns.has(modifier.sourceField))) {
1930
1941
  continue;
1931
1942
  } // Field modifiers have a .field property and .execute function - they can run in parallel
1932
1943
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.6.81",
3
+ "version": "2.6.84",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -3,8 +3,8 @@ const crypto = require("crypto");
3
3
 
4
4
  function generateCacheKey(input) {
5
5
  // Create an MD5 hash of the input string and return it in hexadecimal format
6
- //return crypto.createHash("md5").update(input).digest("hex");
7
- return input;
6
+ return crypto.createHash("md5").update(input).digest("hex");
7
+ //return input;
8
8
  }
9
9
 
10
10
  module.exports = class SpiceCache {
@@ -53,7 +53,8 @@ export default class SpiceModel {
53
53
  var dbtype =
54
54
  spice.config.database.connections[args.connection].type || "couchbase";
55
55
  let Database = require(`spice-${dbtype}`);
56
- this[_mapping_dept] = args?.args?.mapping_dept || 2;
56
+ this[_mapping_dept] =
57
+ args?.args?.mapping_dept || process.env.MAPPING_DEPT || 3;
57
58
  this[_mapping_dept_exempt] = args?.args?.mapping_dept_exempt || [];
58
59
  this.type = "";
59
60
  this.collection = args.connection;
@@ -1589,10 +1590,14 @@ export default class SpiceModel {
1589
1590
  return original_is_array ? data : data[0];
1590
1591
  }
1591
1592
 
1592
- addModifier({ when, execute, field = null }) {
1593
+ addModifier({ when, execute, field = null, sourceField = null }) {
1593
1594
  if (this[_serializers][when]) {
1594
1595
  // Store as object with field info for column-based filtering
1595
- this[_serializers][when]["modifiers"].push({ execute, field });
1596
+ this[_serializers][when]["modifiers"].push({
1597
+ execute,
1598
+ field,
1599
+ sourceField,
1600
+ });
1596
1601
  }
1597
1602
  }
1598
1603
 
@@ -1611,6 +1616,7 @@ export default class SpiceModel {
1611
1616
  createMofifier(properties) {
1612
1617
  for (let i in properties) {
1613
1618
  if (properties[i].map) {
1619
+ console.log("properties[i].map", properties[i].map);
1614
1620
  switch (properties[i].map.type) {
1615
1621
  case MapType.MODEL: {
1616
1622
  const destinationField = properties[i].map.destination || i;
@@ -1620,6 +1626,7 @@ export default class SpiceModel {
1620
1626
  this.addModifier({
1621
1627
  when: properties[i].map.when || "read",
1622
1628
  field: destinationField, // ⚡ Track which field this modifier populates
1629
+ sourceField: i, // ⚡ Track source property for column filtering
1623
1630
  execute: async (data) => {
1624
1631
  return await this.mapToObject(
1625
1632
  data,
@@ -1639,6 +1646,7 @@ export default class SpiceModel {
1639
1646
  this.addModifier({
1640
1647
  when: properties[i].map.when || "read",
1641
1648
  field: destinationField, // ⚡ Track which field this modifier populates
1649
+ sourceField: i, // ⚡ Track source property for column filtering
1642
1650
  execute: async (data) => {
1643
1651
  return await this.mapToObjectArray(
1644
1652
  data,
@@ -1711,6 +1719,7 @@ export default class SpiceModel {
1711
1719
 
1712
1720
  // Add external modifiers only once.
1713
1721
  if (this.type && !this[_external_modifier_loaded]) {
1722
+ console.trace("adding external modifiers", this.type);
1714
1723
  this.addExternalModifiers(this.type);
1715
1724
  this[_external_modifier_loaded] = true;
1716
1725
  }
@@ -1726,11 +1735,13 @@ export default class SpiceModel {
1726
1735
  const genericModifiers = [];
1727
1736
 
1728
1737
  for (const modifier of modifiers) {
1729
- // Skip field-specific modifiers if columns specified and field not requested
1738
+ console.log("modifier", modifier);
1739
+ // Skip field-specific modifiers if columns specified and neither source nor destination field is requested
1730
1740
  if (
1731
1741
  requestedColumns &&
1732
1742
  modifier.field &&
1733
- !requestedColumns.has(modifier.field)
1743
+ !requestedColumns.has(modifier.field) &&
1744
+ !(modifier.sourceField && requestedColumns.has(modifier.sourceField))
1734
1745
  ) {
1735
1746
  continue;
1736
1747
  }