rearchitecting wip

This commit is contained in:
MapleLeaf
2021-12-16 19:01:37 -06:00
parent ffc91900d2
commit 460e7cde1a
16 changed files with 224 additions and 289 deletions

10
packages/helpers/pick.ts Normal file
View 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
}

View File

@@ -1 +1,5 @@
export type MaybePromise<T> = T | Promise<T>
export type ValueOf<Type> = Type extends ReadonlyArray<infer Value>
? Value
: Type[keyof Type]

View 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
}