diff --git a/packages/effect-fc-next/src/Mutation.ts b/packages/effect-fc-next/src/Mutation.ts index 5ae14d4..6ad8140 100644 --- a/packages/effect-fc-next/src/Mutation.ts +++ b/packages/effect-fc-next/src/Mutation.ts @@ -7,7 +7,7 @@ import type * as Subscribable from "./Subscribable.js" export const MutationTypeId: unique symbol = Symbol.for("@effect-fc/Mutation/Mutation") export type MutationTypeId = typeof MutationTypeId -export interface Mutation +export interface Mutation extends Pipeable.Pipeable { readonly [MutationTypeId]: MutationTypeId @@ -23,11 +23,10 @@ extends Pipeable.Pipeable { mutateSubscribable(key: K): Effect.Effect>> } -export declare namespace Mutation { - export type AnyKey = readonly any[] -} +export const isMutation = (u: unknown): u is Mutation => Predicate.hasProperty(u, MutationTypeId) -export class MutationImpl + +export class MutationImpl extends Pipeable.Class implements Mutation { readonly [MutationTypeId]: MutationTypeId = MutationTypeId @@ -129,16 +128,13 @@ extends Pipeable.Class implements Mutation { } -export const isMutation = (u: unknown): u is Mutation => Predicate.hasProperty(u, MutationTypeId) - - export declare namespace make { - export interface Options { + export interface Options { readonly f: (key: K) => Effect.Effect } } -export const make = Effect.fnUntraced(function* ( +export const make = Effect.fnUntraced(function* ( options: make.Options ): Effect.fn.Return< Mutation, diff --git a/packages/effect-fc-next/src/Query.ts b/packages/effect-fc-next/src/Query.ts index 27a6531..6e7d589 100644 --- a/packages/effect-fc-next/src/Query.ts +++ b/packages/effect-fc-next/src/Query.ts @@ -8,7 +8,7 @@ import * as Subscribable from "./Subscribable.js" export const QueryTypeId: unique symbol = Symbol.for("@effect-fc/Query/Query") export type QueryTypeId = typeof QueryTypeId -export interface Query +export interface Query extends Pipeable.Pipeable { readonly [QueryTypeId]: QueryTypeId @@ -34,11 +34,10 @@ extends Pipeable.Pipeable { invalidateCacheEntry(key: K): Effect.Effect } -export declare namespace Query { - export type AnyKey = readonly any[] -} +export const isQuery = (u: unknown): u is Query => Predicate.hasProperty(u, QueryTypeId) -export class QueryImpl + +export class QueryImpl extends Pipeable.Class implements Query { readonly [QueryTypeId]: QueryTypeId = QueryTypeId @@ -239,7 +238,7 @@ extends Pipeable.Class implements Query { } makeCacheKey(key: K): QueryClient.QueryClientCacheKey { - return new QueryClient.QueryClientCacheKey(key, this.f as (key: Query.AnyKey) => Effect.Effect) + return new QueryClient.QueryClientCacheKey(key, this.f as (key: unknown) => Effect.Effect) } getCacheEntry( @@ -269,7 +268,7 @@ extends Pipeable.Class implements Query { get invalidateCache(): Effect.Effect { return QueryClient.QueryClient.pipe( - Effect.andThen(client => client.invalidateCacheEntries(this.f as (key: Query.AnyKey) => Effect.Effect)), + Effect.andThen(client => client.invalidateCacheEntries(this.f as (key: unknown) => Effect.Effect)), Effect.provide(this.context), ) } @@ -285,12 +284,8 @@ extends Pipeable.Class implements Query { } } - -export const isQuery = (u: unknown): u is Query => Predicate.hasProperty(u, QueryTypeId) - - export declare namespace make { - export interface Options { + export interface Options { readonly key: Stream.Stream readonly f: (key: NoInfer) => Effect.Effect readonly staleTime?: Duration.Input @@ -298,7 +293,7 @@ export declare namespace make { } } -export const make = Effect.fnUntraced(function* ( +export const make = Effect.fnUntraced(function* ( options: make.Options ): Effect.fn.Return< Query, @@ -324,7 +319,7 @@ export const make = Effect.fnUntraced(function* ( +export const service = ( options: make.Options ): Effect.Effect< Query, diff --git a/packages/effect-fc-next/src/QueryClient.ts b/packages/effect-fc-next/src/QueryClient.ts index 61dcf59..2405cbd 100644 --- a/packages/effect-fc-next/src/QueryClient.ts +++ b/packages/effect-fc-next/src/QueryClient.ts @@ -1,7 +1,6 @@ import { type Cause, Context, DateTime, Duration, Effect, Equal, Equivalence, Hash, HashMap, type Option, Pipeable, Predicate, Schedule, type Scope, Semaphore, SubscriptionRef } from "effect" import type { AsyncResult } from "effect/unstable/reactivity" import * as Lens from "./Lens.js" -import type * as Query from "./Query.js" import type * as Subscribable from "./Subscribable.js" @@ -23,7 +22,7 @@ export interface QueryClientService extends Pipeable.Pipeable { result: AsyncResult.Success, staleTime: Duration.Duration, ): Effect.Effect - invalidateCacheEntries(f: (key: Query.Query.AnyKey) => Effect.Effect): Effect.Effect + invalidateCacheEntries(f: (key: unknown) => Effect.Effect): Effect.Effect invalidateCacheEntry(key: QueryClientCacheKey): Effect.Effect } @@ -86,7 +85,7 @@ implements QueryClientService { ) } - invalidateCacheEntries(f: (key: Query.Query.AnyKey) => Effect.Effect): Effect.Effect { + invalidateCacheEntries(f: (key: unknown) => Effect.Effect): Effect.Effect { return Lens.update(this.cache, HashMap.filter((_, key) => !Equivalence.strictEqual()(key.f, f))) } invalidateCacheEntry(key: QueryClientCacheKey): Effect.Effect { @@ -137,17 +136,17 @@ implements Pipeable.Pipeable, Equal.Equal { readonly [QueryClientCacheKeyTypeId]: QueryClientCacheKeyTypeId = QueryClientCacheKeyTypeId constructor( - readonly key: Query.Query.AnyKey, - readonly f: (key: Query.Query.AnyKey) => Effect.Effect, + readonly key: unknown, + readonly f: (key: unknown) => Effect.Effect, ) { super() } [Equal.symbol](that: Equal.Equal) { - return isQueryClientCacheKey(that) && Equivalence.Array(Equal.asEquivalence())(this.key, that.key) && Equivalence.strictEqual()(this.f, that.f) + return isQueryClientCacheKey(that) && Equal.equals(this.key, that.key) && Equivalence.strictEqual()(this.f, that.f) } [Hash.symbol]() { - return Hash.combine(Hash.hash(this.f))(Hash.array(this.key)) + return Hash.combine(Hash.hash(this.f))(Hash.hash(this.key)) } }