MCPcopy
hub / github.com/prisma/prisma / ObjectValue

Class ObjectValue

packages/client/src/runtime/core/errorRendering/ObjectValue.ts:36–209  ·  packages/client/src/runtime/core/errorRendering/ObjectValue.ts::ObjectValue

Source from the content-addressed store, hash-verified

34 * Value of sub selection at path [posts, attachments] is { where: { published: true }}
35 */
36export class ObjectValue extends Value {
37 private fields: Record<string, ObjectField> = {}
38 private suggestions: ObjectFieldSuggestion[] = []
39
40 addField(field: ObjectField) {
41 this.fields[field.name] = field
42 }
43
44 addSuggestion(suggestion: ObjectFieldSuggestion) {
45 this.suggestions.push(suggestion)
46 }
47
48 getField(key: string): ObjectField | undefined {
49 return this.fields[key]
50 }
51
52 getDeepField(path: string[]): Field | undefined {
53 const [head, ...tail] = path
54 const firstField = this.getField(head)
55 if (!firstField) {
56 return undefined
57 }
58 let field: Field = firstField
59 for (const segment of tail) {
60 let nextField: Field | undefined
61
62 if (field.value instanceof ObjectValue) {
63 nextField = field.value.getField(segment)
64 } else if (field.value instanceof ArrayValue) {
65 nextField = field.value.getField(Number(segment))
66 }
67 if (!nextField) {
68 return undefined
69 }
70 field = nextField
71 }
72 return field
73 }
74
75 getDeepFieldValue(path: string[]) {
76 if (path.length === 0) {
77 return this
78 }
79 return this.getDeepField(path)?.value
80 }
81
82 hasField(key: string) {
83 return Boolean(this.getField(key))
84 }
85
86 removeAllFields() {
87 this.fields = {}
88 }
89
90 removeField(key: string) {
91 delete this.fields[key]
92 }
93

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected