import { AsyncCallNotify } from '../utils/internalSymbol.ts' import { isFunction } from '../utils/constants.ts' /** * Make the returning type to `Promise` * @internal * @remarks * Due to the limitation of TypeScript, generic signatures cannot be preserved * if the function is the top level parameter of this utility type, * or the function is not returning `Promise`. */ export type _IgnoreResponse = T extends (...args: infer Args) => unknown ? (...args: Args) => Promise : { [key in keyof T as T[key] extends Function ? key : never]: T[key] extends ( ...args: infer Args ) => infer Return ? Return extends Promise ? T[key] : (...args: Args) => Promise : never } /** * Wrap the AsyncCall instance to send notification. * @param instanceOrFnOnInstance - The AsyncCall instance or function on the AsyncCall instance * @example * const notifyOnly = notify(AsyncCall(...)) * @public */ export function notify(instanceOrFnOnInstance: T): _IgnoreResponse { if (isFunction(instanceOrFnOnInstance)) return (instanceOrFnOnInstance as any)[AsyncCallNotify] return new Proxy(instanceOrFnOnInstance, { get: notifyTrap }) as any } const notifyTrap = (target: any, p: string | number | symbol) => { return target[p][AsyncCallNotify] }