dfx 0.74.0 → 0.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cache/prelude.d.ts +4 -3
- package/Cache/prelude.d.ts.map +1 -1
- package/Cache/prelude.js +6 -6
- package/Cache/prelude.js.map +1 -1
- package/Cache.d.ts +5 -6
- package/Cache.d.ts.map +1 -1
- package/Cache.js +20 -18
- package/Cache.js.map +1 -1
- package/DiscordGateway/DiscordWS.js +1 -1
- package/DiscordGateway/DiscordWS.js.map +1 -1
- package/DiscordGateway/Shard.d.ts +2 -2
- package/DiscordGateway/Shard.js +1 -1
- package/DiscordGateway/Shard.js.map +1 -1
- package/DiscordGateway/Sharder.js +1 -1
- package/DiscordGateway/Sharder.js.map +1 -1
- package/DiscordGateway/WS.d.ts +0 -1
- package/DiscordGateway/WS.d.ts.map +1 -1
- package/DiscordGateway.d.ts +1 -3
- package/DiscordGateway.d.ts.map +1 -1
- package/DiscordGateway.js +7 -4
- package/DiscordGateway.js.map +1 -1
- package/DiscordREST.js +1 -1
- package/DiscordREST.js.map +1 -1
- package/Helpers/interactions.js +1 -1
- package/Helpers/interactions.js.map +1 -1
- package/Helpers/permissions.d.ts +2 -2
- package/Helpers/permissions.d.ts.map +1 -1
- package/Interactions/context.d.ts +1 -1
- package/Interactions/definitions.d.ts +3 -3
- package/Interactions/gateway.d.ts +1 -3
- package/Interactions/gateway.d.ts.map +1 -1
- package/Interactions/gateway.js +10 -6
- package/Interactions/gateway.js.map +1 -1
- package/RateLimit.d.ts +2 -2
- package/gateway.d.ts +2 -3
- package/gateway.d.ts.map +1 -1
- package/gateway.js +7 -8
- package/gateway.js.map +1 -1
- package/mjs/Cache/prelude.mjs +6 -6
- package/mjs/Cache/prelude.mjs.map +1 -1
- package/mjs/Cache.mjs +20 -18
- package/mjs/Cache.mjs.map +1 -1
- package/mjs/DiscordGateway/DiscordWS.mjs +1 -1
- package/mjs/DiscordGateway/DiscordWS.mjs.map +1 -1
- package/mjs/DiscordGateway/Shard.mjs +1 -1
- package/mjs/DiscordGateway/Shard.mjs.map +1 -1
- package/mjs/DiscordGateway/Sharder.mjs +1 -1
- package/mjs/DiscordGateway/Sharder.mjs.map +1 -1
- package/mjs/DiscordGateway.mjs +7 -4
- package/mjs/DiscordGateway.mjs.map +1 -1
- package/mjs/DiscordREST.mjs +1 -1
- package/mjs/DiscordREST.mjs.map +1 -1
- package/mjs/Helpers/interactions.mjs +1 -1
- package/mjs/Helpers/interactions.mjs.map +1 -1
- package/mjs/Interactions/gateway.mjs +9 -6
- package/mjs/Interactions/gateway.mjs.map +1 -1
- package/mjs/gateway.mjs +3 -4
- package/mjs/gateway.mjs.map +1 -1
- package/mjs/types.mjs +6 -2
- package/mjs/types.mjs.map +1 -1
- package/mjs/version.mjs +1 -1
- package/mjs/webhooks.mjs +3 -3
- package/mjs/webhooks.mjs.map +1 -1
- package/package.json +4 -4
- package/src/Cache/prelude.ts +92 -92
- package/src/Cache.ts +136 -100
- package/src/DiscordGateway/DiscordWS.ts +1 -1
- package/src/DiscordGateway/Shard.ts +1 -1
- package/src/DiscordGateway/Sharder.ts +1 -1
- package/src/DiscordGateway.ts +19 -11
- package/src/DiscordREST.ts +2 -2
- package/src/Helpers/interactions.ts +1 -1
- package/src/Interactions/gateway.ts +40 -40
- package/src/gateway.ts +10 -16
- package/src/types.ts +28 -18
- package/src/version.ts +1 -1
- package/src/webhooks.ts +3 -3
- package/types.d.ts +28 -18
- package/types.d.ts.map +1 -1
- package/types.js +6 -2
- package/types.js.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/webhooks.js +3 -3
- package/webhooks.js.map +1 -1
package/src/Cache.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as Option from "effect/Option"
|
|
2
|
+
import * as Schedule from "effect/Schedule"
|
|
3
|
+
import type * as Scope from "effect/Scope"
|
|
2
4
|
import * as Effect from "effect/Effect"
|
|
3
5
|
import * as Stream from "effect/Stream"
|
|
4
6
|
import type { CacheDriver, ParentCacheDriver } from "dfx/Cache/driver"
|
|
@@ -24,7 +26,11 @@ export type CacheOp<T> =
|
|
|
24
26
|
| { op: "update"; resourceId: string; resource: T }
|
|
25
27
|
| { op: "delete"; resourceId: string }
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
const retryPolicy = Schedule.exponential("500 millis").pipe(
|
|
30
|
+
Schedule.union(Schedule.spaced("10 seconds")),
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
export interface ParentCache<EDriver, EMiss, EPMiss, A> {
|
|
28
34
|
readonly get: (
|
|
29
35
|
parentId: string,
|
|
30
36
|
id: string,
|
|
@@ -38,7 +44,6 @@ export interface ParentCache<EOps, EDriver, EMiss, EPMiss, A> {
|
|
|
38
44
|
readonly getForParent: (
|
|
39
45
|
parentId: string,
|
|
40
46
|
) => Effect.Effect<never, EDriver | EPMiss, ReadonlyMap<string, A>>
|
|
41
|
-
readonly run: Effect.Effect<never, EOps | EDriver, void>
|
|
42
47
|
readonly size: Effect.Effect<never, EDriver, number>
|
|
43
48
|
readonly sizeForParent: (
|
|
44
49
|
parentId: string,
|
|
@@ -77,86 +82,101 @@ export const makeWithParent = <EOps, EDriver, EMiss, EPMiss, A>({
|
|
|
77
82
|
onParentMiss: (
|
|
78
83
|
parentId: string,
|
|
79
84
|
) => Effect.Effect<never, EPMiss, Array<[id: string, resource: A]>>
|
|
80
|
-
}):
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return driver.delete(op.parentId, op.resourceId)
|
|
90
|
-
|
|
91
|
-
case "parentDelete":
|
|
92
|
-
return driver.parentDelete(op.parentId)
|
|
93
|
-
}
|
|
94
|
-
}),
|
|
95
|
-
)
|
|
85
|
+
}): Effect.Effect<Scope.Scope, never, ParentCache<EDriver, EMiss, EPMiss, A>> =>
|
|
86
|
+
Effect.gen(function* (_) {
|
|
87
|
+
yield* _(
|
|
88
|
+
Stream.runDrain(
|
|
89
|
+
Stream.tap(ops, (op): Effect.Effect<never, EDriver, void> => {
|
|
90
|
+
switch (op.op) {
|
|
91
|
+
case "create":
|
|
92
|
+
case "update":
|
|
93
|
+
return driver.set(op.parentId, op.resourceId, op.resource)
|
|
96
94
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
driver.get(parentId, id),
|
|
100
|
-
Option.match({
|
|
101
|
-
onNone: () =>
|
|
102
|
-
Effect.tap(onMiss(parentId, id), a => driver.set(parentId, id, a)),
|
|
103
|
-
onSome: Effect.succeed,
|
|
104
|
-
}),
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
const put = (_: A) =>
|
|
108
|
-
Effect.flatMap(id(_), ([parentId, id]) => driver.set(parentId, id, _))
|
|
95
|
+
case "delete":
|
|
96
|
+
return driver.delete(op.parentId, op.resourceId)
|
|
109
97
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
Effect.
|
|
117
|
-
Effect.
|
|
98
|
+
case "parentDelete":
|
|
99
|
+
return driver.parentDelete(op.parentId)
|
|
100
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
),
|
|
103
|
+
Effect.tapErrorCause(_ => Effect.logError("ops error, restarting", _)),
|
|
104
|
+
Effect.retry(retryPolicy),
|
|
105
|
+
Effect.forkScoped,
|
|
106
|
+
)
|
|
107
|
+
yield* _(
|
|
108
|
+
driver.run,
|
|
109
|
+
Effect.tapErrorCause(_ =>
|
|
110
|
+
Effect.logError("cache driver error, restarting", _),
|
|
111
|
+
),
|
|
112
|
+
Effect.retry(retryPolicy),
|
|
113
|
+
Effect.forkScoped,
|
|
118
114
|
)
|
|
119
115
|
|
|
120
|
-
|
|
121
|
-
...driver,
|
|
122
|
-
|
|
123
|
-
get,
|
|
124
|
-
put,
|
|
125
|
-
update,
|
|
126
|
-
|
|
127
|
-
getForParent: (parentId: string) =>
|
|
116
|
+
const get = (parentId: string, id: string) =>
|
|
128
117
|
Effect.flatMap(
|
|
129
|
-
driver.
|
|
118
|
+
driver.get(parentId, id),
|
|
130
119
|
Option.match({
|
|
131
120
|
onNone: () =>
|
|
132
|
-
|
|
133
|
-
Effect.tap(entries =>
|
|
134
|
-
Effect.all(
|
|
135
|
-
entries.map(([id, a]) => driver.set(parentId, id, a)),
|
|
136
|
-
{ concurrency: "unbounded" },
|
|
137
|
-
),
|
|
138
|
-
),
|
|
139
|
-
Effect.map(entries => new Map(entries) as ReadonlyMap<string, A>),
|
|
140
|
-
),
|
|
121
|
+
Effect.tap(onMiss(parentId, id), a => driver.set(parentId, id, a)),
|
|
141
122
|
onSome: Effect.succeed,
|
|
142
123
|
}),
|
|
143
|
-
)
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
const put = (_: A) =>
|
|
127
|
+
Effect.flatMap(id(_), ([parentId, id]) => driver.set(parentId, id, _))
|
|
128
|
+
|
|
129
|
+
const update = <R, E>(
|
|
130
|
+
parentId: string,
|
|
131
|
+
id: string,
|
|
132
|
+
f: (_: A) => Effect.Effect<R, E, A>,
|
|
133
|
+
) =>
|
|
134
|
+
get(parentId, id).pipe(
|
|
135
|
+
Effect.flatMap(f),
|
|
136
|
+
Effect.tap(_ => driver.set(parentId, id, _)),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
...driver,
|
|
141
|
+
|
|
142
|
+
get,
|
|
143
|
+
put,
|
|
144
|
+
update,
|
|
144
145
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
getForParent: (parentId: string) =>
|
|
147
|
+
Effect.flatMap(
|
|
148
|
+
driver.getForParent(parentId),
|
|
149
|
+
Option.match({
|
|
150
|
+
onNone: () =>
|
|
151
|
+
onParentMiss(parentId).pipe(
|
|
152
|
+
Effect.tap(entries =>
|
|
153
|
+
Effect.all(
|
|
154
|
+
entries.map(([id, a]) => driver.set(parentId, id, a)),
|
|
155
|
+
{ concurrency: "unbounded" },
|
|
156
|
+
),
|
|
157
|
+
),
|
|
158
|
+
Effect.map(
|
|
159
|
+
entries => new Map(entries) as ReadonlyMap<string, A>,
|
|
160
|
+
),
|
|
161
|
+
),
|
|
162
|
+
onSome: Effect.succeed,
|
|
163
|
+
}),
|
|
164
|
+
),
|
|
165
|
+
} as const
|
|
166
|
+
}).pipe(
|
|
167
|
+
Effect.annotateLogs({
|
|
168
|
+
package: "dfx",
|
|
169
|
+
service: "Cache",
|
|
148
170
|
}),
|
|
149
|
-
|
|
150
|
-
}
|
|
171
|
+
)
|
|
151
172
|
|
|
152
|
-
export interface Cache<
|
|
173
|
+
export interface Cache<EDriver, EMiss, A> {
|
|
153
174
|
readonly get: (id: string) => Effect.Effect<never, EDriver | EMiss, A>
|
|
154
175
|
readonly put: (_: A) => Effect.Effect<never, EDriver, void>
|
|
155
176
|
readonly update: <R, E>(
|
|
156
177
|
id: string,
|
|
157
178
|
f: (_: A) => Effect.Effect<R, E, A>,
|
|
158
179
|
) => Effect.Effect<R, EDriver | EMiss | E, A>
|
|
159
|
-
readonly run: Effect.Effect<never, EOps | EDriver, void>
|
|
160
180
|
readonly size: Effect.Effect<never, EDriver, number>
|
|
161
181
|
readonly set: (
|
|
162
182
|
resourceId: string,
|
|
@@ -178,48 +198,64 @@ export const make = <EOps, EDriver, EMiss, A>({
|
|
|
178
198
|
ops?: Stream.Stream<never, EOps, CacheOp<A>>
|
|
179
199
|
id: (_: A) => string
|
|
180
200
|
onMiss: (id: string) => Effect.Effect<never, EMiss, A>
|
|
181
|
-
}):
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return driver.delete(op.resourceId)
|
|
191
|
-
}
|
|
192
|
-
}),
|
|
193
|
-
)
|
|
201
|
+
}): Effect.Effect<Scope.Scope, never, Cache<EDriver, EMiss, A>> =>
|
|
202
|
+
Effect.gen(function* (_) {
|
|
203
|
+
yield* _(
|
|
204
|
+
Stream.runDrain(
|
|
205
|
+
Stream.tap(ops, (op): Effect.Effect<never, EDriver, void> => {
|
|
206
|
+
switch (op.op) {
|
|
207
|
+
case "create":
|
|
208
|
+
case "update":
|
|
209
|
+
return driver.set(op.resourceId, op.resource)
|
|
194
210
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
211
|
+
case "delete":
|
|
212
|
+
return driver.delete(op.resourceId)
|
|
213
|
+
}
|
|
214
|
+
}),
|
|
215
|
+
),
|
|
216
|
+
Effect.tapErrorCause(_ => Effect.logError("ops error, restarting", _)),
|
|
217
|
+
Effect.retry(retryPolicy),
|
|
218
|
+
Effect.forkScoped,
|
|
202
219
|
)
|
|
203
220
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
Effect.
|
|
221
|
+
yield* _(
|
|
222
|
+
driver.run,
|
|
223
|
+
Effect.tapErrorCause(_ =>
|
|
224
|
+
Effect.logError("cache driver error, restarting", _),
|
|
225
|
+
),
|
|
226
|
+
Effect.retry(retryPolicy),
|
|
227
|
+
Effect.forkScoped,
|
|
210
228
|
)
|
|
211
229
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
230
|
+
const get = (id: string) =>
|
|
231
|
+
Effect.flatMap(
|
|
232
|
+
driver.get(id),
|
|
233
|
+
Option.match({
|
|
234
|
+
onNone: () => Effect.tap(onMiss(id), a => driver.set(id, a)),
|
|
235
|
+
onSome: Effect.succeed,
|
|
236
|
+
}),
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
const put = (_: A) => driver.set(id(_), _)
|
|
240
|
+
|
|
241
|
+
const update = <R, E>(id: string, f: (_: A) => Effect.Effect<R, E, A>) =>
|
|
242
|
+
get(id).pipe(
|
|
243
|
+
Effect.flatMap(f),
|
|
244
|
+
Effect.tap(_ => driver.set(id, _)),
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
...driver,
|
|
249
|
+
get,
|
|
250
|
+
put,
|
|
251
|
+
update,
|
|
252
|
+
} as const
|
|
253
|
+
}).pipe(
|
|
254
|
+
Effect.annotateLogs({
|
|
255
|
+
package: "dfx",
|
|
256
|
+
service: "Cache",
|
|
220
257
|
}),
|
|
221
|
-
|
|
222
|
-
}
|
|
258
|
+
)
|
|
223
259
|
|
|
224
260
|
export class CacheMissError {
|
|
225
261
|
readonly _tag = "CacheMissError"
|
|
@@ -70,6 +70,6 @@ const make = Effect.gen(function* (_) {
|
|
|
70
70
|
export interface DiscordWS extends Effect.Effect.Success<typeof make> {}
|
|
71
71
|
export const DiscordWS = Tag<DiscordWS>()
|
|
72
72
|
export const LiveDiscordWS = Layer.provide(
|
|
73
|
-
LiveWS,
|
|
74
73
|
Layer.effect(DiscordWS, make),
|
|
74
|
+
LiveWS,
|
|
75
75
|
)
|
|
@@ -192,8 +192,8 @@ export const make = Effect.gen(function* (_) {
|
|
|
192
192
|
export interface Shard extends Effect.Effect.Success<typeof make> {}
|
|
193
193
|
export const Shard = Tag<Shard>()
|
|
194
194
|
export const LiveShard = Layer.provide(
|
|
195
|
-
Layer.merge(LiveDiscordWS, LiveRateLimiter),
|
|
196
195
|
Layer.effect(Shard, make),
|
|
196
|
+
Layer.merge(LiveDiscordWS, LiveRateLimiter),
|
|
197
197
|
)
|
|
198
198
|
|
|
199
199
|
export interface RunningShard
|
|
@@ -135,6 +135,6 @@ const make = Effect.gen(function* (_) {
|
|
|
135
135
|
export interface Sharder extends Effect.Effect.Success<typeof make> {}
|
|
136
136
|
export const Sharder = Tag<Sharder>()
|
|
137
137
|
export const LiveSharder = Layer.provide(
|
|
138
|
-
Layer.merge(LiveRateLimiter, LiveShard),
|
|
139
138
|
Layer.effect(Sharder, make),
|
|
139
|
+
Layer.merge(LiveRateLimiter, LiveShard),
|
|
140
140
|
)
|
package/src/DiscordGateway.ts
CHANGED
|
@@ -7,9 +7,9 @@ import * as Queue from "effect/Queue"
|
|
|
7
7
|
import * as Stream from "effect/Stream"
|
|
8
8
|
import type { RunningShard } from "dfx/DiscordGateway/Shard"
|
|
9
9
|
import { LiveSharder, Sharder } from "dfx/DiscordGateway/Sharder"
|
|
10
|
-
import type { WebSocketCloseError, WebSocketError } from "dfx/DiscordGateway/WS"
|
|
11
10
|
import type * as Discord from "dfx/types"
|
|
12
11
|
import * as EffectUtils from "dfx/utils/Effect"
|
|
12
|
+
import * as Schedule from "effect/Schedule"
|
|
13
13
|
|
|
14
14
|
const fromDispatchFactory =
|
|
15
15
|
<R, E>(
|
|
@@ -33,15 +33,10 @@ const handleDispatchFactory =
|
|
|
33
33
|
if (_.t === event) {
|
|
34
34
|
return handle(_.d as any)
|
|
35
35
|
}
|
|
36
|
-
return Effect.unit
|
|
36
|
+
return Effect.unit as any
|
|
37
37
|
})
|
|
38
38
|
|
|
39
39
|
export interface DiscordGateway {
|
|
40
|
-
readonly run: Effect.Effect<
|
|
41
|
-
never,
|
|
42
|
-
WebSocketError | WebSocketCloseError,
|
|
43
|
-
never
|
|
44
|
-
>
|
|
45
40
|
readonly dispatch: Stream.Stream<
|
|
46
41
|
never,
|
|
47
42
|
never,
|
|
@@ -77,19 +72,32 @@ export const make = Effect.gen(function* (_) {
|
|
|
77
72
|
const fromDispatch = fromDispatchFactory(dispatch)
|
|
78
73
|
const handleDispatch = handleDispatchFactory(hub)
|
|
79
74
|
|
|
80
|
-
|
|
75
|
+
yield* _(
|
|
76
|
+
sharder.run(hub, sendQueue),
|
|
77
|
+
Effect.tapErrorCause(_ => Effect.logError("fatal error, restarting", _)),
|
|
78
|
+
Effect.retry(
|
|
79
|
+
Schedule.exponential("1 seconds").pipe(
|
|
80
|
+
Schedule.union(Schedule.spaced("30 seconds")),
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
Effect.forkScoped,
|
|
84
|
+
)
|
|
81
85
|
|
|
82
86
|
return DiscordGateway.of({
|
|
83
|
-
run,
|
|
84
87
|
dispatch,
|
|
85
88
|
fromDispatch,
|
|
86
89
|
handleDispatch,
|
|
87
90
|
send,
|
|
88
91
|
shards: sharder.shards,
|
|
89
92
|
})
|
|
90
|
-
})
|
|
93
|
+
}).pipe(
|
|
94
|
+
Effect.annotateLogs({
|
|
95
|
+
package: "dfx",
|
|
96
|
+
service: "DiscordGateway",
|
|
97
|
+
}),
|
|
98
|
+
)
|
|
91
99
|
|
|
92
100
|
export const LiveDiscordGateway = Layer.provide(
|
|
101
|
+
Layer.scoped(DiscordGateway, make),
|
|
93
102
|
LiveSharder,
|
|
94
|
-
Layer.effect(DiscordGateway, make),
|
|
95
103
|
)
|
package/src/DiscordREST.ts
CHANGED
|
@@ -255,6 +255,6 @@ export interface DiscordREST
|
|
|
255
255
|
|
|
256
256
|
export const DiscordREST = Tag<DiscordREST>()
|
|
257
257
|
export const LiveDiscordREST = Layer.effect(DiscordREST, make).pipe(
|
|
258
|
-
Layer.
|
|
259
|
-
Layer.
|
|
258
|
+
Layer.provide(LiveRateLimiter),
|
|
259
|
+
Layer.provide(Http.client.layer),
|
|
260
260
|
)
|
|
@@ -151,7 +151,7 @@ export const resolveValues =
|
|
|
151
151
|
),
|
|
152
152
|
Option.bind("r", () => resolved(a)),
|
|
153
153
|
Option.map(({ r, values }) =>
|
|
154
|
-
Arr.
|
|
154
|
+
Arr.getSomes(values.map(a => Option.fromNullable(f(a as any, r)))),
|
|
155
155
|
),
|
|
156
156
|
)
|
|
157
157
|
|
|
@@ -2,7 +2,6 @@ import * as Chunk from "effect/Chunk"
|
|
|
2
2
|
import { Tag } from "effect/Context"
|
|
3
3
|
import * as Duration from "effect/Duration"
|
|
4
4
|
import { pipe } from "effect/Function"
|
|
5
|
-
import type { Cause } from "effect/Cause"
|
|
6
5
|
import * as Effect from "effect/Effect"
|
|
7
6
|
import * as Layer from "effect/Layer"
|
|
8
7
|
import * as Queue from "effect/Queue"
|
|
@@ -21,6 +20,7 @@ import type { InteractionBuilder } from "dfx/Interactions/index"
|
|
|
21
20
|
import { builder, Interaction } from "dfx/Interactions/index"
|
|
22
21
|
import type * as Discord from "dfx/types"
|
|
23
22
|
import * as EffectUtils from "dfx/utils/Effect"
|
|
23
|
+
import * as Schedule from "effect/Schedule"
|
|
24
24
|
|
|
25
25
|
export interface RunOpts {
|
|
26
26
|
sync?: boolean
|
|
@@ -112,55 +112,55 @@ export const run =
|
|
|
112
112
|
)
|
|
113
113
|
})
|
|
114
114
|
|
|
115
|
-
const makeRegistry =
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const register = <E>(ix: InteractionBuilder<never, E, never>) =>
|
|
124
|
-
Effect.flatMap(
|
|
125
|
-
Ref.updateAndGet(ref, _ => _.concat(ix as any)),
|
|
126
|
-
_ => Queue.offer(queue, _),
|
|
115
|
+
const makeRegistry = (options?: RunOpts) =>
|
|
116
|
+
Effect.gen(function* (_) {
|
|
117
|
+
const ref = yield* _(
|
|
118
|
+
Ref.make(builder as InteractionBuilder<never, never, never>),
|
|
119
|
+
)
|
|
120
|
+
const queue = yield* _(
|
|
121
|
+
Queue.sliding<InteractionBuilder<never, never, never>>(1),
|
|
127
122
|
)
|
|
128
123
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
pipe(
|
|
138
|
-
|
|
124
|
+
const register = <E>(ix: InteractionBuilder<never, E, never>) =>
|
|
125
|
+
Effect.flatMap(
|
|
126
|
+
Ref.updateAndGet(ref, _ => _.concat(ix as any)),
|
|
127
|
+
_ => Queue.offer(queue, _),
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
yield* _(
|
|
131
|
+
EffectUtils.foreverSwitch(Queue.take(queue), ix =>
|
|
132
|
+
pipe(
|
|
133
|
+
ix,
|
|
134
|
+
run(
|
|
135
|
+
Effect.catchAllCause(_ => Effect.logError("unhandled error", _)),
|
|
136
|
+
options,
|
|
137
|
+
),
|
|
138
|
+
Effect.delay(Duration.seconds(0.1)),
|
|
139
|
+
),
|
|
140
|
+
),
|
|
141
|
+
Effect.tapErrorCause(_ => Effect.logError("registry error", _)),
|
|
142
|
+
Effect.retry(
|
|
143
|
+
Schedule.exponential("1 seconds").pipe(
|
|
144
|
+
Schedule.union(Schedule.spaced("20 seconds")),
|
|
145
|
+
),
|
|
139
146
|
),
|
|
147
|
+
Effect.forkScoped,
|
|
140
148
|
)
|
|
141
149
|
|
|
142
|
-
|
|
143
|
-
})
|
|
150
|
+
return { register } as const
|
|
151
|
+
}).pipe(
|
|
152
|
+
Effect.annotateLogs({
|
|
153
|
+
package: "dfx",
|
|
154
|
+
service: "InteractionsRegistry",
|
|
155
|
+
}),
|
|
156
|
+
)
|
|
144
157
|
|
|
145
158
|
export interface InteractionsRegistry {
|
|
146
159
|
readonly register: <E>(
|
|
147
160
|
ix: InteractionBuilder<never, E, never>,
|
|
148
161
|
) => Effect.Effect<never, never, void>
|
|
149
|
-
|
|
150
|
-
readonly run: <R, E>(
|
|
151
|
-
onError: (
|
|
152
|
-
_: Cause<DiscordRESTError | DefinitionNotFound>,
|
|
153
|
-
) => Effect.Effect<R, E, void>,
|
|
154
|
-
opts?: RunOpts,
|
|
155
|
-
) => Effect.Effect<
|
|
156
|
-
DiscordREST | DiscordGateway | Exclude<R, Discord.Interaction>,
|
|
157
|
-
DiscordRESTError | Http.error.ResponseError | E,
|
|
158
|
-
never
|
|
159
|
-
>
|
|
160
162
|
}
|
|
161
163
|
|
|
162
164
|
export const InteractionsRegistry = Tag<InteractionsRegistry>()
|
|
163
|
-
export const InteractionsRegistryLive =
|
|
164
|
-
InteractionsRegistry,
|
|
165
|
-
makeRegistry,
|
|
166
|
-
)
|
|
165
|
+
export const InteractionsRegistryLive = (options?: RunOpts) =>
|
|
166
|
+
Layer.scoped(InteractionsRegistry, makeRegistry(options))
|
package/src/gateway.ts
CHANGED
|
@@ -14,8 +14,6 @@ import * as SendEvent from "dfx/DiscordGateway/Shard/sendEvents"
|
|
|
14
14
|
import * as ShardStore from "dfx/DiscordGateway/ShardStore"
|
|
15
15
|
import { LiveMemoryShardStore } from "dfx/DiscordGateway/ShardStore"
|
|
16
16
|
import * as WS from "dfx/DiscordGateway/WS"
|
|
17
|
-
import { InteractionsRegistryLive } from "dfx/gateway"
|
|
18
|
-
import type { InteractionsRegistry } from "dfx/gateway"
|
|
19
17
|
import type { RateLimiter } from "dfx/RateLimit"
|
|
20
18
|
import { LiveMemoryRateLimitStore, LiveRateLimiter } from "dfx/RateLimit"
|
|
21
19
|
|
|
@@ -30,21 +28,18 @@ export {
|
|
|
30
28
|
export { CachePrelude, DiscordWS, SendEvent, Shard, ShardStore, WS }
|
|
31
29
|
|
|
32
30
|
export const MemoryRateLimit = Layer.provide(
|
|
33
|
-
LiveMemoryRateLimitStore,
|
|
34
31
|
LiveRateLimiter,
|
|
32
|
+
LiveMemoryRateLimitStore,
|
|
35
33
|
)
|
|
36
34
|
|
|
37
|
-
export const MemoryBot = Layer.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
),
|
|
43
|
-
Layer.
|
|
44
|
-
|
|
45
|
-
MemoryRateLimit,
|
|
46
|
-
InteractionsRegistryLive,
|
|
47
|
-
),
|
|
35
|
+
export const MemoryBot = Layer.mergeAll(
|
|
36
|
+
MemoryRateLimit,
|
|
37
|
+
LiveDiscordGateway,
|
|
38
|
+
).pipe(
|
|
39
|
+
Layer.provideMerge(LiveDiscordREST),
|
|
40
|
+
Layer.provide(LiveJsonDiscordWSCodec),
|
|
41
|
+
Layer.provide(LiveMemoryRateLimitStore),
|
|
42
|
+
Layer.provide(LiveMemoryShardStore),
|
|
48
43
|
)
|
|
49
44
|
|
|
50
45
|
export const gatewayLayer = (
|
|
@@ -54,7 +49,6 @@ export const gatewayLayer = (
|
|
|
54
49
|
ConfigError.ConfigError,
|
|
55
50
|
| RateLimiter
|
|
56
51
|
| Log.Log
|
|
57
|
-
| InteractionsRegistry
|
|
58
52
|
| DiscordREST
|
|
59
53
|
| DiscordGateway
|
|
60
54
|
| DiscordConfig.DiscordConfig
|
|
@@ -65,7 +59,7 @@ export const gatewayLayer = (
|
|
|
65
59
|
Effect.map(config => {
|
|
66
60
|
const LiveLog = config.debug ? Log.LiveLogDebug : Log.LiveLog
|
|
67
61
|
const LiveConfig = Layer.succeed(DiscordConfig.DiscordConfig, config)
|
|
68
|
-
return Layer.provideMerge(Layer.merge(LiveLog, LiveConfig)
|
|
62
|
+
return Layer.provideMerge(MemoryBot, Layer.merge(LiveLog, LiveConfig))
|
|
69
63
|
}),
|
|
70
64
|
),
|
|
71
65
|
)
|