dfx 0.86.0 → 0.87.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/driver.d.ts +15 -15
- package/Cache/driver.d.ts.map +1 -1
- package/Cache/memory.d.ts +2 -2
- package/Cache/memory.d.ts.map +1 -1
- package/Cache/memory.js.map +1 -1
- package/Cache/memoryTTL.d.ts +2 -2
- package/Cache/memoryTTL.js.map +1 -1
- package/Cache/prelude.d.ts +13 -16
- package/Cache/prelude.d.ts.map +1 -1
- package/Cache/prelude.js.map +1 -1
- package/Cache.d.ts +25 -25
- package/Cache.d.ts.map +1 -1
- package/Cache.js.map +1 -1
- package/DiscordConfig.d.ts +3 -4
- package/DiscordConfig.d.ts.map +1 -1
- package/DiscordConfig.js +1 -1
- package/DiscordConfig.js.map +1 -1
- package/DiscordGateway/DiscordWS.d.ts +10 -11
- package/DiscordGateway/DiscordWS.d.ts.map +1 -1
- package/DiscordGateway/DiscordWS.js +2 -2
- package/DiscordGateway/DiscordWS.js.map +1 -1
- package/DiscordGateway/Messaging.d.ts +12 -13
- package/DiscordGateway/Messaging.d.ts.map +1 -1
- package/DiscordGateway/Messaging.js +1 -1
- package/DiscordGateway/Messaging.js.map +1 -1
- package/DiscordGateway/Shard/heartbeats.d.ts +1 -1
- package/DiscordGateway/Shard/heartbeats.d.ts.map +1 -1
- package/DiscordGateway/Shard/heartbeats.js.map +1 -1
- package/DiscordGateway/Shard/identify.d.ts +1 -1
- package/DiscordGateway/Shard/identify.d.ts.map +1 -1
- package/DiscordGateway/Shard/identify.js.map +1 -1
- package/DiscordGateway/Shard/invalidSession.d.ts +1 -1
- package/DiscordGateway/Shard/invalidSession.d.ts.map +1 -1
- package/DiscordGateway/Shard/utils.d.ts +2 -2
- package/DiscordGateway/Shard/utils.d.ts.map +1 -1
- package/DiscordGateway/Shard/utils.js.map +1 -1
- package/DiscordGateway/Shard.d.ts +10 -11
- package/DiscordGateway/Shard.d.ts.map +1 -1
- package/DiscordGateway/Shard.js +1 -1
- package/DiscordGateway/Shard.js.map +1 -1
- package/DiscordGateway/ShardStore.d.ts +5 -6
- package/DiscordGateway/ShardStore.d.ts.map +1 -1
- package/DiscordGateway/ShardStore.js +1 -1
- package/DiscordGateway/ShardStore.js.map +1 -1
- package/DiscordGateway/Sharder.d.ts +3 -4
- package/DiscordGateway/Sharder.d.ts.map +1 -1
- package/DiscordGateway/Sharder.js +1 -1
- package/DiscordGateway/Sharder.js.map +1 -1
- package/DiscordGateway/WS.d.ts +7 -8
- package/DiscordGateway/WS.d.ts.map +1 -1
- package/DiscordGateway/WS.js +1 -1
- package/DiscordGateway/WS.js.map +1 -1
- package/DiscordGateway.d.ts +8 -9
- package/DiscordGateway.d.ts.map +1 -1
- package/DiscordGateway.js +1 -1
- package/DiscordGateway.js.map +1 -1
- package/DiscordREST/types.d.ts +2 -2
- package/DiscordREST/types.d.ts.map +1 -1
- package/DiscordREST.d.ts +3 -4
- package/DiscordREST.d.ts.map +1 -1
- package/DiscordREST.js +1 -1
- package/DiscordREST.js.map +1 -1
- package/Helpers/permissions.d.ts +3 -3
- package/Helpers/permissions.d.ts.map +1 -1
- package/Interactions/builder.d.ts +12 -12
- package/Interactions/builder.d.ts.map +1 -1
- package/Interactions/context.d.ts +22 -23
- package/Interactions/context.d.ts.map +1 -1
- package/Interactions/context.js +6 -6
- package/Interactions/context.js.map +1 -1
- package/Interactions/definitions.d.ts +23 -25
- package/Interactions/definitions.d.ts.map +1 -1
- package/Interactions/gateway.d.ts +5 -6
- package/Interactions/gateway.d.ts.map +1 -1
- package/Interactions/gateway.js +1 -1
- package/Interactions/gateway.js.map +1 -1
- package/Interactions/handlers.d.ts +2 -2
- package/Interactions/handlers.d.ts.map +1 -1
- package/Interactions/handlers.js.map +1 -1
- package/Interactions/index.d.ts +5 -5
- package/Interactions/utils.d.ts +26 -26
- package/Interactions/utils.js.map +1 -1
- package/Interactions/webhook.d.ts +7 -8
- package/Interactions/webhook.d.ts.map +1 -1
- package/Interactions/webhook.js +1 -1
- package/Interactions/webhook.js.map +1 -1
- package/RateLimit.d.ts +11 -12
- package/RateLimit.d.ts.map +1 -1
- package/RateLimit.js +2 -2
- package/RateLimit.js.map +1 -1
- package/gateway.d.ts +2 -2
- package/mjs/Cache/memory.mjs.map +1 -1
- package/mjs/Cache/memoryTTL.mjs.map +1 -1
- package/mjs/Cache/prelude.mjs.map +1 -1
- package/mjs/Cache.mjs.map +1 -1
- package/mjs/DiscordConfig.mjs +2 -2
- package/mjs/DiscordConfig.mjs.map +1 -1
- package/mjs/DiscordGateway/DiscordWS.mjs +3 -3
- package/mjs/DiscordGateway/DiscordWS.mjs.map +1 -1
- package/mjs/DiscordGateway/Messaging.mjs +2 -2
- package/mjs/DiscordGateway/Messaging.mjs.map +1 -1
- package/mjs/DiscordGateway/Shard/heartbeats.mjs.map +1 -1
- package/mjs/DiscordGateway/Shard/identify.mjs.map +1 -1
- package/mjs/DiscordGateway/Shard/utils.mjs.map +1 -1
- package/mjs/DiscordGateway/Shard.mjs +2 -2
- package/mjs/DiscordGateway/Shard.mjs.map +1 -1
- package/mjs/DiscordGateway/ShardStore.mjs +2 -2
- package/mjs/DiscordGateway/ShardStore.mjs.map +1 -1
- package/mjs/DiscordGateway/Sharder.mjs +2 -2
- package/mjs/DiscordGateway/Sharder.mjs.map +1 -1
- package/mjs/DiscordGateway/WS.mjs +2 -2
- package/mjs/DiscordGateway/WS.mjs.map +1 -1
- package/mjs/DiscordGateway.mjs +2 -2
- package/mjs/DiscordGateway.mjs.map +1 -1
- package/mjs/DiscordREST.mjs +2 -2
- package/mjs/DiscordREST.mjs.map +1 -1
- package/mjs/Interactions/context.mjs +7 -7
- package/mjs/Interactions/context.mjs.map +1 -1
- package/mjs/Interactions/gateway.mjs +2 -2
- package/mjs/Interactions/gateway.mjs.map +1 -1
- package/mjs/Interactions/handlers.mjs.map +1 -1
- package/mjs/Interactions/utils.mjs.map +1 -1
- package/mjs/Interactions/webhook.mjs +2 -2
- package/mjs/Interactions/webhook.mjs.map +1 -1
- package/mjs/RateLimit.mjs +3 -3
- package/mjs/RateLimit.mjs.map +1 -1
- package/mjs/version.mjs +1 -1
- package/package.json +4 -4
- package/src/Cache/driver.ts +15 -15
- package/src/Cache/memory.ts +2 -10
- package/src/Cache/memoryTTL.ts +4 -4
- package/src/Cache/prelude.ts +25 -24
- package/src/Cache.ts +31 -31
- package/src/DiscordConfig.ts +4 -4
- package/src/DiscordGateway/DiscordWS.ts +5 -5
- package/src/DiscordGateway/Messaging.ts +9 -8
- package/src/DiscordGateway/Shard/heartbeats.ts +2 -2
- package/src/DiscordGateway/Shard/identify.ts +2 -6
- package/src/DiscordGateway/Shard/invalidSession.ts +1 -1
- package/src/DiscordGateway/Shard/utils.ts +7 -11
- package/src/DiscordGateway/Shard.ts +2 -2
- package/src/DiscordGateway/ShardStore.ts +5 -5
- package/src/DiscordGateway/Sharder.ts +7 -4
- package/src/DiscordGateway/WS.ts +8 -8
- package/src/DiscordGateway.ts +8 -12
- package/src/DiscordREST/types.ts +2 -6
- package/src/DiscordREST.ts +5 -9
- package/src/Helpers/permissions.ts +1 -1
- package/src/Interactions/builder.ts +11 -11
- package/src/Interactions/context.ts +28 -32
- package/src/Interactions/definitions.ts +34 -38
- package/src/Interactions/gateway.ts +6 -14
- package/src/Interactions/handlers.ts +3 -7
- package/src/Interactions/utils.ts +6 -6
- package/src/Interactions/webhook.ts +15 -19
- package/src/RateLimit.ts +9 -9
- package/src/utils/Effect.ts +9 -9
- package/src/version.ts +1 -1
- package/utils/Effect.d.ts +2 -2
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/webhooks.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dfx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.87.0",
|
|
4
4
|
"description": "Effect-TS discord library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"ws": "^8.16.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@effect/platform": "^0.
|
|
43
|
-
"effect": "^2.
|
|
42
|
+
"@effect/platform": "^0.44.0",
|
|
43
|
+
"effect": "^2.3.0"
|
|
44
44
|
},
|
|
45
45
|
"optionalDependencies": {
|
|
46
46
|
"bufferutil": "^4.0.8",
|
|
@@ -48,6 +48,6 @@
|
|
|
48
48
|
"utf-8-validate": "^6.0.3",
|
|
49
49
|
"zlib-sync": "^0.1.9"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "25dc1203ca0dcf3b1cc04753885b752c72e08105",
|
|
52
52
|
"main": "./index.js"
|
|
53
53
|
}
|
package/src/Cache/driver.ts
CHANGED
|
@@ -2,42 +2,42 @@ import type * as Option from "effect/Option"
|
|
|
2
2
|
import type * as Effect from "effect/Effect"
|
|
3
3
|
|
|
4
4
|
export interface ParentCacheDriver<E, T> {
|
|
5
|
-
readonly size: Effect.Effect<
|
|
6
|
-
sizeForParent: (parentId: string) => Effect.Effect<
|
|
5
|
+
readonly size: Effect.Effect<number, E>
|
|
6
|
+
sizeForParent: (parentId: string) => Effect.Effect<number, E>
|
|
7
7
|
get: (
|
|
8
8
|
parentId: string,
|
|
9
9
|
resourceId: string,
|
|
10
|
-
) => Effect.Effect<
|
|
10
|
+
) => Effect.Effect<Option.Option<T>, E>
|
|
11
11
|
getForParent: (
|
|
12
12
|
parentId: string,
|
|
13
|
-
) => Effect.Effect<
|
|
13
|
+
) => Effect.Effect<Option.Option<ReadonlyMap<string, T>>, E>
|
|
14
14
|
set: (
|
|
15
15
|
parentId: string,
|
|
16
16
|
resourceId: string,
|
|
17
17
|
resource: T,
|
|
18
|
-
) => Effect.Effect<
|
|
18
|
+
) => Effect.Effect<void, E>
|
|
19
19
|
delete: (
|
|
20
20
|
parentId: string,
|
|
21
21
|
resourceId: string,
|
|
22
|
-
) => Effect.Effect<
|
|
23
|
-
parentDelete: (parentId: string) => Effect.Effect<
|
|
22
|
+
) => Effect.Effect<void, E>
|
|
23
|
+
parentDelete: (parentId: string) => Effect.Effect<void, E>
|
|
24
24
|
refreshTTL: (
|
|
25
25
|
parentId: string,
|
|
26
26
|
resourceId: string,
|
|
27
|
-
) => Effect.Effect<
|
|
28
|
-
readonly run: Effect.Effect<never, E
|
|
27
|
+
) => Effect.Effect<void, E>
|
|
28
|
+
readonly run: Effect.Effect<never, E>
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export const createParentDriver = <E, T>(driver: ParentCacheDriver<E, T>) =>
|
|
32
32
|
driver
|
|
33
33
|
|
|
34
34
|
export interface CacheDriver<E, T> {
|
|
35
|
-
readonly size: Effect.Effect<
|
|
36
|
-
get: (resourceId: string) => Effect.Effect<
|
|
37
|
-
set: (resourceId: string, resource: T) => Effect.Effect<
|
|
38
|
-
delete: (resourceId: string) => Effect.Effect<
|
|
39
|
-
refreshTTL: (resourceId: string) => Effect.Effect<
|
|
40
|
-
readonly run: Effect.Effect<never, E
|
|
35
|
+
readonly size: Effect.Effect<number, E>
|
|
36
|
+
get: (resourceId: string) => Effect.Effect<Option.Option<T>, E>
|
|
37
|
+
set: (resourceId: string, resource: T) => Effect.Effect<void, E>
|
|
38
|
+
delete: (resourceId: string) => Effect.Effect<void, E>
|
|
39
|
+
refreshTTL: (resourceId: string) => Effect.Effect<void, E>
|
|
40
|
+
readonly run: Effect.Effect<never, E>
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export const createDriver = <E, T>(driver: CacheDriver<E, T>) => driver
|
package/src/Cache/memory.ts
CHANGED
|
@@ -3,11 +3,7 @@ import * as Effect from "effect/Effect"
|
|
|
3
3
|
import type { CacheDriver, ParentCacheDriver } from "dfx/Cache/driver"
|
|
4
4
|
import { createDriver, createParentDriver } from "dfx/Cache/driver"
|
|
5
5
|
|
|
6
|
-
export const createWithParent = <T>(): Effect.Effect<
|
|
7
|
-
never,
|
|
8
|
-
never,
|
|
9
|
-
ParentCacheDriver<never, T>
|
|
10
|
-
> =>
|
|
6
|
+
export const createWithParent = <T>(): Effect.Effect<ParentCacheDriver<never, T>> =>
|
|
11
7
|
Effect.sync(() => {
|
|
12
8
|
const map = new Map<string, Map<string, T>>()
|
|
13
9
|
|
|
@@ -56,11 +52,7 @@ export const createWithParent = <T>(): Effect.Effect<
|
|
|
56
52
|
})
|
|
57
53
|
})
|
|
58
54
|
|
|
59
|
-
export const create = <T>(): Effect.Effect<
|
|
60
|
-
never,
|
|
61
|
-
never,
|
|
62
|
-
CacheDriver<never, T>
|
|
63
|
-
> =>
|
|
55
|
+
export const create = <T>(): Effect.Effect<CacheDriver<never, T>> =>
|
|
64
56
|
Effect.sync(() => {
|
|
65
57
|
const map = new Map<string, T>()
|
|
66
58
|
|
package/src/Cache/memoryTTL.ts
CHANGED
|
@@ -134,12 +134,12 @@ const make = <T>({
|
|
|
134
134
|
|
|
135
135
|
export const create = <T>(
|
|
136
136
|
opts: MemoryTTLOpts,
|
|
137
|
-
): Effect.Effect<
|
|
137
|
+
): Effect.Effect<CacheDriver<never, T>> =>
|
|
138
138
|
Effect.sync(() => make<T>(opts))
|
|
139
139
|
|
|
140
140
|
export const createWithParent = <T>(
|
|
141
141
|
opts: MemoryTTLOpts,
|
|
142
|
-
): Effect.Effect<
|
|
142
|
+
): Effect.Effect<ParentCacheDriver<never, T>> =>
|
|
143
143
|
Effect.sync(() => {
|
|
144
144
|
const store = make<T>(opts)
|
|
145
145
|
const parentIds = new Map<string, Set<string>>()
|
|
@@ -204,7 +204,7 @@ export const createWithParent = <T>(
|
|
|
204
204
|
const ids = parentIds.get(parentId)
|
|
205
205
|
parentIds.delete(parentId)
|
|
206
206
|
|
|
207
|
-
const effects: Array<Effect.Effect<
|
|
207
|
+
const effects: Array<Effect.Effect<void>> = []
|
|
208
208
|
if (ids) {
|
|
209
209
|
ids.forEach(id => {
|
|
210
210
|
effects.push(store.delete(id))
|
|
@@ -218,5 +218,5 @@ export const createWithParent = <T>(
|
|
|
218
218
|
}),
|
|
219
219
|
|
|
220
220
|
run: store.run,
|
|
221
|
-
})
|
|
221
|
+
});
|
|
222
222
|
})
|
package/src/Cache/prelude.ts
CHANGED
|
@@ -18,15 +18,11 @@ import type * as Discord from "dfx/types"
|
|
|
18
18
|
|
|
19
19
|
export interface OptsWithParentOptions<E, A> {
|
|
20
20
|
readonly id: (a: A) => string
|
|
21
|
-
readonly fromParent: Stream.Stream<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
>
|
|
26
|
-
readonly create: Stream.Stream<never, E, [parentId: string, resource: A]>
|
|
27
|
-
readonly update: Stream.Stream<never, E, [parentId: string, resource: A]>
|
|
28
|
-
readonly remove: Stream.Stream<never, E, [parentId: string, id: string]>
|
|
29
|
-
readonly parentRemove: Stream.Stream<never, E, string>
|
|
21
|
+
readonly fromParent: Stream.Stream<[parentId: string, resources: Array<A>], E>
|
|
22
|
+
readonly create: Stream.Stream<[parentId: string, resource: A], E>
|
|
23
|
+
readonly update: Stream.Stream<[parentId: string, resource: A], E>
|
|
24
|
+
readonly remove: Stream.Stream<[parentId: string, id: string], E>
|
|
25
|
+
readonly parentRemove: Stream.Stream<string, E>
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
export const opsWithParent = <E, T>({
|
|
@@ -36,7 +32,7 @@ export const opsWithParent = <E, T>({
|
|
|
36
32
|
parentRemove,
|
|
37
33
|
remove,
|
|
38
34
|
update,
|
|
39
|
-
}: OptsWithParentOptions<E, T>): Stream.Stream<
|
|
35
|
+
}: OptsWithParentOptions<E, T>): Stream.Stream<ParentCacheOp<T>, E> => {
|
|
40
36
|
const fromParentOps = Stream.flatMap(fromParent, ([parentId, a]) =>
|
|
41
37
|
Stream.fromIterable(
|
|
42
38
|
a.map(
|
|
@@ -96,9 +92,9 @@ export const opsWithParent = <E, T>({
|
|
|
96
92
|
|
|
97
93
|
export interface OpsOptions<E, A> {
|
|
98
94
|
id: (a: A) => string
|
|
99
|
-
create: Stream.Stream<
|
|
100
|
-
update: Stream.Stream<
|
|
101
|
-
remove: Stream.Stream<
|
|
95
|
+
create: Stream.Stream<A, E>
|
|
96
|
+
update: Stream.Stream<A, E>
|
|
97
|
+
remove: Stream.Stream<string, E>
|
|
102
98
|
}
|
|
103
99
|
|
|
104
100
|
export const ops = <E, T>({
|
|
@@ -106,7 +102,7 @@ export const ops = <E, T>({
|
|
|
106
102
|
id,
|
|
107
103
|
remove,
|
|
108
104
|
update,
|
|
109
|
-
}: OpsOptions<E, T>): Stream.Stream<
|
|
105
|
+
}: OpsOptions<E, T>): Stream.Stream<CacheOp<T>, E> => {
|
|
110
106
|
const createOps = Stream.map(
|
|
111
107
|
create,
|
|
112
108
|
(resource): CacheOp<T> => ({
|
|
@@ -137,11 +133,11 @@ export const ops = <E, T>({
|
|
|
137
133
|
}
|
|
138
134
|
|
|
139
135
|
export const guilds = <RM, EM, E>(
|
|
140
|
-
makeDriver: Effect.Effect<
|
|
136
|
+
makeDriver: Effect.Effect<CacheDriver<E, Discord.Guild>, EM, RM>,
|
|
141
137
|
): Effect.Effect<
|
|
142
|
-
|
|
138
|
+
Cache<E, ResponseError | DiscordRESTError, Discord.Guild>,
|
|
143
139
|
EM,
|
|
144
|
-
|
|
140
|
+
RM | DiscordGateway | DiscordREST | Scope.Scope
|
|
145
141
|
> =>
|
|
146
142
|
Effect.gen(function* (_) {
|
|
147
143
|
const driver = yield* _(makeDriver)
|
|
@@ -170,16 +166,16 @@ export const guilds = <RM, EM, E>(
|
|
|
170
166
|
})
|
|
171
167
|
|
|
172
168
|
export const channels = <RM, EM, E>(
|
|
173
|
-
makeDriver: Effect.Effect<
|
|
169
|
+
makeDriver: Effect.Effect<ParentCacheDriver<E, Discord.Channel>, EM, RM>,
|
|
174
170
|
): Effect.Effect<
|
|
175
|
-
DiscordGateway | DiscordREST | RM | Scope.Scope,
|
|
176
|
-
EM,
|
|
177
171
|
ParentCache<
|
|
178
172
|
E,
|
|
179
173
|
ResponseError | DiscordRESTError,
|
|
180
174
|
ResponseError | DiscordRESTError,
|
|
181
175
|
Discord.Channel
|
|
182
|
-
|
|
176
|
+
>,
|
|
177
|
+
EM,
|
|
178
|
+
DiscordGateway | DiscordREST | RM | Scope.Scope
|
|
183
179
|
> =>
|
|
184
180
|
Effect.gen(function* (_) {
|
|
185
181
|
const driver = yield* _(makeDriver)
|
|
@@ -224,11 +220,16 @@ export const channels = <RM, EM, E>(
|
|
|
224
220
|
})
|
|
225
221
|
|
|
226
222
|
export const roles = <RM, EM, E>(
|
|
227
|
-
makeDriver: Effect.Effect<
|
|
223
|
+
makeDriver: Effect.Effect<ParentCacheDriver<E, Discord.Role>, EM, RM>,
|
|
228
224
|
): Effect.Effect<
|
|
229
|
-
|
|
225
|
+
ParentCache<
|
|
226
|
+
E,
|
|
227
|
+
CacheMissError,
|
|
228
|
+
ResponseError | DiscordRESTError,
|
|
229
|
+
Discord.Role
|
|
230
|
+
>,
|
|
230
231
|
EM,
|
|
231
|
-
|
|
232
|
+
DiscordGateway | DiscordREST | RM | Scope.Scope
|
|
232
233
|
> =>
|
|
233
234
|
Effect.gen(function* (_) {
|
|
234
235
|
const driver = yield* _(makeDriver)
|
package/src/Cache.ts
CHANGED
|
@@ -34,36 +34,36 @@ export interface ParentCache<EDriver, EMiss, EPMiss, A> {
|
|
|
34
34
|
readonly get: (
|
|
35
35
|
parentId: string,
|
|
36
36
|
id: string,
|
|
37
|
-
) => Effect.Effect<
|
|
38
|
-
readonly put: (_: A) => Effect.Effect<
|
|
37
|
+
) => Effect.Effect<A, EDriver | EMiss>
|
|
38
|
+
readonly put: (_: A) => Effect.Effect<void, EDriver | EMiss>
|
|
39
39
|
readonly update: <R, E>(
|
|
40
40
|
parentId: string,
|
|
41
41
|
id: string,
|
|
42
|
-
f: (_: A) => Effect.Effect<
|
|
43
|
-
) => Effect.Effect<
|
|
42
|
+
f: (_: A) => Effect.Effect<A, E, R>,
|
|
43
|
+
) => Effect.Effect<A, EDriver | EMiss | E, R>
|
|
44
44
|
readonly getForParent: (
|
|
45
45
|
parentId: string,
|
|
46
|
-
) => Effect.Effect<
|
|
47
|
-
readonly size: Effect.Effect<
|
|
46
|
+
) => Effect.Effect<ReadonlyMap<string, A>, EDriver | EPMiss>
|
|
47
|
+
readonly size: Effect.Effect<number, EDriver>
|
|
48
48
|
readonly sizeForParent: (
|
|
49
49
|
parentId: string,
|
|
50
|
-
) => Effect.Effect<
|
|
50
|
+
) => Effect.Effect<number, EDriver>
|
|
51
51
|
readonly set: (
|
|
52
52
|
parentId: string,
|
|
53
53
|
resourceId: string,
|
|
54
54
|
resource: A,
|
|
55
|
-
) => Effect.Effect<
|
|
55
|
+
) => Effect.Effect<void, EDriver>
|
|
56
56
|
readonly delete: (
|
|
57
57
|
parentId: string,
|
|
58
58
|
resourceId: string,
|
|
59
|
-
) => Effect.Effect<
|
|
59
|
+
) => Effect.Effect<void, EDriver>
|
|
60
60
|
readonly parentDelete: (
|
|
61
61
|
parentId: string,
|
|
62
|
-
) => Effect.Effect<
|
|
62
|
+
) => Effect.Effect<void, EDriver>
|
|
63
63
|
readonly refreshTTL: (
|
|
64
64
|
parentId: string,
|
|
65
65
|
resourceId: string,
|
|
66
|
-
) => Effect.Effect<
|
|
66
|
+
) => Effect.Effect<void, EDriver>
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export const makeWithParent = <EOps, EDriver, EMiss, EPMiss, A>({
|
|
@@ -74,19 +74,19 @@ export const makeWithParent = <EOps, EDriver, EMiss, EPMiss, A>({
|
|
|
74
74
|
ops = Stream.empty,
|
|
75
75
|
}: {
|
|
76
76
|
driver: ParentCacheDriver<EDriver, A>
|
|
77
|
-
ops?: Stream.Stream<
|
|
77
|
+
ops?: Stream.Stream<ParentCacheOp<A>, EOps>
|
|
78
78
|
id: (
|
|
79
79
|
_: A,
|
|
80
|
-
) => Effect.Effect<
|
|
81
|
-
onMiss: (parentId: string, id: string) => Effect.Effect<
|
|
80
|
+
) => Effect.Effect<readonly [parentId: string, id: string], EMiss>
|
|
81
|
+
onMiss: (parentId: string, id: string) => Effect.Effect<A, EMiss>
|
|
82
82
|
onParentMiss: (
|
|
83
83
|
parentId: string,
|
|
84
|
-
) => Effect.Effect<
|
|
85
|
-
}): Effect.Effect<
|
|
84
|
+
) => Effect.Effect<Array<[id: string, resource: A]>, EPMiss>
|
|
85
|
+
}): Effect.Effect<ParentCache<EDriver, EMiss, EPMiss, A>, never, Scope.Scope> =>
|
|
86
86
|
Effect.gen(function* (_) {
|
|
87
87
|
yield* _(
|
|
88
88
|
Stream.runDrain(
|
|
89
|
-
Stream.tap(ops, (op): Effect.Effect<
|
|
89
|
+
Stream.tap(ops, (op): Effect.Effect<void, EDriver> => {
|
|
90
90
|
switch (op.op) {
|
|
91
91
|
case "create":
|
|
92
92
|
case "update":
|
|
@@ -129,7 +129,7 @@ export const makeWithParent = <EOps, EDriver, EMiss, EPMiss, A>({
|
|
|
129
129
|
const update = <R, E>(
|
|
130
130
|
parentId: string,
|
|
131
131
|
id: string,
|
|
132
|
-
f: (_: A) => Effect.Effect<
|
|
132
|
+
f: (_: A) => Effect.Effect<A, E, R>,
|
|
133
133
|
) =>
|
|
134
134
|
get(parentId, id).pipe(
|
|
135
135
|
Effect.flatMap(f),
|
|
@@ -171,21 +171,21 @@ export const makeWithParent = <EOps, EDriver, EMiss, EPMiss, A>({
|
|
|
171
171
|
)
|
|
172
172
|
|
|
173
173
|
export interface Cache<EDriver, EMiss, A> {
|
|
174
|
-
readonly get: (id: string) => Effect.Effect<
|
|
175
|
-
readonly put: (_: A) => Effect.Effect<
|
|
174
|
+
readonly get: (id: string) => Effect.Effect<A, EDriver | EMiss>
|
|
175
|
+
readonly put: (_: A) => Effect.Effect<void, EDriver>
|
|
176
176
|
readonly update: <R, E>(
|
|
177
177
|
id: string,
|
|
178
|
-
f: (_: A) => Effect.Effect<
|
|
179
|
-
) => Effect.Effect<
|
|
180
|
-
readonly size: Effect.Effect<
|
|
178
|
+
f: (_: A) => Effect.Effect<A, E, R>,
|
|
179
|
+
) => Effect.Effect<A, EDriver | EMiss | E, R>
|
|
180
|
+
readonly size: Effect.Effect<number, EDriver>
|
|
181
181
|
readonly set: (
|
|
182
182
|
resourceId: string,
|
|
183
183
|
resource: A,
|
|
184
|
-
) => Effect.Effect<
|
|
185
|
-
readonly delete: (resourceId: string) => Effect.Effect<
|
|
184
|
+
) => Effect.Effect<void, EDriver>
|
|
185
|
+
readonly delete: (resourceId: string) => Effect.Effect<void, EDriver>
|
|
186
186
|
readonly refreshTTL: (
|
|
187
187
|
resourceId: string,
|
|
188
|
-
) => Effect.Effect<
|
|
188
|
+
) => Effect.Effect<void, EDriver>
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
export const make = <EOps, EDriver, EMiss, A>({
|
|
@@ -195,14 +195,14 @@ export const make = <EOps, EDriver, EMiss, A>({
|
|
|
195
195
|
ops = Stream.empty,
|
|
196
196
|
}: {
|
|
197
197
|
driver: CacheDriver<EDriver, A>
|
|
198
|
-
ops?: Stream.Stream<
|
|
198
|
+
ops?: Stream.Stream<CacheOp<A>, EOps>
|
|
199
199
|
id: (_: A) => string
|
|
200
|
-
onMiss: (id: string) => Effect.Effect<
|
|
201
|
-
}): Effect.Effect<
|
|
200
|
+
onMiss: (id: string) => Effect.Effect<A, EMiss>
|
|
201
|
+
}): Effect.Effect<Cache<EDriver, EMiss, A>, never, Scope.Scope> =>
|
|
202
202
|
Effect.gen(function* (_) {
|
|
203
203
|
yield* _(
|
|
204
204
|
Stream.runDrain(
|
|
205
|
-
Stream.tap(ops, (op): Effect.Effect<
|
|
205
|
+
Stream.tap(ops, (op): Effect.Effect<void, EDriver> => {
|
|
206
206
|
switch (op.op) {
|
|
207
207
|
case "create":
|
|
208
208
|
case "update":
|
|
@@ -238,7 +238,7 @@ export const make = <EOps, EDriver, EMiss, A>({
|
|
|
238
238
|
|
|
239
239
|
const put = (_: A) => driver.set(id(_), _)
|
|
240
240
|
|
|
241
|
-
const update = <R, E>(id: string, f: (_: A) => Effect.Effect<
|
|
241
|
+
const update = <R, E>(id: string, f: (_: A) => Effect.Effect<A, E, R>) =>
|
|
242
242
|
get(id).pipe(
|
|
243
243
|
Effect.flatMap(f),
|
|
244
244
|
Effect.tap(_ => driver.set(id, _)),
|
package/src/DiscordConfig.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GenericTag } from "effect/Context"
|
|
2
2
|
import * as Duration from "effect/Duration"
|
|
3
3
|
import * as Config from "effect/Config"
|
|
4
4
|
import type * as ConfigError from "effect/ConfigError"
|
|
@@ -30,7 +30,7 @@ export interface DiscordConfigService {
|
|
|
30
30
|
readonly identifyRateLimit: readonly [window: number, limit: number]
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
export const DiscordConfig =
|
|
33
|
+
export const DiscordConfig = GenericTag<DiscordConfig, DiscordConfigService>(
|
|
34
34
|
"dfx/DiscordConfig",
|
|
35
35
|
)
|
|
36
36
|
|
|
@@ -64,10 +64,10 @@ export const make = ({
|
|
|
64
64
|
|
|
65
65
|
export const layer = (
|
|
66
66
|
opts: MakeOpts,
|
|
67
|
-
): Layer.Layer<
|
|
67
|
+
): Layer.Layer<DiscordConfig> =>
|
|
68
68
|
Layer.succeed(DiscordConfig, make(opts))
|
|
69
69
|
|
|
70
70
|
export const layerConfig = (
|
|
71
71
|
_: Config.Config.Wrap<MakeOpts>,
|
|
72
|
-
): Layer.Layer<
|
|
72
|
+
): Layer.Layer<DiscordConfig, ConfigError.ConfigError> =>
|
|
73
73
|
Layer.effect(DiscordConfig, Effect.map(Config.unwrap(_), make))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GenericTag } from "effect/Context"
|
|
2
2
|
import * as Effect from "effect/Effect"
|
|
3
3
|
import * as Layer from "effect/Layer"
|
|
4
4
|
import * as Ref from "effect/Ref"
|
|
@@ -12,8 +12,8 @@ export interface OpenOpts {
|
|
|
12
12
|
url?: string
|
|
13
13
|
version?: number
|
|
14
14
|
encoding?: DiscordWSCodec
|
|
15
|
-
outbound: Effect.Effect<
|
|
16
|
-
onConnecting?: Effect.Effect<
|
|
15
|
+
outbound: Effect.Effect<Message>
|
|
16
|
+
onConnecting?: Effect.Effect<void>
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export interface DiscordWSCodecService {
|
|
@@ -24,7 +24,7 @@ export interface DiscordWSCodecService {
|
|
|
24
24
|
export interface DiscordWSCodec {
|
|
25
25
|
readonly _: unique symbol
|
|
26
26
|
}
|
|
27
|
-
export const DiscordWSCodec =
|
|
27
|
+
export const DiscordWSCodec = GenericTag<DiscordWSCodec, DiscordWSCodecService>(
|
|
28
28
|
"dfx/DiscordGateway/DiscordWS/Codec",
|
|
29
29
|
)
|
|
30
30
|
export const JsonDiscordWSCodecLive = Layer.succeed(DiscordWSCodec, {
|
|
@@ -76,7 +76,7 @@ const make = Effect.gen(function* (_) {
|
|
|
76
76
|
export interface DiscordWS {
|
|
77
77
|
readonly _: unique symbol
|
|
78
78
|
}
|
|
79
|
-
export const DiscordWS =
|
|
79
|
+
export const DiscordWS = GenericTag<DiscordWS, Effect.Effect.Success<typeof make>>(
|
|
80
80
|
"dfx/DiscordGateway/DiscordWS",
|
|
81
81
|
)
|
|
82
82
|
export const DiscordWSLive = Layer.provide(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GenericTag } from "effect/Context"
|
|
2
2
|
import * as Effect from "effect/Effect"
|
|
3
3
|
import * as PubSub from "effect/PubSub"
|
|
4
4
|
import * as Layer from "effect/Layer"
|
|
@@ -9,11 +9,11 @@ import * as EffectUtils from "dfx/utils/Effect"
|
|
|
9
9
|
|
|
10
10
|
const fromDispatchFactory =
|
|
11
11
|
<R, E>(
|
|
12
|
-
source: Stream.Stream<
|
|
12
|
+
source: Stream.Stream<Discord.GatewayPayload<Discord.ReceiveEvent>, E, R>,
|
|
13
13
|
) =>
|
|
14
14
|
<K extends keyof Discord.ReceiveEvents>(
|
|
15
15
|
event: K,
|
|
16
|
-
): Stream.Stream<
|
|
16
|
+
): Stream.Stream<Discord.ReceiveEvents[K], E, R> =>
|
|
17
17
|
Stream.map(
|
|
18
18
|
Stream.filter(source, p => p.t === event),
|
|
19
19
|
p => p.d! as any,
|
|
@@ -23,8 +23,8 @@ const handleDispatchFactory =
|
|
|
23
23
|
(hub: PubSub.PubSub<Discord.GatewayPayload<Discord.ReceiveEvent>>) =>
|
|
24
24
|
<K extends keyof Discord.ReceiveEvents, R, E, A>(
|
|
25
25
|
event: K,
|
|
26
|
-
handle: (event: Discord.ReceiveEvents[K]) => Effect.Effect<
|
|
27
|
-
): Effect.Effect<
|
|
26
|
+
handle: (event: Discord.ReceiveEvents[K]) => Effect.Effect<A, E, R>,
|
|
27
|
+
): Effect.Effect<never, E, R> =>
|
|
28
28
|
EffectUtils.subscribeForEachPar(hub, _ => {
|
|
29
29
|
if (_.t === event) {
|
|
30
30
|
return handle(_.d as any)
|
|
@@ -66,7 +66,8 @@ export const make = Effect.gen(function* (_) {
|
|
|
66
66
|
export interface Messsaging {
|
|
67
67
|
readonly _: unique symbol
|
|
68
68
|
}
|
|
69
|
-
export const Messaging =
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
export const Messaging = GenericTag<
|
|
70
|
+
Messsaging,
|
|
71
|
+
Effect.Effect.Success<typeof make>
|
|
72
|
+
>("dfx/DiscordGateway/Messaging")
|
|
72
73
|
export const MesssagingLive = Layer.scoped(Messaging, make)
|
|
@@ -21,7 +21,7 @@ const payloadOrReconnect = (
|
|
|
21
21
|
) =>
|
|
22
22
|
Effect.flatMap(
|
|
23
23
|
Ref.get(ref),
|
|
24
|
-
(acked): Effect.Effect<
|
|
24
|
+
(acked): Effect.Effect<DiscordWS.Message> =>
|
|
25
25
|
acked ? payload(seqRef) : Effect.succeed(Reconnect),
|
|
26
26
|
)
|
|
27
27
|
|
|
@@ -29,7 +29,7 @@ export const send = (
|
|
|
29
29
|
hellos: Queue.Dequeue<Discord.GatewayPayload>,
|
|
30
30
|
acks: Queue.Dequeue<Discord.GatewayPayload>,
|
|
31
31
|
seqRef: Ref.Ref<Option.Option<number>>,
|
|
32
|
-
send: (p: DiscordWS.Message) => Effect.Effect<
|
|
32
|
+
send: (p: DiscordWS.Message) => Effect.Effect<boolean>,
|
|
33
33
|
) =>
|
|
34
34
|
Effect.flatMap(Ref.make(true), ackedRef => {
|
|
35
35
|
const heartbeats = EffectU.foreverSwitch(
|
|
@@ -41,12 +41,8 @@ export const identifyOrResume = (
|
|
|
41
41
|
opts: Options,
|
|
42
42
|
ready: Ref.Ref<Option.Option<Discord.ReadyEvent>>,
|
|
43
43
|
seq: Ref.Ref<Option.Option<number>>,
|
|
44
|
-
): Effect.Effect<
|
|
45
|
-
|
|
46
|
-
never,
|
|
47
|
-
| Discord.GatewayPayload<Discord.Identify>
|
|
48
|
-
| Discord.GatewayPayload<Discord.Resume>
|
|
49
|
-
> =>
|
|
44
|
+
): Effect.Effect<| Discord.GatewayPayload<Discord.Identify>
|
|
45
|
+
| Discord.GatewayPayload<Discord.Resume>> =>
|
|
50
46
|
Effect.map(
|
|
51
47
|
Effect.all([Ref.get(ready), Ref.get(seq)]),
|
|
52
48
|
([readyEvent, seqNumber]) =>
|
|
@@ -8,5 +8,5 @@ import type * as Discord from "dfx/types"
|
|
|
8
8
|
export const fromPayload = (
|
|
9
9
|
p: Discord.GatewayPayload,
|
|
10
10
|
latestReady: Ref.Ref<Option.Option<Discord.ReadyEvent>>,
|
|
11
|
-
): Effect.Effect<
|
|
11
|
+
): Effect.Effect<Message> =>
|
|
12
12
|
Effect.as(p.d ? Effect.unit : Ref.set(latestReady, Option.none()), Reconnect)
|
|
@@ -5,10 +5,10 @@ import * as Stream from "effect/Stream"
|
|
|
5
5
|
import type * as Discord from "dfx/types"
|
|
6
6
|
|
|
7
7
|
export const opCode =
|
|
8
|
-
<R, E>(source: Stream.Stream<
|
|
8
|
+
<R, E>(source: Stream.Stream<Discord.GatewayPayload, E, R>) =>
|
|
9
9
|
<T = any>(
|
|
10
10
|
code: Discord.GatewayOpcode,
|
|
11
|
-
): Stream.Stream<
|
|
11
|
+
): Stream.Stream<Discord.GatewayPayload<T>, E, R> =>
|
|
12
12
|
source.pipe(
|
|
13
13
|
Stream.filter((p): p is Discord.GatewayPayload<T> => p.op === code),
|
|
14
14
|
)
|
|
@@ -18,7 +18,7 @@ const maybeUpdateRef =
|
|
|
18
18
|
f: (p: Discord.GatewayPayload) => Option.Option<T>,
|
|
19
19
|
ref: Ref.Ref<Option.Option<T>>,
|
|
20
20
|
) =>
|
|
21
|
-
(_: Discord.GatewayPayload): Effect.Effect<
|
|
21
|
+
(_: Discord.GatewayPayload): Effect.Effect<void> =>
|
|
22
22
|
Option.match(f(_), {
|
|
23
23
|
onNone: () => Effect.unit,
|
|
24
24
|
onSome: a => Ref.set(ref, Option.some(a)),
|
|
@@ -26,14 +26,10 @@ const maybeUpdateRef =
|
|
|
26
26
|
|
|
27
27
|
export const latest = <T>(
|
|
28
28
|
f: (p: Discord.GatewayPayload) => Option.Option<T>,
|
|
29
|
-
): Effect.Effect<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Ref.Ref<Option.Option<T>>,
|
|
34
|
-
(_: Discord.GatewayPayload<any>) => Effect.Effect<never, never, void>,
|
|
35
|
-
]
|
|
36
|
-
> =>
|
|
29
|
+
): Effect.Effect<readonly [
|
|
30
|
+
Ref.Ref<Option.Option<T>>,
|
|
31
|
+
(_: Discord.GatewayPayload<any>) => Effect.Effect<void>,
|
|
32
|
+
]> =>
|
|
37
33
|
Effect.map(
|
|
38
34
|
Ref.make<Option.Option<T>>(Option.none()),
|
|
39
35
|
ref => [ref, maybeUpdateRef(f, ref)] as const,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Chunk from "effect/Chunk"
|
|
2
|
-
import {
|
|
2
|
+
import { GenericTag } from "effect/Context"
|
|
3
3
|
import * as Duration from "effect/Duration"
|
|
4
4
|
import { pipe } from "effect/Function"
|
|
5
5
|
import * as Option from "effect/Option"
|
|
@@ -207,7 +207,7 @@ type ShardService = Effect.Effect.Success<typeof make>
|
|
|
207
207
|
export interface Shard {
|
|
208
208
|
readonly _: unique symbol
|
|
209
209
|
}
|
|
210
|
-
export const Shard =
|
|
210
|
+
export const Shard = GenericTag<Shard, ShardService>("dfx/DiscordGateway/Shard")
|
|
211
211
|
export const ShardLive = Layer.effect(Shard, make).pipe(
|
|
212
212
|
Layer.provide(DiscordWSLive),
|
|
213
213
|
Layer.provide(MesssagingLive),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GenericTag } from "effect/Context"
|
|
2
2
|
import * as Option from "effect/Option"
|
|
3
3
|
import * as Effect from "effect/Effect"
|
|
4
4
|
import * as Layer from "effect/Layer"
|
|
@@ -11,14 +11,14 @@ export interface ClaimIdContext {
|
|
|
11
11
|
export interface ShardStoreService {
|
|
12
12
|
claimId: (
|
|
13
13
|
ctx: ClaimIdContext,
|
|
14
|
-
) => Effect.Effect<
|
|
15
|
-
allClaimed: (totalCount: number) => Effect.Effect<
|
|
16
|
-
heartbeat?: (shardId: number) => Effect.Effect<
|
|
14
|
+
) => Effect.Effect<Option.Option<number>>
|
|
15
|
+
allClaimed: (totalCount: number) => Effect.Effect<boolean>
|
|
16
|
+
heartbeat?: (shardId: number) => Effect.Effect<void>
|
|
17
17
|
}
|
|
18
18
|
export interface ShardStore {
|
|
19
19
|
readonly _: unique symbol
|
|
20
20
|
}
|
|
21
|
-
export const ShardStore =
|
|
21
|
+
export const ShardStore = GenericTag<ShardStore, ShardStoreService>(
|
|
22
22
|
"dfx/DiscordGateway/ShardStore",
|
|
23
23
|
)
|
|
24
24
|
|
|
@@ -5,7 +5,7 @@ import { ShardStore } from "dfx/DiscordGateway/ShardStore"
|
|
|
5
5
|
import { DiscordREST, DiscordRESTLive } from "dfx/DiscordREST"
|
|
6
6
|
import { RateLimiter, RateLimiterLive } from "dfx/RateLimit"
|
|
7
7
|
import type * as Discord from "dfx/types"
|
|
8
|
-
import {
|
|
8
|
+
import { GenericTag } from "effect/Context"
|
|
9
9
|
import * as Duration from "effect/Duration"
|
|
10
10
|
import * as Effect from "effect/Effect"
|
|
11
11
|
import { pipe } from "effect/Function"
|
|
@@ -47,7 +47,7 @@ const make = Effect.gen(function* (_) {
|
|
|
47
47
|
|
|
48
48
|
const totalCount = config.shardCount ?? gateway.shards
|
|
49
49
|
const currentCount = yield* _(Ref.make(0))
|
|
50
|
-
const claimId = (sharderCount: number): Effect.Effect<
|
|
50
|
+
const claimId = (sharderCount: number): Effect.Effect<number> =>
|
|
51
51
|
pipe(
|
|
52
52
|
store.claimId({
|
|
53
53
|
totalCount,
|
|
@@ -59,7 +59,10 @@ const make = Effect.gen(function* (_) {
|
|
|
59
59
|
const takeConfig = pipe(
|
|
60
60
|
Ref.getAndUpdate(currentCount, _ => _ + 1),
|
|
61
61
|
Effect.flatMap(claimId),
|
|
62
|
-
Effect.map(id => ({
|
|
62
|
+
Effect.map(id => (({
|
|
63
|
+
id,
|
|
64
|
+
totalCount
|
|
65
|
+
}) as const)),
|
|
63
66
|
)
|
|
64
67
|
|
|
65
68
|
const spawner = pipe(
|
|
@@ -105,7 +108,7 @@ const make = Effect.gen(function* (_) {
|
|
|
105
108
|
export interface Sharder {
|
|
106
109
|
readonly _: unique symbol
|
|
107
110
|
}
|
|
108
|
-
export const Sharder =
|
|
111
|
+
export const Sharder = GenericTag<Sharder, Effect.Effect.Success<typeof make>>(
|
|
109
112
|
"dfx/DiscordGateway/Sharder",
|
|
110
113
|
)
|
|
111
114
|
export const SharderLive = Layer.scoped(Sharder, make).pipe(
|