@adminforth/import-export 1.6.0 → 1.6.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.
Files changed (3) hide show
  1. package/dist/index.js +20 -1
  2. package/index.ts +18 -1
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -158,7 +158,14 @@ export default class ImportExport extends AdminForthPlugin {
158
158
  });
159
159
  const fields = columns.map((col) => col.name);
160
160
  const rows = data.data.map((row) => {
161
- return columns.map((col) => row[col.name]);
161
+ return columns.map((col) => {
162
+ var _a;
163
+ const value = row[col.name];
164
+ if (col.type === AdminForthDataTypes.JSON || ((_a = col.isArray) === null || _a === void 0 ? void 0 : _a.enabled)) {
165
+ return value == null ? value : JSON.stringify(value);
166
+ }
167
+ return value;
168
+ });
162
169
  });
163
170
  this.tryToAuditLogAction('export', `Export CSV with filters: ${JSON.stringify(filters)} and sort: ${JSON.stringify(sort)}. Total records: ${rows.length}`, adminUser, headers);
164
171
  return {
@@ -379,6 +386,7 @@ export default class ImportExport extends AdminForthPlugin {
379
386
  return rows;
380
387
  }
381
388
  coerceValue(resourceCol, val) {
389
+ var _a;
382
390
  if (!resourceCol || val === '') {
383
391
  return val;
384
392
  }
@@ -392,6 +400,17 @@ export default class ImportExport extends AdminForthPlugin {
392
400
  }
393
401
  return val === 1 || val === true;
394
402
  }
403
+ if (resourceCol.type === AdminForthDataTypes.JSON || ((_a = resourceCol.isArray) === null || _a === void 0 ? void 0 : _a.enabled)) {
404
+ if (typeof val === 'string') {
405
+ try {
406
+ return JSON.parse(val);
407
+ }
408
+ catch (_b) {
409
+ return val;
410
+ }
411
+ }
412
+ return val;
413
+ }
395
414
  return val;
396
415
  }
397
416
  }
package/index.ts CHANGED
@@ -181,7 +181,13 @@ export default class ImportExport extends AdminForthPlugin {
181
181
  const fields = columns.map((col) => col.name);
182
182
 
183
183
  const rows = data.data.map((row) => {
184
- return columns.map((col) => row[col.name]);
184
+ return columns.map((col) => {
185
+ const value = row[col.name];
186
+ if (col.type === AdminForthDataTypes.JSON || col.isArray?.enabled) {
187
+ return value == null ? value : JSON.stringify(value);
188
+ }
189
+ return value;
190
+ });
185
191
  });
186
192
 
187
193
  this.tryToAuditLogAction('export', `Export CSV with filters: ${JSON.stringify(filters)} and sort: ${JSON.stringify(sort)}. Total records: ${rows.length}`, adminUser, headers);
@@ -468,6 +474,17 @@ export default class ImportExport extends AdminForthPlugin {
468
474
  return val === 1 || val === true;
469
475
  }
470
476
 
477
+ if (resourceCol.type === AdminForthDataTypes.JSON || resourceCol.isArray?.enabled) {
478
+ if (typeof val === 'string') {
479
+ try {
480
+ return JSON.parse(val);
481
+ } catch {
482
+ return val;
483
+ }
484
+ }
485
+ return val;
486
+ }
487
+
471
488
  return val;
472
489
  }
473
490
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/import-export",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",