diff --git a/discord-api-docs b/discord-api-docs index ab64846..d9af6ab 160000 --- a/discord-api-docs +++ b/discord-api-docs @@ -1 +1 @@ -Subproject commit ab64846917ec02b029313e9a92c3d4d6d9c5880b +Subproject commit d9af6ab4e655624fb2f7603d3a2cc17fc3d107ea diff --git a/src/DiscordGateway.ts b/src/DiscordGateway.ts index 30c088d..3103702 100644 --- a/src/DiscordGateway.ts +++ b/src/DiscordGateway.ts @@ -1,6 +1,14 @@ +import type { HttpClient } from "@effect/platform/HttpClient" +import type { WebSocketConstructor } from "@effect/platform/Socket" +import type { DiscordConfig } from "dfx/DiscordConfig" +import type { DiscordWSCodec } from "dfx/DiscordGateway/DiscordWS" +import type { Messsaging } from "dfx/DiscordGateway/Messaging" import { Messaging, MesssagingLive } from "dfx/DiscordGateway/Messaging" import type { RunningShard } from "dfx/DiscordGateway/Shard" +import type { ShardStateStore } from "dfx/DiscordGateway/Shard/StateStore" import { Sharder, SharderLive } from "dfx/DiscordGateway/Sharder" +import type { ShardStore } from "dfx/DiscordGateway/ShardStore" +import type { RateLimitStore } from "dfx/RateLimit" import type * as Discord from "dfx/types" import { GenericTag } from "effect/Context" import * as Effect from "effect/Effect" @@ -30,21 +38,32 @@ export interface DiscordGateway { export const DiscordGateway = GenericTag("dfx/DiscordGateway") -export const make = Effect.gen(function* () { - const sharder = yield* Sharder - const messaging = yield* Messaging +export const make: Effect.Effect = + Effect.gen(function* () { + const sharder = yield* Sharder + const messaging = yield* Messaging - return DiscordGateway.of({ - [TypeId]: TypeId, - dispatch: messaging.dispatch, - fromDispatch: messaging.fromDispatch, - handleDispatch: messaging.handleDispatch, - send: messaging.send, - shards: sharder.shards, + return DiscordGateway.of({ + [TypeId]: TypeId, + dispatch: messaging.dispatch, + fromDispatch: messaging.fromDispatch, + handleDispatch: messaging.handleDispatch, + send: messaging.send, + shards: sharder.shards, + }) }) -}) -export const DiscordGatewayLive = Layer.effect(DiscordGateway, make).pipe( +export const DiscordGatewayLive: Layer.Layer< + DiscordGateway, + never, + | ShardStore + | DiscordConfig + | RateLimitStore + | DiscordWSCodec + | ShardStateStore + | WebSocketConstructor + | HttpClient.Service +> = Layer.effect(DiscordGateway, make).pipe( Layer.provide(MesssagingLive), Layer.provide(SharderLive), ) diff --git a/src/DiscordREST.ts b/src/DiscordREST.ts index 240ccb5..78fc017 100644 --- a/src/DiscordREST.ts +++ b/src/DiscordREST.ts @@ -311,6 +311,8 @@ export interface DiscordRESTService export const DiscordREST = GenericTag( "dfx/DiscordREST", ) -export const DiscordRESTLive = Layer.effect(DiscordREST, make).pipe( - Layer.provide(RateLimiterLive), -) +export const DiscordRESTLive: Layer.Layer< + DiscordREST, + never, + DiscordConfig | HttpClient.HttpClient.Service | RateLimitStore +> = Layer.effect(DiscordREST, make).pipe(Layer.provide(RateLimiterLive)) diff --git a/src/Interactions/gateway.ts b/src/Interactions/gateway.ts index 2729239..ccb8cd2 100644 --- a/src/Interactions/gateway.ts +++ b/src/Interactions/gateway.ts @@ -1,4 +1,5 @@ import * as Chunk from "effect/Chunk" +import type { Tag } from "effect/Context" import { GenericTag } from "effect/Context" import * as Duration from "effect/Duration" import { pipe } from "effect/Function" @@ -165,11 +166,15 @@ export interface InteractionsRegistry { readonly _: unique symbol } -export const InteractionsRegistry = GenericTag< +export const InteractionsRegistry: Tag< InteractionsRegistry, InteractionsRegistryService ->("dfx/Interactions/InteractionsRegistry") -export const InteractionsRegistryLive = Layer.scoped( - InteractionsRegistry, - makeRegistry, +> = GenericTag( + "dfx/Interactions/InteractionsRegistry", ) + +export const InteractionsRegistryLive: Layer.Layer< + InteractionsRegistry, + never, + DiscordREST | DiscordGateway +> = Layer.scoped(InteractionsRegistry, makeRegistry) diff --git a/src/Interactions/webhook.ts b/src/Interactions/webhook.ts index d343fca..c64ba7c 100644 --- a/src/Interactions/webhook.ts +++ b/src/Interactions/webhook.ts @@ -5,7 +5,7 @@ import * as Option from "effect/Option" import type * as Cause from "effect/Cause" import type * as Config from "effect/Config" import type * as ConfigError from "effect/ConfigError" -import * as Secret from "effect/Secret" +import * as Redacted from "effect/Redacted" import * as Effect from "effect/Effect" import * as Layer from "effect/Layer" import type * as D from "dfx/Interactions/definitions" @@ -57,7 +57,7 @@ const checkSignature = ( export interface MakeConfigOpts { readonly applicationId: string - readonly publicKey: Secret.Secret + readonly publicKey: Redacted.Redacted readonly crypto: SubtleCrypto readonly algorithm: keyof typeof Verify.PlatformAlgorithm } @@ -68,7 +68,7 @@ const makeConfig = ({ publicKey, }: MakeConfigOpts) => ({ applicationId, - publicKey: Secret.value(publicKey), + publicKey: Redacted.value(publicKey), crypto, algorithm: Verify.PlatformAlgorithm[algorithm], }) diff --git a/src/gateway.ts b/src/gateway.ts index 031998e..6b002e1 100644 --- a/src/gateway.ts +++ b/src/gateway.ts @@ -1,4 +1,5 @@ import * as CachePrelude from "dfx/Cache/prelude" +import type { DiscordGateway } from "dfx/DiscordGateway" import { DiscordGatewayLive } from "dfx/DiscordGateway" import * as DiscordWS from "dfx/DiscordGateway/DiscordWS" import { JsonDiscordWSCodecLive } from "dfx/DiscordGateway/DiscordWS" @@ -7,10 +8,16 @@ import { ShardStateStore } from "dfx/DiscordGateway/Shard/StateStore" import * as SendEvent from "dfx/DiscordGateway/Shard/sendEvents" import * as ShardStore from "dfx/DiscordGateway/ShardStore" import { MemoryShardStoreLive } from "dfx/DiscordGateway/ShardStore" +import type { DiscordREST } from "dfx/DiscordREST" import { DiscordRESTLive } from "dfx/DiscordREST" +import type { InteractionsRegistry } from "dfx/Interactions/gateway" import { InteractionsRegistryLive } from "dfx/Interactions/gateway" +import type { RateLimiter } from "dfx/RateLimit" import { MemoryRateLimitStoreLive, RateLimiterLive } from "dfx/RateLimit" import * as Layer from "effect/Layer" +import type * as HttpClient from "@effect/platform/HttpClient" +import type { DiscordConfig } from "dfx/DiscordConfig" +import type { WebSocketConstructor } from "@effect/platform/Socket" export { DiscordGateway, DiscordGatewayLive } from "dfx/DiscordGateway" @@ -24,10 +31,11 @@ export { export { CachePrelude, DiscordWS, SendEvent, Shard, ShardStore } -export const DiscordLive = Layer.mergeAll( - RateLimiterLive, - DiscordGatewayLive, -).pipe( +export const DiscordLive: Layer.Layer< + RateLimiter | DiscordGateway | DiscordREST, + never, + DiscordConfig | WebSocketConstructor | HttpClient.HttpClient.Service +> = Layer.mergeAll(RateLimiterLive, DiscordGatewayLive).pipe( Layer.provideMerge(DiscordRESTLive), Layer.provide(JsonDiscordWSCodecLive), Layer.provide(MemoryRateLimitStoreLive), @@ -35,6 +43,8 @@ export const DiscordLive = Layer.mergeAll( Layer.provide(ShardStateStore.MemoryLive), ) -export const DiscordIxLive = InteractionsRegistryLive.pipe( - Layer.provideMerge(DiscordLive), -) +export const DiscordIxLive: Layer.Layer< + RateLimiter | DiscordGateway | DiscordREST | InteractionsRegistry, + never, + DiscordConfig | WebSocketConstructor | HttpClient.HttpClient.Service +> = InteractionsRegistryLive.pipe(Layer.provideMerge(DiscordLive)) diff --git a/src/index.ts b/src/index.ts index 1caa51f..1a6d0f8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,7 @@ +import type { HttpClient } from "@effect/platform/HttpClient" import * as Cache from "dfx/Cache" import * as DiscordConfig from "dfx/DiscordConfig" +import type { DiscordREST } from "dfx/DiscordREST" import { DiscordRESTLive } from "dfx/DiscordREST" import * as Flags from "dfx/Helpers/flags" import * as Intents from "dfx/Helpers/intents" @@ -35,6 +37,8 @@ export { UI, } -export const DiscordRESTMemoryLive = DiscordRESTLive.pipe( - Layer.provide(MemoryRateLimitStoreLive), -) +export const DiscordRESTMemoryLive: Layer.Layer< + DiscordREST, + never, + DiscordConfig.DiscordConfig | HttpClient.Service +> = DiscordRESTLive.pipe(Layer.provide(MemoryRateLimitStoreLive)) diff --git a/src/webhooks.ts b/src/webhooks.ts index a41708d..544a2bd 100644 --- a/src/webhooks.ts +++ b/src/webhooks.ts @@ -1,21 +1,25 @@ +import type { HttpClient } from "@effect/platform/HttpClient" +import type { DiscordConfig } from "dfx/DiscordConfig" +import type { DiscordREST } from "dfx/DiscordREST" import { DiscordRESTLive } from "dfx/DiscordREST" -import { - MemoryRateLimitStoreLive as MemoryRateLimitStoreLive, - RateLimiterLive as RateLimiterLive, -} from "dfx/RateLimit" +import type { RateLimiter } from "dfx/RateLimit" +import { MemoryRateLimitStoreLive, RateLimiterLive } from "dfx/RateLimit" import * as Layer from "effect/Layer" export { BadWebhookSignature, - WebhookConfig, - WebhookParseError, makeHandler, makeSimpleHandler, + WebhookConfig, layer as webhookLayer, layerConfig as webhookLayerConfig, + WebhookParseError, } from "dfx/Interactions/webhook" -export const DiscordLive = Layer.mergeAll( - DiscordRESTLive, - RateLimiterLive, -).pipe(Layer.provide(MemoryRateLimitStoreLive)) +export const DiscordLive: Layer.Layer< + DiscordREST | RateLimiter, + never, + DiscordConfig | HttpClient.Service +> = Layer.mergeAll(DiscordRESTLive, RateLimiterLive).pipe( + Layer.provide(MemoryRateLimitStoreLive), +)