@bli-cockpit/telemetry-core 0.1.58 → 0.1.60
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/log-digest/classify.d.ts +48 -0
- package/dist/log-digest/classify.js +81 -0
- package/dist/log-digest/digest-source.d.ts +101 -0
- package/dist/log-digest/digest-source.js +131 -0
- package/dist/log-digest/digest.d.ts +81 -0
- package/dist/log-digest/digest.js +262 -0
- package/dist/log-digest/index.d.ts +19 -0
- package/dist/log-digest/index.js +19 -0
- package/dist/log-digest/judge.d.ts +33 -0
- package/dist/log-digest/judge.js +198 -0
- package/dist/log-digest/log-projects.d.ts +78 -0
- package/dist/log-digest/log-projects.js +163 -0
- package/dist/log-digest/mask.d.ts +12 -0
- package/dist/log-digest/mask.js +106 -0
- package/dist/log-digest/merge.d.ts +12 -0
- package/dist/log-digest/merge.js +65 -0
- package/dist/log-digest/project-classes.d.ts +16 -0
- package/dist/log-digest/project-classes.js +31 -0
- package/dist/log-digest/render.d.ts +51 -0
- package/dist/log-digest/render.js +214 -0
- package/dist/log-digest/scrub.d.ts +11 -0
- package/dist/log-digest/scrub.js +73 -0
- package/dist/log-digest/sources/collector.d.ts +15 -0
- package/dist/log-digest/sources/collector.js +166 -0
- package/dist/log-digest/sources/process.d.ts +2 -0
- package/dist/log-digest/sources/process.js +78 -0
- package/dist/log-digest/sources/railway.d.ts +6 -0
- package/dist/log-digest/sources/railway.js +156 -0
- package/dist/log-digest/sources/stdin.d.ts +9 -0
- package/dist/log-digest/sources/stdin.js +56 -0
- package/dist/log-digest/sources/types.d.ts +67 -0
- package/dist/log-digest/sources/types.js +13 -0
- package/dist/log-digest/sources/vercel.d.ts +40 -0
- package/dist/log-digest/sources/vercel.js +194 -0
- package/dist/log-digest/stored.d.ts +98 -0
- package/dist/log-digest/stored.js +149 -0
- package/dist/log-digest/tagged.d.ts +37 -0
- package/dist/log-digest/tagged.js +114 -0
- package/dist/log-digest/tower-classes.d.ts +28 -0
- package/dist/log-digest/tower-classes.js +301 -0
- package/dist/log-digest/window.d.ts +21 -0
- package/dist/log-digest/window.js +39 -0
- package/package.json +6 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The time window a digest covers: `90s`, `15m`, `2h`, `1d`, a bare number of
|
|
3
|
+
* minutes, or an ISO timestamp. Kaiben's `--since` took the same relative forms.
|
|
4
|
+
*/
|
|
5
|
+
const UNIT_SECONDS = { "": 60, s: 1, m: 60, h: 3600, d: 86400 };
|
|
6
|
+
/** The only shapes `--since` may take: a count and one unit, or an ISO timestamp. Nothing else reaches a program. */
|
|
7
|
+
export const SINCE_ALLOWLIST = /^(\d{1,4}[smhd]|\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?(Z|[+-]\d{2}:\d{2})?)?)$/;
|
|
8
|
+
export class WindowError extends Error {
|
|
9
|
+
reason = "invalid_since";
|
|
10
|
+
}
|
|
11
|
+
/** Seconds in a relative window like `15m`, or null when the text is not one. */
|
|
12
|
+
export function relativeSeconds(text) {
|
|
13
|
+
const match = /^(\d+(?:\.\d+)?)\s*([smhd]?)$/.exec(text.trim());
|
|
14
|
+
if (!match)
|
|
15
|
+
return null;
|
|
16
|
+
return Number.parseFloat(match[1]) * UNIT_SECONDS[match[2]];
|
|
17
|
+
}
|
|
18
|
+
export function parseWindow(text, nowMs = Date.now()) {
|
|
19
|
+
const raw = (text ?? "15m").trim();
|
|
20
|
+
if (!SINCE_ALLOWLIST.test(raw))
|
|
21
|
+
throw new WindowError(`--since wants 15m, 1h, 2d or an ISO time, not ${JSON.stringify(raw.slice(0, 40))}`);
|
|
22
|
+
const toEpoch = nowMs / 1000;
|
|
23
|
+
const seconds = relativeSeconds(raw);
|
|
24
|
+
if (seconds !== null) {
|
|
25
|
+
if (seconds <= 0)
|
|
26
|
+
throw new WindowError(`--since wants 15m, 1h, 2d or an ISO time, not ${JSON.stringify(raw)}`);
|
|
27
|
+
return { fromEpoch: toEpoch - seconds, toEpoch, label: `last ${raw}` };
|
|
28
|
+
}
|
|
29
|
+
const parsed = Date.parse(raw);
|
|
30
|
+
if (!Number.isFinite(parsed) || !/^\d{4}-\d{2}-\d{2}/.test(raw)) {
|
|
31
|
+
throw new WindowError(`--since wants 15m, 1h, 2d or an ISO time, not ${JSON.stringify(raw)}`);
|
|
32
|
+
}
|
|
33
|
+
if (parsed > nowMs)
|
|
34
|
+
throw new WindowError("--since is in the future");
|
|
35
|
+
return { fromEpoch: parsed / 1000, toEpoch, label: `since ${new Date(parsed).toISOString().slice(0, 16)}Z` };
|
|
36
|
+
}
|
|
37
|
+
export function isoOf(epochSeconds) {
|
|
38
|
+
return new Date(epochSeconds * 1000).toISOString();
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bli-cockpit/telemetry-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.60",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,6 +35,11 @@
|
|
|
35
35
|
"import": "./dist/node-daemon-http-client.js",
|
|
36
36
|
"default": "./dist/node-daemon-http-client.js"
|
|
37
37
|
},
|
|
38
|
+
"./log-digest": {
|
|
39
|
+
"types": "./dist/log-digest/index.d.ts",
|
|
40
|
+
"import": "./dist/log-digest/index.js",
|
|
41
|
+
"default": "./dist/log-digest/index.js"
|
|
42
|
+
},
|
|
38
43
|
"./node-read-cache": {
|
|
39
44
|
"types": "./dist/node-read-cache.d.ts",
|
|
40
45
|
"import": "./dist/node-read-cache.js",
|