@preventive/triage 1.0.0-alpha.78 → 1.0.0-alpha.79
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/common/managed/finding-values.d.ts +2 -2
- package/common/managed/finding-values.js +128 -34
- package/out/activity.js +2 -2
- package/out/{chunk-NCJQDKPK.js → chunk-IIJK4F4U.js} +1 -1
- package/out/chunk-NTJJIEHS.js +259 -0
- package/out/{chunk-I4YPK32I.js → chunk-V43XH2JQ.js} +1 -1
- package/out/chunk-Z54AXVCK.js +3 -0
- package/out/client-managed.js +3 -3
- package/out/compare.js +14 -14
- package/out/dialogs.js +37 -37
- package/out/index.html +2 -2
- package/out/scan.js +1 -1
- package/out/view.css +1 -1
- package/out/view.js +8 -8
- package/package.json +1 -1
- package/server-managed/dependency-review-comments.ts +17 -10
- package/server-managed/http.ts +70 -8
- package/server-managed/npm-kept.ts +11 -1
- package/server-managed/team-reports.ts +25 -15
- package/out/chunk-BGLN56X6.js +0 -3
- package/out/chunk-O2NYWLX3.js +0 -259
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export function
|
|
2
|
-
export function
|
|
1
|
+
export function packTeamReports<T extends { repo?: unknown; data: unknown }>(reports: readonly T[]): { reports: T[]; values: Record<string, unknown[]> | null; keys: string[][] | null }
|
|
2
|
+
export function unpackTeamReport<T>(report: T, sent?: { values?: unknown; keys?: unknown }): T | null
|
|
@@ -1,44 +1,138 @@
|
|
|
1
|
-
// A
|
|
2
|
-
// findings
|
|
3
|
-
//
|
|
4
|
-
// (server-managed/team-reports.ts)
|
|
5
|
-
// (client/managed/session.js)
|
|
6
|
-
|
|
1
|
+
// A team's reports tell the same few values over and over across their many
|
|
2
|
+
// findings: their severity, model, type and effort, the files they are in,
|
|
3
|
+
// their packages, repositories and bundles; and each finding tells the same
|
|
4
|
+
// few field names. A team response (server-managed/team-reports.ts) sends
|
|
5
|
+
// each once, read back as it is read (client/managed/session.js):
|
|
6
|
+
//
|
|
7
|
+
// - `values`: by field, the values told of it, the most told first, so that
|
|
8
|
+
// the commonest are a single digit, and each place one is told as its index
|
|
9
|
+
// there. A field is pooled where that sends fewer characters than its
|
|
10
|
+
// values in place, and then every value it is told but null is an index: a
|
|
11
|
+
// report's own `repo`, its data's own fields (but its entries and links)
|
|
12
|
+
// and its findings'.
|
|
13
|
+
// - `keys`: the field names of its findings, by shape, the most told first,
|
|
14
|
+
// and each finding as an array, its shape's index there and then its
|
|
15
|
+
// values in that shape's order. An entry of a report's data that is an
|
|
16
|
+
// array is a group of them; anything in a group that is not a finding is
|
|
17
|
+
// sent as `[-1, it]`.
|
|
7
18
|
|
|
19
|
+
// A report's data's fields holding its entries and links, never pooled.
|
|
20
|
+
const STRUCTURE = new Set(['findings', 'groups', 'links'])
|
|
21
|
+
const NOT_A_FINDING = -1
|
|
22
|
+
|
|
23
|
+
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
8
24
|
const entriesKey = data => Array.isArray(data?.findings) ? 'findings' : Array.isArray(data?.groups) ? 'groups' : null
|
|
25
|
+
const findingsOf = data => { const key = entriesKey(data); return key ? data[key].flat().filter(isObject) : [] }
|
|
26
|
+
// A finding's fields as JSON writes them: those holding a value.
|
|
27
|
+
const fieldsOf = finding => Object.keys(finding).filter(field => finding[field] !== undefined)
|
|
9
28
|
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const copy = { ...finding }
|
|
22
|
-
for (const field of FIELDS) if (finding[field] != null) copy[field] = indexOf(finding[field])
|
|
23
|
-
return copy
|
|
29
|
+
// Values as they are counted, each kept by itself: a string as it is, and
|
|
30
|
+
// anything else by its JSON. The most told first, then the first told.
|
|
31
|
+
function counter() {
|
|
32
|
+
const others = new Map(), strings = new Map()
|
|
33
|
+
let seen = 0
|
|
34
|
+
const entryOf = (value, create) => {
|
|
35
|
+
const map = typeof value === 'string' ? strings : others
|
|
36
|
+
const key = typeof value === 'string' ? value : JSON.stringify(value)
|
|
37
|
+
let entry = map.get(key)
|
|
38
|
+
if (!entry && create) map.set(key, entry = { value, count: 0, first: seen++, size: typeof value === 'string' ? JSON.stringify(value).length : key.length, index: -1 })
|
|
39
|
+
return entry
|
|
24
40
|
}
|
|
25
41
|
return {
|
|
26
|
-
|
|
27
|
-
index(
|
|
28
|
-
|
|
29
|
-
|
|
42
|
+
count(value) { entryOf(value, true).count++ },
|
|
43
|
+
index: value => entryOf(value, false).index,
|
|
44
|
+
ranked() {
|
|
45
|
+
const entries = [...strings.values(), ...others.values()].toSorted((a, b) => b.count - a.count || a.first - b.first)
|
|
46
|
+
for (const [index, entry] of entries.entries()) entry.index = index
|
|
47
|
+
return entries
|
|
30
48
|
},
|
|
31
49
|
}
|
|
32
50
|
}
|
|
33
51
|
|
|
34
|
-
// A
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
// A field set as JSON.parse sets it: an own field, whatever its name.
|
|
53
|
+
function put(record, field, value) {
|
|
54
|
+
if (field === '__proto__') Object.defineProperty(record, field, { value, enumerable: true, writable: true, configurable: true })
|
|
55
|
+
else record[field] = value
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// `reports` as a team response sends them, `{ id, filename, repo, data, ... }`
|
|
59
|
+
// each: copies, their values pooled in `values` (null where none is) and their
|
|
60
|
+
// findings shaped by `keys` (null where there are none), the reports
|
|
61
|
+
// themselves left as they are.
|
|
62
|
+
export function packTeamReports(reports) {
|
|
63
|
+
const fields = new Map(), shapes = counter()
|
|
64
|
+
const count = (field, value) => {
|
|
65
|
+
if (value == null) return
|
|
66
|
+
let values = fields.get(field)
|
|
67
|
+
if (!values) fields.set(field, values = counter())
|
|
68
|
+
values.count(value)
|
|
69
|
+
}
|
|
70
|
+
for (const report of reports) {
|
|
71
|
+
count('repo', report.repo)
|
|
72
|
+
if (!isObject(report.data)) continue
|
|
73
|
+
for (const field in report.data) if (!STRUCTURE.has(field)) count(field, report.data[field])
|
|
74
|
+
for (const finding of findingsOf(report.data)) {
|
|
75
|
+
const named = fieldsOf(finding)
|
|
76
|
+
shapes.count(named)
|
|
77
|
+
for (const field of named) count(field, finding[field])
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const values = {}
|
|
81
|
+
for (const [field, counted] of fields) {
|
|
82
|
+
const entries = counted.ranked()
|
|
83
|
+
let inline = 0, pooled = JSON.stringify(field).length + 3 + entries.length
|
|
84
|
+
for (const [index, entry] of entries.entries()) { inline += entry.count * entry.size; pooled += entry.size + entry.count * String(index).length }
|
|
85
|
+
if (pooled < inline) put(values, field, entries.map(entry => entry.value))
|
|
86
|
+
else fields.delete(field)
|
|
87
|
+
}
|
|
88
|
+
const keys = shapes.ranked().map(entry => entry.value)
|
|
89
|
+
const sent = (field, value) => value != null && fields.has(field) ? fields.get(field).index(value) : value
|
|
90
|
+
const finding = value => {
|
|
91
|
+
const named = fieldsOf(value)
|
|
92
|
+
return [shapes.index(named), ...named.map(field => sent(field, value[field]))]
|
|
93
|
+
}
|
|
94
|
+
const entry = value => Array.isArray(value) ? value.map(inGroup => isObject(inGroup) ? finding(inGroup) : [NOT_A_FINDING, inGroup])
|
|
95
|
+
: isObject(value) ? finding(value) : value
|
|
96
|
+
return {
|
|
97
|
+
values: fields.size > 0 ? values : null,
|
|
98
|
+
keys: keys.length > 0 ? keys : null,
|
|
99
|
+
reports: reports.map(report => {
|
|
100
|
+
const copy = { ...report }
|
|
101
|
+
if (report.repo != null) copy.repo = sent('repo', report.repo)
|
|
102
|
+
if (!isObject(report.data)) return copy
|
|
103
|
+
copy.data = { ...report.data }
|
|
104
|
+
for (const field in report.data) if (!STRUCTURE.has(field) && fields.has(field)) put(copy.data, field, sent(field, report.data[field]))
|
|
105
|
+
const key = entriesKey(report.data)
|
|
106
|
+
if (key) copy.data[key] = report.data[key].map(entry)
|
|
107
|
+
return copy
|
|
108
|
+
}),
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// A report of a team response, as read, given the response's `values` and
|
|
113
|
+
// `keys`: its findings objects again, their values in place of their index;
|
|
114
|
+
// one sent without either as it is. Null where its findings cannot be read.
|
|
115
|
+
export function unpackTeamReport(report, { values = null, keys = null } = {}) {
|
|
116
|
+
if (!isObject(report)) return report
|
|
117
|
+
const pools = new Map(isObject(values) ? Object.entries(values).filter(([, list]) => Array.isArray(list)) : [])
|
|
118
|
+
const shaped = Array.isArray(keys)
|
|
119
|
+
let readable = true
|
|
120
|
+
const value = (field, sent) => Number.isInteger(sent) && pools.has(field) ? pools.get(field)[sent] : sent
|
|
121
|
+
const expanded = record => { for (const [field, list] of pools) if (Number.isInteger(record[field])) put(record, field, list[record[field]]); return record }
|
|
122
|
+
const tuple = sent => {
|
|
123
|
+
const named = keys[sent[0]]
|
|
124
|
+
if (!Array.isArray(named) || named.length !== sent.length - 1) { readable = false; return null }
|
|
125
|
+
const read = {}
|
|
126
|
+
for (const [index, field] of named.entries()) put(read, field, value(field, sent[index + 1]))
|
|
127
|
+
return read
|
|
128
|
+
}
|
|
129
|
+
const isTuple = sent => shaped && Array.isArray(sent) && Number.isInteger(sent[0])
|
|
130
|
+
const inGroup = sent => isTuple(sent) ? sent[0] === NOT_A_FINDING ? sent[1] : tuple(sent) : isObject(sent) ? expanded(sent) : sent
|
|
131
|
+
const entry = sent => Array.isArray(sent) && !isTuple(sent) ? sent.map(inGroup) : inGroup(sent)
|
|
132
|
+
if (report.repo != null) report.repo = value('repo', report.repo)
|
|
133
|
+
if (!isObject(report.data)) return report
|
|
134
|
+
for (const field in report.data) if (!STRUCTURE.has(field) && pools.has(field)) put(report.data, field, value(field, report.data[field]))
|
|
135
|
+
const key = entriesKey(report.data)
|
|
136
|
+
if (key) report.data[key] = report.data[key].map(entry)
|
|
137
|
+
return readable ? report : null
|
|
44
138
|
}
|