spice-js 2.7.10 → 2.7.12
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.
|
@@ -1355,7 +1355,12 @@ class SpiceModel {
|
|
|
1355
1355
|
buildJoinMetadata(nestings, args) {
|
|
1356
1356
|
var _args$columns;
|
|
1357
1357
|
|
|
1358
|
-
//
|
|
1358
|
+
// Normalize any double backticks to single backticks early (handles URL encoding issues)
|
|
1359
|
+
if (args.columns && typeof args.columns === "string") {
|
|
1360
|
+
args.columns = args.columns.replace(/``/g, "`");
|
|
1361
|
+
} // Decide which aliases we can join: only when map.type===MODEL AND reference is a STRING keyspace.
|
|
1362
|
+
|
|
1363
|
+
|
|
1359
1364
|
var mappedNestings = _.compact(_.uniq(nestings).map(alias => {
|
|
1360
1365
|
var prop = this.props[alias];
|
|
1361
1366
|
if (!(prop == null ? void 0 : prop.map) || prop.map.type !== _2.MapType.MODEL) return null;
|
|
@@ -1547,7 +1552,8 @@ class SpiceModel {
|
|
|
1547
1552
|
yield _this12.run_hook(results.data, "list", "after");
|
|
1548
1553
|
}
|
|
1549
1554
|
|
|
1550
|
-
results.data = _this12.filterResultsByColumns(results.data, args.columns);
|
|
1555
|
+
results.data = _this12.filterResultsByColumns(results.data, args.columns); //console.log("results.data", results.data);
|
|
1556
|
+
|
|
1551
1557
|
return results;
|
|
1552
1558
|
});
|
|
1553
1559
|
|
|
@@ -196,7 +196,12 @@ class RestHelper {
|
|
|
196
196
|
ctx.set("Content-Disposition", "attachment; filename=\"" + filename + "\"");
|
|
197
197
|
ctx.type = "text/csv; charset=utf-8";
|
|
198
198
|
ctx.status = 200;
|
|
199
|
-
|
|
199
|
+
var csvStream = fs.createReadStream(filePath); // Delete file after stream is finished
|
|
200
|
+
|
|
201
|
+
csvStream.on('close', () => {
|
|
202
|
+
fs.promises.unlink(filePath).catch(() => {});
|
|
203
|
+
});
|
|
204
|
+
ctx.body = csvStream;
|
|
200
205
|
return {
|
|
201
206
|
v: void 0
|
|
202
207
|
};
|
|
@@ -213,7 +218,12 @@ class RestHelper {
|
|
|
213
218
|
ctx.set("Content-Disposition", "attachment; filename=\"" + filename + "\"");
|
|
214
219
|
ctx.type = "application/json; charset=utf-8";
|
|
215
220
|
ctx.status = 200;
|
|
216
|
-
|
|
221
|
+
var jsonStream = fs.createReadStream(filePath); // Delete file after stream is finished
|
|
222
|
+
|
|
223
|
+
jsonStream.on('close', () => {
|
|
224
|
+
fs.promises.unlink(filePath).catch(() => {});
|
|
225
|
+
});
|
|
226
|
+
ctx.body = jsonStream;
|
|
217
227
|
} catch (e) {
|
|
218
228
|
console.error(e.stack);
|
|
219
229
|
ctx.status = 400;
|
package/package.json
CHANGED
package/src/models/SpiceModel.js
CHANGED
|
@@ -1168,6 +1168,11 @@ export default class SpiceModel {
|
|
|
1168
1168
|
* @returns {Object} - { mappedNestings, protectedAliases, arrayAliases }
|
|
1169
1169
|
*/
|
|
1170
1170
|
buildJoinMetadata(nestings, args) {
|
|
1171
|
+
// Normalize any double backticks to single backticks early (handles URL encoding issues)
|
|
1172
|
+
if (args.columns && typeof args.columns === "string") {
|
|
1173
|
+
args.columns = args.columns.replace(/``/g, "`");
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1171
1176
|
// Decide which aliases we can join: only when map.type===MODEL AND reference is a STRING keyspace.
|
|
1172
1177
|
const mappedNestings = _.compact(
|
|
1173
1178
|
_.uniq(nestings).map((alias) => {
|
|
@@ -1204,7 +1209,10 @@ export default class SpiceModel {
|
|
|
1204
1209
|
// Columns: first prepare (prefix base table, rewrite array alias.field → ARRAY proj),
|
|
1205
1210
|
// then normalize names and add default aliases
|
|
1206
1211
|
//console.log("Columns in BuildJoinMetadata", args.columns);
|
|
1212
|
+
|
|
1207
1213
|
this[_columns] = args.columns ?? '';
|
|
1214
|
+
|
|
1215
|
+
|
|
1208
1216
|
args.columns = this.prepColumns(
|
|
1209
1217
|
args.columns,
|
|
1210
1218
|
protectedAliases,
|
|
@@ -1384,6 +1392,7 @@ export default class SpiceModel {
|
|
|
1384
1392
|
}
|
|
1385
1393
|
|
|
1386
1394
|
results.data = this.filterResultsByColumns(results.data, args.columns);
|
|
1395
|
+
//console.log("results.data", results.data);
|
|
1387
1396
|
return results;
|
|
1388
1397
|
};
|
|
1389
1398
|
|
|
@@ -1573,8 +1582,8 @@ export default class SpiceModel {
|
|
|
1573
1582
|
const childPath =
|
|
1574
1583
|
this[_current_path] ?
|
|
1575
1584
|
`${this[_current_path]}.${source_property}`
|
|
1576
|
-
|
|
1577
|
-
|
|
1585
|
+
: source_property;
|
|
1586
|
+
|
|
1578
1587
|
// ⚡ Wrap in profiler track() to ensure proper async context for child operations
|
|
1579
1588
|
const fetchRelated = async () => {
|
|
1580
1589
|
return await Promise.allSettled(
|
|
@@ -119,18 +119,22 @@ export default class RestHelper {
|
|
|
119
119
|
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" })
|
|
120
120
|
);
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
const csv = parse(flatRows, { fields, defaultValue: "", excelStrings: true });
|
|
123
|
+
|
|
124
124
|
makeDirectory(`./storage/exports/csv`);
|
|
125
125
|
filename = `${RestHelper.makeid(9)}.csv`;
|
|
126
126
|
filePath = path.resolve(`./storage/exports/csv/${filename}`);
|
|
127
127
|
await fs.promises.writeFile(filePath, csv, "utf8");
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
|
|
130
129
|
ctx.set("Content-Disposition", `attachment; filename="${filename}"`);
|
|
131
130
|
ctx.type = "text/csv; charset=utf-8";
|
|
132
131
|
ctx.status = 200;
|
|
133
|
-
|
|
132
|
+
const csvStream = fs.createReadStream(filePath);
|
|
133
|
+
// Delete file after stream is finished
|
|
134
|
+
csvStream.on('close', () => {
|
|
135
|
+
fs.promises.unlink(filePath).catch(() => {});
|
|
136
|
+
});
|
|
137
|
+
ctx.body = csvStream;
|
|
134
138
|
return;
|
|
135
139
|
}
|
|
136
140
|
|
|
@@ -143,7 +147,12 @@ export default class RestHelper {
|
|
|
143
147
|
ctx.set("Content-Disposition", `attachment; filename="${filename}"`);
|
|
144
148
|
ctx.type = "application/json; charset=utf-8";
|
|
145
149
|
ctx.status = 200;
|
|
146
|
-
|
|
150
|
+
const jsonStream = fs.createReadStream(filePath);
|
|
151
|
+
// Delete file after stream is finished
|
|
152
|
+
jsonStream.on('close', () => {
|
|
153
|
+
fs.promises.unlink(filePath).catch(() => {});
|
|
154
|
+
});
|
|
155
|
+
ctx.body = jsonStream;
|
|
147
156
|
|
|
148
157
|
} catch (e) {
|
|
149
158
|
console.error(e.stack);
|