dfx 0.85.0 → 0.87.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/Cache/driver.d.ts +15 -15
  2. package/Cache/driver.d.ts.map +1 -1
  3. package/Cache/memory.d.ts +2 -2
  4. package/Cache/memory.d.ts.map +1 -1
  5. package/Cache/memory.js.map +1 -1
  6. package/Cache/memoryTTL.d.ts +2 -2
  7. package/Cache/memoryTTL.js.map +1 -1
  8. package/Cache/prelude.d.ts +13 -16
  9. package/Cache/prelude.d.ts.map +1 -1
  10. package/Cache/prelude.js.map +1 -1
  11. package/Cache.d.ts +25 -25
  12. package/Cache.d.ts.map +1 -1
  13. package/Cache.js.map +1 -1
  14. package/DiscordConfig.d.ts +3 -4
  15. package/DiscordConfig.d.ts.map +1 -1
  16. package/DiscordConfig.js +1 -1
  17. package/DiscordConfig.js.map +1 -1
  18. package/DiscordGateway/DiscordWS.d.ts +10 -11
  19. package/DiscordGateway/DiscordWS.d.ts.map +1 -1
  20. package/DiscordGateway/DiscordWS.js +2 -2
  21. package/DiscordGateway/DiscordWS.js.map +1 -1
  22. package/DiscordGateway/Messaging.d.ts +12 -13
  23. package/DiscordGateway/Messaging.d.ts.map +1 -1
  24. package/DiscordGateway/Messaging.js +1 -1
  25. package/DiscordGateway/Messaging.js.map +1 -1
  26. package/DiscordGateway/Shard/heartbeats.d.ts +1 -1
  27. package/DiscordGateway/Shard/heartbeats.d.ts.map +1 -1
  28. package/DiscordGateway/Shard/heartbeats.js.map +1 -1
  29. package/DiscordGateway/Shard/identify.d.ts +1 -1
  30. package/DiscordGateway/Shard/identify.d.ts.map +1 -1
  31. package/DiscordGateway/Shard/identify.js.map +1 -1
  32. package/DiscordGateway/Shard/invalidSession.d.ts +1 -1
  33. package/DiscordGateway/Shard/invalidSession.d.ts.map +1 -1
  34. package/DiscordGateway/Shard/utils.d.ts +2 -2
  35. package/DiscordGateway/Shard/utils.d.ts.map +1 -1
  36. package/DiscordGateway/Shard/utils.js.map +1 -1
  37. package/DiscordGateway/Shard.d.ts +10 -11
  38. package/DiscordGateway/Shard.d.ts.map +1 -1
  39. package/DiscordGateway/Shard.js +1 -1
  40. package/DiscordGateway/Shard.js.map +1 -1
  41. package/DiscordGateway/ShardStore.d.ts +5 -6
  42. package/DiscordGateway/ShardStore.d.ts.map +1 -1
  43. package/DiscordGateway/ShardStore.js +1 -1
  44. package/DiscordGateway/ShardStore.js.map +1 -1
  45. package/DiscordGateway/Sharder.d.ts +3 -4
  46. package/DiscordGateway/Sharder.d.ts.map +1 -1
  47. package/DiscordGateway/Sharder.js +1 -1
  48. package/DiscordGateway/Sharder.js.map +1 -1
  49. package/DiscordGateway/WS.d.ts +7 -8
  50. package/DiscordGateway/WS.d.ts.map +1 -1
  51. package/DiscordGateway/WS.js +1 -1
  52. package/DiscordGateway/WS.js.map +1 -1
  53. package/DiscordGateway.d.ts +8 -9
  54. package/DiscordGateway.d.ts.map +1 -1
  55. package/DiscordGateway.js +1 -1
  56. package/DiscordGateway.js.map +1 -1
  57. package/DiscordREST/types.d.ts +2 -2
  58. package/DiscordREST/types.d.ts.map +1 -1
  59. package/DiscordREST.d.ts +3 -4
  60. package/DiscordREST.d.ts.map +1 -1
  61. package/DiscordREST.js +1 -1
  62. package/DiscordREST.js.map +1 -1
  63. package/Helpers/permissions.d.ts +3 -3
  64. package/Helpers/permissions.d.ts.map +1 -1
  65. package/Interactions/builder.d.ts +12 -12
  66. package/Interactions/builder.d.ts.map +1 -1
  67. package/Interactions/context.d.ts +22 -23
  68. package/Interactions/context.d.ts.map +1 -1
  69. package/Interactions/context.js +6 -6
  70. package/Interactions/context.js.map +1 -1
  71. package/Interactions/definitions.d.ts +23 -25
  72. package/Interactions/definitions.d.ts.map +1 -1
  73. package/Interactions/gateway.d.ts +5 -6
  74. package/Interactions/gateway.d.ts.map +1 -1
  75. package/Interactions/gateway.js +1 -1
  76. package/Interactions/gateway.js.map +1 -1
  77. package/Interactions/handlers.d.ts +2 -2
  78. package/Interactions/handlers.d.ts.map +1 -1
  79. package/Interactions/handlers.js.map +1 -1
  80. package/Interactions/index.d.ts +5 -5
  81. package/Interactions/utils.d.ts +26 -26
  82. package/Interactions/utils.js.map +1 -1
  83. package/Interactions/webhook.d.ts +7 -8
  84. package/Interactions/webhook.d.ts.map +1 -1
  85. package/Interactions/webhook.js +1 -1
  86. package/Interactions/webhook.js.map +1 -1
  87. package/RateLimit.d.ts +11 -12
  88. package/RateLimit.d.ts.map +1 -1
  89. package/RateLimit.js +2 -2
  90. package/RateLimit.js.map +1 -1
  91. package/gateway.d.ts +2 -2
  92. package/mjs/Cache/memory.mjs.map +1 -1
  93. package/mjs/Cache/memoryTTL.mjs.map +1 -1
  94. package/mjs/Cache/prelude.mjs.map +1 -1
  95. package/mjs/Cache.mjs.map +1 -1
  96. package/mjs/DiscordConfig.mjs +2 -2
  97. package/mjs/DiscordConfig.mjs.map +1 -1
  98. package/mjs/DiscordGateway/DiscordWS.mjs +3 -3
  99. package/mjs/DiscordGateway/DiscordWS.mjs.map +1 -1
  100. package/mjs/DiscordGateway/Messaging.mjs +2 -2
  101. package/mjs/DiscordGateway/Messaging.mjs.map +1 -1
  102. package/mjs/DiscordGateway/Shard/heartbeats.mjs.map +1 -1
  103. package/mjs/DiscordGateway/Shard/identify.mjs.map +1 -1
  104. package/mjs/DiscordGateway/Shard/utils.mjs.map +1 -1
  105. package/mjs/DiscordGateway/Shard.mjs +2 -2
  106. package/mjs/DiscordGateway/Shard.mjs.map +1 -1
  107. package/mjs/DiscordGateway/ShardStore.mjs +2 -2
  108. package/mjs/DiscordGateway/ShardStore.mjs.map +1 -1
  109. package/mjs/DiscordGateway/Sharder.mjs +2 -2
  110. package/mjs/DiscordGateway/Sharder.mjs.map +1 -1
  111. package/mjs/DiscordGateway/WS.mjs +2 -2
  112. package/mjs/DiscordGateway/WS.mjs.map +1 -1
  113. package/mjs/DiscordGateway.mjs +2 -2
  114. package/mjs/DiscordGateway.mjs.map +1 -1
  115. package/mjs/DiscordREST.mjs +2 -2
  116. package/mjs/DiscordREST.mjs.map +1 -1
  117. package/mjs/Interactions/context.mjs +7 -7
  118. package/mjs/Interactions/context.mjs.map +1 -1
  119. package/mjs/Interactions/gateway.mjs +2 -2
  120. package/mjs/Interactions/gateway.mjs.map +1 -1
  121. package/mjs/Interactions/handlers.mjs.map +1 -1
  122. package/mjs/Interactions/utils.mjs.map +1 -1
  123. package/mjs/Interactions/webhook.mjs +2 -2
  124. package/mjs/Interactions/webhook.mjs.map +1 -1
  125. package/mjs/RateLimit.mjs +3 -3
  126. package/mjs/RateLimit.mjs.map +1 -1
  127. package/mjs/version.mjs +1 -1
  128. package/package.json +4 -4
  129. package/src/Cache/driver.ts +15 -15
  130. package/src/Cache/memory.ts +2 -10
  131. package/src/Cache/memoryTTL.ts +4 -4
  132. package/src/Cache/prelude.ts +25 -24
  133. package/src/Cache.ts +31 -31
  134. package/src/DiscordConfig.ts +4 -4
  135. package/src/DiscordGateway/DiscordWS.ts +5 -5
  136. package/src/DiscordGateway/Messaging.ts +9 -8
  137. package/src/DiscordGateway/Shard/heartbeats.ts +2 -2
  138. package/src/DiscordGateway/Shard/identify.ts +2 -6
  139. package/src/DiscordGateway/Shard/invalidSession.ts +1 -1
  140. package/src/DiscordGateway/Shard/utils.ts +7 -11
  141. package/src/DiscordGateway/Shard.ts +2 -2
  142. package/src/DiscordGateway/ShardStore.ts +5 -5
  143. package/src/DiscordGateway/Sharder.ts +7 -4
  144. package/src/DiscordGateway/WS.ts +8 -8
  145. package/src/DiscordGateway.ts +8 -12
  146. package/src/DiscordREST/types.ts +2 -6
  147. package/src/DiscordREST.ts +5 -9
  148. package/src/Helpers/permissions.ts +1 -1
  149. package/src/Interactions/builder.ts +11 -11
  150. package/src/Interactions/context.ts +28 -32
  151. package/src/Interactions/definitions.ts +34 -38
  152. package/src/Interactions/gateway.ts +6 -14
  153. package/src/Interactions/handlers.ts +3 -7
  154. package/src/Interactions/utils.ts +6 -6
  155. package/src/Interactions/webhook.ts +15 -19
  156. package/src/RateLimit.ts +9 -9
  157. package/src/utils/Effect.ts +9 -9
  158. package/src/version.ts +1 -1
  159. package/utils/Effect.d.ts +2 -2
  160. package/version.d.ts +1 -1
  161. package/version.js +1 -1
  162. package/webhooks.d.ts +1 -1
@@ -1,4 +1,4 @@
1
- import { Tag } from "effect/Context"
1
+ import { GenericTag } from "effect/Context"
2
2
  import type * as Duration from "effect/Duration"
3
3
  import { identity, pipe } from "effect/Function"
4
4
  import * as Effect from "effect/Effect"
@@ -51,7 +51,7 @@ const offer = (
51
51
  ws: globalThis.WebSocket,
52
52
  queue: Queue.Enqueue<WebSocket.Data>,
53
53
  ) =>
54
- Effect.async<never, WebSocketError | WebSocketCloseError, never>(resume => {
54
+ Effect.async<never, WebSocketError | WebSocketCloseError>(resume => {
55
55
  ws.addEventListener("message", message => {
56
56
  Queue.unsafeOffer(queue, message.data)
57
57
  })
@@ -75,11 +75,11 @@ const waitForOpen = (
75
75
  return Effect.unit
76
76
  }
77
77
 
78
- return Effect.async<never, never, void>(resume => {
78
+ return Effect.async<void>(resume => {
79
79
  ws.addEventListener("open", () => resume(Effect.unit), {
80
80
  once: true,
81
81
  })
82
- })
82
+ });
83
83
  }),
84
84
  {
85
85
  onTimeout: () => new WebSocketError("open-timeout"),
@@ -89,7 +89,7 @@ const waitForOpen = (
89
89
 
90
90
  const send = (
91
91
  ws: globalThis.WebSocket,
92
- take: Effect.Effect<never, never, Message>,
92
+ take: Effect.Effect<Message>,
93
93
  ) =>
94
94
  pipe(
95
95
  take,
@@ -119,8 +119,8 @@ const wsImpl = {
119
119
  urlRef,
120
120
  }: {
121
121
  readonly urlRef: Ref.Ref<string>
122
- readonly takeOutbound: Effect.Effect<never, never, Message>
123
- readonly onConnecting?: Effect.Effect<never, never, void>
122
+ readonly takeOutbound: Effect.Effect<Message>
123
+ readonly onConnecting?: Effect.Effect<void>
124
124
  readonly openTimeout?: Duration.DurationInput
125
125
  readonly reconnectWhen?: Predicate<WebSocketError | WebSocketCloseError>
126
126
  }) =>
@@ -182,5 +182,5 @@ const wsImpl = {
182
182
  export interface WS {
183
183
  readonly _: unique symbol
184
184
  }
185
- export const WS = Tag<WS, typeof wsImpl>("dfx/DiscordGateway/WS")
185
+ export const WS = GenericTag<WS, typeof wsImpl>("dfx/DiscordGateway/WS")
186
186
  export const WSLive = Layer.succeed(WS, wsImpl)
@@ -2,7 +2,7 @@ import { Messaging, MesssagingLive } from "dfx/DiscordGateway/Messaging"
2
2
  import type { RunningShard } from "dfx/DiscordGateway/Shard"
3
3
  import { Sharder, SharderLive } from "dfx/DiscordGateway/Sharder"
4
4
  import type * as Discord from "dfx/types"
5
- import { Tag } from "effect/Context"
5
+ import { GenericTag } from "effect/Context"
6
6
  import * as Effect from "effect/Effect"
7
7
  import type * as HashSet from "effect/HashSet"
8
8
  import * as Layer from "effect/Layer"
@@ -14,25 +14,21 @@ export type TypeId = typeof TypeId
14
14
  export interface DiscordGateway {
15
15
  readonly [TypeId]: TypeId
16
16
 
17
- readonly dispatch: Stream.Stream<
18
- never,
19
- never,
20
- Discord.GatewayPayload<Discord.ReceiveEvent>
21
- >
17
+ readonly dispatch: Stream.Stream<Discord.GatewayPayload<Discord.ReceiveEvent>>
22
18
  readonly fromDispatch: <K extends keyof Discord.ReceiveEvents>(
23
19
  event: K,
24
- ) => Stream.Stream<never, never, Discord.ReceiveEvents[K]>
20
+ ) => Stream.Stream<Discord.ReceiveEvents[K]>
25
21
  readonly handleDispatch: <K extends keyof Discord.ReceiveEvents, R, E, A>(
26
22
  event: K,
27
- handle: (event: Discord.ReceiveEvents[K]) => Effect.Effect<R, E, A>,
28
- ) => Effect.Effect<R, E, never>
23
+ handle: (event: Discord.ReceiveEvents[K]) => Effect.Effect<A, E, R>,
24
+ ) => Effect.Effect<never, E, R>
29
25
  readonly send: (
30
26
  payload: Discord.GatewayPayload<Discord.SendEvent>,
31
- ) => Effect.Effect<never, never, boolean>
32
- readonly shards: Effect.Effect<never, never, HashSet.HashSet<RunningShard>>
27
+ ) => Effect.Effect<boolean>
28
+ readonly shards: Effect.Effect<HashSet.HashSet<RunningShard>>
33
29
  }
34
30
 
35
- export const DiscordGateway = Tag<DiscordGateway>(TypeId)
31
+ export const DiscordGateway = GenericTag<DiscordGateway>("dfx/DiscordGateway")
36
32
 
37
33
  export const make = Effect.gen(function* (_) {
38
34
  const sharder = yield* _(Sharder)
@@ -3,11 +3,7 @@ import type * as Http from "@effect/platform/HttpClient"
3
3
  import type { DiscordRESTError } from "dfx/DiscordREST"
4
4
 
5
5
  export interface ResponseWithData<A> extends Http.response.ClientResponse {
6
- readonly json: Effect.Effect<never, Http.error.ResponseError, A>
6
+ readonly json: Effect.Effect<A, Http.error.ResponseError>
7
7
  }
8
8
 
9
- export type RestResponse<T> = Effect.Effect<
10
- never,
11
- DiscordRESTError,
12
- ResponseWithData<T>
13
- >
9
+ export type RestResponse<T> = Effect.Effect<ResponseWithData<T>, DiscordRESTError>
@@ -1,4 +1,4 @@
1
- import { Tag } from "effect/Context"
1
+ import { GenericTag } from "effect/Context"
2
2
  import * as Duration from "effect/Duration"
3
3
  import { millis } from "effect/Duration"
4
4
  import { pipe } from "effect/Function"
@@ -155,15 +155,11 @@ const make = Effect.gen(function* (_) {
155
155
 
156
156
  const executor = <A = unknown>(
157
157
  request: Http.request.ClientRequest,
158
- ): Effect.Effect<never, DiscordRESTError, ResponseWithData<A>> =>
158
+ ): Effect.Effect<ResponseWithData<A>, DiscordRESTError> =>
159
159
  requestRateLimit(request.url, request).pipe(
160
160
  Effect.zipLeft(globalRateLimit),
161
161
  Effect.zipRight(
162
- httpExecutor(request) as Effect.Effect<
163
- never,
164
- DiscordRESTError,
165
- ResponseWithData<A>
166
- >,
162
+ httpExecutor(request) as Effect.Effect<ResponseWithData<A>, DiscordRESTError>,
167
163
  ),
168
164
  Effect.tap(response => updateBuckets(request, response)),
169
165
  Effect.catchTag("DiscordRESTError", e => {
@@ -261,10 +257,10 @@ export interface DiscordRESTService
261
257
  extends Discord.Endpoints<Partial<Http.request.Options.NoUrl>> {
262
258
  readonly executor: <A = unknown>(
263
259
  request: Http.request.ClientRequest,
264
- ) => Effect.Effect<never, DiscordRESTError, ResponseWithData<A>>
260
+ ) => Effect.Effect<ResponseWithData<A>, DiscordRESTError>
265
261
  }
266
262
 
267
- export const DiscordREST = Tag<DiscordREST, DiscordRESTService>(
263
+ export const DiscordREST = GenericTag<DiscordREST, DiscordRESTService>(
268
264
  "dfx/DiscordREST",
269
265
  )
270
266
  export const DiscordRESTLive = Layer.effect(DiscordREST, make).pipe(
@@ -112,7 +112,7 @@ export const applyOverwrites =
112
112
  interface RolesCache<E> {
113
113
  getForParent: (
114
114
  parentId: string,
115
- ) => Effect.Effect<never, E, ReadonlyMap<string, Discord.Role>>
115
+ ) => Effect.Effect<ReadonlyMap<string, Discord.Role>, E>
116
116
  }
117
117
 
118
118
  export const hasInChannel =
@@ -24,12 +24,12 @@ export class InteractionBuilder<R, E, TE> {
24
24
  handler: D.InteractionDefinition<R, E>,
25
25
  transform: (
26
26
  self: Effect.Effect<any, any, any>,
27
- ) => Effect.Effect<R, TE, void>,
27
+ ) => Effect.Effect<void, TE, R>,
28
28
  ]
29
29
  >,
30
30
  readonly transform: (
31
31
  self: Effect.Effect<any, any, any>,
32
- ) => Effect.Effect<R, TE, void>,
32
+ ) => Effect.Effect<void, TE, R>,
33
33
  ) {}
34
34
 
35
35
  add<R1, E1>(definition: D.InteractionDefinition<R1, E1>) {
@@ -47,7 +47,7 @@ export class InteractionBuilder<R, E, TE> {
47
47
  }
48
48
 
49
49
  private transformTransform<R1, E1>(
50
- f: (selr: Effect.Effect<R, TE, void>) => Effect.Effect<R1, E1, void>,
50
+ f: (selr: Effect.Effect<void, TE, R>) => Effect.Effect<void, E1, R1>,
51
51
  ) {
52
52
  return new InteractionBuilder<R1, E, E1>(
53
53
  Chunk.map(this.definitions, ([d, t]) => [d as any, _ => f(t(_)) as any]),
@@ -57,8 +57,8 @@ export class InteractionBuilder<R, E, TE> {
57
57
 
58
58
  private transformHandlers<R1, E1>(
59
59
  f: (
60
- selr: Effect.Effect<R, E, Discord.InteractionResponse>,
61
- ) => Effect.Effect<R1, E1, Discord.InteractionResponse>,
60
+ selr: Effect.Effect<Discord.InteractionResponse, E, R>,
61
+ ) => Effect.Effect<Discord.InteractionResponse, E1, R1>,
62
62
  ) {
63
63
  return new InteractionBuilder<
64
64
  R1,
@@ -79,7 +79,7 @@ export class InteractionBuilder<R, E, TE> {
79
79
  }
80
80
 
81
81
  catchAllCause<R1, E1>(
82
- f: (cause: Cause.Cause<TE>) => Effect.Effect<R1, E1, void>,
82
+ f: (cause: Cause.Cause<TE>) => Effect.Effect<void, E1, R1>,
83
83
  ) {
84
84
  return this.transformTransform<R | R1, E1>(Effect.catchAllCause(f))
85
85
  }
@@ -87,24 +87,24 @@ export class InteractionBuilder<R, E, TE> {
87
87
  catchAllCauseRespond<R1, E1>(
88
88
  f: (
89
89
  cause: Cause.Cause<E>,
90
- ) => Effect.Effect<R1, E1, Discord.InteractionResponse>,
90
+ ) => Effect.Effect<Discord.InteractionResponse, E1, R1>,
91
91
  ) {
92
92
  return this.transformHandlers<R | R1, E1>(Effect.catchAllCause(f))
93
93
  }
94
94
 
95
- catchAll<R1, E1>(f: (error: TE) => Effect.Effect<R1, E1, void>) {
95
+ catchAll<R1, E1>(f: (error: TE) => Effect.Effect<void, E1, R1>) {
96
96
  return this.transformTransform<R | R1, E1>(Effect.catchAll(f))
97
97
  }
98
98
 
99
99
  catchAllRespond<R1, E1>(
100
- f: (error: E) => Effect.Effect<R1, E1, Discord.InteractionResponse>,
100
+ f: (error: E) => Effect.Effect<Discord.InteractionResponse, E1, R1>,
101
101
  ) {
102
102
  return this.transformHandlers<R | R1, E1>(Effect.catchAll(f))
103
103
  }
104
104
 
105
105
  catchTag<T extends ExtractTag<E>, R1, E1>(
106
106
  tag: T,
107
- f: (error: Extract<TE, { _tag: T }>) => Effect.Effect<R1, E1, void>,
107
+ f: (error: Extract<TE, { _tag: T }>) => Effect.Effect<void, E1, R1>,
108
108
  ) {
109
109
  return this.transformTransform<R | R1, Exclude<TE, { _tag: T }> | E1>(
110
110
  _ => catchTag(_ as any, tag, f as any) as any,
@@ -115,7 +115,7 @@ export class InteractionBuilder<R, E, TE> {
115
115
  tag: T,
116
116
  f: (
117
117
  error: Extract<E, { _tag: T }>,
118
- ) => Effect.Effect<R1, E1, Discord.InteractionResponse>,
118
+ ) => Effect.Effect<Discord.InteractionResponse, E1, R1>,
119
119
  ) {
120
120
  return this.transformHandlers<R | R1, Exclude<E, { _tag: T }> | E1>(
121
121
  _ => catchTag(_ as any, tag, f as any) as any,
@@ -1,4 +1,4 @@
1
- import { Tag } from "effect/Context"
1
+ import { GenericTag } from "effect/Context"
2
2
  import type * as HashMap from "effect/HashMap"
3
3
  import * as Option from "effect/Option"
4
4
  import * as Arr from "effect/ReadonlyArray"
@@ -9,14 +9,14 @@ import type * as Discord from "dfx/types"
9
9
  export interface DiscordInteraction {
10
10
  readonly _: unique symbol
11
11
  }
12
- export const Interaction = Tag<DiscordInteraction, Discord.Interaction>(
12
+ export const Interaction = GenericTag<DiscordInteraction, Discord.Interaction>(
13
13
  "dfx/Interactions/Interaction",
14
14
  )
15
15
 
16
16
  export interface DiscordApplicationCommand {
17
17
  readonly _: unique symbol
18
18
  }
19
- export const ApplicationCommand = Tag<
19
+ export const ApplicationCommand = GenericTag<
20
20
  DiscordApplicationCommand,
21
21
  Discord.ApplicationCommandDatum
22
22
  >("dfx/Interactions/ApplicationCommand")
@@ -24,7 +24,7 @@ export const ApplicationCommand = Tag<
24
24
  export interface DiscordMessageComponent {
25
25
  readonly _: unique symbol
26
26
  }
27
- export const MessageComponentData = Tag<
27
+ export const MessageComponentData = GenericTag<
28
28
  DiscordMessageComponent,
29
29
  Discord.MessageComponentDatum
30
30
  >("dfx/Interactions/MessageComponentData")
@@ -32,7 +32,7 @@ export const MessageComponentData = Tag<
32
32
  export interface DiscordModalSubmit {
33
33
  readonly _: unique symbol
34
34
  }
35
- export const ModalSubmitData = Tag<
35
+ export const ModalSubmitData = GenericTag<
36
36
  DiscordModalSubmit,
37
37
  Discord.ModalSubmitDatum
38
38
  >("dfx/Interactions/ModalSubmitData")
@@ -43,7 +43,7 @@ export interface DiscordFocusedOption {
43
43
  export interface FocusedOptionContext {
44
44
  readonly focusedOption: Discord.ApplicationCommandInteractionDataOption
45
45
  }
46
- export const FocusedOptionContext = Tag<
46
+ export const FocusedOptionContext = GenericTag<
47
47
  DiscordFocusedOption,
48
48
  FocusedOptionContext
49
49
  >("dfx/Interactions/FocusedOptionContext")
@@ -54,7 +54,7 @@ export interface DiscordSubCommand {
54
54
  export interface SubCommandContext {
55
55
  readonly command: Discord.ApplicationCommandInteractionDataOption
56
56
  }
57
- export const SubCommandContext = Tag<DiscordSubCommand, SubCommandContext>(
57
+ export const SubCommandContext = GenericTag<DiscordSubCommand, SubCommandContext>(
58
58
  "dfx/Interactions/SubCommandContext",
59
59
  )
60
60
 
@@ -68,7 +68,7 @@ export class ResolvedDataNotFound {
68
68
 
69
69
  export const resolvedValues = <A>(
70
70
  f: (id: Discord.Snowflake, data: Discord.ResolvedDatum) => A | undefined,
71
- ): Effect.Effect<DiscordInteraction, ResolvedDataNotFound, ReadonlyArray<A>> =>
71
+ ): Effect.Effect<ReadonlyArray<A>, ResolvedDataNotFound, DiscordInteraction> =>
72
72
  Effect.flatMap(Interaction, ix =>
73
73
  Effect.mapError(
74
74
  IxHelpers.resolveValues(f)(ix),
@@ -79,7 +79,7 @@ export const resolvedValues = <A>(
79
79
  export const resolved = <A>(
80
80
  name: string,
81
81
  f: (id: Discord.Snowflake, data: Discord.ResolvedDatum) => A | undefined,
82
- ): Effect.Effect<DiscordInteraction, ResolvedDataNotFound, A> =>
82
+ ): Effect.Effect<A, ResolvedDataNotFound, DiscordInteraction> =>
83
83
  Effect.flatMap(Interaction, ix =>
84
84
  Effect.mapError(
85
85
  IxHelpers.resolveOptionValue(name, f)(ix),
@@ -100,29 +100,25 @@ export class SubCommandNotFound {
100
100
  export const handleSubCommands = <
101
101
  NER extends Record<
102
102
  string,
103
- Effect.Effect<any, any, Discord.InteractionResponse>
103
+ Effect.Effect<Discord.InteractionResponse, any, any>
104
104
  >,
105
105
  >(
106
106
  commands: NER,
107
- ): Effect.Effect<
108
- | Exclude<
109
- [NER[keyof NER]] extends [
110
- { [Effect.EffectTypeId]: { _R: (_: never) => infer R } },
111
- ]
112
- ? R
113
- : never,
114
- SubCommandContext
115
- >
116
- | Discord.Interaction
117
- | Discord.ApplicationCommandDatum,
118
- | ([NER[keyof NER]] extends [
119
- { [Effect.EffectTypeId]: { _E: (_: never) => infer E } },
107
+ ): Effect.Effect<Discord.InteractionResponse, | ([NER[keyof NER]] extends [
108
+ { [Effect.EffectTypeId]: { _E: (_: never) => infer E } },
109
+ ]
110
+ ? E
111
+ : never)
112
+ | SubCommandNotFound, | Exclude<
113
+ [NER[keyof NER]] extends [
114
+ { [Effect.EffectTypeId]: { _R: (_: never) => infer R } },
120
115
  ]
121
- ? E
122
- : never)
123
- | SubCommandNotFound,
124
- Discord.InteractionResponse
125
- > =>
116
+ ? R
117
+ : never,
118
+ SubCommandContext
119
+ >
120
+ | Discord.Interaction
121
+ | Discord.ApplicationCommandDatum> =>
126
122
  ApplicationCommand.pipe(
127
123
  Effect.flatMap(data =>
128
124
  Effect.mapError(
@@ -138,15 +134,15 @@ export const handleSubCommands = <
138
134
  )
139
135
 
140
136
  export const currentSubCommand: Effect.Effect<
141
- DiscordSubCommand,
137
+ Discord.ApplicationCommandInteractionDataOption,
142
138
  never,
143
- Discord.ApplicationCommandInteractionDataOption
139
+ DiscordSubCommand
144
140
  > = Effect.map(SubCommandContext, _ => _.command)
145
141
 
146
142
  export const optionsMap: Effect.Effect<
147
- DiscordApplicationCommand,
143
+ HashMap.HashMap<string, string | undefined>,
148
144
  never,
149
- HashMap.HashMap<string, string | undefined>
145
+ DiscordApplicationCommand
150
146
  > = Effect.map(ApplicationCommand, IxHelpers.optionsMap)
151
147
 
152
148
  export class RequiredOptionNotFound {
@@ -65,13 +65,13 @@ export const guild = <
65
65
  export class MessageComponent<R, E> {
66
66
  readonly _tag = "MessageComponent"
67
67
  constructor(
68
- readonly predicate: (customId: string) => Effect.Effect<R, E, boolean>,
69
- readonly handle: Effect.Effect<R, E, Discord.InteractionResponse>,
68
+ readonly predicate: (customId: string) => Effect.Effect<boolean, E, R>,
69
+ readonly handle: Effect.Effect<Discord.InteractionResponse, E, R>,
70
70
  ) {}
71
71
  }
72
72
 
73
73
  export const messageComponent = <R1, R2, E1, E2>(
74
- pred: (customId: string) => Effect.Effect<R1, E1, boolean>,
74
+ pred: (customId: string) => Effect.Effect<boolean, E1, R1>,
75
75
  handle: CommandHandler<R2, E2, Discord.InteractionResponse>,
76
76
  ) =>
77
77
  new MessageComponent<
@@ -82,14 +82,14 @@ export const messageComponent = <R1, R2, E1, E2>(
82
82
  export class ModalSubmit<R, E> {
83
83
  readonly _tag = "ModalSubmit"
84
84
  constructor(
85
- readonly predicate: (customId: string) => Effect.Effect<R, E, boolean>,
86
- readonly handle: Effect.Effect<R, E, Discord.InteractionResponse>,
85
+ readonly predicate: (customId: string) => Effect.Effect<boolean, E, R>,
86
+ readonly handle: Effect.Effect<Discord.InteractionResponse, E, R>,
87
87
  ) {}
88
88
  }
89
89
 
90
90
  export const modalSubmit = <R1, R2, E1, E2>(
91
- pred: (customId: string) => Effect.Effect<R1, E1, boolean>,
92
- handle: Effect.Effect<R2, E2, Discord.InteractionResponse>,
91
+ pred: (customId: string) => Effect.Effect<boolean, E1, R1>,
92
+ handle: Effect.Effect<Discord.InteractionResponse, E2, R2>,
93
93
  ) =>
94
94
  new ModalSubmit<
95
95
  Exclude<R1 | R2, DiscordInteraction | DiscordModalSubmit>,
@@ -102,8 +102,8 @@ export class Autocomplete<R, E> {
102
102
  readonly predicate: (
103
103
  data: Discord.ApplicationCommandDatum,
104
104
  focusedOption: Discord.ApplicationCommandInteractionDataOption,
105
- ) => Effect.Effect<R, E, boolean>,
106
- readonly handle: Effect.Effect<R, E, Discord.InteractionResponse>,
105
+ ) => Effect.Effect<boolean, E, R>,
106
+ readonly handle: Effect.Effect<Discord.InteractionResponse, E, R>,
107
107
  ) {}
108
108
  }
109
109
 
@@ -111,8 +111,8 @@ export const autocomplete = <R1, R2, E1, E2>(
111
111
  pred: (
112
112
  data: Discord.ApplicationCommandDatum,
113
113
  focusedOption: Discord.ApplicationCommandInteractionDataOption,
114
- ) => Effect.Effect<R1, E1, boolean>,
115
- handle: Effect.Effect<R2, E2, Discord.InteractionResponse>,
114
+ ) => Effect.Effect<boolean, E1, R1>,
115
+ handle: Effect.Effect<Discord.InteractionResponse, E2, R2>,
116
116
  ) =>
117
117
  new Autocomplete<
118
118
  Exclude<
@@ -135,33 +135,33 @@ type DeepReadonlyObject<T> = {
135
135
  }
136
136
 
137
137
  export type CommandHandler<R, E, A = any> =
138
- | Effect.Effect<R, E, Discord.InteractionResponse>
138
+ | Effect.Effect<Discord.InteractionResponse, E, R>
139
139
  | CommandHandlerFn<R, E, A>
140
140
 
141
141
  export interface CommandHelper<A> {
142
142
  resolve: <T>(
143
143
  name: AllResolvables<A>["name"],
144
144
  f: (id: Discord.Snowflake, data: Discord.ResolvedDatum) => T | undefined,
145
- ) => Effect.Effect<DiscordInteraction, ResolvedDataNotFound, T>
145
+ ) => Effect.Effect<T, ResolvedDataNotFound, DiscordInteraction>
146
146
 
147
147
  option: (
148
148
  name: AllCommandOptions<A>["name"],
149
149
  ) => Effect.Effect<
150
- DiscordApplicationCommand,
150
+ Option.Option<Discord.ApplicationCommandInteractionDataOption>,
151
151
  never,
152
- Option.Option<Discord.ApplicationCommandInteractionDataOption>
152
+ DiscordApplicationCommand
153
153
  >
154
154
 
155
155
  optionValue: <N extends AllRequiredCommandOptions<A>["name"]>(
156
156
  name: N,
157
- ) => Effect.Effect<DiscordApplicationCommand, never, CommandValue<A, N>>
157
+ ) => Effect.Effect<CommandValue<A, N>, never, DiscordApplicationCommand>
158
158
 
159
159
  optionValueOptional: <N extends AllCommandOptions<A>["name"]>(
160
160
  name: N,
161
161
  ) => Effect.Effect<
162
- DiscordApplicationCommand,
162
+ Option.Option<CommandValue<A, N>>,
163
163
  never,
164
- Option.Option<CommandValue<A, N>>
164
+ DiscordApplicationCommand
165
165
  >
166
166
 
167
167
  subCommands: <
@@ -169,33 +169,29 @@ export interface CommandHelper<A> {
169
169
  ? never
170
170
  : Record<
171
171
  SubCommandNames<A>,
172
- Effect.Effect<any, any, Discord.InteractionResponse>
172
+ Effect.Effect<Discord.InteractionResponse, any, any>
173
173
  >,
174
174
  >(
175
175
  commands: NER,
176
- ) => Effect.Effect<
177
- | Exclude<
178
- [NER[keyof NER]] extends [
179
- { [Effect.EffectTypeId]: { _R: (_: never) => infer R } },
180
- ]
181
- ? R
182
- : never,
183
- SubCommandContext
184
- >
185
- | DiscordInteraction
186
- | DiscordApplicationCommand,
187
- [NER[keyof NER]] extends [
188
- { [Effect.EffectTypeId]: { _E: (_: never) => infer E } },
189
- ]
190
- ? E
191
- : never,
192
- Discord.InteractionResponse
193
- >
176
+ ) => Effect.Effect<Discord.InteractionResponse, [NER[keyof NER]] extends [
177
+ { [Effect.EffectTypeId]: { _E: (_: never) => infer E } },
178
+ ]
179
+ ? E
180
+ : never, | Exclude<
181
+ [NER[keyof NER]] extends [
182
+ { [Effect.EffectTypeId]: { _R: (_: never) => infer R } },
183
+ ]
184
+ ? R
185
+ : never,
186
+ SubCommandContext
187
+ >
188
+ | DiscordInteraction
189
+ | DiscordApplicationCommand>
194
190
  }
195
191
 
196
192
  export type CommandHandlerFn<R, E, A> = (
197
193
  i: CommandHelper<A>,
198
- ) => Effect.Effect<R, E, Discord.InteractionResponse>
194
+ ) => Effect.Effect<Discord.InteractionResponse, E, R>
199
195
 
200
196
  interface CommandOption {
201
197
  readonly type: any
@@ -1,5 +1,5 @@
1
1
  import * as Chunk from "effect/Chunk"
2
- import { Tag } from "effect/Context"
2
+ import { GenericTag } from "effect/Context"
3
3
  import * as Duration from "effect/Duration"
4
4
  import { pipe } from "effect/Function"
5
5
  import * as Effect from "effect/Effect"
@@ -37,20 +37,12 @@ export const setInteractionsSync = (enabled: boolean) =>
37
37
  export const run =
38
38
  <R, R2, E, TE, E2>(
39
39
  postHandler: (
40
- effect: Effect.Effect<
41
- R | DiscordREST | DiscordInteraction,
42
- TE | DiscordRESTError | DefinitionNotFound,
43
- void
44
- >,
45
- ) => Effect.Effect<R2, E2, void>,
40
+ effect: Effect.Effect<void, TE | DiscordRESTError | DefinitionNotFound, R | DiscordREST | DiscordInteraction>,
41
+ ) => Effect.Effect<void, E2, R2>,
46
42
  ) =>
47
43
  (
48
44
  ix: InteractionBuilder<R, E, TE>,
49
- ): Effect.Effect<
50
- DiscordREST | DiscordGateway | Exclude<R2, DiscordInteraction>,
51
- E2 | DiscordRESTError | Http.error.ResponseError,
52
- never
53
- > =>
45
+ ): Effect.Effect<never, E2 | DiscordRESTError | Http.error.ResponseError, DiscordREST | DiscordGateway | Exclude<R2, DiscordInteraction>> =>
54
46
  Effect.gen(function* (_) {
55
47
  const GlobalApplicationCommand = ix.definitions.pipe(
56
48
  Chunk.map(_ => _[0]),
@@ -160,13 +152,13 @@ const makeRegistry = Effect.gen(function* (_) {
160
152
  export interface InteractionsRegistryService {
161
153
  readonly register: <E>(
162
154
  ix: InteractionBuilder<never, E, never>,
163
- ) => Effect.Effect<never, never, void>
155
+ ) => Effect.Effect<void>
164
156
  }
165
157
  export interface InteractionsRegistry {
166
158
  readonly _: unique symbol
167
159
  }
168
160
 
169
- export const InteractionsRegistry = Tag<
161
+ export const InteractionsRegistry = GenericTag<
170
162
  InteractionsRegistry,
171
163
  InteractionsRegistryService
172
164
  >("dfx/Interactions/InteractionsRegistry")
@@ -12,23 +12,19 @@ export class DefinitionNotFound {
12
12
  constructor(readonly interaction: Discord.Interaction) {}
13
13
  }
14
14
 
15
- type Handler<R, E, A> = Effect.Effect<
16
- R | Ctx.DiscordInteraction,
17
- E | DefinitionNotFound,
18
- A
19
- >
15
+ type Handler<R, E, A> = Effect.Effect<A, E | DefinitionNotFound, R | Ctx.DiscordInteraction>
20
16
 
21
17
  export const handlers = <R, E, TE, A, B>(
22
18
  definitions: Chunk.Chunk<
23
19
  readonly [
24
20
  handler: D.InteractionDefinition<R, E>,
25
- transform: (self: Effect.Effect<R, E, A>) => Effect.Effect<R, TE, B>,
21
+ transform: (self: Effect.Effect<A, E, R>) => Effect.Effect<B, TE, R>,
26
22
  ]
27
23
  >,
28
24
  handleResponse: (
29
25
  ix: Discord.Interaction,
30
26
  _: Discord.InteractionResponse,
31
- ) => Effect.Effect<R, E, A>,
27
+ ) => Effect.Effect<A, E, R>,
32
28
  ): Record<
33
29
  Discord.InteractionType,
34
30
  (i: Discord.Interaction) => Handler<R, E, B>
@@ -10,7 +10,7 @@ export type DefinitionFlattened<R, E, TE, A> = D.InteractionDefinition<
10
10
  > extends infer D
11
11
  ? {
12
12
  [K in keyof D]: K extends "handle"
13
- ? (_: Discord.Interaction) => Effect.Effect<R, TE, A>
13
+ ? (_: Discord.Interaction) => Effect.Effect<A, TE, R>
14
14
  : D[K]
15
15
  }
16
16
  : never
@@ -32,13 +32,13 @@ export const flattenDefinitions = <R, E, TE, A, B>(
32
32
  definitions: Chunk.Chunk<
33
33
  readonly [
34
34
  handler: D.InteractionDefinition<R, E>,
35
- transform: (self: Effect.Effect<R, E, A>) => Effect.Effect<R, TE, B>,
35
+ transform: (self: Effect.Effect<A, E, R>) => Effect.Effect<B, TE, R>,
36
36
  ]
37
37
  >,
38
38
  handleResponse: (
39
39
  ix: Discord.Interaction,
40
40
  _: Discord.InteractionResponse,
41
- ) => Effect.Effect<R, E, A>,
41
+ ) => Effect.Effect<A, E, R>,
42
42
  ) =>
43
43
  Chunk.map(definitions, ([definition, transform]) => ({
44
44
  ...definition,
@@ -83,10 +83,10 @@ export const splitDefinitions = <R, E, TE, A>(
83
83
  Chunk.reduce(
84
84
  {} as Record<string, DefinitionFlattenedCommand<R, E, TE, A>>,
85
85
  (acc, d) =>
86
- ({
86
+ (({
87
87
  ...acc,
88
- [d.command.name]: d,
89
- }) as any,
88
+ [d.command.name]: d
89
+ }) as any),
90
90
  ),
91
91
  )
92
92