spl2dql 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +18 -0
- package/README.md +82 -2
- package/bin/spl2dql.js +20 -0
- package/dist/inputs.d.ts +21 -0
- package/dist/inputs.js +130 -0
- package/dist/main.d.ts +41 -0
- package/dist/main.js +650 -0
- package/dist/mapping.d.ts +18 -0
- package/dist/mapping.js +60 -0
- package/dist/report.d.ts +95 -0
- package/dist/report.js +285 -0
- package/dist/safe-fs.d.ts +7 -0
- package/dist/safe-fs.js +81 -0
- package/dist/serve/server.d.ts +47 -0
- package/dist/serve/server.js +195 -0
- package/package.json +64 -3
- package/web/404.html +27 -0
- package/web/THIRD-PARTY-NOTICES.txt +774 -0
- package/web/_headers +26 -0
- package/web/assets/BatchView-CJw9TDhQ.js +1 -0
- package/web/assets/DashboardsView-gW0FEoq7.js +1 -0
- package/web/assets/DropZone-CIbk77sc.js +492 -0
- package/web/assets/MappingView-Co21Vkp_.js +14 -0
- package/web/assets/ReferenceView-S1R-kCt6.js +2 -0
- package/web/assets/atkinson-hyperlegible-mono-latin-ext-wght-normal-CXgNM06D.woff2 +0 -0
- package/web/assets/atkinson-hyperlegible-mono-latin-wght-normal-CoA7y8X5.woff2 +0 -0
- package/web/assets/atkinson-hyperlegible-next-latin-ext-wght-normal-C6vrW8VD.woff2 +0 -0
- package/web/assets/atkinson-hyperlegible-next-latin-wght-normal-BcXVPD7q.woff2 +0 -0
- package/web/assets/dict-9ToLi8Te.js +1 -0
- package/web/assets/index-BO3AM1fZ.js +46 -0
- package/web/assets/index-DPywAY6M.css +2 -0
- package/web/assets/jsx-runtime-Wy9s6hX0.js +1 -0
- package/web/assets/mapping-text-B64_Oh2A.js +106 -0
- package/web/assets/translate.worker-C2M3Sf23.js +656 -0
- package/web/icon-180.png +0 -0
- package/web/icon-192.png +0 -0
- package/web/icon-512.png +0 -0
- package/web/icon.svg +1 -0
- package/web/index.html +63 -0
- package/web/manifest.webmanifest +15 -0
- package/web/robots.txt +2 -0
- package/web/social.png +0 -0
- package/web/sw.js +24 -0
package/dist/mapping.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { existsSync, lstatSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { parseMappingConfig } from '@spl2dql/core';
|
|
4
|
+
import { parse as parseYaml } from 'yaml';
|
|
5
|
+
export class MappingError extends Error {
|
|
6
|
+
issues;
|
|
7
|
+
constructor(message, issues = []) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.issues = issues;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const DEFAULT_FILE = 'spl2dql.mapping.yaml';
|
|
13
|
+
const MAX_MAPPING = 5 * 1024 * 1024;
|
|
14
|
+
/** Reads mapping text (YAML or JSON) safely: no custom tags, limited aliases, unique keys. */
|
|
15
|
+
function readMappingText(text, name) {
|
|
16
|
+
try {
|
|
17
|
+
return parseYaml(text, { schema: 'core', maxAliasCount: 100, uniqueKeys: true, merge: false, prettyErrors: true });
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
throw new MappingError(`${name}: ${e.message.split('\n')[0]}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Validates already-parsed mapping data. */
|
|
24
|
+
export function validateMapping(data, name) {
|
|
25
|
+
const result = parseMappingConfig(data);
|
|
26
|
+
if (!result.ok)
|
|
27
|
+
throw new MappingError(`${name} has ${result.issues.length} problem(s).`, result.issues);
|
|
28
|
+
return result.value;
|
|
29
|
+
}
|
|
30
|
+
/** Parses mapping text (YAML or JSON) and validates it. */
|
|
31
|
+
export function parseMappingText(text, name) {
|
|
32
|
+
return validateMapping(readMappingText(text, name), name);
|
|
33
|
+
}
|
|
34
|
+
/** Loads --mapping, or spl2dql.mapping.yaml from the working directory when present. */
|
|
35
|
+
export function loadMappingFile(path, cwd) {
|
|
36
|
+
const file = path ? resolve(cwd, path) : resolve(cwd, DEFAULT_FILE);
|
|
37
|
+
if (!path && !existsSync(file))
|
|
38
|
+
return undefined;
|
|
39
|
+
let size;
|
|
40
|
+
try {
|
|
41
|
+
const st = lstatSync(file);
|
|
42
|
+
if (!st.isFile())
|
|
43
|
+
throw new MappingError(`${file} is not a regular file.`);
|
|
44
|
+
size = st.size;
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
if (e instanceof MappingError)
|
|
48
|
+
throw e;
|
|
49
|
+
throw new MappingError(`Cannot read the mapping file ${file}.`);
|
|
50
|
+
}
|
|
51
|
+
if (size > MAX_MAPPING)
|
|
52
|
+
throw new MappingError(`${file} is larger than 5 MB.`);
|
|
53
|
+
const data = readMappingText(readFileSync(file, 'utf8'), file);
|
|
54
|
+
const mapping = validateMapping(data, file);
|
|
55
|
+
return { file, data: data, mapping };
|
|
56
|
+
}
|
|
57
|
+
export function loadMapping(path, cwd) {
|
|
58
|
+
return loadMappingFile(path, cwd)?.mapping;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=mapping.js.map
|
package/dist/report.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { Confidence, DashboardConversion, Diagnostic, TileOutcome, TranslateResult } from '@spl2dql/core';
|
|
2
|
+
/** What a report needs of one translation; the rest of the result is not kept for the whole run. */
|
|
3
|
+
export interface ReportResult {
|
|
4
|
+
dql: string;
|
|
5
|
+
confidence: Confidence;
|
|
6
|
+
score: number;
|
|
7
|
+
/** The first MAX_NOTES_SHOWN notes. */
|
|
8
|
+
diagnostics: Diagnostic[];
|
|
9
|
+
/** Notes left out of the report; they are only counted. */
|
|
10
|
+
moreNotes?: number;
|
|
11
|
+
/** Warnings and errors among all the notes, for the report's index. */
|
|
12
|
+
attention: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ReportEntry {
|
|
15
|
+
name: string;
|
|
16
|
+
origin: string;
|
|
17
|
+
file: string;
|
|
18
|
+
spl: string;
|
|
19
|
+
result: ReportResult;
|
|
20
|
+
/** From savedsearches.conf: the saved time range, the schedule, and whether Splunk has it switched off. */
|
|
21
|
+
earliest?: string;
|
|
22
|
+
latest?: string;
|
|
23
|
+
schedule?: string;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** Set when the report's budget was reached: the search is listed without SPL, DQL and notes. */
|
|
26
|
+
noDetail?: true;
|
|
27
|
+
}
|
|
28
|
+
/** What a report needs of one converted dashboard. */
|
|
29
|
+
export interface ReportBoard {
|
|
30
|
+
title: string;
|
|
31
|
+
format: DashboardConversion['format'];
|
|
32
|
+
counts: DashboardConversion['counts'];
|
|
33
|
+
notes: string[];
|
|
34
|
+
variables: {
|
|
35
|
+
key: string;
|
|
36
|
+
token: string;
|
|
37
|
+
type: string;
|
|
38
|
+
notes: string[];
|
|
39
|
+
}[];
|
|
40
|
+
tiles: {
|
|
41
|
+
title: string;
|
|
42
|
+
outcome: TileOutcome;
|
|
43
|
+
visualization?: string;
|
|
44
|
+
spl?: string;
|
|
45
|
+
result?: {
|
|
46
|
+
confidence: Confidence;
|
|
47
|
+
dql: string;
|
|
48
|
+
};
|
|
49
|
+
notes: string[];
|
|
50
|
+
}[];
|
|
51
|
+
/** Set when the report's budget was reached: panels are listed without SPL, DQL and notes. */
|
|
52
|
+
noDetail?: true;
|
|
53
|
+
}
|
|
54
|
+
export interface DashboardEntry {
|
|
55
|
+
origin: string;
|
|
56
|
+
/** Name of the Dynatrace dashboard file that was written. */
|
|
57
|
+
file: string;
|
|
58
|
+
conversion: ReportBoard;
|
|
59
|
+
}
|
|
60
|
+
/** Characters of one query (or search) a report shows; the rest is in the file it names. */
|
|
61
|
+
export declare const MAX_SHOWN = 20000;
|
|
62
|
+
/** The text as a report shows it: at most MAX_SHOWN characters, then a line saying where the rest is. */
|
|
63
|
+
export declare function shown(text: string, where: string): string;
|
|
64
|
+
/** Notes of one search a report lists; a search can have up to 10,001. */
|
|
65
|
+
export declare const MAX_NOTES_SHOWN = 200;
|
|
66
|
+
/** Characters of detail one search adds to a report. */
|
|
67
|
+
export declare function detailSize(e: ReportEntry): number;
|
|
68
|
+
/** Lists the search without its detail. */
|
|
69
|
+
export declare function dropDetail(e: ReportEntry): void;
|
|
70
|
+
/** Characters of detail one dashboard adds to a report. */
|
|
71
|
+
export declare function boardDetailSize(b: ReportBoard): number;
|
|
72
|
+
/** Lists the dashboard's panels without their detail. */
|
|
73
|
+
export declare function dropBoardDetail(b: ReportBoard): void;
|
|
74
|
+
/** Keeps of a translation only what the report shows. */
|
|
75
|
+
export declare function reportResult(result: TranslateResult, where: string): ReportResult;
|
|
76
|
+
/** Keeps of a dashboard conversion only what the report shows. */
|
|
77
|
+
export declare function reportBoard(c: DashboardConversion, file: string, origin: string): ReportBoard;
|
|
78
|
+
export declare const OUTCOME_WORD: Record<TileOutcome, string>;
|
|
79
|
+
export declare const CONFIDENCE_WORD: Record<Confidence, string>;
|
|
80
|
+
export declare function summary(entries: readonly ReportEntry[]): Record<Confidence, number>;
|
|
81
|
+
/** Replaces quoted values, IPv4 addresses and e-mail addresses with same-length placeholders. */
|
|
82
|
+
export declare function redact(text: string): string;
|
|
83
|
+
export interface ReportOptions {
|
|
84
|
+
redact: boolean;
|
|
85
|
+
/** Set when the run stopped early: why, in one sentence. */
|
|
86
|
+
cutShort?: string;
|
|
87
|
+
}
|
|
88
|
+
export declare function jsonReport(entries: readonly ReportEntry[], generated: string, opts: ReportOptions, dashboards?: readonly DashboardEntry[]): string;
|
|
89
|
+
/** Text for the HTML report: escaped, and without control characters other than tab and newline. */
|
|
90
|
+
export declare function escapeHtml(s: string): string;
|
|
91
|
+
/**
|
|
92
|
+
* A single self-contained HTML file. It contains no scripts at all and a CSP that forbids them, so
|
|
93
|
+
* nothing in a translated search can execute when the report is opened.
|
|
94
|
+
*/
|
|
95
|
+
export declare function htmlReport(entries: readonly ReportEntry[], generated: string, opts: ReportOptions, dashboards?: readonly DashboardEntry[]): string;
|
package/dist/report.js
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/** Characters of one query (or search) a report shows; the rest is in the file it names. */
|
|
2
|
+
export const MAX_SHOWN = 20_000;
|
|
3
|
+
/** The text as a report shows it: at most MAX_SHOWN characters, then a line saying where the rest is. */
|
|
4
|
+
export function shown(text, where) {
|
|
5
|
+
if (text.length <= MAX_SHOWN)
|
|
6
|
+
return text;
|
|
7
|
+
return `${text.slice(0, MAX_SHOWN)}\n… ${text.length - MAX_SHOWN} more characters; the full text is in ${where}.`;
|
|
8
|
+
}
|
|
9
|
+
/** Notes of one search a report lists; a search can have up to 10,001. */
|
|
10
|
+
export const MAX_NOTES_SHOWN = 200;
|
|
11
|
+
/** Characters of detail one search adds to a report. */
|
|
12
|
+
export function detailSize(e) {
|
|
13
|
+
let n = e.spl.length + e.result.dql.length;
|
|
14
|
+
for (const d of e.result.diagnostics)
|
|
15
|
+
n += d.message.length + 60;
|
|
16
|
+
return n;
|
|
17
|
+
}
|
|
18
|
+
/** Lists the search without its detail. */
|
|
19
|
+
export function dropDetail(e) {
|
|
20
|
+
e.spl = '';
|
|
21
|
+
const { moreNotes: _dropped, ...rest } = e.result;
|
|
22
|
+
e.result = { ...rest, dql: '', diagnostics: [] };
|
|
23
|
+
e.noDetail = true;
|
|
24
|
+
}
|
|
25
|
+
/** Characters of detail one dashboard adds to a report. */
|
|
26
|
+
export function boardDetailSize(b) {
|
|
27
|
+
let n = 0;
|
|
28
|
+
for (const t of b.tiles)
|
|
29
|
+
n += (t.spl?.length ?? 0) + (t.result?.dql.length ?? 0) + t.notes.reduce((a, x) => a + x.length, 0);
|
|
30
|
+
return n;
|
|
31
|
+
}
|
|
32
|
+
/** Lists the dashboard's panels without their detail. */
|
|
33
|
+
export function dropBoardDetail(b) {
|
|
34
|
+
b.tiles = b.tiles.map((t) => {
|
|
35
|
+
const tile = { title: t.title, outcome: t.outcome, notes: [] };
|
|
36
|
+
if (t.visualization !== undefined)
|
|
37
|
+
tile.visualization = t.visualization;
|
|
38
|
+
return tile;
|
|
39
|
+
});
|
|
40
|
+
b.noDetail = true;
|
|
41
|
+
}
|
|
42
|
+
/** The sentence a report shows when its budget was reached. */
|
|
43
|
+
function withoutDetail(entries, dashboards) {
|
|
44
|
+
const searches = entries.filter((e) => e.noDetail).length;
|
|
45
|
+
const boards = dashboards.filter((d) => d.conversion.noDetail).length;
|
|
46
|
+
if (searches === 0 && boards === 0)
|
|
47
|
+
return undefined;
|
|
48
|
+
return `The report reached its size limit: ${searches} search(es) and ${boards} dashboard(s) are listed without detail. Their files hold everything.`;
|
|
49
|
+
}
|
|
50
|
+
/** Keeps of a translation only what the report shows. */
|
|
51
|
+
export function reportResult(result, where) {
|
|
52
|
+
const out = {
|
|
53
|
+
dql: shown(result.dql, where),
|
|
54
|
+
confidence: result.confidence,
|
|
55
|
+
score: result.score,
|
|
56
|
+
diagnostics: result.diagnostics.slice(0, MAX_NOTES_SHOWN),
|
|
57
|
+
attention: result.diagnostics.filter((d) => d.severity !== 'info').length,
|
|
58
|
+
};
|
|
59
|
+
if (result.diagnostics.length > MAX_NOTES_SHOWN)
|
|
60
|
+
out.moreNotes = result.diagnostics.length - MAX_NOTES_SHOWN;
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/** Keeps of a dashboard conversion only what the report shows. */
|
|
64
|
+
export function reportBoard(c, file, origin) {
|
|
65
|
+
return {
|
|
66
|
+
title: c.title,
|
|
67
|
+
format: c.format,
|
|
68
|
+
counts: c.counts,
|
|
69
|
+
notes: c.notes,
|
|
70
|
+
variables: c.variables.map((v) => ({ key: v.key, token: v.token, type: v.type, notes: v.notes })),
|
|
71
|
+
tiles: c.tiles.map((t) => {
|
|
72
|
+
const tile = { title: t.title, outcome: t.outcome, notes: t.notes };
|
|
73
|
+
if (t.visualization !== undefined)
|
|
74
|
+
tile.visualization = t.visualization;
|
|
75
|
+
if (t.spl !== undefined)
|
|
76
|
+
tile.spl = shown(t.spl, origin);
|
|
77
|
+
if (t.result)
|
|
78
|
+
tile.result = { confidence: t.result.confidence, dql: shown(t.result.dql, file) };
|
|
79
|
+
return tile;
|
|
80
|
+
}),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export const OUTCOME_WORD = {
|
|
84
|
+
live: 'Converted',
|
|
85
|
+
manual: 'Needs manual work',
|
|
86
|
+
text: 'Text',
|
|
87
|
+
};
|
|
88
|
+
export const CONFIDENCE_WORD = {
|
|
89
|
+
high: 'Exact',
|
|
90
|
+
review: 'Needs review',
|
|
91
|
+
low: 'Incomplete',
|
|
92
|
+
none: 'Not translated',
|
|
93
|
+
};
|
|
94
|
+
const ORDER = ['none', 'low', 'review', 'high'];
|
|
95
|
+
export function summary(entries) {
|
|
96
|
+
const s = { high: 0, review: 0, low: 0, none: 0 };
|
|
97
|
+
for (const e of entries)
|
|
98
|
+
s[e.result.confidence]++;
|
|
99
|
+
return s;
|
|
100
|
+
}
|
|
101
|
+
/** Replaces quoted values, IPv4 addresses and e-mail addresses with same-length placeholders. */
|
|
102
|
+
export function redact(text) {
|
|
103
|
+
return redactQuoted(text)
|
|
104
|
+
.replace(/\b\d{1,3}(\.\d{1,3}){3}\b/g, (m) => m.replace(/\d/g, '0'))
|
|
105
|
+
.replace(/\b[A-Za-z0-9._%+-]{1,64}@[A-Za-z0-9-]{1,63}(?:\.[A-Za-z0-9-]{1,63}){1,8}\b/g, (m) => 'x'.repeat(m.length));
|
|
106
|
+
}
|
|
107
|
+
const MAX_QUOTED = 4000;
|
|
108
|
+
/**
|
|
109
|
+
* Replaces the inside of every double-quoted string of at most MAX_QUOTED characters or escape
|
|
110
|
+
* pairs with "x"s — what `/"((?:[^"\\]|\\.){0,4000})"/g` matches, in linear time: where the string
|
|
111
|
+
* that starts at each position would end, and how long it is, is computed once from the right, so
|
|
112
|
+
* text full of escaped quotes is not rescanned from every quote (ADR-029).
|
|
113
|
+
*/
|
|
114
|
+
function redactQuoted(text) {
|
|
115
|
+
const n = text.length;
|
|
116
|
+
// end[i]: index of the closing quote of a string body starting at i, or -1; units[i]: its length.
|
|
117
|
+
const end = new Int32Array(n + 2).fill(-1);
|
|
118
|
+
const units = new Int32Array(n + 2);
|
|
119
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
120
|
+
const c = text[i];
|
|
121
|
+
if (c === '"') {
|
|
122
|
+
end[i] = i;
|
|
123
|
+
}
|
|
124
|
+
else if (c === '\\') {
|
|
125
|
+
const next = text[i + 1];
|
|
126
|
+
if (next !== undefined && !/[\n\r\u2028\u2029]/.test(next)) {
|
|
127
|
+
end[i] = end[i + 2];
|
|
128
|
+
units[i] = units[i + 2] + 1;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
end[i] = end[i + 1];
|
|
133
|
+
units[i] = units[i + 1] + 1;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
let out = '';
|
|
137
|
+
let copied = 0;
|
|
138
|
+
for (let p = 0; p < n; p++) {
|
|
139
|
+
if (text[p] !== '"')
|
|
140
|
+
continue;
|
|
141
|
+
const close = end[p + 1];
|
|
142
|
+
if (close === -1 || units[p + 1] > MAX_QUOTED)
|
|
143
|
+
continue;
|
|
144
|
+
out += `${text.slice(copied, p + 1)}${'x'.repeat(close - p - 1)}"`;
|
|
145
|
+
copied = close + 1;
|
|
146
|
+
p = close;
|
|
147
|
+
}
|
|
148
|
+
return out + text.slice(copied);
|
|
149
|
+
}
|
|
150
|
+
export function jsonReport(entries, generated, opts, dashboards = []) {
|
|
151
|
+
const r = (t) => (opts.redact ? redact(t) : t);
|
|
152
|
+
const notesOf = (result) => result.diagnostics.map((d) => ({ code: d.code, severity: d.severity, stage: d.stageIndex, message: r(d.message) }));
|
|
153
|
+
const body = {
|
|
154
|
+
generated,
|
|
155
|
+
...(opts.cutShort !== undefined ? { cutShort: opts.cutShort } : {}),
|
|
156
|
+
...(withoutDetail(entries, dashboards) !== undefined ? { withoutDetail: withoutDetail(entries, dashboards) } : {}),
|
|
157
|
+
summary: summary(entries),
|
|
158
|
+
searches: entries.map((e) => ({
|
|
159
|
+
name: e.name,
|
|
160
|
+
origin: e.origin,
|
|
161
|
+
file: e.file,
|
|
162
|
+
confidence: e.result.confidence,
|
|
163
|
+
score: e.result.score,
|
|
164
|
+
...(e.earliest !== undefined ? { earliest: e.earliest } : {}),
|
|
165
|
+
...(e.latest !== undefined ? { latest: e.latest } : {}),
|
|
166
|
+
...(e.schedule !== undefined ? { schedule: e.schedule } : {}),
|
|
167
|
+
...(e.disabled ? { disabled: true } : {}),
|
|
168
|
+
...(e.noDetail ? { detail: false } : { spl: r(e.spl), dql: r(e.result.dql), notes: notesOf(e.result) }),
|
|
169
|
+
...(e.result.moreNotes !== undefined ? { moreNotes: e.result.moreNotes } : {}),
|
|
170
|
+
})),
|
|
171
|
+
};
|
|
172
|
+
if (dashboards.length > 0) {
|
|
173
|
+
body.dashboards = dashboards.map((d) => ({
|
|
174
|
+
title: d.conversion.title,
|
|
175
|
+
origin: d.origin,
|
|
176
|
+
file: d.file,
|
|
177
|
+
format: d.conversion.format,
|
|
178
|
+
tiles: d.conversion.counts,
|
|
179
|
+
notes: d.conversion.notes.map(r),
|
|
180
|
+
variables: d.conversion.variables.map((v) => ({ key: v.key, token: v.token, type: v.type, notes: v.notes.map(r) })),
|
|
181
|
+
panels: d.conversion.tiles.map((t) => ({
|
|
182
|
+
title: r(t.title),
|
|
183
|
+
outcome: t.outcome,
|
|
184
|
+
...(t.visualization !== undefined ? { visualization: t.visualization } : {}),
|
|
185
|
+
...(t.spl !== undefined ? { spl: r(t.spl) } : {}),
|
|
186
|
+
...(t.result ? { confidence: t.result.confidence, dql: r(t.result.dql) } : {}),
|
|
187
|
+
notes: t.notes.map(r),
|
|
188
|
+
})),
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
return `${JSON.stringify(body, null, 2)}\n`;
|
|
192
|
+
}
|
|
193
|
+
const ESC = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
|
|
194
|
+
/** Text for the HTML report: escaped, and without control characters other than tab and newline. */
|
|
195
|
+
export function escapeHtml(s) {
|
|
196
|
+
return s.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g, '').replace(/[&<>"']/g, (c) => ESC[c] ?? c);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* A single self-contained HTML file. It contains no scripts at all and a CSP that forbids them, so
|
|
200
|
+
* nothing in a translated search can execute when the report is opened.
|
|
201
|
+
*/
|
|
202
|
+
export function htmlReport(entries, generated, opts, dashboards = []) {
|
|
203
|
+
const r = (t) => escapeHtml(opts.redact ? redact(t) : t);
|
|
204
|
+
const saved = (e) => {
|
|
205
|
+
const parts = [];
|
|
206
|
+
if (e.disabled)
|
|
207
|
+
parts.push('Switched off in Splunk');
|
|
208
|
+
if (e.earliest !== undefined || e.latest !== undefined)
|
|
209
|
+
parts.push(`Time range ${r(e.earliest ?? '…')} to ${r(e.latest ?? 'now')}`);
|
|
210
|
+
if (e.schedule !== undefined)
|
|
211
|
+
parts.push(`Schedule ${r(e.schedule)}`);
|
|
212
|
+
return parts.length > 0 ? `<p class="o">${parts.join(' · ')}</p>` : '';
|
|
213
|
+
};
|
|
214
|
+
const boards = dashboards
|
|
215
|
+
.map((d, i) => {
|
|
216
|
+
const c = d.conversion;
|
|
217
|
+
const tiles = c.tiles
|
|
218
|
+
.map((t) => `<tr class="t-${t.outcome}"><td>${r(t.title || '(no title)')}</td><td>${OUTCOME_WORD[t.outcome]}</td><td>${t.visualization ? escapeHtml(t.visualization) : ''}</td><td>${t.notes.length > 0 ? `<ul>${t.notes.map((n) => `<li>${r(n)}</li>`).join('')}</ul>` : ''}</td></tr>`)
|
|
219
|
+
.join('');
|
|
220
|
+
const vars = c.variables.length > 0
|
|
221
|
+
? `<p class="o">Variables: ${c.variables.map((v) => `<code>$${escapeHtml(v.key)}</code> (${v.type}, from <code>$${r(v.token)}$</code>)`).join(', ')}</p>`
|
|
222
|
+
: '';
|
|
223
|
+
const notes = [...c.notes, ...c.variables.flatMap((v) => v.notes.map((n) => `$${v.key}: ${n}`))];
|
|
224
|
+
return `<section id="d${i}" class="${c.counts.manual > 0 ? 'review' : 'high'}">
|
|
225
|
+
<h2>${r(c.title)} <span class="c">${c.counts.live} converted · ${c.counts.manual} need manual work · ${c.counts.text} text</span></h2>
|
|
226
|
+
<p class="o">${r(d.origin)} → <code>${escapeHtml(d.file)}</code></p>
|
|
227
|
+
${vars}
|
|
228
|
+
${notes.length > 0 ? `<ul>${notes.map((n) => `<li class="warning"><span aria-hidden="true">▲</span> ${r(n)}</li>`).join('')}</ul>` : ''}
|
|
229
|
+
<table class="tiles"><thead><tr><th>Panel</th><th>Result</th><th>Shown as</th><th>To check</th></tr></thead><tbody>${tiles}</tbody></table>
|
|
230
|
+
</section>`;
|
|
231
|
+
})
|
|
232
|
+
.join('\n');
|
|
233
|
+
const boardTotals = dashboards.reduce((a, d) => ({ live: a.live + d.conversion.counts.live, manual: a.manual + d.conversion.counts.manual, text: a.text + d.conversion.counts.text }), { live: 0, manual: 0, text: 0 });
|
|
234
|
+
const s = summary(entries);
|
|
235
|
+
const sorted = [...entries].sort((a, b) => ORDER.indexOf(a.result.confidence) - ORDER.indexOf(b.result.confidence) || a.name.localeCompare(b.name));
|
|
236
|
+
const mark = (d) => (d.severity === 'error' ? '■' : d.severity === 'warning' ? '▲' : '●');
|
|
237
|
+
const rows = sorted
|
|
238
|
+
.map((e, i) => {
|
|
239
|
+
return `<section id="s${i}" class="${e.result.confidence}">
|
|
240
|
+
<h2>${r(e.name)} <span class="c">${CONFIDENCE_WORD[e.result.confidence]}</span></h2>
|
|
241
|
+
<p class="o">${r(e.origin)}</p>
|
|
242
|
+
${saved(e)}
|
|
243
|
+
${e.noDetail ? `<p class="o">Listed without detail; the full DQL is in <code>${escapeHtml(e.file)}</code>.</p>` : `<div class="g"><div><h3>Splunk SPL</h3><pre>${r(e.spl)}</pre></div><div><h3>Dynatrace DQL</h3><pre>${r(e.result.dql)}</pre></div></div>`}
|
|
244
|
+
${e.result.diagnostics.length > 0 ? `<ul>${e.result.diagnostics.map((d) => `<li class="${d.severity}"><span aria-hidden="true">${mark(d)}</span> <b>${d.code}</b> stage ${d.stageIndex + 1}: ${r(d.message)}</li>`).join('')}${e.result.moreNotes !== undefined ? `<li class="info">… and ${e.result.moreNotes} more notes</li>` : ''}</ul>` : ''}
|
|
245
|
+
</section>`;
|
|
246
|
+
})
|
|
247
|
+
.join('\n');
|
|
248
|
+
const index = sorted
|
|
249
|
+
.map((e, i) => `<tr><td><a href="#s${i}">${r(e.name)}</a></td><td>${CONFIDENCE_WORD[e.result.confidence]}</td><td>${e.result.attention}</td></tr>`)
|
|
250
|
+
.join('');
|
|
251
|
+
return `<!doctype html>
|
|
252
|
+
<html lang="en"><head><meta charset="utf-8">
|
|
253
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; img-src 'none'; form-action 'none'; base-uri 'none'">
|
|
254
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
255
|
+
<meta name="referrer" content="no-referrer">
|
|
256
|
+
<title>spl2dql report</title>
|
|
257
|
+
<style>
|
|
258
|
+
:root{--canvas:#EEF1F0;--surface:#FBFCFB;--ink:#17232B;--muted:#51616B;--line:#CBD3D1;--exact:#0B6E78;--check:#9A5B00;--blocked:#A8214F}
|
|
259
|
+
@media (prefers-color-scheme:dark){:root{--canvas:#1A2227;--surface:#222C32;--ink:#E6ECEA;--muted:#9DAAB0;--line:#37444B;--exact:#4FB8C2;--check:#E0A64A;--blocked:#F07A9E}}
|
|
260
|
+
body{margin:0;padding:24px 16px;background:var(--canvas);color:var(--ink);font:15px/1.5 system-ui,sans-serif}
|
|
261
|
+
main{max-width:1100px;margin:0 auto}h1{font-size:24px}h2{font-size:18px;margin:0 0 4px}h3{font-size:13px;color:var(--muted);margin:0 0 4px;font-weight:600}
|
|
262
|
+
table{border-collapse:collapse;width:100%;background:var(--surface)}td,th{border-bottom:1px solid var(--line);padding:6px 8px;text-align:left}
|
|
263
|
+
section{background:var(--surface);border-left:4px solid var(--line);padding:16px;margin:16px 0}
|
|
264
|
+
section.high{border-color:var(--exact)}section.review{border-color:var(--check)}section.low,section.none{border-color:var(--blocked)}
|
|
265
|
+
.c{font-size:13px;font-weight:600;color:var(--muted)}.o{color:var(--muted);font-size:13px;margin:0 0 8px}
|
|
266
|
+
.g{display:grid;grid-template-columns:1fr 1fr;gap:16px}@media (max-width:760px){.g{grid-template-columns:1fr}}
|
|
267
|
+
pre{white-space:pre-wrap;word-break:break-word;background:var(--canvas);padding:8px;margin:0;font:13px/1.55 ui-monospace,monospace}
|
|
268
|
+
li.error span{color:var(--blocked)}li.warning span{color:var(--check)}li.info span{color:var(--muted)}ul{padding-left:18px;margin:8px 0 0}
|
|
269
|
+
code{font:13px/1.4 ui-monospace,monospace}table.tiles{margin-top:12px;background:none}table.tiles td{vertical-align:top}table.tiles ul{margin:0}
|
|
270
|
+
tr.t-manual td:nth-child(2){color:var(--blocked);font-weight:600}.cut{border-left:4px solid var(--blocked);padding:8px 12px;background:var(--surface)}tr.t-live td:nth-child(2){color:var(--exact);font-weight:600}
|
|
271
|
+
</style></head><body><main>
|
|
272
|
+
<h1>spl2dql report</h1>
|
|
273
|
+
<p>${entries.length} searches · Exact ${s.high} · Needs review ${s.review} · Incomplete ${s.low} · Not translated ${s.none}${dashboards.length > 0
|
|
274
|
+
? `<br>${dashboards.length} dashboards · ${boardTotals.live} panels converted · ${boardTotals.manual} need manual work · ${boardTotals.text} text`
|
|
275
|
+
: ''}<br><span class="c">Generated ${escapeHtml(generated)}${opts.redact ? ' · values redacted' : ''}</span></p>
|
|
276
|
+
${opts.cutShort !== undefined ? `<p class="cut"><b>This run was cut short.</b> ${escapeHtml(opts.cutShort)}</p>` : ''}
|
|
277
|
+
${withoutDetail(entries, dashboards) !== undefined ? `<p class="cut">${escapeHtml(withoutDetail(entries, dashboards))}</p>` : ''}
|
|
278
|
+
${dashboards.length > 0 ? `<h2>Dashboards</h2>\n${boards}` : ''}
|
|
279
|
+
${entries.length > 0 ? `${dashboards.length > 0 ? '<h2>Searches</h2>\n' : ''}<table><thead><tr><th>Search</th><th>Confidence</th><th>Notes</th></tr></thead><tbody>${index}</tbody></table>` : ''}
|
|
280
|
+
${rows}
|
|
281
|
+
<p class="c">Made with spl2dql, an independent open-source project that is not affiliated with, endorsed by or supported by Splunk Inc., Cisco or Dynatrace. Splunk, SPL, Dynatrace and DQL are trademarks of their respective owners. Provided without warranty; check every translated query before relying on it.</p>
|
|
282
|
+
</main></body></html>
|
|
283
|
+
`;
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Creates the output directory (and parents) and returns its real path. */
|
|
2
|
+
export declare function prepareOutDir(dir: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* Writes `name` inside `dir` only: refuses paths that leave the directory and refuses to write
|
|
5
|
+
* through an existing symbolic link (which could point anywhere).
|
|
6
|
+
*/
|
|
7
|
+
export declare function writeInside(dir: string, name: string, content: string, afterOpen?: () => void): string;
|
package/dist/safe-fs.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { closeSync, constants, existsSync, fstatSync, lstatSync, mkdirSync, openSync, realpathSync, unlinkSync, writeSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
3
|
+
/** Creates the output directory (and parents) and returns its real path. */
|
|
4
|
+
export function prepareOutDir(dir) {
|
|
5
|
+
mkdirSync(dir, { recursive: true });
|
|
6
|
+
return realpathSync(dir);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Writes `name` inside `dir` only: refuses paths that leave the directory and refuses to write
|
|
10
|
+
* through an existing symbolic link (which could point anywhere).
|
|
11
|
+
*/
|
|
12
|
+
export function writeInside(dir, name, content, afterOpen) {
|
|
13
|
+
const target = resolve(dir, name);
|
|
14
|
+
const rel = relative(dir, target);
|
|
15
|
+
if (rel === '' || rel.startsWith('..') || isAbsolute(rel))
|
|
16
|
+
throw new Error(`Refusing to write outside ${dir}: ${name}`);
|
|
17
|
+
if (dirname(target) !== dir) {
|
|
18
|
+
// A folder on the way may be a symbolic link that leads out of the output folder: check the
|
|
19
|
+
// deepest folder that exists before creating anything, and the real parent afterwards.
|
|
20
|
+
let existing = dirname(target);
|
|
21
|
+
while (!existsSync(existing) && existing !== dir)
|
|
22
|
+
existing = dirname(existing);
|
|
23
|
+
insideOrRefuse(dir, existing, name);
|
|
24
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
25
|
+
insideOrRefuse(dir, dirname(target), name);
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const st = lstatSync(target);
|
|
29
|
+
if (st.isSymbolicLink())
|
|
30
|
+
throw new Error(`Refusing to write through the symbolic link ${target}`);
|
|
31
|
+
if (!st.isFile())
|
|
32
|
+
throw new Error(`Refusing to replace ${target}: it is not a regular file`);
|
|
33
|
+
// Remove the old entry (this also detaches hard links) and create a fresh file below.
|
|
34
|
+
unlinkSync(target);
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
if (e.code !== 'ENOENT')
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
// O_EXCL fails if anything reappeared at this path in the meantime; O_NOFOLLOW never follows a link.
|
|
41
|
+
const fd = openSync(target, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o644);
|
|
42
|
+
try {
|
|
43
|
+
// `afterOpen` lets a test change the folders between opening and checking.
|
|
44
|
+
afterOpen?.();
|
|
45
|
+
// Before any content is written: the file that was opened must be the one at the real path
|
|
46
|
+
// inside the output folder. A program that swapped a folder in the meantime gets an empty file
|
|
47
|
+
// at most, never the content (ADR-029).
|
|
48
|
+
if (!sameFileInside(dir, target, fd)) {
|
|
49
|
+
throw new Error(`Refusing to write ${name}: a folder on its way changed while the file was being created; nothing was written.`);
|
|
50
|
+
}
|
|
51
|
+
writeSync(fd, content, null, 'utf8');
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
closeSync(fd);
|
|
55
|
+
}
|
|
56
|
+
return target;
|
|
57
|
+
}
|
|
58
|
+
/** `folder`'s real path must be the output folder's real path or below it. */
|
|
59
|
+
function insideOrRefuse(dir, folder, name) {
|
|
60
|
+
const real = realpathSync(folder);
|
|
61
|
+
const rel = relative(realpathSync(dir), real);
|
|
62
|
+
if (rel.startsWith('..') || isAbsolute(rel)) {
|
|
63
|
+
throw new Error(`Refusing to write ${name}: a folder on its way is a symbolic link that leads outside the output folder ${dir}.`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** The open file `fd` is the regular file at `target`'s real location inside `dir`. */
|
|
67
|
+
function sameFileInside(dir, target, fd) {
|
|
68
|
+
try {
|
|
69
|
+
const parent = realpathSync(dirname(target));
|
|
70
|
+
const rel = relative(realpathSync(dir), parent);
|
|
71
|
+
if (rel.startsWith('..') || isAbsolute(rel))
|
|
72
|
+
return false;
|
|
73
|
+
const opened = fstatSync(fd);
|
|
74
|
+
const there = lstatSync(join(parent, basename(target)));
|
|
75
|
+
return there.isFile() && opened.isFile() && there.dev === opened.dev && there.ino === opened.ino;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=safe-fs.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `spl2dql serve`: serves the built web app on the loopback interface. The app translates in the
|
|
3
|
+
* browser; this server has no API, reads no credentials and makes no outbound connections. It only
|
|
4
|
+
* hands out a fixed set of files read once at start-up (docs/spec/cli.md → serve).
|
|
5
|
+
*/
|
|
6
|
+
export interface ServeOptions {
|
|
7
|
+
port: number;
|
|
8
|
+
host: string;
|
|
9
|
+
/** Directory with the built web app; defaults to ../../web next to this file. */
|
|
10
|
+
webDir?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ServeHandle {
|
|
13
|
+
url: string;
|
|
14
|
+
close(): Promise<void>;
|
|
15
|
+
closed: Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export declare class ServeError extends Error {
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The policy when the web folder has no `_headers` file (an unbuilt checkout): the same rules the
|
|
21
|
+
* build writes (apps/web/vite.config.ts), so the local server never sends less than the hosted page.
|
|
22
|
+
*/
|
|
23
|
+
export declare const DEFAULT_HEADERS = "/*\n Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'none'; worker-src 'self'; manifest-src 'self'; object-src 'none'; base-uri 'none'; form-action 'none'; require-trusted-types-for 'script'; trusted-types spl2dql; frame-ancestors 'none'\n X-Content-Type-Options: nosniff\n X-Frame-Options: DENY\n Referrer-Policy: no-referrer\n Cross-Origin-Opener-Policy: same-origin\n Cross-Origin-Resource-Policy: same-origin\n Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=(), usb=()\n/sw.js\n ! Content-Security-Policy\n Content-Security-Policy: default-src 'none'; connect-src 'self'; frame-ancestors 'none'\n/social.png\n ! Cross-Origin-Resource-Policy\n Cross-Origin-Resource-Policy: cross-origin\n";
|
|
24
|
+
/** One rule of a `_headers` file: a path pattern and its lines in order. */
|
|
25
|
+
interface HeaderRule {
|
|
26
|
+
pattern: string;
|
|
27
|
+
lines: ({
|
|
28
|
+
set: string;
|
|
29
|
+
value: string;
|
|
30
|
+
} | {
|
|
31
|
+
remove: string;
|
|
32
|
+
})[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Reads the subset of the `_headers` format the build writes: a path (`/sw.js`) or a folder
|
|
36
|
+
* pattern (`/assets/*`, `/*`) at the start of a line, then indented `Name: value` lines and
|
|
37
|
+
* `! Name` lines that remove a header an earlier rule set. Comments and blank lines are skipped.
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseHeadersFile(text: string): HeaderRule[];
|
|
40
|
+
/**
|
|
41
|
+
* The headers a path gets: every matching rule in order. The hosted page's caching rules are not
|
|
42
|
+
* applied: a loopback server sends `Cache-Control: no-store` for everything (docs/spec/cli.md).
|
|
43
|
+
*/
|
|
44
|
+
export declare function headersFor(rules: readonly HeaderRule[], path: string): Record<string, string>;
|
|
45
|
+
/** Starts the local web app server. Loopback only; GET and HEAD only; own Host names only. */
|
|
46
|
+
export declare function startServer(options: ServeOptions): Promise<ServeHandle>;
|
|
47
|
+
export {};
|