Skip to content

Commit

Permalink
feat(client): extensions generic type api (#16936)
Browse files Browse the repository at this point in the history
* fix typescript compiler crash

* update snaps

* feat(client): extensions generic type api

* fix type performance

* rework ctx and meta

* update snaps

* yet another significant type perf fix

* fix broken tests

* simplify meta.name and add tests

* implement altering internal params

* use all models in test instead

* fix object id in tests

* fix node length exceeded and payload export

* second attempt to fix node inference

* add Payload type utility

* fix and test exact types in generic context

* expose extension utils in non generated client

* fix issue wrt exact types not enforcing type-checks

* fix type mismatch

* enable default client cross generated client extensions tests

* add regression test for tsc crash

* create sub-folder for extension publishing

* add test fro extension publishing + various cleanups

* exclude e2e from dep checks

* remove non needed payload kind

* add comment

* remove payload kind from tests
  • Loading branch information
millsp committed Jan 16, 2023
1 parent d47209d commit 7716c77
Show file tree
Hide file tree
Showing 59 changed files with 1,733 additions and 249 deletions.
2 changes: 1 addition & 1 deletion helpers/compile/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async function dependencyCheck(options: BuildOptions) {
const buildPromise = esbuild.build({
entryPoints: glob.sync('**/*.{j,t}s', {
// We don't check dependencies in ecosystem tests because tests are isolated from the build.
ignore: ['./src/__tests__/**/*', './tests/ecosystem/**/*'],
ignore: ['./src/__tests__/**/*', './tests/e2e/**/*'],
gitignore: true,
}),
logLevel: 'silent', // there will be errors
Expand Down
50 changes: 31 additions & 19 deletions packages/client/scripts/default-index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable prettier/prettier */

import runtime from '@prisma/client/runtime'

/**
Expand All @@ -17,6 +15,7 @@ import runtime from '@prisma/client/runtime'
* Read more in our [docs](https://github.com/prisma/prisma/blob/main/docs/prisma-client-js/api.md).
*/
export declare const PrismaClient: any

/**
* ## Prisma Client ʲˢ
*
Expand All @@ -33,16 +32,20 @@ export declare const PrismaClient: any
*/
export declare type PrismaClient = any

export declare type PrismaClientExtends<ExtArgs extends runtime.Types.Extensions.Args = runtime.Types.Extensions.DefaultArgs> = {
export declare type PrismaClientExtends<
ExtArgs extends runtime.Types.Extensions.Args = runtime.Types.Extensions.DefaultArgs,
> = {
$extends: { extArgs: ExtArgs } & (<
R extends runtime.Types.Extensions.Args['result'] = {},
M extends runtime.Types.Extensions.Args['model'] = {},
Q extends runtime.Types.Extensions.Args['query'] = {},
C extends runtime.Types.Extensions.Args['client'] = {},
Args extends runtime.Types.Extensions.Args = { result: R; model: M; query: Q; client: C }
>(args: ((client: PrismaClientExtends<ExtArgs>) => { $extends: { extArgs: Args } }) | {
result?: R; model?: M; query?: Q; client?: C
}) => PrismaClientExtends<runtime.Types.Utils.PatchDeep<Args, ExtArgs>>)
R extends runtime.Types.Extensions.UserArgs['result'] = {},
M extends runtime.Types.Extensions.UserArgs['model'] = {},
Q extends runtime.Types.Extensions.UserArgs['query'] = {},
C extends runtime.Types.Extensions.UserArgs['client'] = {},
Args extends runtime.Types.Extensions.Args = runtime.Types.Extensions.InternalArgs<R, M, Q, C>,
>(
args:
| ((client: PrismaClientExtends<ExtArgs>) => { $extends: { extArgs: Args } })
| { name?: string; result?: R; model?: M; query?: Q; client?: C },
) => PrismaClientExtends<Args & ExtArgs>)
}

export declare const dmmf: any
Expand All @@ -62,12 +65,21 @@ export namespace Prisma {
export type TransactionClient = any

export function defineExtension<
R extends runtime.Types.Extensions.Args['result'] = {},
M extends runtime.Types.Extensions.Args['model'] = {},
Q extends runtime.Types.Extensions.Args['query'] = {},
C extends runtime.Types.Extensions.Args['client'] = {},
Args extends runtime.Types.Extensions.Args = { result: R; model: M; query: Q; client: C }
>(args: ((client: PrismaClientExtends) => { $extends: { extArgs: Args } }) | {
result?: R; model?: M; query?: Q; client?: C
}): (client: any) => PrismaClientExtends<Args>
R extends runtime.Types.Extensions.UserArgs['result'] = {},
M extends runtime.Types.Extensions.UserArgs['model'] = {},
Q extends runtime.Types.Extensions.UserArgs['query'] = {},
C extends runtime.Types.Extensions.UserArgs['client'] = {},
Args extends runtime.Types.Extensions.Args = runtime.Types.Extensions.InternalArgs<R, M, Q, C>,
>(
args:
| ((client: PrismaClientExtends) => { $extends: { extArgs: Args } })
| { name?: string; result?: R; model?: M; query?: Q; client?: C },
): (client: any) => PrismaClientExtends<Args>

export type Extension = runtime.Types.Extensions.UserArgs
export import getExtensionContext = runtime.Extensions.getExtensionContext
export type Args<T, F extends runtime.Types.Public.Operation> = runtime.Types.Public.Args<T, F> & {}
export type Payload<T, F extends runtime.Types.Public.Operation> = runtime.Types.Public.Payload<T, F> & {}
export type Result<T, A, F extends runtime.Types.Public.Operation> = runtime.Types.Public.Result<T, A, F> & {}
export type Exact<T, W> = runtime.Types.Public.Exact<T, W> & {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1243,19 +1243,11 @@ export namespace Prisma {

export type Keys<U extends Union> = U extends unknown ? keyof U : never

type Exact<A, W = unknown> =
W extends unknown ? A extends Narrowable ? Cast<A, W> : Cast<
{[K in keyof A]: K extends keyof W ? Exact<A[K], W[K]> : never},
{[K in keyof W]: K extends keyof A ? Exact<A[K], W[K]> : W[K]}>
: never;

type Narrowable = string | number | boolean | bigint;

type Cast<A, B> = A extends B ? A : B;

export const type: unique symbol;

export function validator<V>(): <S>(select: Exact<S, V>) => S;
export function validator<V>(): <S>(select: runtime.Types.Utils.LegacyExact<S, V>) => S;

/**
* Used by group by
Expand Down Expand Up @@ -1762,6 +1754,7 @@ export namespace Prisma {




}

/**
Expand Down Expand Up @@ -1872,6 +1865,7 @@ export namespace Prisma {




}

/**
Expand Down Expand Up @@ -2136,13 +2130,13 @@ export namespace Prisma {
: Post


type PostCountArgs = Merge<
type PostCountArgs =
Omit<PostFindManyArgs, 'select' | 'include'> & {
select?: PostCountAggregateInputType | true
}
>

export interface PostDelegate<GlobalRejectSettings extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined> {

/**
* Find zero or one Post that matches the filter.
* @param {PostFindUniqueArgs} args - Arguments to find a Post
Expand Down Expand Up @@ -3251,13 +3245,13 @@ export namespace Prisma {
: User


type UserCountArgs = Merge<
type UserCountArgs =
Omit<UserFindManyArgs, 'select' | 'include'> & {
select?: UserCountAggregateInputType | true
}
>

export interface UserDelegate<GlobalRejectSettings extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined> {

/**
* Find zero or one User that matches the filter.
* @param {UserFindUniqueArgs} args - Arguments to find a User
Expand Down Expand Up @@ -4265,13 +4259,13 @@ export namespace Prisma {
: EmbedHolder


type EmbedHolderCountArgs = Merge<
type EmbedHolderCountArgs =
Omit<EmbedHolderFindManyArgs, 'select' | 'include'> & {
select?: EmbedHolderCountAggregateInputType | true
}
>

export interface EmbedHolderDelegate<GlobalRejectSettings extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined> {

/**
* Find zero or one EmbedHolder that matches the filter.
* @param {EmbedHolderFindUniqueArgs} args - Arguments to find a EmbedHolder
Expand Down Expand Up @@ -5391,13 +5385,13 @@ export namespace Prisma {
: M


type MCountArgs = Merge<
type MCountArgs =
Omit<MFindManyArgs, 'select' | 'include'> & {
select?: MCountAggregateInputType | true
}
>

export interface MDelegate<GlobalRejectSettings extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined> {

/**
* Find zero or one M that matches the filter.
* @param {MFindUniqueArgs} args - Arguments to find a M
Expand Down Expand Up @@ -6511,13 +6505,13 @@ export namespace Prisma {
: N


type NCountArgs = Merge<
type NCountArgs =
Omit<NFindManyArgs, 'select' | 'include'> & {
select?: NCountAggregateInputType | true
}
>

export interface NDelegate<GlobalRejectSettings extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined> {

/**
* Find zero or one N that matches the filter.
* @param {NFindUniqueArgs} args - Arguments to find a N
Expand Down Expand Up @@ -7627,13 +7621,13 @@ export namespace Prisma {
: OneOptional


type OneOptionalCountArgs = Merge<
type OneOptionalCountArgs =
Omit<OneOptionalFindManyArgs, 'select' | 'include'> & {
select?: OneOptionalCountAggregateInputType | true
}
>

export interface OneOptionalDelegate<GlobalRejectSettings extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined> {

/**
* Find zero or one OneOptional that matches the filter.
* @param {OneOptionalFindUniqueArgs} args - Arguments to find a OneOptional
Expand Down Expand Up @@ -8747,13 +8741,13 @@ export namespace Prisma {
: ManyRequired


type ManyRequiredCountArgs = Merge<
type ManyRequiredCountArgs =
Omit<ManyRequiredFindManyArgs, 'select' | 'include'> & {
select?: ManyRequiredCountAggregateInputType | true
}
>

export interface ManyRequiredDelegate<GlobalRejectSettings extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined> {

/**
* Find zero or one ManyRequired that matches the filter.
* @param {ManyRequiredFindUniqueArgs} args - Arguments to find a ManyRequired
Expand Down Expand Up @@ -9846,13 +9840,13 @@ export namespace Prisma {
: OptionalSide1


type OptionalSide1CountArgs = Merge<
type OptionalSide1CountArgs =
Omit<OptionalSide1FindManyArgs, 'select' | 'include'> & {
select?: OptionalSide1CountAggregateInputType | true
}
>

export interface OptionalSide1Delegate<GlobalRejectSettings extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined> {

/**
* Find zero or one OptionalSide1 that matches the filter.
* @param {OptionalSide1FindUniqueArgs} args - Arguments to find a OptionalSide1
Expand Down Expand Up @@ -10937,13 +10931,13 @@ export namespace Prisma {
: OptionalSide2


type OptionalSide2CountArgs = Merge<
type OptionalSide2CountArgs =
Omit<OptionalSide2FindManyArgs, 'select' | 'include'> & {
select?: OptionalSide2CountAggregateInputType | true
}
>

export interface OptionalSide2Delegate<GlobalRejectSettings extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined> {

/**
* Find zero or one OptionalSide2 that matches the filter.
* @param {OptionalSide2FindUniqueArgs} args - Arguments to find a OptionalSide2
Expand Down Expand Up @@ -11968,13 +11962,13 @@ export namespace Prisma {
: A


type ACountArgs = Merge<
type ACountArgs =
Omit<AFindManyArgs, 'select' | 'include'> & {
select?: ACountAggregateInputType | true
}
>

export interface ADelegate<GlobalRejectSettings extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined> {

/**
* Find zero or one A that matches the filter.
* @param {AFindUniqueArgs} args - Arguments to find a A
Expand Down Expand Up @@ -12930,13 +12924,13 @@ export namespace Prisma {
: B


type BCountArgs = Merge<
type BCountArgs =
Omit<BFindManyArgs, 'select' | 'include'> & {
select?: BCountAggregateInputType | true
}
>

export interface BDelegate<GlobalRejectSettings extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined> {

/**
* Find zero or one B that matches the filter.
* @param {BFindUniqueArgs} args - Arguments to find a B
Expand Down Expand Up @@ -13886,13 +13880,13 @@ export namespace Prisma {
: C


type CCountArgs = Merge<
type CCountArgs =
Omit<CFindManyArgs, 'select' | 'include'> & {
select?: CCountAggregateInputType | true
}
>

export interface CDelegate<GlobalRejectSettings extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined> {

/**
* Find zero or one C that matches the filter.
* @param {CFindUniqueArgs} args - Arguments to find a C
Expand Down Expand Up @@ -14864,13 +14858,13 @@ export namespace Prisma {
: D


type DCountArgs = Merge<
type DCountArgs =
Omit<DFindManyArgs, 'select' | 'include'> & {
select?: DCountAggregateInputType | true
}
>

export interface DDelegate<GlobalRejectSettings extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined> {

/**
* Find zero or one D that matches the filter.
* @param {DFindUniqueArgs} args - Arguments to find a D
Expand Down Expand Up @@ -15796,13 +15790,13 @@ export namespace Prisma {
: E


type ECountArgs = Merge<
type ECountArgs =
Omit<EFindManyArgs, 'select' | 'include'> & {
select?: ECountAggregateInputType | true
}
>

export interface EDelegate<GlobalRejectSettings extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined> {

/**
* Find zero or one E that matches the filter.
* @param {EFindUniqueArgs} args - Arguments to find a E
Expand Down

0 comments on commit 7716c77

Please sign in to comment.