Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-spiders-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-atom/atom": minor
---

allow overriding AtomHttpApi & AtomRpc runtime factory
1 change: 1 addition & 0 deletions docs/atom/AtomHttpApi.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export declare const Tag: <Self>() => <
| ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>)
| undefined
readonly baseUrl?: URL | string | undefined
readonly runtime?: Atom.RuntimeFactory | undefined
}
) => AtomHttpApiClient<Self, Id, Groups, ApiE, E>
```
Expand Down
1 change: 1 addition & 0 deletions docs/atom/AtomRpc.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export declare const Tag: <Self>() => <
readonly generateRequestId?: (() => RequestId) | undefined
readonly disableTracing?: boolean | undefined
readonly makeEffect?: Effect.Effect<RpcClient.RpcClient.Flat<Rpcs, RpcClientError>, never, RM> | undefined
readonly runtime?: Atom.RuntimeFactory | undefined
}
) => AtomRpcClient<Self, Id, Rpcs, ER>
```
Expand Down
4 changes: 3 additions & 1 deletion packages/atom/src/AtomHttpApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export const Tag =
| ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>)
| undefined
readonly baseUrl?: URL | string | undefined
readonly runtime?: Atom.RuntimeFactory | undefined
}
): AtomHttpApiClient<Self, Id, Groups, ApiE, E> => {
const self: Mutable<AtomHttpApiClient<Self, Id, Groups, ApiE, E>> = Context.Tag(id)<
Expand All @@ -172,7 +173,8 @@ export const Tag =
self,
HttpApiClient.make(options.api, options)
).pipe(Layer.provide(options.httpClient)) as Layer.Layer<Self, E>
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<{
Expand Down
4 changes: 3 additions & 1 deletion packages/atom/src/AtomRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export const Tag = <Self>() =>
readonly generateRequestId?: (() => RequestId) | undefined
readonly disableTracing?: boolean | undefined
readonly makeEffect?: Effect.Effect<RpcClient.RpcClient.Flat<Rpcs, RpcClientError>, never, RM> | undefined
readonly runtime?: Atom.RuntimeFactory | undefined
}
): AtomRpcClient<Self, Id, Rpcs, ER> => {
const self: Mutable<AtomRpcClient<Self, Id, Rpcs, ER>> = Context.Tag(id)<
Expand All @@ -133,7 +134,8 @@ export const Tag = <Self>() =>
flatten: true
}) as Effect.Effect<RpcClient.RpcClient.Flat<Rpcs, RpcClientError>, 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 extends Rpc.Tag<Rpcs>>(tag: Tag) =>
self.runtime.fn<{
Expand Down