@budibase/server 2.5.10-alpha.0 → 2.5.10-alpha.1

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.
@@ -63,7 +63,7 @@ const backend_core_1 = require("@budibase/backend-core");
63
63
  const staticFormula_1 = require("./staticFormula");
64
64
  const exporters_1 = require("../view/exporters");
65
65
  const fileSystem_1 = require("../../../utilities/fileSystem");
66
- const { cleanExportRows } = require("./utils");
66
+ const utils_3 = require("./utils");
67
67
  const CALCULATION_TYPES = {
68
68
  SUM: "sum",
69
69
  COUNT: "count",
@@ -398,6 +398,9 @@ function exportRows(ctx) {
398
398
  const table = yield db.get(ctx.params.tableId);
399
399
  const rowIds = ctx.request.body.rows;
400
400
  let format = ctx.query.format;
401
+ if (typeof format !== "string") {
402
+ ctx.throw(400, "Format parameter is not valid");
403
+ }
401
404
  const { columns, query } = ctx.request.body;
402
405
  let result;
403
406
  if (rowIds) {
@@ -425,7 +428,7 @@ function exportRows(ctx) {
425
428
  else {
426
429
  rows = result;
427
430
  }
428
- let exportRows = cleanExportRows(rows, schema, format, columns);
431
+ let exportRows = (0, utils_3.cleanExportRows)(rows, schema, format, columns);
429
432
  if (format === exporters_1.Format.CSV) {
430
433
  ctx.attachment("export.csv");
431
434
  return (0, fileSystem_1.apiFileReturn)((0, exporters_1.csv)(Object.keys(rows[0]), exportRows));
@@ -164,8 +164,8 @@ function cleanExportRows(rows, schema, format, columns) {
164
164
  });
165
165
  delete schema[column];
166
166
  });
167
- // Intended to avoid 'undefined' in export
168
167
  if (format === exporters_1.Format.CSV) {
168
+ // Intended to append empty values in export
169
169
  const schemaKeys = Object.keys(schema);
170
170
  for (let key of schemaKeys) {
171
171
  if ((columns === null || columns === void 0 ? void 0 : columns.length) && columns.indexOf(key) > 0) {
@@ -173,7 +173,7 @@ function cleanExportRows(rows, schema, format, columns) {
173
173
  }
174
174
  for (let row of cleanRows) {
175
175
  if (row[key] == null) {
176
- row[key] = "";
176
+ row[key] = undefined;
177
177
  }
178
178
  }
179
179
  }
@@ -43,7 +43,7 @@ const utils_1 = require("../../../integrations/utils");
43
43
  const utils_2 = require("../../../db/utils");
44
44
  const backend_core_1 = require("@budibase/backend-core");
45
45
  const sdk_1 = __importDefault(require("../../../sdk"));
46
- const csvtojson_1 = __importDefault(require("csvtojson"));
46
+ const csv_1 = require("../../../utilities/csv");
47
47
  function pickApi({ tableId, table }) {
48
48
  if (table && !tableId) {
49
49
  tableId = table._id;
@@ -136,7 +136,7 @@ exports.bulkImport = bulkImport;
136
136
  function csvToJson(ctx) {
137
137
  return __awaiter(this, void 0, void 0, function* () {
138
138
  const { csvString } = ctx.request.body;
139
- const result = yield (0, csvtojson_1.default)().fromString(csvString);
139
+ const result = yield (0, csv_1.jsonFromCsvString)(csvString);
140
140
  ctx.status = 200;
141
141
  ctx.body = result;
142
142
  });
@@ -10,7 +10,9 @@ function csv(headers, rows) {
10
10
  val =
11
11
  typeof val === "object" && !(val instanceof Date)
12
12
  ? `"${JSON.stringify(val).replace(/"/g, "'")}"`
13
- : `"${val}"`;
13
+ : val !== undefined
14
+ ? `"${val}"`
15
+ : "";
14
16
  return val.trim();
15
17
  })
16
18
  .join(",")}`;