dfx 0.51.0 → 0.51.2

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 (335) hide show
  1. package/Cache/driver.d.ts +17 -16
  2. package/Cache/driver.d.ts.map +1 -1
  3. package/Cache/driver.js +10 -2
  4. package/Cache/driver.js.map +1 -1
  5. package/Cache/memory.d.ts +3 -3
  6. package/Cache/memory.d.ts.map +1 -1
  7. package/Cache/memory.js +55 -45
  8. package/Cache/memory.js.map +1 -1
  9. package/Cache/memoryTTL.d.ts +7 -6
  10. package/Cache/memoryTTL.d.ts.map +1 -1
  11. package/Cache/memoryTTL.js +126 -118
  12. package/Cache/memoryTTL.js.map +1 -1
  13. package/Cache/prelude.d.ts +53 -47
  14. package/Cache/prelude.d.ts.map +1 -1
  15. package/Cache/prelude.js +125 -96
  16. package/Cache/prelude.js.map +1 -1
  17. package/Cache.d.ts +33 -32
  18. package/Cache.d.ts.map +1 -1
  19. package/Cache.js +137 -65
  20. package/Cache.js.map +1 -1
  21. package/DiscordConfig.d.ts +26 -20
  22. package/DiscordConfig.d.ts.map +1 -1
  23. package/DiscordConfig.js +43 -25
  24. package/DiscordConfig.js.map +1 -1
  25. package/DiscordGateway/DiscordWS.d.ts +17 -14
  26. package/DiscordGateway/DiscordWS.d.ts.map +1 -1
  27. package/DiscordGateway/DiscordWS.js +49 -30
  28. package/DiscordGateway/DiscordWS.js.map +1 -1
  29. package/DiscordGateway/Shard/heartbeats.d.ts +7 -3
  30. package/DiscordGateway/Shard/heartbeats.d.ts.map +1 -1
  31. package/DiscordGateway/Shard/heartbeats.js +28 -18
  32. package/DiscordGateway/Shard/heartbeats.js.map +1 -1
  33. package/DiscordGateway/Shard/identify.d.ts +10 -8
  34. package/DiscordGateway/Shard/identify.d.ts.map +1 -1
  35. package/DiscordGateway/Shard/identify.js +41 -24
  36. package/DiscordGateway/Shard/identify.js.map +1 -1
  37. package/DiscordGateway/Shard/invalidSession.d.ts +6 -3
  38. package/DiscordGateway/Shard/invalidSession.d.ts.map +1 -1
  39. package/DiscordGateway/Shard/invalidSession.js +14 -5
  40. package/DiscordGateway/Shard/invalidSession.js.map +1 -1
  41. package/DiscordGateway/Shard/sendEvents.d.ts +1 -1
  42. package/DiscordGateway/Shard/sendEvents.d.ts.map +1 -1
  43. package/DiscordGateway/Shard/sendEvents.js +30 -18
  44. package/DiscordGateway/Shard/sendEvents.js.map +1 -1
  45. package/DiscordGateway/Shard/utils.d.ts +7 -3
  46. package/DiscordGateway/Shard/utils.d.ts.map +1 -1
  47. package/DiscordGateway/Shard/utils.js +19 -9
  48. package/DiscordGateway/Shard/utils.js.map +1 -1
  49. package/DiscordGateway/Shard.d.ts +15 -10
  50. package/DiscordGateway/Shard.d.ts.map +1 -1
  51. package/DiscordGateway/Shard.js +109 -87
  52. package/DiscordGateway/Shard.js.map +1 -1
  53. package/DiscordGateway/ShardStore.d.ts +9 -6
  54. package/DiscordGateway/ShardStore.d.ts.map +1 -1
  55. package/DiscordGateway/ShardStore.js +30 -18
  56. package/DiscordGateway/ShardStore.js.map +1 -1
  57. package/DiscordGateway/Sharder.d.ts +17 -11
  58. package/DiscordGateway/Sharder.d.ts.map +1 -1
  59. package/DiscordGateway/Sharder.js +82 -52
  60. package/DiscordGateway/Sharder.js.map +1 -1
  61. package/DiscordGateway/WS.d.ts +13 -10
  62. package/DiscordGateway/WS.d.ts.map +1 -1
  63. package/DiscordGateway/WS.js +100 -74
  64. package/DiscordGateway/WS.js.map +1 -1
  65. package/DiscordGateway.d.ts +19 -13
  66. package/DiscordGateway.d.ts.map +1 -1
  67. package/DiscordGateway.js +45 -32
  68. package/DiscordGateway.js.map +1 -1
  69. package/DiscordREST/types.d.ts +5 -5
  70. package/DiscordREST/types.d.ts.map +1 -1
  71. package/DiscordREST/types.js +5 -1
  72. package/DiscordREST/types.js.map +1 -1
  73. package/DiscordREST/utils.d.ts +3 -2
  74. package/DiscordREST/utils.d.ts.map +1 -1
  75. package/DiscordREST/utils.js +27 -17
  76. package/DiscordREST/utils.js.map +1 -1
  77. package/DiscordREST.d.ts +11 -8
  78. package/DiscordREST.d.ts.map +1 -1
  79. package/DiscordREST.js +141 -127
  80. package/DiscordREST.js.map +1 -1
  81. package/Helpers/flags.js +31 -19
  82. package/Helpers/flags.js.map +1 -1
  83. package/Helpers/intents.d.ts.map +1 -1
  84. package/Helpers/intents.js +22 -10
  85. package/Helpers/intents.js.map +1 -1
  86. package/Helpers/interactions.d.ts +22 -21
  87. package/Helpers/interactions.d.ts.map +1 -1
  88. package/Helpers/interactions.js +75 -39
  89. package/Helpers/interactions.js.map +1 -1
  90. package/Helpers/members.d.ts +3 -3
  91. package/Helpers/members.d.ts.map +1 -1
  92. package/Helpers/members.js +10 -3
  93. package/Helpers/members.js.map +1 -1
  94. package/Helpers/permissions.d.ts +5 -4
  95. package/Helpers/permissions.d.ts.map +1 -1
  96. package/Helpers/permissions.js +69 -52
  97. package/Helpers/permissions.js.map +1 -1
  98. package/Helpers/ui.d.ts +1 -1
  99. package/Helpers/ui.d.ts.map +1 -1
  100. package/Helpers/ui.js +44 -29
  101. package/Helpers/ui.js.map +1 -1
  102. package/Interactions/builder.d.ts +20 -19
  103. package/Interactions/builder.d.ts.map +1 -1
  104. package/Interactions/builder.js +66 -63
  105. package/Interactions/builder.js.map +1 -1
  106. package/Interactions/context.d.ts +26 -23
  107. package/Interactions/context.d.ts.map +1 -1
  108. package/Interactions/context.js +86 -57
  109. package/Interactions/context.js.map +1 -1
  110. package/Interactions/definitions.d.ts +33 -30
  111. package/Interactions/definitions.d.ts.map +1 -1
  112. package/Interactions/definitions.js +61 -47
  113. package/Interactions/definitions.js.map +1 -1
  114. package/Interactions/gateway.d.ts +15 -10
  115. package/Interactions/gateway.d.ts.map +1 -1
  116. package/Interactions/gateway.js +55 -42
  117. package/Interactions/gateway.js.map +1 -1
  118. package/Interactions/handlers.d.ts +6 -4
  119. package/Interactions/handlers.d.ts.map +1 -1
  120. package/Interactions/handlers.js +68 -57
  121. package/Interactions/handlers.js.map +1 -1
  122. package/Interactions/index.d.ts +11 -10
  123. package/Interactions/index.d.ts.map +1 -1
  124. package/Interactions/index.js +95 -10
  125. package/Interactions/index.js.map +1 -1
  126. package/Interactions/utils.d.ts +42 -40
  127. package/Interactions/utils.d.ts.map +1 -1
  128. package/Interactions/utils.js +40 -32
  129. package/Interactions/utils.js.map +1 -1
  130. package/Interactions/webhook.d.ts +20 -16
  131. package/Interactions/webhook.d.ts.map +1 -1
  132. package/Interactions/webhook.js +73 -41
  133. package/Interactions/webhook.js.map +1 -1
  134. package/Log.d.ts +8 -5
  135. package/Log.d.ts.map +1 -1
  136. package/Log.js +23 -14
  137. package/Log.js.map +1 -1
  138. package/RateLimit/memory.d.ts +1 -1
  139. package/RateLimit/memory.d.ts.map +1 -1
  140. package/RateLimit/memory.js +46 -33
  141. package/RateLimit/memory.js.map +1 -1
  142. package/RateLimit/utils.d.ts +1 -1
  143. package/RateLimit/utils.d.ts.map +1 -1
  144. package/RateLimit/utils.js +23 -16
  145. package/RateLimit/utils.js.map +1 -1
  146. package/RateLimit.d.ts +18 -14
  147. package/RateLimit.d.ts.map +1 -1
  148. package/RateLimit.js +40 -26
  149. package/RateLimit.js.map +1 -1
  150. package/gateway.d.ts +20 -13
  151. package/gateway.d.ts.map +1 -1
  152. package/gateway.js +72 -25
  153. package/gateway.js.map +1 -1
  154. package/index.d.ts +14 -13
  155. package/index.d.ts.map +1 -1
  156. package/index.js +71 -13
  157. package/index.js.map +1 -1
  158. package/mjs/Cache/driver.mjs +3 -0
  159. package/mjs/Cache/driver.mjs.map +1 -0
  160. package/mjs/Cache/memory.mjs +48 -0
  161. package/mjs/Cache/memory.mjs.map +1 -0
  162. package/mjs/Cache/memoryTTL.mjs +119 -0
  163. package/mjs/Cache/memoryTTL.mjs.map +1 -0
  164. package/mjs/Cache/prelude.mjs +125 -0
  165. package/mjs/Cache/prelude.mjs.map +1 -0
  166. package/mjs/Cache.mjs +87 -0
  167. package/mjs/Cache.mjs.map +1 -0
  168. package/mjs/DiscordConfig.mjs +34 -0
  169. package/mjs/DiscordConfig.mjs.map +1 -0
  170. package/mjs/DiscordGateway/DiscordWS.mjs +39 -0
  171. package/mjs/DiscordGateway/DiscordWS.mjs.map +1 -0
  172. package/mjs/DiscordGateway/Shard/heartbeats.mjs +21 -0
  173. package/mjs/DiscordGateway/Shard/heartbeats.mjs.map +1 -0
  174. package/mjs/DiscordGateway/Shard/identify.mjs +37 -0
  175. package/mjs/DiscordGateway/Shard/identify.mjs.map +1 -0
  176. package/mjs/DiscordGateway/Shard/invalidSession.mjs +6 -0
  177. package/mjs/DiscordGateway/Shard/invalidSession.mjs.map +1 -0
  178. package/mjs/DiscordGateway/Shard/sendEvents.mjs +25 -0
  179. package/mjs/DiscordGateway/Shard/sendEvents.mjs.map +1 -0
  180. package/mjs/DiscordGateway/Shard/utils.mjs +11 -0
  181. package/mjs/DiscordGateway/Shard/utils.mjs.map +1 -0
  182. package/mjs/DiscordGateway/Shard.mjs +99 -0
  183. package/mjs/DiscordGateway/Shard.mjs.map +1 -0
  184. package/mjs/DiscordGateway/ShardStore.mjs +24 -0
  185. package/mjs/DiscordGateway/ShardStore.mjs.map +1 -0
  186. package/mjs/DiscordGateway/Sharder.mjs +73 -0
  187. package/mjs/DiscordGateway/Sharder.mjs.map +1 -0
  188. package/mjs/DiscordGateway/WS.mjs +94 -0
  189. package/mjs/DiscordGateway/WS.mjs.map +1 -0
  190. package/mjs/DiscordGateway.mjs +36 -0
  191. package/mjs/DiscordGateway.mjs.map +1 -0
  192. package/mjs/DiscordREST/types.mjs +2 -0
  193. package/mjs/DiscordREST/types.mjs.map +1 -0
  194. package/mjs/DiscordREST/utils.mjs +19 -0
  195. package/mjs/DiscordREST/utils.mjs.map +1 -0
  196. package/mjs/DiscordREST.mjs +129 -0
  197. package/mjs/DiscordREST.mjs.map +1 -0
  198. package/mjs/Helpers/flags.mjs +36 -0
  199. package/mjs/Helpers/flags.mjs.map +1 -0
  200. package/mjs/Helpers/intents.mjs +27 -0
  201. package/mjs/Helpers/intents.mjs.map +1 -0
  202. package/mjs/Helpers/interactions.mjs +104 -0
  203. package/mjs/Helpers/interactions.mjs.map +1 -0
  204. package/mjs/Helpers/members.mjs +9 -0
  205. package/mjs/Helpers/members.mjs.map +1 -0
  206. package/mjs/Helpers/permissions.mjs +82 -0
  207. package/mjs/Helpers/permissions.mjs.map +1 -0
  208. package/mjs/Helpers/ui.mjs +66 -0
  209. package/mjs/Helpers/ui.mjs.map +1 -0
  210. package/mjs/Interactions/builder.mjs +62 -0
  211. package/mjs/Interactions/builder.mjs.map +1 -0
  212. package/mjs/Interactions/context.mjs +63 -0
  213. package/mjs/Interactions/context.mjs.map +1 -0
  214. package/mjs/Interactions/definitions.mjs +51 -0
  215. package/mjs/Interactions/definitions.mjs.map +1 -0
  216. package/mjs/Interactions/gateway.mjs +48 -0
  217. package/mjs/Interactions/gateway.mjs.map +1 -0
  218. package/mjs/Interactions/handlers.mjs +61 -0
  219. package/mjs/Interactions/handlers.mjs.map +1 -0
  220. package/mjs/Interactions/index.mjs +12 -0
  221. package/mjs/Interactions/index.mjs.map +1 -0
  222. package/mjs/Interactions/utils.mjs +35 -0
  223. package/mjs/Interactions/utils.mjs.map +1 -0
  224. package/mjs/Interactions/webhook.mjs +73 -0
  225. package/mjs/Interactions/webhook.mjs.map +1 -0
  226. package/mjs/Log.mjs +15 -0
  227. package/mjs/Log.mjs.map +1 -0
  228. package/mjs/RateLimit/memory.mjs +39 -0
  229. package/mjs/RateLimit/memory.mjs.map +1 -0
  230. package/mjs/RateLimit/utils.mjs +18 -0
  231. package/mjs/RateLimit/utils.mjs.map +1 -0
  232. package/mjs/RateLimit.mjs +29 -0
  233. package/mjs/RateLimit.mjs.map +1 -0
  234. package/mjs/gateway.mjs +27 -0
  235. package/mjs/gateway.mjs.map +1 -0
  236. package/mjs/index.mjs +15 -0
  237. package/mjs/index.mjs.map +1 -0
  238. package/mjs/types.mjs +1211 -0
  239. package/mjs/types.mjs.map +1 -0
  240. package/mjs/utils/Effect.mjs +28 -0
  241. package/mjs/utils/Effect.mjs.map +1 -0
  242. package/mjs/utils/tsplus.mjs +2 -0
  243. package/mjs/utils/tsplus.mjs.map +1 -0
  244. package/mjs/version.mjs +2 -0
  245. package/mjs/version.mjs.map +1 -0
  246. package/mjs/webhooks.mjs +30 -0
  247. package/mjs/webhooks.mjs.map +1 -0
  248. package/package.json +46 -50
  249. package/src/Cache/driver.ts +27 -15
  250. package/src/Cache/memory.ts +9 -5
  251. package/src/Cache/memoryTTL.ts +69 -53
  252. package/src/Cache/prelude.ts +113 -91
  253. package/src/Cache.ts +73 -58
  254. package/src/DiscordConfig.ts +33 -19
  255. package/src/DiscordGateway/DiscordWS.ts +28 -25
  256. package/src/DiscordGateway/Shard/heartbeats.ts +47 -27
  257. package/src/DiscordGateway/Shard/identify.ts +29 -25
  258. package/src/DiscordGateway/Shard/invalidSession.ts +9 -7
  259. package/src/DiscordGateway/Shard/sendEvents.ts +1 -1
  260. package/src/DiscordGateway/Shard/utils.ts +33 -9
  261. package/src/DiscordGateway/Shard.ts +119 -99
  262. package/src/DiscordGateway/ShardStore.ts +12 -5
  263. package/src/DiscordGateway/Sharder.ts +95 -74
  264. package/src/DiscordGateway/WS.ts +85 -60
  265. package/src/DiscordGateway.ts +58 -18
  266. package/src/DiscordREST/types.ts +5 -5
  267. package/src/DiscordREST/utils.ts +10 -7
  268. package/src/DiscordREST.ts +152 -132
  269. package/src/Helpers/intents.ts +1 -0
  270. package/src/Helpers/interactions.ts +51 -38
  271. package/src/Helpers/members.ts +2 -0
  272. package/src/Helpers/permissions.ts +6 -5
  273. package/src/Helpers/ui.ts +1 -1
  274. package/src/Interactions/builder.ts +56 -43
  275. package/src/Interactions/context.ts +68 -38
  276. package/src/Interactions/definitions.ts +32 -24
  277. package/src/Interactions/gateway.ts +72 -47
  278. package/src/Interactions/handlers.ts +56 -39
  279. package/src/Interactions/index.ts +6 -5
  280. package/src/Interactions/utils.ts +32 -21
  281. package/src/Interactions/webhook.ts +78 -42
  282. package/src/Log.ts +4 -0
  283. package/src/RateLimit/memory.ts +10 -4
  284. package/src/RateLimit/utils.ts +1 -1
  285. package/src/RateLimit.ts +38 -25
  286. package/src/gateway.ts +62 -25
  287. package/src/index.ts +29 -15
  288. package/src/utils/Effect.ts +69 -0
  289. package/src/version.ts +1 -0
  290. package/src/webhooks.ts +47 -20
  291. package/tsconfig.base.json +48 -0
  292. package/tsconfig.build.json +10 -0
  293. package/tsconfig.examples.json +11 -0
  294. package/tsconfig.json +12 -8
  295. package/tsconfig.madge.json +12 -0
  296. package/tsconfig.test.json +10 -0
  297. package/types.d.ts.map +1 -1
  298. package/types.js +1216 -1200
  299. package/types.js.map +1 -1
  300. package/utils/Effect.d.ts +8 -0
  301. package/utils/Effect.d.ts.map +1 -0
  302. package/utils/Effect.js +38 -0
  303. package/utils/Effect.js.map +1 -0
  304. package/utils/tsplus.js +5 -1
  305. package/utils/tsplus.js.map +1 -1
  306. package/version.d.ts +2 -0
  307. package/version.d.ts.map +1 -0
  308. package/version.js +9 -0
  309. package/version.js.map +1 -0
  310. package/webhooks.d.ts +14 -9
  311. package/webhooks.d.ts.map +1 -1
  312. package/webhooks.js +76 -27
  313. package/webhooks.js.map +1 -1
  314. package/_common.d.ts +0 -37
  315. package/_common.d.ts.map +0 -1
  316. package/_common.js +0 -8
  317. package/_common.js.map +0 -1
  318. package/global.d.ts +0 -18
  319. package/global.d.ts.map +0 -1
  320. package/global.js +0 -2
  321. package/global.js.map +0 -1
  322. package/src/_common.ts +0 -43
  323. package/src/global.ts +0 -45
  324. package/src/package.json +0 -52
  325. package/src/utils/effect.ts +0 -0
  326. package/src/utils/hub.ts +0 -47
  327. package/tsplus.config.json +0 -8
  328. package/utils/effect.d.ts +0 -2
  329. package/utils/effect.d.ts.map +0 -1
  330. package/utils/effect.js +0 -2
  331. package/utils/effect.js.map +0 -1
  332. package/utils/hub.d.ts +0 -12
  333. package/utils/hub.d.ts.map +0 -1
  334. package/utils/hub.js +0 -26
  335. package/utils/hub.js.map +0 -1
@@ -1,9 +1,12 @@
1
1
  import * as Http from "@effect-http/client"
2
+ import * as Chunk from "@effect/data/Chunk"
3
+ import { identity } from "@effect/data/Function"
4
+ import type * as Cause from "@effect/io/Cause"
5
+ import * as Effect from "@effect/io/Effect"
2
6
  import { catchTag } from "@effect/io/Effect"
3
- import { DiscordREST } from "dfx"
4
- import { Discord, Effect } from "dfx/_common"
5
- import * as D from "./definitions.js"
6
- import { DiscordRESTError } from "dfx/DiscordREST"
7
+ import { DiscordREST, type DiscordRESTError } from "dfx/DiscordREST"
8
+ import type * as Discord from "dfx/types"
9
+ import type * as D from "dfx/Interactions/definitions"
7
10
 
8
11
  type ExtractTag<A> = A extends { _tag: infer Tag }
9
12
  ? Tag extends string
@@ -16,49 +19,53 @@ type ExtractTag<A> = A extends { _tag: infer Tag }
16
19
  */
17
20
  export class InteractionBuilder<R, E, TE> {
18
21
  constructor(
19
- readonly definitions: Chunk<
22
+ readonly definitions: Chunk.Chunk<
20
23
  readonly [
21
24
  handler: D.InteractionDefinition<R, E>,
22
- transform: (self: Effect<any, any, any>) => Effect<R, TE, void>,
25
+ transform: (
26
+ self: Effect.Effect<any, any, any>,
27
+ ) => Effect.Effect<R, TE, void>,
23
28
  ]
24
29
  >,
25
- readonly transform: (self: Effect<any, any, any>) => Effect<R, TE, void>,
30
+ readonly transform: (
31
+ self: Effect.Effect<any, any, any>,
32
+ ) => Effect.Effect<R, TE, void>,
26
33
  ) {}
27
34
 
28
35
  add<R1, E1>(definition: D.InteractionDefinition<R1, E1>) {
29
36
  return new InteractionBuilder<R | R1, E | E1, TE | E1>(
30
- this.definitions.append([definition, this.transform] as const),
37
+ Chunk.append(this.definitions, [definition, this.transform] as const),
31
38
  this.transform,
32
39
  )
33
40
  }
34
41
 
35
42
  concat<R1, E1, TE1>(builder: InteractionBuilder<R1, E1, TE1>) {
36
43
  return new InteractionBuilder<R | R1, E | E1, TE | TE1>(
37
- this.definitions.appendAll(builder.definitions),
44
+ Chunk.appendAll(this.definitions, builder.definitions),
38
45
  this.transform,
39
46
  )
40
47
  }
41
48
 
42
49
  private transformTransform<R1, E1>(
43
- f: (selr: Effect<R, TE, void>) => Effect<R1, E1, void>,
50
+ f: (selr: Effect.Effect<R, TE, void>) => Effect.Effect<R1, E1, void>,
44
51
  ) {
45
52
  return new InteractionBuilder<R1, E, E1>(
46
- this.definitions.map(([d, t]) => [d as any, _ => f(t(_)) as any]),
53
+ Chunk.map(this.definitions, ([d, t]) => [d as any, _ => f(t(_)) as any]),
47
54
  _ => f(this.transform(_)) as any,
48
55
  )
49
56
  }
50
57
 
51
58
  private transformHandlers<R1, E1>(
52
59
  f: (
53
- selr: Effect<R, E, Discord.InteractionResponse>,
54
- ) => Effect<R1, E1, Discord.InteractionResponse>,
60
+ selr: Effect.Effect<R, E, Discord.InteractionResponse>,
61
+ ) => Effect.Effect<R1, E1, Discord.InteractionResponse>,
55
62
  ) {
56
63
  return new InteractionBuilder<
57
64
  R1,
58
65
  E1,
59
66
  Exclude<TE, Exclude<E, E1>> | Exclude<E1, E>
60
67
  >(
61
- this.definitions.map(([d, t]) => [
68
+ Chunk.map(this.definitions, ([d, t]) => [
62
69
  {
63
70
  ...d,
64
71
  handle: Effect.isEffect(d.handle)
@@ -71,29 +78,33 @@ export class InteractionBuilder<R, E, TE> {
71
78
  )
72
79
  }
73
80
 
74
- catchAllCause<R1, E1>(f: (cause: Cause<TE>) => Effect<R1, E1, void>) {
75
- return this.transformTransform<R | R1, E1>(_ => _.catchAllCause(f))
81
+ catchAllCause<R1, E1>(
82
+ f: (cause: Cause.Cause<TE>) => Effect.Effect<R1, E1, void>,
83
+ ) {
84
+ return this.transformTransform<R | R1, E1>(Effect.catchAllCause(f))
76
85
  }
77
86
 
78
87
  catchAllCauseRespond<R1, E1>(
79
- f: (cause: Cause<E>) => Effect<R1, E1, Discord.InteractionResponse>,
88
+ f: (
89
+ cause: Cause.Cause<E>,
90
+ ) => Effect.Effect<R1, E1, Discord.InteractionResponse>,
80
91
  ) {
81
- return this.transformHandlers<R | R1, E1>(_ => _.catchAllCause(f))
92
+ return this.transformHandlers<R | R1, E1>(Effect.catchAllCause(f))
82
93
  }
83
94
 
84
- catchAll<R1, E1>(f: (error: TE) => Effect<R1, E1, void>) {
85
- return this.transformTransform<R | R1, E1>(_ => _.catchAll(f))
95
+ catchAll<R1, E1>(f: (error: TE) => Effect.Effect<R1, E1, void>) {
96
+ return this.transformTransform<R | R1, E1>(Effect.catchAll(f))
86
97
  }
87
98
 
88
99
  catchAllRespond<R1, E1>(
89
- f: (error: E) => Effect<R1, E1, Discord.InteractionResponse>,
100
+ f: (error: E) => Effect.Effect<R1, E1, Discord.InteractionResponse>,
90
101
  ) {
91
- return this.transformHandlers<R | R1, E1>(_ => _.catchAll(f))
102
+ return this.transformHandlers<R | R1, E1>(Effect.catchAll(f))
92
103
  }
93
104
 
94
105
  catchTag<T extends ExtractTag<E>, R1, E1>(
95
106
  tag: T,
96
- f: (error: Extract<TE, { _tag: T }>) => Effect<R1, E1, void>,
107
+ f: (error: Extract<TE, { _tag: T }>) => Effect.Effect<R1, E1, void>,
97
108
  ) {
98
109
  return this.transformTransform<R | R1, Exclude<TE, { _tag: T }> | E1>(
99
110
  _ => catchTag(_ as any, tag, f as any) as any,
@@ -104,7 +115,7 @@ export class InteractionBuilder<R, E, TE> {
104
115
  tag: T,
105
116
  f: (
106
117
  error: Extract<E, { _tag: T }>,
107
- ) => Effect<R1, E1, Discord.InteractionResponse>,
118
+ ) => Effect.Effect<R1, E1, Discord.InteractionResponse>,
108
119
  ) {
109
120
  return this.transformHandlers<R | R1, Exclude<E, { _tag: T }> | E1>(
110
121
  _ => catchTag(_ as any, tag, f as any) as any,
@@ -112,40 +123,42 @@ export class InteractionBuilder<R, E, TE> {
112
123
  }
113
124
 
114
125
  get syncGlobal() {
115
- const commands = this.definitions
116
- .map(([d, _]) => d)
117
- .filter(
126
+ const commands = this.definitions.pipe(
127
+ Chunk.map(([d, _]) => d),
128
+ Chunk.filter(
118
129
  (c): c is D.GlobalApplicationCommand<R, E> =>
119
130
  c._tag === "GlobalApplicationCommand",
120
- )
121
- .map(c => c.command)
122
-
123
- return DiscordREST.accessWithEffect(rest =>
124
- rest
125
- .getCurrentBotApplicationInformation()
126
- .flatMap(r => r.json)
127
- .flatMap(app =>
131
+ ),
132
+ Chunk.map(c => c.command),
133
+ )
134
+
135
+ return Effect.flatMap(DiscordREST, rest =>
136
+ rest.getCurrentBotApplicationInformation().pipe(
137
+ Effect.flatMap(r => r.json),
138
+ Effect.flatMap(app =>
128
139
  rest.bulkOverwriteGlobalApplicationCommands(app.id, {
129
- body: Http.body.json(commands.toReadonlyArray),
140
+ body: Http.body.json(Chunk.toReadonlyArray(commands)),
130
141
  }),
131
142
  ),
143
+ ),
132
144
  )
133
145
  }
134
146
 
135
147
  syncGuild(appId: Discord.Snowflake, guildId: Discord.Snowflake) {
136
- const commands = this.definitions
137
- .map(([d, _]) => d)
138
- .filter(
148
+ const commands = this.definitions.pipe(
149
+ Chunk.map(([d, _]) => d),
150
+ Chunk.filter(
139
151
  (c): c is D.GuildApplicationCommand<R, E> =>
140
152
  c._tag === "GuildApplicationCommand",
141
- )
142
- .map(c => c.command)
153
+ ),
154
+ Chunk.map(c => c.command),
155
+ )
143
156
 
144
- return DiscordREST.accessWithEffect(rest =>
157
+ return Effect.flatMap(DiscordREST, rest =>
145
158
  rest.bulkOverwriteGuildApplicationCommands(
146
159
  appId,
147
160
  guildId,
148
- commands.toReadonlyArray as any,
161
+ Chunk.toReadonlyArray(commands) as any,
149
162
  ),
150
163
  )
151
164
  }
@@ -1,6 +1,10 @@
1
+ import { Tag } from "@effect/data/Context"
2
+ import * as HashMap from "@effect/data/HashMap"
3
+ import * as Option from "@effect/data/Option"
1
4
  import * as Arr from "@effect/data/ReadonlyArray"
2
- import { Effect, EffectTypeId } from "@effect/io/Effect"
5
+ import * as Effect from "@effect/io/Effect"
3
6
  import * as IxHelpers from "dfx/Helpers/interactions"
7
+ import * as Discord from "dfx/types"
4
8
  import { ModalSubmitDatum } from "dfx/types"
5
9
 
6
10
  export const Interaction = Tag<Discord.Interaction>()
@@ -25,23 +29,27 @@ export class ResolvedDataNotFound {
25
29
 
26
30
  export const resolvedValues = <A>(
27
31
  f: (id: Discord.Snowflake, data: Discord.ResolvedDatum) => A | undefined,
28
- ) =>
29
- Interaction.accessWithEffect(ix =>
30
- IxHelpers.resolveValues(f)(ix).mapError(() => new ResolvedDataNotFound(ix)),
32
+ ): Effect.Effect<Discord.Interaction, ResolvedDataNotFound, readonly A[]> =>
33
+ Effect.flatMap(Interaction, ix =>
34
+ Effect.mapError(
35
+ IxHelpers.resolveValues(f)(ix),
36
+ () => new ResolvedDataNotFound(ix),
37
+ ),
31
38
  )
32
39
 
33
40
  export const resolved = <A>(
34
41
  name: string,
35
42
  f: (id: Discord.Snowflake, data: Discord.ResolvedDatum) => A | undefined,
36
- ) =>
37
- Interaction.accessWithEffect(ix =>
38
- IxHelpers.resolveOptionValue(
39
- name,
40
- f,
41
- )(ix).mapError(() => new ResolvedDataNotFound(ix, name)),
43
+ ): Effect.Effect<Discord.Interaction, ResolvedDataNotFound, A> =>
44
+ Effect.flatMap(Interaction, ix =>
45
+ Effect.mapError(
46
+ IxHelpers.resolveOptionValue(name, f)(ix),
47
+ () => new ResolvedDataNotFound(ix, name),
48
+ ),
42
49
  )
43
50
 
44
- export const focusedOptionValue = FocusedOptionContext.accessWith(
51
+ export const focusedOptionValue = Effect.map(
52
+ FocusedOptionContext,
45
53
  _ => _.focusedOption.value ?? "",
46
54
  )
47
55
 
@@ -51,13 +59,16 @@ export class SubCommandNotFound {
51
59
  }
52
60
 
53
61
  export const handleSubCommands = <
54
- NER extends Record<string, Effect<any, any, Discord.InteractionResponse>>,
62
+ NER extends Record<
63
+ string,
64
+ Effect.Effect<any, any, Discord.InteractionResponse>
65
+ >,
55
66
  >(
56
67
  commands: NER,
57
- ): Effect<
68
+ ): Effect.Effect<
58
69
  | Exclude<
59
70
  [NER[keyof NER]] extends [
60
- { [EffectTypeId]: { _R: (_: never) => infer R } },
71
+ { [Effect.EffectTypeId]: { _R: (_: never) => infer R } },
61
72
  ]
62
73
  ? R
63
74
  : never,
@@ -66,26 +77,38 @@ export const handleSubCommands = <
66
77
  | Discord.Interaction
67
78
  | Discord.ApplicationCommandDatum,
68
79
  | ([NER[keyof NER]] extends [
69
- { [EffectTypeId]: { _E: (_: never) => infer E } },
80
+ { [Effect.EffectTypeId]: { _E: (_: never) => infer E } },
70
81
  ]
71
82
  ? E
72
83
  : never)
73
84
  | SubCommandNotFound,
74
85
  Discord.InteractionResponse
75
86
  > =>
76
- ApplicationCommand.accessWithEffect(data =>
77
- Arr.findFirst(IxHelpers.allSubCommands(data), _ => !!commands[_.name])
78
- .mapError(() => new SubCommandNotFound(data))
79
- .flatMap(command =>
80
- commands[command.name].provideService(SubCommandContext, {
81
- command,
82
- }),
87
+ ApplicationCommand.pipe(
88
+ Effect.flatMap(data =>
89
+ Effect.mapError(
90
+ Arr.findFirst(IxHelpers.allSubCommands(data), _ => !!commands[_.name]),
91
+ () => new SubCommandNotFound(data),
83
92
  ),
93
+ ),
94
+ Effect.flatMap(command =>
95
+ Effect.provideService(commands[command.name], SubCommandContext, {
96
+ command,
97
+ }),
98
+ ),
84
99
  )
85
100
 
86
- export const currentSubCommand = SubCommandContext.accessWith(_ => _.command)
101
+ export const currentSubCommand: Effect.Effect<
102
+ SubCommandContext,
103
+ never,
104
+ Discord.ApplicationCommandInteractionDataOption
105
+ > = Effect.map(SubCommandContext, _ => _.command)
87
106
 
88
- export const optionsMap = ApplicationCommand.accessWith(IxHelpers.optionsMap)
107
+ export const optionsMap: Effect.Effect<
108
+ Discord.ApplicationCommandDatum,
109
+ never,
110
+ HashMap.HashMap<string, string | undefined>
111
+ > = Effect.map(ApplicationCommand, IxHelpers.optionsMap)
89
112
 
90
113
  export class RequiredOptionNotFound {
91
114
  readonly _tag = "RequiredOptionNotFound"
@@ -98,26 +121,32 @@ export class RequiredOptionNotFound {
98
121
  }
99
122
 
100
123
  export const option = (name: string) =>
101
- ApplicationCommand.accessWith(IxHelpers.getOption(name))
124
+ Effect.map(ApplicationCommand, IxHelpers.getOption(name))
102
125
 
103
126
  export const optionValue = (name: string) =>
104
- option(name).flatMap(_ =>
105
- _.flatMapNullable(a => a.value).match({
106
- onNone: () =>
107
- ApplicationCommand.accessWithEffect(data =>
108
- Effect.fail(new RequiredOptionNotFound(data, name)),
109
- ),
110
- onSome: Effect.succeed,
111
- }),
127
+ Effect.flatMap(option(name), _ =>
128
+ Option.match(
129
+ Option.flatMapNullable(_, a => a.value),
130
+ {
131
+ onNone: () =>
132
+ Effect.flatMap(ApplicationCommand, data =>
133
+ Effect.fail(new RequiredOptionNotFound(data, name)),
134
+ ),
135
+ onSome: Effect.succeed,
136
+ },
137
+ ),
112
138
  )
113
139
 
114
140
  export const optionValueOptional = (name: string) =>
115
- option(name).map(o => o.flatMapNullable(o => o.value))
141
+ Effect.map(
142
+ option(name),
143
+ Option.flatMapNullable(o => o.value),
144
+ )
116
145
 
117
- export const modalValues = ModalSubmitData.accessWith(IxHelpers.componentsMap)
146
+ export const modalValues = Effect.map(ModalSubmitData, IxHelpers.componentsMap)
118
147
 
119
148
  export const modalValueOption = (name: string) =>
120
- ModalSubmitData.accessWith(IxHelpers.componentValue(name))
149
+ Effect.map(ModalSubmitData, IxHelpers.componentValue(name))
121
150
 
122
151
  export class ModalValueNotFound {
123
152
  readonly _tag = "ModalValueNotFound"
@@ -125,8 +154,9 @@ export class ModalValueNotFound {
125
154
  }
126
155
 
127
156
  export const modalValue = (name: string) =>
128
- ModalSubmitData.accessWithEffect(data =>
129
- IxHelpers.componentValue(name)(data).mapError(
157
+ Effect.flatMap(ModalSubmitData, data =>
158
+ Effect.mapError(
159
+ IxHelpers.componentValue(name)(data),
130
160
  () => new ModalValueNotFound(data, name),
131
161
  ),
132
162
  )
@@ -1,9 +1,11 @@
1
- import { Effect, EffectTypeId } from "@effect/io/Effect"
1
+ import * as Option from "@effect/data/Option"
2
+ import * as Effect from "@effect/io/Effect"
2
3
  import {
3
4
  FocusedOptionContext,
4
5
  ResolvedDataNotFound,
5
6
  SubCommandContext,
6
- } from "./context.js"
7
+ } from "dfx/Interactions/context"
8
+ import * as Discord from "dfx/types"
7
9
 
8
10
  export type InteractionDefinition<R, E> =
9
11
  | GlobalApplicationCommand<R, E>
@@ -57,13 +59,13 @@ export const guild = <
57
59
  export class MessageComponent<R, E> {
58
60
  readonly _tag = "MessageComponent"
59
61
  constructor(
60
- readonly predicate: (customId: string) => Effect<R, E, boolean>,
61
- readonly handle: Effect<R, E, Discord.InteractionResponse>,
62
+ readonly predicate: (customId: string) => Effect.Effect<R, E, boolean>,
63
+ readonly handle: Effect.Effect<R, E, Discord.InteractionResponse>,
62
64
  ) {}
63
65
  }
64
66
 
65
67
  export const messageComponent = <R1, R2, E1, E2>(
66
- pred: (customId: string) => Effect<R1, E1, boolean>,
68
+ pred: (customId: string) => Effect.Effect<R1, E1, boolean>,
67
69
  handle: CommandHandler<R2, E2, Discord.InteractionResponse>,
68
70
  ) =>
69
71
  new MessageComponent<
@@ -74,14 +76,14 @@ export const messageComponent = <R1, R2, E1, E2>(
74
76
  export class ModalSubmit<R, E> {
75
77
  readonly _tag = "ModalSubmit"
76
78
  constructor(
77
- readonly predicate: (customId: string) => Effect<R, E, boolean>,
78
- readonly handle: Effect<R, E, Discord.InteractionResponse>,
79
+ readonly predicate: (customId: string) => Effect.Effect<R, E, boolean>,
80
+ readonly handle: Effect.Effect<R, E, Discord.InteractionResponse>,
79
81
  ) {}
80
82
  }
81
83
 
82
84
  export const modalSubmit = <R1, R2, E1, E2>(
83
- pred: (customId: string) => Effect<R1, E1, boolean>,
84
- handle: Effect<R2, E2, Discord.InteractionResponse>,
85
+ pred: (customId: string) => Effect.Effect<R1, E1, boolean>,
86
+ handle: Effect.Effect<R2, E2, Discord.InteractionResponse>,
85
87
  ) =>
86
88
  new ModalSubmit<
87
89
  Exclude<R1 | R2, Discord.Interaction | Discord.ModalSubmitDatum>,
@@ -94,8 +96,8 @@ export class Autocomplete<R, E> {
94
96
  readonly predicate: (
95
97
  data: Discord.ApplicationCommandDatum,
96
98
  focusedOption: Discord.ApplicationCommandInteractionDataOption,
97
- ) => Effect<R, E, boolean>,
98
- readonly handle: Effect<R, E, Discord.InteractionResponse>,
99
+ ) => Effect.Effect<R, E, boolean>,
100
+ readonly handle: Effect.Effect<R, E, Discord.InteractionResponse>,
99
101
  ) {}
100
102
  }
101
103
 
@@ -103,8 +105,8 @@ export const autocomplete = <R1, R2, E1, E2>(
103
105
  pred: (
104
106
  data: Discord.ApplicationCommandDatum,
105
107
  focusedOption: Discord.ApplicationCommandInteractionDataOption,
106
- ) => Effect<R1, E1, boolean>,
107
- handle: Effect<R2, E2, Discord.InteractionResponse>,
108
+ ) => Effect.Effect<R1, E1, boolean>,
109
+ handle: Effect.Effect<R2, E2, Discord.InteractionResponse>,
108
110
  ) =>
109
111
  new Autocomplete<
110
112
  Exclude<
@@ -129,44 +131,48 @@ type DeepReadonlyObject<T> = {
129
131
  }
130
132
 
131
133
  export type CommandHandler<R, E, A = any> =
132
- | Effect<R, E, Discord.InteractionResponse>
134
+ | Effect.Effect<R, E, Discord.InteractionResponse>
133
135
  | CommandHandlerFn<R, E, A>
134
136
 
135
137
  export interface CommandHelper<A> {
136
138
  resolve: <T>(
137
139
  name: AllResolvables<A>["name"],
138
140
  f: (id: Discord.Snowflake, data: Discord.ResolvedDatum) => T | undefined,
139
- ) => Effect<Discord.Interaction, ResolvedDataNotFound, T>
141
+ ) => Effect.Effect<Discord.Interaction, ResolvedDataNotFound, T>
140
142
 
141
143
  option: (
142
144
  name: AllCommandOptions<A>["name"],
143
- ) => Effect<
145
+ ) => Effect.Effect<
144
146
  Discord.ApplicationCommandDatum,
145
147
  never,
146
- Maybe<Discord.ApplicationCommandInteractionDataOption>
148
+ Option.Option<Discord.ApplicationCommandInteractionDataOption>
147
149
  >
148
150
 
149
151
  optionValue: <N extends AllRequiredCommandOptions<A>["name"]>(
150
152
  name: N,
151
- ) => Effect<Discord.ApplicationCommandDatum, never, CommandValue<A, N>>
153
+ ) => Effect.Effect<Discord.ApplicationCommandDatum, never, CommandValue<A, N>>
152
154
 
153
155
  optionValueOptional: <N extends AllCommandOptions<A>["name"]>(
154
156
  name: N,
155
- ) => Effect<Discord.ApplicationCommandDatum, never, Maybe<CommandValue<A, N>>>
157
+ ) => Effect.Effect<
158
+ Discord.ApplicationCommandDatum,
159
+ never,
160
+ Option.Option<CommandValue<A, N>>
161
+ >
156
162
 
157
163
  subCommands: <
158
164
  NER extends SubCommandNames<A> extends never
159
165
  ? never
160
166
  : Record<
161
167
  SubCommandNames<A>,
162
- Effect<any, any, Discord.InteractionResponse>
168
+ Effect.Effect<any, any, Discord.InteractionResponse>
163
169
  >,
164
170
  >(
165
171
  commands: NER,
166
- ) => Effect<
172
+ ) => Effect.Effect<
167
173
  | Exclude<
168
174
  [NER[keyof NER]] extends [
169
- { [EffectTypeId]: { _R: (_: never) => infer R } },
175
+ { [Effect.EffectTypeId]: { _R: (_: never) => infer R } },
170
176
  ]
171
177
  ? R
172
178
  : never,
@@ -174,7 +180,9 @@ export interface CommandHelper<A> {
174
180
  >
175
181
  | Discord.Interaction
176
182
  | Discord.ApplicationCommandDatum,
177
- [NER[keyof NER]] extends [{ [EffectTypeId]: { _E: (_: never) => infer E } }]
183
+ [NER[keyof NER]] extends [
184
+ { [Effect.EffectTypeId]: { _E: (_: never) => infer E } },
185
+ ]
178
186
  ? E
179
187
  : never,
180
188
  Discord.InteractionResponse
@@ -183,7 +191,7 @@ export interface CommandHelper<A> {
183
191
 
184
192
  export type CommandHandlerFn<R, E, A> = (
185
193
  i: CommandHelper<A>,
186
- ) => Effect<R, E, Discord.InteractionResponse>
194
+ ) => Effect.Effect<R, E, Discord.InteractionResponse>
187
195
 
188
196
  interface CommandOption {
189
197
  readonly type: any