dfx 0.86.0 → 0.88.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/driver.js.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.d.ts.map +1 -1
- 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 +4 -4
- 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 +6 -2
- package/DiscordREST/types.d.ts.map +1 -1
- package/DiscordREST.d.ts +4 -4
- package/DiscordREST.d.ts.map +1 -1
- package/DiscordREST.js +19 -2
- 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 -23
- 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 +5 -5
- package/Interactions/gateway.js.map +1 -1
- package/Interactions/handlers.d.ts +2 -2
- package/Interactions/handlers.d.ts.map +1 -1
- package/Interactions/index.d.ts +5 -5
- package/Interactions/utils.d.ts +26 -26
- package/Interactions/utils.d.ts.map +1 -1
- 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/driver.mjs.map +1 -1
- package/mjs/Cache/memory.mjs.map +1 -1
- package/mjs/Cache/memoryTTL.mjs.map +1 -1
- package/mjs/Cache/prelude.mjs +4 -4
- 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 +20 -3
- 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 +6 -6
- package/mjs/Interactions/gateway.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 -21
- package/src/Cache/memory.ts +1 -7
- package/src/Cache/memoryTTL.ts +3 -4
- package/src/Cache/prelude.ts +33 -34
- package/src/Cache.ts +31 -31
- package/src/DiscordConfig.ts +4 -4
- package/src/DiscordGateway/DiscordWS.ts +8 -7
- package/src/DiscordGateway/Messaging.ts +9 -8
- package/src/DiscordGateway/Shard/heartbeats.ts +2 -2
- package/src/DiscordGateway/Shard/identify.ts +0 -2
- package/src/DiscordGateway/Shard/invalidSession.ts +1 -1
- package/src/DiscordGateway/Shard/utils.ts +4 -6
- package/src/DiscordGateway/Shard.ts +2 -2
- package/src/DiscordGateway/ShardStore.ts +5 -7
- package/src/DiscordGateway/Sharder.ts +10 -4
- package/src/DiscordGateway/WS.ts +7 -10
- package/src/DiscordGateway.ts +8 -12
- package/src/DiscordREST/types.ts +7 -6
- package/src/DiscordREST.ts +36 -7
- package/src/Helpers/permissions.ts +1 -1
- package/src/Interactions/builder.ts +11 -11
- package/src/Interactions/context.ts +25 -24
- package/src/Interactions/definitions.ts +35 -34
- package/src/Interactions/gateway.ts +19 -18
- package/src/Interactions/handlers.ts +4 -4
- package/src/Interactions/utils.ts +10 -12
- package/src/Interactions/webhook.ts +17 -16
- 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
|
@@ -65,13 +65,13 @@ export const guild = <
|
|
|
65
65
|
export class MessageComponent<R, E> {
|
|
66
66
|
readonly _tag = "MessageComponent"
|
|
67
67
|
constructor(
|
|
68
|
-
readonly predicate: (customId: string) => Effect.Effect<
|
|
69
|
-
readonly handle: Effect.Effect<
|
|
68
|
+
readonly predicate: (customId: string) => Effect.Effect<boolean, E, R>,
|
|
69
|
+
readonly handle: Effect.Effect<Discord.InteractionResponse, E, R>,
|
|
70
70
|
) {}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
export const messageComponent = <R1, R2, E1, E2>(
|
|
74
|
-
pred: (customId: string) => Effect.Effect<
|
|
74
|
+
pred: (customId: string) => Effect.Effect<boolean, E1, R1>,
|
|
75
75
|
handle: CommandHandler<R2, E2, Discord.InteractionResponse>,
|
|
76
76
|
) =>
|
|
77
77
|
new MessageComponent<
|
|
@@ -82,14 +82,14 @@ export const messageComponent = <R1, R2, E1, E2>(
|
|
|
82
82
|
export class ModalSubmit<R, E> {
|
|
83
83
|
readonly _tag = "ModalSubmit"
|
|
84
84
|
constructor(
|
|
85
|
-
readonly predicate: (customId: string) => Effect.Effect<
|
|
86
|
-
readonly handle: Effect.Effect<
|
|
85
|
+
readonly predicate: (customId: string) => Effect.Effect<boolean, E, R>,
|
|
86
|
+
readonly handle: Effect.Effect<Discord.InteractionResponse, E, R>,
|
|
87
87
|
) {}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
export const modalSubmit = <R1, R2, E1, E2>(
|
|
91
|
-
pred: (customId: string) => Effect.Effect<
|
|
92
|
-
handle: Effect.Effect<
|
|
91
|
+
pred: (customId: string) => Effect.Effect<boolean, E1, R1>,
|
|
92
|
+
handle: Effect.Effect<Discord.InteractionResponse, E2, R2>,
|
|
93
93
|
) =>
|
|
94
94
|
new ModalSubmit<
|
|
95
95
|
Exclude<R1 | R2, DiscordInteraction | DiscordModalSubmit>,
|
|
@@ -102,8 +102,8 @@ export class Autocomplete<R, E> {
|
|
|
102
102
|
readonly predicate: (
|
|
103
103
|
data: Discord.ApplicationCommandDatum,
|
|
104
104
|
focusedOption: Discord.ApplicationCommandInteractionDataOption,
|
|
105
|
-
) => Effect.Effect<
|
|
106
|
-
readonly handle: Effect.Effect<
|
|
105
|
+
) => Effect.Effect<boolean, E, R>,
|
|
106
|
+
readonly handle: Effect.Effect<Discord.InteractionResponse, E, R>,
|
|
107
107
|
) {}
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -111,8 +111,8 @@ export const autocomplete = <R1, R2, E1, E2>(
|
|
|
111
111
|
pred: (
|
|
112
112
|
data: Discord.ApplicationCommandDatum,
|
|
113
113
|
focusedOption: Discord.ApplicationCommandInteractionDataOption,
|
|
114
|
-
) => Effect.Effect<
|
|
115
|
-
handle: Effect.Effect<
|
|
114
|
+
) => Effect.Effect<boolean, E1, R1>,
|
|
115
|
+
handle: Effect.Effect<Discord.InteractionResponse, E2, R2>,
|
|
116
116
|
) =>
|
|
117
117
|
new Autocomplete<
|
|
118
118
|
Exclude<
|
|
@@ -123,45 +123,46 @@ export const autocomplete = <R1, R2, E1, E2>(
|
|
|
123
123
|
>(pred as any, handle as any)
|
|
124
124
|
|
|
125
125
|
// ==== Command handler helpers
|
|
126
|
-
type DeepReadonly<T> =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
126
|
+
type DeepReadonly<T> =
|
|
127
|
+
T extends Array<infer R>
|
|
128
|
+
? ReadonlyArray<DeepReadonly<R>>
|
|
129
|
+
: T extends Function
|
|
130
|
+
? T
|
|
131
|
+
: T extends object
|
|
132
|
+
? DeepReadonlyObject<T>
|
|
133
|
+
: T
|
|
133
134
|
type DeepReadonlyObject<T> = {
|
|
134
135
|
readonly [P in keyof T]: DeepReadonly<T[P]>
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
export type CommandHandler<R, E, A = any> =
|
|
138
|
-
| Effect.Effect<
|
|
139
|
+
| Effect.Effect<Discord.InteractionResponse, E, R>
|
|
139
140
|
| CommandHandlerFn<R, E, A>
|
|
140
141
|
|
|
141
142
|
export interface CommandHelper<A> {
|
|
142
143
|
resolve: <T>(
|
|
143
144
|
name: AllResolvables<A>["name"],
|
|
144
145
|
f: (id: Discord.Snowflake, data: Discord.ResolvedDatum) => T | undefined,
|
|
145
|
-
) => Effect.Effect<
|
|
146
|
+
) => Effect.Effect<T, ResolvedDataNotFound, DiscordInteraction>
|
|
146
147
|
|
|
147
148
|
option: (
|
|
148
149
|
name: AllCommandOptions<A>["name"],
|
|
149
150
|
) => Effect.Effect<
|
|
150
|
-
|
|
151
|
+
Option.Option<Discord.ApplicationCommandInteractionDataOption>,
|
|
151
152
|
never,
|
|
152
|
-
|
|
153
|
+
DiscordApplicationCommand
|
|
153
154
|
>
|
|
154
155
|
|
|
155
156
|
optionValue: <N extends AllRequiredCommandOptions<A>["name"]>(
|
|
156
157
|
name: N,
|
|
157
|
-
) => Effect.Effect<
|
|
158
|
+
) => Effect.Effect<CommandValue<A, N>, never, DiscordApplicationCommand>
|
|
158
159
|
|
|
159
160
|
optionValueOptional: <N extends AllCommandOptions<A>["name"]>(
|
|
160
161
|
name: N,
|
|
161
162
|
) => Effect.Effect<
|
|
162
|
-
|
|
163
|
+
Option.Option<CommandValue<A, N>>,
|
|
163
164
|
never,
|
|
164
|
-
|
|
165
|
+
DiscordApplicationCommand
|
|
165
166
|
>
|
|
166
167
|
|
|
167
168
|
subCommands: <
|
|
@@ -169,11 +170,17 @@ export interface CommandHelper<A> {
|
|
|
169
170
|
? never
|
|
170
171
|
: Record<
|
|
171
172
|
SubCommandNames<A>,
|
|
172
|
-
Effect.Effect<
|
|
173
|
+
Effect.Effect<Discord.InteractionResponse, any, any>
|
|
173
174
|
>,
|
|
174
175
|
>(
|
|
175
176
|
commands: NER,
|
|
176
177
|
) => Effect.Effect<
|
|
178
|
+
Discord.InteractionResponse,
|
|
179
|
+
[NER[keyof NER]] extends [
|
|
180
|
+
{ [Effect.EffectTypeId]: { _E: (_: never) => infer E } },
|
|
181
|
+
]
|
|
182
|
+
? E
|
|
183
|
+
: never,
|
|
177
184
|
| Exclude<
|
|
178
185
|
[NER[keyof NER]] extends [
|
|
179
186
|
{ [Effect.EffectTypeId]: { _R: (_: never) => infer R } },
|
|
@@ -183,19 +190,13 @@ export interface CommandHelper<A> {
|
|
|
183
190
|
SubCommandContext
|
|
184
191
|
>
|
|
185
192
|
| DiscordInteraction
|
|
186
|
-
| DiscordApplicationCommand
|
|
187
|
-
[NER[keyof NER]] extends [
|
|
188
|
-
{ [Effect.EffectTypeId]: { _E: (_: never) => infer E } },
|
|
189
|
-
]
|
|
190
|
-
? E
|
|
191
|
-
: never,
|
|
192
|
-
Discord.InteractionResponse
|
|
193
|
+
| DiscordApplicationCommand
|
|
193
194
|
>
|
|
194
195
|
}
|
|
195
196
|
|
|
196
197
|
export type CommandHandlerFn<R, E, A> = (
|
|
197
198
|
i: CommandHelper<A>,
|
|
198
|
-
) => Effect.Effect<
|
|
199
|
+
) => Effect.Effect<Discord.InteractionResponse, E, R>
|
|
199
200
|
|
|
200
201
|
interface CommandOption {
|
|
201
202
|
readonly type: any
|
|
@@ -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 Effect from "effect/Effect"
|
|
@@ -38,18 +38,18 @@ export const run =
|
|
|
38
38
|
<R, R2, E, TE, E2>(
|
|
39
39
|
postHandler: (
|
|
40
40
|
effect: Effect.Effect<
|
|
41
|
-
|
|
41
|
+
void,
|
|
42
42
|
TE | DiscordRESTError | DefinitionNotFound,
|
|
43
|
-
|
|
43
|
+
R | DiscordREST | DiscordInteraction
|
|
44
44
|
>,
|
|
45
|
-
) => Effect.Effect<
|
|
45
|
+
) => Effect.Effect<void, E2, R2>,
|
|
46
46
|
) =>
|
|
47
47
|
(
|
|
48
48
|
ix: InteractionBuilder<R, E, TE>,
|
|
49
49
|
): Effect.Effect<
|
|
50
|
-
|
|
50
|
+
never,
|
|
51
51
|
E2 | DiscordRESTError | Http.error.ResponseError,
|
|
52
|
-
|
|
52
|
+
DiscordREST | DiscordGateway | Exclude<R2, DiscordInteraction>
|
|
53
53
|
> =>
|
|
54
54
|
Effect.gen(function* (_) {
|
|
55
55
|
const GlobalApplicationCommand = ix.definitions.pipe(
|
|
@@ -73,8 +73,7 @@ export const run =
|
|
|
73
73
|
const rest = yield* _(DiscordREST)
|
|
74
74
|
|
|
75
75
|
const application = yield* _(
|
|
76
|
-
rest.getCurrentBotApplicationInformation(),
|
|
77
|
-
Effect.flatMap(a => a.json),
|
|
76
|
+
rest.getCurrentBotApplicationInformation().json,
|
|
78
77
|
)
|
|
79
78
|
|
|
80
79
|
const globalSync = rest.bulkOverwriteGlobalApplicationCommands(
|
|
@@ -84,20 +83,22 @@ export const run =
|
|
|
84
83
|
GlobalApplicationCommand.map(_ => _.command),
|
|
85
84
|
),
|
|
86
85
|
},
|
|
87
|
-
)
|
|
86
|
+
).asUnit
|
|
88
87
|
|
|
89
88
|
const guildSync = GuildApplicationCommand.length
|
|
90
|
-
? gateway.handleDispatch(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
? gateway.handleDispatch(
|
|
90
|
+
"GUILD_CREATE",
|
|
91
|
+
a =>
|
|
92
|
+
rest.bulkOverwriteGuildApplicationCommands(
|
|
93
|
+
application.id,
|
|
94
|
+
a.id,
|
|
95
|
+
GuildApplicationCommand.map(_ => _.command) as any,
|
|
96
|
+
).asUnit,
|
|
96
97
|
)
|
|
97
98
|
: Effect.never
|
|
98
99
|
|
|
99
100
|
const handle = handlers(ix.definitions, (i, r) =>
|
|
100
|
-
rest.createInteractionResponse(i.id, i.token, r),
|
|
101
|
+
rest.createInteractionResponse(i.id, i.token, r).pipe(Effect.scoped),
|
|
101
102
|
)
|
|
102
103
|
|
|
103
104
|
const run = gateway.handleDispatch("INTERACTION_CREATE", i =>
|
|
@@ -160,13 +161,13 @@ const makeRegistry = Effect.gen(function* (_) {
|
|
|
160
161
|
export interface InteractionsRegistryService {
|
|
161
162
|
readonly register: <E>(
|
|
162
163
|
ix: InteractionBuilder<never, E, never>,
|
|
163
|
-
) => Effect.Effect<
|
|
164
|
+
) => Effect.Effect<void>
|
|
164
165
|
}
|
|
165
166
|
export interface InteractionsRegistry {
|
|
166
167
|
readonly _: unique symbol
|
|
167
168
|
}
|
|
168
169
|
|
|
169
|
-
export const InteractionsRegistry =
|
|
170
|
+
export const InteractionsRegistry = GenericTag<
|
|
170
171
|
InteractionsRegistry,
|
|
171
172
|
InteractionsRegistryService
|
|
172
173
|
>("dfx/Interactions/InteractionsRegistry")
|
|
@@ -13,22 +13,22 @@ export class DefinitionNotFound {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
type Handler<R, E, A> = Effect.Effect<
|
|
16
|
-
|
|
16
|
+
A,
|
|
17
17
|
E | DefinitionNotFound,
|
|
18
|
-
|
|
18
|
+
R | Ctx.DiscordInteraction
|
|
19
19
|
>
|
|
20
20
|
|
|
21
21
|
export const handlers = <R, E, TE, A, B>(
|
|
22
22
|
definitions: Chunk.Chunk<
|
|
23
23
|
readonly [
|
|
24
24
|
handler: D.InteractionDefinition<R, E>,
|
|
25
|
-
transform: (self: Effect.Effect<
|
|
25
|
+
transform: (self: Effect.Effect<A, E, R>) => Effect.Effect<B, TE, R>,
|
|
26
26
|
]
|
|
27
27
|
>,
|
|
28
28
|
handleResponse: (
|
|
29
29
|
ix: Discord.Interaction,
|
|
30
30
|
_: Discord.InteractionResponse,
|
|
31
|
-
) => Effect.Effect<
|
|
31
|
+
) => Effect.Effect<A, E, R>,
|
|
32
32
|
): Record<
|
|
33
33
|
Discord.InteractionType,
|
|
34
34
|
(i: Discord.Interaction) => Handler<R, E, B>
|
|
@@ -4,16 +4,14 @@ import * as Ctx from "dfx/Interactions/context"
|
|
|
4
4
|
import type * as D from "dfx/Interactions/definitions"
|
|
5
5
|
import type * as Discord from "dfx/types"
|
|
6
6
|
|
|
7
|
-
export type DefinitionFlattened<R, E, TE, A> =
|
|
8
|
-
R,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
: never
|
|
7
|
+
export type DefinitionFlattened<R, E, TE, A> =
|
|
8
|
+
D.InteractionDefinition<R, E> extends infer D
|
|
9
|
+
? {
|
|
10
|
+
[K in keyof D]: K extends "handle"
|
|
11
|
+
? (_: Discord.Interaction) => Effect.Effect<A, TE, R>
|
|
12
|
+
: D[K]
|
|
13
|
+
}
|
|
14
|
+
: never
|
|
17
15
|
|
|
18
16
|
export type DefinitionFlattenedCommand<R, E, TE, A> = Extract<
|
|
19
17
|
DefinitionFlattened<R, E, TE, A>,
|
|
@@ -32,13 +30,13 @@ export const flattenDefinitions = <R, E, TE, A, B>(
|
|
|
32
30
|
definitions: Chunk.Chunk<
|
|
33
31
|
readonly [
|
|
34
32
|
handler: D.InteractionDefinition<R, E>,
|
|
35
|
-
transform: (self: Effect.Effect<
|
|
33
|
+
transform: (self: Effect.Effect<A, E, R>) => Effect.Effect<B, TE, R>,
|
|
36
34
|
]
|
|
37
35
|
>,
|
|
38
36
|
handleResponse: (
|
|
39
37
|
ix: Discord.Interaction,
|
|
40
38
|
_: Discord.InteractionResponse,
|
|
41
|
-
) => Effect.Effect<
|
|
39
|
+
) => Effect.Effect<A, E, R>,
|
|
42
40
|
) =>
|
|
43
41
|
Chunk.map(definitions, ([definition, transform]) => ({
|
|
44
42
|
...definition,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Chunk from "effect/Chunk"
|
|
2
|
-
import {
|
|
2
|
+
import { GenericTag } from "effect/Context"
|
|
3
3
|
import { identity } from "effect/Function"
|
|
4
4
|
import * as Option from "effect/Option"
|
|
5
5
|
import type * as Cause from "effect/Cause"
|
|
@@ -74,16 +74,17 @@ const makeConfig = ({
|
|
|
74
74
|
export interface WebhookConfig {
|
|
75
75
|
readonly _: unique symbol
|
|
76
76
|
}
|
|
77
|
-
export const WebhookConfig =
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
export const WebhookConfig = GenericTag<
|
|
78
|
+
WebhookConfig,
|
|
79
|
+
ReturnType<typeof makeConfig>
|
|
80
|
+
>("dfx/Interactions/WebhookConfig")
|
|
80
81
|
|
|
81
82
|
export const layer = (opts: MakeConfigOpts) =>
|
|
82
83
|
Layer.succeed(WebhookConfig, makeConfig(opts))
|
|
83
84
|
|
|
84
85
|
export const layerConfig: (
|
|
85
86
|
config: Config.Config<MakeConfigOpts>,
|
|
86
|
-
) => Layer.Layer<
|
|
87
|
+
) => Layer.Layer<WebhookConfig, ConfigError.ConfigError> = (
|
|
87
88
|
config: Config.Config<MakeConfigOpts>,
|
|
88
89
|
) => Layer.effect(WebhookConfig, Effect.map(config, makeConfig))
|
|
89
90
|
|
|
@@ -109,23 +110,23 @@ const run = <R, E>(
|
|
|
109
110
|
readonly [
|
|
110
111
|
handler: D.InteractionDefinition<R, E>,
|
|
111
112
|
transform: (
|
|
112
|
-
self: Effect.Effect<
|
|
113
|
-
) => Effect.Effect<
|
|
113
|
+
self: Effect.Effect<Discord.InteractionResponse, E, R>,
|
|
114
|
+
) => Effect.Effect<Discord.InteractionResponse, E, R>,
|
|
114
115
|
]
|
|
115
116
|
>,
|
|
116
117
|
handleResponse: (
|
|
117
118
|
ix: Discord.Interaction,
|
|
118
119
|
_: Discord.InteractionResponse,
|
|
119
|
-
) => Effect.Effect<
|
|
120
|
+
) => Effect.Effect<Discord.InteractionResponse, E, R>,
|
|
120
121
|
) => {
|
|
121
122
|
const handler = handlers(definitions, handleResponse)
|
|
122
123
|
return (
|
|
123
124
|
headers: Headers,
|
|
124
125
|
body: string,
|
|
125
126
|
): Effect.Effect<
|
|
126
|
-
|
|
127
|
+
Discord.InteractionResponse,
|
|
127
128
|
BadWebhookSignature | WebhookParseError | E | DefinitionNotFound,
|
|
128
|
-
|
|
129
|
+
WebhookConfig | Exclude<R, DiscordInteraction>
|
|
129
130
|
> =>
|
|
130
131
|
Effect.flatMap(fromHeadersAndBody(headers, body), interaction =>
|
|
131
132
|
Effect.provideService(
|
|
@@ -139,8 +140,8 @@ const run = <R, E>(
|
|
|
139
140
|
export interface HandleWebhookOpts<E> {
|
|
140
141
|
headers: Headers
|
|
141
142
|
body: string
|
|
142
|
-
success: (a: Discord.InteractionResponse) => Effect.Effect<
|
|
143
|
-
error: (e: Cause.Cause<E>) => Effect.Effect<
|
|
143
|
+
success: (a: Discord.InteractionResponse) => Effect.Effect<void>
|
|
144
|
+
error: (e: Cause.Cause<E>) => Effect.Effect<void>
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
/**
|
|
@@ -155,7 +156,7 @@ export const makeHandler = <R, E, TE>(
|
|
|
155
156
|
success,
|
|
156
157
|
}: HandleWebhookOpts<
|
|
157
158
|
E | WebhookParseError | BadWebhookSignature | DefinitionNotFound
|
|
158
|
-
>) => Effect.Effect<
|
|
159
|
+
>) => Effect.Effect<void, never, WebhookConfig>) => {
|
|
159
160
|
const handle = run(
|
|
160
161
|
Chunk.map(ix.definitions, ([d]) => [d, identity] as any),
|
|
161
162
|
(_i, r) => Effect.succeed(r),
|
|
@@ -168,7 +169,7 @@ export const makeHandler = <R, E, TE>(
|
|
|
168
169
|
success,
|
|
169
170
|
}: HandleWebhookOpts<
|
|
170
171
|
E | WebhookParseError | BadWebhookSignature | DefinitionNotFound
|
|
171
|
-
>): Effect.Effect<
|
|
172
|
+
>): Effect.Effect<void, never, WebhookConfig> =>
|
|
172
173
|
handle(headers, body).pipe(
|
|
173
174
|
Effect.flatMap(success),
|
|
174
175
|
Effect.catchAllCause(error),
|
|
@@ -187,9 +188,9 @@ export const makeSimpleHandler = <R, E, TE>(
|
|
|
187
188
|
headers: Headers
|
|
188
189
|
body: string
|
|
189
190
|
}) => Effect.Effect<
|
|
190
|
-
|
|
191
|
+
Discord.InteractionResponse,
|
|
191
192
|
BadWebhookSignature | WebhookParseError | DefinitionNotFound,
|
|
192
|
-
|
|
193
|
+
WebhookConfig
|
|
193
194
|
>) => {
|
|
194
195
|
const handle = run(
|
|
195
196
|
Chunk.map(ix.definitions, ([d]) => [d, identity] as any),
|
package/src/RateLimit.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 type * as Option from "effect/Option"
|
|
4
4
|
import * as Effect from "effect/Effect"
|
|
@@ -15,35 +15,35 @@ export type BucketDetails = {
|
|
|
15
15
|
export interface RateLimitStoreService {
|
|
16
16
|
readonly hasBucket: (
|
|
17
17
|
bucketKey: string,
|
|
18
|
-
) => Effect.Effect<
|
|
18
|
+
) => Effect.Effect<boolean>
|
|
19
19
|
|
|
20
20
|
readonly putBucket: (
|
|
21
21
|
bucket: BucketDetails,
|
|
22
|
-
) => Effect.Effect<
|
|
22
|
+
) => Effect.Effect<void>
|
|
23
23
|
|
|
24
24
|
readonly getBucketForRoute: (
|
|
25
25
|
route: string,
|
|
26
|
-
) => Effect.Effect<
|
|
26
|
+
) => Effect.Effect<Option.Option<BucketDetails>>
|
|
27
27
|
|
|
28
28
|
readonly putBucketRoute: (
|
|
29
29
|
route: string,
|
|
30
30
|
bucketKey: string,
|
|
31
|
-
) => Effect.Effect<
|
|
31
|
+
) => Effect.Effect<void>
|
|
32
32
|
|
|
33
33
|
readonly incrementCounter: (
|
|
34
34
|
key: string,
|
|
35
35
|
window: number,
|
|
36
36
|
limit: number,
|
|
37
|
-
) => Effect.Effect<
|
|
37
|
+
) => Effect.Effect<readonly [count: number, ttl: number]>
|
|
38
38
|
|
|
39
|
-
readonly removeCounter: (key: string) => Effect.Effect<
|
|
39
|
+
readonly removeCounter: (key: string) => Effect.Effect<void>
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export interface RateLimitStore {
|
|
43
43
|
readonly _: unique symbol
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export const RateLimitStore =
|
|
46
|
+
export const RateLimitStore = GenericTag<RateLimitStore, RateLimitStoreService>(
|
|
47
47
|
"dfx/RateLimit/RateLimitStore",
|
|
48
48
|
)
|
|
49
49
|
export const MemoryRateLimitStoreLive = Layer.sync(RateLimitStore, Memory.make)
|
|
@@ -84,7 +84,7 @@ const makeLimiter = Effect.gen(function* (_) {
|
|
|
84
84
|
export interface RateLimiter {
|
|
85
85
|
readonly _: unique symbol
|
|
86
86
|
}
|
|
87
|
-
export const RateLimiter =
|
|
87
|
+
export const RateLimiter = GenericTag<
|
|
88
88
|
RateLimiter,
|
|
89
89
|
Effect.Effect.Success<typeof makeLimiter>
|
|
90
90
|
>("dfx/RateLimit/RateLimiter")
|
package/src/utils/Effect.ts
CHANGED
|
@@ -7,9 +7,9 @@ import * as Queue from "effect/Queue"
|
|
|
7
7
|
|
|
8
8
|
export const subscribeForEachPar = <R, E, A, X>(
|
|
9
9
|
self: PubSub.PubSub<A>,
|
|
10
|
-
effect: (_: A) => Effect.Effect<
|
|
11
|
-
): Effect.Effect<
|
|
12
|
-
Effect.flatMap(Deferred.make<
|
|
10
|
+
effect: (_: A) => Effect.Effect<X, E, R>,
|
|
11
|
+
): Effect.Effect<never, E, R> =>
|
|
12
|
+
Effect.flatMap(Deferred.make<never, E>(), deferred => {
|
|
13
13
|
const run = pipe(
|
|
14
14
|
PubSub.subscribe(self),
|
|
15
15
|
Effect.flatMap(queue =>
|
|
@@ -29,15 +29,15 @@ export const subscribeForEachPar = <R, E, A, X>(
|
|
|
29
29
|
return Effect.all([run, Deferred.await(deferred)], {
|
|
30
30
|
concurrency: "unbounded",
|
|
31
31
|
discard: true,
|
|
32
|
-
}) as Effect.Effect<
|
|
32
|
+
}) as Effect.Effect<never, E, R>
|
|
33
33
|
})
|
|
34
34
|
|
|
35
35
|
export const foreverSwitch = <R, E, A, R1, E1, X>(
|
|
36
|
-
self: Effect.Effect<
|
|
37
|
-
f: (_: A) => Effect.Effect<
|
|
38
|
-
): Effect.Effect<
|
|
36
|
+
self: Effect.Effect<A, E, R>,
|
|
37
|
+
f: (_: A) => Effect.Effect<X, E1, R1>,
|
|
38
|
+
): Effect.Effect<never, E | E1, R | R1> =>
|
|
39
39
|
pipe(
|
|
40
|
-
Effect.all([Deferred.make<
|
|
40
|
+
Effect.all([Deferred.make<never, E1>(), Effect.fiberId]),
|
|
41
41
|
Effect.flatMap(([causeDeferred, fiberId]) => {
|
|
42
42
|
let fiber: Fiber.RuntimeFiber<unknown, unknown> | undefined
|
|
43
43
|
|
|
@@ -64,6 +64,6 @@ export const foreverSwitch = <R, E, A, R1, E1, X>(
|
|
|
64
64
|
return Effect.all([run, Deferred.await(causeDeferred)], {
|
|
65
65
|
concurrency: "unbounded",
|
|
66
66
|
discard: true,
|
|
67
|
-
}) as Effect.Effect<
|
|
67
|
+
}) as Effect.Effect<never, E | E1, R | R1>
|
|
68
68
|
}),
|
|
69
69
|
)
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = "0.
|
|
1
|
+
export const LIB_VERSION = "0.88.0";
|
package/utils/Effect.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as PubSub from "effect/PubSub";
|
|
3
|
-
export declare const subscribeForEachPar: <R, E, A, X>(self: PubSub.PubSub<A>, effect: (_: A) => Effect.Effect<
|
|
4
|
-
export declare const foreverSwitch: <R, E, A, R1, E1, X>(self: Effect.Effect<
|
|
3
|
+
export declare const subscribeForEachPar: <R, E, A, X>(self: PubSub.PubSub<A>, effect: (_: A) => Effect.Effect<X, E, R>) => Effect.Effect<never, E, R>;
|
|
4
|
+
export declare const foreverSwitch: <R, E, A, R1, E1, X>(self: Effect.Effect<A, E, R>, f: (_: A) => Effect.Effect<X, E1, R1>) => Effect.Effect<never, E | E1, R | R1>;
|
|
5
5
|
//# sourceMappingURL=Effect.d.ts.map
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const LIB_VERSION = "0.
|
|
1
|
+
export declare const LIB_VERSION = "0.88.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/webhooks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as Layer from "effect/Layer";
|
|
2
2
|
export { BadWebhookSignature, WebhookConfig, WebhookParseError, makeHandler, makeSimpleHandler, layer as webhookLayer, layerConfig as webhookLayerConfig, } from "dfx/Interactions/webhook";
|
|
3
|
-
export declare const DiscordLive: Layer.Layer<import("
|
|
3
|
+
export declare const DiscordLive: Layer.Layer<import("dfx/RateLimit").RateLimiter | import("dfx/DiscordREST").DiscordREST, never, import("./DiscordConfig").DiscordConfig>;
|
|
4
4
|
//# sourceMappingURL=webhooks.d.ts.map
|