@@ -40,9 +40,15 @@ import type {
4040 UpdateManyArgs ,
4141 UpsertArgs ,
4242} from './crud-types' ;
43- import type { CoreCrudOperations } from './crud/operations/base' ;
43+ import type {
44+ CoreCreateOperations ,
45+ CoreCrudOperations ,
46+ CoreDeleteOperations ,
47+ CoreReadOperations ,
48+ CoreUpdateOperations ,
49+ } from './crud/operations/base' ;
4450import type { ClientOptions , QueryOptions , ToQueryOptions } from './options' ;
45- import type { ExtQueryArgsBase , RuntimePlugin } from './plugin' ;
51+ import type { ExtClientMembersBase , ExtQueryArgsBase , RuntimePlugin } from './plugin' ;
4652import type { ZenStackPromise } from './promise' ;
4753import type { ToKysely } from './query-builder' ;
4854
@@ -51,11 +57,26 @@ type TransactionUnsupportedMethods = (typeof TRANSACTION_UNSUPPORTED_METHODS)[nu
5157/**
5258 * Extracts extended query args for a specific operation.
5359 */
54- type ExtractExtQueryArgs < ExtQueryArgs , Operation extends CoreCrudOperations > = Operation extends keyof ExtQueryArgs
55- ? NonNullable < ExtQueryArgs [ Operation ] >
56- : 'all' extends keyof ExtQueryArgs
57- ? NonNullable < ExtQueryArgs [ 'all' ] >
58- : { } ;
60+ type ExtractExtQueryArgs < ExtQueryArgs , Operation extends CoreCrudOperations > = ( Operation extends keyof ExtQueryArgs
61+ ? ExtQueryArgs [ Operation ]
62+ : { } ) &
63+ ( '$create' extends keyof ExtQueryArgs
64+ ? Operation extends CoreCreateOperations
65+ ? ExtQueryArgs [ '$create' ]
66+ : { }
67+ : { } ) &
68+ ( '$read' extends keyof ExtQueryArgs ? ( Operation extends CoreReadOperations ? ExtQueryArgs [ '$read' ] : { } ) : { } ) &
69+ ( '$update' extends keyof ExtQueryArgs
70+ ? Operation extends CoreUpdateOperations
71+ ? ExtQueryArgs [ '$update' ]
72+ : { }
73+ : { } ) &
74+ ( '$delete' extends keyof ExtQueryArgs
75+ ? Operation extends CoreDeleteOperations
76+ ? ExtQueryArgs [ '$delete' ]
77+ : { }
78+ : { } ) &
79+ ( '$all' extends keyof ExtQueryArgs ? ExtQueryArgs [ '$all' ] : { } ) ;
5980
6081/**
6182 * Transaction isolation levels.
@@ -75,6 +96,7 @@ export type ClientContract<
7596 Schema extends SchemaDef ,
7697 Options extends ClientOptions < Schema > = ClientOptions < Schema > ,
7798 ExtQueryArgs extends ExtQueryArgsBase = { } ,
99+ ExtClientMembers extends ExtClientMembersBase = { } ,
78100> = {
79101 /**
80102 * The schema definition.
@@ -132,7 +154,7 @@ export type ClientContract<
132154 /**
133155 * Sets the current user identity.
134156 */
135- $setAuth ( auth : AuthType < Schema > | undefined ) : ClientContract < Schema , Options , ExtQueryArgs > ;
157+ $setAuth ( auth : AuthType < Schema > | undefined ) : ClientContract < Schema , Options , ExtQueryArgs , ExtClientMembers > ;
136158
137159 /**
138160 * Returns a new client with new options applied.
@@ -141,15 +163,17 @@ export type ClientContract<
141163 * const dbNoValidation = db.$setOptions({ ...db.$options, validateInput: false });
142164 * ```
143165 */
144- $setOptions < Options extends ClientOptions < Schema > > ( options : Options ) : ClientContract < Schema , Options , ExtQueryArgs > ;
166+ $setOptions < NewOptions extends ClientOptions < Schema > > (
167+ options : NewOptions ,
168+ ) : ClientContract < Schema , NewOptions , ExtQueryArgs , ExtClientMembers > ;
145169
146170 /**
147171 * Returns a new client enabling/disabling input validations expressed with attributes like
148172 * `@email`, `@regex`, `@@validate`, etc.
149173 *
150174 * @deprecated Use {@link $setOptions} instead.
151175 */
152- $setInputValidation ( enable : boolean ) : ClientContract < Schema , Options , ExtQueryArgs > ;
176+ $setInputValidation ( enable : boolean ) : ClientContract < Schema , Options , ExtQueryArgs , ExtClientMembers > ;
153177
154178 /**
155179 * The Kysely query builder instance.
@@ -165,7 +189,7 @@ export type ClientContract<
165189 * Starts an interactive transaction.
166190 */
167191 $transaction < T > (
168- callback : ( tx : TransactionClientContract < Schema , Options , ExtQueryArgs > ) => Promise < T > ,
192+ callback : ( tx : TransactionClientContract < Schema , Options , ExtQueryArgs , ExtClientMembers > ) => Promise < T > ,
169193 options ?: { isolationLevel ?: TransactionIsolationLevel } ,
170194 ) : Promise < T > ;
171195
@@ -180,14 +204,18 @@ export type ClientContract<
180204 /**
181205 * Returns a new client with the specified plugin installed.
182206 */
183- $use < PluginSchema extends SchemaDef = Schema , PluginExtQueryArgs extends ExtQueryArgsBase = { } > (
184- plugin : RuntimePlugin < PluginSchema , PluginExtQueryArgs > ,
185- ) : ClientContract < Schema , Options , ExtQueryArgs & PluginExtQueryArgs > ;
207+ $use <
208+ PluginSchema extends SchemaDef = Schema ,
209+ PluginExtQueryArgs extends ExtQueryArgsBase = { } ,
210+ PluginExtClientMembers extends ExtClientMembersBase = { } ,
211+ > (
212+ plugin : RuntimePlugin < PluginSchema , PluginExtQueryArgs , PluginExtClientMembers > ,
213+ ) : ClientContract < Schema , Options , ExtQueryArgs & PluginExtQueryArgs , ExtClientMembers & PluginExtClientMembers > ;
186214
187215 /**
188216 * Returns a new client with the specified plugin removed.
189217 */
190- $unuse ( pluginId : string ) : ClientContract < Schema , Options , ExtQueryArgs > ;
218+ $unuse ( pluginId : string ) : ClientContract < Schema , Options , ExtQueryArgs , ExtClientMembers > ;
191219
192220 /**
193221 * Returns a new client with all plugins removed.
@@ -216,7 +244,8 @@ export type ClientContract<
216244 ToQueryOptions < Options > ,
217245 ExtQueryArgs
218246 > ;
219- } & ProcedureOperations < Schema > ;
247+ } & ProcedureOperations < Schema > &
248+ ExtClientMembers ;
220249
221250/**
222251 * The contract for a client in a transaction.
@@ -225,7 +254,8 @@ export type TransactionClientContract<
225254 Schema extends SchemaDef ,
226255 Options extends ClientOptions < Schema > ,
227256 ExtQueryArgs extends ExtQueryArgsBase ,
228- > = Omit < ClientContract < Schema , Options , ExtQueryArgs > , TransactionUnsupportedMethods > ;
257+ ExtClientMembers extends ExtClientMembersBase ,
258+ > = Omit < ClientContract < Schema , Options , ExtQueryArgs , ExtClientMembers > , TransactionUnsupportedMethods > ;
229259
230260export type ProcedureOperations < Schema extends SchemaDef > =
231261 Schema [ 'procedures' ] extends Record < string , ProcedureDef >
0 commit comments