export * from './builder'; export * from './mappers'; export type Nullable = { [P in keyof T]: T[P] | null; }; type GenericEntityIdInput = { id?: string }; type PropertyTypes = string | number | boolean | Date | bigint; export type GenericPrismaInput = Record; export type GenericPrismaOneConnect = { connect?: any }; type GenericPrismaManyConnect = { connect?: any[] | null }; export type PrismaInputArgs = T extends { data?: infer U } ? U : never; type ExtractPrismaInputFromMany = PrismaInput< | (C extends unknown ? never : C) | (U extends { data?: infer D } ? D extends Record ? D : never : never) >; // type ExtractArrayModelDataType = S extends any[] ? S[0] : never; type ExtractPrismaInputFromOne = PrismaInput< C extends Record ? C | undefined : U extends Record ? U | undefined : never >; type ExtractManyRelationConnectType = T extends { connect?: (infer C)[] | null; } ? C | undefined : never; type ExtractManyRelationDisconnectType = T extends { disconnect?: (infer C)[] | null; } ? C | undefined : undefined; type ExtractManyReferenceType = T extends { connect?: (infer C)[] } ? C | undefined : never; type ExtractManyRelationUpdateDataType = U extends { data?: infer UU } ? Partial | undefined : any; type ExtractManyRelationUpdateWhereType = U extends { where?: infer UU } ? Partial | undefined : any; type UnknownToUndefined = T extends unknown ? undefined : T; export type SafeProperty = K extends keyof T ? UnknownToUndefined : undefined; export type PrismaInput = T; export type PrismaOneObjectInput = { connect?: Connect; create?: Create; disconnect?: boolean; update?: Update; }; export type PrismaManyObjectInput< Create, Update, UpdateWhere, Connect, Disconnect, > = { connect?: Connect[]; create?: Create[]; disconnect?: Disconnect[]; update?: { where: UpdateWhere; data: Update }[]; }; export type PrismaOneReferenceInput = { connect?: Connect | null; disconnect?: boolean; }; export type PrismaManyReferenceInput = { connect?: Connect[] | null; disconnect?: GenericEntityIdInput[]; }; // --- export type PropertyMapper = { // fake property needed for the mapper to work __key__?: Key; pick?: (o?: ModelSource) => Model | undefined; map: (props: { value?: Model; oldValue?: Model; method: 'create' | 'update'; }) => Model | { set?: Model } | undefined; __typename: 'Property'; }; export type OneRelationMapper< Model, NullableModel extends boolean, Create, Update, Connect, ModelSource, Key, > = { __key__?: Key; pick?: ( o?: ModelSource | null, ) => NullableModel extends true ? Model | undefined | null : Model | undefined; map: (props: { value?: Model | null; oldValue?: Model | null; }) => PrismaOneObjectInput | undefined; __typename: 'Relation'; }; export type ManyRelationMapper< Model, Create, Update, UpdateWhere, Connect, Disconnect, ModelSource, Key, > = { __key__?: Key; pick?: ( o?: ModelSource | null, ) => (Partial | null | undefined)[] | null | undefined; map: (props: { value?: Model[] | null; oldValue?: Model[] | null; }) => | PrismaManyObjectInput | undefined; __typename: 'ManyRelation'; }; export type OneReferenceMapper< // eslint-disable-next-line @typescript-eslint/no-unused-vars _Input extends GenericPrismaOneConnect, Model, // TODO: Model no needed, eg Model is always same as Connect Connect, ModelSource, Key, Required extends boolean, > = { __key__?: Key; __required__?: Required; pick?: (o?: ModelSource | null) => Model | undefined; map: (props: { value?: Model; oldValue?: Model; }) => PrismaOneReferenceInput | undefined; __typename: 'Reference'; }; export type ManyReferenceMapper< Input extends GenericPrismaManyConnect | null, Source = any, Connect = ExtractManyReferenceType, ModelSource = any, Key = any, Required extends boolean = false, > = { __key__?: Key; __required__?: Required; pick?: (o?: ModelSource | null) => Source | null | undefined; map: (props: { value?: Source | null; oldValue?: Source | null; }) => PrismaManyReferenceInput | undefined; __typename: 'ManyReference'; }; // --- /** * Represents a type that determines the appropriate schema property mapper based on the structure of a given Prisma input property. * * The type performs a series of checks on the input property `T` to decide which mapper type should be used: * * This type is instrumental in constructing a Prisma input schema that accurately represents the structure * and relations of the underlying Prisma model. * * @typeParam Input - Represents the Prisma input property structure. * @typeParam Model - Represents the model property type that the input property maps to. */ export type PrismaInputSchemaProperty< Input = any, Model = any, ModelSource = any, InputSource = any, Key extends keyof InputSource = any, InputCopy = InputSource[Key], > = Input extends { create?: (infer C)[] | null; update?: (infer U)[] | null; } ? | ManyRelationMapper< any, C | undefined, ExtractManyRelationUpdateDataType | undefined, ExtractManyRelationUpdateWhereType | undefined, ExtractManyRelationConnectType | undefined, ExtractManyRelationDisconnectType, ModelSource, Key > | (Input extends { connect?: (infer C)[] | null } ? ManyReferenceMapper< Input, Model | undefined, Partial | undefined, ModelSource, Key, InputCopy extends null ? false | true : true > : never) : Input extends { create?: infer C; update?: infer U } ? | OneRelationMapper< any, // Model, InputCopy extends null ? true : false, C extends unknown ? C | undefined : C | undefined, U extends unknown ? U | undefined : U | undefined, 'connect' extends keyof Input ? Input['connect'] : undefined, ModelSource, Key > | (Input extends { connect?: infer Co } ? OneReferenceMapper< Input, Partial | undefined, Partial | undefined, ModelSource, Key, null extends InputCopy ? false : true > : never) : Input extends { connect?: (infer C)[] | null } ? ManyReferenceMapper< Input, Model | undefined, Partial | undefined, ModelSource, Key, InputCopy extends null ? false | true : true > : Input extends { connect?: infer C } ? OneReferenceMapper< Input, Model | undefined, Partial | undefined, ModelSource, Key, InputCopy extends null ? false | true : true > : Input extends { set?: infer S } ? PropertyMapper : Input extends PropertyTypes ? PropertyMapper< Exclude | undefined, ModelSource, Key > : Input extends object ? PropertyMapper : never; /** * Represents a type that defines the structure and mapping behavior of a Prisma input schema. * * The type consists of two main parts: * * 1. `mapper`: A function that transforms a given source value (and its previous value, if any) into the desired * Prisma input format. The function receives the current value, the old value, and the schema itself as arguments. * * 2. `properties`: An object that maps each key of the input type `T` to its corresponding Prisma input schema property. * It ensures that only valid properties, as defined by `PrismaInputSchemaProperty`, are included in the resulting schema. * * This type provides a blueprint for constructing and transforming Prisma input data, ensuring that the input aligns * with the expected structure and relations of the underlying Prisma model. * * @typeParam Input - Represents the Prisma input the mappter will return. * @typeParam Model - The model of the value and value that are mapped to the Input type. */ export type PrismaInputSchema< Input extends GenericPrismaInput | unknown, Model, InputModel = InferPrismaModel>, > = { mapper(props: { value?: Partial | null; oldValue?: Partial | null; mapper: PrismaInputSchema; }): Input | undefined; properties: { [K in keyof Input]-?: K extends keyof InputModel ? PrismaInputSchemaProperty : never; }; }; /** * Represents a type that infers the structure of a property within a Prisma model based on a given Prisma input property. * * This type is useful for determining the expected model property structure based on various Prisma input patterns, * especially when dealing with relations, connections, or value updates. * * @typeParam Input - Represents the Prisma input structure from which the model is inferred. */ export type InferPrismaModelProperty = Input extends { set?: infer U; } ? U : Input extends { create?: (infer C)[] | null; update?: (infer U)[] | null } ? | InferPrismaModel>>[] | undefined | null : Input extends { create?: infer C; update?: infer U } ? | InferPrismaModel>> | undefined | null : Input extends { connect?: infer C } ? C : Input; /** * Represents a type that infers the structure of a Prisma model based on a given Prisma input. * * For each property type `Input`, it infers the corresponding model property type * using the `InferPrismaModelProperty` utility type. * * This type is useful for deriving the expected model structure from a Prisma input, especially * when dealing with complex nested inputs or relations. * * @typeParam Input - Represents the Prisma input structure from which the model is inferred. */ export type InferPrismaModel = { [K in keyof Input]: InferPrismaModelProperty; }; /** * Represents a type that maps each property of an inferred Prisma input to its corresponding model property. * * For each key in `Input`, is associated with a `PrismaInputSchemaProperty` that describes how the model is * mapped to the input. * * @typeParam Input - Represents the Prisma input structure from which the model is inferred. */ export type PrismaInputSchemaProperties< Input, Model, InputModel = InferPrismaModel, > = { [K in keyof Input]-?: PrismaInputSchemaProperty< Input[K], K extends keyof InputModel ? InputModel[K] : unknown, Model, Input, K >; };