rearchitecting wip
This commit is contained in:
10
packages/helpers/pick.ts
Normal file
10
packages/helpers/pick.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export function pick<T, K extends keyof T>(
|
||||
object: T,
|
||||
...keys: K[]
|
||||
): Pick<T, K> {
|
||||
const result: any = {}
|
||||
for (const key of keys) {
|
||||
result[key] = object[key]
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -1 +1,5 @@
|
||||
export type MaybePromise<T> = T | Promise<T>
|
||||
|
||||
export type ValueOf<Type> = Type extends ReadonlyArray<infer Value>
|
||||
? Value
|
||||
: Type[keyof Type]
|
||||
|
||||
20
packages/helpers/with-logged-method-calls.ts
Normal file
20
packages/helpers/with-logged-method-calls.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { inspect } from "node:util"
|
||||
|
||||
export function withLoggedMethodCalls<T extends object>(value: T) {
|
||||
return new Proxy(value as Record<string | symbol, unknown>, {
|
||||
get(target, property) {
|
||||
const value = target[property]
|
||||
if (typeof value !== "function") {
|
||||
return value
|
||||
}
|
||||
return (...values: any[]) => {
|
||||
console.log(
|
||||
`${String(property)}(${values
|
||||
.map((value: any) => inspect(value))
|
||||
.join(", ")})`,
|
||||
)
|
||||
return value.apply(target, values)
|
||||
}
|
||||
},
|
||||
}) as T
|
||||
}
|
||||
Reference in New Issue
Block a user