diff --git a/.changeset/soft-spiders-care.md b/.changeset/soft-spiders-care.md new file mode 100644 index 00000000..600e13e7 --- /dev/null +++ b/.changeset/soft-spiders-care.md @@ -0,0 +1,5 @@ +--- +"@effect-atom/atom": minor +--- + +allow overriding AtomHttpApi & AtomRpc runtime factory diff --git a/docs/atom/AtomHttpApi.ts.md b/docs/atom/AtomHttpApi.ts.md index 0c04b3c6..3e73e47c 100644 --- a/docs/atom/AtomHttpApi.ts.md +++ b/docs/atom/AtomHttpApi.ts.md @@ -49,6 +49,7 @@ export declare const Tag: () => < | ((effect: Effect.Effect) => Effect.Effect) | undefined readonly baseUrl?: URL | string | undefined + readonly runtime?: Atom.RuntimeFactory | undefined } ) => AtomHttpApiClient ``` diff --git a/docs/atom/AtomRpc.ts.md b/docs/atom/AtomRpc.ts.md index 06d654ed..375540c3 100644 --- a/docs/atom/AtomRpc.ts.md +++ b/docs/atom/AtomRpc.ts.md @@ -41,6 +41,7 @@ export declare const Tag: () => < readonly generateRequestId?: (() => RequestId) | undefined readonly disableTracing?: boolean | undefined readonly makeEffect?: Effect.Effect, never, RM> | undefined + readonly runtime?: Atom.RuntimeFactory | undefined } ) => AtomRpcClient ``` diff --git a/packages/atom/src/AtomHttpApi.ts b/packages/atom/src/AtomHttpApi.ts index a58f1d05..cb622d92 100644 --- a/packages/atom/src/AtomHttpApi.ts +++ b/packages/atom/src/AtomHttpApi.ts @@ -161,6 +161,7 @@ export const Tag = | ((effect: Effect.Effect) => Effect.Effect) | undefined readonly baseUrl?: URL | string | undefined + readonly runtime?: Atom.RuntimeFactory | undefined } ): AtomHttpApiClient => { const self: Mutable> = Context.Tag(id)< @@ -172,7 +173,8 @@ export const Tag = self, HttpApiClient.make(options.api, options) ).pipe(Layer.provide(options.httpClient)) as Layer.Layer - self.runtime = Atom.runtime(self.layer) + const runtimeFactory = options.runtime ?? Atom.runtime + self.runtime = runtimeFactory(self.layer) const mutationFamily = Atom.family(({ endpoint, group, withResponse }: MutationKey) => self.runtime.fn<{ diff --git a/packages/atom/src/AtomRpc.ts b/packages/atom/src/AtomRpc.ts index 91c2ad98..bbec106e 100644 --- a/packages/atom/src/AtomRpc.ts +++ b/packages/atom/src/AtomRpc.ts @@ -118,6 +118,7 @@ export const Tag = () => readonly generateRequestId?: (() => RequestId) | undefined readonly disableTracing?: boolean | undefined readonly makeEffect?: Effect.Effect, never, RM> | undefined + readonly runtime?: Atom.RuntimeFactory | undefined } ): AtomRpcClient => { const self: Mutable> = Context.Tag(id)< @@ -133,7 +134,8 @@ export const Tag = () => flatten: true }) as Effect.Effect, never, RM> ).pipe(Layer.provide(options.protocol)) - self.runtime = Atom.runtime(self.layer) + const runtimeFactory = options.runtime ?? Atom.runtime + self.runtime = runtimeFactory(self.layer) self.mutation = Atom.family(>(tag: Tag) => self.runtime.fn<{