@fctc/interface-logic 1.5.2 → 1.5.4

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/utils.mjs CHANGED
@@ -1,6 +1,43 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __pow = Math.pow;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __spreadValues = (a, b) => {
8
+ for (var prop in b || (b = {}))
9
+ if (__hasOwnProp.call(b, prop))
10
+ __defNormalProp(a, prop, b[prop]);
11
+ if (__getOwnPropSymbols)
12
+ for (var prop of __getOwnPropSymbols(b)) {
13
+ if (__propIsEnum.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ }
16
+ return a;
17
+ };
18
+ var __async = (__this, __arguments, generator) => {
19
+ return new Promise((resolve, reject) => {
20
+ var fulfilled = (value) => {
21
+ try {
22
+ step(generator.next(value));
23
+ } catch (e) {
24
+ reject(e);
25
+ }
26
+ };
27
+ var rejected = (value) => {
28
+ try {
29
+ step(generator.throw(value));
30
+ } catch (e) {
31
+ reject(e);
32
+ }
33
+ };
34
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
35
+ step((generator = generator.apply(__this, __arguments)).next());
36
+ });
37
+ };
38
+
1
39
  // src/utils/error-handler.ts
2
40
  var WesapError = class extends Error {
3
- code;
4
41
  constructor(message, code) {
5
42
  super(message);
6
43
  this.code = code;
@@ -1387,22 +1424,6 @@ var PyRelativeDelta = class _PyRelativeDelta {
1387
1424
  this.microsecond = params.microsecond;
1388
1425
  this.weekday = params.weekday;
1389
1426
  }
1390
- years;
1391
- months;
1392
- days;
1393
- hours;
1394
- minutes;
1395
- seconds;
1396
- microseconds;
1397
- leapDays;
1398
- year;
1399
- month;
1400
- day;
1401
- hour;
1402
- minute;
1403
- second;
1404
- microsecond;
1405
- weekday;
1406
1427
  negate() {
1407
1428
  return new _PyRelativeDelta(this, -1);
1408
1429
  }
@@ -1517,7 +1538,7 @@ function execOnIterable(iterable, func) {
1517
1538
  if (typeof iterable === "object" && !Array.isArray(iterable) && !(iterable instanceof Set)) {
1518
1539
  iterable = Object.keys(iterable);
1519
1540
  }
1520
- if (typeof iterable?.[Symbol.iterator] !== "function") {
1541
+ if (typeof (iterable == null ? void 0 : iterable[Symbol.iterator]) !== "function") {
1521
1542
  throw new EvaluationError("value not iterable");
1522
1543
  }
1523
1544
  return func(iterable);
@@ -1840,7 +1861,7 @@ function applyBinaryOp(ast, context) {
1840
1861
  }
1841
1862
  return Math.floor(left / right);
1842
1863
  case "**":
1843
- return left ** right;
1864
+ return __pow(left, right);
1844
1865
  case "==":
1845
1866
  return isEqual(left, right);
1846
1867
  case "<>":
@@ -1962,7 +1983,7 @@ function evaluate(ast, context = {}) {
1962
1983
  const dicts = /* @__PURE__ */ new Set();
1963
1984
  let pyContext;
1964
1985
  const evalContext = Object.create(context);
1965
- if (!evalContext?.context) {
1986
+ if (!(evalContext == null ? void 0 : evalContext.context)) {
1966
1987
  Object.defineProperty(evalContext, "context", {
1967
1988
  get() {
1968
1989
  if (!pyContext) {
@@ -1973,17 +1994,18 @@ function evaluate(ast, context = {}) {
1973
1994
  });
1974
1995
  }
1975
1996
  function _innerEvaluate(ast2) {
1976
- switch (ast2?.type) {
1997
+ var _a, _b, _c;
1998
+ switch (ast2 == null ? void 0 : ast2.type) {
1977
1999
  case 0:
1978
2000
  // Number
1979
2001
  case 1:
1980
2002
  return ast2.value;
1981
2003
  case 5:
1982
2004
  if (ast2.value in evalContext) {
1983
- if (typeof evalContext[ast2.value] === "object" && evalContext[ast2.value]?.id) {
1984
- return evalContext[ast2.value]?.id;
2005
+ if (typeof evalContext[ast2.value] === "object" && ((_a = evalContext[ast2.value]) == null ? void 0 : _a.id)) {
2006
+ return (_b = evalContext[ast2.value]) == null ? void 0 : _b.id;
1985
2007
  }
1986
- return evalContext[ast2.value] ?? false;
2008
+ return (_c = evalContext[ast2.value]) != null ? _c : false;
1987
2009
  } else if (ast2.value in BUILTINS) {
1988
2010
  return BUILTINS[ast2.value];
1989
2011
  } else {
@@ -2020,7 +2042,7 @@ function evaluate(ast, context = {}) {
2020
2042
  const args = ast2.args.map(_evaluate);
2021
2043
  const kwargs = {};
2022
2044
  for (const kwarg in ast2.kwargs) {
2023
- kwargs[kwarg] = _evaluate(ast2?.kwargs[kwarg]);
2045
+ kwargs[kwarg] = _evaluate(ast2 == null ? void 0 : ast2.kwargs[kwarg]);
2024
2046
  }
2025
2047
  if (fnValue === PyDate || fnValue === PyDateTime || fnValue === PyTime || fnValue === PyRelativeDelta || fnValue === PyTimeDelta) {
2026
2048
  return fnValue.create(...args, kwargs);
@@ -2113,7 +2135,7 @@ function evalPartialContext(_context, evaluationContext = {}) {
2113
2135
  const value = ast.value[key];
2114
2136
  try {
2115
2137
  context[key] = evaluate(value, evaluationContext);
2116
- } catch {
2138
+ } catch (e) {
2117
2139
  }
2118
2140
  }
2119
2141
  return context;
@@ -2141,9 +2163,25 @@ function escapeRegExp(str) {
2141
2163
  var InvalidDomainError = class extends Error {
2142
2164
  };
2143
2165
  var Domain = class _Domain {
2144
- ast = { type: -1, value: null };
2145
- static TRUE;
2146
- static FALSE;
2166
+ constructor(descr = []) {
2167
+ this.ast = { type: -1, value: null };
2168
+ if (descr instanceof _Domain) {
2169
+ return new _Domain(descr.toString());
2170
+ } else {
2171
+ let rawAST;
2172
+ try {
2173
+ rawAST = typeof descr === "string" ? parseExpr(descr) : toAST(descr);
2174
+ } catch (error) {
2175
+ throw new InvalidDomainError(
2176
+ `Invalid domain representation: ${descr}`,
2177
+ {
2178
+ cause: error
2179
+ }
2180
+ );
2181
+ }
2182
+ this.ast = normalizeDomainAST(rawAST);
2183
+ }
2184
+ }
2147
2185
  static combine(domains, operator) {
2148
2186
  if (domains.length === 0) {
2149
2187
  return new _Domain([]);
@@ -2222,24 +2260,6 @@ var Domain = class _Domain {
2222
2260
  processLeaf(d.ast.value, 0, "&", newDomain);
2223
2261
  return newDomain;
2224
2262
  }
2225
- constructor(descr = []) {
2226
- if (descr instanceof _Domain) {
2227
- return new _Domain(descr.toString());
2228
- } else {
2229
- let rawAST;
2230
- try {
2231
- rawAST = typeof descr === "string" ? parseExpr(descr) : toAST(descr);
2232
- } catch (error) {
2233
- throw new InvalidDomainError(
2234
- `Invalid domain representation: ${descr}`,
2235
- {
2236
- cause: error
2237
- }
2238
- );
2239
- }
2240
- this.ast = normalizeDomainAST(rawAST);
2241
- }
2242
- }
2243
2263
  contains(record) {
2244
2264
  const expr = evaluate(this.ast, record);
2245
2265
  return matchDomain(record, expr);
@@ -2258,7 +2278,7 @@ var Domain = class _Domain {
2258
2278
  return evaluatedAsList;
2259
2279
  }
2260
2280
  return this.toString();
2261
- } catch {
2281
+ } catch (e) {
2262
2282
  return this.toString();
2263
2283
  }
2264
2284
  }
@@ -2482,7 +2502,7 @@ var checkDomain = (context, domain) => {
2482
2502
  };
2483
2503
  var matchDomains = (context, domains) => {
2484
2504
  if (Array.isArray(domains)) {
2485
- if (domains?.length > 0) {
2505
+ if ((domains == null ? void 0 : domains.length) > 0) {
2486
2506
  return domains && domains.some((domain) => checkDomain(context, domain));
2487
2507
  }
2488
2508
  } else return checkDomain(context, domains);
@@ -2499,15 +2519,17 @@ var evalJSONContext = (_context, context = {}) => {
2499
2519
  }
2500
2520
  };
2501
2521
  var evalJSONDomain = (domain, context) => {
2522
+ var _a;
2502
2523
  try {
2503
2524
  if (context) {
2504
- Object.keys(context)?.forEach((key) => {
2525
+ (_a = Object.keys(context)) == null ? void 0 : _a.forEach((key) => {
2526
+ var _a2, _b;
2505
2527
  if (Array.isArray(context[key])) {
2506
- const isTypeObject = context[key]?.every(
2507
- (item) => typeof item === "object" && item !== null && item?.id !== void 0
2528
+ const isTypeObject = (_a2 = context[key]) == null ? void 0 : _a2.every(
2529
+ (item) => typeof item === "object" && item !== null && (item == null ? void 0 : item.id) !== void 0
2508
2530
  );
2509
2531
  if (isTypeObject) {
2510
- context[key] = context[key]?.map((item) => item?.id);
2532
+ context[key] = (_b = context[key]) == null ? void 0 : _b.map((item) => item == null ? void 0 : item.id);
2511
2533
  }
2512
2534
  }
2513
2535
  });
@@ -2527,7 +2549,7 @@ var formatSortingString = (input) => {
2527
2549
  if (!input) return null;
2528
2550
  return input.split(",").map((field) => {
2529
2551
  const [key, order] = field.trim().split(/\s+/);
2530
- const sortOrder = order?.toUpperCase() === "DESC" ? "DESC" : "ASC";
2552
+ const sortOrder = (order == null ? void 0 : order.toUpperCase()) === "DESC" ? "DESC" : "ASC";
2531
2553
  return `${key} ${sortOrder}`;
2532
2554
  }).join(", ");
2533
2555
  };
@@ -2571,11 +2593,11 @@ var getFieldsOnChange = (fields) => {
2571
2593
  function traverse(items) {
2572
2594
  for (const item of items) {
2573
2595
  if (item) {
2574
- if (item?.type_co === "field" && matchDomains(fields, item?.on_change)) {
2596
+ if ((item == null ? void 0 : item.type_co) === "field" && matchDomains(fields, item == null ? void 0 : item.on_change)) {
2575
2597
  result.push(item.name);
2576
2598
  }
2577
- if (item?.fields && Array.isArray(item?.fields)) {
2578
- traverse(item?.fields);
2599
+ if ((item == null ? void 0 : item.fields) && Array.isArray(item == null ? void 0 : item.fields)) {
2600
+ traverse(item == null ? void 0 : item.fields);
2579
2601
  }
2580
2602
  }
2581
2603
  }
@@ -2591,39 +2613,42 @@ var filterFieldDirty = ({
2591
2613
  model,
2592
2614
  defaultData
2593
2615
  }) => {
2594
- const data = id ? { ...dirtyFields } : { ...formValues };
2616
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
2617
+ const data = id ? __spreadValues({}, dirtyFields) : __spreadValues({}, formValues);
2595
2618
  for (const key in data) {
2596
- if (viewData?.models?.[model]?.[key]?.type === "one2many" /* ONE2MANY */) {
2619
+ if (((_c = (_b = (_a = viewData == null ? void 0 : viewData.models) == null ? void 0 : _a[model]) == null ? void 0 : _b[key]) == null ? void 0 : _c.type) === "one2many" /* ONE2MANY */) {
2597
2620
  const lineData = [];
2598
- (formValues[key] ?? []).forEach((itemData, index) => {
2599
- if (typeof itemData?.id === "string" && itemData?.id.includes("virtual")) {
2600
- delete itemData?.id;
2621
+ ((_d = formValues[key]) != null ? _d : []).forEach((itemData, index) => {
2622
+ var _a2, _b2, _c2, _d2;
2623
+ if (typeof (itemData == null ? void 0 : itemData.id) === "string" && (itemData == null ? void 0 : itemData.id.includes("virtual"))) {
2624
+ itemData == null ? true : delete itemData.id;
2601
2625
  }
2602
- if (!itemData?.id) {
2626
+ if (!(itemData == null ? void 0 : itemData.id)) {
2603
2627
  lineData.push([
2604
2628
  0 /* CREATE */,
2605
2629
  `virtual_${index}`,
2606
2630
  filterFieldDirty({
2607
- id: itemData?.id,
2631
+ id: itemData == null ? void 0 : itemData.id,
2608
2632
  viewData,
2609
2633
  formValues: itemData,
2610
2634
  dirtyFields: {},
2611
- model: viewData?.models?.[model]?.[key]?.relation,
2635
+ model: (_c2 = (_b2 = (_a2 = viewData == null ? void 0 : viewData.models) == null ? void 0 : _a2[model]) == null ? void 0 : _b2[key]) == null ? void 0 : _c2.relation,
2612
2636
  defaultData
2613
2637
  })
2614
2638
  ]);
2615
- } else if (dirtyFields[key]?.length) {
2639
+ } else if ((_d2 = dirtyFields[key]) == null ? void 0 : _d2.length) {
2616
2640
  dirtyFields[key].forEach((itemDirty, indexDirty) => {
2641
+ var _a3, _b3, _c3;
2617
2642
  if (Object.values(itemDirty).includes(true) && indexDirty === index) {
2618
2643
  lineData.push([
2619
2644
  1 /* UPDATE */,
2620
- itemData?.id,
2645
+ itemData == null ? void 0 : itemData.id,
2621
2646
  filterFieldDirty({
2622
- id: itemData?.id,
2647
+ id: itemData == null ? void 0 : itemData.id,
2623
2648
  viewData,
2624
2649
  formValues: itemData,
2625
2650
  dirtyFields: itemDirty,
2626
- model: viewData?.models?.[model]?.[key]?.relation,
2651
+ model: (_c3 = (_b3 = (_a3 = viewData == null ? void 0 : viewData.models) == null ? void 0 : _a3[model]) == null ? void 0 : _b3[key]) == null ? void 0 : _c3.relation,
2627
2652
  defaultData: {}
2628
2653
  })
2629
2654
  ]);
@@ -2631,37 +2656,39 @@ var filterFieldDirty = ({
2631
2656
  });
2632
2657
  }
2633
2658
  });
2634
- (defaultData[key] ?? []).forEach((item) => {
2635
- if (!(formValues[key] ?? []).find(
2636
- (itemData) => itemData?.id === item?.id
2659
+ ((_e = defaultData[key]) != null ? _e : []).forEach((item) => {
2660
+ var _a2;
2661
+ if (!((_a2 = formValues[key]) != null ? _a2 : []).find(
2662
+ (itemData) => (itemData == null ? void 0 : itemData.id) === (item == null ? void 0 : item.id)
2637
2663
  )) {
2638
- lineData.push([2 /* DELETE */, item?.id, item]);
2664
+ lineData.push([2 /* DELETE */, item == null ? void 0 : item.id, item]);
2639
2665
  }
2640
2666
  });
2641
2667
  data[key] = lineData;
2642
- } else if (viewData?.models?.[model]?.[key]?.type === "many2many" /* MANY2MANY */) {
2668
+ } else if (((_h = (_g = (_f = viewData == null ? void 0 : viewData.models) == null ? void 0 : _f[model]) == null ? void 0 : _g[key]) == null ? void 0 : _h.type) === "many2many" /* MANY2MANY */) {
2643
2669
  const lineData = [];
2644
2670
  (formValues[key] || []).forEach((itemData) => {
2645
- if (itemData?.id) {
2646
- lineData.push([4 /* NO_CHANGE */, itemData?.id]);
2671
+ if (itemData == null ? void 0 : itemData.id) {
2672
+ lineData.push([4 /* NO_CHANGE */, itemData == null ? void 0 : itemData.id]);
2647
2673
  }
2648
2674
  });
2649
- (defaultData[key] ?? []).forEach((item) => {
2650
- if (!(formValues[key] ?? []).find(
2651
- (itemData) => itemData?.id === item?.id
2675
+ ((_i = defaultData[key]) != null ? _i : []).forEach((item) => {
2676
+ var _a2;
2677
+ if (!((_a2 = formValues[key]) != null ? _a2 : []).find(
2678
+ (itemData) => (itemData == null ? void 0 : itemData.id) === (item == null ? void 0 : item.id)
2652
2679
  )) {
2653
- lineData.push([3 /* UNLINK */, item?.id]);
2680
+ lineData.push([3 /* UNLINK */, item == null ? void 0 : item.id]);
2654
2681
  }
2655
2682
  });
2656
2683
  data[key] = lineData;
2657
2684
  } else {
2658
- if (id && (typeof dirtyFields?.[key] === "object" && !dirtyFields?.[key]?.id || typeof dirtyFields[key] !== "object" && !dirtyFields[key])) {
2685
+ if (id && (typeof (dirtyFields == null ? void 0 : dirtyFields[key]) === "object" && !((_j = dirtyFields == null ? void 0 : dirtyFields[key]) == null ? void 0 : _j.id) || typeof dirtyFields[key] !== "object" && !dirtyFields[key])) {
2659
2686
  delete data[key];
2660
2687
  } else {
2661
2688
  if (!data[key]) {
2662
2689
  delete data[key];
2663
2690
  } else {
2664
- data[key] = formValues?.[key]?.display_name ? formValues?.[key]?.id : formValues?.[key];
2691
+ data[key] = ((_k = formValues == null ? void 0 : formValues[key]) == null ? void 0 : _k.display_name) ? (_l = formValues == null ? void 0 : formValues[key]) == null ? void 0 : _l.id : formValues == null ? void 0 : formValues[key];
2665
2692
  }
2666
2693
  }
2667
2694
  }
@@ -2670,15 +2697,12 @@ var filterFieldDirty = ({
2670
2697
  };
2671
2698
  var mergeObjects = (object1, object2) => {
2672
2699
  if (!object1 || !object2) return void 0;
2673
- const mergedObject = { ...object2 };
2700
+ const mergedObject = __spreadValues({}, object2);
2674
2701
  Object.keys(object1).forEach((key) => {
2675
2702
  if (Array.isArray(object1[key]) && Array.isArray(object2[key])) {
2676
2703
  mergedObject[key] = object2[key].map((item, index) => {
2677
2704
  if (object1[key][index]) {
2678
- return {
2679
- ...item,
2680
- ...object1[key][index]
2681
- };
2705
+ return __spreadValues(__spreadValues({}, item), object1[key][index]);
2682
2706
  }
2683
2707
  return item;
2684
2708
  });
@@ -2720,14 +2744,15 @@ var removeUndefinedFields = (obj) => {
2720
2744
  return newObj;
2721
2745
  };
2722
2746
  var useTabModel = (viewData, onchangeData) => {
2723
- const tabsData = viewData?.views?.form?.tabs?.filter((val) => {
2747
+ var _a, _b, _c;
2748
+ const tabsData = ((_c = (_b = (_a = viewData == null ? void 0 : viewData.views) == null ? void 0 : _a.form) == null ? void 0 : _b.tabs) == null ? void 0 : _c.filter((val) => {
2724
2749
  if (!val) return null;
2725
2750
  const hide = checkDomain(onchangeData, val.invisible);
2726
2751
  if (!hide) {
2727
2752
  return val;
2728
2753
  }
2729
2754
  return false;
2730
- }) || [];
2755
+ })) || [];
2731
2756
  return tabsData;
2732
2757
  };
2733
2758
  var isBase64File = (str) => {
@@ -2768,7 +2793,7 @@ var formatFileSize = (size) => {
2768
2793
  return `${(size / Math.pow(1024, i)).toFixed(2)} ${sizes[i]}`;
2769
2794
  };
2770
2795
  var getSubdomain = (url = window.location.href) => {
2771
- const parts = url?.split(".");
2796
+ const parts = url == null ? void 0 : url.split(".");
2772
2797
  if (parts.length > 2) {
2773
2798
  return parts[0].replace("https://", "").replace("http://", "");
2774
2799
  }
@@ -2791,9 +2816,9 @@ var getOffSet = (arr, start, end) => {
2791
2816
  }
2792
2817
  return arr.slice(0, start).length;
2793
2818
  };
2794
- var copyTextToClipboard = async (text) => {
2819
+ var copyTextToClipboard = (text) => __async(null, null, function* () {
2795
2820
  if ("clipboard" in navigator) {
2796
- return await navigator.clipboard.writeText(text);
2821
+ return yield navigator.clipboard.writeText(text);
2797
2822
  } else {
2798
2823
  const textArea = document.createElement("textarea");
2799
2824
  textArea.value = text;
@@ -2807,7 +2832,7 @@ var copyTextToClipboard = async (text) => {
2807
2832
  document.body.removeChild(textArea);
2808
2833
  }
2809
2834
  }
2810
- };
2835
+ });
2811
2836
  var updateTokenParamInOriginalRequest = (originalRequest, newAccessToken) => {
2812
2837
  if (!originalRequest.data) return originalRequest.data;
2813
2838
  if (typeof originalRequest.data === "string") {
@@ -2843,7 +2868,7 @@ var useField = (props) => {
2843
2868
  index,
2844
2869
  name
2845
2870
  } = props;
2846
- const nameField = rootField ? `${rootField?.name}.${index}.${name}` : null;
2871
+ const nameField = rootField ? `${rootField == null ? void 0 : rootField.name}.${index}.${name}` : null;
2847
2872
  useEffect(() => {
2848
2873
  if (onchangeData && Object.keys(onchangeData).length > 0) {
2849
2874
  setRequired(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fctc/interface-logic",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",