Skip to content

Commit

Permalink
cleanup layers
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Dec 12, 2023
1 parent 77d504e commit e95ab08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
28 changes: 13 additions & 15 deletions packages/infra/_src/services/Store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import * as CosmosClient from "@effect-app/infra-adapters/cosmos-client"
import * as RedisClient from "@effect-app/infra-adapters/redis-client"
import { createClient } from "redis"

import { makeCosmosStore } from "./Cosmos.js"
import { makeDiskStore } from "./Disk.js"
import { makeMemoryStore } from "./Memory.js"
import { MemoryStoreLive } from "./Memory.js"
import { makeRedisStore } from "./Redis.js"
import type { StorageConfig } from "./service.js"
import { StoreMaker } from "./service.js"
Expand All @@ -14,34 +13,33 @@ import { StoreMaker } from "./service.js"
* @tsplus static StoreMaker.Ops Live
*/
export function StoreMakerLive(config: Config<StorageConfig>) {
return config
.flatMap((cfg) => {
return Effect
.gen(function*($) {
const cfg = yield* $(config)
const storageUrl = cfg.url.value
if (storageUrl.startsWith("mem://")) {
console.log("Using in memory store")
return Effect(makeMemoryStore())
return MemoryStoreLive
}
if (storageUrl.startsWith("disk://")) {
const dir = storageUrl.replace("disk://", "")
console.log("Using disk store at " + dir)
return makeDiskStore(cfg, dir)
.toLayer(StoreMaker)
}
if (storageUrl.startsWith("redis://")) {
console.log("Using Redis store")
return RedisClient.makeRedisClient(makeRedis(storageUrl)).flatMap((client) =>
makeRedisStore(cfg).provideService(
RedisClient.RedisClient,
client
)
)
return makeRedisStore(cfg)
.toLayer(StoreMaker)
.provide(RedisClient.RedisClientLive(makeRedis(storageUrl)))
}

console.log("Using Cosmos DB store")
return CosmosClient.makeCosmosClient(storageUrl, cfg.dbName).flatMap((client) =>
makeCosmosStore(cfg).provideService(CosmosClient.CosmosClient, client)
)
return makeCosmosStore(cfg)
.toLayer(StoreMaker)
.provide(CosmosClient.CosmosClientLive(storageUrl, cfg.dbName))
})
.toLayerScoped(StoreMaker)
.unwrapLayer
}

function makeRedis(storageUrl: string) {
Expand Down
5 changes: 4 additions & 1 deletion packages/vue/_src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const DefaultApiConfig = Config.all({
})

export function makeApiLayers(config: Config<ApiConfig> = DefaultApiConfig) {
return HttpClientBrowser.client.layer + ApiConfig.Live(config)
return HttpClientBrowser
.client
.layer
.merge(ApiConfig.Live(config))
}

export function makeAppRuntime<R, E, A>(layer: Layer<R, E, A>) {
Expand Down

0 comments on commit e95ab08

Please sign in to comment.