Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions packages/orm/src/client/client-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import type { ProcedureDef, SchemaDef } from '../schema';
import type { AnyKysely } from '../utils/kysely-utils';
import type { UnwrapTuplePromises } from '../utils/type-utils';
import type { ClientOptions, ProceduresOptions } from './options';
import type {
AuthType,
ClientConstructor,
Expand All @@ -21,13 +22,13 @@ import type {
TransactionIsolationLevel,
} from './contract';
import { AggregateOperationHandler } from './crud/operations/aggregate';
import type { AllCrudOperation, CoreCrudOperation } from './crud/operations/base';
import type { AllCrudOperations, CoreCrudOperations } from './crud/operations/base';
import { BaseOperationHandler } from './crud/operations/base';
import { CountOperationHandler } from './crud/operations/count';
import { CreateOperationHandler } from './crud/operations/create';
import { DeleteOperationHandler } from './crud/operations/delete';
import { FindOperationHandler } from './crud/operations/find';
import { ExistsOperationHandler } from './crud/operations/exists';
import { FindOperationHandler } from './crud/operations/find';
import { GroupByOperationHandler } from './crud/operations/group-by';
import { UpdateOperationHandler } from './crud/operations/update';
import { InputValidator } from './crud/validator';
Expand All @@ -36,7 +37,6 @@ import { ZenStackDriver } from './executor/zenstack-driver';
import { ZenStackQueryExecutor } from './executor/zenstack-query-executor';
import * as BuiltinFunctions from './functions';
import { SchemaDbPusher } from './helpers/schema-db-pusher';
import type { ClientOptions, ProceduresOptions } from './options';
import type { RuntimePlugin } from './plugin';
import { createZenStackPromise, type ZenStackPromise } from './promise';
import { ResultProcessor } from './result-processor';
Expand Down Expand Up @@ -292,9 +292,9 @@ export class ClientImpl {
await new SchemaDbPusher(this.schema, this.kysely).push();
}

$use(plugin: RuntimePlugin<SchemaDef>) {
$use(plugin: RuntimePlugin<any, any>) {
// tsc perf
const newPlugins: RuntimePlugin<SchemaDef>[] = [...(this.$options.plugins ?? []), plugin];
const newPlugins: RuntimePlugin<any, any>[] = [...(this.$options.plugins ?? []), plugin];
const newOptions: ClientOptions<SchemaDef> = {
...this.options,
plugins: newPlugins,
Expand All @@ -304,7 +304,7 @@ export class ClientImpl {

$unuse(pluginId: string) {
// tsc perf
const newPlugins: RuntimePlugin<SchemaDef>[] = [];
const newPlugins: RuntimePlugin<any, any>[] = [];
for (const plugin of this.options.plugins ?? []) {
if (plugin.id !== pluginId) {
newPlugins.push(plugin);
Expand All @@ -321,7 +321,7 @@ export class ClientImpl {
// tsc perf
const newOptions: ClientOptions<SchemaDef> = {
...this.options,
plugins: [] as RuntimePlugin<SchemaDef>[],
plugins: [] as RuntimePlugin<any, any>[],
};
return new ClientImpl(this.schema, newOptions, this);
}
Expand Down Expand Up @@ -419,8 +419,8 @@ function createModelCrudHandler(
resultProcessor: ResultProcessor<any>,
): ModelOperations<any, any> {
const createPromise = (
operation: CoreCrudOperation,
nominalOperation: AllCrudOperation,
operation: CoreCrudOperations,
nominalOperation: AllCrudOperations,
args: unknown,
handler: BaseOperationHandler<any>,
postProcess = false,
Expand Down Expand Up @@ -448,16 +448,18 @@ function createModelCrudHandler(
const onQuery = plugin.onQuery;
if (onQuery) {
const _proceed = proceed;
proceed = (_args: unknown) =>
onQuery({
proceed = (_args: unknown) => {
const ctx: any = {
client,
model,
operation: nominalOperation,
// reflect the latest override if provided
args: _args,
// ensure inner overrides are propagated to the previous proceed
proceed: (nextArgs: unknown) => _proceed(nextArgs),
}) as Promise<unknown>;
};
return (onQuery as (ctx: any) => Promise<unknown>)(ctx);
};
}
}

Expand Down Expand Up @@ -516,6 +518,7 @@ function createModelCrudHandler(
args,
new FindOperationHandler<any>(client, model, inputValidator),
true,
false,
);
},

Expand Down
Loading
Loading