@cosmotech/core 1.10.0 → 1.10.2

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