spice-js 2.7.22 → 2.7.23
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 +1 -1
- package/src/models/SpiceModel.js +24 -49
package/package.json
CHANGED
package/src/models/SpiceModel.js
CHANGED
|
@@ -1128,68 +1128,42 @@ export default class SpiceModel {
|
|
|
1128
1128
|
|
|
1129
1129
|
filterResultsByColumns(data, columns) {
|
|
1130
1130
|
if (columns && columns !== "") {
|
|
1131
|
+
// Remove backticks and replace meta().id with id
|
|
1131
1132
|
const cleanedColumns = columns
|
|
1132
1133
|
.replace(/`/g, "")
|
|
1133
1134
|
.replace(/meta\(\)\.id/g, "id");
|
|
1134
1135
|
|
|
1135
|
-
|
|
1136
|
+
// Process each column by splitting on comma and trimming
|
|
1137
|
+
const columnList = cleanedColumns
|
|
1136
1138
|
.split(",")
|
|
1137
1139
|
.map((col) => col.trim())
|
|
1138
1140
|
.map((col) => {
|
|
1141
|
+
// Check for alias with AS (case-insensitive)
|
|
1139
1142
|
const aliasMatch = col.match(/\s+AS\s+([\w]+)/i);
|
|
1140
1143
|
if (aliasMatch) {
|
|
1141
|
-
return
|
|
1142
|
-
original: col,
|
|
1143
|
-
path: col.replace(/\s+AS\s+[\w]+/i, "").trim(),
|
|
1144
|
-
alias: aliasMatch[1].trim(),
|
|
1145
|
-
};
|
|
1144
|
+
return aliasMatch[1].trim();
|
|
1146
1145
|
}
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
requiredKeys.forEach((key) => {
|
|
1157
|
-
if (entry.hasOwnProperty(key)) {
|
|
1158
|
-
result[key] = entry[key];
|
|
1159
|
-
}
|
|
1160
|
-
});
|
|
1161
|
-
|
|
1162
|
-
// Process each column path
|
|
1163
|
-
columnPaths.forEach(({ path, alias }) => {
|
|
1164
|
-
let actualPath = path;
|
|
1165
|
-
|
|
1166
|
-
// Remove table prefix if it matches this.type
|
|
1167
|
-
if (path.includes(".")) {
|
|
1168
|
-
const parts = path.split(".");
|
|
1169
|
-
if (parts[0] === this.type) {
|
|
1170
|
-
actualPath = parts.slice(1).join(".");
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
const value = _.get(entry, actualPath);
|
|
1175
|
-
|
|
1176
|
-
if (value !== undefined) {
|
|
1177
|
-
if (alias) {
|
|
1178
|
-
result[alias] = value;
|
|
1179
|
-
} else if (actualPath.includes(".")) {
|
|
1180
|
-
// For nested paths, use the last part as the key
|
|
1181
|
-
const key = actualPath.split(".").pop();
|
|
1182
|
-
result[key] = value;
|
|
1183
|
-
} else {
|
|
1184
|
-
result[actualPath] = value;
|
|
1146
|
+
// Otherwise, for dot-notation, keep the first segment after removing
|
|
1147
|
+
// the base model prefix (e.g. user.group.name -> group).
|
|
1148
|
+
if (col.includes(".")) {
|
|
1149
|
+
let pathParts = col
|
|
1150
|
+
.split(".")
|
|
1151
|
+
.map((part) => part.trim())
|
|
1152
|
+
.filter((part) => part !== "");
|
|
1153
|
+
if (pathParts[0] === this.type && pathParts.length > 1) {
|
|
1154
|
+
pathParts = pathParts.slice(1);
|
|
1185
1155
|
}
|
|
1156
|
+
return pathParts[0];
|
|
1186
1157
|
}
|
|
1158
|
+
return col;
|
|
1187
1159
|
});
|
|
1188
1160
|
|
|
1189
|
-
|
|
1190
|
-
|
|
1161
|
+
// Ensure that essential keys are always picked
|
|
1162
|
+
const requiredKeys = ["_permissions", "_permissions_", "id"];
|
|
1163
|
+
const finalKeys = [...new Set([...columnList, ...requiredKeys])];
|
|
1164
|
+
|
|
1165
|
+
return data.map((entry) => _.pick(entry, finalKeys));
|
|
1191
1166
|
}
|
|
1192
|
-
console.log("filterResultsByColumns", data);
|
|
1193
1167
|
return data;
|
|
1194
1168
|
}
|
|
1195
1169
|
|
|
@@ -1426,12 +1400,13 @@ export default class SpiceModel {
|
|
|
1426
1400
|
// Find alias tokens from query/columns/sort
|
|
1427
1401
|
const nestings = [
|
|
1428
1402
|
...this.extractNestings(args?.query || "", this.type),
|
|
1429
|
-
|
|
1403
|
+
//...this.extractNestings(args?.columns || "", this.type),
|
|
1430
1404
|
...this.extractNestings(args?.sort || "", this.type),
|
|
1431
1405
|
];
|
|
1432
1406
|
|
|
1433
1407
|
// Build join metadata and prepare columns
|
|
1434
1408
|
const { mappedNestings } = this.buildJoinMetadata(nestings, args);
|
|
1409
|
+
|
|
1435
1410
|
// Build JOIN/NEST from the mapped keyspaces
|
|
1436
1411
|
args._join = this.createJoinSection(mappedNestings);
|
|
1437
1412
|
|
|
@@ -1506,7 +1481,7 @@ export default class SpiceModel {
|
|
|
1506
1481
|
await this.run_hook(results.data, "list", "after");
|
|
1507
1482
|
}
|
|
1508
1483
|
|
|
1509
|
-
results.data = this.filterResultsByColumns(results.data,
|
|
1484
|
+
results.data = this.filterResultsByColumns(results.data, args.columns);
|
|
1510
1485
|
//console.log("results.data", results.data);
|
|
1511
1486
|
return results;
|
|
1512
1487
|
};
|