-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tim Smart
committed
Dec 10, 2022
1 parent
346c682
commit 6cf5237
Showing
6 changed files
with
78 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Cache } from "dfx" | ||
import { CacheOps } from "dfx/gateway" | ||
import { Effect, toLayer } from "@effect/io/Effect" | ||
|
||
const makeGuilds = <RM, EM, E>( | ||
driver: Effect<RM, EM, Cache.CacheStoreDriver<E, Discord.Guild>>, | ||
) => | ||
Cache.make({ | ||
driver, | ||
ops: CacheOps.guilds, | ||
onMiss: (id) => rest.getGuild(id).flatMap((r) => r.json), | ||
}) | ||
|
||
export interface GuildsCache extends Success<ReturnType<typeof makeGuilds>> {} | ||
export const GuildsCache = Tag<GuildsCache>() | ||
export const guilds = flow(makeGuilds, toLayer(GuildsCache)) | ||
|
||
const makeChannels = <RM, EM, E>( | ||
driver: Effect<RM, EM, Cache.ParentCacheStoreDriver<E, Discord.Channel>>, | ||
) => | ||
Cache.makeParent({ | ||
driver, | ||
ops: CacheOps.channels, | ||
onMiss: (id) => rest.getChannel(id).flatMap((r) => r.json), | ||
onParentMiss: (guildId) => | ||
rest | ||
.getGuildChannels(guildId) | ||
.flatMap((r) => r.json) | ||
.map((a) => a.map((a) => [a.id, a])), | ||
}) | ||
|
||
export interface ChannelsCache | ||
extends Success<ReturnType<typeof makeChannels>> {} | ||
export const ChannelsCache = Tag<ChannelsCache>() | ||
export const channels = flow(makeChannels, toLayer(ChannelsCache)) | ||
|
||
const makeRoles = <RM, EM, E>( | ||
driver: Effect<RM, EM, Cache.ParentCacheStoreDriver<E, Discord.Role>>, | ||
) => | ||
Cache.makeParent({ | ||
driver, | ||
ops: CacheOps.roles, | ||
onMiss: (id) => Effect.fail(new Cache.CacheMissError("RolesCache", id)), | ||
onParentMiss: (guildId) => | ||
rest | ||
.getGuildRoles(guildId) | ||
.flatMap((r) => r.json) | ||
.map((a) => a.map((a) => [a.id, a])), | ||
}) | ||
|
||
export interface RolesCache extends Success<ReturnType<typeof makeRoles>> {} | ||
export const RolesCache = Tag<RolesCache>() | ||
export const roles = flow(makeRoles, toLayer(RolesCache)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters