dfx 0.9.4 → 0.9.5

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/README.md CHANGED
@@ -1,3 +1,41 @@
1
1
  # dfx
2
2
 
3
- A Discord library for effect-ts
3
+ A Discord library built on top of @effect/io
4
+
5
+ - Supports both the gateway and webhooks
6
+ - Simple yet powerful abstractions to build Discord bots
7
+
8
+ ## Example
9
+
10
+ ```typescript
11
+ import * as Effect from "@effect/io/Effect"
12
+ import { pipe } from "@fp-ts/data/Function"
13
+ import { Ix, runIxGateway, makeLayer } from "dfx"
14
+
15
+ // Create the dependencies layer
16
+ const Dependencies = makeLayer({
17
+ token: "xxx",
18
+ })
19
+
20
+ // Create hello command that responds with "Hello!"
21
+ const hello = Ix.global(
22
+ {
23
+ name: "hello",
24
+ description: "A basic command",
25
+ },
26
+ Effect.succeedSome({
27
+ type: 4,
28
+ data: {
29
+ content: "Hello!",
30
+ },
31
+ }),
32
+ )
33
+
34
+ // Run it
35
+ pipe(
36
+ Ix.builder.add(hello),
37
+ runIxGateway((error) => Effect.fail(error)),
38
+ Effect.providerLayer(Dependencies),
39
+ Effect.unsafeRunPromise,
40
+ )
41
+ ```
@@ -3,5 +3,5 @@ import { InteractionBuilder } from "./index.js";
3
3
  export interface RunOpts {
4
4
  sync?: boolean;
5
5
  }
6
- export declare const run: <R, R2, E, E2>(ix: InteractionBuilder<R, E>, catchAll: (e: import("../Http/index.js").FetchError | import("../Http/index.js").StatusCodeError | import("../Http/index.js").JsonParseError | E) => import("../common.js").Effect<R2, E2, any>, { sync }?: RunOpts) => import("../common.js").Effect<import("../index.js").DiscordREST | import("../DiscordGateway/index.js").DiscordGateway | R | R2, import("../Http/index.js").FetchError | import("../Http/index.js").StatusCodeError | import("../Http/index.js").JsonParseError | E2, void>;
6
+ export declare const run: <R2, E, E2>(catchAll: (e: import("../Http/index.js").FetchError | import("../Http/index.js").StatusCodeError | import("../Http/index.js").JsonParseError | E) => import("../common.js").Effect<R2, E2, any>, { sync }?: RunOpts) => <R>(ix: InteractionBuilder<R, E>) => import("../common.js").Effect<import("../index.js").DiscordREST | import("../DiscordGateway/index.js").DiscordGateway | R2 | R, import("../Http/index.js").FetchError | import("../Http/index.js").StatusCodeError | import("../Http/index.js").JsonParseError | E2, void>;
7
7
  //# sourceMappingURL=gateway.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../src/Interactions/gateway.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAG/C,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED,eAAO,MAAM,GAAG,2PAKG,OAAO,+QAwCtB,CAAA"}
1
+ {"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../src/Interactions/gateway.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAG/C,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED,eAAO,MAAM,GAAG,0NAKK,OAAO,oTAyCtB,CAAA"}
@@ -4,7 +4,7 @@ import * as tsplus_module_3 from "@fp-ts/data/Option";
4
4
  import * as tsplus_module_4 from "dfx/common-gateway";
5
5
  import { handlers } from "./handlers.js";
6
6
  import { splitDefinitions } from "./utils.js";
7
- export const run = (ix, catchAll, { sync = true } = {}) => (() => {
7
+ export const run = (catchAll, { sync = true } = {}) => (ix) => (() => {
8
8
  const { GlobalApplicationCommand, GuildApplicationCommand } = splitDefinitions(ix.definitions);
9
9
  return tsplus_module_1.flatMap(application => {
10
10
  const globalSync = tsplus_module_2.Rest.rest.bulkOverwriteGlobalApplicationCommands(application.id, {
@@ -1 +1 @@
1
- {"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../src/Interactions/gateway.ts"],"names":[],"mappings":";;;;AAAA,OAAO,EAAE,QAAQ,EAAE,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AC7C,WAAW,CAAC,EAAE,EACd,CAAC,CAAC,EAAE,EACJ,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAQ,CACrD,CACF;YACH,CAAC,CAAC,sBAAa,CAAA;QAEjB,MAAM,MAAM,GAAG,QAAQ,CAAC,EAAE,CAAC,WAAW,CAAC,CAAA;QAEvC,MAAM,GAAG,GAAG,gBAAA,OAAO,CAAC,cAAc,CAAC,oBAAoB,EAAE,CAAC,CAAC,EAAE,EAAE,CAC7D,yBAMY,QAAQ,EANpB,oBACO,CAAC,CAAC,EAAE,EAAE,CACT,4CAAqB,CAAC,CAAC,EAAE,EAAE,CACzB,gBAAA,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,EADvD,CAAC,CAEA,EAJL,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAKd,CACkB,CACtB,CAAA;iDAEC,IAAI,CAAC,CAAC,CAAC,uBAA8B,SAAS,EAAvC,uBAAW,UAAU,EAArB,GAAG,CAAmB,CAAkB,CAAC,CAAC,CAAC,GAAG;OAhCrD,wBAAwD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAArE,gBAAA,IAAI,CAAC,IAAI,CAAC,mCAAmC,EAAE,CAAuB;IAiCxE,CAAA"}
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export * as DiscordWS from "./DiscordGateway/DiscordWS/index.js";
5
5
  export * as Gateway from "./DiscordGateway/index.js";
6
6
  export { DiscordREST, LiveDiscordREST, rest } from "./DiscordREST/index.js";
7
7
  export * as Ix from "./Interactions/index.js";
8
- export { run as IxRunGateway } from "./Interactions/gateway.js";
8
+ export { run as runIxGateway } from "./Interactions/gateway.js";
9
9
  export * as Log from "./Log/index.js";
10
10
  export * as RateLimitStore from "./RateLimitStore/index.js";
11
11
  export * as Flags from "./Helpers/flags.js";
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ export * as DiscordWS from "./DiscordGateway/DiscordWS/index.js";
7
7
  export * as Gateway from "./DiscordGateway/index.js";
8
8
  export { DiscordREST, LiveDiscordREST, rest } from "./DiscordREST/index.js";
9
9
  export * as Ix from "./Interactions/index.js";
10
- export { run as IxRunGateway } from "./Interactions/gateway.js";
10
+ export { run as runIxGateway } from "./Interactions/gateway.js";
11
11
  export * as Log from "./Log/index.js";
12
12
  export * as RateLimitStore from "./RateLimitStore/index.js";
13
13
  export * as Flags from "./Helpers/flags.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dfx",
3
- "version": "0.9.4",
3
+ "version": "0.9.5",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -50,5 +50,5 @@
50
50
  "@fp-ts/data": "^0.0.20"
51
51
  }
52
52
  },
53
- "gitHead": "7b4807d4e97e8bdd5a4b6efb7679e81fa60401bf"
53
+ "gitHead": "138bb3ca8bee27e8fb9b66916ed1b75c2751198b"
54
54
  }
@@ -6,49 +6,50 @@ export interface RunOpts {
6
6
  sync?: boolean
7
7
  }
8
8
 
9
- export const run = <R, R2, E, E2>(
10
- ix: InteractionBuilder<R, E>,
11
- catchAll: (
12
- e: Http.FetchError | Http.StatusCodeError | Http.JsonParseError | E,
13
- ) => Effect<R2, E2, any>,
14
- { sync = true }: RunOpts = {},
15
- ) =>
16
- Do(($) => {
17
- const { GlobalApplicationCommand, GuildApplicationCommand } =
18
- splitDefinitions(ix.definitions)
19
-
20
- const application = $(
21
- Rest.rest.getCurrentBotApplicationInformation().flatMap((a) => a.json),
22
- )
23
-
24
- const globalSync = Rest.rest.bulkOverwriteGlobalApplicationCommands(
25
- application.id,
26
- {
27
- body: JSON.stringify(GlobalApplicationCommand.map((a) => a.command)),
28
- },
29
- )
30
-
31
- const guildSync = GuildApplicationCommand.length
32
- ? Gateway.handleDispatch("GUILD_CREATE", (a) =>
33
- Rest.rest.bulkOverwriteGuildApplicationCommands(
34
- application.id,
35
- a.id,
36
- GuildApplicationCommand.map((a) => a.command) as any,
37
- ),
38
- )
39
- : Effect.unit()
40
-
41
- const handle = handlers(ix.definitions)
42
-
43
- const run = Gateway.handleDispatch("INTERACTION_CREATE", (i) =>
44
- handle[i.type](i)
45
- .tap((r) =>
46
- r.match(Effect.unit, (r) =>
47
- Rest.rest.createInteractionResponse(i.id, i.token, r),
48
- ),
49
- )
50
- .catchAll(catchAll),
51
- )
52
-
53
- $(sync ? run.zipPar(globalSync).zipPar(guildSync) : run)
54
- })
9
+ export const run =
10
+ <R2, E, E2>(
11
+ catchAll: (
12
+ e: Http.FetchError | Http.StatusCodeError | Http.JsonParseError | E,
13
+ ) => Effect<R2, E2, any>,
14
+ { sync = true }: RunOpts = {},
15
+ ) =>
16
+ <R>(ix: InteractionBuilder<R, E>) =>
17
+ Do(($) => {
18
+ const { GlobalApplicationCommand, GuildApplicationCommand } =
19
+ splitDefinitions(ix.definitions)
20
+
21
+ const application = $(
22
+ Rest.rest.getCurrentBotApplicationInformation().flatMap((a) => a.json),
23
+ )
24
+
25
+ const globalSync = Rest.rest.bulkOverwriteGlobalApplicationCommands(
26
+ application.id,
27
+ {
28
+ body: JSON.stringify(GlobalApplicationCommand.map((a) => a.command)),
29
+ },
30
+ )
31
+
32
+ const guildSync = GuildApplicationCommand.length
33
+ ? Gateway.handleDispatch("GUILD_CREATE", (a) =>
34
+ Rest.rest.bulkOverwriteGuildApplicationCommands(
35
+ application.id,
36
+ a.id,
37
+ GuildApplicationCommand.map((a) => a.command) as any,
38
+ ),
39
+ )
40
+ : Effect.unit()
41
+
42
+ const handle = handlers(ix.definitions)
43
+
44
+ const run = Gateway.handleDispatch("INTERACTION_CREATE", (i) =>
45
+ handle[i.type](i)
46
+ .tap((r) =>
47
+ r.match(Effect.unit, (r) =>
48
+ Rest.rest.createInteractionResponse(i.id, i.token, r),
49
+ ),
50
+ )
51
+ .catchAll(catchAll),
52
+ )
53
+
54
+ $(sync ? run.zipPar(globalSync).zipPar(guildSync) : run)
55
+ })
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ export * as DiscordWS from "./DiscordGateway/DiscordWS/index.js"
5
5
  export * as Gateway from "./DiscordGateway/index.js"
6
6
  export { DiscordREST, LiveDiscordREST, rest } from "./DiscordREST/index.js"
7
7
  export * as Ix from "./Interactions/index.js"
8
- export { run as IxRunGateway } from "./Interactions/gateway.js"
8
+ export { run as runIxGateway } from "./Interactions/gateway.js"
9
9
  export * as Log from "./Log/index.js"
10
10
  export * as RateLimitStore from "./RateLimitStore/index.js"
11
11