refactor: replace array-based expressions with typed class hierarchy

Replace the old Lisp-like array expression representation
(["AND", ["PARAM", ...], ...]) with a class hierarchy rooted in
an abstract Expression class (Literal, Parameter, Binary, Unary,
FunctionCall, Conditional). This gives compile-time type safety
to expression construction, evaluation, and pattern matching.

Key changes:
- New lib/common/expression.ts defines the class hierarchy with
  map/evaluate/toString methods
- Rewrite parser as hand-rolled recursive descent, removing the
  parsimmon dependency
- Extend Path with a colon separator to unify parameter identity
  and attributes into a single address space (e.g.
  "Device.WiFi.SSID.1.Name:writable"). The colon field tracks
  how many trailing segments are attribute qualifiers. PathSet
  rewritten with separate param/attr segment indexes
- Flatten device attribute representation in the UI to
  colon-delimited keys mirroring the new path syntax
This commit is contained in:
Zaid Humaimidi committed 2026-03-12 14:58:20 -07:00
1 parent 75908e624f
commit 6f3ce6f7c8
71 files changed
+4045 -3449

No files matched your search

+25 -28
View File
@@ -1,31 +1,29 @@
import { ClosureComponent, Component } from "mithril";
import { ClosureComponent } from "mithril";
import { m } from "./components.ts";
import config from "./config.ts";
import { overview } from "./config.ts";
import * as store from "./store.ts";
import pieChartComponent from "./pie-chart-component.ts";
const GROUPS = config.ui.overview.groups || {};
const CHARTS = {};
for (const group of Object.values(GROUPS)) {
for (const chartName of Object.values(group["charts"]) as string[])
CHARTS[chartName] = config.ui.overview.charts[chartName];
const GROUPS = overview.groups;
const CHARTS: typeof overview.charts = {};
for (const group of GROUPS) {
for (const chartName of group.charts)
CHARTS[chartName] = overview.charts[chartName];
}
function queryCharts(charts: Record<string, unknown>): Record<string, unknown> {
function queryCharts(charts: typeof overview.charts): typeof charts {
charts = Object.assign({}, charts);
for (let [chartName, chart] of Object.entries(charts)) {
charts[chartName] = chart = Object.assign({}, chart);
chart["slices"] = Object.assign({}, chart["slices"]);
for (let [sliceName, slice] of Object.entries(chart["slices"])) {
const filter = slice["filter"];
chart["slices"][sliceName] = slice = Object.assign({}, slice);
slice["count"] = store.count("devices", filter);
charts[chartName] = chart = { ...chart };
chart.slices = chart.slices.map((s) => ({ ...s }));
for (const slice of chart.slices) {
slice["count"] = store.count("devices", slice.filter);
}
}
return charts;
}
export function init(): Promise<Record<string, unknown>> {
export function init(): Promise<{ charts: typeof overview.charts }> {
if (!window.authorizer.hasAccess("devices", 1)) {
return Promise.reject(
new Error("You are not authorized to view this page"),
@@ -35,37 +33,36 @@ export function init(): Promise<Record<string, unknown>> {
return Promise.resolve({ charts: queryCharts(CHARTS) });
}
export const component: ClosureComponent = (): Component => {
interface Attrs {
charts: typeof overview.charts;
}
export const component: ClosureComponent<Attrs> = () => {
return {
view: (vnode) => {
document.title = "Overview - GenieACS";
const children = [];
for (const group of Object.values(GROUPS)) {
if (group["label"]) {
for (const group of GROUPS) {
if (group.label) {
children.push(
m(
"h1.text-xl font-medium text-stone-900 mb-5",
store.evaluateExpression(group["label"], null),
),
m("h1.text-xl font-medium text-stone-900 mb-5", group["label"]),
);
}
const groupChildren = [];
for (const chartName of Object.values(group["charts"]) as string[]) {
const chart = vnode.attrs["charts"][chartName];
for (const chartName of group.charts) {
const chart = vnode.attrs.charts[chartName];
const chartChildren = [];
if (chart.label) {
chartChildren.push(
m(
"h2.text-lg font-semibold text-stone-700 truncate mb-5 text-center",
store.evaluateExpression(chart.label, null),
chart.label,
),
);
}
const attrs = {};
attrs["chart"] = chart;
chartChildren.push(m(pieChartComponent, attrs));
chartChildren.push(m(pieChartComponent, { chart }));
groupChildren.push(
m(