This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { type HashMap, Pipeable, Predicate, type Subscribable, type SubscriptionRef } from "effect"
|
||||
import { Equal, Equivalence, Hash, type HashMap, Pipeable, Predicate, type Ref } from "effect"
|
||||
import type * as Query from "./Query.js"
|
||||
import type * as Result from "./Result.js"
|
||||
|
||||
@@ -9,17 +9,35 @@ export type QueryClientTypeId = typeof QueryClientTypeId
|
||||
export interface QueryClient extends Pipeable.Pipeable {
|
||||
readonly [QueryClientTypeId]: QueryClientTypeId
|
||||
|
||||
readonly cache: Subscribable.Subscribable<HashMap.HashMap<Query.Query.AnyKey, Result.Final<unknown, unknown, unknown>>>
|
||||
readonly cache: Ref.Ref<HashMap.HashMap<Query.Query.AnyKey, Result.Final<unknown, unknown, unknown>>>
|
||||
}
|
||||
|
||||
export class QueryClientImpl extends Pipeable.Class() implements QueryClient {
|
||||
readonly [QueryClientTypeId]: QueryClientTypeId = QueryClientTypeId
|
||||
|
||||
constructor(
|
||||
readonly cache: SubscriptionRef.SubscriptionRef<HashMap.HashMap<Query.Query.AnyKey, Result.Final<unknown, unknown, unknown>>>
|
||||
readonly cache: Ref.Ref<HashMap.HashMap<Query.Query.AnyKey, Result.Final<unknown, unknown, unknown>>>
|
||||
) {
|
||||
super()
|
||||
}
|
||||
}
|
||||
|
||||
export const isQueryClient = (u: unknown): u is QueryClient => Predicate.hasProperty(u, QueryClientTypeId)
|
||||
|
||||
|
||||
const QueryClientCacheKeyTypeId: unique symbol = Symbol.for("@effect-fc/QueryClient/QueryClientCacheKey")
|
||||
type QueryClientCacheKeyTypeId = typeof QueryClientCacheKeyTypeId
|
||||
|
||||
class QueryClientCacheKey implements Equal.Equal {
|
||||
readonly [QueryClientCacheKeyTypeId]: QueryClientCacheKeyTypeId = QueryClientCacheKeyTypeId
|
||||
constructor(readonly key: Query.Query.AnyKey) {}
|
||||
|
||||
[Equal.symbol](that: Equal.Equal) {
|
||||
return isQueryClientKey(that) && Equivalence.array(Equal.equivalence())(this.key, that.key)
|
||||
}
|
||||
[Hash.symbol]() {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
const isQueryClientKey = (u: unknown): u is QueryClientCacheKey => Predicate.hasProperty(u, QueryClientCacheKeyTypeId)
|
||||
|
||||
Reference in New Issue
Block a user