spice-js 2.6.74 → 2.6.75

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.6.74",
3
+ "version": "2.6.75",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -20,7 +20,8 @@ var SDate = require("sonover-date"),
20
20
  _skip_cache = Symbol(),
21
21
  _serializers = Symbol(),
22
22
  _level = Symbol(),
23
- _mapping_dept = Symbol();
23
+ _mapping_dept = Symbol(),
24
+ _mapping_dept_exempt = Symbol();
24
25
 
25
26
  //const _type = Symbol("type");
26
27
 
@@ -52,6 +53,7 @@ export default class SpiceModel {
52
53
  spice.config.database.connections[args.connection].type || "couchbase";
53
54
  let Database = require(`spice-${dbtype}`);
54
55
  this[_mapping_dept] = args?.args?.mapping_dept || 100;
56
+ this[_mapping_dept_exempt] = args?.args?.mapping_dept_exempt || [];
55
57
  this.type = "";
56
58
  this.collection = args.connection;
57
59
  this[_args] = args.args;
@@ -491,6 +493,8 @@ export default class SpiceModel {
491
493
 
492
494
  const doGet = async () => {
493
495
  if (args.mapping_dept) this[_mapping_dept] = args.mapping_dept;
496
+ if (args.mapping_dept_exempt)
497
+ this[_mapping_dept_exempt] = args.mapping_dept_exempt;
494
498
 
495
499
  if (!args) {
496
500
  args = {};
@@ -563,12 +567,12 @@ export default class SpiceModel {
563
567
  await this.propsToBeRemoved(results)
564
568
  );
565
569
  }
566
-
570
+
567
571
  // ⚡ OPTIMIZED: Filter results by columns if specified
568
572
  if (args.columns) {
569
573
  results = this.filterResultsByColumns([results], args.columns)[0];
570
574
  }
571
-
575
+
572
576
  if (args.skip_hooks !== true) {
573
577
  await this.run_hook(results, "get", "after");
574
578
  }
@@ -1144,6 +1148,8 @@ export default class SpiceModel {
1144
1148
 
1145
1149
  const doList = async () => {
1146
1150
  if (args.mapping_dept) this[_mapping_dept] = args.mapping_dept;
1151
+ if (args.mapping_dept_exempt)
1152
+ this[_mapping_dept_exempt] = args.mapping_dept_exempt;
1147
1153
 
1148
1154
  // Find alias tokens from query/columns/sort
1149
1155
  const nestings = [
@@ -1417,9 +1423,8 @@ export default class SpiceModel {
1417
1423
  if (!original_is_array) {
1418
1424
  data = Array.of(data);
1419
1425
  }
1420
- this[_mapping_dept];
1421
-
1422
- if (this[_level] + 1 < this[_mapping_dept]) {
1426
+ const isExempt = this[_mapping_dept_exempt].includes(source_property);
1427
+ if (isExempt || this[_level] + 1 < this[_mapping_dept]) {
1423
1428
  let classes = _.compact(_.isArray(Class) ? Class : [Class]);
1424
1429
 
1425
1430
  let ids = [];
@@ -1439,6 +1444,7 @@ export default class SpiceModel {
1439
1444
  skip_cache: this[_skip_cache],
1440
1445
  _level: this[_level] + 1,
1441
1446
  mapping_dept: this[_mapping_dept],
1447
+ mapping_dept_exempt: this[_mapping_dept_exempt],
1442
1448
  }).getMulti({
1443
1449
  skip_hooks: true,
1444
1450
  ids: ids,
@@ -1476,7 +1482,8 @@ export default class SpiceModel {
1476
1482
  if (!original_is_array) {
1477
1483
  data = Array.of(data);
1478
1484
  }
1479
- if (this[_level] + 1 < this[_mapping_dept]) {
1485
+ const isExempt = this[_mapping_dept_exempt].includes(source_property);
1486
+ if (isExempt || this[_level] + 1 < this[_mapping_dept]) {
1480
1487
  let ids = [];
1481
1488
  _.each(data, (result) => {
1482
1489
  let value = [];
@@ -1501,6 +1508,7 @@ export default class SpiceModel {
1501
1508
  skip_cache: this[_skip_cache],
1502
1509
  _level: this[_level] + 1,
1503
1510
  mapping_dept: this[_mapping_dept],
1511
+ mapping_dept_exempt: this[_mapping_dept_exempt],
1504
1512
  }).getMulti({
1505
1513
  skip_hooks: true,
1506
1514
  ids: ids,
@@ -1619,12 +1627,12 @@ export default class SpiceModel {
1619
1627
  // ⚡ Parse columns string into a Set for fast lookup
1620
1628
  parseRequestedColumns(columns) {
1621
1629
  if (!columns || columns === "") return null;
1622
-
1630
+
1623
1631
  // Extract field names from column specifications
1624
1632
  // Handles: "field", "`field`", "table.field", "`table`.`field`", "expr AS alias"
1625
1633
  const fields = new Set();
1626
1634
  const columnList = columns.split(",").map((c) => c.trim());
1627
-
1635
+
1628
1636
  for (const col of columnList) {
1629
1637
  // Check for AS alias
1630
1638
  const aliasMatch = col.match(/\s+AS\s+`?([\w]+)`?$/i);
@@ -1632,7 +1640,7 @@ export default class SpiceModel {
1632
1640
  fields.add(aliasMatch[1]);
1633
1641
  continue;
1634
1642
  }
1635
-
1643
+
1636
1644
  // Get the last part after dots (the field name)
1637
1645
  const parts = col.replace(/`/g, "").split(".");
1638
1646
  const fieldName = parts[parts.length - 1];
@@ -1640,7 +1648,7 @@ export default class SpiceModel {
1640
1648
  fields.add(fieldName);
1641
1649
  }
1642
1650
  }
1643
-
1651
+
1644
1652
  return fields.size > 0 ? fields : null;
1645
1653
  }
1646
1654
 
@@ -1668,12 +1676,17 @@ export default class SpiceModel {
1668
1676
  for (const modifier of modifiers) {
1669
1677
  try {
1670
1678
  // ⚡ OPTIMIZED: Skip field-specific modifiers if columns specified and field not requested
1671
- if (requestedColumns && modifier.field && !requestedColumns.has(modifier.field)) {
1679
+ if (
1680
+ requestedColumns &&
1681
+ modifier.field &&
1682
+ !requestedColumns.has(modifier.field)
1683
+ ) {
1672
1684
  continue; // Skip this modifier - field not in requested columns
1673
1685
  }
1674
-
1686
+
1675
1687
  // Execute modifier (supports both old function format and new object format)
1676
- const executeFn = typeof modifier === "function" ? modifier : modifier.execute;
1688
+ const executeFn =
1689
+ typeof modifier === "function" ? modifier : modifier.execute;
1677
1690
  data = await executeFn(data, old_data, this[_ctx], this.type);
1678
1691
  } catch (error) {
1679
1692
  console.error("Modifier error in do_serialize:", error.stack);