@johnoscott/isometric-engine 0.0.0-stage → 0.9.0
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/EDITOR-GUIDE.md +317 -0
- package/LICENSE +21 -0
- package/LICENSES/ajv.txt +22 -0
- package/LICENSES/lucide-static.txt +43 -0
- package/LICENSES/yaml.txt +13 -0
- package/README.md +62 -2
- package/assets/app.css +265 -0
- package/assets/default-theme.yaml +99 -0
- package/assets/icons.svg +1 -0
- package/assets/marks.css +35 -0
- package/assets/skin.css +181 -0
- package/iso-editor.d.ts +4 -0
- package/iso-editor.js +550 -0
- package/iso-render.d.ts +3 -0
- package/iso-render.js +388 -0
- package/iso-systems.d.ts +4 -0
- package/iso-systems.js +389 -0
- package/js/iso-core/compile-schema.js +22 -0
- package/js/iso-core/depth.js +55 -0
- package/js/iso-core/errors.js +65 -0
- package/js/iso-core/glyphs.js +100 -0
- package/js/iso-core/index.js +55 -0
- package/js/iso-core/kernel.js +158 -0
- package/js/iso-core/metrics.json +1 -0
- package/js/iso-core/package.json +6 -0
- package/js/iso-core/parse.js +79 -0
- package/js/iso-core/schema-errors.js +170 -0
- package/js/iso-core/shims/crypto.js +125 -0
- package/js/iso-core/shims/path.js +49 -0
- package/js/iso-core/svg-dom.js +144 -0
- package/js/iso-core/theme.js +48 -0
- package/js/iso-core/vdom.js +48 -0
- package/js/iso-editor/adapter.js +0 -0
- package/js/iso-editor/clipboard.js +152 -0
- package/js/iso-editor/commands.js +173 -0
- package/js/iso-editor/complete.js +55 -0
- package/js/iso-editor/doc.js +182 -0
- package/js/iso-editor/index.js +105 -0
- package/js/iso-editor/model.js +210 -0
- package/js/iso-editor/outline.js +111 -0
- package/js/iso-editor/package.json +6 -0
- package/js/iso-editor/path.js +19 -0
- package/js/iso-editor/providers.js +96 -0
- package/js/iso-editor/schema-nav.js +117 -0
- package/js/iso-editor/splice.js +441 -0
- package/js/iso-editor/storage-keys.js +6 -0
- package/js/iso-editor/ui/actions.js +116 -0
- package/js/iso-editor/ui/canvas-layer.js +0 -0
- package/js/iso-editor/ui/canvas.js +1205 -0
- package/js/iso-editor/ui/clip.js +133 -0
- package/js/iso-editor/ui/dialog.js +26 -0
- package/js/iso-editor/ui/flat-canvas.js +54 -0
- package/js/iso-editor/ui/icons.js +15 -0
- package/js/iso-editor/ui/keys.js +26 -0
- package/js/iso-editor/ui/later.js +28 -0
- package/js/iso-editor/ui/layer.js +11 -0
- package/js/iso-editor/ui/menu.js +105 -0
- package/js/iso-editor/ui/monaco-entry.js +2 -0
- package/js/iso-editor/ui/mount-kit.js +0 -0
- package/js/iso-editor/ui/mount.js +767 -0
- package/js/iso-editor/ui/pane.js +0 -0
- package/js/iso-editor/ui/part.js +0 -0
- package/js/iso-editor/ui/plain-icons.js +34 -0
- package/js/iso-editor/ui/props.js +314 -0
- package/js/iso-editor/ui/scope-css.js +81 -0
- package/js/iso-editor/ui/setup.js +145 -0
- package/js/iso-editor/ui/text.js +323 -0
- package/js/iso-editor/ui/tree.js +728 -0
- package/js/iso-editor/validate.js +33 -0
- package/js/iso-editor/window/protocol.js +8 -0
- package/js/iso-objects/assemble.js +43 -0
- package/js/iso-objects/assets.js +88 -0
- package/js/iso-objects/board.js +162 -0
- package/js/iso-objects/compile.js +60 -0
- package/js/iso-objects/css.js +154 -0
- package/js/iso-objects/flat.js +696 -0
- package/js/iso-objects/focus.js +16 -0
- package/js/iso-objects/geometry.js +76 -0
- package/js/iso-objects/index.js +93 -0
- package/js/iso-objects/kinds.js +12 -0
- package/js/iso-objects/labels.js +325 -0
- package/js/iso-objects/package.json +6 -0
- package/js/iso-objects/place.js +347 -0
- package/js/iso-objects/route.js +461 -0
- package/js/iso-objects/scene.js +350 -0
- package/js/iso-objects/steps.js +246 -0
- package/js/iso-objects/types.js +0 -0
- package/js/iso-systems/catalog.js +42 -0
- package/js/iso-systems/compile.js +34 -0
- package/js/iso-systems/css.js +8 -0
- package/js/iso-systems/index.js +16 -0
- package/js/iso-systems/nodes.js +124 -0
- package/js/iso-systems/package.json +6 -0
- package/js/iso-systems/schema.json +311 -0
- package/js/iso-systems/validate.js +35 -0
- package/js/iso-viewer/bundle.js +20 -0
- package/js/iso-viewer/card-motion.js +228 -0
- package/js/iso-viewer/dom.js +14 -0
- package/js/iso-viewer/dual-view.js +212 -0
- package/js/iso-viewer/flat-view.js +124 -0
- package/js/iso-viewer/history.js +990 -0
- package/js/iso-viewer/index.js +98 -0
- package/js/iso-viewer/morph.js +192 -0
- package/js/iso-viewer/overlay.js +199 -0
- package/js/iso-viewer/package.json +6 -0
- package/js/iso-viewer/page.js +138 -0
- package/js/iso-viewer/player.js +409 -0
- package/js/iso-viewer/still.js +81 -0
- package/js/iso-viewer/timeline-contract.js +14 -0
- package/js/iso-viewer/timeline-engine.js +475 -0
- package/js/iso-viewer/timeline-export.js +36 -0
- package/js/iso-viewer/timeline-scale.js +116 -0
- package/js/iso-viewer/timeline-scope.js +58 -0
- package/js/iso-viewer/timeline-search.js +216 -0
- package/js/iso-viewer/timeline-time.js +55 -0
- package/js/iso-viewer/view-css.js +68 -0
- package/js/iso-viewer/viewport.js +177 -0
- package/package.json +502 -4
- package/src/iso-core/compile-schema.ts +23 -0
- package/src/iso-core/depth.ts +56 -0
- package/src/iso-core/errors.ts +73 -0
- package/src/iso-core/glyphs.ts +108 -0
- package/src/iso-core/index.ts +27 -0
- package/src/iso-core/kernel.ts +163 -0
- package/src/iso-core/metrics.json +1 -0
- package/src/iso-core/package.json +6 -0
- package/src/iso-core/parse.ts +91 -0
- package/src/iso-core/schema-errors.ts +163 -0
- package/src/iso-core/shims/crypto.ts +37 -0
- package/src/iso-core/shims/path.ts +24 -0
- package/src/iso-core/svg-dom.ts +103 -0
- package/src/iso-core/theme.ts +64 -0
- package/src/iso-core/vdom.ts +41 -0
- package/src/iso-editor/adapter.ts +128 -0
- package/src/iso-editor/clipboard.ts +163 -0
- package/src/iso-editor/commands.ts +191 -0
- package/src/iso-editor/complete.ts +73 -0
- package/src/iso-editor/doc.ts +207 -0
- package/src/iso-editor/index.ts +67 -0
- package/src/iso-editor/model.ts +234 -0
- package/src/iso-editor/outline.ts +126 -0
- package/src/iso-editor/package.json +6 -0
- package/src/iso-editor/path.ts +18 -0
- package/src/iso-editor/providers.ts +113 -0
- package/src/iso-editor/schema-nav.ts +129 -0
- package/src/iso-editor/splice.ts +472 -0
- package/src/iso-editor/storage-keys.ts +6 -0
- package/src/iso-editor/ui/actions.ts +119 -0
- package/src/iso-editor/ui/app.css +230 -0
- package/src/iso-editor/ui/canvas-layer.ts +56 -0
- package/src/iso-editor/ui/canvas.ts +1071 -0
- package/src/iso-editor/ui/clip.ts +97 -0
- package/src/iso-editor/ui/dialog.ts +25 -0
- package/src/iso-editor/ui/flat-canvas.ts +51 -0
- package/src/iso-editor/ui/icons.ts +21 -0
- package/src/iso-editor/ui/keys.ts +30 -0
- package/src/iso-editor/ui/later.ts +22 -0
- package/src/iso-editor/ui/layer.ts +7 -0
- package/src/iso-editor/ui/marks.css +35 -0
- package/src/iso-editor/ui/menu.ts +67 -0
- package/src/iso-editor/ui/monaco-entry.ts +6 -0
- package/src/iso-editor/ui/mount-kit.ts +35 -0
- package/src/iso-editor/ui/mount.ts +684 -0
- package/src/iso-editor/ui/pane.ts +45 -0
- package/src/iso-editor/ui/part.ts +45 -0
- package/src/iso-editor/ui/plain-icons.ts +83 -0
- package/src/iso-editor/ui/props.ts +347 -0
- package/src/iso-editor/ui/scope-css.ts +65 -0
- package/src/iso-editor/ui/setup.ts +144 -0
- package/src/iso-editor/ui/skin.css +181 -0
- package/src/iso-editor/ui/text.ts +262 -0
- package/src/iso-editor/ui/tree.ts +657 -0
- package/src/iso-editor/validate.ts +62 -0
- package/src/iso-editor/window/protocol.ts +33 -0
- package/src/iso-objects/assemble.ts +57 -0
- package/src/iso-objects/assets.ts +122 -0
- package/src/iso-objects/board.ts +169 -0
- package/src/iso-objects/compile.ts +76 -0
- package/src/iso-objects/css.ts +163 -0
- package/src/iso-objects/flat.ts +653 -0
- package/src/iso-objects/focus.ts +14 -0
- package/src/iso-objects/geometry.ts +86 -0
- package/src/iso-objects/index.ts +33 -0
- package/src/iso-objects/kinds.ts +56 -0
- package/src/iso-objects/labels.ts +310 -0
- package/src/iso-objects/package.json +6 -0
- package/src/iso-objects/place.ts +318 -0
- package/src/iso-objects/route.ts +444 -0
- package/src/iso-objects/scene.ts +376 -0
- package/src/iso-objects/steps.ts +234 -0
- package/src/iso-objects/types.ts +68 -0
- package/src/iso-systems/catalog.ts +31 -0
- package/src/iso-systems/compile.ts +39 -0
- package/src/iso-systems/css.ts +9 -0
- package/src/iso-systems/index.ts +12 -0
- package/src/iso-systems/nodes.ts +126 -0
- package/src/iso-systems/package.json +6 -0
- package/src/iso-systems/schema.json +311 -0
- package/src/iso-systems/validate.ts +34 -0
- package/src/iso-viewer/bundle.ts +15 -0
- package/src/iso-viewer/card-motion.ts +237 -0
- package/src/iso-viewer/dom.ts +13 -0
- package/src/iso-viewer/dual-view.ts +212 -0
- package/src/iso-viewer/flat-view.ts +127 -0
- package/src/iso-viewer/history.ts +781 -0
- package/src/iso-viewer/index.ts +40 -0
- package/src/iso-viewer/morph.ts +191 -0
- package/src/iso-viewer/overlay.ts +212 -0
- package/src/iso-viewer/package.json +6 -0
- package/src/iso-viewer/page.ts +150 -0
- package/src/iso-viewer/player.ts +321 -0
- package/src/iso-viewer/still.ts +74 -0
- package/src/iso-viewer/timeline-contract.ts +342 -0
- package/src/iso-viewer/timeline-engine.ts +420 -0
- package/src/iso-viewer/timeline-export.ts +31 -0
- package/src/iso-viewer/timeline-scale.ts +129 -0
- package/src/iso-viewer/timeline-scope.ts +56 -0
- package/src/iso-viewer/timeline-search.ts +198 -0
- package/src/iso-viewer/timeline-time.ts +54 -0
- package/src/iso-viewer/view-css.ts +59 -0
- package/src/iso-viewer/viewport.ts +142 -0
- package/types/iso-core/compile-schema.d.ts +11 -0
- package/types/iso-core/depth.d.ts +6 -0
- package/types/iso-core/errors.d.ts +24 -0
- package/types/iso-core/glyphs.d.ts +19 -0
- package/types/iso-core/index.d.ts +17 -0
- package/types/iso-core/kernel.d.ts +130 -0
- package/types/iso-core/metrics.json +1 -0
- package/types/iso-core/parse.d.ts +18 -0
- package/types/iso-core/schema-errors.d.ts +14 -0
- package/types/iso-core/shims/crypto.d.ts +9 -0
- package/types/iso-core/svg-dom.d.ts +15 -0
- package/types/iso-core/theme.d.ts +38 -0
- package/types/iso-core/vdom.d.ts +26 -0
- package/types/iso-editor/adapter.d.ts +145 -0
- package/types/iso-editor/clipboard.d.ts +23 -0
- package/types/iso-editor/commands.d.ts +32 -0
- package/types/iso-editor/complete.d.ts +25 -0
- package/types/iso-editor/doc.d.ts +50 -0
- package/types/iso-editor/index.d.ts +57 -0
- package/types/iso-editor/model.d.ts +96 -0
- package/types/iso-editor/outline.d.ts +28 -0
- package/types/iso-editor/path.d.ts +7 -0
- package/types/iso-editor/providers.d.ts +43 -0
- package/types/iso-editor/schema-nav.d.ts +34 -0
- package/types/iso-editor/splice.d.ts +53 -0
- package/types/iso-editor/storage-keys.d.ts +5 -0
- package/types/iso-editor/ui/actions.d.ts +23 -0
- package/types/iso-editor/ui/canvas-layer.d.ts +65 -0
- package/types/iso-editor/ui/canvas.d.ts +279 -0
- package/types/iso-editor/ui/clip.d.ts +14 -0
- package/types/iso-editor/ui/dialog.d.ts +7 -0
- package/types/iso-editor/ui/flat-canvas.d.ts +2 -0
- package/types/iso-editor/ui/icons.d.ts +5 -0
- package/types/iso-editor/ui/keys.d.ts +7 -0
- package/types/iso-editor/ui/later.d.ts +12 -0
- package/types/iso-editor/ui/layer.d.ts +2 -0
- package/types/iso-editor/ui/menu.d.ts +21 -0
- package/types/iso-editor/ui/mount-kit.d.ts +31 -0
- package/types/iso-editor/ui/mount.d.ts +146 -0
- package/types/iso-editor/ui/pane.d.ts +60 -0
- package/types/iso-editor/ui/part.d.ts +40 -0
- package/types/iso-editor/ui/plain-icons.d.ts +10 -0
- package/types/iso-editor/ui/props.d.ts +57 -0
- package/types/iso-editor/ui/scope-css.d.ts +5 -0
- package/types/iso-editor/ui/setup.d.ts +40 -0
- package/types/iso-editor/ui/text.d.ts +19 -0
- package/types/iso-editor/ui/tree.d.ts +100 -0
- package/types/iso-editor/validate.d.ts +36 -0
- package/types/iso-editor/window/protocol.d.ts +60 -0
- package/types/iso-objects/assemble.d.ts +35 -0
- package/types/iso-objects/assets.d.ts +49 -0
- package/types/iso-objects/board.d.ts +36 -0
- package/types/iso-objects/compile.d.ts +35 -0
- package/types/iso-objects/css.d.ts +16 -0
- package/types/iso-objects/flat.d.ts +130 -0
- package/types/iso-objects/focus.d.ts +1 -0
- package/types/iso-objects/geometry.d.ts +59 -0
- package/types/iso-objects/index.d.ts +26 -0
- package/types/iso-objects/kinds.d.ts +53 -0
- package/types/iso-objects/labels.d.ts +92 -0
- package/types/iso-objects/place.d.ts +25 -0
- package/types/iso-objects/route.d.ts +67 -0
- package/types/iso-objects/scene.d.ts +63 -0
- package/types/iso-objects/steps.d.ts +90 -0
- package/types/iso-objects/types.d.ts +140 -0
- package/types/iso-systems/catalog.d.ts +4 -0
- package/types/iso-systems/compile.d.ts +6 -0
- package/types/iso-systems/css.d.ts +3 -0
- package/types/iso-systems/index.d.ts +5 -0
- package/types/iso-systems/nodes.d.ts +3 -0
- package/types/iso-viewer/card-motion.d.ts +56 -0
- package/types/iso-viewer/dom.d.ts +1 -0
- package/types/iso-viewer/dual-view.d.ts +44 -0
- package/types/iso-viewer/flat-view.d.ts +25 -0
- package/types/iso-viewer/history.d.ts +91 -0
- package/types/iso-viewer/index.d.ts +31 -0
- package/types/iso-viewer/morph.d.ts +28 -0
- package/types/iso-viewer/overlay.d.ts +135 -0
- package/types/iso-viewer/page.d.ts +13 -0
- package/types/iso-viewer/still.d.ts +26 -0
- package/types/iso-viewer/timeline-contract.d.ts +345 -0
- package/types/iso-viewer/timeline-engine.d.ts +20 -0
- package/types/iso-viewer/timeline-export.d.ts +5 -0
- package/types/iso-viewer/timeline-scale.d.ts +44 -0
- package/types/iso-viewer/timeline-scope.d.ts +33 -0
- package/types/iso-viewer/timeline-search.d.ts +52 -0
- package/types/iso-viewer/timeline-time.d.ts +8 -0
- package/types/iso-viewer/view-css.d.ts +7 -0
- package/types/iso-viewer/viewport.d.ts +50 -0
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BIN_MS,
|
|
3
|
+
SEVERITIES
|
|
4
|
+
} from "./timeline-contract.js";
|
|
5
|
+
import { levelOf, prefixAt, within, kindOf, nameOf, scopeRules } from "./timeline-scope.js";
|
|
6
|
+
import { searchFor, rangeOf } from "./timeline-search.js";
|
|
7
|
+
import { binStart, offsetAt } from "./timeline-time.js";
|
|
8
|
+
const DAY = 864e5, HOUR = 36e5;
|
|
9
|
+
const byTimeId = (a, b) => a.t - b.t || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
10
|
+
function lower(es, t) {
|
|
11
|
+
let lo = 0, hi = es.length;
|
|
12
|
+
while (lo < hi) {
|
|
13
|
+
const m = lo + hi >> 1;
|
|
14
|
+
if (es[m].t < t) lo = m + 1;
|
|
15
|
+
else hi = m;
|
|
16
|
+
}
|
|
17
|
+
return lo;
|
|
18
|
+
}
|
|
19
|
+
const combine = (into, f) => {
|
|
20
|
+
into.min = Math.min(into.min, f.min);
|
|
21
|
+
into.max = Math.max(into.max, f.max);
|
|
22
|
+
into.sum += f.sum;
|
|
23
|
+
into.count += f.count;
|
|
24
|
+
};
|
|
25
|
+
function rollUp(fine, bin, tz) {
|
|
26
|
+
const out = [];
|
|
27
|
+
for (const f of fine) {
|
|
28
|
+
const t = binStart(f.t, bin, tz), last = out[out.length - 1];
|
|
29
|
+
if (last && last.t === t) combine(last, f);
|
|
30
|
+
else out.push({ t, min: f.min, max: f.max, sum: f.sum, count: f.count });
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
function place(xs, x, same, order) {
|
|
35
|
+
for (let i2 = lower(xs, x.t); i2 < xs.length && xs[i2].t === x.t; i2++) if (same(xs[i2])) {
|
|
36
|
+
xs[i2] = x;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const last = xs[xs.length - 1];
|
|
40
|
+
if (!last || order(last, x) <= 0) {
|
|
41
|
+
xs.push(x);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let i = lower(xs, x.t);
|
|
45
|
+
while (i < xs.length && order(xs[i], x) < 0) i++;
|
|
46
|
+
xs.splice(i, 0, x);
|
|
47
|
+
}
|
|
48
|
+
function remove(xs, t, same) {
|
|
49
|
+
for (let i = lower(xs, t); i < xs.length && xs[i].t === t; i++) if (same(xs[i])) {
|
|
50
|
+
xs.splice(i, 1);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function memorySource(rec, cat, o = {}) {
|
|
55
|
+
const catalog = rec.catalog;
|
|
56
|
+
const { isScope } = scopeRules(cat), { parseSearch, matchAst, toAst } = searchFor(cat);
|
|
57
|
+
const flagsOf = (n) => Object.fromEntries(cat.flags.filter((f) => n?.[f]).map((f) => [f, true]));
|
|
58
|
+
let now = o.now ?? catalog.now;
|
|
59
|
+
const aliases = (catalog.names ?? []).flatMap((n) => (n.aliases ?? []).map((a) => [a, n.scope])).sort((a, b) => b[0].length - a[0].length);
|
|
60
|
+
const canonical = /* @__PURE__ */ new Map();
|
|
61
|
+
const canon = (s) => {
|
|
62
|
+
if (!aliases.length) return s;
|
|
63
|
+
let c = canonical.get(s);
|
|
64
|
+
if (c === void 0) {
|
|
65
|
+
const a = aliases.find(([from]) => within(s, from));
|
|
66
|
+
c = a ? a[1] + s.slice(a[0].length) : s;
|
|
67
|
+
canonical.set(s, c);
|
|
68
|
+
}
|
|
69
|
+
return c;
|
|
70
|
+
};
|
|
71
|
+
const names = new Map((catalog.names ?? []).map((n) => [n.scope, n]));
|
|
72
|
+
const fix = (e) => aliases.length ? { ...e, scope: canon(e.scope) } : e;
|
|
73
|
+
const keyOf = (e) => `${e.source}\0${e.id}`;
|
|
74
|
+
const events = rec.events.map(fix).sort(byTimeId);
|
|
75
|
+
const byId = /* @__PURE__ */ new Map();
|
|
76
|
+
for (const e of events) byId.set(keyOf(e), e);
|
|
77
|
+
const spans = events.filter((e) => e.dur !== void 0 && !e.open);
|
|
78
|
+
let maxDur = spans.reduce((m, e) => Math.max(m, e.dur), 0);
|
|
79
|
+
const open = /* @__PURE__ */ new Map();
|
|
80
|
+
for (const e of events) if (e.open) open.set(keyOf(e), e);
|
|
81
|
+
const stores = /* @__PURE__ */ new Map();
|
|
82
|
+
const scopes = /* @__PURE__ */ new Set();
|
|
83
|
+
const noteScope = (s) => {
|
|
84
|
+
for (let l = levelOf(s); l >= 1; l--) {
|
|
85
|
+
const p = prefixAt(s, l);
|
|
86
|
+
if (scopes.has(p)) break;
|
|
87
|
+
scopes.add(p);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const seriesType = /* @__PURE__ */ new Map();
|
|
91
|
+
for (const s of catalog.sources) for (const x of s.series) seriesType.set(x.name, x.type);
|
|
92
|
+
const sensitive = catalog.sources.flatMap((s) => (s.sensitive ?? []).map((a) => `${s.name}.${a}`));
|
|
93
|
+
const retention = /* @__PURE__ */ new Map();
|
|
94
|
+
for (const s of catalog.sources) retention.set(s.name, { events: s.defaultRetention.events, rollups: { ...s.defaultRetention.rollups }, setBy: "default" });
|
|
95
|
+
for (const r of catalog.retention) retention.set(r.source, { events: r.events, rollups: { ...r.rollups }, setBy: r.setBy });
|
|
96
|
+
const seriesSource = /* @__PURE__ */ new Map();
|
|
97
|
+
for (const s of catalog.sources) for (const x of s.series) seriesSource.set(x.name, s.name);
|
|
98
|
+
function addMetric(m) {
|
|
99
|
+
const scope = canon(m.scope), key = `${m.series}\0${scope}`;
|
|
100
|
+
let st = stores.get(key);
|
|
101
|
+
if (!st) {
|
|
102
|
+
st = { series: m.series, scope, fine: [], cache: /* @__PURE__ */ new Map() };
|
|
103
|
+
stores.set(key, st);
|
|
104
|
+
noteScope(scope);
|
|
105
|
+
}
|
|
106
|
+
const f = "value" in m ? { t: m.t, min: m.value, max: m.value, sum: m.value, count: 1 } : { t: m.t, min: m.min, max: m.max, sum: m.sum, count: m.count };
|
|
107
|
+
place(st.fine, f, (a) => a.t === f.t, (a, b) => a.t - b.t);
|
|
108
|
+
st.cache.clear();
|
|
109
|
+
}
|
|
110
|
+
for (const e of events) noteScope(e.scope);
|
|
111
|
+
for (const m of rec.metrics) addMetric(m);
|
|
112
|
+
const hours = /* @__PURE__ */ new Map();
|
|
113
|
+
const present = /* @__PURE__ */ new Set();
|
|
114
|
+
const tally = (e, by) => {
|
|
115
|
+
present.add(e.source);
|
|
116
|
+
let bySrc = hours.get(e.scope);
|
|
117
|
+
if (!bySrc) hours.set(e.scope, bySrc = /* @__PURE__ */ new Map());
|
|
118
|
+
let byT = bySrc.get(e.source);
|
|
119
|
+
if (!byT) bySrc.set(e.source, byT = /* @__PURE__ */ new Map());
|
|
120
|
+
const t = Math.floor(e.t / HOUR) * HOUR;
|
|
121
|
+
let b = byT.get(t);
|
|
122
|
+
if (!b) byT.set(t, b = { t, count: 0, severity: {}, kinds: {}, first: Infinity, last: -Infinity });
|
|
123
|
+
b.count += by;
|
|
124
|
+
if (by > 0) {
|
|
125
|
+
b.first = Math.min(b.first, e.t);
|
|
126
|
+
b.last = Math.max(b.last, e.t);
|
|
127
|
+
} else if (e.t === b.first || e.t === b.last) {
|
|
128
|
+
b.first = Infinity;
|
|
129
|
+
b.last = -Infinity;
|
|
130
|
+
for (let i = lower(events, t); i < events.length && events[i].t < t + HOUR; i++) {
|
|
131
|
+
const x = events[i];
|
|
132
|
+
if (x.scope === e.scope && x.source === e.source) {
|
|
133
|
+
b.first = Math.min(b.first, x.t);
|
|
134
|
+
b.last = Math.max(b.last, x.t);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
b.severity[e.severity] = (b.severity[e.severity] ?? 0) + by;
|
|
139
|
+
b.kinds[e.kind] = (b.kinds[e.kind] ?? 0) + by;
|
|
140
|
+
if (b.severity[e.severity] === 0) delete b.severity[e.severity];
|
|
141
|
+
if (b.kinds[e.kind] === 0) delete b.kinds[e.kind];
|
|
142
|
+
if (!b.count) byT.delete(t);
|
|
143
|
+
};
|
|
144
|
+
for (const e of events) tally(e, 1);
|
|
145
|
+
const binned = (st, bin, tz) => {
|
|
146
|
+
const key = `${bin}|${tz ?? ""}`;
|
|
147
|
+
let c = st.cache.get(key);
|
|
148
|
+
if (!c) {
|
|
149
|
+
c = bin === "1d" ? rollUp(binned(st, "1h", tz), "1d", tz) : rollUp(st.fine, bin, tz);
|
|
150
|
+
st.cache.set(key, c);
|
|
151
|
+
}
|
|
152
|
+
return c;
|
|
153
|
+
};
|
|
154
|
+
const cutoff = (d) => d === null ? -Infinity : now - d * DAY;
|
|
155
|
+
const eventCut = (source) => cutoff(retention.get(source)?.events ?? null);
|
|
156
|
+
const binCut = (source, bin) => {
|
|
157
|
+
const r = retention.get(source);
|
|
158
|
+
return cutoff(r ? bin ? r.rollups[bin] : r.events : null);
|
|
159
|
+
};
|
|
160
|
+
function effective(srcNames) {
|
|
161
|
+
const out = [];
|
|
162
|
+
for (const name of new Set(srcNames)) {
|
|
163
|
+
const r = retention.get(name);
|
|
164
|
+
if (!r) continue;
|
|
165
|
+
const first = events.find((e) => e.source === name && e.t >= eventCut(name))?.t;
|
|
166
|
+
const firstSample = (bin) => {
|
|
167
|
+
let m = Infinity;
|
|
168
|
+
for (const st of stores.values()) if (seriesSource.get(st.series) === name) {
|
|
169
|
+
const f = (bin ? binned(st, bin) : st.fine).find((x) => x.t >= binCut(name, bin));
|
|
170
|
+
if (f && f.t < m) m = f.t;
|
|
171
|
+
}
|
|
172
|
+
return m === Infinity ? void 0 : m;
|
|
173
|
+
};
|
|
174
|
+
const ev = [first, firstSample()].filter((x) => x !== void 0);
|
|
175
|
+
const rollups = {};
|
|
176
|
+
for (const b of ["1m", "1h", "1d"]) {
|
|
177
|
+
const f = firstSample(b) ?? (first !== void 0 && first >= binCut(name, b) ? first : void 0);
|
|
178
|
+
if (f !== void 0) rollups[b] = Math.max(f, binCut(name, b));
|
|
179
|
+
}
|
|
180
|
+
out.push({ source: name, events: r.events, rollups: { ...r.rollups }, setBy: r.setBy, keptFrom: { ...ev.length ? { events: Math.min(...ev) } : {}, rollups } });
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
function predicate(q) {
|
|
185
|
+
let where = q.where, range = { from: q.from, to: q.to }, warnings = [];
|
|
186
|
+
if (!where && q.q) {
|
|
187
|
+
const p = parseSearch(q.q, now);
|
|
188
|
+
where = toAst(p);
|
|
189
|
+
range = rangeOf(p, q.from, q.to);
|
|
190
|
+
warnings = p.warnings;
|
|
191
|
+
}
|
|
192
|
+
const m = matchAst(where, sensitive);
|
|
193
|
+
const f = q.filters ?? {};
|
|
194
|
+
const src = f.source?.length ? new Set(f.source) : void 0, kind = f.kind?.length ? new Set(f.kind) : void 0;
|
|
195
|
+
const sev = f.severity?.length ? new Set(f.severity) : void 0, sc = f.scope?.length ? f.scope : void 0;
|
|
196
|
+
const test = (e) => within(e.scope, q.scope) && (!src || src.has(e.source)) && (!kind || kind.has(e.kind)) && (!sev || sev.has(e.severity)) && (!sc || sc.some((s) => within(e.scope, s))) && e.t >= eventCut(e.source) && m(e);
|
|
197
|
+
return { test, range, warnings };
|
|
198
|
+
}
|
|
199
|
+
function rowsOf(q) {
|
|
200
|
+
const base = levelOf(q.scope), level = base + q.depth;
|
|
201
|
+
const rowOf = /* @__PURE__ */ new Map();
|
|
202
|
+
const at = (s) => {
|
|
203
|
+
let r = rowOf.get(s);
|
|
204
|
+
if (r === void 0 && !rowOf.has(s)) {
|
|
205
|
+
r = within(s, q.scope) ? levelOf(s) >= level ? prefixAt(s, level) : s : void 0;
|
|
206
|
+
rowOf.set(s, r);
|
|
207
|
+
}
|
|
208
|
+
return r;
|
|
209
|
+
};
|
|
210
|
+
const children = (s) => {
|
|
211
|
+
let n = 0;
|
|
212
|
+
const l = levelOf(s) + 1;
|
|
213
|
+
for (const x of scopes) if (levelOf(x) === l && within(x, s)) n++;
|
|
214
|
+
return n;
|
|
215
|
+
};
|
|
216
|
+
const rows = /* @__PURE__ */ new Map();
|
|
217
|
+
const add = (s) => {
|
|
218
|
+
let r = rows.get(s);
|
|
219
|
+
if (!r) {
|
|
220
|
+
const d = levelOf(s) - base, n = names.get(s);
|
|
221
|
+
r = { scope: s, label: n?.label ?? nameOf(s), kind: kindOf(s), ...flagsOf(n), depth: d, ...d < q.depth ? { own: true } : {}, children: children(s), count: 0 };
|
|
222
|
+
rows.set(s, r);
|
|
223
|
+
}
|
|
224
|
+
return r;
|
|
225
|
+
};
|
|
226
|
+
for (const s of scopes) if (levelOf(s) === level && within(s, q.scope)) add(s);
|
|
227
|
+
if (level === 0) add("");
|
|
228
|
+
return { at, add, rows };
|
|
229
|
+
}
|
|
230
|
+
const sortRows = (rows) => [...rows.values()].sort((a, b) => a.scope === b.scope ? 0 : a.scope < b.scope ? -1 : 1);
|
|
231
|
+
function inRange(from, to) {
|
|
232
|
+
const out = [];
|
|
233
|
+
for (let i = lower(spans, from - maxDur); i < spans.length && spans[i].t < from; i++) if (spans[i].t + spans[i].dur > from) out.push(spans[i]);
|
|
234
|
+
for (const e of open.values()) if (e.t < from && now > from) out.push(e);
|
|
235
|
+
for (let i = lower(events, from); i < events.length && events[i].t < to; i++) out.push(events[i]);
|
|
236
|
+
return out;
|
|
237
|
+
}
|
|
238
|
+
function metricsFor(q, at, from, to) {
|
|
239
|
+
const want = q.series ? new Set(q.series) : void 0;
|
|
240
|
+
const acc = /* @__PURE__ */ new Map();
|
|
241
|
+
for (const st of stores.values()) {
|
|
242
|
+
if (want && !want.has(st.series)) continue;
|
|
243
|
+
const row = at(st.scope);
|
|
244
|
+
if (row === void 0) continue;
|
|
245
|
+
const src = seriesSource.get(st.series) ?? "";
|
|
246
|
+
const cut = binCut(src, q.bin);
|
|
247
|
+
const list = q.bin ? binned(st, q.bin, q.tz) : st.fine;
|
|
248
|
+
for (let i = lower(list, q.bin ? binStart(from, q.bin, q.tz) : from); i < list.length && list[i].t < to; i++) {
|
|
249
|
+
const f = list[i];
|
|
250
|
+
if (f.t < cut) continue;
|
|
251
|
+
const key = `${st.series}\0${row}\0${f.t}`;
|
|
252
|
+
const a = acc.get(key);
|
|
253
|
+
if (a) combine(a, f);
|
|
254
|
+
else acc.set(key, { series: st.series, scope: row, t: f.t, bin: q.bin ?? "1m", min: f.min, max: f.max, sum: f.sum, count: f.count });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const out = [...acc.values()].sort((a, b) => a.t - b.t || (a.series < b.series ? -1 : 1) || (a.scope < b.scope ? -1 : 1));
|
|
258
|
+
if (q.bin) return out;
|
|
259
|
+
return out.map((r) => ({ series: r.series, scope: r.scope, t: r.t, value: r.count === 1 || seriesType.get(r.series) !== "gauge" ? r.sum : r.sum / r.count }));
|
|
260
|
+
}
|
|
261
|
+
const encode = (e) => `${e.t}:${e.id}`;
|
|
262
|
+
const after = (e, c) => {
|
|
263
|
+
const i = c.indexOf(":"), t = Number(c.slice(0, i)), id = c.slice(i + 1);
|
|
264
|
+
return e.t > t || e.t === t && e.id > id;
|
|
265
|
+
};
|
|
266
|
+
function fastBinned(q) {
|
|
267
|
+
if (q.bin !== "1h" && q.bin !== "1d") return void 0;
|
|
268
|
+
if ((q.where?.all.length ?? 0) || q.q || q.filters?.kind?.length || q.filters?.severity?.length || q.filters?.scope?.length) return void 0;
|
|
269
|
+
if (offsetAt(q.tz, q.from) % HOUR || offsetAt(q.tz, q.to) % HOUR) return void 0;
|
|
270
|
+
const srcs = q.filters?.source?.length ? new Set(q.filters.source) : void 0;
|
|
271
|
+
const fromOf = (src) => Math.max(q.from, eventCut(src));
|
|
272
|
+
const { at, add, rows } = rowsOf(q);
|
|
273
|
+
const sources = /* @__PURE__ */ new Set();
|
|
274
|
+
const bins = /* @__PURE__ */ new Map();
|
|
275
|
+
let total = 0;
|
|
276
|
+
const binOf = (row, t) => {
|
|
277
|
+
const bt = binStart(t, q.bin, q.tz), key = `${row}\0${bt}`;
|
|
278
|
+
let b = bins.get(key);
|
|
279
|
+
if (!b) {
|
|
280
|
+
b = { scope: row, t: bt, bin: q.bin, count: 0, severity: {}, kinds: {} };
|
|
281
|
+
bins.set(key, b);
|
|
282
|
+
}
|
|
283
|
+
return b;
|
|
284
|
+
};
|
|
285
|
+
const count = (row, t, n) => {
|
|
286
|
+
const r = add(row);
|
|
287
|
+
r.count += n;
|
|
288
|
+
total += n;
|
|
289
|
+
if (r.first === void 0 || t < r.first) r.first = t;
|
|
290
|
+
if (r.last === void 0 || t > r.last) r.last = t;
|
|
291
|
+
};
|
|
292
|
+
const inner1 = Math.floor(q.to / HOUR) * HOUR;
|
|
293
|
+
for (const [scope, bySrc] of hours) {
|
|
294
|
+
const row = at(scope);
|
|
295
|
+
if (row === void 0) continue;
|
|
296
|
+
for (const [source, byT] of bySrc) {
|
|
297
|
+
if (srcs && !srcs.has(source)) continue;
|
|
298
|
+
const inner0 = Math.ceil(fromOf(source) / HOUR) * HOUR;
|
|
299
|
+
for (const [t, hb] of byT) {
|
|
300
|
+
if (t < inner0 || t >= inner1) continue;
|
|
301
|
+
count(row, hb.first, hb.count);
|
|
302
|
+
if (hb.last > (rows.get(row).last ?? -Infinity)) rows.get(row).last = hb.last;
|
|
303
|
+
sources.add(source);
|
|
304
|
+
const b = binOf(row, t);
|
|
305
|
+
b.count += hb.count;
|
|
306
|
+
for (const [k, n] of Object.entries(hb.severity)) b.severity[k] = (b.severity[k] ?? 0) + n;
|
|
307
|
+
for (const [k, n] of Object.entries(hb.kinds)) b.kinds[k] = (b.kinds[k] ?? 0) + n;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const take = (e) => within(e.scope, q.scope) && (!srcs || srcs.has(e.source)) && e.t >= eventCut(e.source) && at(e.scope) !== void 0;
|
|
312
|
+
const one = (e) => {
|
|
313
|
+
const row = at(e.scope);
|
|
314
|
+
count(row, e.t, 1);
|
|
315
|
+
sources.add(e.source);
|
|
316
|
+
const b = binOf(row, e.t);
|
|
317
|
+
b.count++;
|
|
318
|
+
b.severity[e.severity] = (b.severity[e.severity] ?? 0) + 1;
|
|
319
|
+
b.kinds[e.kind] = (b.kinds[e.kind] ?? 0) + 1;
|
|
320
|
+
};
|
|
321
|
+
for (const src of present) {
|
|
322
|
+
if (srcs && !srcs.has(src)) continue;
|
|
323
|
+
const a0 = fromOf(src), inner0 = Math.ceil(a0 / HOUR) * HOUR;
|
|
324
|
+
const edges = inner0 >= inner1 ? [[a0, q.to]] : [[a0, inner0], [inner1, q.to]];
|
|
325
|
+
for (const [a, z] of edges) for (let i = lower(events, a); i < events.length && events[i].t < z; i++) {
|
|
326
|
+
const e = events[i];
|
|
327
|
+
if (e.source === src && take(e)) one(e);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const w = BIN_MS[q.bin], long = [];
|
|
331
|
+
for (let i = lower(spans, q.from - maxDur); i < spans.length && spans[i].t < q.from; i++) {
|
|
332
|
+
const e = spans[i];
|
|
333
|
+
if (e.t + e.dur > q.from && take(e)) {
|
|
334
|
+
count(at(e.scope), e.t, 1);
|
|
335
|
+
sources.add(e.source);
|
|
336
|
+
if (e.dur >= w && long.length < 5e3) long.push(e);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
for (const e of open.values()) if (e.t < q.from && now > q.from && take(e)) {
|
|
340
|
+
count(at(e.scope), e.t, 1);
|
|
341
|
+
sources.add(e.source);
|
|
342
|
+
if (long.length < 5e3) long.push(e);
|
|
343
|
+
}
|
|
344
|
+
for (let i = lower(spans, q.from); i < spans.length && spans[i].t < q.to && long.length < 5e3; i++) if (spans[i].dur >= w && take(spans[i])) long.push(spans[i]);
|
|
345
|
+
for (const e of open.values()) if (e.t >= q.from && e.t < q.to && long.length < 5e3 && take(e)) long.push(e);
|
|
346
|
+
const metrics = metricsFor(q, at, q.from, q.to);
|
|
347
|
+
for (const m of metrics) {
|
|
348
|
+
const s2 = seriesSource.get(m.series);
|
|
349
|
+
if (s2) sources.add(s2);
|
|
350
|
+
}
|
|
351
|
+
const out = [...bins.values()].sort((a, b) => a.t - b.t || (a.scope < b.scope ? -1 : 1));
|
|
352
|
+
return { timeline: 1, type: "result", rows: sortRows(rows), bins: out, spans: long, metrics, total, retention: effective(sources) };
|
|
353
|
+
}
|
|
354
|
+
async function query(q) {
|
|
355
|
+
if (!isScope(q.scope)) throw new Error(`not a scope path: ${JSON.stringify(q.scope)}`);
|
|
356
|
+
const fast = fastBinned(q);
|
|
357
|
+
if (fast) return fast;
|
|
358
|
+
const { test, range, warnings } = predicate(q);
|
|
359
|
+
const { at, add, rows } = rowsOf(q);
|
|
360
|
+
const sources = /* @__PURE__ */ new Set();
|
|
361
|
+
const hits = [];
|
|
362
|
+
for (const e of inRange(range.from, range.to)) {
|
|
363
|
+
if (!test(e)) continue;
|
|
364
|
+
const row = at(e.scope);
|
|
365
|
+
if (row === void 0) continue;
|
|
366
|
+
const r = add(row);
|
|
367
|
+
r.count++;
|
|
368
|
+
if (r.first === void 0 || e.t < r.first) r.first = e.t;
|
|
369
|
+
if (r.last === void 0 || e.t > r.last) r.last = e.t;
|
|
370
|
+
sources.add(e.source);
|
|
371
|
+
hits.push(e);
|
|
372
|
+
}
|
|
373
|
+
hits.sort(byTimeId);
|
|
374
|
+
const metrics = metricsFor(q, at, range.from, range.to);
|
|
375
|
+
for (const m of metrics) {
|
|
376
|
+
const s = seriesSource.get(m.series);
|
|
377
|
+
if (s) sources.add(s);
|
|
378
|
+
}
|
|
379
|
+
const base = { timeline: 1, type: "result", total: hits.length, ...warnings.length ? { warnings } : {} };
|
|
380
|
+
if (q.bin) {
|
|
381
|
+
const w = BIN_MS[q.bin], bins = /* @__PURE__ */ new Map(), long = [];
|
|
382
|
+
for (const e of hits) {
|
|
383
|
+
if ((e.open || e.dur !== void 0 && e.dur >= w) && long.length < 5e3) long.push(e);
|
|
384
|
+
if (e.t < range.from) continue;
|
|
385
|
+
const row = at(e.scope), t = binStart(e.t, q.bin, q.tz), key = `${row}\0${t}`;
|
|
386
|
+
let b = bins.get(key);
|
|
387
|
+
if (!b) {
|
|
388
|
+
b = { scope: row, t, bin: q.bin, count: 0, severity: {}, kinds: {} };
|
|
389
|
+
bins.set(key, b);
|
|
390
|
+
}
|
|
391
|
+
b.count++;
|
|
392
|
+
b.severity[e.severity] = (b.severity[e.severity] ?? 0) + 1;
|
|
393
|
+
b.kinds[e.kind] = (b.kinds[e.kind] ?? 0) + 1;
|
|
394
|
+
}
|
|
395
|
+
const out = [...bins.values()].sort((a, b) => a.t - b.t || (a.scope < b.scope ? -1 : 1));
|
|
396
|
+
return { ...base, rows: sortRows(rows), bins: out, spans: long, metrics, retention: effective(sources) };
|
|
397
|
+
}
|
|
398
|
+
const limit = Math.min(1e4, Math.max(1, q.limit ?? 2e3));
|
|
399
|
+
const start = q.cursor ? hits.findIndex((e) => after(e, q.cursor)) : 0;
|
|
400
|
+
const page = start < 0 ? [] : hits.slice(start, start + limit);
|
|
401
|
+
const more = start >= 0 && start + limit < hits.length;
|
|
402
|
+
return { ...base, rows: sortRows(rows), events: page, metrics, retention: effective(sources), ...more ? { next: encode(page[page.length - 1]) } : {} };
|
|
403
|
+
}
|
|
404
|
+
const subs = /* @__PURE__ */ new Set();
|
|
405
|
+
const severityOk = (s) => SEVERITIES.includes(s);
|
|
406
|
+
let seq = 0;
|
|
407
|
+
function put(e) {
|
|
408
|
+
const key = keyOf(e), old = byId.get(key);
|
|
409
|
+
if (old) {
|
|
410
|
+
remove(events, old.t, (x) => x === old);
|
|
411
|
+
tally(old, -1);
|
|
412
|
+
if (old.dur !== void 0 && !old.open) remove(spans, old.t, (x) => x === old);
|
|
413
|
+
open.delete(key);
|
|
414
|
+
}
|
|
415
|
+
byId.set(key, e);
|
|
416
|
+
tally(e, 1);
|
|
417
|
+
place(events, e, () => false, byTimeId);
|
|
418
|
+
if (e.open) open.set(key, e);
|
|
419
|
+
else if (e.dur !== void 0) {
|
|
420
|
+
place(spans, e, () => false, byTimeId);
|
|
421
|
+
maxDur = Math.max(maxDur, e.dur);
|
|
422
|
+
}
|
|
423
|
+
noteScope(e.scope);
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
async catalog() {
|
|
427
|
+
return { ...catalog, now, retention: effective(catalog.sources.map((s) => s.name)) };
|
|
428
|
+
},
|
|
429
|
+
query,
|
|
430
|
+
subscribe(q, on) {
|
|
431
|
+
const sub = { q, on };
|
|
432
|
+
subs.add(sub);
|
|
433
|
+
return () => {
|
|
434
|
+
subs.delete(sub);
|
|
435
|
+
};
|
|
436
|
+
},
|
|
437
|
+
...o.stateAt ? { stateAt: (scope, t) => o.stateAt(scope, t) } : {},
|
|
438
|
+
append(es, ms = [], t) {
|
|
439
|
+
if (t !== void 0) now = Math.max(now, t);
|
|
440
|
+
const known = new Set(scopes);
|
|
441
|
+
const fixed = es.map(fix);
|
|
442
|
+
for (const e of fixed) {
|
|
443
|
+
if (!severityOk(e.severity)) throw new Error(`not a severity: ${e.severity}`);
|
|
444
|
+
put(e);
|
|
445
|
+
}
|
|
446
|
+
for (const m of ms) addMetric(m);
|
|
447
|
+
seq++;
|
|
448
|
+
for (const s of subs) {
|
|
449
|
+
const { test } = predicate(s.q);
|
|
450
|
+
const { at } = rowsOf(s.q);
|
|
451
|
+
const evs = fixed.filter((e) => test(e) && at(e.scope) !== void 0);
|
|
452
|
+
const want = s.q.series ? new Set(s.q.series) : void 0;
|
|
453
|
+
const mets = ms.filter((m) => within(canon(m.scope), s.q.scope) && (!want || want.has(m.series))).map((m) => ({ ...m, scope: at(canon(m.scope)) }));
|
|
454
|
+
const fresh = [...scopes].filter((x) => !known.has(x));
|
|
455
|
+
const level = levelOf(s.q.scope) + s.q.depth;
|
|
456
|
+
const rows = fresh.filter((x) => levelOf(x) === level && within(x, s.q.scope)).map((x) => ({ scope: x, label: names.get(x)?.label ?? nameOf(x), kind: kindOf(x), depth: s.q.depth, children: 0, count: 0 }));
|
|
457
|
+
s.on({ timeline: 1, type: "batch", events: evs, metrics: mets, ...rows.length ? { rows } : {}, now, resume: String(seq) });
|
|
458
|
+
}
|
|
459
|
+
},
|
|
460
|
+
setRetention(source, r) {
|
|
461
|
+
retention.set(source, { events: r.events, rollups: { ...r.rollups }, setBy: "user" });
|
|
462
|
+
},
|
|
463
|
+
get now() {
|
|
464
|
+
return now;
|
|
465
|
+
},
|
|
466
|
+
get size() {
|
|
467
|
+
let n = 0;
|
|
468
|
+
for (const st of stores.values()) n += st.fine.length;
|
|
469
|
+
return { events: events.length, samples: n };
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
export {
|
|
474
|
+
memorySource
|
|
475
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const BASE = ["id", "time", "t", "dur", "scope", "source", "kind", "severity", "summary"];
|
|
2
|
+
const cell = (v) => {
|
|
3
|
+
if (v === void 0 || v === null) return "";
|
|
4
|
+
const s = typeof v === "string" && /^[=+\-@\t\r]/.test(v) ? `'${v}` : String(v);
|
|
5
|
+
return /[",\n\r]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
|
|
6
|
+
};
|
|
7
|
+
const drop = (e, sensitive) => sensitive.size ? { ...e, attrs: Object.fromEntries(Object.entries(e.attrs).filter(([k]) => !sensitive.has(`${e.source}.${k}`))) } : e;
|
|
8
|
+
function toJSON(events, sensitive = []) {
|
|
9
|
+
const s = new Set(sensitive);
|
|
10
|
+
return JSON.stringify(events.map((e) => drop(e, s)), null, 2) + "\n";
|
|
11
|
+
}
|
|
12
|
+
function toCSV(events, sensitive = []) {
|
|
13
|
+
const s = new Set(sensitive);
|
|
14
|
+
const es = events.map((e) => drop(e, s));
|
|
15
|
+
const attrs = [...new Set(es.flatMap((e) => Object.keys(e.attrs)))].sort();
|
|
16
|
+
const links = [...new Set(es.flatMap((e) => Object.keys(e.links)))].sort();
|
|
17
|
+
const head = [...BASE, ...attrs.map((a) => `attr.${a}`), ...links.map((l) => `link.${l}`)];
|
|
18
|
+
const rows = es.map((e) => [
|
|
19
|
+
e.id,
|
|
20
|
+
new Date(e.t).toISOString(),
|
|
21
|
+
e.t,
|
|
22
|
+
e.dur,
|
|
23
|
+
e.scope,
|
|
24
|
+
e.source,
|
|
25
|
+
e.kind,
|
|
26
|
+
e.severity,
|
|
27
|
+
e.summary,
|
|
28
|
+
...attrs.map((a) => e.attrs[a]),
|
|
29
|
+
...links.map((l) => e.links[l])
|
|
30
|
+
].map(cell).join(","));
|
|
31
|
+
return [head.join(","), ...rows].join("\r\n") + "\r\n";
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
toCSV,
|
|
35
|
+
toJSON
|
|
36
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { offsetAt } from "./timeline-time.js";
|
|
2
|
+
const MIN = 6e4, HOUR = 36e5, DAY = 864e5;
|
|
3
|
+
function findGaps(activity, t0, t1, o = {}) {
|
|
4
|
+
const minLen = Math.max((o.minFrac ?? 0.15) * (t1 - t0), o.minMs ?? 10 * MIN);
|
|
5
|
+
const xs = activity.filter(([a, b]) => b >= t0 && a < t1).map(([a, b]) => [Math.max(t0, a), Math.min(t1, Math.max(a, b))]).sort((p, q) => p[0] - q[0]);
|
|
6
|
+
const out = [];
|
|
7
|
+
if (!xs.length) return out;
|
|
8
|
+
let at = t0;
|
|
9
|
+
for (const [a, b] of xs) {
|
|
10
|
+
if (a - at > minLen) out.push({ from: at, to: a });
|
|
11
|
+
at = Math.max(at, b);
|
|
12
|
+
}
|
|
13
|
+
if (t1 - at > minLen) out.push({ from: at, to: t1 });
|
|
14
|
+
return out;
|
|
15
|
+
}
|
|
16
|
+
function gapLabel(ms) {
|
|
17
|
+
if (ms >= DAY) {
|
|
18
|
+
const d = Math.floor(ms / DAY), hh = Math.round((ms - d * DAY) / HOUR);
|
|
19
|
+
return hh ? `${d} d ${hh} h` : `${d} d`;
|
|
20
|
+
}
|
|
21
|
+
if (ms >= HOUR) {
|
|
22
|
+
const hh = Math.floor(ms / HOUR), m = Math.round((ms - hh * HOUR) / MIN);
|
|
23
|
+
return m && hh < 10 ? `${hh} h ${m} min` : `${hh} h`;
|
|
24
|
+
}
|
|
25
|
+
return `${Math.max(1, Math.round(ms / MIN))} min`;
|
|
26
|
+
}
|
|
27
|
+
const gapKey = (g) => `${g.from}-${g.to}`;
|
|
28
|
+
function timeScale(t0, t1, width, gaps = [], o = {}) {
|
|
29
|
+
const cutPx = o.cut ?? 24, W = Math.max(1, width), span = Math.max(1, t1 - t0);
|
|
30
|
+
const gs = gaps.filter((g) => g.to > t0 && g.from < t1).map((g) => ({ from: Math.max(t0, g.from), to: Math.min(t1, g.to), w: o.weights?.get(gapKey(g)) ?? 0 })).sort((a, b) => a.from - b.from);
|
|
31
|
+
const lenC = gs.reduce((n, g) => n + (g.to - g.from) * (1 - g.w), 0);
|
|
32
|
+
const fixed = gs.reduce((n, g) => n + (1 - g.w) * cutPx, 0);
|
|
33
|
+
let k = (W - fixed) / Math.max(1, span - lenC);
|
|
34
|
+
if (!(k > 0) || fixed > W * 0.6) {
|
|
35
|
+
return timeScale(t0, t1, width, [], o);
|
|
36
|
+
}
|
|
37
|
+
const pts = [[t0, 0]];
|
|
38
|
+
let x = 0, t = t0;
|
|
39
|
+
const cuts = [];
|
|
40
|
+
for (const g of gs) {
|
|
41
|
+
x += (g.from - t) * k;
|
|
42
|
+
pts.push([g.from, x]);
|
|
43
|
+
const wpx = (1 - g.w) * cutPx + g.w * k * (g.to - g.from);
|
|
44
|
+
cuts.push({ from: g.from, to: g.to, x0: x, x1: x + wpx, weight: g.w });
|
|
45
|
+
x += wpx;
|
|
46
|
+
pts.push([g.to, x]);
|
|
47
|
+
t = g.to;
|
|
48
|
+
}
|
|
49
|
+
pts.push([t1, x + (t1 - t) * k]);
|
|
50
|
+
const xOf = (tt) => {
|
|
51
|
+
if (tt <= t0) return (tt - t0) * k;
|
|
52
|
+
if (tt >= t1) return pts[pts.length - 1][1] + (tt - t1) * k;
|
|
53
|
+
let lo = 0, hi = pts.length - 1;
|
|
54
|
+
while (hi - lo > 1) {
|
|
55
|
+
const m = lo + hi >> 1;
|
|
56
|
+
if (pts[m][0] <= tt) lo = m;
|
|
57
|
+
else hi = m;
|
|
58
|
+
}
|
|
59
|
+
const [ta, xa] = pts[lo], [tb, xb] = pts[hi];
|
|
60
|
+
return tb === ta ? xa : xa + (tt - ta) / (tb - ta) * (xb - xa);
|
|
61
|
+
};
|
|
62
|
+
const cutAt = (px) => cuts.find((c) => c.weight < 1 && px > c.x0 && px < c.x1);
|
|
63
|
+
const tOf = (px) => {
|
|
64
|
+
const c = cutAt(px);
|
|
65
|
+
if (c) return px - c.x0 < c.x1 - px ? c.from : c.to;
|
|
66
|
+
if (px <= 0) return t0 + px / k;
|
|
67
|
+
let lo = 0, hi = pts.length - 1;
|
|
68
|
+
if (px >= pts[hi][1]) return t1 + (px - pts[hi][1]) / k;
|
|
69
|
+
while (hi - lo > 1) {
|
|
70
|
+
const m = lo + hi >> 1;
|
|
71
|
+
if (pts[m][1] <= px) lo = m;
|
|
72
|
+
else hi = m;
|
|
73
|
+
}
|
|
74
|
+
const [ta, xa] = pts[lo], [tb, xb] = pts[hi];
|
|
75
|
+
return xb === xa ? ta : ta + (px - xa) / (xb - xa) * (tb - ta);
|
|
76
|
+
};
|
|
77
|
+
return { t0, t1, width: W, cuts, x: xOf, t: tOf, cutAt, msPerPx: 1 / k };
|
|
78
|
+
}
|
|
79
|
+
const STEPS = [1e3, 5e3, 15e3, 3e4, MIN, 5 * MIN, 15 * MIN, 30 * MIN, HOUR, 3 * HOUR, 6 * HOUR, 12 * HOUR, DAY, 2 * DAY, 7 * DAY, 14 * DAY, 28 * DAY];
|
|
80
|
+
function ticks(s, tz, minPx = 80) {
|
|
81
|
+
const step = STEPS.find((st) => st / s.msPerPx >= minPx) ?? STEPS[STEPS.length - 1];
|
|
82
|
+
const out = [];
|
|
83
|
+
const fmt = (t) => {
|
|
84
|
+
const local = new Date(t + offsetAt(tz, t));
|
|
85
|
+
const hh = String(local.getUTCHours()).padStart(2, "0"), mm = String(local.getUTCMinutes()).padStart(2, "0"), ss = String(local.getUTCSeconds()).padStart(2, "0");
|
|
86
|
+
const day = `${local.getUTCDate()} ${["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][local.getUTCMonth()]}`;
|
|
87
|
+
const midnight = hh === "00" && mm === "00" && ss === "00";
|
|
88
|
+
if (step >= DAY || midnight) return { label: day, major: true };
|
|
89
|
+
return { label: step < MIN ? `${hh}:${mm}:${ss}` : `${hh}:${mm}`, major: false };
|
|
90
|
+
};
|
|
91
|
+
const segs = [];
|
|
92
|
+
let a = s.t0;
|
|
93
|
+
for (const c of s.cuts) if (c.weight < 1) {
|
|
94
|
+
segs.push([a, c.from]);
|
|
95
|
+
a = c.to;
|
|
96
|
+
}
|
|
97
|
+
segs.push([a, s.t1]);
|
|
98
|
+
for (const [from, to] of segs) {
|
|
99
|
+
const utc = (lt2) => lt2 - offsetAt(tz, lt2 - offsetAt(tz, lt2));
|
|
100
|
+
let lt = Math.ceil((from + offsetAt(tz, from)) / step) * step;
|
|
101
|
+
if (step >= 7 * DAY) lt = Math.ceil((from + offsetAt(tz, from)) / DAY) * DAY;
|
|
102
|
+
for (let guard = 0, t = utc(lt); t < to && guard < 2e3; guard++, lt += step, t = utc(lt)) {
|
|
103
|
+
if (t < from) continue;
|
|
104
|
+
const x = s.x(t), prev = out[out.length - 1];
|
|
105
|
+
if (!prev || x - prev.x >= minPx * 0.6) out.push({ t, x, ...fmt(t) });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
findGaps,
|
|
112
|
+
gapKey,
|
|
113
|
+
gapLabel,
|
|
114
|
+
ticks,
|
|
115
|
+
timeScale
|
|
116
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { scopePattern } from "./timeline-contract.js";
|
|
2
|
+
function scopeRules(cat) {
|
|
3
|
+
const RE = new RegExp(scopePattern(cat));
|
|
4
|
+
const isScope = (s) => RE.test(s);
|
|
5
|
+
function parseScope(s) {
|
|
6
|
+
if (!RE.test(s)) throw new Error(`not a scope path: ${JSON.stringify(s)}`);
|
|
7
|
+
if (s === "") return [];
|
|
8
|
+
return s.split("/").map((seg) => {
|
|
9
|
+
const i = seg.indexOf(":");
|
|
10
|
+
return { kind: seg.slice(0, i), name: decodeURIComponent(seg.slice(i + 1)) };
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
function wellNested(s) {
|
|
14
|
+
let parent = "";
|
|
15
|
+
for (const seg of parseScope(s)) {
|
|
16
|
+
if (!cat.parents[seg.kind].includes(parent)) return false;
|
|
17
|
+
parent = seg.kind;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return { isScope, parseScope, wellNested };
|
|
22
|
+
}
|
|
23
|
+
const escapeName = (n) => n.replace(/[%/:\s]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`);
|
|
24
|
+
const formatScope = (segs) => segs.map((s) => `${s.kind}:${escapeName(s.name)}`).join("/");
|
|
25
|
+
const join = (parent, kind, name) => (parent ? `${parent}/` : "") + `${kind}:${escapeName(name)}`;
|
|
26
|
+
const levelOf = (s) => s === "" ? 0 : s.split("/").length;
|
|
27
|
+
function prefixAt(s, level) {
|
|
28
|
+
if (level <= 0) return "";
|
|
29
|
+
const parts = s === "" ? [] : s.split("/");
|
|
30
|
+
return parts.slice(0, level).join("/");
|
|
31
|
+
}
|
|
32
|
+
const parentOf = (s) => prefixAt(s, levelOf(s) - 1);
|
|
33
|
+
const within = (s, prefix) => prefix === "" || s === prefix || s.startsWith(`${prefix}/`);
|
|
34
|
+
const hasSegment = (s, seg) => s !== "" && s.split("/").includes(seg);
|
|
35
|
+
const kindOf = (s) => s === "" ? "fleet" : s.slice(s.lastIndexOf("/") + 1).split(":")[0];
|
|
36
|
+
const nameOf = (s) => s === "" ? "all hosts" : decodeURIComponent(s.slice(s.lastIndexOf("/") + 1).split(":").slice(1).join(":"));
|
|
37
|
+
function crumbs(s) {
|
|
38
|
+
const out = [{ scope: "", label: "all hosts", kind: "fleet" }];
|
|
39
|
+
for (let l = 1; l <= levelOf(s); l++) {
|
|
40
|
+
const p = prefixAt(s, l);
|
|
41
|
+
out.push({ scope: p, label: nameOf(p), kind: kindOf(p) });
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
crumbs,
|
|
47
|
+
escapeName,
|
|
48
|
+
formatScope,
|
|
49
|
+
hasSegment,
|
|
50
|
+
join,
|
|
51
|
+
kindOf,
|
|
52
|
+
levelOf,
|
|
53
|
+
nameOf,
|
|
54
|
+
parentOf,
|
|
55
|
+
prefixAt,
|
|
56
|
+
scopeRules,
|
|
57
|
+
within
|
|
58
|
+
};
|