feat(lib/patcher/types): export UnpatchFunction

This commit is contained in:
PalmDevs 2025-07-13 15:47:45 +07:00
parent 37a20160db
commit 709a944d49
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
4 changed files with 21 additions and 8 deletions

View file

@ -4,7 +4,12 @@ import {
unproxy, unproxy,
} from '../_internal' } from '../_internal'
import type { HookNode, PatchedFunctionProxyState } from '../_internal' import type { HookNode, PatchedFunctionProxyState } from '../_internal'
import type { AfterHook, FiniteDomain, UnknownFunction } from '../types' import type {
AfterHook,
FiniteDomain,
UnknownFunction,
UnpatchFunction,
} from '../types'
function unpatchAfter<T extends UnknownFunction>( function unpatchAfter<T extends UnknownFunction>(
state: PatchedFunctionProxyState<PropertyKey, T>, state: PatchedFunctionProxyState<PropertyKey, T>,
@ -63,12 +68,12 @@ function unpatchAfter<T extends UnknownFunction>(
export function after< export function after<
Parent extends Record<Key, UnknownFunction>, Parent extends Record<Key, UnknownFunction>,
Key extends keyof Parent, Key extends keyof Parent,
>(parent: Parent, key: Key, hook: AfterHook<Parent[Key]>): () => void >(parent: Parent, key: Key, hook: AfterHook<Parent[Key]>): UnpatchFunction
export function after<Key extends PropertyKey, Value extends UnknownFunction>( export function after<Key extends PropertyKey, Value extends UnknownFunction>(
parent: Record<Key, Value>, parent: Record<Key, Value>,
key: FiniteDomain<Key>, key: FiniteDomain<Key>,
hook: AfterHook<Value>, hook: AfterHook<Value>,
) { ): UnpatchFunction {
const target = parent[key] const target = parent[key]
let state = patchedFunctionProxyStates.get(target) let state = patchedFunctionProxyStates.get(target)

View file

@ -4,7 +4,12 @@ import {
unproxy, unproxy,
} from '../_internal' } from '../_internal'
import type { HookNode, PatchedFunctionProxyState } from '../_internal' import type { HookNode, PatchedFunctionProxyState } from '../_internal'
import type { BeforeHook, FiniteDomain, UnknownFunction } from '../types' import type {
BeforeHook,
FiniteDomain,
UnknownFunction,
UnpatchFunction,
} from '../types'
function unpatchBefore<T extends UnknownFunction>( function unpatchBefore<T extends UnknownFunction>(
state: PatchedFunctionProxyState<PropertyKey, T>, state: PatchedFunctionProxyState<PropertyKey, T>,
@ -63,12 +68,12 @@ function unpatchBefore<T extends UnknownFunction>(
export function before< export function before<
Parent extends Record<Key, UnknownFunction>, Parent extends Record<Key, UnknownFunction>,
Key extends keyof Parent, Key extends keyof Parent,
>(parent: Parent, key: Key, hook: BeforeHook<Parent[Key]>): () => void >(parent: Parent, key: Key, hook: BeforeHook<Parent[Key]>): UnpatchFunction
export function before<Key extends PropertyKey, Value extends UnknownFunction>( export function before<Key extends PropertyKey, Value extends UnknownFunction>(
parent: Record<Key, Value>, parent: Record<Key, Value>,
key: FiniteDomain<Key>, key: FiniteDomain<Key>,
hook: BeforeHook<Value>, hook: BeforeHook<Value>,
) { ): UnpatchFunction {
const target = parent[key] const target = parent[key]
let state = patchedFunctionProxyStates.get(target) let state = patchedFunctionProxyStates.get(target)

View file

@ -15,6 +15,7 @@ import type {
FiniteDomain, FiniteDomain,
InsteadHook, InsteadHook,
UnknownFunction, UnknownFunction,
UnpatchFunction,
} from '../types' } from '../types'
const insteadHookProxyHandler = { const insteadHookProxyHandler = {
@ -110,12 +111,12 @@ function unpatchInstead<T extends UnknownFunction>(
export function instead< export function instead<
Parent extends Record<Key, UnknownFunction>, Parent extends Record<Key, UnknownFunction>,
Key extends keyof Parent, Key extends keyof Parent,
>(parent: Parent, key: Key, hook: InsteadHook<Parent[Key]>): () => void >(parent: Parent, key: Key, hook: InsteadHook<Parent[Key]>): UnpatchFunction
export function instead<Key extends PropertyKey, Value extends UnknownFunction>( export function instead<Key extends PropertyKey, Value extends UnknownFunction>(
parent: Record<Key, Value>, parent: Record<Key, Value>,
key: FiniteDomain<Key>, key: FiniteDomain<Key>,
hook: InsteadHook<Value>, hook: InsteadHook<Value>,
) { ): UnpatchFunction {
const target = parent[key] const target = parent[key]
let state = patchedFunctionProxyStates.get(target) let state = patchedFunctionProxyStates.get(target)

View file

@ -222,3 +222,5 @@ export type OverloadUnionNewableInner<
ConcreteNewable<Args, Return> ConcreteNewable<Args, Return>
> >
: never : never
export type UnpatchFunction = () => void