spice-js 2.7.23 → 2.7.24

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.
@@ -1036,65 +1036,33 @@ class SpiceModel {
1036
1036
  }
1037
1037
  filterResultsByColumns(data, columns) {
1038
1038
  if (columns && columns !== "") {
1039
+ // Remove backticks and replace meta().id with id
1039
1040
  var cleanedColumns = columns.replace(/`/g, "").replace(/meta\(\)\.id/g, "id");
1040
- var columnPaths = cleanedColumns.split(",").map(col => col.trim()).map(col => {
1041
+
1042
+ // Process each column by splitting on comma and trimming
1043
+ var columnList = cleanedColumns.split(",").map(col => col.trim()).map(col => {
1044
+ // Check for alias with AS (case-insensitive)
1041
1045
  var aliasMatch = col.match(/\s+AS\s+([\w]+)/i);
1042
1046
  if (aliasMatch) {
1043
- return {
1044
- original: col,
1045
- path: col.replace(/\s+AS\s+[\w]+/i, "").trim(),
1046
- alias: aliasMatch[1].trim()
1047
- };
1047
+ return aliasMatch[1].trim();
1048
1048
  }
1049
- return {
1050
- original: col,
1051
- path: col,
1052
- alias: null
1053
- };
1049
+ // Otherwise, for dot-notation, keep the first segment after removing
1050
+ // the base model prefix (e.g. user.group.name -> group).
1051
+ if (col.includes(".")) {
1052
+ var pathParts = col.split(".").map(part => part.trim()).filter(part => part !== "");
1053
+ if (pathParts[0] === this.type && pathParts.length > 1) {
1054
+ pathParts = pathParts.slice(1);
1055
+ }
1056
+ return pathParts[0];
1057
+ }
1058
+ return col;
1054
1059
  });
1055
- var requiredKeys = ["_permissions", "_permissions_", "id"];
1056
- return data.map(entry => {
1057
- var result = {};
1058
-
1059
- // Add required keys
1060
- requiredKeys.forEach(key => {
1061
- if (entry.hasOwnProperty(key)) {
1062
- result[key] = entry[key];
1063
- }
1064
- });
1065
1060
 
1066
- // Process each column path
1067
- columnPaths.forEach(_ref10 => {
1068
- var {
1069
- path,
1070
- alias
1071
- } = _ref10;
1072
- var actualPath = path;
1073
-
1074
- // Remove table prefix if it matches this.type
1075
- if (path.includes(".")) {
1076
- var parts = path.split(".");
1077
- if (parts[0] === this.type) {
1078
- actualPath = parts.slice(1).join(".");
1079
- }
1080
- }
1081
- var value = _.get(entry, actualPath);
1082
- if (value !== undefined) {
1083
- if (alias) {
1084
- result[alias] = value;
1085
- } else if (actualPath.includes(".")) {
1086
- // For nested paths, use the last part as the key
1087
- var key = actualPath.split(".").pop();
1088
- result[key] = value;
1089
- } else {
1090
- result[actualPath] = value;
1091
- }
1092
- }
1093
- });
1094
- return result;
1095
- });
1061
+ // Ensure that essential keys are always picked
1062
+ var requiredKeys = ["_permissions", "_permissions_", "id"];
1063
+ var finalKeys = [...new Set([...columnList, ...requiredKeys])];
1064
+ return data.map(entry => _.pick(entry, finalKeys));
1096
1065
  }
1097
- console.log("filterResultsByColumns", data);
1098
1066
  return data;
1099
1067
  }
1100
1068
  extractNestings(string, localType) {
@@ -1135,12 +1103,12 @@ class SpiceModel {
1135
1103
  }
1136
1104
  createJoinSection(mappedNestings) {
1137
1105
  if (!mappedNestings || mappedNestings.length === 0) return "";
1138
- return mappedNestings.map(_ref11 => {
1106
+ return mappedNestings.map(_ref10 => {
1139
1107
  var {
1140
1108
  alias,
1141
1109
  reference,
1142
1110
  is_array
1143
- } = _ref11;
1111
+ } = _ref10;
1144
1112
  var keyspace = (0, _fix.fixCollection)(reference);
1145
1113
  if (is_array === true) {
1146
1114
  return "LEFT NEST `" + keyspace + "` AS `" + alias + "` ON KEYS `" + this.type + "`.`" + alias + "`";
@@ -1285,8 +1253,8 @@ class SpiceModel {
1285
1253
  // Profiling: use track() for proper async context forking
1286
1254
  var p = (_this10$_ctx = _this10[_ctx]) == null ? void 0 : _this10$_ctx.profiler;
1287
1255
  var doList = /*#__PURE__*/function () {
1288
- var _ref12 = _asyncToGenerator(function* () {
1289
- var _args10, _args11, _args12;
1256
+ var _ref11 = _asyncToGenerator(function* () {
1257
+ var _args10, _args11;
1290
1258
  if (args.mapping_dept) _this10[_mapping_dept] = args.mapping_dept;
1291
1259
  if (args.mapping_dept_exempt) _this10[_mapping_dept_exempt] = args.mapping_dept_exempt;
1292
1260
 
@@ -1302,12 +1270,15 @@ class SpiceModel {
1302
1270
  var originalColumns = args.columns;
1303
1271
 
1304
1272
  // Find alias tokens from query/columns/sort
1305
- var nestings = [..._this10.extractNestings(((_args10 = args) == null ? void 0 : _args10.query) || "", _this10.type), ..._this10.extractNestings(((_args11 = args) == null ? void 0 : _args11.columns) || "", _this10.type), ..._this10.extractNestings(((_args12 = args) == null ? void 0 : _args12.sort) || "", _this10.type)];
1273
+ var nestings = [..._this10.extractNestings(((_args10 = args) == null ? void 0 : _args10.query) || "", _this10.type),
1274
+ //...this.extractNestings(args?.columns || "", this.type),
1275
+ ..._this10.extractNestings(((_args11 = args) == null ? void 0 : _args11.sort) || "", _this10.type)];
1306
1276
 
1307
1277
  // Build join metadata and prepare columns
1308
1278
  var {
1309
1279
  mappedNestings
1310
1280
  } = _this10.buildJoinMetadata(nestings, args);
1281
+
1311
1282
  // Build JOIN/NEST from the mapped keyspaces
1312
1283
  args._join = _this10.createJoinSection(mappedNestings);
1313
1284
 
@@ -1357,20 +1328,20 @@ class SpiceModel {
1357
1328
  if (args.skip_hooks !== true) {
1358
1329
  yield _this10.run_hook(results.data, "list", "after");
1359
1330
  }
1360
- results.data = _this10.filterResultsByColumns(results.data, originalColumns);
1331
+ results.data = _this10.filterResultsByColumns(results.data, args.columns);
1361
1332
  //console.log("results.data", results.data);
1362
1333
  return results;
1363
1334
  });
1364
1335
  return function doList() {
1365
- return _ref12.apply(this, arguments);
1336
+ return _ref11.apply(this, arguments);
1366
1337
  };
1367
1338
  }();
1368
1339
  try {
1369
1340
  if (p) {
1370
- var _args13, _args14;
1341
+ var _args12, _args13;
1371
1342
  return yield p.track(_this10.type + ".list", doList, {
1372
- limit: (_args13 = args) == null ? void 0 : _args13.limit,
1373
- offset: (_args14 = args) == null ? void 0 : _args14.offset
1343
+ limit: (_args12 = args) == null ? void 0 : _args12.limit,
1344
+ offset: (_args13 = args) == null ? void 0 : _args13.offset
1374
1345
  });
1375
1346
  }
1376
1347
  return yield doList();
@@ -1416,7 +1387,7 @@ class SpiceModel {
1416
1387
  // Profiling: use track() for proper async context forking
1417
1388
  var p = (_this11$_ctx = _this11[_ctx]) == null ? void 0 : _this11$_ctx.profiler;
1418
1389
  var doFetch = /*#__PURE__*/function () {
1419
- var _ref13 = _asyncToGenerator(function* () {
1390
+ var _ref12 = _asyncToGenerator(function* () {
1420
1391
  if (args.is_custom_query === "true" && args.ids.length > 0) {
1421
1392
  return yield _this11.database.query(query);
1422
1393
  } else if (args.is_full_text === "true") {
@@ -1428,7 +1399,7 @@ class SpiceModel {
1428
1399
  }
1429
1400
  });
1430
1401
  return function doFetch() {
1431
- return _ref13.apply(this, arguments);
1402
+ return _ref12.apply(this, arguments);
1432
1403
  };
1433
1404
  }();
1434
1405
  if (p) {
@@ -1437,12 +1408,12 @@ class SpiceModel {
1437
1408
  return yield doFetch();
1438
1409
  })();
1439
1410
  }
1440
- addHook(_ref14) {
1411
+ addHook(_ref13) {
1441
1412
  var {
1442
1413
  operation,
1443
1414
  when,
1444
1415
  execute
1445
- } = _ref14;
1416
+ } = _ref13;
1446
1417
  this[_hooks][operation][when].push(execute);
1447
1418
  }
1448
1419
  run_hook(data, op, when, old_data) {
@@ -1564,7 +1535,7 @@ class SpiceModel {
1564
1535
 
1565
1536
  // ⚡ Wrap in profiler track() to ensure proper async context for child operations
1566
1537
  var fetchRelated = /*#__PURE__*/function () {
1567
- var _ref15 = _asyncToGenerator(function* () {
1538
+ var _ref14 = _asyncToGenerator(function* () {
1568
1539
  return yield Promise.allSettled(_.map(classes, obj => {
1569
1540
  var objInstance = new obj(_extends({}, _this13[_args], {
1570
1541
  skip_cache: _this13[_skip_cache],
@@ -1582,7 +1553,7 @@ class SpiceModel {
1582
1553
  }));
1583
1554
  });
1584
1555
  return function fetchRelated() {
1585
- return _ref15.apply(this, arguments);
1556
+ return _ref14.apply(this, arguments);
1586
1557
  };
1587
1558
  }();
1588
1559
  var returned_all;
@@ -1682,7 +1653,7 @@ class SpiceModel {
1682
1653
 
1683
1654
  // ⚡ Wrap in profiler track() to ensure proper async context for child operations
1684
1655
  var fetchRelated = /*#__PURE__*/function () {
1685
- var _ref16 = _asyncToGenerator(function* () {
1656
+ var _ref15 = _asyncToGenerator(function* () {
1686
1657
  return yield Promise.allSettled(_.map(classes, obj => {
1687
1658
  return new obj(_extends({}, _this14[_args], {
1688
1659
  skip_cache: _this14[_skip_cache],
@@ -1699,7 +1670,7 @@ class SpiceModel {
1699
1670
  }));
1700
1671
  });
1701
1672
  return function fetchRelated() {
1702
- return _ref16.apply(this, arguments);
1673
+ return _ref15.apply(this, arguments);
1703
1674
  };
1704
1675
  }();
1705
1676
  var returned_all;
@@ -1747,11 +1718,11 @@ class SpiceModel {
1747
1718
  return original_is_array ? data : data[0];
1748
1719
  })();
1749
1720
  }
1750
- addModifier(_ref17) {
1721
+ addModifier(_ref16) {
1751
1722
  var {
1752
1723
  when,
1753
1724
  execute
1754
- } = _ref17;
1725
+ } = _ref16;
1755
1726
  if (this[_serializers][when]) {
1756
1727
  this[_serializers][when]["modifiers"].push(execute);
1757
1728
  }
@@ -1881,7 +1852,7 @@ class SpiceModel {
1881
1852
  // Profiling: use track() for proper async context forking
1882
1853
  var p = (_this16$_ctx = _this16[_ctx]) == null ? void 0 : _this16$_ctx.profiler;
1883
1854
  var doSerialize = /*#__PURE__*/function () {
1884
- var _ref18 = _asyncToGenerator(function* () {
1855
+ var _ref17 = _asyncToGenerator(function* () {
1885
1856
  var _this16$_serializers, _this16$_serializers$;
1886
1857
  // Early exit if serialization should not run.
1887
1858
  if (!_this16.shouldSerializerRun(args, type)) {
@@ -1949,7 +1920,7 @@ class SpiceModel {
1949
1920
  return originalIsArray ? data : data[0];
1950
1921
  });
1951
1922
  return function doSerialize() {
1952
- return _ref18.apply(this, arguments);
1923
+ return _ref17.apply(this, arguments);
1953
1924
  };
1954
1925
  }();
1955
1926
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.7.23",
3
+ "version": "2.7.24",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {