Skip to content

Commit

Permalink
feat!: rename execute to interceptor hook
Browse files Browse the repository at this point in the history
  • Loading branch information
unnoq committed Dec 28, 2024
1 parent 11a25ed commit 9588d75
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/client/action-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function useAction<TInput, TOutput>(
const output = await executeWithHooks({
context: undefined,
hooks: {
execute: [...convertToArray(hooks?.execute), ...convertToArray(executeHooks?.execute)],
interceptor: [...convertToArray(hooks?.interceptor), ...convertToArray(executeHooks?.interceptor)],
onStart: [...convertToArray(hooks?.onStart), ...convertToArray(executeHooks?.onStart)],
onSuccess: [...convertToArray(hooks?.onSuccess), ...convertToArray(executeHooks?.onSuccess)],
onError: [...convertToArray(hooks?.onError), ...convertToArray(executeHooks?.onError)],
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/procedure-client.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('createProcedureClient', () => {
createProcedureClient({
procedure,

async execute(input, context, meta) {
async interceptor(input, context, meta) {
expectTypeOf(input).toEqualTypeOf<unknown>()
expectTypeOf(context).toEqualTypeOf<WELL_CONTEXT>()
expectTypeOf(meta).toEqualTypeOf<Meta & { next: () => Promise<{ val: number }> }>()
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/procedure-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ describe.each(procedureCases)('createProcedureClient - case %s', async (_, proce
procedure,
context,
path: ['users'],
execute,
interceptor: execute,
onStart,
onSuccess,
onError,
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/router-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('createRouterClient', () => {
const onSuccess = vi.fn()
const onError = vi.fn()
const onFinish = vi.fn()
const execute = vi.fn()
const interceptor = vi.fn()

const client = createRouterClient({
router,
Expand All @@ -126,7 +126,7 @@ describe('createRouterClient', () => {
onSuccess,
onError,
onFinish,
execute,
interceptor,
})

expect(client.pong({ val: '123' })).toEqual('__mocked__')
Expand All @@ -140,7 +140,7 @@ describe('createRouterClient', () => {
onSuccess,
onError,
onFinish,
execute,
interceptor,
}))
})

Expand Down
6 changes: 3 additions & 3 deletions packages/shared/src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface BaseHookMeta<TOutput> {
}

export interface Hooks<TInput, TOutput, TContext, TMeta extends (Record<string, any> & { next?: never }) | undefined> {
execute?: Arrayable<(input: TInput, context: TContext, meta: (TMeta extends undefined ? unknown : TMeta) & BaseHookMeta<TOutput>) => Promise<TOutput>>
interceptor?: Arrayable<(input: TInput, context: TContext, meta: (TMeta extends undefined ? unknown : TMeta) & BaseHookMeta<TOutput>) => Promise<TOutput>>
onStart?: Arrayable<(state: OnStartState<TInput>, context: TContext, meta: TMeta) => Promisable<void>>
onSuccess?: Arrayable<(state: OnSuccessState<TInput, TOutput>, context: TContext, meta: TMeta) => Promisable<void>>
onError?: Arrayable<(state: OnErrorState<TInput>, context: TContext, meta: TMeta) => Promisable<void>>
Expand All @@ -26,7 +26,7 @@ export async function executeWithHooks<TInput, TOutput, TContext, TMeta extends
execute: BaseHookMeta<TOutput>['next']
},
): Promise<TOutput> {
const executes = convertToArray(options.hooks?.execute)
const interceptors = convertToArray(options.hooks?.interceptor)
const onStarts = convertToArray(options.hooks?.onStart)
const onSuccesses = convertToArray(options.hooks?.onSuccess)
const onErrors = convertToArray(options.hooks?.onError)
Expand All @@ -35,7 +35,7 @@ export async function executeWithHooks<TInput, TOutput, TContext, TMeta extends
let currentExecuteIndex = 0

const next = async (): Promise<TOutput> => {
const execute = executes[currentExecuteIndex]
const execute = interceptors[currentExecuteIndex]

if (execute) {
currentExecuteIndex++
Expand Down

0 comments on commit 9588d75

Please sign in to comment.