diff --git a/packages/effect-fc/src/Query.ts b/packages/effect-fc/src/Query.ts index 9c306b7..6db26ea 100644 --- a/packages/effect-fc/src/Query.ts +++ b/packages/effect-fc/src/Query.ts @@ -6,12 +6,12 @@ import * as Result from "./Result.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 readonly context: Context.Context - readonly key: Stream.Stream + readonly key: Stream.Stream readonly f: (key: K) => Effect.Effect readonly initialProgress: P @@ -37,13 +37,13 @@ export declare namespace Query { export type AnyKey = readonly any[] } -export class QueryImpl -extends Pipeable.Class() implements Query { +export class QueryImpl +extends Pipeable.Class() implements Query { readonly [QueryTypeId]: QueryTypeId = QueryTypeId constructor( - readonly context: Context.Context, - readonly key: Stream.Stream, + readonly context: Context.Context, + readonly key: Stream.Stream, readonly f: (key: K) => Effect.Effect, readonly initialProgress: P, @@ -77,6 +77,7 @@ extends Pipeable.Class() implements Query { ], { concurrency: "unbounded" }).pipe( Effect.ignore, this.runSemaphore.withPermits(1), + Effect.provide(this.context), ) } @@ -265,11 +266,11 @@ extends Pipeable.Class() implements Query { } } -export const isQuery = (u: unknown): u is Query => Predicate.hasProperty(u, QueryTypeId) +export const isQuery = (u: unknown): u is Query => Predicate.hasProperty(u, QueryTypeId) export declare namespace make { - export interface Options { - readonly key: Stream.Stream + export interface Options { + readonly key: Stream.Stream readonly f: (key: NoInfer) => Effect.Effect>> readonly initialProgress?: P readonly staleTime?: Duration.DurationInput @@ -277,17 +278,17 @@ export declare namespace make { } } -export const make = Effect.fnUntraced(function* ( - options: make.Options +export const make = Effect.fnUntraced(function* ( + options: make.Options ): Effect.fn.Return< - Query, P>, + Query, P>, never, - Scope.Scope | QueryClient.QueryClient | Result.forkEffect.OutputContext + Scope.Scope | QueryClient.QueryClient | KR | Result.forkEffect.OutputContext > { const client = yield* QueryClient.QueryClient return new QueryImpl( - yield* Effect.context>(), + yield* Effect.context>(), options.key, options.f as any, options.initialProgress as P, @@ -304,12 +305,12 @@ export const make = Effect.fnUntraced(function* ( - options: make.Options +export const service = ( + options: make.Options ): Effect.Effect< - Query, P>, + Query, P>, never, - Scope.Scope | QueryClient.QueryClient | Result.forkEffect.OutputContext + Scope.Scope | QueryClient.QueryClient | KR | Result.forkEffect.OutputContext > => Effect.tap( make(options), query => Effect.forkScoped(query.run),