UNPKG

3.92 kBTypeScriptView Raw
1import { /*dmmf, */ DMMFClass } from './dmmf';
2import { DMMF } from './dmmf-types';
3import { ArgError, FieldError, InvalidArgError, InvalidFieldError } from './error-types';
4import { MissingItem } from './utils/printJsonErrors';
5export declare class Document {
6 readonly type: 'query' | 'mutation';
7 readonly children: Field[];
8 constructor(type: 'query' | 'mutation', children: Field[]);
9 toString(): string;
10 validate(select?: any, isTopLevelQuery?: boolean, originalMethod?: string, errorFormat?: 'pretty' | 'minimal' | 'colorless', validationCallsite?: any): void;
11 protected printFieldError: ({ error, path }: FieldError, missingItems: MissingItem[], minimal: boolean) => string;
12 protected printArgError: ({ error, path }: ArgError, hasMissingItems: boolean, minimal: boolean) => string;
13 /**
14 * As we're allowing both single objects and array of objects for list inputs, we need to remove incorrect
15 * zero indexes from the path
16 * @param inputPath e.g. ['where', 'AND', 0, 'id']
17 * @param select select object
18 */
19 private normalizePath;
20}
21export declare class PrismaClientValidationError extends Error {
22}
23export interface FieldArgs {
24 name: string;
25 schemaField?: DMMF.SchemaField;
26 args?: Args;
27 children?: Field[];
28 error?: InvalidFieldError;
29}
30export declare class Field {
31 readonly name: string;
32 readonly args?: Args;
33 readonly children?: Field[];
34 readonly error?: InvalidFieldError;
35 readonly hasInvalidChild: boolean;
36 readonly hasInvalidArg: boolean;
37 readonly schemaField?: DMMF.SchemaField;
38 constructor({ name, args, children, error, schemaField }: FieldArgs);
39 toString(): string;
40 collectErrors(prefix?: string): {
41 fieldErrors: FieldError[];
42 argErrors: ArgError[];
43 };
44}
45export declare class Args {
46 args: Arg[];
47 readonly hasInvalidArg: boolean;
48 constructor(args?: Arg[]);
49 toString(): string;
50 collectErrors(): ArgError[];
51}
52interface ArgOptions {
53 key: string;
54 value: ArgValue;
55 argType?: DMMF.ArgType;
56 isEnum?: boolean;
57 error?: InvalidArgError;
58 schemaArg?: DMMF.SchemaArg;
59}
60export declare class Arg {
61 readonly key: string;
62 value: ArgValue;
63 readonly error?: InvalidArgError;
64 readonly hasError: boolean;
65 readonly isEnum: boolean;
66 readonly schemaArg?: DMMF.SchemaArg;
67 readonly argType?: DMMF.ArgType;
68 readonly isNullable: boolean;
69 constructor({ key, value, argType, isEnum, error, schemaArg, }: ArgOptions);
70 _toString(value: ArgValue, key: string): string | undefined;
71 toString(): string;
72 collectErrors(): ArgError[];
73}
74export declare type ArgValue = string | boolean | number | undefined | Args | string[] | boolean[] | number[] | Args[] | null;
75export interface DocumentInput {
76 dmmf: DMMFClass;
77 rootTypeName: 'query' | 'mutation';
78 rootField: string;
79 select?: any;
80}
81export declare function makeDocument({ dmmf, rootTypeName, rootField, select, }: DocumentInput): Document;
82export declare function transformDocument(document: Document): Document;
83export declare function selectionToFields(dmmf: DMMFClass, selection: any, schemaField: DMMF.SchemaField, path: string[]): Field[];
84export declare function isInputArgType(argType: DMMF.ArgType): argType is DMMF.InputType;
85export interface UnpackOptions {
86 document: Document;
87 path: string[];
88 data: any;
89}
90/**
91 * Unpacks the result of a data object and maps DateTime fields to instances of `Date` inplace
92 * @param options: UnpackOptions
93 */
94export declare function unpack({ document, path, data }: UnpackOptions): any;
95export interface MapDatesOptions {
96 field: Field;
97 data: any;
98}
99export declare function mapDates({ field, data }: MapDatesOptions): any;
100export declare function mapJson({ field, data }: MapDatesOptions): any;
101export declare function getField(document: Document, path: string[]): Field;
102export {};