@cosmotech/core 1.10.0 → 1.10.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.
package/dist/index.cjs.js CHANGED
@@ -10,17 +10,14 @@ var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
10
10
 
11
11
  function ownKeys(object, enumerableOnly) {
12
12
  var keys = Object.keys(object);
13
-
14
13
  if (Object.getOwnPropertySymbols) {
15
14
  var symbols = Object.getOwnPropertySymbols(object);
16
15
  enumerableOnly && (symbols = symbols.filter(function (sym) {
17
16
  return Object.getOwnPropertyDescriptor(object, sym).enumerable;
18
17
  })), keys.push.apply(keys, symbols);
19
18
  }
20
-
21
19
  return keys;
22
20
  }
23
-
24
21
  function _objectSpread2(target) {
25
22
  for (var i = 1; i < arguments.length; i++) {
26
23
  var source = null != arguments[i] ? arguments[i] : {};
@@ -30,10 +27,8 @@ function _objectSpread2(target) {
30
27
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
31
28
  });
32
29
  }
33
-
34
30
  return target;
35
31
  }
36
-
37
32
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
38
33
  try {
39
34
  var info = gen[key](arg);
@@ -42,34 +37,28 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
42
37
  reject(error);
43
38
  return;
44
39
  }
45
-
46
40
  if (info.done) {
47
41
  resolve(value);
48
42
  } else {
49
43
  Promise.resolve(value).then(_next, _throw);
50
44
  }
51
45
  }
52
-
53
46
  function _asyncToGenerator(fn) {
54
47
  return function () {
55
48
  var self = this,
56
- args = arguments;
49
+ args = arguments;
57
50
  return new Promise(function (resolve, reject) {
58
51
  var gen = fn.apply(self, args);
59
-
60
52
  function _next(value) {
61
53
  asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
62
54
  }
63
-
64
55
  function _throw(err) {
65
56
  asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
66
57
  }
67
-
68
58
  _next(undefined);
69
59
  });
70
60
  };
71
61
  }
72
-
73
62
  function _defineProperty$w(obj, key, value) {
74
63
  if (key in obj) {
75
64
  Object.defineProperty(obj, key, {
@@ -81,7 +70,6 @@ function _defineProperty$w(obj, key, value) {
81
70
  } else {
82
71
  obj[key] = value;
83
72
  }
84
-
85
73
  return obj;
86
74
  }
87
75
 
@@ -156,7 +144,7 @@ var Parser$1 = /** @class */ (function () {
156
144
  if (rows.length === 0) {
157
145
  return [];
158
146
  }
159
- var headers_1 = rows.shift();
147
+ var headers_1 = rows.shift().map(function (k) { return k.trim(); });
160
148
  return rows.map(function (row) { return headers_1.reduce(function (data, k, i) {
161
149
  data[k] = row[i];
162
150
  return data;
@@ -599,17 +587,14 @@ __export(CSV);
599
587
  }(dist));
600
588
 
601
589
  // Copyright (c) Cosmo Tech.
602
-
603
590
  var read$1 = dataStr => {
604
591
  return dist.parse(dataStr).map(row => {
605
592
  return row.map(cell => cell.trim());
606
593
  });
607
594
  };
608
-
609
595
  var write = dataArray => {
610
596
  return dist.stringify(dataArray);
611
597
  };
612
-
613
598
  var CSVUtils = {
614
599
  read: read$1,
615
600
  write
@@ -20037,14 +20022,11 @@ var _castCellValueToStr = cellValue => {
20037
20022
  if (cellValue === null || cellValue === undefined) {
20038
20023
  return '';
20039
20024
  }
20040
-
20041
20025
  return '' + cellValue;
20042
20026
  };
20043
-
20044
20027
  var read = /*#__PURE__*/function () {
20045
20028
  var _ref = _asyncToGenerator(function* (fileBlob, forceStr, emptyCols) {
20046
20029
  var data;
20047
-
20048
20030
  try {
20049
20031
  var buffer = yield fileBlob.arrayBuffer();
20050
20032
  var workbook = readSync(buffer);
@@ -20059,21 +20041,17 @@ var read = /*#__PURE__*/function () {
20059
20041
  } catch (err) {
20060
20042
  throw new Error("Can't parse file. Please provide a valid XLSX file.");
20061
20043
  }
20062
-
20063
20044
  if (forceStr) {
20064
20045
  data = data.map(row => {
20065
20046
  return row.map(cell => _castCellValueToStr(cell));
20066
20047
  });
20067
20048
  }
20068
-
20069
20049
  return data;
20070
20050
  });
20071
-
20072
20051
  return function read(_x, _x2, _x3) {
20073
20052
  return _ref.apply(this, arguments);
20074
20053
  };
20075
20054
  }();
20076
-
20077
20055
  var XLSXUtils = {
20078
20056
  read
20079
20057
  };
@@ -33567,7 +33545,6 @@ function isMatch(dateString, formatString, options) {
33567
33545
  }
33568
33546
 
33569
33547
  // Copyright (c) Cosmo Tech.
33570
-
33571
33548
  var parse = (dateStr, dateFormat) => {
33572
33549
  try {
33573
33550
  return parse$1(dateStr, dateFormat, new Date());
@@ -33575,10 +33552,8 @@ var parse = (dateStr, dateFormat) => {
33575
33552
  console.error(error);
33576
33553
  }
33577
33554
  };
33578
-
33579
33555
  var format = function format(date) {
33580
33556
  var dateFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "yyyy-MM-dd'T'HH:mm:ss.SSSX";
33581
-
33582
33557
  if (date) {
33583
33558
  try {
33584
33559
  return format$1(date, dateFormat);
@@ -33586,46 +33561,39 @@ var format = function format(date) {
33586
33561
  console.error(error);
33587
33562
  }
33588
33563
  }
33589
-
33590
33564
  return '';
33591
33565
  };
33592
-
33593
33566
  var isValid$1 = (dateStr, dateFormat) => {
33594
33567
  return isMatch(dateStr, dateFormat);
33595
33568
  };
33596
-
33597
33569
  var min = (dateA, dateB) => {
33598
33570
  if (dateA && dateB) {
33599
33571
  return dateA < dateB ? dateA : dateB;
33600
33572
  }
33601
33573
  };
33602
-
33603
33574
  var max = (dateA, dateB) => {
33604
33575
  if (dateA && dateB) {
33605
33576
  return dateA > dateB ? dateA : dateB;
33606
33577
  }
33607
- }; // Same as min, but accepts string parameters and returns a string value
33608
-
33578
+ };
33609
33579
 
33580
+ // Same as min, but accepts string parameters and returns a string value
33610
33581
  var strMin = (dateStrA, dateStrB, dateFormat) => {
33611
33582
  var dateA = parse(dateStrA, dateFormat);
33612
33583
  var dateB = parse(dateStrB, dateFormat);
33613
-
33614
33584
  if (dateA && dateB) {
33615
33585
  return dateA < dateB ? dateStrA : dateStrB;
33616
33586
  }
33617
- }; // Same as max, but accepts string parameters and returns a string value
33618
-
33587
+ };
33619
33588
 
33589
+ // Same as max, but accepts string parameters and returns a string value
33620
33590
  var strMax = (dateStrA, dateStrB, dateFormat) => {
33621
33591
  var dateA = parse(dateStrA, dateFormat);
33622
33592
  var dateB = parse(dateStrB, dateFormat);
33623
-
33624
33593
  if (dateA && dateB) {
33625
33594
  return dateA > dateB ? dateStrA : dateStrB;
33626
33595
  }
33627
33596
  };
33628
-
33629
33597
  var DateUtils = {
33630
33598
  parse,
33631
33599
  format,
@@ -33637,75 +33605,57 @@ var DateUtils = {
33637
33605
  };
33638
33606
 
33639
33607
  // Copyright (c) Cosmo Tech.
33640
-
33641
33608
  var isBool = dataStr => {
33642
33609
  return validator.isBoolean(dataStr, {
33643
33610
  loose: true
33644
33611
  });
33645
33612
  };
33646
-
33647
33613
  var isDate = (dataStr, dateFormat) => {
33648
33614
  return DateUtils.isValid(dataStr, dateFormat);
33649
33615
  };
33650
-
33651
33616
  var isEnum = (dataStr, enumValues) => {
33652
33617
  return enumValues.indexOf(dataStr) !== -1;
33653
33618
  };
33654
-
33655
33619
  var isInt = dataStr => {
33656
33620
  return validator.isInt(dataStr);
33657
33621
  };
33658
-
33659
33622
  var isNumber = dataStr => {
33660
33623
  return validator.isNumeric(dataStr);
33661
33624
  };
33662
-
33663
33625
  var isString = data => {
33664
33626
  return typeof data === 'string';
33665
33627
  };
33666
-
33667
33628
  var isValid = function isValid(dataStr, type, options) {
33668
33629
  var canBeEmpty = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
33669
-
33670
33630
  if (canBeEmpty && dataStr === '') {
33671
33631
  return true;
33672
33632
  }
33673
-
33674
33633
  switch (type) {
33675
33634
  case 'bool':
33676
33635
  return isBool(dataStr);
33677
-
33678
33636
  case 'date':
33679
33637
  if (!options.dateFormat) {
33680
33638
  console.error("Missing option dateFormat, can't perform date validation.");
33681
33639
  return false;
33682
33640
  }
33683
-
33684
33641
  return isDate(dataStr, options.dateFormat);
33685
-
33686
33642
  case 'enum':
33687
33643
  if (!options.enumValues) {
33688
33644
  console.error("Missing option enumValues, can't perform enum validation.");
33689
33645
  return false;
33690
33646
  }
33691
-
33692
33647
  return isEnum(dataStr, options.enumValues);
33693
-
33694
33648
  case 'int':
33695
33649
  return isInt(dataStr);
33696
-
33697
33650
  case 'number':
33698
33651
  return isNumber(dataStr);
33699
-
33700
33652
  case 'string':
33701
33653
  return isString(dataStr);
33702
-
33703
33654
  default:
33704
33655
  console.error("Unknown type \"".concat(type, "\", can't perform type validation."));
33705
33656
  return false;
33706
33657
  }
33707
33658
  };
33708
-
33709
33659
  var ValidationUtils = {
33710
33660
  isBool,
33711
33661
  isDate,
@@ -33717,17 +33667,16 @@ var ValidationUtils = {
33717
33667
 
33718
33668
  // Copyright (c) Cosmo Tech.
33719
33669
  // Licensed under the MIT license.
33670
+
33720
33671
  class Error$1 {
33721
33672
  constructor(summary, loc, context) {
33722
33673
  this.summary = summary;
33723
33674
  this.loc = loc;
33724
33675
  this.context = context;
33725
33676
  }
33726
-
33727
33677
  toString() {
33728
33678
  return "Summary: ".concat(this.summary, "\n") + "Loc: ".concat(this.loc, "\n") + "Context: ".concat(this.context);
33729
33679
  }
33730
-
33731
33680
  }
33732
33681
 
33733
33682
  var _buildColumnsCountError = (missingColsCount, rowIndex, expectedColsCount, colsCount, expectedColsName, row) => {
@@ -33736,26 +33685,21 @@ var _buildColumnsCountError = (missingColsCount, rowIndex, expectedColsCount, co
33736
33685
  var errorContext = "".concat(errorSummary, " (").concat(errorLoc, ") : ").concat(expectedColsCount, " fields expected, ") + "but only ".concat(colsCount, " field").concat(colsCount > 1 ? 's' : '', " found\n") + "Expected data format : \"".concat(expectedColsName, "\"\n") + "Incorrect Row : \"".concat(row, "\"");
33737
33686
  return new Error$1(errorSummary, errorLoc, errorContext);
33738
33687
  };
33739
-
33740
33688
  var _buildTypeError = (type, rowIndex, colIndex, colsData, value, expected) => {
33741
33689
  var errorSummary = "Incorrect ".concat(type, " value");
33742
33690
  var errorLoc = "Line ".concat(rowIndex, " , Column ").concat(colIndex, " (\"").concat(colsData[colIndex].field, "\")");
33743
33691
  var errorContext = "".concat(errorSummary, " (").concat(errorLoc, ")\n") + "Incorrect value : \"".concat(value, "\" for type ").concat(type);
33744
-
33745
33692
  if (!expected || expected.length === 0) {
33746
33693
  return new Error$1(errorSummary, errorLoc, errorContext);
33747
33694
  }
33748
-
33749
33695
  return new Error$1(errorSummary, errorLoc, errorContext + '\n' + expected);
33750
33696
  };
33751
-
33752
33697
  var DEFAULT_CSV_EXPORT_OPTIONS = {
33753
33698
  colSep: ',',
33754
33699
  dateFormat: 'yyyy-MM-dd',
33755
33700
  rowSep: '\n',
33756
33701
  writeHeader: true
33757
33702
  };
33758
-
33759
33703
  var _forgeColumnsCountError = (row, rowIndex, expectedCols) => {
33760
33704
  var colsCount = Object.values(row).filter(el => el !== undefined).length;
33761
33705
  var expectedColsCount = expectedCols.length;
@@ -33763,32 +33707,26 @@ var _forgeColumnsCountError = (row, rowIndex, expectedCols) => {
33763
33707
  var missingColsCount = expectedColsCount - colsCount;
33764
33708
  return _buildColumnsCountError(missingColsCount, rowIndex, expectedColsCount, colsCount, expectedColsName, row);
33765
33709
  };
33766
-
33767
33710
  var _forgeTypeError = (value, rowIndex, type, options, colsData, colIndex) => {
33768
33711
  var expected = '';
33769
-
33770
33712
  if (type === 'enum') {
33771
33713
  expected = "Expected values: [".concat(options.enumValues.join(), "]");
33772
33714
  } else if (type === 'date') {
33773
33715
  expected = "Expected format: ".concat(options.dateFormat);
33774
33716
  }
33775
-
33776
33717
  return _buildTypeError(type, rowIndex, colIndex, colsData, value, expected);
33777
33718
  };
33778
-
33779
33719
  var _getColTypeFromTypeArray = typeArray => {
33780
33720
  if (!typeArray || typeArray.length === 0) {
33781
33721
  return 'string'; // Fall back to default type
33782
33722
  }
33783
33723
 
33784
33724
  var knownTypes = ['bool', 'date', 'enum', 'int', 'number'];
33785
-
33786
33725
  for (var type of knownTypes) {
33787
33726
  if (typeArray.indexOf(type) !== -1) {
33788
33727
  return type;
33789
33728
  }
33790
33729
  }
33791
-
33792
33730
  return 'string'; // Fall back to default type
33793
33731
  };
33794
33732
 
@@ -33799,29 +33737,21 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
33799
33737
  var errors = [];
33800
33738
  var knownColsCount = colsData.length;
33801
33739
  var startIndex = hasHeader ? 1 : 0;
33802
-
33803
33740
  var _loop = function _loop(rowIndex) {
33804
33741
  var row = rows[rowIndex];
33805
-
33806
33742
  if (row.length < knownColsCount || row.includes(undefined)) {
33807
33743
  errors.push(_forgeColumnsCountError(rows[rowIndex], rowIndex, colsData));
33808
33744
  }
33809
-
33810
33745
  row.forEach((rowCell, colIndex) => {
33811
33746
  if (colIndex < knownColsCount) {
33812
33747
  var colType = colsData[colIndex].type;
33813
-
33814
33748
  if (colType && rowCell !== undefined) {
33815
33749
  var _colsData$colIndex, _colsData$colIndex2, _colsData$colIndex2$c, _colsData$colIndex$ce, _colsData$colIndex$ce2;
33816
-
33817
33750
  var enumValues = ((_colsData$colIndex = colsData[colIndex]) === null || _colsData$colIndex === void 0 ? void 0 : _colsData$colIndex.enumValues) || ((_colsData$colIndex2 = colsData[colIndex]) === null || _colsData$colIndex2 === void 0 ? void 0 : (_colsData$colIndex2$c = _colsData$colIndex2.cellEditorParams) === null || _colsData$colIndex2$c === void 0 ? void 0 : _colsData$colIndex2$c.enumValues);
33818
-
33819
33751
  var colOptions = _objectSpread2(_objectSpread2({}, options), {}, {
33820
33752
  enumValues: enumValues
33821
33753
  });
33822
-
33823
33754
  var acceptsEmptyFields = (_colsData$colIndex$ce = (_colsData$colIndex$ce2 = colsData[colIndex].cellEditorParams) === null || _colsData$colIndex$ce2 === void 0 ? void 0 : _colsData$colIndex$ce2.acceptsEmptyFields) !== null && _colsData$colIndex$ce !== void 0 ? _colsData$colIndex$ce : false;
33824
-
33825
33755
  if (!ValidationUtils.isValid(rowCell, colType, colOptions, acceptsEmptyFields)) {
33826
33756
  errors.push(_forgeTypeError(rowCell, rowIndex, colType, colOptions, colsData, colIndex));
33827
33757
  }
@@ -33829,93 +33759,71 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
33829
33759
  }
33830
33760
  });
33831
33761
  };
33832
-
33833
33762
  for (var rowIndex = startIndex; rowIndex < rows.length; rowIndex++) {
33834
33763
  _loop(rowIndex);
33835
33764
  }
33836
-
33837
33765
  return errors;
33838
33766
  };
33839
-
33840
33767
  var _reformatBoolValue = csvCellValue => {
33841
33768
  csvCellValue = csvCellValue.toLowerCase();
33842
-
33843
33769
  if (['0', 'false', 'no'].includes(csvCellValue)) {
33844
33770
  return 'false';
33845
33771
  } else if (['1', 'true', 'yes'].includes(csvCellValue)) {
33846
33772
  return 'true';
33847
33773
  }
33848
33774
  };
33849
-
33850
33775
  var _reformatValue = (csvCellValue, colTypes) => {
33851
33776
  if (colTypes && colTypes.includes('bool')) {
33852
33777
  return _reformatBoolValue(csvCellValue);
33853
33778
  }
33854
-
33855
33779
  return csvCellValue;
33856
33780
  };
33857
-
33858
33781
  var _buildCols = header => header.map(col => ({
33859
33782
  field: col
33860
33783
  }));
33861
-
33862
33784
  var _calculateEmptyCols = cols => {
33863
33785
  if (cols === undefined) {
33864
33786
  return [];
33865
33787
  }
33866
-
33867
33788
  return cols.map((_, index) => index).filter(colIndex => {
33868
33789
  var _cols$colIndex$cellEd;
33869
-
33870
33790
  return (_cols$colIndex$cellEd = cols[colIndex].cellEditorParams) === null || _cols$colIndex$cellEd === void 0 ? void 0 : _cols$colIndex$cellEd.acceptsEmptyFields;
33871
33791
  });
33872
33792
  };
33873
-
33874
33793
  var _processTableToTransformNonAcceptableEmptyCols = (lines, emptyCols) => {
33875
33794
  return lines.map(line => line.map((cell, index) => cell === '' && !emptyCols.includes(index) ? undefined : cell));
33876
33795
  };
33877
-
33878
33796
  var _buildRows = (rows, hasHeader, cols) => {
33879
33797
  var formattedData = [];
33880
33798
  var startIndex = hasHeader ? 1 : 0;
33881
-
33882
33799
  for (var rowIndex = startIndex; rowIndex < rows.length; rowIndex++) {
33883
33800
  var row = {};
33884
-
33885
33801
  for (var colIndex = 0; colIndex < cols.length; colIndex++) {
33886
33802
  var csvCellValue = rows[rowIndex][colIndex];
33887
33803
  row[cols[colIndex].field] = _reformatValue(csvCellValue, cols[colIndex].type);
33888
33804
  }
33889
-
33890
33805
  formattedData.push(row);
33891
33806
  }
33892
-
33893
33807
  return formattedData;
33894
33808
  };
33895
-
33896
33809
  var fromCSV = function fromCSV(dataStr) {
33897
33810
  var hasHeader = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
33898
33811
  var cols = arguments.length > 2 ? arguments[2] : undefined;
33899
33812
  var options = arguments.length > 3 ? arguments[3] : undefined;
33900
-
33901
33813
  if (!hasHeader && !cols) {
33902
33814
  return {
33903
33815
  error: [new Error$1('cols must be defined if hasHeader=false', null, null)]
33904
33816
  };
33905
33817
  }
33906
-
33907
33818
  if (!dataStr || dataStr.length === 0) {
33908
33819
  return {
33909
33820
  cols: [],
33910
33821
  rows: []
33911
33822
  };
33912
33823
  }
33913
-
33914
33824
  var rows = [];
33915
33825
  var csvLines;
33916
-
33917
33826
  var emptyCols = _calculateEmptyCols(cols);
33918
-
33919
33827
  try {
33920
33828
  csvLines = _processTableToTransformNonAcceptableEmptyCols(CSVUtils.read(dataStr), emptyCols);
33921
33829
  } catch (err) {
@@ -33923,13 +33831,10 @@ var fromCSV = function fromCSV(dataStr) {
33923
33831
  error: [err]
33924
33832
  };
33925
33833
  }
33926
-
33927
33834
  if (!cols) {
33928
33835
  cols = _buildCols(csvLines[0]);
33929
33836
  }
33930
-
33931
33837
  var errors = _validateFormat(csvLines, hasHeader, cols, options);
33932
-
33933
33838
  if (errors.length > 0) return {
33934
33839
  error: errors
33935
33840
  };
@@ -33939,75 +33844,58 @@ var fromCSV = function fromCSV(dataStr) {
33939
33844
  rows: rows
33940
33845
  };
33941
33846
  };
33942
-
33943
33847
  var _generateHeader = function _generateHeader(cols) {
33944
33848
  var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ',';
33945
33849
  return cols.map(col => col.field).join(separator);
33946
33850
  };
33947
-
33948
33851
  var _generateRow = function _generateRow(row, cols) {
33949
33852
  var separator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ',';
33950
33853
  return cols.map(col => row[col.field]).join(separator);
33951
33854
  };
33952
-
33953
33855
  var _generateRows = function _generateRows(rows, cols) {
33954
33856
  var colSep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ',';
33955
33857
  var rowSep = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '\n';
33956
33858
  return rows.map(row => _generateRow(row, cols, colSep)).join(rowSep);
33957
33859
  };
33958
-
33959
33860
  var toCSV = (rows, cols, options) => {
33960
33861
  if (cols == null || cols.length === 0) {
33961
33862
  return {
33962
33863
  error: ["Cols must be defined"]
33963
33864
  };
33964
33865
  }
33965
-
33966
33866
  if (!rows) {
33967
33867
  rows = [];
33968
33868
  }
33969
-
33970
33869
  options = _objectSpread2(_objectSpread2({}, DEFAULT_CSV_EXPORT_OPTIONS), options);
33971
-
33972
33870
  var rowsStr = _generateRows(rows, cols, options.colSep, options.rowSep);
33973
-
33974
33871
  var header = '';
33975
-
33976
33872
  if (options.writeHeader) {
33977
33873
  header = _generateHeader(cols);
33978
-
33979
33874
  if (rowsStr.length > 0) {
33980
33875
  header = header.concat(options.rowSep);
33981
33876
  }
33982
33877
  }
33983
-
33984
33878
  return header.concat(rowsStr);
33985
33879
  };
33986
-
33987
33880
  var fromXLSX = /*#__PURE__*/function () {
33988
33881
  var _ref = _asyncToGenerator(function* (fileBlob) {
33989
33882
  var hasHeader = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
33990
33883
  var cols = arguments.length > 2 ? arguments[2] : undefined;
33991
33884
  var options = arguments.length > 3 ? arguments[3] : undefined;
33992
-
33993
33885
  if (!hasHeader && !cols) {
33994
33886
  return {
33995
33887
  error: [new Error$1('cols must be defined if hasHeader=false', null, null)]
33996
33888
  };
33997
33889
  }
33998
-
33999
33890
  if (!fileBlob) {
34000
33891
  return {
34001
33892
  cols: [],
34002
33893
  rows: []
34003
33894
  };
34004
33895
  }
34005
-
34006
33896
  var rows = [];
34007
33897
  var xlsxLines;
34008
-
34009
33898
  var emptyCols = _calculateEmptyCols(cols);
34010
-
34011
33899
  try {
34012
33900
  xlsxLines = yield XLSXUtils.read(fileBlob, true, emptyCols.length > 0);
34013
33901
  if (emptyCols.length > 0) xlsxLines = _processTableToTransformNonAcceptableEmptyCols(xlsxLines, emptyCols);
@@ -34016,13 +33904,10 @@ var fromXLSX = /*#__PURE__*/function () {
34016
33904
  error: [new Error$1((err === null || err === void 0 ? void 0 : err.message) || err, fileBlob.name, (err === null || err === void 0 ? void 0 : err.stack) || null)]
34017
33905
  };
34018
33906
  }
34019
-
34020
33907
  if (!cols) {
34021
33908
  cols = _buildCols(xlsxLines[0]);
34022
33909
  }
34023
-
34024
33910
  var errors = _validateFormat(xlsxLines, hasHeader, cols, options);
34025
-
34026
33911
  if (errors.length > 0) return {
34027
33912
  error: errors
34028
33913
  };
@@ -34032,12 +33917,10 @@ var fromXLSX = /*#__PURE__*/function () {
34032
33917
  rows: rows
34033
33918
  };
34034
33919
  });
34035
-
34036
33920
  return function fromXLSX(_x) {
34037
33921
  return _ref.apply(this, arguments);
34038
33922
  };
34039
33923
  }();
34040
-
34041
33924
  var AgGridUtils = {
34042
33925
  fromCSV,
34043
33926
  fromXLSX,
@@ -34081,24 +33964,19 @@ var fileDownload = function(data, filename, mime, bom) {
34081
33964
  };
34082
33965
 
34083
33966
  // Copyright (c) Cosmo Tech.
34084
-
34085
33967
  function downloadFileFromData(fileData, fileName) {
34086
33968
  fileDownload(fileData, fileName);
34087
33969
  }
34088
-
34089
33970
  function readFileBlobAsync(fileBlob) {
34090
33971
  return new Promise((resolve, reject) => {
34091
33972
  var reader = new FileReader();
34092
-
34093
33973
  reader.onload = () => {
34094
33974
  resolve(reader.result);
34095
33975
  };
34096
-
34097
33976
  reader.onerror = reject;
34098
33977
  reader.readAsText(fileBlob);
34099
33978
  });
34100
33979
  }
34101
-
34102
33980
  var FileBlobUtils = {
34103
33981
  downloadFileFromData,
34104
33982
  readFileBlobAsync
@@ -34106,38 +33984,31 @@ var FileBlobUtils = {
34106
33984
 
34107
33985
  // Copyright (c) Cosmo Tech.
34108
33986
  // Licensed under the MIT license.
33987
+
34109
33988
  var getBaseNameFromFileName = fileName => {
34110
33989
  if (fileName.indexOf('.') === -1) {
34111
33990
  return fileName;
34112
33991
  }
34113
-
34114
33992
  var nameParts = fileName.split('.');
34115
33993
  var extension = nameParts.pop();
34116
33994
  var baseName = nameParts.join('.');
34117
-
34118
33995
  if (extension.length === 0 || baseName.length === 0) {
34119
33996
  return fileName;
34120
33997
  }
34121
-
34122
33998
  return baseName;
34123
33999
  };
34124
-
34125
34000
  var getExtensionFromFileName = fileName => {
34126
34001
  if (fileName.indexOf('.') === -1) {
34127
34002
  return '';
34128
34003
  }
34129
-
34130
34004
  var nameParts = fileName.split('.');
34131
34005
  var extension = nameParts.pop();
34132
34006
  var baseName = nameParts.join('.');
34133
-
34134
34007
  if (extension.length === 0 || baseName.length === 0) {
34135
34008
  return '';
34136
34009
  }
34137
-
34138
34010
  return extension;
34139
34011
  };
34140
-
34141
34012
  var PathUtils = {
34142
34013
  getBaseNameFromFileName,
34143
34014
  getExtensionFromFileName
@@ -34145,6 +34016,7 @@ var PathUtils = {
34145
34016
 
34146
34017
  // Copyright (c) Cosmo Tech.
34147
34018
  // Licensed under the MIT license.
34019
+
34148
34020
  // Functions to read & write from storage.
34149
34021
  // Notes : local storage works on Chromium but not on Firefox if "Delete
34150
34022
  // cookies and site data when Firefox is closed" is selected (for more
@@ -34152,22 +34024,19 @@ var PathUtils = {
34152
34024
  function writeToStorage(key, value) {
34153
34025
  localStorage.setItem(key, value);
34154
34026
  }
34155
-
34156
34027
  function readFromStorage(key) {
34157
34028
  return localStorage.getItem(key);
34158
34029
  }
34159
-
34160
34030
  function clearFromStorage(key) {
34161
34031
  localStorage.removeItem(key);
34162
- } // Currently selected provider
34163
-
34164
-
34165
- var currentProvider; // Dict of registered providers
34166
-
34167
- var providers = {}; // List of callbacks to call on authentication data change
34032
+ }
34168
34033
 
34034
+ // Currently selected provider
34035
+ var currentProvider;
34036
+ // Dict of registered providers
34037
+ var providers = {};
34038
+ // List of callbacks to call on authentication data change
34169
34039
  var onAuthChangeCallbacks = [];
34170
-
34171
34040
  function addProvider(newProvider) {
34172
34041
  // Check that provider name is defined
34173
34042
  if (newProvider.name === undefined) {
@@ -34180,135 +34049,105 @@ function addProvider(newProvider) {
34180
34049
  // Otherwise, store new provider
34181
34050
  providers[newProvider.name] = newProvider;
34182
34051
  }
34183
-
34184
34052
  return providers[newProvider.name];
34185
34053
  }
34186
-
34187
34054
  function setProvider(providerName) {
34188
34055
  // Set new provider if it exists
34189
34056
  if (providers[providerName] === undefined) {
34190
34057
  console.error('Provider "' + providerName + '" does not exist, you have ' + 'to register authentication providers with "addProvider" function ' + 'before using them');
34191
34058
  currentProvider = undefined;
34192
34059
  } else {
34193
- currentProvider = providers[providerName]; // Update callbacks for the new provider
34194
-
34060
+ currentProvider = providers[providerName];
34061
+ // Update callbacks for the new provider
34195
34062
  if (currentProvider.setAuthChangeCallbacks) {
34196
34063
  currentProvider.setAuthChangeCallbacks(onAuthChangeCallbacks);
34197
- } // Store the provider used in local storage
34198
-
34199
-
34064
+ }
34065
+ // Store the provider used in local storage
34200
34066
  writeToStorage('authProvider', providerName);
34201
34067
  }
34202
- } // If no provider is currently selected but local storage has the information
34068
+ }
34069
+
34070
+ // If no provider is currently selected but local storage has the information
34203
34071
  // of a provider used (in another tab or before a page refresh, for instance),
34204
34072
  // this provider will be selected
34205
-
34206
-
34207
34073
  function initProviderIfNull() {
34208
34074
  if (currentProvider === undefined) {
34209
34075
  var newProviderName = readFromStorage('authProvider');
34210
-
34211
34076
  if (newProviderName !== undefined && newProviderName !== null) {
34212
34077
  setProvider(newProviderName);
34213
34078
  }
34214
34079
  }
34215
34080
  }
34216
-
34217
34081
  function signIn$1() {
34218
34082
  return currentProvider.signIn();
34219
34083
  }
34220
-
34221
34084
  function signOut$1() {
34222
- initProviderIfNull(); // Clear last auth provider used from local storage
34223
-
34085
+ initProviderIfNull();
34086
+ // Clear last auth provider used from local storage
34224
34087
  clearFromStorage('authProvider');
34225
34088
  return currentProvider.signOut();
34226
34089
  }
34227
-
34228
34090
  function onAuthStateChanged(newCallback) {
34229
34091
  onAuthChangeCallbacks.push(newCallback);
34230
34092
  }
34231
-
34232
34093
  function isAsync$1() {
34233
34094
  initProviderIfNull();
34234
-
34235
34095
  if (currentProvider && currentProvider.isAsync) {
34236
34096
  return currentProvider.isAsync();
34237
34097
  }
34238
-
34239
34098
  return false;
34240
34099
  }
34241
-
34242
34100
  function acquireTokens$1(callback) {
34243
34101
  initProviderIfNull();
34244
-
34245
34102
  if (currentProvider === undefined) {
34246
34103
  return undefined;
34247
34104
  }
34248
-
34249
34105
  return currentProvider.acquireTokens(callback);
34250
34106
  }
34251
-
34252
34107
  function acquireTokensByRequest$1(tokenReq) {
34253
34108
  initProviderIfNull();
34254
-
34255
34109
  if (currentProvider === undefined) {
34256
34110
  return undefined;
34257
34111
  }
34258
-
34259
34112
  return currentProvider.acquireTokensByRequest(tokenReq);
34260
34113
  }
34261
-
34262
34114
  function isUserSignedIn$1(callback) {
34263
34115
  initProviderIfNull();
34264
-
34265
34116
  if (currentProvider === undefined) {
34266
34117
  return false;
34267
34118
  }
34268
-
34269
34119
  return currentProvider.isUserSignedIn(callback);
34270
34120
  }
34271
-
34272
34121
  function getUserEmail() {
34273
34122
  if (currentProvider === undefined) {
34274
34123
  return undefined;
34275
34124
  }
34276
-
34277
34125
  return currentProvider.getUserEmail();
34278
34126
  }
34279
-
34280
34127
  function getUserName$1() {
34281
34128
  if (currentProvider === undefined) {
34282
34129
  return undefined;
34283
34130
  }
34284
-
34285
34131
  return currentProvider.getUserName();
34286
34132
  }
34287
-
34288
34133
  function getUserRoles$1() {
34289
34134
  if (currentProvider === undefined) {
34290
34135
  return undefined;
34291
34136
  }
34292
-
34293
34137
  return currentProvider.getUserRoles();
34294
34138
  }
34295
-
34296
34139
  function getUserId$1() {
34297
34140
  if (currentProvider === undefined) {
34298
34141
  return undefined;
34299
34142
  }
34300
-
34301
34143
  return currentProvider.getUserId();
34302
34144
  }
34303
-
34304
34145
  function getUserPicUrl$1() {
34305
34146
  if (currentProvider === undefined) {
34306
34147
  return undefined;
34307
34148
  }
34308
-
34309
34149
  return currentProvider.getUserPicUrl();
34310
34150
  }
34311
-
34312
34151
  var Auth = {
34313
34152
  addProvider,
34314
34153
  setProvider,
@@ -34328,9 +34167,9 @@ var Auth = {
34328
34167
 
34329
34168
  // Copyright (c) Cosmo Tech.
34330
34169
  // Licensed under the MIT license.
34170
+
34331
34171
  var name = 'auth-dev';
34332
34172
  var authData = null;
34333
-
34334
34173
  function setDefaultUser() {
34335
34174
  authData = {
34336
34175
  userId: 1,
@@ -34338,61 +34177,47 @@ function setDefaultUser() {
34338
34177
  roles: ['Organization.User']
34339
34178
  };
34340
34179
  }
34341
-
34342
34180
  function signIn() {
34343
34181
  setDefaultUser();
34344
34182
  window.location.href = '/';
34345
34183
  }
34346
-
34347
34184
  function signOut() {
34348
34185
  window.location.href = '/';
34349
34186
  }
34350
-
34351
34187
  function isAsync() {
34352
34188
  return false;
34353
34189
  }
34354
-
34355
34190
  function isUserSignedIn() {
34356
34191
  setDefaultUser();
34357
34192
  return true;
34358
34193
  }
34359
-
34360
34194
  function getUserName() {
34361
34195
  if (authData) {
34362
34196
  return authData.userName;
34363
34197
  }
34364
-
34365
34198
  return undefined;
34366
34199
  }
34367
-
34368
34200
  function acquireTokens() {
34369
34201
  return undefined;
34370
34202
  }
34371
-
34372
34203
  function acquireTokensByRequest(tokenReq) {
34373
34204
  return undefined;
34374
34205
  }
34375
-
34376
34206
  function getUserId() {
34377
34207
  if (authData) {
34378
34208
  return authData.userId;
34379
34209
  }
34380
-
34381
34210
  return undefined;
34382
34211
  }
34383
-
34384
34212
  function getUserRoles() {
34385
34213
  if (authData) {
34386
34214
  return authData.roles;
34387
34215
  }
34388
-
34389
34216
  return undefined;
34390
34217
  }
34391
-
34392
34218
  function getUserPicUrl() {
34393
34219
  return undefined;
34394
34220
  }
34395
-
34396
34221
  var AuthDev = {
34397
34222
  name,
34398
34223
  signIn,
@@ -34409,43 +34234,37 @@ var AuthDev = {
34409
34234
 
34410
34235
  // Copyright (c) Cosmo Tech.
34411
34236
  // Licensed under the MIT license.
34237
+
34412
34238
  var getDatasetNames = (datasets, scenarioDatasets) => {
34413
34239
  if (!scenarioDatasets || !datasets) {
34414
34240
  return '';
34415
34241
  }
34416
-
34417
34242
  var names = [];
34418
-
34419
34243
  var _loop = function _loop(datasetId) {
34420
34244
  var dataset = datasets.find(el => el.id === datasetId);
34421
-
34422
34245
  if (dataset) {
34423
34246
  names.push(dataset.name);
34424
34247
  }
34425
34248
  };
34426
-
34427
34249
  for (var datasetId of scenarioDatasets) {
34428
34250
  _loop(datasetId);
34429
34251
  }
34430
-
34431
34252
  return names.join(', ');
34432
34253
  };
34433
-
34434
34254
  var DatasetUtils = {
34435
34255
  getDatasetNames
34436
34256
  };
34437
34257
 
34438
34258
  // Copyright (c) Cosmo Tech.
34439
34259
  // Licensed under the MIT license.
34260
+
34440
34261
  var NAME_VALIDATOR = /^[a-zA-Z0-9][\w\s.-]*$/;
34441
34262
 
34442
34263
  // Copyright (c) Cosmo Tech.
34443
-
34444
34264
  var scenarioExistsInList = (scenarioName, scenarioList) => {
34445
34265
  scenarioName = scenarioName.trim();
34446
34266
  return scenarioList.find(scenario => scenario.name.trim() === scenarioName) !== undefined;
34447
34267
  };
34448
-
34449
34268
  var scenarioExistsInTree = (scenarioName, scenarioTree) => {
34450
34269
  var treeSearch = node => {
34451
34270
  for (var scenario of node) {
@@ -34453,16 +34272,12 @@ var scenarioExistsInTree = (scenarioName, scenarioTree) => {
34453
34272
  return true;
34454
34273
  }
34455
34274
  }
34456
-
34457
34275
  return false;
34458
34276
  };
34459
-
34460
34277
  return treeSearch(scenarioTree);
34461
34278
  };
34462
-
34463
34279
  var scenarioNameIsValid = (scenarioName, scenarioList) => {
34464
34280
  scenarioName = scenarioName.trimEnd();
34465
-
34466
34281
  if (scenarioName.length === 0) {
34467
34282
  return 'emptyScenarioName';
34468
34283
  } else {
@@ -34472,50 +34287,39 @@ var scenarioNameIsValid = (scenarioName, scenarioList) => {
34472
34287
  return 'existingScenarioName';
34473
34288
  }
34474
34289
  }
34475
-
34476
34290
  return null;
34477
34291
  };
34478
-
34479
34292
  var getScenarioTree = (scenarioList, compareFn) => {
34480
- var scenarioTree = []; // Sort scenario list based on optional user-defined function
34481
-
34482
- scenarioList.sort(compareFn); // Set master & orphan scenarios as root scenarios, and add all their children
34483
-
34293
+ var scenarioTree = [];
34294
+ // Sort scenario list based on optional user-defined function
34295
+ scenarioList.sort(compareFn);
34296
+ // Set master & orphan scenarios as root scenarios, and add all their children
34484
34297
  var _loop = function _loop(parentScenario) {
34485
34298
  if (!parentScenario.parentId || scenarioList.find(grandParent => grandParent.id === parentScenario.parentId) === undefined) {
34486
34299
  scenarioTree.push(parentScenario);
34487
34300
  }
34488
-
34489
34301
  parentScenario.children = [];
34490
-
34491
34302
  for (var childScenario of scenarioList) {
34492
34303
  if (childScenario.parentId === parentScenario.id) {
34493
34304
  parentScenario.children.push(childScenario);
34494
34305
  }
34495
34306
  }
34496
34307
  };
34497
-
34498
34308
  for (var parentScenario of scenarioList) {
34499
34309
  _loop(parentScenario);
34500
34310
  }
34501
-
34502
34311
  return scenarioTree;
34503
34312
  };
34504
-
34505
34313
  function countScenariosInTree(treeData) {
34506
34314
  if (!treeData) {
34507
34315
  return 0;
34508
34316
  }
34509
-
34510
34317
  var count = treeData.length;
34511
-
34512
34318
  for (var node of treeData) {
34513
34319
  count += countScenariosInTree(node.children);
34514
34320
  }
34515
-
34516
34321
  return count;
34517
34322
  }
34518
-
34519
34323
  var ScenarioUtils = {
34520
34324
  scenarioExistsInList,
34521
34325
  scenarioExistsInTree,