MCPcopy
hub / github.com/prisma/prisma / ArrayValue

Class ArrayValue

packages/client/src/runtime/core/errorRendering/ArrayValue.ts:8–62  ·  packages/client/src/runtime/core/errorRendering/ArrayValue.ts::ArrayValue

Source from the content-addressed store, hash-verified

6import { Value } from class="st">'./Value'
7
8export class ArrayValue extends Value {
9 private items: ArrayField[] = []
10
11 addItem(item: Value): this {
12 this.items.push(new ArrayField(item))
13 return this
14 }
15
16 getField(index: number): ArrayField | undefined {
17 return this.items[index]
18 }
19
20 override getPrintWidth(): number {
21 if (this.items.length === 0) {
22 return 2
23 }
24 const maxItemWidth = Math.max(...this.items.map((item) => item.value.getPrintWidth()))
25 return maxItemWidth + INDENT_SIZE
26 }
27
28 override write(writer: ErrorWriter): void {
29 if (this.items.length === 0) {
30 this.writeEmpty(writer)
31 return
32 }
33 this.writeWithItems(writer)
34 }
35
36 private writeEmpty(writer: ErrorWriter) {
37 const output = new FormattedString(class="st">'[]')
38 if (this.hasError) {
39 output.setColor(writer.context.colors.red).underline()
40 }
41 writer.write(output)
42 }
43
44 private writeWithItems(writer: ErrorWriter) {
45 const { colors } = writer.context
46
47 writer
48 .writeLine(class="st">'[')
49 .withIndent(() => writer.writeJoined(fieldsSeparator, this.items).newLine())
50 .write(class="st">']')
51
52 if (this.hasError) {
53 writer.afterNextNewline(() => {
54 writer.writeLine(colors.red(class="st">'~'.repeat(this.getPrintWidth())))
55 })
56 }
57 }
58
59 override asObject(): undefined {
60 return undefined
61 }
62}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected