Splitting Service Construction in Effect Typescript
Is there any way to split the construction of a service up? Ive done it before using
MyService.of({..})MyService.of({..}), but now Im stuck with Layer.effect(Database, Effect.gen(function() {})Layer.effect(Database, Effect.gen(function() {})export const DatabaseLive = Layer.effect(
Database,
Effect.gen(function* () {
const db = yield* PgDrizzle.PgDrizzle
const sql = yield* SqlClient.SqlClient
return {
billingProgress: {
// I want to import this from "./get-all"
getAll: Effect.gen(function* () {
return {...} satisfies BillingProgressGroups["All"]
})
// .pipe(Effect.provide(db)) <-- would be nice if possible
,
// I want to import this from "./set-all"
setAll: (buildings: Building[]) =>
Effect.gen(function* () {
yield* db.delete(portfoliosTable)
}).pipe(
sql.withTransaction,
Effect.catchTag("SqlError", (e) =>
Effect.die(e),
),
),
},
}
}),
).pipe(Layer.provide(DatabaseDependencies))export const DatabaseLive = Layer.effect(
Database,
Effect.gen(function* () {
const db = yield* PgDrizzle.PgDrizzle
const sql = yield* SqlClient.SqlClient
return {
billingProgress: {
// I want to import this from "./get-all"
getAll: Effect.gen(function* () {
return {...} satisfies BillingProgressGroups["All"]
})
// .pipe(Effect.provide(db)) <-- would be nice if possible
,
// I want to import this from "./set-all"
setAll: (buildings: Building[]) =>
Effect.gen(function* () {
yield* db.delete(portfoliosTable)
}).pipe(
sql.withTransaction,
Effect.catchTag("SqlError", (e) =>
Effect.die(e),
),
),
},
}
}),
).pipe(Layer.provide(DatabaseDependencies))