dfx 0.51.0 → 0.51.1

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 +42 -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,88 +1,110 @@
1
- import * as tsplus_module_1 from "@effect/io/Effect";
2
- import * as tsplus_module_2 from "dfx/_common";
3
- import * as tsplus_module_3 from "@effect/io/Config/Secret";
4
- import * as tsplus_module_4 from "@effect/io/Queue";
5
- import * as tsplus_module_5 from "@effect/data/Option";
6
- import * as tsplus_module_6 from "@effect/data/Chunk";
7
- import * as tsplus_module_7 from "@effect/io/Ref";
8
- import * as tsplus_module_8 from "@effect/data/Duration";
9
- import * as tsplus_module_9 from "@effect/data/Function";
10
- import * as tsplus_module_10 from "@effect/io/Layer";
11
- import { DiscordConfig } from "dfx/DiscordConfig";
12
- import { LiveRateLimiter, RateLimiter } from "dfx/RateLimit";
13
- import { DiscordWS, LiveDiscordWS } from "./DiscordWS.js";
14
- import * as Heartbeats from "./Shard/heartbeats.js";
15
- import * as Identify from "./Shard/identify.js";
16
- import * as InvalidSession from "./Shard/invalidSession.js";
17
- import * as Utils from "./Shard/utils.js";
18
- import { Reconnect } from "./WS.js";
19
- import { Log } from "dfx/Log";
20
- export const make = tsplus_module_1.flatMap(tsplus_module_1.map(DiscordConfig, tsplus_module_9.identity), ({ token, gateway }) => tsplus_module_1.flatMap(tsplus_module_1.map(RateLimiter, tsplus_module_9.identity), limiter => tsplus_module_1.flatMap(tsplus_module_1.map(DiscordWS, tsplus_module_9.identity), dws => tsplus_module_1.map(tsplus_module_1.map(Log, tsplus_module_9.identity), log => {
21
- const connect = (shard, hub, sendQueue) => tsplus_module_1.flatMap(tsplus_module_4.unbounded(), outboundQueue => tsplus_module_1.flatMap(tsplus_module_4.unbounded(), pendingQueue => tsplus_module_1.flatMap(tsplus_module_7.make(0 /* Phase.Connecting */), phase => {
22
- const setPhase = (p) => tsplus_module_1.zipLeft(tsplus_module_7.set(phase, p), log.debug("Shard", shard, "phase", p));
23
- const outbound = tsplus_module_1.tap(outboundQueue
24
- .take(), () => limiter.maybeWait("dfx.shard.send", tsplus_module_8.minutes(1), 120));
25
- const send = (p) => tsplus_module_1.flatMap(tsplus_module_7.get(phase), _ => _ === 2 /* Phase.Connected */
26
- ? outboundQueue.offer(p)
27
- : pendingQueue.offer(p));
28
- const heartbeatSend = (p) => tsplus_module_1.flatMap(tsplus_module_7.get(phase), _ => _ !== 0 /* Phase.Connecting */
29
- ? outboundQueue.offer(p)
30
- : tsplus_module_1.succeed(false));
31
- const prioritySend = (p) => outboundQueue.offer(p);
32
- const resume = tsplus_module_1.asUnit(tsplus_module_1.tap(tsplus_module_1.zipRight(setPhase(2 /* Phase.Connected */), pendingQueue.takeAll()), _ => outboundQueue.offerAll(_)));
33
- const onConnecting = tsplus_module_1.zipRight(tsplus_module_1.tap(outboundQueue
34
- .takeAll(), _ => pendingQueue.offerAll(tsplus_module_6.filter(_, msg => msg !== Reconnect &&
35
- msg.op !== 2 /* Discord.GatewayOpcode.IDENTIFY */ &&
36
- msg.op !== 6 /* Discord.GatewayOpcode.RESUME */ &&
37
- msg.op !== 1 /* Discord.GatewayOpcode.HEARTBEAT */))), setPhase(0 /* Phase.Connecting */));
38
- return tsplus_module_1.flatMap(dws.connect({ outbound, onConnecting }), socket => tsplus_module_1.flatMap(Utils.latest(p => tsplus_module_5.map(tsplus_module_5.filter(tsplus_module_5.some(p), (p) => p.op === 0 /* Discord.GatewayOpcode.DISPATCH */ && p.t === "READY"), p => p.d)), ([latestReady, updateLatestReady]) => tsplus_module_1.flatMap(Utils.latest(p => tsplus_module_5.fromNullable(p.s)), ([latestSequence, updateLatestSequence]) => {
39
- const maybeUpdateUrl = (p) => tsplus_module_5.match(tsplus_module_5.map(tsplus_module_5.filter(tsplus_module_5.some(p), (p) => p.op === 0 /* Discord.GatewayOpcode.DISPATCH */ && p.t === "READY"), p => p.d), {
40
- onNone: () => tsplus_module_1.unit,
41
- onSome: ({ resume_gateway_url }) => socket.setUrl(resume_gateway_url),
42
- });
43
- return tsplus_module_1.flatMap(tsplus_module_4.unbounded(), hellos => tsplus_module_1.map(tsplus_module_4.unbounded(), acks => {
44
- // heartbeats
45
- const heartbeats = Heartbeats.send(hellos, acks, latestSequence, heartbeatSend);
46
- // identify
47
- const identify = Identify.identifyOrResume({
48
- token: tsplus_module_3.value(token),
49
- shard,
50
- intents: gateway.intents,
51
- presence: gateway.presence,
52
- }, latestReady, latestSequence);
53
- const onPayload = (p) => tsplus_module_1.flatMap(tsplus_module_1.zip(tsplus_module_1.zip(updateLatestReady(p), updateLatestSequence(p), { parallel: true }), maybeUpdateUrl(p)), () => {
54
- let effect = tsplus_module_1.unit;
55
- switch (p.op) {
56
- case 10 /* Discord.GatewayOpcode.HELLO */:
57
- effect = tsplus_module_1.zip(tsplus_module_1.tap(identify, prioritySend), tsplus_module_1.zipRight(setPhase(1 /* Phase.Handshake */), hellos.offer(p)), {
58
- parallel: true,
59
- });
60
- break;
61
- case 11 /* Discord.GatewayOpcode.HEARTBEAT_ACK */:
62
- effect = acks.offer(p);
63
- break;
64
- case 9 /* Discord.GatewayOpcode.INVALID_SESSION */:
65
- effect = tsplus_module_1.tap(InvalidSession.fromPayload(p, latestReady), send);
66
- break;
67
- case 0 /* Discord.GatewayOpcode.DISPATCH */:
68
- if (p.t === "READY" || p.t === "RESUMED") {
69
- effect = tsplus_module_1.zipRight(resume, hub.publish(p));
70
- }
71
- else {
72
- effect = hub.publish(p);
73
- }
74
- break;
75
- }
76
- return tsplus_module_1.map(effect, () => void 0);
77
- });
78
- const drainSendQueue = tsplus_module_1.forever(tsplus_module_1.tap(sendQueue.take(), send));
79
- const run = tsplus_module_1.all(tsplus_module_1.forever(tsplus_module_1.flatMap(socket.take, onPayload)), heartbeats, drainSendQueue, socket.run, { discard: true, concurrency: "unbounded" });
80
- return { id: shard, send, run };
81
- }));
82
- })));
83
- })));
84
- return { connect };
85
- }))));
86
- export const Shard = tsplus_module_2.Tag();
87
- export const LiveShard = tsplus_module_10.provide(tsplus_module_10.effect(Shard, make))((tsplus_module_10.merge(LiveRateLimiter)(LiveDiscordWS)));
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.make = exports.Shard = exports.LiveShard = void 0;
7
+ var _DiscordConfig = /*#__PURE__*/require("dfx/DiscordConfig");
8
+ var _RateLimit = /*#__PURE__*/require("dfx/RateLimit");
9
+ var _DiscordWS = /*#__PURE__*/require("dfx/DiscordGateway/DiscordWS");
10
+ var Heartbeats = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("dfx/DiscordGateway/Shard/heartbeats"));
11
+ var Identify = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("dfx/DiscordGateway/Shard/identify"));
12
+ var InvalidSession = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("dfx/DiscordGateway/Shard/invalidSession"));
13
+ var Utils = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("dfx/DiscordGateway/Shard/utils"));
14
+ var _WS = /*#__PURE__*/require("dfx/DiscordGateway/WS");
15
+ var _Log = /*#__PURE__*/require("dfx/Log");
16
+ var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Effect"));
17
+ var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Layer"));
18
+ var _Context = /*#__PURE__*/require("@effect/data/Context");
19
+ var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Option"));
20
+ var Hub = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Hub"));
21
+ var Queue = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Queue"));
22
+ var Ref = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Ref"));
23
+ var Duration = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Duration"));
24
+ var Chunk = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Chunk"));
25
+ var ConfigSecret = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Config/Secret"));
26
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
28
+ const make = /*#__PURE__*/Effect.gen(function* (_) {
29
+ const {
30
+ token,
31
+ gateway
32
+ } = yield* _(_DiscordConfig.DiscordConfig);
33
+ const limiter = yield* _(_RateLimit.RateLimiter);
34
+ const dws = yield* _(_DiscordWS.DiscordWS);
35
+ const log = yield* _(_Log.Log);
36
+ const connect = (shard, hub, sendQueue) => Effect.gen(function* (_) {
37
+ const outboundQueue = yield* _(Queue.unbounded());
38
+ const pendingQueue = yield* _(Queue.unbounded());
39
+ const phase = yield* _(Ref.make(0 /* Phase.Connecting */));
40
+ const setPhase = p => Effect.zipLeft(Ref.set(phase, p), log.debug("Shard", shard, "phase", p));
41
+ const outbound = Effect.zipLeft(Queue.take(outboundQueue), limiter.maybeWait("dfx.shard.send", Duration.minutes(1), 120));
42
+ const send = p => Effect.flatMap(Ref.get(phase), phase => phase === 2 /* Phase.Connected */ ? Queue.offer(outboundQueue, p) : Queue.offer(pendingQueue, p));
43
+ const heartbeatSend = p => Effect.flatMap(Ref.get(phase), phase => phase !== 0 /* Phase.Connecting */ ? Queue.offer(outboundQueue, p) : Effect.succeed(false));
44
+ const prioritySend = p => Queue.offer(outboundQueue, p);
45
+ const resume = setPhase(2 /* Phase.Connected */).pipe(Effect.zipRight(Queue.takeAll(pendingQueue)), Effect.tap(_ => Queue.offerAll(outboundQueue, _)), Effect.asUnit);
46
+ const onConnecting = Queue.takeAll(outboundQueue).pipe(Effect.tap(msgs => Queue.offerAll(pendingQueue, Chunk.filter(msgs, msg => msg !== _WS.Reconnect && msg.op !== 2 /* Discord.GatewayOpcode.IDENTIFY */ && msg.op !== 6 /* Discord.GatewayOpcode.RESUME */ && msg.op !== 1 /* Discord.GatewayOpcode.HEARTBEAT */))), Effect.zipRight(setPhase(0 /* Phase.Connecting */)));
47
+ const socket = yield* _(dws.connect({
48
+ outbound,
49
+ onConnecting
50
+ }));
51
+ const [latestReady, updateLatestReady] = yield* _(Utils.latest(p => Option.some(p).pipe(Option.filter(p => p.op === 0 /* Discord.GatewayOpcode.DISPATCH */ && p.t === "READY"), Option.map(p => p.d))));
52
+ const [latestSequence, updateLatestSequence] = yield* _(Utils.latest(p => Option.fromNullable(p.s)));
53
+ const maybeUpdateUrl = p => Option.some(p).pipe(Option.filter(p => p.op === 0 /* Discord.GatewayOpcode.DISPATCH */ && p.t === "READY"), Option.map(p => p.d), Option.match({
54
+ onNone: () => Effect.unit,
55
+ onSome: ({
56
+ resume_gateway_url
57
+ }) => socket.setUrl(resume_gateway_url)
58
+ }));
59
+ const hellos = yield* _(Queue.unbounded());
60
+ const acks = yield* _(Queue.unbounded());
61
+ // heartbeats
62
+ const heartbeats = Heartbeats.send(hellos, acks, latestSequence, heartbeatSend);
63
+ // identify
64
+ const identify = Identify.identifyOrResume({
65
+ token: ConfigSecret.value(token),
66
+ shard,
67
+ intents: gateway.intents,
68
+ presence: gateway.presence
69
+ }, latestReady, latestSequence);
70
+ const onPayload = p => Effect.tap(Effect.all(updateLatestReady(p), updateLatestSequence(p), maybeUpdateUrl(p), {
71
+ discard: true
72
+ }), () => {
73
+ switch (p.op) {
74
+ case 10 /* Discord.GatewayOpcode.HELLO */:
75
+ return Effect.all(Effect.tap(identify, prioritySend), setPhase(1 /* Phase.Handshake */), Queue.offer(hellos, p), {
76
+ discard: true
77
+ });
78
+ case 11 /* Discord.GatewayOpcode.HEARTBEAT_ACK */:
79
+ return Queue.offer(acks, p);
80
+ case 9 /* Discord.GatewayOpcode.INVALID_SESSION */:
81
+ return Effect.tap(InvalidSession.fromPayload(p, latestReady), send);
82
+ case 0 /* Discord.GatewayOpcode.DISPATCH */:
83
+ if (p.t === "READY" || p.t === "RESUMED") {
84
+ return Effect.zipRight(resume, Hub.publish(hub, p));
85
+ }
86
+ return Hub.publish(hub, p);
87
+ }
88
+ return Effect.unit;
89
+ });
90
+ const drainSendQueue = Queue.take(sendQueue).pipe(Effect.tap(send), Effect.forever);
91
+ const run = Effect.all(socket.take.pipe(Effect.flatMap(onPayload), Effect.forever), heartbeats, drainSendQueue, socket.run, {
92
+ discard: true,
93
+ concurrency: "unbounded"
94
+ });
95
+ return {
96
+ id: shard,
97
+ send,
98
+ run
99
+ };
100
+ });
101
+ return {
102
+ connect
103
+ };
104
+ });
105
+ exports.make = make;
106
+ const Shard = /*#__PURE__*/(0, _Context.Tag)();
107
+ exports.Shard = Shard;
108
+ const LiveShard = /*#__PURE__*/Layer.provide( /*#__PURE__*/Layer.merge(_DiscordWS.LiveDiscordWS, _RateLimit.LiveRateLimiter), /*#__PURE__*/Layer.effect(Shard, make));
109
+ exports.LiveShard = LiveShard;
88
110
  //# sourceMappingURL=Shard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Shard.js","sourceRoot":"","sources":["../src/DiscordGateway/Shard.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,eAAe,EAA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B,CAAA;AAGF,MAAM,CAAC,MAAM,KAAK,GAAG,gBAAA,GAAG,EAAS,CAAA;AACjC,MAAM,CAAC,MAAM,SAAS,4BACiB,wBAAa,KAAK,EAAE,IAAI,CAAC,EAA9D,wBAAiB,eAAe,EAA/B,aAAa,EAAmB,CAA6B,CAAA"}
1
+ {"version":3,"file":"Shard.js","names":["_DiscordConfig","require","_RateLimit","_DiscordWS","Heartbeats","_interopRequireWildcard","Identify","InvalidSession","Utils","_WS","_Log","Effect","Layer","_Context","Option","Hub","Queue","Ref","Duration","Chunk","ConfigSecret","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","make","gen","_","token","gateway","DiscordConfig","limiter","RateLimiter","dws","DiscordWS","log","Log","connect","shard","hub","sendQueue","outboundQueue","unbounded","pendingQueue","phase","setPhase","p","zipLeft","debug","outbound","take","maybeWait","minutes","send","flatMap","offer","heartbeatSend","succeed","prioritySend","resume","pipe","zipRight","takeAll","tap","offerAll","asUnit","onConnecting","msgs","filter","msg","Reconnect","op","socket","latestReady","updateLatestReady","latest","some","t","map","d","latestSequence","updateLatestSequence","fromNullable","s","maybeUpdateUrl","match","onNone","unit","onSome","resume_gateway_url","setUrl","hellos","acks","heartbeats","identify","identifyOrResume","value","intents","presence","onPayload","all","discard","fromPayload","publish","drainSendQueue","forever","run","concurrency","id","exports","Shard","Tag","LiveShard","provide","merge","LiveDiscordWS","LiveRateLimiter","effect"],"sources":["../src/DiscordGateway/Shard.ts"],"sourcesContent":[null],"mappings":";;;;;;AAAA,IAAAA,cAAA,gBAAAC,OAAA;AACA,IAAAC,UAAA,gBAAAD,OAAA;AACA,IAAAE,UAAA,gBAAAF,OAAA;AACA,IAAAG,UAAA,gBAAAC,uBAAA,eAAAJ,OAAA;AACA,IAAAK,QAAA,gBAAAD,uBAAA,eAAA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OAAO;IAAErE;EAAO,CAAW;AAC7B,CAAC,CAAC;AAAAwE,OAAA,CAAApF,IAAA,GAAAA,IAAA;AAGK,MAAMqF,KAAK,gBAAG,IAAAC,YAAG,GAAS;AAAAF,OAAA,CAAAC,KAAA,GAAAA,KAAA;AAC1B,MAAME,SAAS,gBAAGtH,KAAK,CAACuH,OAAO,eACpCvH,KAAK,CAACwH,KAAK,CAACC,wBAAa,EAAEC,0BAAe,CAAC,eAC3C1H,KAAK,CAAC2H,MAAM,CAACP,KAAK,EAAErF,IAAI,CAAC,CAC1B;AAAAoF,OAAA,CAAAG,SAAA,GAAAA,SAAA"}
@@ -1,13 +1,16 @@
1
- import { Effect, Maybe } from "dfx/_common";
1
+ import * as Effect from "@effect/io/Effect";
2
+ import * as Layer from "@effect/io/Layer";
3
+ import { Tag } from "@effect/data/Context";
4
+ import * as Option from "@effect/data/Option";
2
5
  export interface ClaimIdContext {
3
6
  sharderCount: number;
4
7
  totalCount: number;
5
8
  }
6
9
  export interface ShardStore {
7
- claimId: (ctx: ClaimIdContext) => Effect<never, never, Maybe<number>>;
8
- allClaimed: (totalCount: number) => Effect<never, never, boolean>;
9
- heartbeat?: (shardId: number) => Effect<never, never, void>;
10
+ claimId: (ctx: ClaimIdContext) => Effect.Effect<never, never, Option.Option<number>>;
11
+ allClaimed: (totalCount: number) => Effect.Effect<never, never, boolean>;
12
+ heartbeat?: (shardId: number) => Effect.Effect<never, never, void>;
10
13
  }
11
- export declare const ShardStore: import("@effect/data/Context").Tag<ShardStore, ShardStore>;
12
- export declare const LiveMemoryShardStore: import("@effect-http/client/_common").Layer<never, never, ShardStore>;
14
+ export declare const ShardStore: Tag<ShardStore, ShardStore>;
15
+ export declare const LiveMemoryShardStore: Layer.Layer<never, never, ShardStore>;
13
16
  //# sourceMappingURL=ShardStore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ShardStore.d.ts","sourceRoot":"","sources":["../src/DiscordGateway/ShardStore.ts"],"names":[],"mappings":";AA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AAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;CACnE;AACD,eAAO,MAAM,UAAU,6BAAoB,CAAA;AAsB3C,eAAO,MAAM,oBAAoB,uCAAsC,CAAA"}
@@ -1,22 +1,34 @@
1
- import * as tsplus_module_1 from "dfx/_common";
2
- import * as tsplus_module_2 from "@effect/data/Option";
3
- import * as tsplus_module_3 from "@effect/io/Effect";
4
- import * as tsplus_module_4 from "@effect/io/Layer";
5
- export const ShardStore = tsplus_module_1.Tag();
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ShardStore = exports.LiveMemoryShardStore = void 0;
7
+ var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Effect"));
8
+ var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Layer"));
9
+ var _Context = /*#__PURE__*/require("@effect/data/Context");
10
+ var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Option"));
11
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
+ const ShardStore = /*#__PURE__*/(0, _Context.Tag)();
6
14
  // Very basic shard id store, that does no health checks
15
+ exports.ShardStore = ShardStore;
7
16
  const memoryStore = () => {
8
- let currentId = 0;
9
- return {
10
- claimId: ({ totalCount }) => tsplus_module_3.sync(() => {
11
- if (currentId >= totalCount) {
12
- return tsplus_module_2.none();
13
- }
14
- const id = currentId;
15
- currentId++;
16
- return tsplus_module_2.some(id);
17
- }),
18
- allClaimed: totalCount => tsplus_module_3.sync(() => currentId >= totalCount),
19
- };
17
+ let currentId = 0;
18
+ return {
19
+ claimId: ({
20
+ totalCount
21
+ }) => Effect.sync(() => {
22
+ if (currentId >= totalCount) {
23
+ return Option.none();
24
+ }
25
+ const id = currentId;
26
+ currentId++;
27
+ return Option.some(id);
28
+ }),
29
+ allClaimed: totalCount => Effect.sync(() => currentId >= totalCount)
30
+ };
20
31
  };
21
- export const LiveMemoryShardStore = tsplus_module_4.sync(ShardStore, memoryStore);
32
+ const LiveMemoryShardStore = /*#__PURE__*/Layer.sync(ShardStore, memoryStore);
33
+ exports.LiveMemoryShardStore = LiveMemoryShardStore;
22
34
  //# sourceMappingURL=ShardStore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ShardStore.js","sourceRoot":"","sources":["../src/DiscordGateway/ShardStore.ts"],"names":[],"mappings":";;;;AAUA,MAAM,CAAC,MAAM,UAAU,GAAG,gBAAA,GAAG,EAAc,CAAA;AAE3C,wDAAwD;AACxD,MAAM,WAAW,GAAG,GAAe,EAAE;IACnC,IAAI,SAAS,GAAG,CAAC,CAAA;IAEjB,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAC1B,qBAAY,GAAG,EAAE;YACf,IAAI,SAAS,IAAI,UAAU,EAAE;gBAC3B,OAAO,sBAAY,CAAA;aACpB;YAED,MAAM,EAAE,GAAG,SAAS,CAAA;YACpB,SAAS,EAAE,CAAA;YACX,OAAO,qBAAW,EAAE,CAAC,CAAA;QACvB,CAAC,CAAC;QAEJ,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC,qBAAY,GAAG,EAAE,CAAC,SAAS,IAAI,UAAU,CAAC;KACrE,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAAW,UAAU,EAAE,WAAW,CAAC,CAAA"}
1
+ {"version":3,"file":"ShardStore.js","names":["Effect","_interopRequireWildcard","require","Layer","_Context","Option","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ShardStore","Tag","exports","memoryStore","currentId","claimId","totalCount","sync","none","id","some","allClaimed","LiveMemoryShardStore"],"sources":["../src/DiscordGateway/ShardStore.ts"],"sourcesContent":[null],"mappings":";;;;;;AAAA,IAAAA,MAAA,gBAAAC,uBAAA,eAAAC,OAAA;AACA,IAAAC,KAAA,gBAAAF,uBAAA,eAAAC,OAAA;AACA,IAAAE,QAAA,gBAAAF,OAAA;AACA,IAAAG,MAAA,gBAAAJ,uBAAA,eAAAC,OAAA;AAA6C,SAAAI,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAN,wBAAAU,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,Y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AACgC,IAAI,CAACP,UAAU,EAAEG,WAAW,CAAC;AAAAD,OAAA,CAAAU,oBAAA,GAAAA,oBAAA"}
@@ -1,17 +1,23 @@
1
- import { Maybe, Schedule, Effect, Discord, Hub, Dequeue } from "dfx/_common";
1
+ import { Tag } from "@effect/data/Context";
2
+ import * as HashSet from "@effect/data/HashSet";
3
+ import * as Effect from "@effect/io/Effect";
4
+ import * as Hub from "@effect/io/Hub";
5
+ import * as Layer from "@effect/io/Layer";
6
+ import * as Queue from "@effect/io/Queue";
2
7
  import { DiscordConfig } from "dfx/DiscordConfig";
8
+ import { RunningShard, Shard } from "dfx/DiscordGateway/Shard";
9
+ import { ShardStore } from "dfx/DiscordGateway/ShardStore";
10
+ import { WebSocketCloseError, WebSocketError } from "dfx/DiscordGateway/WS";
3
11
  import { DiscordREST } from "dfx/DiscordREST";
4
- import { RateLimiter } from "../RateLimit.js";
5
- import { RunningShard, Shard } from "./Shard.js";
6
- import { ShardStore } from "./ShardStore.js";
7
- import { WebSocketCloseError, WebSocketError } from "./WS.js";
8
- declare const make: import("@effect/io/Effect").Effect<DiscordREST | DiscordConfig | RateLimiter | Shard | ShardStore, never, {
9
- readonly shards: import("@effect/io/Effect").Effect<never, never, import("../_common.js").HashSet<RunningShard>>;
10
- readonly run: (hub: Hub<Discord.GatewayPayload<Discord.ReceiveEvent>>, sendQueue: Dequeue<Discord.GatewayPayload<Discord.SendEvent>>) => import("@effect/io/Effect").Effect<never, WebSocketError | WebSocketCloseError, never>;
12
+ import { RateLimiter } from "dfx/RateLimit";
13
+ import * as Discord from "dfx/types";
14
+ declare const make: Effect.Effect<DiscordConfig | RateLimiter | DiscordREST | ShardStore | Shard, never, {
15
+ readonly shards: Effect.Effect<never, never, HashSet.HashSet<RunningShard>>;
16
+ readonly run: (hub: Hub.Hub<Discord.GatewayPayload<Discord.ReceiveEvent>>, sendQueue: Queue.Dequeue<Discord.GatewayPayload<Discord.SendEvent>>) => Effect.Effect<never, WebSocketError | WebSocketCloseError, never>;
11
17
  }>;
12
- export interface Sharder extends Effect.Success<typeof make> {
18
+ export interface Sharder extends Effect.Effect.Success<typeof make> {
13
19
  }
14
- export declare const Sharder: import("@effect/data/Context").Tag<Sharder, Sharder>;
15
- export declare const LiveSharder: import("@effect-http/client/_common").Layer<DiscordREST | DiscordConfig | import("../Log.js").Log | import("../RateLimit.js").RateLimitStore | import("./DiscordWS.js").DiscordWSCodec | ShardStore, never, Sharder>;
20
+ export declare const Sharder: Tag<Sharder, Sharder>;
21
+ export declare const LiveSharder: Layer.Layer<DiscordConfig | import("../Log").Log | import("dfx/RateLimit").RateLimitStore | DiscordREST | ShardStore | import("./DiscordWS").DiscordWSCodec, never, Sharder>;
16
22
  export {};
17
23
  //# sourceMappingURL=Sharder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Sharder.d.ts","sourceRoot":"","sources":["../src/DiscordGateway/Sharder.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAmB,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EAAa,YAAY,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAO7D,QAAA,MAAM,IAAI;;wBA8CD,IAAI,QAAQ,cAAc,CAAC,QAAQ,YAAY,CAAC,CAAC,aAC3C,QAAQ,QAAQ,cAAc,CAAC,QAAQ,SAAS,CAAC,CAAC;EAgD/D,CAAA;AAEF,MAAM,WAAW,OAAQ,SAAQ,MAAM,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC;CAAG;AAC/D,eAAO,MAAM,OAAO,sDAAiB,CAAA;AACrC,eAAO,MAAM,WAAW,sNACsC,CAAA"}
1
+ {"version":3,"file":"Sharder.d.ts","sourceRoot":"","sources":["../src/DiscordGateway/Sharder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAE1C,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAA;AAG/C,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAC3C,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AAGzC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAa,YAAY,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC1D,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAmB,WAAW,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,KAAK,OAAO,MAAM,WAAW,CAAA;AAOpC,QAAA,MAAM,IAAI;;wBAiDD,OAAO,CAAC,QAAQ,cAAc,CAAC,QAAQ,YAAY,CAAC,CAAC,aAC/C,MAAM,OAAO,CAAC,QAAQ,cAAc,CAAC,QAAQ,SAAS,CAAC,CAAC;EAoDrE,CAAA;AAEF,MAAM,WAAW,OAAQ,SAAQ,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC;CAAG;AACtE,eAAO,MAAM,OAAO,uBAAiB,CAAA;AACrC,eAAO,MAAM,WAAW,8KAGvB,CAAA"}
@@ -1,53 +1,83 @@
1
- import * as tsplus_module_1 from "@effect/data/Option";
2
- import * as tsplus_module_2 from "@effect/data/Duration";
3
- import * as tsplus_module_3 from "@effect/io/Schedule";
4
- import * as tsplus_module_4 from "@effect/io/Ref";
5
- import * as tsplus_module_5 from "@effect/io/Effect";
6
- import * as tsplus_module_6 from "dfx/_common";
7
- import * as tsplus_module_7 from "@effect/data/Chunk";
8
- import * as tsplus_module_8 from "@effect/io/Deferred";
9
- import * as tsplus_module_9 from "@effect/data/HashSet";
10
- import * as tsplus_module_10 from "@effect/data/Function";
11
- import * as tsplus_module_11 from "@effect/io/Layer";
12
- import { millis } from "@effect/data/Duration";
13
- import { DiscordConfig } from "dfx/DiscordConfig";
14
- import { DiscordREST } from "dfx/DiscordREST";
15
- import { LiveRateLimiter, RateLimiter } from "../RateLimit.js";
16
- import { LiveShard, Shard } from "./Shard.js";
17
- import { ShardStore } from "./ShardStore.js";
18
- const claimRepeatPolicy = tsplus_module_3.passthrough(tsplus_module_3.whileInput(tsplus_module_3.fixed(tsplus_module_2.minutes(3)), (_) => tsplus_module_1.isNone(_)));
19
- const make = tsplus_module_5.flatMap(tsplus_module_5.map(ShardStore, tsplus_module_10.identity), store => tsplus_module_5.flatMap(tsplus_module_5.map(DiscordREST, tsplus_module_10.identity), rest => tsplus_module_5.flatMap(tsplus_module_5.map(DiscordConfig, tsplus_module_10.identity), ({ gateway: config }) => tsplus_module_5.flatMap(tsplus_module_5.map(RateLimiter, tsplus_module_10.identity), limiter => tsplus_module_5.flatMap(tsplus_module_5.map(Shard, tsplus_module_10.identity), shard => tsplus_module_5.flatMap(tsplus_module_4.make(tsplus_module_9.empty()), currentShards => {
20
- const takeConfig = (totalCount) => tsplus_module_5.map(tsplus_module_4.make(0), currentCount => {
21
- const claimId = (sharderCount) => tsplus_module_5.map(tsplus_module_5.repeat(store
22
- .claimId({
23
- totalCount,
24
- sharderCount,
25
- }), claimRepeatPolicy), _ => _.value);
26
- return tsplus_module_5.map(tsplus_module_5.flatMap(tsplus_module_4.getAndUpdate(currentCount, _ => _ + 1), claimId), id => ({ id, totalCount }));
27
- });
28
- return tsplus_module_5.map(tsplus_module_5.catchAll(tsplus_module_5.flatMap(rest
29
- .getGatewayBot(), r => r.json), () => tsplus_module_5.succeed({
30
- url: "wss://gateway.discord.gg/",
31
- shards: 1,
32
- session_start_limit: {
33
- total: 0,
34
- remaining: 0,
35
- reset_after: 0,
36
- max_concurrency: 1,
37
- },
38
- })), gateway => {
39
- const run = (hub, sendQueue) => tsplus_module_5.flatMap(tsplus_module_8.make(), deferred => tsplus_module_5.flatMap(takeConfig(config.shardCount ?? gateway.shards), take => {
40
- const spawner = tsplus_module_5.forever(tsplus_module_5.flatMap(tsplus_module_5.flatMap(tsplus_module_5.tap(tsplus_module_5.map(take, config => ({
41
- ...config,
42
- url: gateway.url,
43
- concurrency: gateway.session_start_limit.max_concurrency,
44
- })), ({ id, concurrency }) => limiter.maybeWait(`dfx.sharder.${id % concurrency}`, millis(config.identifyRateLimit[0]), config.identifyRateLimit[1])), c => shard.connect([c.id, c.totalCount], hub, sendQueue)), shard => tsplus_module_5.fork(tsplus_module_5.catchAllCause(tsplus_module_5.acquireUseRelease(tsplus_module_4.update(currentShards, _ => tsplus_module_9.add(_, shard)), () => shard.run, () => tsplus_module_4.update(currentShards, _ => tsplus_module_9.remove(_, shard))), _ => tsplus_module_8.failCause(deferred, _)))));
45
- const spawners = tsplus_module_7.map(tsplus_module_7.range(1, gateway.session_start_limit.max_concurrency), () => spawner);
46
- return tsplus_module_5.all(tsplus_module_5.all(spawners, { concurrency: "unbounded", discard: true }), tsplus_module_6.deferredAwait(deferred), { concurrency: "unbounded", discard: true });
47
- }));
48
- return { shards: tsplus_module_4.get(currentShards), run };
49
- });
50
- }))))));
51
- export const Sharder = tsplus_module_6.Tag();
52
- export const LiveSharder = tsplus_module_11.provide(tsplus_module_11.effect(Sharder, make))((tsplus_module_11.merge(LiveShard)(LiveRateLimiter)));
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Sharder = exports.LiveSharder = void 0;
7
+ var Chunk = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Chunk"));
8
+ var _Context = /*#__PURE__*/require("@effect/data/Context");
9
+ var Duration = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Duration"));
10
+ var HashSet = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/HashSet"));
11
+ var Deferred = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Deferred"));
12
+ var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Effect"));
13
+ var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Layer"));
14
+ var Ref = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Ref"));
15
+ var Schedule = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Schedule"));
16
+ var _DiscordConfig = /*#__PURE__*/require("dfx/DiscordConfig");
17
+ var _Shard = /*#__PURE__*/require("dfx/DiscordGateway/Shard");
18
+ var _ShardStore = /*#__PURE__*/require("dfx/DiscordGateway/ShardStore");
19
+ var _DiscordREST = /*#__PURE__*/require("dfx/DiscordREST");
20
+ var _RateLimit = /*#__PURE__*/require("dfx/RateLimit");
21
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
22
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
+ const claimRepeatPolicy = /*#__PURE__*/Schedule.fixed("3 minutes").pipe( /*#__PURE__*/Schedule.whileInput(_ => _._tag === "None"), Schedule.passthrough);
24
+ const make = /*#__PURE__*/Effect.gen(function* (_) {
25
+ const store = yield* _(_ShardStore.ShardStore);
26
+ const rest = yield* _(_DiscordREST.DiscordREST);
27
+ const {
28
+ gateway: config
29
+ } = yield* _(_DiscordConfig.DiscordConfig);
30
+ const limiter = yield* _(_RateLimit.RateLimiter);
31
+ const shard = yield* _(_Shard.Shard);
32
+ const currentShards = yield* _(Ref.make(HashSet.empty()));
33
+ const takeConfig = totalCount => Effect.gen(function* (_) {
34
+ const currentCount = yield* _(Ref.make(0));
35
+ const claimId = sharderCount => store.claimId({
36
+ totalCount,
37
+ sharderCount
38
+ }).pipe(Effect.repeat(claimRepeatPolicy), Effect.map(_ => _.value));
39
+ return Ref.getAndUpdate(currentCount, _ => _ + 1).pipe(Effect.flatMap(claimId), Effect.map(id => ({
40
+ id,
41
+ totalCount
42
+ })));
43
+ });
44
+ const gateway = yield* _(rest.getGatewayBot(), Effect.flatMap(r => r.json), Effect.catchAll(() => Effect.succeed({
45
+ url: "wss://gateway.discord.gg/",
46
+ shards: 1,
47
+ session_start_limit: {
48
+ total: 0,
49
+ remaining: 0,
50
+ reset_after: 0,
51
+ max_concurrency: 1
52
+ }
53
+ })));
54
+ const run = (hub, sendQueue) => Effect.gen(function* (_) {
55
+ const deferred = yield* _(Deferred.make());
56
+ const take = yield* _(takeConfig(config.shardCount ?? gateway.shards));
57
+ const spawner = take.pipe(Effect.map(config => ({
58
+ ...config,
59
+ url: gateway.url,
60
+ concurrency: gateway.session_start_limit.max_concurrency
61
+ })), Effect.tap(({
62
+ id,
63
+ concurrency
64
+ }) => limiter.maybeWait(`dfx.sharder.${id % concurrency}`, Duration.millis(config.identifyRateLimit[0]), config.identifyRateLimit[1])), Effect.flatMap(c => shard.connect([c.id, c.totalCount], hub, sendQueue)), Effect.flatMap(shard => Effect.acquireUseRelease(Ref.update(currentShards, HashSet.add(shard)), () => shard.run, () => Ref.update(currentShards, HashSet.remove(shard))).pipe(Effect.catchAllCause(_ => Deferred.failCause(deferred, _)), Effect.fork)), Effect.forever);
65
+ const spawners = Chunk.map(Chunk.range(1, gateway.session_start_limit.max_concurrency), () => spawner);
66
+ return yield* _(Effect.all(Effect.all(spawners, {
67
+ concurrency: "unbounded",
68
+ discard: true
69
+ }), Deferred.await(deferred), {
70
+ concurrency: "unbounded",
71
+ discard: true
72
+ }));
73
+ });
74
+ return {
75
+ shards: Ref.get(currentShards),
76
+ run
77
+ };
78
+ });
79
+ const Sharder = /*#__PURE__*/(0, _Context.Tag)();
80
+ exports.Sharder = Sharder;
81
+ const LiveSharder = /*#__PURE__*/Layer.provide( /*#__PURE__*/Layer.merge(_RateLimit.LiveRateLimiter, _Shard.LiveShard), /*#__PURE__*/Layer.effect(Sharder, make));
82
+ exports.LiveSharder = LiveSharder;
53
83
  //# sourceMappingURL=Sharder.js.map