av6-core 1.6.1 → 1.6.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.
Files changed (3) hide show
  1. package/dist/index.js +216 -11
  2. package/dist/index.mjs +216 -11
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1320,15 +1320,11 @@ function customOmit(obj, keys) {
1320
1320
  return { rest, omitted };
1321
1321
  }
1322
1322
  function getDynamicValue(obj, accessorKey) {
1323
- if (!accessorKey || obj == null || typeof obj !== "object") {
1324
- return null;
1325
- }
1323
+ if (!accessorKey || obj == null || typeof obj !== "object") return null;
1326
1324
  const keys = accessorKey.split(".");
1327
1325
  let result = obj;
1328
1326
  for (const key of keys) {
1329
- if (result == null || typeof result !== "object" || !(key in result)) {
1330
- return null;
1331
- }
1327
+ if (result == null || typeof result !== "object" || !(key in result)) return null;
1332
1328
  result = result[key];
1333
1329
  }
1334
1330
  return result === void 0 ? null : result;
@@ -1592,6 +1588,213 @@ var buildJoiSchemaForOp = (cfg, op, ctx) => {
1592
1588
  });
1593
1589
  };
1594
1590
 
1591
+ // src/utils/dynamicOperation.utils.ts
1592
+ var OP_PRECEDENCE = {
1593
+ "u-": 3,
1594
+ // unary minus
1595
+ "*": 2,
1596
+ "/": 2,
1597
+ "%": 2,
1598
+ "+": 1,
1599
+ "-": 1
1600
+ };
1601
+ var OP_ASSOC = {
1602
+ "u-": "R",
1603
+ "*": "L",
1604
+ "/": "L",
1605
+ "%": "L",
1606
+ "+": "L",
1607
+ "-": "L"
1608
+ };
1609
+ function isDigit(ch) {
1610
+ return ch >= "0" && ch <= "9";
1611
+ }
1612
+ function isIdentStart(ch) {
1613
+ return /[A-Za-z_$]/.test(ch);
1614
+ }
1615
+ function isIdentPart(ch) {
1616
+ return /[A-Za-z0-9_$]/.test(ch);
1617
+ }
1618
+ function tokenize(expr) {
1619
+ const tokens = [];
1620
+ let i = 0;
1621
+ while (i < expr.length) {
1622
+ const ch = expr[i];
1623
+ if (ch === " " || ch === " " || ch === "\n" || ch === "\r") {
1624
+ i++;
1625
+ continue;
1626
+ }
1627
+ if (ch === "(" || ch === ")") {
1628
+ tokens.push({ type: "paren", value: ch });
1629
+ i++;
1630
+ continue;
1631
+ }
1632
+ if (ch === "+" || ch === "-" || ch === "*" || ch === "/" || ch === "%") {
1633
+ tokens.push({ type: "op", value: ch });
1634
+ i++;
1635
+ continue;
1636
+ }
1637
+ if (isDigit(ch) || ch === "." && isDigit(expr[i + 1] ?? "")) {
1638
+ let j = i;
1639
+ let seenDot = false;
1640
+ while (j < expr.length) {
1641
+ const c = expr[j];
1642
+ if (c === ".") {
1643
+ if (seenDot) break;
1644
+ seenDot = true;
1645
+ j++;
1646
+ continue;
1647
+ }
1648
+ if (!isDigit(c)) break;
1649
+ j++;
1650
+ }
1651
+ const raw = expr.slice(i, j);
1652
+ const num = Number(raw);
1653
+ tokens.push({ type: "number", value: num });
1654
+ i = j;
1655
+ continue;
1656
+ }
1657
+ if (isIdentStart(ch)) {
1658
+ let j = i;
1659
+ while (j < expr.length) {
1660
+ const c = expr[j];
1661
+ if (c === ".") {
1662
+ j++;
1663
+ continue;
1664
+ }
1665
+ if (!isIdentPart(c)) break;
1666
+ j++;
1667
+ }
1668
+ const ident = expr.slice(i, j);
1669
+ tokens.push({ type: "ident", value: ident });
1670
+ i = j;
1671
+ continue;
1672
+ }
1673
+ throw new Error(`Invalid character in expression: "${ch}" at position ${i}`);
1674
+ }
1675
+ const out = [];
1676
+ for (let k = 0; k < tokens.length; k++) {
1677
+ const t = tokens[k];
1678
+ if (t.type === "op" && t.value === "-") {
1679
+ const prev = out[out.length - 1];
1680
+ const isUnary = !prev || prev.type === "op" || prev.type === "paren" && prev.value === "(";
1681
+ out.push({ type: "op", value: isUnary ? "u-" : "-" });
1682
+ } else {
1683
+ out.push(t);
1684
+ }
1685
+ }
1686
+ return out;
1687
+ }
1688
+ function toRpn(tokens) {
1689
+ const output = [];
1690
+ const stack = [];
1691
+ for (const t of tokens) {
1692
+ if (t.type === "number" || t.type === "ident") {
1693
+ output.push(t);
1694
+ continue;
1695
+ }
1696
+ if (t.type === "op") {
1697
+ while (stack.length) {
1698
+ const top = stack[stack.length - 1];
1699
+ if (top.type !== "op") break;
1700
+ const pTop = OP_PRECEDENCE[top.value];
1701
+ const pCur = OP_PRECEDENCE[t.value];
1702
+ const shouldPop = OP_ASSOC[t.value] === "L" && pCur <= pTop || OP_ASSOC[t.value] === "R" && pCur < pTop;
1703
+ if (!shouldPop) break;
1704
+ output.push(stack.pop());
1705
+ }
1706
+ stack.push(t);
1707
+ continue;
1708
+ }
1709
+ if (t.type === "paren" && t.value === "(") {
1710
+ stack.push(t);
1711
+ continue;
1712
+ }
1713
+ if (t.type === "paren" && t.value === ")") {
1714
+ let foundLeft = false;
1715
+ while (stack.length) {
1716
+ const top = stack.pop();
1717
+ if (top.type === "paren" && top.value === "(") {
1718
+ foundLeft = true;
1719
+ break;
1720
+ }
1721
+ output.push(top);
1722
+ }
1723
+ if (!foundLeft) throw new Error("Mismatched parentheses");
1724
+ continue;
1725
+ }
1726
+ }
1727
+ while (stack.length) {
1728
+ const top = stack.pop();
1729
+ if (top.type === "paren") throw new Error("Mismatched parentheses");
1730
+ output.push(top);
1731
+ }
1732
+ return output;
1733
+ }
1734
+ function evalRpn(rpn, rowObj) {
1735
+ const stack = [];
1736
+ const toNumberOrNull2 = (v) => {
1737
+ if (v === null || v === void 0 || v === "") return null;
1738
+ const n = typeof v === "number" ? v : Number(v);
1739
+ return Number.isFinite(n) ? n : null;
1740
+ };
1741
+ for (const t of rpn) {
1742
+ if (t.type === "number") {
1743
+ stack.push(t.value);
1744
+ continue;
1745
+ }
1746
+ if (t.type === "ident") {
1747
+ const v = getDynamicValue(rowObj, t.value);
1748
+ const n = toNumberOrNull2(v);
1749
+ if (n === null) return null;
1750
+ stack.push(n);
1751
+ continue;
1752
+ }
1753
+ if (t.type === "op") {
1754
+ if (t.value === "u-") {
1755
+ if (stack.length < 1) throw new Error("Bad expression (unary -)");
1756
+ const a2 = stack.pop();
1757
+ stack.push(-a2);
1758
+ continue;
1759
+ }
1760
+ if (stack.length < 2) throw new Error("Bad expression (binary op)");
1761
+ const b = stack.pop();
1762
+ const a = stack.pop();
1763
+ switch (t.value) {
1764
+ case "+":
1765
+ stack.push(a + b);
1766
+ break;
1767
+ case "-":
1768
+ stack.push(a - b);
1769
+ break;
1770
+ case "*":
1771
+ stack.push(a * b);
1772
+ break;
1773
+ case "/":
1774
+ stack.push(b === 0 ? NaN : a / b);
1775
+ break;
1776
+ case "%":
1777
+ stack.push(b === 0 ? NaN : a % b);
1778
+ break;
1779
+ }
1780
+ continue;
1781
+ }
1782
+ }
1783
+ if (stack.length !== 1) throw new Error("Bad expression (final stack)");
1784
+ const res = stack[0];
1785
+ return Number.isFinite(res) ? res : null;
1786
+ }
1787
+ function getDynamicValueOrExpression(obj, accessorOrExpr) {
1788
+ const s = (accessorOrExpr ?? "").trim();
1789
+ if (!s) return null;
1790
+ if (/[+\-*/%()]/.test(s)) {
1791
+ const tokens = tokenize(s);
1792
+ const rpn = toRpn(tokens);
1793
+ return evalRpn(rpn, obj);
1794
+ }
1795
+ return getDynamicValue(obj, s);
1796
+ }
1797
+
1595
1798
  // src/services/common.service.ts
1596
1799
  var import_axios = __toESM(require("axios"));
1597
1800
  var import_exceljs = __toESM(require("exceljs"));
@@ -1643,7 +1846,7 @@ var commonService = (serviceDeps) => {
1643
1846
  ws.addRow(headers).font = { bold: true };
1644
1847
  for (const element of commonData.data) {
1645
1848
  const row = searchParams.config.map((config) => {
1646
- const value = getDynamicValue(element, config.accessorKey);
1849
+ const value = getDynamicValueOrExpression(element, config.accessorKey);
1647
1850
  return value === null || value === void 0 ? "" : value;
1648
1851
  });
1649
1852
  ws.addRow(row);
@@ -1661,7 +1864,7 @@ var commonService = (serviceDeps) => {
1661
1864
  const detail = searchParams.config?.reduce(
1662
1865
  (acc, curr) => ({
1663
1866
  ...acc,
1664
- [curr.label]: getDynamicValue(element, curr.accessorKey)
1867
+ [curr.label]: getDynamicValueOrExpression(element, curr.accessorKey)
1665
1868
  }),
1666
1869
  {}
1667
1870
  );
@@ -1689,7 +1892,7 @@ var commonService = (serviceDeps) => {
1689
1892
  ws.addRow(headers).font = { bold: true };
1690
1893
  for (const element2 of detailsList) {
1691
1894
  const row = searchParams.detailedConfig.map((config) => {
1692
- const value = getDynamicValue(element2, config.accessorKey);
1895
+ const value = getDynamicValueOrExpression(element2, config.accessorKey);
1693
1896
  return value === null || value === void 0 ? "" : value;
1694
1897
  });
1695
1898
  ws.addRow(row);
@@ -3734,9 +3937,11 @@ var NotificationService = class {
3734
3937
  async (recipient) => {
3735
3938
  const res = await args.provider.send({
3736
3939
  recipient,
3737
- bodyValues: args.bodyValues,
3738
- provider: args.provider
3940
+ bodyValues: args.bodyValues
3941
+ // provider: args.provider,
3739
3942
  // these extra fields exist in your old types; provider.send will ignore extras if not used
3943
+ // eventConfigId: 0,
3944
+ // evt
3740
3945
  });
3741
3946
  return {
3742
3947
  recipient,
package/dist/index.mjs CHANGED
@@ -1270,15 +1270,11 @@ function customOmit(obj, keys) {
1270
1270
  return { rest, omitted };
1271
1271
  }
1272
1272
  function getDynamicValue(obj, accessorKey) {
1273
- if (!accessorKey || obj == null || typeof obj !== "object") {
1274
- return null;
1275
- }
1273
+ if (!accessorKey || obj == null || typeof obj !== "object") return null;
1276
1274
  const keys = accessorKey.split(".");
1277
1275
  let result = obj;
1278
1276
  for (const key of keys) {
1279
- if (result == null || typeof result !== "object" || !(key in result)) {
1280
- return null;
1281
- }
1277
+ if (result == null || typeof result !== "object" || !(key in result)) return null;
1282
1278
  result = result[key];
1283
1279
  }
1284
1280
  return result === void 0 ? null : result;
@@ -1542,6 +1538,213 @@ var buildJoiSchemaForOp = (cfg, op, ctx) => {
1542
1538
  });
1543
1539
  };
1544
1540
 
1541
+ // src/utils/dynamicOperation.utils.ts
1542
+ var OP_PRECEDENCE = {
1543
+ "u-": 3,
1544
+ // unary minus
1545
+ "*": 2,
1546
+ "/": 2,
1547
+ "%": 2,
1548
+ "+": 1,
1549
+ "-": 1
1550
+ };
1551
+ var OP_ASSOC = {
1552
+ "u-": "R",
1553
+ "*": "L",
1554
+ "/": "L",
1555
+ "%": "L",
1556
+ "+": "L",
1557
+ "-": "L"
1558
+ };
1559
+ function isDigit(ch) {
1560
+ return ch >= "0" && ch <= "9";
1561
+ }
1562
+ function isIdentStart(ch) {
1563
+ return /[A-Za-z_$]/.test(ch);
1564
+ }
1565
+ function isIdentPart(ch) {
1566
+ return /[A-Za-z0-9_$]/.test(ch);
1567
+ }
1568
+ function tokenize(expr) {
1569
+ const tokens = [];
1570
+ let i = 0;
1571
+ while (i < expr.length) {
1572
+ const ch = expr[i];
1573
+ if (ch === " " || ch === " " || ch === "\n" || ch === "\r") {
1574
+ i++;
1575
+ continue;
1576
+ }
1577
+ if (ch === "(" || ch === ")") {
1578
+ tokens.push({ type: "paren", value: ch });
1579
+ i++;
1580
+ continue;
1581
+ }
1582
+ if (ch === "+" || ch === "-" || ch === "*" || ch === "/" || ch === "%") {
1583
+ tokens.push({ type: "op", value: ch });
1584
+ i++;
1585
+ continue;
1586
+ }
1587
+ if (isDigit(ch) || ch === "." && isDigit(expr[i + 1] ?? "")) {
1588
+ let j = i;
1589
+ let seenDot = false;
1590
+ while (j < expr.length) {
1591
+ const c = expr[j];
1592
+ if (c === ".") {
1593
+ if (seenDot) break;
1594
+ seenDot = true;
1595
+ j++;
1596
+ continue;
1597
+ }
1598
+ if (!isDigit(c)) break;
1599
+ j++;
1600
+ }
1601
+ const raw = expr.slice(i, j);
1602
+ const num = Number(raw);
1603
+ tokens.push({ type: "number", value: num });
1604
+ i = j;
1605
+ continue;
1606
+ }
1607
+ if (isIdentStart(ch)) {
1608
+ let j = i;
1609
+ while (j < expr.length) {
1610
+ const c = expr[j];
1611
+ if (c === ".") {
1612
+ j++;
1613
+ continue;
1614
+ }
1615
+ if (!isIdentPart(c)) break;
1616
+ j++;
1617
+ }
1618
+ const ident = expr.slice(i, j);
1619
+ tokens.push({ type: "ident", value: ident });
1620
+ i = j;
1621
+ continue;
1622
+ }
1623
+ throw new Error(`Invalid character in expression: "${ch}" at position ${i}`);
1624
+ }
1625
+ const out = [];
1626
+ for (let k = 0; k < tokens.length; k++) {
1627
+ const t = tokens[k];
1628
+ if (t.type === "op" && t.value === "-") {
1629
+ const prev = out[out.length - 1];
1630
+ const isUnary = !prev || prev.type === "op" || prev.type === "paren" && prev.value === "(";
1631
+ out.push({ type: "op", value: isUnary ? "u-" : "-" });
1632
+ } else {
1633
+ out.push(t);
1634
+ }
1635
+ }
1636
+ return out;
1637
+ }
1638
+ function toRpn(tokens) {
1639
+ const output = [];
1640
+ const stack = [];
1641
+ for (const t of tokens) {
1642
+ if (t.type === "number" || t.type === "ident") {
1643
+ output.push(t);
1644
+ continue;
1645
+ }
1646
+ if (t.type === "op") {
1647
+ while (stack.length) {
1648
+ const top = stack[stack.length - 1];
1649
+ if (top.type !== "op") break;
1650
+ const pTop = OP_PRECEDENCE[top.value];
1651
+ const pCur = OP_PRECEDENCE[t.value];
1652
+ const shouldPop = OP_ASSOC[t.value] === "L" && pCur <= pTop || OP_ASSOC[t.value] === "R" && pCur < pTop;
1653
+ if (!shouldPop) break;
1654
+ output.push(stack.pop());
1655
+ }
1656
+ stack.push(t);
1657
+ continue;
1658
+ }
1659
+ if (t.type === "paren" && t.value === "(") {
1660
+ stack.push(t);
1661
+ continue;
1662
+ }
1663
+ if (t.type === "paren" && t.value === ")") {
1664
+ let foundLeft = false;
1665
+ while (stack.length) {
1666
+ const top = stack.pop();
1667
+ if (top.type === "paren" && top.value === "(") {
1668
+ foundLeft = true;
1669
+ break;
1670
+ }
1671
+ output.push(top);
1672
+ }
1673
+ if (!foundLeft) throw new Error("Mismatched parentheses");
1674
+ continue;
1675
+ }
1676
+ }
1677
+ while (stack.length) {
1678
+ const top = stack.pop();
1679
+ if (top.type === "paren") throw new Error("Mismatched parentheses");
1680
+ output.push(top);
1681
+ }
1682
+ return output;
1683
+ }
1684
+ function evalRpn(rpn, rowObj) {
1685
+ const stack = [];
1686
+ const toNumberOrNull2 = (v) => {
1687
+ if (v === null || v === void 0 || v === "") return null;
1688
+ const n = typeof v === "number" ? v : Number(v);
1689
+ return Number.isFinite(n) ? n : null;
1690
+ };
1691
+ for (const t of rpn) {
1692
+ if (t.type === "number") {
1693
+ stack.push(t.value);
1694
+ continue;
1695
+ }
1696
+ if (t.type === "ident") {
1697
+ const v = getDynamicValue(rowObj, t.value);
1698
+ const n = toNumberOrNull2(v);
1699
+ if (n === null) return null;
1700
+ stack.push(n);
1701
+ continue;
1702
+ }
1703
+ if (t.type === "op") {
1704
+ if (t.value === "u-") {
1705
+ if (stack.length < 1) throw new Error("Bad expression (unary -)");
1706
+ const a2 = stack.pop();
1707
+ stack.push(-a2);
1708
+ continue;
1709
+ }
1710
+ if (stack.length < 2) throw new Error("Bad expression (binary op)");
1711
+ const b = stack.pop();
1712
+ const a = stack.pop();
1713
+ switch (t.value) {
1714
+ case "+":
1715
+ stack.push(a + b);
1716
+ break;
1717
+ case "-":
1718
+ stack.push(a - b);
1719
+ break;
1720
+ case "*":
1721
+ stack.push(a * b);
1722
+ break;
1723
+ case "/":
1724
+ stack.push(b === 0 ? NaN : a / b);
1725
+ break;
1726
+ case "%":
1727
+ stack.push(b === 0 ? NaN : a % b);
1728
+ break;
1729
+ }
1730
+ continue;
1731
+ }
1732
+ }
1733
+ if (stack.length !== 1) throw new Error("Bad expression (final stack)");
1734
+ const res = stack[0];
1735
+ return Number.isFinite(res) ? res : null;
1736
+ }
1737
+ function getDynamicValueOrExpression(obj, accessorOrExpr) {
1738
+ const s = (accessorOrExpr ?? "").trim();
1739
+ if (!s) return null;
1740
+ if (/[+\-*/%()]/.test(s)) {
1741
+ const tokens = tokenize(s);
1742
+ const rpn = toRpn(tokens);
1743
+ return evalRpn(rpn, obj);
1744
+ }
1745
+ return getDynamicValue(obj, s);
1746
+ }
1747
+
1545
1748
  // src/services/common.service.ts
1546
1749
  import axios from "axios";
1547
1750
  import ExcelJs from "exceljs";
@@ -1593,7 +1796,7 @@ var commonService = (serviceDeps) => {
1593
1796
  ws.addRow(headers).font = { bold: true };
1594
1797
  for (const element of commonData.data) {
1595
1798
  const row = searchParams.config.map((config) => {
1596
- const value = getDynamicValue(element, config.accessorKey);
1799
+ const value = getDynamicValueOrExpression(element, config.accessorKey);
1597
1800
  return value === null || value === void 0 ? "" : value;
1598
1801
  });
1599
1802
  ws.addRow(row);
@@ -1611,7 +1814,7 @@ var commonService = (serviceDeps) => {
1611
1814
  const detail = searchParams.config?.reduce(
1612
1815
  (acc, curr) => ({
1613
1816
  ...acc,
1614
- [curr.label]: getDynamicValue(element, curr.accessorKey)
1817
+ [curr.label]: getDynamicValueOrExpression(element, curr.accessorKey)
1615
1818
  }),
1616
1819
  {}
1617
1820
  );
@@ -1639,7 +1842,7 @@ var commonService = (serviceDeps) => {
1639
1842
  ws.addRow(headers).font = { bold: true };
1640
1843
  for (const element2 of detailsList) {
1641
1844
  const row = searchParams.detailedConfig.map((config) => {
1642
- const value = getDynamicValue(element2, config.accessorKey);
1845
+ const value = getDynamicValueOrExpression(element2, config.accessorKey);
1643
1846
  return value === null || value === void 0 ? "" : value;
1644
1847
  });
1645
1848
  ws.addRow(row);
@@ -3684,9 +3887,11 @@ var NotificationService = class {
3684
3887
  async (recipient) => {
3685
3888
  const res = await args.provider.send({
3686
3889
  recipient,
3687
- bodyValues: args.bodyValues,
3688
- provider: args.provider
3890
+ bodyValues: args.bodyValues
3891
+ // provider: args.provider,
3689
3892
  // these extra fields exist in your old types; provider.send will ignore extras if not used
3893
+ // eventConfigId: 0,
3894
+ // evt
3690
3895
  });
3691
3896
  return {
3692
3897
  recipient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",