@reffuse/extension-query 0.1.4 #15

Merged
Thilawyn merged 340 commits from next into master 2025-05-26 04:15:01 +02:00
Showing only changes of commit 58752253b3 - Show all commits

View File

@@ -1,3 +1,6 @@
import { Option, Predicate } from "effect"
export type Paths<T> = T extends object export type Paths<T> = T extends object
? { ? {
[K in keyof T as K extends string | number | symbol ? K : never]: [K in keyof T as K extends string | number | symbol ? K : never]:
@@ -26,9 +29,19 @@ const persons = [
] ]
const getFromPath = <T, const P extends Paths<T>>(value: T, path: P): ValueFromPath<T, P> => ( export const get = <T, const P extends Paths<T>>(parent: T, path: P): Option.Option<ValueFromPath<T, P>> => path.reduce(
path.reduce((acc: any, key: any) => acc?.[key], value) (acc: Option.Option<any>, key: any): Option.Option<any> => Option.isSome(acc)
? Predicate.hasProperty(acc.value, key)
? Option.some(acc.value[key])
: Option.none()
: acc,
Option.some(parent),
) )
const res = getFromPath(persons, [1, "name"]) export const getOrUndefined = <T, const P extends Paths<T>>(parent: T, path: P): ValueFromPath<T, P> => (
path.reduce((acc: any, key: any) => acc?.[key], parent)
)
const res = get(persons, [1, "name"])
console.log(res) console.log(res)