feat(lib/utils/proxy): allow passing any hint to proxify

This commit is contained in:
PalmDevs 2025-06-08 18:48:43 +07:00
parent 3619993dc0
commit f453a82dab
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA

View file

@ -93,7 +93,7 @@ export interface ProxifyOptions {
*
* @default 'function'
*/
hint?: 'object' | 'function'
hint?: 'object' | 'function' | object
/**
* Whether the proxified value should be cached.
*/
@ -124,8 +124,22 @@ export interface ProxifyOptions {
* ```
*/
export function proxify<T>(signal: () => T, options?: ProxifyOptions): T {
// biome-ignore lint/complexity/useArrowFunction: We need a function with a constructor
const hint = (options?.hint === 'object' ? {} : function () {}) as any
let hint: any
switch (options?.hint) {
case undefined:
case 'function':
// biome-ignore lint/complexity/useArrowFunction: We need a function with a constructor
hint = function () {}
break
case 'object':
hint = {}
break
default:
hint = options!.hint
break
}
_metas.set(hint, [signal, options?.cache ?? false])
return new Proxy(hint, _handler)
}