@contrast/patcher
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -16,18 +16,58 @@ /* | ||
// import { Core } from '@contrast/core'; | ||
import { Logger } from '@contrast/logger'; | ||
// TODO | ||
interface Core { | ||
logger: Logger; | ||
} | ||
interface HookData<T, P extends readonly any[] = any[], R = any> { | ||
hooked(...args: P): R; | ||
orig(...args: P): R; | ||
funcKey: string; | ||
obj: T; | ||
name: string; | ||
args: P; | ||
} | ||
interface ResultHookData<T, P extends readonly any[] = any[], R = any> | ||
extends HookData<T, P, R> { | ||
result: R; | ||
} | ||
interface PatchOptions<T, P extends readonly any[] = any[], R = any> { | ||
name: string; | ||
patchType: string; | ||
pre?(data: HookData<T, P, R>): void; | ||
around?(next: () => void, data: HookData<T, P, R>): void; | ||
post?(data: ResultHookData<T, P, R>): void; | ||
} | ||
export interface Patcher { | ||
patch: (obj: function | class | { [key: string]: any }, prop: string, options: { name: string, | ||
patchType: string, pre?: function, around?: function, post?: function }) => function | class | { [key: string]: any }, | ||
resetInstrumentation: () => void, | ||
unpatch: (fn: function, funcName: string, patchType: string) => void, | ||
unwrap: (fn: function) => function | ||
isContrastHooked: (fn: function) => boolean | ||
hookedFunctionToString: (fn: function) => string | ||
hookedFunctions: WeakMap<K<function>, V<{ fn: function }>> | ||
patch<T extends (...args: any[]) => any>( | ||
fn: T, | ||
options: PatchOptions<T, Parameters<T>, ReturnType<T>>, | ||
): T | null; | ||
patch<T, K extends keyof T>( | ||
obj: T, | ||
method: K, | ||
options: T[K] extends (...args: infer P) => infer R | ||
? PatchOptions<T, P, R> | ||
: PatchOptions<T>, | ||
): T | null; | ||
resetInstrumentation(): void; | ||
unpatch<T extends (...args: any[]) => any>( | ||
fn: T, | ||
funcName: string, | ||
patchType: string, | ||
): void; | ||
unwrap<T extends (...args: any[]) => any>(fn: T): T; | ||
isContrastHooked<T extends (...args: any[]) => any>(fn: T): boolean; | ||
hookedFunctionToString<T extends (...args: any[]) => any>(fn: T): string; | ||
hookedFunctions: WeakMap<(...args: any[]) => any, (...args: any[]) => any>; | ||
} | ||
declare function init(core: any): Patcher; | ||
declare function init(core: Core): Patcher; | ||
export default init; |
{ | ||
"name": "@contrast/patcher", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Advanced monkey patching--registers hooks to run in and around functions", | ||
@@ -5,0 +5,0 @@ "license": "SEE LICENSE IN LICENSE", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18863
456