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,12 +1,26 @@
1
1
  import * as Http from "@effect-http/client"
2
+ import * as Chunk from "@effect/data/Chunk"
3
+ import { Tag } from "@effect/data/Context"
4
+ import * as Duration from "@effect/data/Duration"
5
+ import { pipe } from "@effect/data/Function"
6
+ import type { Cause } from "@effect/io/Cause"
7
+ import * as Effect from "@effect/io/Effect"
8
+ import * as Layer from "@effect/io/Layer"
9
+ import * as Queue from "@effect/io/Queue"
10
+ import * as Ref from "@effect/io/Ref"
2
11
  import { DiscordGateway } from "dfx/DiscordGateway"
3
- import { DiscordREST, DiscordRESTError } from "dfx/DiscordREST"
4
- import { DefinitionNotFound, handlers } from "./handlers.js"
5
- import { Interaction, InteractionBuilder, builder } from "./index.js"
12
+ import type { DiscordRESTError } from "dfx/DiscordREST"
13
+ import { DiscordREST } from "dfx/DiscordREST"
6
14
  import type {
7
15
  GlobalApplicationCommand,
8
16
  GuildApplicationCommand,
9
- } from "./definitions.js"
17
+ } from "dfx/Interactions/definitions"
18
+ import type { DefinitionNotFound } from "dfx/Interactions/handlers"
19
+ import { handlers } from "dfx/Interactions/handlers"
20
+ import type { InteractionBuilder } from "dfx/Interactions/index"
21
+ import { Interaction, builder } from "dfx/Interactions/index"
22
+ import type * as Discord from "dfx/types"
23
+ import * as EffectUtils from "dfx/utils/Effect"
10
24
 
11
25
  export interface RunOpts {
12
26
  sync?: boolean
@@ -18,47 +32,50 @@ export interface RunOpts {
18
32
  export const run =
19
33
  <R, R2, E, TE, E2>(
20
34
  postHandler: (
21
- effect: Effect<
35
+ effect: Effect.Effect<
22
36
  R | DiscordREST | Discord.Interaction,
23
37
  TE | DiscordRESTError | DefinitionNotFound,
24
38
  void
25
39
  >,
26
- ) => Effect<R2, E2, void>,
40
+ ) => Effect.Effect<R2, E2, void>,
27
41
  { sync = true }: RunOpts = {},
28
42
  ) =>
29
43
  (
30
44
  ix: InteractionBuilder<R, E, TE>,
31
- ): Effect<
45
+ ): Effect.Effect<
32
46
  DiscordREST | DiscordGateway | Exclude<R2, Discord.Interaction>,
33
47
  E2 | DiscordRESTError | Http.ResponseDecodeError,
34
48
  never
35
49
  > =>
36
- Do($ => {
37
- const GlobalApplicationCommand = ix.definitions
38
- .map(_ => _[0])
39
- .filter(
50
+ Effect.gen(function* (_) {
51
+ const GlobalApplicationCommand = ix.definitions.pipe(
52
+ Chunk.map(_ => _[0]),
53
+ Chunk.filter(
40
54
  (_): _ is GlobalApplicationCommand<R, E> =>
41
55
  _._tag === "GlobalApplicationCommand",
42
- ).toReadonlyArray
43
- const GuildApplicationCommand = ix.definitions
44
- .map(_ => _[0])
45
- .filter(
56
+ ),
57
+ Chunk.toReadonlyArray,
58
+ )
59
+ const GuildApplicationCommand = ix.definitions.pipe(
60
+ Chunk.map(_ => _[0]),
61
+ Chunk.filter(
46
62
  (_): _ is GuildApplicationCommand<R, E> =>
47
63
  _._tag === "GuildApplicationCommand",
48
- ).toReadonlyArray
64
+ ),
65
+ Chunk.toReadonlyArray,
66
+ )
49
67
 
50
- const gateway = $(DiscordGateway.accessWith(identity))
51
- const rest = $(DiscordREST.accessWith(identity))
68
+ const gateway = yield* _(DiscordGateway)
69
+ const rest = yield* _(DiscordREST)
52
70
 
53
- const application = $(
54
- rest.getCurrentBotApplicationInformation().flatMap(a => a.json),
71
+ const application = yield* _(
72
+ rest.getCurrentBotApplicationInformation(),
73
+ Effect.flatMap(a => a.json),
55
74
  )
56
75
 
57
76
  const globalSync = rest.bulkOverwriteGlobalApplicationCommands(
58
77
  application.id,
59
- {
60
- body: Http.body.json(GlobalApplicationCommand.map(_ => _.command)),
61
- },
78
+ { body: Http.body.json(GlobalApplicationCommand.map(_ => _.command)) },
62
79
  )
63
80
 
64
81
  const guildSync = GuildApplicationCommand.length
@@ -76,54 +93,62 @@ export const run =
76
93
  )
77
94
 
78
95
  const run = gateway.handleDispatch("INTERACTION_CREATE", i =>
79
- postHandler(handle[i.type](i)).provideService(Interaction, i),
96
+ Effect.provideService(postHandler(handle[i.type](i)), Interaction, i),
80
97
  )
81
98
 
82
- return $(
99
+ return yield* _(
83
100
  sync
84
- ? Effect.all(run, globalSync, guildSync, {
85
- concurrency: "unbounded",
86
- discard: true,
87
- }).forever
101
+ ? Effect.forever(
102
+ Effect.all(run, globalSync, guildSync, {
103
+ concurrency: "unbounded",
104
+ discard: true,
105
+ }),
106
+ )
88
107
  : run,
89
108
  )
90
109
  })
91
110
 
92
- const makeRegistry = Do($ => {
93
- const ref = $(Ref.make(builder as InteractionBuilder<never, never, never>))
94
- const queue = $(Queue.sliding<InteractionBuilder<never, never, never>>(1))
111
+ const makeRegistry = Effect.gen(function* (_) {
112
+ const ref = yield* _(
113
+ Ref.make(builder as InteractionBuilder<never, never, never>),
114
+ )
115
+ const queue = yield* _(
116
+ Queue.sliding<InteractionBuilder<never, never, never>>(1),
117
+ )
95
118
 
96
119
  const register = <E>(ix: InteractionBuilder<never, E, never>) =>
97
- ref.updateAndGet(_ => _.concat(ix as any)).flatMap(_ => queue.offer(_))
120
+ Effect.flatMap(
121
+ Ref.updateAndGet(ref, _ => _.concat(ix as any)),
122
+ _ => Queue.offer(queue, _),
123
+ )
98
124
 
99
- const run = <R, E>(
125
+ const run_ = <R, E>(
100
126
  onError: (
101
127
  _: Cause<DiscordRESTError | DefinitionNotFound>,
102
- ) => Effect<R, E, void>,
128
+ ) => Effect.Effect<R, E, void>,
103
129
  opts?: RunOpts,
104
130
  ) =>
105
- queue
106
- .take()
107
- .foreverSwitch(ix =>
108
- ix
109
- .runGateway(_ => _.catchAllCause(onError), opts)
110
- .delay(Duration.seconds(0.1)),
111
- )
112
-
113
- return { register, run } as const
131
+ EffectUtils.foreverSwitch(Queue.take(queue), ix =>
132
+ Effect.delay(
133
+ pipe(ix, run(Effect.catchAllCause(onError), opts)),
134
+ Duration.seconds(0.1),
135
+ ),
136
+ )
137
+
138
+ return { register, run: run_ } as const
114
139
  })
115
140
 
116
141
  export interface InteractionsRegistry {
117
142
  readonly register: <E>(
118
143
  ix: InteractionBuilder<never, E, never>,
119
- ) => Effect<never, never, void>
144
+ ) => Effect.Effect<never, never, void>
120
145
 
121
146
  readonly run: <R, E>(
122
147
  onError: (
123
148
  _: Cause<DiscordRESTError | DefinitionNotFound>,
124
- ) => Effect<R, E, void>,
149
+ ) => Effect.Effect<R, E, void>,
125
150
  opts?: RunOpts,
126
- ) => Effect<
151
+ ) => Effect.Effect<
127
152
  DiscordREST | DiscordGateway | Exclude<R, Discord.Interaction>,
128
153
  DiscordRESTError | Http.ResponseDecodeError | E,
129
154
  never
@@ -1,30 +1,34 @@
1
+ import * as Chunk from "@effect/data/Chunk"
2
+ import * as Option from "@effect/data/Option"
3
+ import * as Effect from "@effect/io/Effect"
1
4
  import * as IxHelpers from "dfx/Helpers/interactions"
2
- import * as Ctx from "./context.js"
3
- import * as D from "./definitions.js"
4
- import { flattenDefinitions, splitDefinitions } from "./utils.js"
5
+ import * as Ctx from "dfx/Interactions/context"
6
+ import * as D from "dfx/Interactions/definitions"
7
+ import { flattenDefinitions, splitDefinitions } from "dfx/Interactions/utils"
8
+ import * as Discord from "dfx/types"
5
9
 
6
10
  export class DefinitionNotFound {
7
11
  readonly _tag = "DefinitionNotFound"
8
12
  constructor(readonly interaction: Discord.Interaction) {}
9
13
  }
10
14
 
11
- type Handler<R, E, A> = Effect<
15
+ type Handler<R, E, A> = Effect.Effect<
12
16
  R | Discord.Interaction,
13
17
  E | DefinitionNotFound,
14
18
  A
15
19
  >
16
20
 
17
21
  export const handlers = <R, E, TE, A, B>(
18
- definitions: Chunk<
22
+ definitions: Chunk.Chunk<
19
23
  readonly [
20
24
  handler: D.InteractionDefinition<R, E>,
21
- transform: (self: Effect<R, E, A>) => Effect<R, TE, B>,
25
+ transform: (self: Effect.Effect<R, E, A>) => Effect.Effect<R, TE, B>,
22
26
  ]
23
27
  >,
24
28
  handleResponse: (
25
29
  ix: Discord.Interaction,
26
30
  _: Discord.InteractionResponse,
27
- ) => Effect<R, E, A>,
31
+ ) => Effect.Effect<R, E, A>,
28
32
  ): Record<
29
33
  Discord.InteractionType,
30
34
  (i: Discord.Interaction) => Handler<R, E, B>
@@ -43,68 +47,81 @@ export const handlers = <R, E, TE, A, B>(
43
47
  [Discord.InteractionType.APPLICATION_COMMAND]: i => {
44
48
  const data = i.data as Discord.ApplicationCommandDatum
45
49
 
46
- return Maybe.fromNullable(Commands[data.name]).match({
50
+ return Option.match(Option.fromNullable(Commands[data.name]), {
47
51
  onNone: () => Effect.fail(new DefinitionNotFound(i)),
48
52
  onSome: command =>
49
- command
50
- .handle(i)
51
- .provideService(Ctx.ApplicationCommand, data) as Handler<R, E, B>,
53
+ Effect.provideService(
54
+ command.handle(i),
55
+ Ctx.ApplicationCommand,
56
+ data,
57
+ ) as Handler<R, E, B>,
52
58
  })
53
59
  },
54
60
 
55
61
  [Discord.InteractionType.MODAL_SUBMIT]: i => {
56
62
  const data = i.data as Discord.ModalSubmitDatum
57
63
 
58
- return ModalSubmit.findFirst(_ => _.predicate(data.custom_id)).flatMap(
59
- _ =>
60
- _.match({
64
+ return Effect.findFirst(ModalSubmit, _ =>
65
+ _.predicate(data.custom_id),
66
+ ).pipe(
67
+ Effect.flatMap(
68
+ Option.match({
61
69
  onNone: () => Effect.fail(new DefinitionNotFound(i)),
62
70
  onSome: match =>
63
- match
64
- .handle(i)
65
- .provideService(Ctx.ModalSubmitData, data) as Handler<R, E, B>,
71
+ Effect.provideService(
72
+ match.handle(i),
73
+ Ctx.ModalSubmitData,
74
+ data,
75
+ ) as Handler<R, E, B>,
66
76
  }),
77
+ ),
67
78
  )
68
79
  },
69
80
 
70
81
  [Discord.InteractionType.MESSAGE_COMPONENT]: i => {
71
82
  const data = i.data as Discord.MessageComponentDatum
72
83
 
73
- return MessageComponent.findFirst(_ =>
84
+ return Effect.findFirst(MessageComponent, _ =>
74
85
  _.predicate(data.custom_id),
75
- ).flatMap(_ =>
76
- _.match({
77
- onNone: () => Effect.fail(new DefinitionNotFound(i)),
78
- onSome: match =>
79
- match
80
- .handle(i)
81
- .provideService(Ctx.MessageComponentData, data) as Handler<
82
- R,
83
- E,
84
- B
85
- >,
86
- }),
86
+ ).pipe(
87
+ Effect.flatMap(
88
+ Option.match({
89
+ onNone: () => Effect.fail(new DefinitionNotFound(i)),
90
+ onSome: match =>
91
+ Effect.provideService(
92
+ match.handle(i),
93
+ Ctx.MessageComponentData,
94
+ data,
95
+ ) as Handler<R, E, B>,
96
+ }),
97
+ ),
87
98
  )
88
99
  },
89
100
 
90
101
  [Discord.InteractionType.APPLICATION_COMMAND_AUTOCOMPLETE]: i => {
91
102
  const data = i.data as Discord.ApplicationCommandDatum
92
103
 
93
- return IxHelpers.focusedOption(data).match({
104
+ return Option.match(IxHelpers.focusedOption(data), {
94
105
  onNone: () => Effect.fail(new DefinitionNotFound(i)),
95
106
  onSome: focusedOption =>
96
- Autocomplete.findFirst(_ => _.predicate(data, focusedOption)).flatMap(
97
- _ =>
98
- _.match({
107
+ Effect.findFirst(Autocomplete, _ =>
108
+ _.predicate(data, focusedOption),
109
+ ).pipe(
110
+ Effect.flatMap(
111
+ Option.match({
99
112
  onNone: () => Effect.fail(new DefinitionNotFound(i)),
100
113
  onSome: match =>
101
- match
102
- .handle(i)
103
- .provideService(Ctx.ApplicationCommand, data)
104
- .provideService(Ctx.FocusedOptionContext, {
114
+ Effect.provideService(
115
+ match.handle(i),
116
+ Ctx.ApplicationCommand,
117
+ data,
118
+ ).pipe(
119
+ Effect.provideService(Ctx.FocusedOptionContext, {
105
120
  focusedOption,
106
- }) as Handler<R, E, B>,
121
+ }),
122
+ ) as Handler<R, E, B>,
107
123
  }),
124
+ ),
108
125
  ),
109
126
  })
110
127
  },
@@ -1,8 +1,9 @@
1
- import { Discord, Effect } from "dfx/_common"
1
+ import * as Effect from "@effect/io/Effect"
2
+ import type * as Discord from "dfx/types"
2
3
 
3
- export { response } from "../Helpers/interactions.js"
4
- export * from "./builder.js"
5
- export * from "./context.js"
4
+ export { response } from "dfx/Helpers/interactions"
5
+ export * from "dfx/Interactions/builder"
6
+ export * from "dfx/Interactions/context"
6
7
  export {
7
8
  InteractionDefinition,
8
9
  autocomplete,
@@ -10,7 +11,7 @@ export {
10
11
  guild,
11
12
  messageComponent,
12
13
  modalSubmit,
13
- } from "./definitions.js"
14
+ } from "dfx/Interactions/definitions"
14
15
 
15
16
  // Filters
16
17
  export const id = (query: string) => (customId: string) =>
@@ -1,5 +1,8 @@
1
- import * as D from "./definitions.js"
2
- import * as Ctx from "./context.js"
1
+ import * as Chunk from "@effect/data/Chunk"
2
+ import * as Effect from "@effect/io/Effect"
3
+ import * as Ctx from "dfx/Interactions/context"
4
+ import * as D from "dfx/Interactions/definitions"
5
+ import * as Discord from "dfx/types"
3
6
 
4
7
  export type DefinitionFlattened<R, E, TE, A> = D.InteractionDefinition<
5
8
  R,
@@ -7,7 +10,7 @@ export type DefinitionFlattened<R, E, TE, A> = D.InteractionDefinition<
7
10
  > extends infer D
8
11
  ? {
9
12
  [K in keyof D]: K extends "handle"
10
- ? (_: Discord.Interaction) => Effect<R, TE, A>
13
+ ? (_: Discord.Interaction) => Effect.Effect<R, TE, A>
11
14
  : D[K]
12
15
  }
13
16
  : never
@@ -26,31 +29,36 @@ const context: D.CommandHelper<any> = {
26
29
  } as any
27
30
 
28
31
  export const flattenDefinitions = <R, E, TE, A, B>(
29
- definitions: Chunk<
32
+ definitions: Chunk.Chunk<
30
33
  readonly [
31
34
  handler: D.InteractionDefinition<R, E>,
32
- transform: (self: Effect<R, E, A>) => Effect<R, TE, B>,
35
+ transform: (self: Effect.Effect<R, E, A>) => Effect.Effect<R, TE, B>,
33
36
  ]
34
37
  >,
35
38
  handleResponse: (
36
39
  ix: Discord.Interaction,
37
40
  _: Discord.InteractionResponse,
38
- ) => Effect<R, E, A>,
41
+ ) => Effect.Effect<R, E, A>,
39
42
  ) =>
40
- definitions.map(([definition, transform]) => ({
43
+ Chunk.map(definitions, ([definition, transform]) => ({
41
44
  ...definition,
42
45
  handle: (i: Discord.Interaction) =>
43
46
  Effect.isEffect(definition.handle)
44
- ? transform(definition.handle.flatMap(_ => handleResponse(i, _)))
47
+ ? transform(
48
+ Effect.flatMap(definition.handle, _ => handleResponse(i, _)),
49
+ )
45
50
  : transform(
46
- definition.handle(context).flatMap(_ => handleResponse(i, _)),
51
+ Effect.flatMap(definition.handle(context), _ =>
52
+ handleResponse(i, _),
53
+ ),
47
54
  ),
48
55
  }))
49
56
 
50
57
  export const splitDefinitions = <R, E, TE, A>(
51
- definitions: Chunk<DefinitionFlattened<R, E, TE, A>>,
58
+ definitions: Chunk.Chunk<DefinitionFlattened<R, E, TE, A>>,
52
59
  ) => {
53
- const grouped = definitions.reduce(
60
+ const grouped = Chunk.reduce(
61
+ definitions,
54
62
  {
55
63
  Autocomplete: Chunk.empty(),
56
64
  GlobalApplicationCommand: Chunk.empty(),
@@ -58,25 +66,28 @@ export const splitDefinitions = <R, E, TE, A>(
58
66
  MessageComponent: Chunk.empty(),
59
67
  ModalSubmit: Chunk.empty(),
60
68
  } as {
61
- [K in D.InteractionDefinition<R, E>["_tag"]]: Chunk<
69
+ [K in D.InteractionDefinition<R, E>["_tag"]]: Chunk.Chunk<
62
70
  Extract<DefinitionFlattened<R, E, TE, A>, { _tag: K }>
63
71
  >
64
72
  },
65
73
  (acc, d) => ({
66
74
  ...acc,
67
- [d._tag]: (acc[d._tag] as Chunk<any>).append(d),
75
+ [d._tag]: Chunk.append(acc[d._tag] as Chunk.Chunk<any>, d),
68
76
  }),
69
77
  )
70
78
 
71
- const Commands = grouped.GlobalApplicationCommand.appendAll(
79
+ const Commands = Chunk.appendAll(
80
+ grouped.GlobalApplicationCommand,
72
81
  grouped.GuildApplicationCommand,
73
- ).reduce(
74
- {} as Record<string, DefinitionFlattenedCommand<R, E, TE, A>>,
75
- (acc, d) =>
76
- ({
77
- ...acc,
78
- [d.command.name]: d,
79
- } as any),
82
+ ).pipe(
83
+ Chunk.reduce(
84
+ {} as Record<string, DefinitionFlattenedCommand<R, E, TE, A>>,
85
+ (acc, d) =>
86
+ ({
87
+ ...acc,
88
+ [d.command.name]: d,
89
+ } as any),
90
+ ),
80
91
  )
81
92
 
82
93
  return {
@@ -1,9 +1,18 @@
1
- import * as Verify from "discord-verify"
2
- import * as D from "./definitions.js"
3
- import { DefinitionNotFound, handlers } from "./handlers.js"
4
- import { InteractionBuilder, Interaction } from "./index.js"
1
+ import * as Chunk from "@effect/data/Chunk"
2
+ import { Tag } from "@effect/data/Context"
3
+ import { identity } from "@effect/data/Function"
5
4
  import * as Option from "@effect/data/Option"
5
+ import * as Cause from "@effect/io/Cause"
6
+ import * as Config from "@effect/io/Config"
7
+ import * as ConfigError from "@effect/io/Config/Error"
8
+ import * as ConfigSecret from "@effect/io/Config/Secret"
6
9
  import * as Effect from "@effect/io/Effect"
10
+ import * as Layer from "@effect/io/Layer"
11
+ import * as D from "dfx/Interactions/definitions"
12
+ import { DefinitionNotFound, handlers } from "dfx/Interactions/handlers"
13
+ import { Interaction, InteractionBuilder } from "dfx/Interactions/index"
14
+ import * as Discord from "dfx/types"
15
+ import * as Verify from "discord-verify"
7
16
 
8
17
  export class BadWebhookSignature {
9
18
  readonly _tag = "BadWebhookSignature"
@@ -19,10 +28,10 @@ const checkSignature = (
19
28
  algorithm: any,
20
29
  ) =>
21
30
  Option.all({
22
- signature: Maybe.fromNullable(headers["x-signature-ed25519"]),
23
- timestamp: Maybe.fromNullable(headers["x-signature-timestamp"]),
24
- })
25
- .flatMap(_ =>
31
+ signature: Option.fromNullable(headers["x-signature-ed25519"]),
32
+ timestamp: Option.fromNullable(headers["x-signature-timestamp"]),
33
+ }).pipe(
34
+ Effect.flatMap(_ =>
26
35
  Effect.promise(() =>
27
36
  Verify.verify(
28
37
  body,
@@ -33,15 +42,17 @@ const checkSignature = (
33
42
  algorithm,
34
43
  ),
35
44
  ),
36
- )
37
- .filterOrFail(identity, () => new BadWebhookSignature())
38
- .catchAllCause(() => Effect.fail(new BadWebhookSignature())).asUnit
45
+ ),
46
+ Effect.filterOrFail(identity, () => new BadWebhookSignature()),
47
+ Effect.catchAllCause(() => Effect.fail(new BadWebhookSignature())),
48
+ Effect.asUnit,
49
+ )
39
50
 
40
51
  export interface MakeConfigOpts {
41
- applicationId: string
42
- publicKey: ConfigSecret
43
- crypto: SubtleCrypto
44
- algorithm: keyof typeof Verify.PlatformAlgorithm
52
+ readonly applicationId: string
53
+ readonly publicKey: ConfigSecret.ConfigSecret
54
+ readonly crypto: SubtleCrypto
55
+ readonly algorithm: keyof typeof Verify.PlatformAlgorithm
45
56
  }
46
57
  const makeConfig = ({
47
58
  applicationId,
@@ -50,16 +61,22 @@ const makeConfig = ({
50
61
  algorithm,
51
62
  }: MakeConfigOpts) => ({
52
63
  applicationId,
53
- publicKey: publicKey.value,
64
+ publicKey: ConfigSecret.value(publicKey),
54
65
  crypto,
55
66
  algorithm: Verify.PlatformAlgorithm[algorithm],
56
67
  })
68
+
57
69
  export interface WebhookConfig extends ReturnType<typeof makeConfig> {}
58
70
  export const WebhookConfig = Tag<WebhookConfig>()
71
+
59
72
  export const makeConfigLayer = (opts: MakeConfigOpts) =>
60
73
  Layer.succeed(WebhookConfig, makeConfig(opts))
61
- export const makeFromConfig = (a: Config<MakeConfigOpts>) =>
62
- Layer.effect(WebhookConfig, a.config.map(makeConfig))
74
+
75
+ export const makeFromConfig: (
76
+ a: Config.Config<MakeConfigOpts>,
77
+ ) => Layer.Layer<never, ConfigError.ConfigError, WebhookConfig> = (
78
+ a: Config.Config<MakeConfigOpts>,
79
+ ) => Layer.effect(WebhookConfig, Effect.map(Effect.config(a), makeConfig))
63
80
 
64
81
  export class WebhookParseError {
65
82
  readonly _tag = "WebhookParseError"
@@ -67,21 +84,19 @@ export class WebhookParseError {
67
84
  }
68
85
 
69
86
  const fromHeadersAndBody = (headers: Headers, body: string) =>
70
- Do($ => {
71
- const { publicKey, crypto, algorithm } = $(
72
- WebhookConfig.accessWith(identity),
73
- )
74
- $(checkSignature(publicKey, headers, body, crypto, algorithm))
75
- return $(
87
+ Effect.tap(WebhookConfig, ({ publicKey, crypto, algorithm }) =>
88
+ checkSignature(publicKey, headers, body, crypto, algorithm),
89
+ ).pipe(
90
+ Effect.flatMap(() =>
76
91
  Effect.try({
77
92
  try: () => JSON.parse(body) as Discord.Interaction,
78
93
  catch: reason => new WebhookParseError(reason),
79
94
  }),
80
- )
81
- })
95
+ ),
96
+ )
82
97
 
83
98
  const run = <R, E>(
84
- definitions: Chunk<
99
+ definitions: Chunk.Chunk<
85
100
  readonly [
86
101
  handler: D.InteractionDefinition<R, E>,
87
102
  transform: (
@@ -96,30 +111,37 @@ const run = <R, E>(
96
111
  ) => {
97
112
  const handler = handlers(definitions, handleResponse)
98
113
  return (headers: Headers, body: string) =>
99
- Do($ => {
100
- const interaction = $(fromHeadersAndBody(headers, body))
101
- return $(
102
- handler[interaction.type](interaction).provideService(
103
- Interaction,
104
- interaction,
105
- ),
106
- )
107
- })
114
+ Effect.flatMap(fromHeadersAndBody(headers, body), interaction =>
115
+ Effect.provideService(
116
+ handler[interaction.type](interaction),
117
+ Interaction,
118
+ interaction,
119
+ ),
120
+ )
108
121
  }
109
122
 
110
123
  export interface HandleWebhookOpts<E> {
111
124
  headers: Headers
112
125
  body: string
113
126
  success: (a: Discord.InteractionResponse) => Effect.Effect<never, never, void>
114
- error: (e: Cause<E>) => Effect.Effect<never, never, void>
127
+ error: (e: Cause.Cause<E>) => Effect.Effect<never, never, void>
115
128
  }
116
129
 
117
130
  /**
118
131
  * @tsplus getter dfx/InteractionBuilder webhookHandler
119
132
  */
120
- export const makeHandler = <R, E, TE>(ix: InteractionBuilder<R, E, TE>) => {
133
+ export const makeHandler = <R, E, TE>(
134
+ ix: InteractionBuilder<R, E, TE>,
135
+ ): (({
136
+ headers,
137
+ body,
138
+ success,
139
+ error,
140
+ }: HandleWebhookOpts<
141
+ E | WebhookParseError | BadWebhookSignature | DefinitionNotFound
142
+ >) => Effect.Effect<WebhookConfig, never, void>) => {
121
143
  const handle = run(
122
- ix.definitions.map(([d]) => [d, identity] as any),
144
+ Chunk.map(ix.definitions, ([d]) => [d, identity] as any),
123
145
  (_i, r) => Effect.succeed(r),
124
146
  )
125
147
 
@@ -130,7 +152,11 @@ export const makeHandler = <R, E, TE>(ix: InteractionBuilder<R, E, TE>) => {
130
152
  error,
131
153
  }: HandleWebhookOpts<
132
154
  E | WebhookParseError | BadWebhookSignature | DefinitionNotFound
133
- >) => handle(headers, body).flatMap(success).catchAllCause(error)
155
+ >): Effect.Effect<WebhookConfig, never, void> =>
156
+ handle(headers, body).pipe(
157
+ Effect.flatMap(success),
158
+ Effect.catchAllCause(error),
159
+ )
134
160
  }
135
161
 
136
162
  /**
@@ -138,9 +164,19 @@ export const makeHandler = <R, E, TE>(ix: InteractionBuilder<R, E, TE>) => {
138
164
  */
139
165
  export const makeSimpleHandler = <R, E, TE>(
140
166
  ix: InteractionBuilder<R, E, TE>,
141
- ) => {
167
+ ): (({
168
+ headers,
169
+ body,
170
+ }: {
171
+ headers: Headers
172
+ body: string
173
+ }) => Effect.Effect<
174
+ WebhookConfig,
175
+ BadWebhookSignature | WebhookParseError | DefinitionNotFound,
176
+ Discord.InteractionResponse
177
+ >) => {
142
178
  const handle = run(
143
- ix.definitions.map(([d]) => [d, identity] as any),
179
+ Chunk.map(ix.definitions, ([d]) => [d, identity] as any),
144
180
  (_i, r) => Effect.succeed(r),
145
181
  )
146
182