dfx 0.43.1 → 0.45.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/Interactions/builder.d.ts +48 -0
- package/Interactions/builder.js +68 -0
- package/Interactions/builder.js.map +1 -0
- package/Interactions/definitions.d.ts +2 -2
- package/Interactions/gateway.d.ts +8 -2
- package/Interactions/gateway.js +21 -9
- package/Interactions/gateway.js.map +1 -1
- package/Interactions/handlers.d.ts +3 -3
- package/Interactions/handlers.js +15 -28
- package/Interactions/handlers.js.map +1 -1
- package/Interactions/index.d.ts +2 -17
- package/Interactions/index.js +1 -40
- package/Interactions/index.js.map +1 -1
- package/Interactions/utils.d.ts +75 -7
- package/Interactions/utils.js +28 -15
- package/Interactions/utils.js.map +1 -1
- package/Interactions/webhook.d.ts +4 -4
- package/Interactions/webhook.js +5 -4
- package/Interactions/webhook.js.map +1 -1
- package/gateway.d.ts +1 -1
- package/gateway.js +1 -1
- package/gateway.js.map +1 -1
- package/package.json +2 -2
- package/src/Interactions/builder.ts +156 -0
- package/src/Interactions/definitions.ts +2 -2
- package/src/Interactions/gateway.ts +65 -16
- package/src/Interactions/handlers.ts +59 -80
- package/src/Interactions/index.ts +2 -65
- package/src/Interactions/utils.ts +72 -29
- package/src/Interactions/webhook.ts +27 -6
- package/src/gateway.ts +5 -1
- package/src/package.json +2 -2
|
@@ -1,39 +1,82 @@
|
|
|
1
1
|
import * as D from "./definitions.js"
|
|
2
|
+
import * as Ctx from "./context.js"
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
-
|
|
4
|
+
export type DefinitionFlattened<R, E, TE, A> = D.InteractionDefinition<
|
|
5
|
+
R,
|
|
6
|
+
E
|
|
7
|
+
> extends infer D
|
|
8
|
+
? {
|
|
9
|
+
[K in keyof D]: K extends "handle"
|
|
10
|
+
? (_: Discord.Interaction) => Effect<R, TE, A>
|
|
11
|
+
: D[K]
|
|
12
|
+
}
|
|
13
|
+
: never
|
|
14
|
+
|
|
15
|
+
export type DefinitionFlattenedCommand<R, E, TE, A> = Extract<
|
|
16
|
+
DefinitionFlattened<R, E, TE, A>,
|
|
17
|
+
{ _tag: "GlobalApplicationCommand" | "GuildApplicationCommand" }
|
|
18
|
+
>
|
|
19
|
+
|
|
20
|
+
const context: D.CommandHelper<any> = {
|
|
21
|
+
resolve: Ctx.resolved,
|
|
22
|
+
option: Ctx.option,
|
|
23
|
+
optionValue: Ctx.optionValue,
|
|
24
|
+
optionValueOptional: Ctx.optionValueOptional,
|
|
25
|
+
subCommands: Ctx.handleSubCommands,
|
|
26
|
+
} as any
|
|
27
|
+
|
|
28
|
+
export const flattenDefinitions = <R, E, TE, A, B>(
|
|
29
|
+
definitions: Chunk<
|
|
30
|
+
readonly [
|
|
31
|
+
handler: D.InteractionDefinition<R, E>,
|
|
32
|
+
transform: (self: Effect<R, E, A>) => Effect<R, TE, B>,
|
|
33
|
+
]
|
|
34
|
+
>,
|
|
35
|
+
handleResponse: (
|
|
36
|
+
ix: Discord.Interaction,
|
|
37
|
+
_: Discord.InteractionResponse,
|
|
38
|
+
) => Effect<R, E, A>,
|
|
39
|
+
) =>
|
|
40
|
+
definitions.map(([definition, transform]) => ({
|
|
41
|
+
...definition,
|
|
42
|
+
handle: (i: Discord.Interaction) =>
|
|
43
|
+
Effect.isEffect(definition.handle)
|
|
44
|
+
? transform(definition.handle.flatMap(_ => handleResponse(i, _)))
|
|
45
|
+
: transform(
|
|
46
|
+
definition.handle(context).flatMap(_ => handleResponse(i, _)),
|
|
47
|
+
),
|
|
48
|
+
}))
|
|
49
|
+
|
|
50
|
+
export const splitDefinitions = <R, E, TE, A>(
|
|
51
|
+
definitions: Chunk<DefinitionFlattened<R, E, TE, A>>,
|
|
5
52
|
) => {
|
|
6
|
-
const grouped = definitions.reduce
|
|
7
|
-
[K in D.InteractionDefinition<R, E>["_tag"]]: Extract<
|
|
8
|
-
D.InteractionDefinition<R, E>,
|
|
9
|
-
{ _tag: K }
|
|
10
|
-
>[]
|
|
11
|
-
}>(
|
|
12
|
-
(acc, a) => ({
|
|
13
|
-
...acc,
|
|
14
|
-
[a._tag]: [...(acc[a._tag] ?? []), a],
|
|
15
|
-
}),
|
|
53
|
+
const grouped = definitions.reduce(
|
|
16
54
|
{
|
|
17
|
-
Autocomplete:
|
|
18
|
-
GlobalApplicationCommand:
|
|
19
|
-
GuildApplicationCommand:
|
|
20
|
-
MessageComponent:
|
|
21
|
-
ModalSubmit:
|
|
55
|
+
Autocomplete: Chunk.empty(),
|
|
56
|
+
GlobalApplicationCommand: Chunk.empty(),
|
|
57
|
+
GuildApplicationCommand: Chunk.empty(),
|
|
58
|
+
MessageComponent: Chunk.empty(),
|
|
59
|
+
ModalSubmit: Chunk.empty(),
|
|
60
|
+
} as {
|
|
61
|
+
[K in D.InteractionDefinition<R, E>["_tag"]]: Chunk<
|
|
62
|
+
Extract<DefinitionFlattened<R, E, TE, A>, { _tag: K }>
|
|
63
|
+
>
|
|
22
64
|
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const Commands = [
|
|
26
|
-
...grouped.GlobalApplicationCommand,
|
|
27
|
-
...grouped.GuildApplicationCommand,
|
|
28
|
-
].reduce(
|
|
29
|
-
(acc, a) => ({
|
|
65
|
+
(acc, d) => ({
|
|
30
66
|
...acc,
|
|
31
|
-
[
|
|
67
|
+
[d._tag]: (acc[d._tag] as Chunk<any>).append(d),
|
|
32
68
|
}),
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
const Commands = grouped.GlobalApplicationCommand.concat(
|
|
72
|
+
grouped.GuildApplicationCommand,
|
|
73
|
+
).reduce(
|
|
74
|
+
{} as Record<string, DefinitionFlattenedCommand<R, E, TE, A>>,
|
|
75
|
+
(acc, d) =>
|
|
76
|
+
({
|
|
77
|
+
...acc,
|
|
78
|
+
[d.command.name]: d,
|
|
79
|
+
} as any),
|
|
37
80
|
)
|
|
38
81
|
|
|
39
82
|
return {
|
|
@@ -62,8 +62,21 @@ const fromHeadersAndBody = (headers: Headers, body: string) =>
|
|
|
62
62
|
)
|
|
63
63
|
})
|
|
64
64
|
|
|
65
|
-
const run = <R, E>(
|
|
66
|
-
|
|
65
|
+
const run = <R, E>(
|
|
66
|
+
definitions: Chunk<
|
|
67
|
+
readonly [
|
|
68
|
+
handler: D.InteractionDefinition<R, E>,
|
|
69
|
+
transform: (
|
|
70
|
+
self: Effect<R, E, Discord.InteractionResponse>,
|
|
71
|
+
) => Effect<R, E, Discord.InteractionResponse>,
|
|
72
|
+
]
|
|
73
|
+
>,
|
|
74
|
+
handleResponse: (
|
|
75
|
+
ix: Discord.Interaction,
|
|
76
|
+
_: Discord.InteractionResponse,
|
|
77
|
+
) => Effect<R, E, Discord.InteractionResponse>,
|
|
78
|
+
) => {
|
|
79
|
+
const handler = handlers(definitions, handleResponse)
|
|
67
80
|
return (headers: Headers, body: string) =>
|
|
68
81
|
Do($ => {
|
|
69
82
|
const interaction = $(fromHeadersAndBody(headers, body))
|
|
@@ -86,8 +99,11 @@ export interface HandleWebhookOpts<E> {
|
|
|
86
99
|
/**
|
|
87
100
|
* @tsplus getter dfx/InteractionBuilder webhookHandler
|
|
88
101
|
*/
|
|
89
|
-
export const makeHandler = <R, E>(ix: InteractionBuilder<R, E>) => {
|
|
90
|
-
const handle = run(
|
|
102
|
+
export const makeHandler = <R, E, TE>(ix: InteractionBuilder<R, E, TE>) => {
|
|
103
|
+
const handle = run(
|
|
104
|
+
ix.definitions.map(([d]) => [d, identity] as any),
|
|
105
|
+
(_i, r) => Effect.succeed(r),
|
|
106
|
+
)
|
|
91
107
|
|
|
92
108
|
return ({
|
|
93
109
|
headers,
|
|
@@ -102,8 +118,13 @@ export const makeHandler = <R, E>(ix: InteractionBuilder<R, E>) => {
|
|
|
102
118
|
/**
|
|
103
119
|
* @tsplus getter dfx/InteractionBuilder simpleWebhookHandler
|
|
104
120
|
*/
|
|
105
|
-
export const makeSimpleHandler = <R, E
|
|
106
|
-
|
|
121
|
+
export const makeSimpleHandler = <R, E, TE>(
|
|
122
|
+
ix: InteractionBuilder<R, E, TE>,
|
|
123
|
+
) => {
|
|
124
|
+
const handle = run(
|
|
125
|
+
ix.definitions.map(([d]) => [d, identity] as any),
|
|
126
|
+
(_i, r) => Effect.succeed(r),
|
|
127
|
+
)
|
|
107
128
|
|
|
108
129
|
return ({ headers, body }: { headers: Headers; body: string }) =>
|
|
109
130
|
handle(headers, body)
|
package/src/gateway.ts
CHANGED
|
@@ -11,7 +11,11 @@ export * as DiscordWS from "./DiscordGateway/DiscordWS.js"
|
|
|
11
11
|
export * as Shard from "./DiscordGateway/Shard.js"
|
|
12
12
|
export * as ShardStore from "./DiscordGateway/ShardStore.js"
|
|
13
13
|
export * as WS from "./DiscordGateway/WS.js"
|
|
14
|
-
export {
|
|
14
|
+
export {
|
|
15
|
+
InteractionsRegistry,
|
|
16
|
+
InteractionsRegistryLive,
|
|
17
|
+
run as runIx,
|
|
18
|
+
} from "./Interactions/gateway.js"
|
|
15
19
|
|
|
16
20
|
export const MemoryRateLimit = LiveMemoryRateLimitStore >> LiveRateLimiter
|
|
17
21
|
|
package/src/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dfx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"ws": "^8.13.0"
|
|
49
49
|
},
|
|
50
50
|
"sideEffects": false,
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "1120664f76fc34a00312d277c22007b37d623a30"
|
|
52
52
|
}
|