@exodus/stasis 1.0.0-beta.15 → 1.0.0-beta.16

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.
Files changed (67) hide show
  1. package/README.md +1 -1
  2. package/bin/stasis.js +19 -6
  3. package/package.json +10 -9
  4. package/src/audit-corrections.js +11 -42
  5. package/src/audit.js +113 -233
  6. package/src/babel.js +39 -122
  7. package/src/bundle-from-lockfile.js +9 -21
  8. package/src/bundle-reader.js +5 -9
  9. package/src/bundle.js +0 -3
  10. package/src/cmd/build.js +50 -166
  11. package/src/cmd/bundle-options.js +110 -167
  12. package/src/cmd/bundle.js +853 -1344
  13. package/src/cmd/diff.js +1 -4
  14. package/src/cmd/github-bundle.js +18 -22
  15. package/src/cmd/output.js +15 -12
  16. package/src/cmd/sbom.js +3 -8
  17. package/src/cmd/tokens.js +10 -23
  18. package/src/define.js +34 -97
  19. package/src/diff.js +72 -128
  20. package/src/esbuild.js +0 -4
  21. package/src/flow.js +10 -25
  22. package/src/installed.js +265 -0
  23. package/src/json-stream.js +4 -9
  24. package/src/loader-mock.js +3 -8
  25. package/src/loader.js +1 -5
  26. package/src/loaders/bash.js +41 -93
  27. package/src/loaders/cargo.js +298 -805
  28. package/src/loaders/foundry.js +109 -285
  29. package/src/loaders/paths.js +13 -13
  30. package/src/loaders/php.js +210 -489
  31. package/src/loaders/rust.js +507 -1430
  32. package/src/loaders/solidity-ownership.js +48 -128
  33. package/src/loaders/solidity.js +39 -122
  34. package/src/loaders/toml.js +7 -17
  35. package/src/lockfile.js +0 -3
  36. package/src/metro-assets.js +9 -33
  37. package/src/metro-resolver.js +20 -47
  38. package/src/metro-transformer.js +0 -5
  39. package/src/metro.js +0 -4
  40. package/src/mock.js +32 -80
  41. package/src/parse.js +2 -5
  42. package/src/prune.js +0 -3
  43. package/src/resolve-fields.js +90 -220
  44. package/src/resolve-node.js +27 -45
  45. package/src/resolve-typescript.js +109 -313
  46. package/src/rollup.js +0 -4
  47. package/src/run-installed.js +10 -0
  48. package/src/sbom.js +52 -128
  49. package/src/scan.js +136 -283
  50. package/src/sixel.js +18 -41
  51. package/src/table.js +14 -35
  52. package/src/validate-notes.d.ts +3 -2
  53. package/src/validate-notes.js +25 -19
  54. package/src/validate.d.ts +38 -11
  55. package/src/validate.js +478 -512
  56. package/src/vfs-bundle/entries.js +40 -57
  57. package/src/vfs-bundle/github.js +77 -121
  58. package/src/vfs-bundle/glob.js +4 -45
  59. package/src/vfs-bundle/lazy.js +27 -56
  60. package/src/vfs-bundle/prisma.js +167 -110
  61. package/src/vfs-bundle/soldeer.js +28 -49
  62. package/src/vfs-bundle/tree.js +295 -318
  63. package/src/vfs-bundle/yarnclean.js +10 -31
  64. package/src/vfs-bundle.js +23 -64
  65. package/src/webpack.js +0 -4
  66. package/src/why.js +75 -231
  67. package/src/installed-commits.js +0 -184
package/src/sixel.js CHANGED
@@ -1,10 +1,6 @@
1
- // Logos for where an advisory comes from, as `stasis audit` may draw them beside it: sixel images, for a
2
- // terminal that draws them, as supported() asks it.
3
-
4
- // Each a sixel image 16 pixels square, prepared once (nothing here converts one): its pixels square (P1 9,
5
- // and raster attributes 1:1), its background left as the terminal has it (P2 1), in 8 colours at most.
6
- // Its edges inside are blended; its outline isn't, as nothing tells a sixel image what it's drawn over, so
7
- // a pixel is drawn where at least half of it is covered.
1
+ // Sixel logos `stasis audit` may draw beside an advisory's source: square pixels (P1 9, raster 1:1), the background
2
+ // left as is (P2 1), 8 colours at most, edges inside blended, and, as nothing tells what it's drawn over, an outline
3
+ // pixel where half is covered.
8
4
 
9
5
  // npm's registry (upstream's `registry` source): simple-icons' npm (16.36.0, CC0-1.0), #CB3837, its
10
6
  // knocked-out n filled white.
@@ -30,9 +26,8 @@ export const OSV = '\x1bP9;1q"1;1;16;16#1;2;55;58;62#2;2;88;13;16#3;2;98;86;86#4
30
26
  '#1???CEF!4MFFB@' +
31
27
  '\x1b\\'
32
28
 
33
- // The three at each size, made as those above are (simple-icons' and triage's paths, at least half a
34
- // pixel covered for a pixel to be drawn, in 8 colours at most): 16 pixels for the cells most terminals
35
- // draw sixel images over, more for larger ones, as a Retina screen's are in iTerm2, two pixels a point.
29
+ // The three at each size, made as those above are: 16 pixels for most terminals' cells, more for larger ones, as a
30
+ // Retina screen's are in iTerm2, two pixels a point.
36
31
  const LOGOS = {
37
32
  12: {
38
33
  npm: '\x1bP9;1q"1;1;12;12#1;2;80;22;22#2;2;100;100;100#3;2;84;40;40#4;2;93;71;71#5;2;90;61;61#6;2;89;56;56#7;' +
@@ -168,8 +163,7 @@ const LOGOS = {
168
163
 
169
164
  const SIZES = Object.keys(LOGOS).map(Number)
170
165
 
171
- // An image's size, its colours by register, and each pixel's register (0 for none), as sixel data draws
172
- // them: in bands of six rows, a character's bits a band's column, top first.
166
+ // Each pixel's register (0 for none): sixel data draws in bands of six rows, a character's bits a column, top first.
173
167
  function decode(image) {
174
168
  const header = image.slice(0, image.indexOf('#'))
175
169
  const [width, height] = header.split(';').slice(-2).map(Number)
@@ -195,8 +189,7 @@ function decode(image) {
195
189
  return { width, height, colours, pixels }
196
190
  }
197
191
 
198
- // decode()'s image as sixel data, as the logos above are written: square pixels, the background left as
199
- // it is, a band's registers each a line, runs of three or more counted.
192
+ // As the logos above are written: a band's registers each a line, runs of three or more counted.
200
193
  function encode({ width, height, colours, pixels }) {
201
194
  const bands = []
202
195
  for (let y = 0; y < height; y += 6) {
@@ -230,12 +223,8 @@ function lowered(image, top) {
230
223
  // where other terminals leave it as it is; so it is drawn with, a blank character, which draws nothing.
231
224
  const BACKGROUND = 9
232
225
 
233
- // The logos to draw over two of the terminal's cells, `cell` (its `width` and `height` in the pixels it
234
- // draws sixel images in, as capabilities() tells them): the largest that fits two cells, a gap of an eighth
235
- // of a row (two pixels at least) left over, lowered by half of it, so that it sits in the middle of its row,
236
- // apart from those on the lines above and below; the smallest where none fits. With `background` (`r;g;b`
237
- // in percent, as capabilities() tells it), what a logo leaves undrawn is that, for iTerm2. Those 16 pixels
238
- // square, as they are, where `cell` isn't known.
226
+ // The logos for two cells of `cell`'s size (capabilities()'s): the largest leaving an eighth of a row (two pixels at
227
+ // least), lowered to sit mid-row, else the smallest. `background` (`r;g;b` in percent) fills what they leave, for iTerm2.
239
228
  export function logos(cell, background) {
240
229
  let size = 16
241
230
  let top = 0
@@ -251,9 +240,8 @@ export function logos(cell, background) {
251
240
  return Object.fromEntries(Object.entries(LOGOS[size]).map(([name, image]) => [name, fitted(image)]))
252
241
  }
253
242
 
254
- // Primary Device Attributes (DA1), which a terminal answers `CSI ? 62 ; 4 ; 22 c`, say: its class, then
255
- // what it has, 4 being sixel graphics (tmux's `CSI ? 1 ; 2 ; 4 c` too). Every terminal answers it, so it is
256
- // asked last, its answer telling the others have come, or won't.
243
+ // Primary Device Attributes, answered `CSI ? 62 ; 4 ; 22 c`, say: its class, then what it has, 4 sixel graphics. Every
244
+ // terminal answers it, so it is asked last, its answer telling the others have come, or won't.
257
245
  const DA1 = '\x1b[c'
258
246
  const SIXEL = '4'
259
247
 
@@ -263,19 +251,15 @@ const REPORT_CELL_SIZE = '\x1b]1337;ReportCellSize\x1b\\'
263
251
  // A cell's size in pixels (XTWINOPS 16), answered `CSI 6 ; height ; width t`: as xterm.js draws sixel images,
264
252
  // in CSS pixels; but iTerm2's in points, which it doesn't draw them in.
265
253
  const CELL_SIZE = '\x1b[16t'
266
- // The terminal's background colour (OSC 11), answered `OSC 11 ; rgb:RRRR/GGGG/BBBB ST`, each of 1 to 4 hex
267
- // digits.
254
+ // OSC 11, answered `OSC 11 ; rgb:RRRR/GGGG/BBBB ST`, each of 1 to 4 hex digits.
268
255
  const BACKGROUND_COLOUR = '\x1b]11;?\x1b\\'
269
256
 
270
- // The first reply in `read` that `pattern` matches after an ESC, its parameters; text like a reply,
271
- // without its ESC, is not one.
257
+ // The first reply in `read` that `pattern` matches after an ESC: text like a reply, without its ESC, is not one.
272
258
  const reply = (read, pattern) => [...read.matchAll(pattern)].find(({ index }) => read[index - 1] === '\x1b')
273
259
 
274
- // Whether DA1's answer in `read` has sixel graphics among what the terminal has.
275
260
  const sixelIn = (read) => reply(read, /\[\?([\d;]*)c/gu)?.[1].split(';').slice(1).includes(SIXEL) ?? false
276
261
 
277
- // A cell's size in the pixels the terminal draws sixel images in: iTerm2's, its points by its scale; else
278
- // XTWINOPS 16's; null where neither is answered.
262
+ // In the pixels the terminal draws sixel images in: iTerm2's points by its scale, else XTWINOPS 16's.
279
263
  function cellIn(read) {
280
264
  const iterm2 = reply(read, /\]1337;ReportCellSize=([\d.]+);([\d.]+)(?:;([\d.]+))?/gu)
281
265
  if (iterm2) return { height: iterm2[1] * (iterm2[3] ?? 1), width: iterm2[2] * (iterm2[3] ?? 1) }
@@ -283,10 +267,8 @@ function cellIn(read) {
283
267
  return xtwinops ? { height: Number(xtwinops[1]), width: Number(xtwinops[2]) } : null
284
268
  }
285
269
 
286
- // What the terminal `output` writes to answers `question` with, DA1 last, read on `input` up to DA1's answer;
287
- // null where either is no terminal (a pipe, a file) or it is a dumb one (Emacs' shell), and nothing is asked,
288
- // or it hasn't answered in `timeout` ms. Meanwhile `input` is raw, as a terminal answers there, and read, as
289
- // it is left; a key pressed in that time is read with the answer and dropped.
270
+ // The terminal's answer to `question` (DA1 last), up to DA1's; null, asking nothing, where a stream is no terminal or
271
+ // a dumb one (Emacs' shell), or after `timeout` ms. A key pressed meanwhile is read with the answer and dropped.
290
272
  function ask(question, { input = process.stdin, output = process.stdout, env = process.env, timeout = 1000 } = {}) {
291
273
  if (!input?.isTTY || !output?.isTTY || env.TERM === 'dumb') return Promise.resolve(null)
292
274
  const { promise, resolve } = Promise.withResolvers()
@@ -313,20 +295,15 @@ function ask(question, { input = process.stdin, output = process.stdout, env = p
313
295
  return promise
314
296
  }
315
297
 
316
- // Whether the terminal `output` writes to draws sixel images: whether it answers DA1 with sixel graphics
317
- // among what it has (see ask(), for `options`).
318
298
  export const supported = async (options) => sixelIn((await ask(DA1, options)) ?? '')
319
299
 
320
- // The background colour in `read`, `r;g;b` in percent, as a sixel image's colours are; null where it isn't
321
- // answered.
300
+ // `r;g;b` in percent, as a sixel image's colours are.
322
301
  function backgroundIn(read) {
323
302
  const colour = reply(read, /\]11;rgb:([\da-f]{1,4})\/([\da-f]{1,4})\/([\da-f]{1,4})/giu)
324
303
  return colour ? colour.slice(1).map((hex) => Math.round((Number.parseInt(hex, 16) / (16 ** hex.length - 1)) * 100)).join(';') : null
325
304
  }
326
305
 
327
- // What the terminal `output` writes to tells of its images, in one round trip: whether it draws sixel images
328
- // (`sixel`, as supported()), its cells' size in the pixels it draws them in (`cell`, `{ width, height }`, see
329
- // cellIn), and its background colour (`background`, see backgroundIn), each null where it doesn't tell.
306
+ // In one round trip: `sixel` (as supported()), `cell` (`{ width, height }`) and `background`, each null where untold.
330
307
  export async function capabilities(options) {
331
308
  const read = (await ask(REPORT_CELL_SIZE + CELL_SIZE + BACKGROUND_COLOUR + DA1, options)) ?? ''
332
309
  return { sixel: sixelIn(read), cell: cellIn(read), background: backgroundIn(read) }
package/src/table.js CHANGED
@@ -1,31 +1,20 @@
1
- // A report's tables, as `stasis audit` and `stasis validate` print them, and their colours where the
2
- // stream they go to takes colours.
3
1
  import { styleText } from 'node:util'
4
2
 
5
- // Strip line breaks (LF/CR/CRLF, U+2028/U+2029) from a cell (an advisory's title, say) so they can't
6
- // break the box layout.
3
+ // Line breaks (LF/CR/CRLF, U+2028/U+2029) in a cell (an advisory's title, say) would break the box layout.
7
4
  const cell = (v) => String(v ?? '').replace(/[\r\n\u2028\u2029]+/gu, ' ')
8
5
 
9
- // Split a value into the physical lines a cell occupies. Non-multiline columns
10
- // collapse every line break to a space via `cell` (one line). A column named in
11
- // `multiline` (the `--why` reason column) keeps intentional `\n` breaks -- one
12
- // physical line per entry -- while still flattening stray CR/separators in each.
13
- const cellLines = (v, multiline) =>
14
- multiline ? String(v ?? '').split('\n').map((s) => cell(s)) : [cell(v)]
6
+ // The physical lines a cell occupies: one, but a `multiline` column's (`--why`'s reason) one per `\n`-separated entry.
7
+ const cellLines = (v, multiline) => (multiline ? String(v ?? '').split('\n').map((s) => cell(s)) : [cell(v)])
15
8
 
16
- // The longest of `items` by `lengthOf` (a string's or an array's length), 0 for none: a fold, as a column
17
- // (a --why cell of 2000 chains, say) may hold more lines and words than one call takes arguments.
9
+ // A fold, not Math.max(...): a column (a --why cell of 2000 chains, say) may hold more items than a call takes arguments.
18
10
  const longest = (items, lengthOf = (item) => item.length) => items.reduce((max, item) => Math.max(max, lengthOf(item)), 0)
19
11
 
20
- // A column that wraps narrows no further than its header, and its longest word up to this, so that only
21
- // a longer word is ever cut.
12
+ // A wrapping column narrows no further than its header, and its longest word up to this: only a longer word is cut.
22
13
  const MAX_WHOLE_WORD = 20
23
14
 
24
- // What a `multiline` column's entry wrapped starts its further lines with.
25
15
  const INDENT = ' '
26
16
 
27
- // `text` cut into lines of at most `width`, at spaces where it has them, a word wider than a line cut where
28
- // it must be; each line after the first starts with `indent`.
17
+ // `text` cut into lines of at most `width`, at spaces where it has them; each after the first starts with `indent`.
29
18
  function wrapLine(text, width, indent = '') {
30
19
  const lines = []
31
20
  let rest = text
@@ -42,21 +31,15 @@ function wrapLine(text, width, indent = '') {
42
31
  return lines
43
32
  }
44
33
 
45
- // `rows` as a boxed table of `columns`, its header their names. `paint(text, column, row)`, where
46
- // given, styles the text of each cell of a row (with colour, say), its padding after, unstyled;
47
- // `paintHeader(text, column)` each name in the header, and `paintFrame(text)` the box drawn around them.
48
- // Where `width` is given and the table is wider, the `wrap` columns narrow, the widest first, to fit it
49
- // where they can (see MAX_WHOLE_WORD), their text wrapped (see wrapLine); a `multiline` column's further
50
- // lines of an entry indented, so they don't read as entries of their own.
34
+ // `rows` as a boxed table of `columns`, `paint(text, column, row)` styling a cell's text (not its padding). Wider than
35
+ // `width`, its `wrap` columns narrow, the widest first, as far as MAX_WHOLE_WORD lets them.
51
36
  export function formatTable(rows, columns, { multiline = [], paint, paintHeader, paintFrame, width, wrap = [] } = {}) {
52
37
  if (rows.length === 0) return ''
53
38
  const ml = new Set(multiline)
54
39
  const linesOf = (obj) => columns.map((c) => cellLines(obj[c], ml.has(c)))
55
40
  const header = columns.map((c) => [c])
56
- let body = rows.map((r) => linesOf(r))
57
- const measure = () => columns.map((c, i) =>
58
- Math.max(c.length, longest(body, (cells) => longest(cells[i])))
59
- )
41
+ let body = rows.map(linesOf)
42
+ const measure = () => columns.map((c, i) => Math.max(c.length, longest(body, (cells) => longest(cells[i]))))
60
43
  let widths = measure()
61
44
  // Each column's text, a space either side, and a border after it; one more border before the first.
62
45
  const total = () => widths.reduce((sum, w) => sum + w + 3, 1)
@@ -70,16 +53,14 @@ export function formatTable(rows, columns, { multiline = [], paint, paintHeader,
70
53
  if (widest === undefined) break
71
54
  widths[widest]--
72
55
  }
73
- const narrowed = widths
74
56
  body = body.map((cells) => cells.map((lines, i) =>
75
- wrapping.includes(i) ? lines.flatMap((l) => wrapLine(l, narrowed[i], indent(i))) : lines))
57
+ wrapping.includes(i) ? lines.flatMap((l) => wrapLine(l, widths[i], indent(i))) : lines))
76
58
  widths = measure()
77
59
  }
78
60
  const frame = (text) => (paintFrame ? paintFrame(text) : text)
79
61
  const bar = frame('│')
80
62
  const line = (l, m, r, fill) => frame(l + widths.map((w) => fill.repeat(w + 2)).join(m) + r)
81
- // A row spans as many physical lines as its tallest cell; shorter cells pad
82
- // out with blanks so the borders stay aligned.
63
+ // A row spans as many physical lines as its tallest cell.
83
64
  const render = (cells, style) => {
84
65
  const height = longest(cells)
85
66
  const out = []
@@ -100,8 +81,7 @@ export function formatTable(rows, columns, { multiline = [], paint, paintHeader,
100
81
  ].join('\n')
101
82
  }
102
83
 
103
- // Whether `stream` takes colours, as @exodus/test tells it: CI's logs do, though no terminal; a
104
- // terminal that has them does (a TTY's hasColors); a pipe, or a file, doesn't.
84
+ // As @exodus/test tells it: CI's logs take colours, though no terminal, as does a TTY that has them.
105
85
  export function takesColors(stream) {
106
86
  return Boolean(process.env.CI) || Boolean(stream?.hasColors?.())
107
87
  }
@@ -109,8 +89,7 @@ export function takesColors(stream) {
109
89
  // Dimmed text's format: CI's logs show gray, not faint.
110
90
  export const DIM = process.env.CI ? 'gray' : 'dim'
111
91
 
112
- // `paint(format, text)`: `text` in `format` (util.styleText's: a colour, `bold`, or a list of them)
113
- // where `colors` (else as `stream` takes them, takesColors), else as it is.
92
+ // `paint(format, text)`: `text` in util.styleText's `format` where `colors`, else as it is.
114
93
  export function painter(stream, colors = takesColors(stream)) {
115
94
  return (format, text) => (colors && format && text !== '' ? styleText(format, text, { validateStream: false }) : text)
116
95
  }
@@ -1,17 +1,18 @@
1
- // Types of `@exodus/stasis/validate-notes` (validate-notes.js), whose comments tell what each does.
1
+ // Types of `@exodus/stasis/validate-notes` (validate-notes.js).
2
2
 
3
3
  export const OWN_REASONS: Readonly<Record<string, string>>
4
4
  export const PACKAGE_REASONS: Readonly<Record<string, string>>
5
5
  export const PATCH_ERRORS: Readonly<Record<string, string>>
6
6
  export const FILE_REASONS: Readonly<Record<string, string>>
7
7
  export const LOCKFILE_ERRORS: Readonly<Record<string, string>>
8
+ export function generatedBy(client: { schema: string; generator: string; prisma: string }): string
8
9
 
9
10
  // A package as a report tells it, as much as its note reads.
10
11
  export interface NotedPackage {
11
12
  reason?: string
12
13
  at?: string
13
14
  directory?: string
14
- patch?: { path?: string; from?: string; error?: string; verified?: boolean; applied?: boolean }
15
+ patch?: { path?: string; from?: string; error?: string; verified?: boolean; applied?: boolean; recorded?: true }
15
16
  }
16
17
  export type NotePart = string | { path: string }
17
18
  export function noteOf(pkg: NotedPackage): NotePart[]
@@ -1,8 +1,4 @@
1
- // What a validation's report (validate.js's) tells, in words: why own code, a package or a file
2
- // wasn't checked or is as it is, why no lockfile was held to, and a package's note beside its status.
3
- // Of no module, for a browser too (`@exodus/stasis/validate-notes`), as printValidationReport tells it.
4
-
5
- // Why own code wasn't checked, by `own.reason`.
1
+ // A validation report in words, as printValidationReport tells it. Of no module, for a browser too.
6
2
  export const OWN_REASONS = {
7
3
  skipped: 'skipped (--only-deps): its dependencies alone validated',
8
4
  'no-repository': 'no repository to read it of',
@@ -11,11 +7,13 @@ export const OWN_REASONS = {
11
7
  'history-unread': 'its commit is at no tag or branch head, nor in its default branch\'s history, and not every other branch was compared',
12
8
  }
13
9
 
14
- // A package's reason, unverified (the first) or failing its lockfile (the last four).
10
+ // A package's reason: unverified, or, from `misplaced` on, failing its lockfile or what it records.
15
11
  export const PACKAGE_REASONS = {
16
12
  local: 'installed from a directory of the repository, which isn\'t read',
17
13
  'patch-unverified': 'as patched by the bundle\'s patch, which isn\'t verified against the repository',
18
14
  git: 'locked from git, not a registry',
15
+ 'not-a-submodule': 'no submodule of its repository\'s tree at its path',
16
+ 'git-built': 'locked from git: of the files its repository hasn\'t at the commit, which its install may build, none verified',
19
17
  'not-registry': 'locked from elsewhere than its registry',
20
18
  'no-integrity': 'locked with no sha512 to hold its tarball to',
21
19
  unsupported: 'no upstream package for its ecosystem',
@@ -27,8 +25,13 @@ export const PACKAGE_REASONS = {
27
25
  'alias-unverified': 'installed under another name, an alias no lockfile read tells of',
28
26
  misplaced: 'installed where its path or its lockfile names another package or version',
29
27
  'not-locked': 'not locked by the lockfile',
30
- 'integrity-mismatch': 'its registry\'s tarball is not the one the lockfile locks',
31
- 'integrity-conflict': 'locked with two integrities',
28
+ 'integrity-mismatch': 'its registry\'s tarball is not the one it is locked or recorded with',
29
+ 'integrity-conflict': 'locked or recorded with two integrities',
30
+ 'integrity-not-locked': 'records an integrity its lockfile doesn\'t lock it with',
31
+ 'commit-not-locked': 'records another commit than its repository\'s tree pins it at',
32
+ 'patch-not-locked': 'records a patch its lockfile doesn\'t patch it with',
33
+ 'patch-not-recorded': 'records an integrity and no patch, where its lockfile patches it',
34
+ 'patch-conflict': 'its copies record different patches, or one of them none, where pnpm patches every copy with one',
32
35
  }
33
36
 
34
37
  // Why a patch wasn't applied, told after `its patch` and its path.
@@ -38,10 +41,17 @@ export const PATCH_ERRORS = {
38
41
  'patch-mismatch': 'is not of the hash its lockfile locks',
39
42
  }
40
43
 
41
- // Why a file is as it is, by a problem's `reason`.
42
- export const FILE_REASONS = { symlink: 'a symlink in the repository', submodule: 'in a submodule', 'tree-cut': 'the repository\'s tree was too large to list whole' }
44
+ export const FILE_REASONS = {
45
+ symlink: 'a symlink in the repository',
46
+ submodule: 'in a submodule',
47
+ 'tree-cut': 'the repository\'s tree was too large to list whole',
48
+ generated: 'not as the repository\'s Prisma schema generates it',
49
+ 'not-generated': 'in a Prisma Client\'s output, which generates no such file',
50
+ listed: 'the repository\'s tree was listed, not read, and a lockfile records its integrity alone',
51
+ }
52
+
53
+ export const generatedBy = (client) => `${client.schema}'s ${client.generator} (Prisma ${client.prisma})`
43
54
 
44
- // Why the dependencies were held to no lockfile, by a report's `lockfileError` (a ValidateError's code).
45
55
  export const LOCKFILE_ERRORS = {
46
56
  'no-lockfile': 'no lockfile of its repository locks them',
47
57
  'lockfile-ambiguous': 'more than one package manager\'s lockfile installs it',
@@ -49,18 +59,14 @@ export const LOCKFILE_ERRORS = {
49
59
  'lockfile-unsupported': 'its lockfile is of a kind validate doesn\'t read',
50
60
  }
51
61
 
52
- // What a report tells of a package beside its status, as parts: text, and the paths in it as `{ path }`,
53
- // for a caller to set apart: why it is unverified or fails its lockfile, its patch, or the directory
54
- // it is held to; none where nothing more.
62
+ // The paths in it as `{ path }`, for a caller to set apart.
55
63
  export function noteOf(pkg) {
56
64
  const { patch } = pkg
57
65
  if (pkg.reason) return [PACKAGE_REASONS[pkg.reason] ?? pkg.reason, ...(pkg.at ? [': ', { path: pkg.at }] : [])]
58
66
  if (patch?.error) return ['its patch', ...(patch.path ? [' ', { path: patch.path }] : []), ` ${PATCH_ERRORS[patch.error] ?? `could not be applied (${patch.error})`}`]
59
- // A patch the bundle holds, as checked against the repository.
60
- const whose = patch?.from !== 'bundle' ? [] : [patch.verified ? ' (the bundle\'s, as the repository has it)' : ' (the bundle\'s, not verified against the repository)']
61
- if (patch) return [patch.applied === false ? 'locked patched, bundled as published' : 'patched', ...(patch.path ? [' by ', { path: patch.path }, ...whose] : [])]
62
- return pkg.directory ? ['held to ', { path: pkg.directory }, ' of the repository'] : []
67
+ if (!patch) return pkg.directory ? ['held to ', { path: pkg.directory }, ' of the repository'] : []
68
+ const whose = patch.from !== 'bundle' ? [] : [patch.verified ? ' (the bundle\'s, as the repository has it)' : ' (the bundle\'s, not verified against the repository)']
69
+ return [patch.applied === false ? 'bundled as published, not patched' : 'patched', ...(patch.path ? [' by ', { path: patch.path }, ...whose] : []), ...(patch.recorded ? [', as recorded'] : [])]
63
70
  }
64
71
 
65
- // A package's note as text: '' where nothing more.
66
72
  export const noteText = (pkg) => noteOf(pkg).map((part) => (typeof part === 'string' ? part : part.path)).join('')
package/src/validate.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Types of `@exodus/stasis/validate` (validate.js), whose comments tell what each does.
1
+ // Types of `@exodus/stasis/validate` (validate.js).
2
2
  import type { Client, RepoDirEntry } from '@preventive/upstream/github.js'
3
3
 
4
4
  export { HttpError } from '@preventive/upstream/npm.js'
@@ -11,23 +11,23 @@ export class PatchError extends Error {
11
11
  code: string
12
12
  }
13
13
 
14
- export type ValidateErrorCode = 'not-a-bundle' | 'no-repository' | 'no-commit' | 'commit-not-in-history' | 'history-unread'
14
+ export type ValidateErrorCode = 'no-repository' | 'no-commit' | 'commit-not-in-history' | 'history-unread'
15
15
  | 'no-lockfile' | 'lockfile-ambiguous' | 'lockfile-unsupported' | 'lockfile-unreadable'
16
16
  export class ValidateError extends Error {
17
17
  constructor(code: ValidateErrorCode, message: string)
18
18
  code: ValidateErrorCode
19
19
  }
20
20
 
21
- // What validation checks of a bundle (validationPlan).
22
- export interface PlanFile { path: string; dir: string; rel: string; format?: string; bytes(): Uint8Array }
23
- export interface PlanPackage { ecosystem: string; name: string; version: string; files: PlanFile[] }
21
+ // What validation checks of a bundle, or a stasis.lock.json (validationPlan): a file's bytes, or their integrity.
22
+ export type PlanFile = { path: string; dir: string; rel: string; format?: string } & ({ bytes(): Uint8Array } | { integrity: string })
23
+ export interface PlanPackage { ecosystem: string; name: string; version: string; files: PlanFile[]; recorded: Map<string, string>; integrities: Map<string, string>; repos: Map<string, { github: string; directory?: string; commit?: string }> }
24
24
  export interface ValidationPlan { files: number; own: PlanFile[]; packages: PlanPackage[]; patches: Map<string, string> }
25
25
  // A parsed bundle (Bundle.parse's, or parseFileWithKind's artifact).
26
26
  export interface PlannedBundle {
27
- modules: Map<string, { name?: string; version?: string; ecosystem?: string; files: Record<string, unknown> }>
27
+ modules: Map<string, { name?: string; version?: string; ecosystem?: string; integrity?: string; repo?: { github: string; directory?: string; commit?: string }; patch?: { integrity: string }; files: Record<string, unknown> }>
28
28
  formats?: Map<string, string>
29
29
  }
30
- export function validationPlan(bundle: PlannedBundle): ValidationPlan
30
+ export function validationPlan(bundle: PlannedBundle, options?: { lockfile?: boolean }): ValidationPlan
31
31
 
32
32
  export function gitBlobId(bytes: Uint8Array): string
33
33
  export function tarballFiles(tarball: Uint8Array): Promise<Map<string, Uint8Array | { symlink: string }>>
@@ -51,16 +51,20 @@ interface Where { repository: string; movedFrom?: string; commit: string; ref?:
51
51
  export type OwnCode = (Where & { entries: Map<string, RepositoryEntry>; cut?: boolean })
52
52
  | (Partial<Where> & { reason: string; entries?: Map<string, RepositoryEntry> })
53
53
 
54
- export interface Lock { from: 'registry' | 'git' | 'elsewhere' | 'local'; integrity?: string; conflict?: true; directories?: string[] }
54
+ export interface Lock { from: 'registry' | 'git' | 'elsewhere' | 'local'; integrity?: string; conflict?: true; directories?: string[]; at?: GitAt }
55
55
  export interface Lockfile {
56
56
  path: string
57
57
  text: string
58
58
  from?: 'repository' | 'local'
59
59
  read?: (path: string) => string | Promise<string>
60
60
  tree?: (dir: string) => Promise<Map<string, Uint8Array>>
61
+ // A git dependency's files, of the GitHub repository at the commit and path its lockfile locks.
62
+ git?: (at: GitAt) => Promise<Map<string, Uint8Array>>
61
63
  patches?: string[]
62
64
  root?: string
65
+ at?: string
63
66
  }
67
+ export type GitAt = { github: string; commit: string; path: string }
64
68
  // A patch pnpm's lockfile names for a version: by its path, or by its hash alone, in a file of one of
65
69
  // `names` in a patches directory (locate).
66
70
  export type LockedPatch = { hash: string; path: string } | { hash: string; names: string[] }
@@ -74,11 +78,18 @@ export interface Locked {
74
78
  aliased(as: string, named: string): boolean | undefined
75
79
  from?: 'repository' | 'local'
76
80
  tree?: (dir: string) => Promise<Map<string, Uint8Array>>
81
+ git?: (at: GitAt) => Promise<Map<string, Uint8Array>>
77
82
  read(path: string): Promise<string>
83
+ split(pkg: PlanPackage): { pkg: PlanPackage; locked: Locked }[] | undefined
78
84
  }
79
85
  export function lockedBy(lockfiles: Lockfile[]): Locked
80
86
 
81
87
  export interface Problem { path: string; kind: 'differs' | 'unexpected' | 'unverified'; of: string; reason?: string }
88
+ // A Prisma Client the repository's schemas generate, as validateBundle's `generated` gives it: its files
89
+ // by their paths from its output `dir`, which is by its path from the bundle's root, as `schema` is.
90
+ export interface PrismaClientOutput { dir: string; files: Map<string, string | Uint8Array>; schema: string; generator: string; prisma: string }
91
+ // A client a report tells files of the bundle generated by: their paths, from the bundle's root.
92
+ export interface GeneratedClient { output: string; schema: string; generator: string; prisma: string; files: string[] }
82
93
  export interface PackageReport {
83
94
  ecosystem: string
84
95
  name: string
@@ -88,23 +99,32 @@ export interface PackageReport {
88
99
  reason?: string
89
100
  at?: string
90
101
  directory?: string
91
- patch?: { hash?: string; path?: string; from?: 'repository' | 'local' | 'bundle'; error?: string; applied?: boolean }
102
+ patch?: { hash?: string; path?: string; from?: 'repository' | 'local' | 'bundle'; error?: string; verified?: boolean; applied?: boolean; recorded?: true }
92
103
  }
93
104
  export interface BundleValidation {
94
105
  validatedAt: number
95
106
  status: 'valid' | 'invalid' | 'incomplete'
96
107
  own: (Where & { checked: true; cut?: true }) | { checked: false; reason: string; patches?: number }
97
108
  lockfiles: string[] | null
98
- counts: Record<'files' | 'own' | 'dependencies' | 'matched' | 'eol' | 'differs' | 'unexpected' | 'unverified' | 'skipped' | 'packages' | 'validPackages' | 'lockFailures' | 'misplaced', number>
109
+ counts: Record<'files' | 'own' | 'dependencies' | 'matched' | 'eol' | 'generated' | 'differs' | 'unexpected' | 'unverified' | 'skipped' | 'packages' | 'validPackages' | 'lockFailures' | 'misplaced', number>
99
110
  problems: Problem[]
100
111
  moreProblems: number
101
112
  packages: PackageReport[]
113
+ generated: GeneratedClient[]
114
+ // Why no Prisma Client was generated to hold its files the repository doesn't hold to.
115
+ generatedError?: string
102
116
  // validateRepository's, `strict` false: why no lockfile was held to.
103
117
  lockfileError?: ValidateErrorCode
118
+ // The stasis.lock.json the repository commits beside it, which it is held to, and what it contradicts of it.
119
+ stasisLockfile?: { path: string; error?: string }
104
120
  }
105
121
 
106
122
  export function validateBundle(plan: ValidationPlan, own: OwnCode | Promise<OwnCode>,
107
- options?: { fetch?: Fetch; locked?: Locked | null; deadline?: number; now?: () => number }): Promise<BundleValidation>
123
+ options?: {
124
+ fetch?: Fetch; locked?: Locked | null; generated?: () => Promise<PrismaClientOutput[]>; deadline?: number; now?: () => number
125
+ // A submodule's commit as the repository's tree pins one at a directory (null for none), and its repository's files there.
126
+ submodules?: { at(dir: string): Promise<string | null>; read(at: GitAt): Promise<Map<string, Uint8Array>> }
127
+ }): Promise<BundleValidation>
108
128
  export function exitCodeOf(report: BundleValidation, options?: { allowUnverified?: boolean }): 0 | 1 | 2
109
129
 
110
130
  type Read = 'getRepoTreeId' | 'getRepoTreeTarball' | 'listRepoDir' | 'getRepoFile' | 'getRepoHead' | 'listRepoTags' | 'listRepoBranches' | 'compareCommits'
@@ -118,6 +138,8 @@ export function historyOf(repository: Repository, commit: string, options?: { ma
118
138
  export function repositoryFiles(repository: Repository, where: { github?: string; commit: string; directory?: string }): Promise<Map<string, RepositoryEntry>>
119
139
  export function repositoryLockfiles(options: { directory?: string; ecosystems: Set<string>; list: (dir: string) => Promise<string[]>; read: (path: string) => Promise<string> })
120
140
  : Promise<{ path: string; text: string }[]>
141
+ export function configuredLockfiles(options: { directory?: string; list: (dir: string) => Promise<string[]>; read: (path: string) => Promise<string> }): Promise<string[] | undefined>
142
+ export function lockedNpmPackages(dir: string): Promise<{ path: string; name: string; packages: { name: string; version: string }[] }[]>
121
143
 
122
144
  interface Options { own?: boolean; fetch?: Fetch; deadline?: number }
123
145
  export function validateRepository(plan: ValidationPlan, where: { repository?: Repository | null; commit?: string; directory?: string }, options?: Options & {
@@ -125,6 +147,11 @@ export function validateRepository(plan: ValidationPlan, where: { repository?: R
125
147
  // A listing of the commit's tree, as upstream's listRepoTree gives it, for these paths.
126
148
  listTree?: (paths: string[]) => Promise<{ entries: RepoDirEntry[]; cut?: boolean }>
127
149
  strict?: boolean
150
+ generated?: () => Promise<PrismaClientOutput[]>
151
+ // The lockfile of what is validated, held to the stasis.lock.json the repository commits.
152
+ attested?: () => import('@exodus/stasis-core/lockfile').Lockfile
153
+ // What reads a git dependency's repository (followingMoves wraps it).
154
+ client?: Reads
128
155
  }): Promise<BundleValidation>
129
156
  export function validate(file: string, options?: Options & { client?: Reads; github?: string; sha?: string; directory?: string; lockfile?: boolean | string[] }): Promise<BundleValidation>
130
157