spice-js 2.7.9 → 2.7.10

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.
@@ -1353,6 +1353,8 @@ class SpiceModel {
1353
1353
 
1354
1354
 
1355
1355
  buildJoinMetadata(nestings, args) {
1356
+ var _args$columns;
1357
+
1356
1358
  // Decide which aliases we can join: only when map.type===MODEL AND reference is a STRING keyspace.
1357
1359
  var mappedNestings = _.compact(_.uniq(nestings).map(alias => {
1358
1360
  var prop = this.props[alias];
@@ -1381,7 +1383,7 @@ class SpiceModel {
1381
1383
  // then normalize names and add default aliases
1382
1384
  //console.log("Columns in BuildJoinMetadata", args.columns);
1383
1385
 
1384
- this[_columns] = "" + args.columns;
1386
+ this[_columns] = (_args$columns = args.columns) != null ? _args$columns : '';
1385
1387
  args.columns = this.prepColumns(args.columns, protectedAliases, arrayAliases);
1386
1388
  args.columns = this.fixColumnName(args.columns, protectedAliases); //console.log("Columns in BuildJoinMetadata after fixColumnName", args.columns);
1387
1389
 
@@ -1981,6 +1983,34 @@ class SpiceModel {
1981
1983
  that.addModifier(modifier);
1982
1984
  });
1983
1985
  }
1986
+ /**
1987
+ * Checks if a field is present in the columns string.
1988
+ * Used to skip modifier execution when the field isn't requested.
1989
+ * @param {string} fieldName - The field name to check for
1990
+ * @param {string} columns - Comma-separated column string
1991
+ * @returns {boolean} - True if field is in columns or columns is empty (fetch all)
1992
+ */
1993
+
1994
+
1995
+ isFieldInColumns(fieldName, columns) {
1996
+ // No columns filter = include all
1997
+ if (!columns || columns === '') return true;
1998
+ var tokens = columns.split(',');
1999
+
2000
+ for (var col of tokens) {
2001
+ var trimmed = col.trim(); // Check if this column starts with the field name (exact match or nested like "fieldName.subfield")
2002
+
2003
+ var firstPart = trimmed.split('.')[0]; // Handle backtick-wrapped column names
2004
+
2005
+ var cleanFirstPart = firstPart.startsWith('`') && firstPart.endsWith('`') ? firstPart.slice(1, -1) : firstPart;
2006
+
2007
+ if (cleanFirstPart === fieldName) {
2008
+ return true;
2009
+ }
2010
+ }
2011
+
2012
+ return false;
2013
+ }
1984
2014
 
1985
2015
  createMofifier(properties) {
1986
2016
  var _this17 = this;
@@ -1998,6 +2028,11 @@ class SpiceModel {
1998
2028
  when: properties[i].map.when || "read",
1999
2029
  execute: function () {
2000
2030
  var _execute = _asyncToGenerator(function* (data, old_data, ctx, type, args, mapping_dept, level, columns) {
2031
+ // Skip if columns are specified but this field isn't included
2032
+ if (!_this17.isFieldInColumns(i, columns)) {
2033
+ return data;
2034
+ }
2035
+
2001
2036
  return yield _this17.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], args, type, mapping_dept, level, columns);
2002
2037
  });
2003
2038
 
@@ -2019,6 +2054,11 @@ class SpiceModel {
2019
2054
  when: properties[i].map.when || "read",
2020
2055
  execute: function () {
2021
2056
  var _execute2 = _asyncToGenerator(function* (data, old_data, ctx, type, args, mapping_dept, level, columns) {
2057
+ // Skip if columns are specified but this field isn't included
2058
+ if (!_this17.isFieldInColumns(i, columns)) {
2059
+ return data;
2060
+ }
2061
+
2022
2062
  return yield _this17.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], args, type, mapping_dept, level, columns);
2023
2063
  });
2024
2064
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.7.9",
3
+ "version": "2.7.10",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -1204,7 +1204,7 @@ export default class SpiceModel {
1204
1204
  // Columns: first prepare (prefix base table, rewrite array alias.field → ARRAY proj),
1205
1205
  // then normalize names and add default aliases
1206
1206
  //console.log("Columns in BuildJoinMetadata", args.columns);
1207
- this[_columns] = `${args.columns}`;
1207
+ this[_columns] = args.columns ?? '';
1208
1208
  args.columns = this.prepColumns(
1209
1209
  args.columns,
1210
1210
  protectedAliases,
@@ -1804,6 +1804,34 @@ export default class SpiceModel {
1804
1804
  });
1805
1805
  }
1806
1806
 
1807
+ /**
1808
+ * Checks if a field is present in the columns string.
1809
+ * Used to skip modifier execution when the field isn't requested.
1810
+ * @param {string} fieldName - The field name to check for
1811
+ * @param {string} columns - Comma-separated column string
1812
+ * @returns {boolean} - True if field is in columns or columns is empty (fetch all)
1813
+ */
1814
+ isFieldInColumns(fieldName, columns) {
1815
+ // No columns filter = include all
1816
+ if (!columns || columns === '') return true;
1817
+
1818
+ const tokens = columns.split(',');
1819
+ for (const col of tokens) {
1820
+ const trimmed = col.trim();
1821
+ // Check if this column starts with the field name (exact match or nested like "fieldName.subfield")
1822
+ const firstPart = trimmed.split('.')[0];
1823
+ // Handle backtick-wrapped column names
1824
+ const cleanFirstPart = firstPart.startsWith('`') && firstPart.endsWith('`')
1825
+ ? firstPart.slice(1, -1)
1826
+ : firstPart;
1827
+
1828
+ if (cleanFirstPart === fieldName) {
1829
+ return true;
1830
+ }
1831
+ }
1832
+ return false;
1833
+ }
1834
+
1807
1835
  createMofifier(properties) {
1808
1836
  for (let i in properties) {
1809
1837
  if (properties[i].map) {
@@ -1815,6 +1843,10 @@ export default class SpiceModel {
1815
1843
  this.addModifier({
1816
1844
  when: properties[i].map.when || "read",
1817
1845
  execute: async (data, old_data, ctx, type, args, mapping_dept, level, columns) => {
1846
+ // Skip if columns are specified but this field isn't included
1847
+ if (!this.isFieldInColumns(i, columns)) {
1848
+ return data;
1849
+ }
1818
1850
  return await this.mapToObject(
1819
1851
  data,
1820
1852
  _.isString(properties[i].map.reference) ?
@@ -1838,6 +1870,10 @@ export default class SpiceModel {
1838
1870
  this.addModifier({
1839
1871
  when: properties[i].map.when || "read",
1840
1872
  execute: async (data, old_data, ctx, type, args, mapping_dept, level, columns) => {
1873
+ // Skip if columns are specified but this field isn't included
1874
+ if (!this.isFieldInColumns(i, columns)) {
1875
+ return data;
1876
+ }
1841
1877
  return await this.mapToObjectArray(
1842
1878
  data,
1843
1879
  _.isString(properties[i].map.reference) ?