Skip to content

Commit

Permalink
remove platform http client from layers
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Mar 26, 2024
1 parent 848c3fa commit 04c3203
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
6 changes: 5 additions & 1 deletion examples/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Discord, DiscordConfig, Ix } from "dfx"
import { DiscordLive, runIx } from "dfx/gateway"
import Dotenv from "dotenv"
import { Cause, Config, Effect, Layer, Option, pipe } from "effect"
import * as NodeHttp from "@effect/platform-node/NodeHttpClient"

Dotenv.config()

Expand Down Expand Up @@ -78,7 +79,10 @@ const program = Effect.gen(function* (_) {
yield* _(interactions)
})

const EnvLive = DiscordLive.pipe(Layer.provide(DiscordConfigLive))
const EnvLive = DiscordLive.pipe(
Layer.provide(NodeHttp.layer),
Layer.provide(DiscordConfigLive),
)

// Run it
program.pipe(
Expand Down
6 changes: 5 additions & 1 deletion examples/readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DiscordConfig, Ix } from "dfx"
import { DiscordIxLive, InteractionsRegistry } from "dfx/gateway"
import * as Dotenv from "dotenv"
import { Config, Effect, Layer } from "effect"
import * as NodeHttp from "@effect/platform-node/NodeHttpClient"

Dotenv.config()

Expand Down Expand Up @@ -41,7 +42,10 @@ const HelloLive = Layer.effectDiscard(
)

// Construct the main layer
const MainLive = HelloLive.pipe(Layer.provide(DiscordConfigLive))
const MainLive = HelloLive.pipe(
Layer.provide(NodeHttp.layer),
Layer.provide(DiscordConfigLive),
)

// run it
runMain(Layer.launch(MainLive))
2 changes: 2 additions & 0 deletions examples/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "dfx/gateway"
import Dotenv from "dotenv"
import { Config, Effect, Layer, LogLevel, Logger } from "effect"
import * as NodeHttp from "@effect/platform-node/NodeHttpClient"

Dotenv.config()

Expand Down Expand Up @@ -55,6 +56,7 @@ const GreetLive = Layer.effectDiscard(makeGreetService)
const MainLive = GreetLive.pipe(
Layer.provide(InteractionsRegistryLive),
Layer.provide(DiscordLive),
Layer.provide(NodeHttp.layer),
Layer.provide(
DiscordConfig.layerConfig({
token: Config.secret("DISCORD_BOT_TOKEN"),
Expand Down
1 change: 0 additions & 1 deletion src/DiscordREST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,5 +310,4 @@ export const DiscordREST = GenericTag<DiscordREST, DiscordRESTService>(
)
export const DiscordRESTLive = Layer.effect(DiscordREST, make).pipe(
Layer.provide(RateLimiterLive),
Layer.provide(Http.client.layer),
)
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import * as Cache from "dfx/Cache"
import * as DiscordConfig from "dfx/DiscordConfig"
import { DiscordRESTLive } from "dfx/DiscordREST"
import * as Flags from "dfx/Helpers/flags"
import * as Intents from "dfx/Helpers/intents"
import * as IxHelpers from "dfx/Helpers/interactions"
import * as Members from "dfx/Helpers/members"
import * as Perms from "dfx/Helpers/permissions"
import * as UI from "dfx/Helpers/ui"
import * as Ix from "dfx/Interactions/index"
import { MemoryRateLimitStoreLive } from "dfx/RateLimit"
import * as Discord from "dfx/types"
import * as Layer from "effect/Layer"

export { DiscordREST, DiscordRESTLive } from "dfx/DiscordREST"

export {
BucketDetails,
MemoryRateLimitStoreLive,
RateLimiterLive,
RateLimiter,
RateLimitStore,
RateLimiter,
RateLimiterLive,
} from "dfx/RateLimit"

export {
Expand All @@ -31,3 +34,7 @@ export {
Perms,
UI,
}

export const DiscordRESTMemoryLive = DiscordRESTLive.pipe(
Layer.provide(MemoryRateLimitStoreLive),
)

0 comments on commit 04c3203

Please sign in to comment.