dfx 0.95.1 → 0.95.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.
- package/DiscordGateway/Shard/StateStore.d.ts +25 -0
- package/DiscordGateway/Shard/StateStore.d.ts.map +1 -0
- package/DiscordGateway/Shard/StateStore.js +33 -0
- package/DiscordGateway/Shard/StateStore.js.map +1 -0
- package/DiscordGateway/Shard/heartbeats.d.ts +2 -2
- package/DiscordGateway/Shard/heartbeats.d.ts.map +1 -1
- package/DiscordGateway/Shard/heartbeats.js +4 -4
- package/DiscordGateway/Shard/heartbeats.js.map +1 -1
- package/DiscordGateway/Shard/identify.d.ts +2 -6
- package/DiscordGateway/Shard/identify.d.ts.map +1 -1
- package/DiscordGateway/Shard/identify.js +5 -12
- package/DiscordGateway/Shard/identify.js.map +1 -1
- package/DiscordGateway/Shard/utils.d.ts +1 -8
- package/DiscordGateway/Shard/utils.d.ts.map +1 -1
- package/DiscordGateway/Shard/utils.js +1 -10
- package/DiscordGateway/Shard/utils.js.map +1 -1
- package/DiscordGateway/Shard.d.ts +5 -4
- package/DiscordGateway/Shard.d.ts.map +1 -1
- package/DiscordGateway/Shard.js +41 -26
- package/DiscordGateway/Shard.js.map +1 -1
- package/DiscordGateway/Sharder.d.ts +1 -1
- package/DiscordGateway/Sharder.d.ts.map +1 -1
- package/DiscordGateway.d.ts +1 -1
- package/DiscordGateway.d.ts.map +1 -1
- package/gateway.d.ts +2 -2
- package/gateway.d.ts.map +1 -1
- package/gateway.js +2 -1
- package/gateway.js.map +1 -1
- package/mjs/DiscordGateway/Shard/StateStore.mjs +25 -0
- package/mjs/DiscordGateway/Shard/StateStore.mjs.map +1 -0
- package/mjs/DiscordGateway/Shard/heartbeats.mjs +4 -4
- package/mjs/DiscordGateway/Shard/heartbeats.mjs.map +1 -1
- package/mjs/DiscordGateway/Shard/identify.mjs +5 -12
- package/mjs/DiscordGateway/Shard/identify.mjs.map +1 -1
- package/mjs/DiscordGateway/Shard/utils.mjs +0 -8
- package/mjs/DiscordGateway/Shard/utils.mjs.map +1 -1
- package/mjs/DiscordGateway/Shard.mjs +41 -26
- package/mjs/DiscordGateway/Shard.mjs.map +1 -1
- package/mjs/gateway.mjs +2 -1
- package/mjs/gateway.mjs.map +1 -1
- package/mjs/version.mjs +1 -1
- package/package.json +2 -2
- package/src/DiscordGateway/Shard/StateStore.ts +46 -0
- package/src/DiscordGateway/Shard/heartbeats.ts +8 -7
- package/src/DiscordGateway/Shard/identify.ts +10 -18
- package/src/DiscordGateway/Shard/utils.ts +1 -28
- package/src/DiscordGateway/Shard.ts +53 -50
- package/src/gateway.ts +2 -0
- package/src/version.ts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/src/DiscordGateway/Shard/invalidSession.ts +0 -11
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
import * as Chunk from "effect/Chunk"
|
|
2
|
-
import { GenericTag } from "effect/Context"
|
|
3
|
-
import * as Duration from "effect/Duration"
|
|
4
|
-
import { pipe } from "effect/Function"
|
|
5
|
-
import * as Option from "effect/Option"
|
|
6
|
-
import * as Secret from "effect/Secret"
|
|
7
|
-
import * as Effect from "effect/Effect"
|
|
8
|
-
import * as PubSub from "effect/PubSub"
|
|
9
|
-
import * as Layer from "effect/Layer"
|
|
10
|
-
import * as Queue from "effect/Queue"
|
|
11
|
-
import * as Ref from "effect/Ref"
|
|
12
1
|
import { DiscordConfig } from "dfx/DiscordConfig"
|
|
13
2
|
import type { Message } from "dfx/DiscordGateway/DiscordWS"
|
|
14
3
|
import {
|
|
@@ -16,13 +5,25 @@ import {
|
|
|
16
5
|
DiscordWSLive,
|
|
17
6
|
Reconnect,
|
|
18
7
|
} from "dfx/DiscordGateway/DiscordWS"
|
|
8
|
+
import { Messaging, MesssagingLive } from "dfx/DiscordGateway/Messaging"
|
|
9
|
+
import type { ShardState } from "dfx/DiscordGateway/Shard/StateStore"
|
|
10
|
+
import { ShardStateStore } from "dfx/DiscordGateway/Shard/StateStore"
|
|
19
11
|
import * as Heartbeats from "dfx/DiscordGateway/Shard/heartbeats"
|
|
20
12
|
import * as Identify from "dfx/DiscordGateway/Shard/identify"
|
|
21
|
-
import
|
|
22
|
-
import * as Utils from "dfx/DiscordGateway/Shard/utils"
|
|
23
|
-
import { RateLimiterLive, RateLimiter } from "dfx/RateLimit"
|
|
13
|
+
import { RateLimiter, RateLimiterLive } from "dfx/RateLimit"
|
|
24
14
|
import * as Discord from "dfx/types"
|
|
25
|
-
import
|
|
15
|
+
import * as Chunk from "effect/Chunk"
|
|
16
|
+
import { GenericTag } from "effect/Context"
|
|
17
|
+
import * as Duration from "effect/Duration"
|
|
18
|
+
import * as Effect from "effect/Effect"
|
|
19
|
+
import { pipe } from "effect/Function"
|
|
20
|
+
import * as Layer from "effect/Layer"
|
|
21
|
+
import * as Option from "effect/Option"
|
|
22
|
+
import * as PubSub from "effect/PubSub"
|
|
23
|
+
import * as Queue from "effect/Queue"
|
|
24
|
+
import * as Ref from "effect/Ref"
|
|
25
|
+
import * as Secret from "effect/Secret"
|
|
26
|
+
import type * as Types from "effect/Types"
|
|
26
27
|
|
|
27
28
|
const enum Phase {
|
|
28
29
|
Connecting,
|
|
@@ -35,13 +36,23 @@ export const make = Effect.gen(function* () {
|
|
|
35
36
|
const limiter = yield* RateLimiter
|
|
36
37
|
const dws = yield* DiscordWS
|
|
37
38
|
const { hub, sendQueue } = yield* Messaging
|
|
39
|
+
const shardState = yield* ShardStateStore
|
|
38
40
|
|
|
39
41
|
const connect = (shard: [id: number, count: number]) =>
|
|
40
|
-
Effect.gen(function* () {
|
|
42
|
+
Effect.gen(function* (_) {
|
|
41
43
|
const outboundQueue = yield* Queue.unbounded<Message>()
|
|
42
44
|
const pendingQueue = yield* Queue.unbounded<Message>()
|
|
43
45
|
const phase = yield* Ref.make(Phase.Connecting)
|
|
44
|
-
const
|
|
46
|
+
const stateStore = shardState.forShard(shard)
|
|
47
|
+
const resumeState: Types.Mutable<ShardState> = Option.getOrElse(
|
|
48
|
+
yield* stateStore.get,
|
|
49
|
+
() => ({
|
|
50
|
+
resumeUrl: "",
|
|
51
|
+
sessionId: "",
|
|
52
|
+
sequence: 0,
|
|
53
|
+
}),
|
|
54
|
+
)
|
|
55
|
+
const setPhase = (p: Phase): Effect.Effect<void> =>
|
|
45
56
|
Effect.zipLeft(
|
|
46
57
|
Ref.set(phase, p),
|
|
47
58
|
Effect.annotateLogs(Effect.logTrace("phase transition"), "phase", p),
|
|
@@ -94,29 +105,6 @@ export const make = Effect.gen(function* () {
|
|
|
94
105
|
|
|
95
106
|
const socket = yield* dws.connect({ outbound, onConnecting })
|
|
96
107
|
|
|
97
|
-
const isReady = Option.liftPredicate(
|
|
98
|
-
(
|
|
99
|
-
p: Discord.GatewayPayload,
|
|
100
|
-
): p is Discord.GatewayPayload<Discord.ReadyEvent> =>
|
|
101
|
-
p.op === Discord.GatewayOpcode.DISPATCH && p.t === "READY",
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
const [latestReady, updateLatestReady] = yield* Utils.latest(p =>
|
|
105
|
-
Option.map(isReady(p), p => p.d!),
|
|
106
|
-
)
|
|
107
|
-
const [latestSequence, updateLatestSequence] = yield* Utils.latest(p =>
|
|
108
|
-
Option.fromNullable(p.s),
|
|
109
|
-
)
|
|
110
|
-
const maybeUpdateUrl = (p: Discord.GatewayPayload) =>
|
|
111
|
-
Option.match(
|
|
112
|
-
Option.map(isReady(p), p => p.d!),
|
|
113
|
-
{
|
|
114
|
-
onNone: () => Effect.void,
|
|
115
|
-
onSome: ({ resume_gateway_url }) =>
|
|
116
|
-
socket.setUrl(resume_gateway_url),
|
|
117
|
-
},
|
|
118
|
-
)
|
|
119
|
-
|
|
120
108
|
const hellos = yield* Effect.acquireRelease(
|
|
121
109
|
Queue.unbounded<Discord.GatewayPayload>(),
|
|
122
110
|
Queue.shutdown,
|
|
@@ -127,7 +115,7 @@ export const make = Effect.gen(function* () {
|
|
|
127
115
|
)
|
|
128
116
|
|
|
129
117
|
// heartbeats
|
|
130
|
-
yield* Heartbeats.send(hellos, acks,
|
|
118
|
+
yield* Heartbeats.send(hellos, acks, stateStore.get, heartbeatSend).pipe(
|
|
131
119
|
Effect.forkScoped,
|
|
132
120
|
Effect.interruptible,
|
|
133
121
|
)
|
|
@@ -140,15 +128,29 @@ export const make = Effect.gen(function* () {
|
|
|
140
128
|
intents: gateway.intents,
|
|
141
129
|
presence: gateway.presence,
|
|
142
130
|
},
|
|
143
|
-
|
|
144
|
-
latestSequence,
|
|
131
|
+
stateStore.get,
|
|
145
132
|
)
|
|
146
133
|
|
|
147
134
|
const onPayload = (p: Discord.GatewayPayload) =>
|
|
148
135
|
pipe(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
136
|
+
Effect.suspend(() => {
|
|
137
|
+
if (typeof p.s === "number") {
|
|
138
|
+
resumeState.sequence = p.s
|
|
139
|
+
}
|
|
140
|
+
if (p.op === Discord.GatewayOpcode.DISPATCH && p.t === "READY") {
|
|
141
|
+
const payload = p.d as Discord.ReadyEvent
|
|
142
|
+
resumeState.sessionId = payload.session_id
|
|
143
|
+
resumeState.resumeUrl = payload.resume_gateway_url
|
|
144
|
+
return Effect.zipRight(
|
|
145
|
+
stateStore.set(resumeState),
|
|
146
|
+
socket.setUrl(payload.resume_gateway_url),
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
if (resumeState.resumeUrl !== "" && resumeState.sessionId !== "") {
|
|
150
|
+
return stateStore.set(resumeState)
|
|
151
|
+
}
|
|
152
|
+
return Effect.void
|
|
153
|
+
}),
|
|
152
154
|
Effect.tap(() => {
|
|
153
155
|
switch (p.op) {
|
|
154
156
|
case Discord.GatewayOpcode.HELLO: {
|
|
@@ -162,10 +164,11 @@ export const make = Effect.gen(function* () {
|
|
|
162
164
|
return Queue.offer(acks, p)
|
|
163
165
|
}
|
|
164
166
|
case Discord.GatewayOpcode.INVALID_SESSION: {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
if (p.d) {
|
|
168
|
+
return send(Reconnect)
|
|
169
|
+
}
|
|
170
|
+
resumeState.sessionId = ""
|
|
171
|
+
return Effect.zipRight(stateStore.clear, send(Reconnect))
|
|
169
172
|
}
|
|
170
173
|
case Discord.GatewayOpcode.DISPATCH: {
|
|
171
174
|
if (p.t === "READY" || p.t === "RESUMED") {
|
package/src/gateway.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { DiscordGatewayLive } from "dfx/DiscordGateway"
|
|
|
3
3
|
import * as DiscordWS from "dfx/DiscordGateway/DiscordWS"
|
|
4
4
|
import { JsonDiscordWSCodecLive } from "dfx/DiscordGateway/DiscordWS"
|
|
5
5
|
import * as Shard from "dfx/DiscordGateway/Shard"
|
|
6
|
+
import { MemoryShardStateStoreLive } from "dfx/DiscordGateway/Shard/StateStore"
|
|
6
7
|
import * as SendEvent from "dfx/DiscordGateway/Shard/sendEvents"
|
|
7
8
|
import * as ShardStore from "dfx/DiscordGateway/ShardStore"
|
|
8
9
|
import { MemoryShardStoreLive } from "dfx/DiscordGateway/ShardStore"
|
|
@@ -31,6 +32,7 @@ export const DiscordLive = Layer.mergeAll(
|
|
|
31
32
|
Layer.provide(JsonDiscordWSCodecLive),
|
|
32
33
|
Layer.provide(MemoryRateLimitStoreLive),
|
|
33
34
|
Layer.provide(MemoryShardStoreLive),
|
|
35
|
+
Layer.provide(MemoryShardStateStoreLive),
|
|
34
36
|
)
|
|
35
37
|
|
|
36
38
|
export const DiscordIxLive = InteractionsRegistryLive.pipe(
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = "0.95.
|
|
1
|
+
export const LIB_VERSION = "0.95.2";
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const LIB_VERSION = "0.95.
|
|
1
|
+
export declare const LIB_VERSION = "0.95.2";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as Option from "effect/Option"
|
|
2
|
-
import * as Effect from "effect/Effect"
|
|
3
|
-
import * as Ref from "effect/Ref"
|
|
4
|
-
import { Reconnect, type Message } from "dfx/DiscordGateway/DiscordWS"
|
|
5
|
-
import type * as Discord from "dfx/types"
|
|
6
|
-
|
|
7
|
-
export const fromPayload = (
|
|
8
|
-
p: Discord.GatewayPayload,
|
|
9
|
-
latestReady: Ref.Ref<Option.Option<Discord.ReadyEvent>>,
|
|
10
|
-
): Effect.Effect<Message> =>
|
|
11
|
-
Effect.as(p.d ? Effect.void : Ref.set(latestReady, Option.none()), Reconnect)
|