dfx 0.42.9 → 0.43.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.
@@ -1,6 +1,7 @@
1
1
  import { ConfigSecret, Duration, Discord, Config } from "dfx/_common";
2
2
  export interface DiscordConfig {
3
3
  token: ConfigSecret;
4
+ debug: boolean;
4
5
  rest: {
5
6
  baseUrl: string;
6
7
  globalRateLimit: {
@@ -18,9 +19,10 @@ export interface DiscordConfig {
18
19
  export declare const DiscordConfig: import("@effect/data/Context").Tag<DiscordConfig, DiscordConfig>;
19
20
  export interface MakeOpts {
20
21
  token: ConfigSecret;
22
+ debug?: boolean;
21
23
  rest?: Partial<DiscordConfig["rest"]>;
22
24
  gateway?: Partial<DiscordConfig["gateway"]>;
23
25
  }
24
- export declare const make: ({ token, rest, gateway }: MakeOpts) => DiscordConfig;
26
+ export declare const make: ({ token, debug, rest, gateway, }: MakeOpts) => DiscordConfig;
25
27
  export declare const makeLayer: (a_0: MakeOpts) => import("@effect-http/client/_common").Layer<never, never, DiscordConfig>;
26
28
  export declare const makeFromConfig: (_: Config.Wrap<MakeOpts>) => import("@effect-http/client/_common").Layer<never, import("./_common.js").ConfigError, DiscordConfig>;
package/DiscordConfig.js CHANGED
@@ -6,8 +6,9 @@ import * as tsplus_module_5 from "@effect/io/Config";
6
6
  import * as tsplus_module_6 from "@effect/io/Effect";
7
7
  const VERSION = 10;
8
8
  export const DiscordConfig = tsplus_module_1.Tag();
9
- export const make = ({ token, rest, gateway }) => ({
9
+ export const make = ({ token, debug = false, rest, gateway, }) => ({
10
10
  token,
11
+ debug,
11
12
  rest: {
12
13
  baseUrl: `https://discord.com/api/v${VERSION}`,
13
14
  ...(rest ?? {}),
@@ -1 +1 @@
1
- {"version":3,"file":"DiscordConfig.js","sourceRoot":"","sources":["src/DiscordConfig.ts"],"names":[],"mappings":";;;;;;AAAA,MAAM,OAAO,GAAG,EAAE,CAAA;AAmBlB,MAAM,CAAC,MAAM,a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AO,EAAE,4BAA4B,OAAO,EAAE;QAC9C,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;QACf,eAAe,EAAE;YACf,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,wBAAiB,CAAC,CAAC;YAC3B,GAAG,CAAC,IAAI,EAAE,eAAe,IAAI,EAAE,CAAC;SACjC;KACF;IACD,OAAO,EAAE;QACP,OAAO,EAAE,gBAAA,OAAO,CAAC,cAAc,CAAC,MAAM;QACtC,iBAAiB,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5B,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;KACnB;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,gBAAA,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,wBAAc,aAAa,EAAE,CAAC,CAAC,CAAC,CAAA;AACzE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAwB,EAAE,EAAE,CACzD,wBAAA,2CAAA,uBAAc,CAAC,CAAC,GAAY,IAAI,CAAC,EAAS,aAAa,CAAC,CAAA"}
@@ -2,10 +2,10 @@ import { Hub, Discord, Effect } from "dfx/_common";
2
2
  import { DiscordConfig } from "dfx/DiscordConfig";
3
3
  import { RateLimiter } from "dfx/RateLimit";
4
4
  import { DiscordWS } from "./DiscordWS.js";
5
- export declare const make: import("@effect/io/Effect").Effect<DiscordConfig | RateLimiter | DiscordWS, never, {
5
+ import { Log } from "dfx/Log";
6
+ export declare const make: import("@effect/io/Effect").Effect<DiscordConfig | Log | RateLimiter | DiscordWS, never, {
6
7
  readonly connect: (shard: [id: number, count: number], hub: Hub<Discord.GatewayPayload<Discord.ReceiveEvent>>) => import("@effect/io/Effect").Effect<never, never, {
7
8
  readonly run: import("@effect/io/Effect").Effect<never, import("./WS.js").WebSocketError | import("./WS.js").WebSocketCloseError, never>;
8
- readonly connected: import("@effect/io/Effect").Effect<never, never, boolean>;
9
9
  readonly send: (p: Discord.GatewayPayload) => import("@effect/io/Effect").Effect<never, never, boolean>;
10
10
  readonly reconnect: import("@effect/io/Effect").Effect<never, never, boolean>;
11
11
  }>;
@@ -13,4 +13,4 @@ export declare const make: import("@effect/io/Effect").Effect<DiscordConfig | Ra
13
13
  export interface Shard extends Effect.Success<typeof make> {
14
14
  }
15
15
  export declare const Shard: import("@effect/data/Context").Tag<Shard, Shard>;
16
- export declare const LiveShard: import("@effect-http/client/_common").Layer<DiscordConfig | import("../Log.js").Log | import("dfx/RateLimit").RateLimitStore | import("./DiscordWS.js").DiscordWSCodec, never, Shard>;
16
+ export declare const LiveShard: import("@effect-http/client/_common").Layer<DiscordConfig | Log | import("dfx/RateLimit").RateLimitStore | import("./DiscordWS.js").DiscordWSCodec, never, Shard>;
@@ -1,10 +1,10 @@
1
- import * as tsplus_module_1 from "@effect/io/Ref";
2
- import * as tsplus_module_2 from "@effect/io/Effect";
3
- import * as tsplus_module_3 from "dfx/_common";
4
- import * as tsplus_module_4 from "@effect/io/Config/Secret";
5
- import * as tsplus_module_5 from "@effect/io/Queue";
6
- import * as tsplus_module_6 from "@effect/data/Option";
7
- import * as tsplus_module_7 from "@effect/data/Chunk";
1
+ import * as tsplus_module_1 from "@effect/io/Effect";
2
+ import * as tsplus_module_2 from "dfx/_common";
3
+ import * as tsplus_module_3 from "@effect/io/Config/Secret";
4
+ import * as tsplus_module_4 from "@effect/io/Queue";
5
+ import * as tsplus_module_5 from "@effect/data/Option";
6
+ import * as tsplus_module_6 from "@effect/data/Chunk";
7
+ import * as tsplus_module_7 from "@effect/io/Ref";
8
8
  import * as tsplus_module_8 from "@effect/data/Duration";
9
9
  import * as tsplus_module_9 from "@effect/io/Layer";
10
10
  import { DiscordConfig } from "dfx/DiscordConfig";
@@ -15,57 +15,63 @@ import * as Identify from "./Shard/identify.js";
15
15
  import * as InvalidSession from "./Shard/invalidSession.js";
16
16
  import * as Utils from "./Shard/utils.js";
17
17
  import { Reconnect } from "./WS.js";
18
- export const make = tsplus_module_2.flatMap(DiscordConfig, ({ token, gateway }) => tsplus_module_2.flatMap(RateLimiter, limiter => tsplus_module_2.map(DiscordWS, dws => {
19
- const connect = (shard, hub) => tsplus_module_2.flatMap(tsplus_module_5.unbounded(), outboundQueue => tsplus_module_2.flatMap(tsplus_module_5.unbounded(), pendingQueue => tsplus_module_2.flatMap(tsplus_module_1.make(true), connecting => {
20
- const outbound = tsplus_module_2.tap(outboundQueue
18
+ import { Log } from "dfx/Log";
19
+ export const make = tsplus_module_1.flatMap(DiscordConfig, ({ token, gateway }) => tsplus_module_1.flatMap(RateLimiter, limiter => tsplus_module_1.flatMap(DiscordWS, dws => tsplus_module_1.map(Log, log => {
20
+ const connect = (shard, hub) => tsplus_module_1.flatMap(tsplus_module_4.unbounded(), outboundQueue => tsplus_module_1.flatMap(tsplus_module_4.unbounded(), pendingQueue => tsplus_module_1.flatMap(tsplus_module_7.make(0 /* Phase.Connecting */), phase => {
21
+ const setPhase = (p) => tsplus_module_1.zipLeft(tsplus_module_7.set(phase, p), log.debug("Shard", shard, "phase", p));
22
+ const outbound = tsplus_module_1.tap(outboundQueue
21
23
  .take(), () => limiter.maybeWait("dfx.shard.send", tsplus_module_8.minutes(1), 120));
22
- const send = (p) => tsplus_module_2.flatMap(tsplus_module_1.get(connecting), _ => _ ? pendingQueue.offer(p) : outboundQueue.offer(p));
24
+ const send = (p) => tsplus_module_1.flatMap(tsplus_module_7.get(phase), _ => _ === 2 /* Phase.Connected */
25
+ ? outboundQueue.offer(p)
26
+ : pendingQueue.offer(p));
27
+ const heartbeatSend = (p) => tsplus_module_1.flatMap(tsplus_module_7.get(phase), _ => _ !== 0 /* Phase.Connecting */
28
+ ? outboundQueue.offer(p)
29
+ : tsplus_module_1.succeed(false));
23
30
  const prioritySend = (p) => outboundQueue.offer(p);
24
- const resume = tsplus_module_2.asUnit(tsplus_module_2.tap(tsplus_module_2.zipRight(tsplus_module_1.set(connecting, false), pendingQueue.takeAll()), _ => outboundQueue.offerAll(_)));
25
- const onReconnect = tsplus_module_2.zipRight(tsplus_module_2.tap(outboundQueue
26
- .takeAll(), _ => pendingQueue.offerAll(tsplus_module_7.filter(_, msg => msg !== Reconnect &&
31
+ const resume = tsplus_module_1.asUnit(tsplus_module_1.tap(tsplus_module_1.zipRight(setPhase(2 /* Phase.Connected */), pendingQueue.takeAll()), _ => outboundQueue.offerAll(_)));
32
+ const onReconnect = tsplus_module_1.zipRight(tsplus_module_1.tap(outboundQueue
33
+ .takeAll(), _ => pendingQueue.offerAll(tsplus_module_6.filter(_, msg => msg !== Reconnect &&
27
34
  msg.op !== 2 /* Discord.GatewayOpcode.IDENTIFY */ &&
28
35
  msg.op !== 6 /* Discord.GatewayOpcode.RESUME */ &&
29
- msg.op !== 1 /* Discord.GatewayOpcode.HEARTBEAT */))), tsplus_module_1.set(connecting, true));
30
- return tsplus_module_2.flatMap(dws.connect({ outbound, onReconnect }), socket => tsplus_module_2.flatMap(Utils.latest(p => tsplus_module_6.map(tsplus_module_6.filter((p) => p.op === 0 /* Discord.GatewayOpcode.DISPATCH */ && p.t === "READY")(tsplus_module_6.some(p)), p => p.d)), ([latestReady, updateLatestReady]) => tsplus_module_2.flatMap(Utils.latest(p => tsplus_module_6.fromNullable(p.s)), ([latestSequence, updateLatestSequence]) => {
31
- const maybeUpdateUrl = (p) => tsplus_module_6.match(tsplus_module_6.map(tsplus_module_6.filter((p) => p.op === 0 /* Discord.GatewayOpcode.DISPATCH */ && p.t === "READY")(tsplus_module_6.some(p)), p => p.d), () => tsplus_module_2.unit(), a => socket.setUrl(a.resume_gateway_url));
32
- return tsplus_module_2.flatMap(tsplus_module_5.unbounded(), hellos => tsplus_module_2.map(tsplus_module_5.unbounded(), acks => {
36
+ msg.op !== 1 /* Discord.GatewayOpcode.HEARTBEAT */))), setPhase(0 /* Phase.Connecting */));
37
+ return tsplus_module_1.flatMap(dws.connect({ outbound, onReconnect }), socket => tsplus_module_1.flatMap(Utils.latest(p => tsplus_module_5.map(tsplus_module_5.filter((p) => p.op === 0 /* Discord.GatewayOpcode.DISPATCH */ && p.t === "READY")(tsplus_module_5.some(p)), p => p.d)), ([latestReady, updateLatestReady]) => tsplus_module_1.flatMap(Utils.latest(p => tsplus_module_5.fromNullable(p.s)), ([latestSequence, updateLatestSequence]) => {
38
+ const maybeUpdateUrl = (p) => tsplus_module_5.match(tsplus_module_5.map(tsplus_module_5.filter((p) => p.op === 0 /* Discord.GatewayOpcode.DISPATCH */ && p.t === "READY")(tsplus_module_5.some(p)), p => p.d), () => tsplus_module_1.unit(), a => socket.setUrl(a.resume_gateway_url));
39
+ return tsplus_module_1.flatMap(tsplus_module_4.unbounded(), hellos => tsplus_module_1.map(tsplus_module_4.unbounded(), acks => {
33
40
  // heartbeats
34
- const heartbeats = Heartbeats.send(hellos, acks, latestSequence, send);
41
+ const heartbeats = Heartbeats.send(hellos, acks, latestSequence, heartbeatSend);
35
42
  // identify
36
43
  const identify = Identify.identifyOrResume({
37
- token: tsplus_module_4.value(token),
44
+ token: tsplus_module_3.value(token),
38
45
  shard,
39
46
  intents: gateway.intents,
40
47
  presence: gateway.presence,
41
48
  }, latestReady, latestSequence);
42
- const onPayload = (p) => tsplus_module_2.flatMap(tsplus_module_2.zipPar(tsplus_module_2.zipPar(updateLatestReady(p), updateLatestSequence(p)), maybeUpdateUrl(p)), () => {
43
- let effect = tsplus_module_2.unit();
49
+ const onPayload = (p) => tsplus_module_1.flatMap(tsplus_module_1.zipPar(tsplus_module_1.zipPar(updateLatestReady(p), updateLatestSequence(p)), maybeUpdateUrl(p)), () => {
50
+ let effect = tsplus_module_1.unit();
44
51
  switch (p.op) {
45
52
  case 10 /* Discord.GatewayOpcode.HELLO */:
46
- effect = tsplus_module_2.zipPar(tsplus_module_2.tap(identify, prioritySend), hellos.offer(p));
53
+ effect = tsplus_module_1.zipPar(tsplus_module_1.tap(identify, prioritySend), tsplus_module_1.zipRight(setPhase(1 /* Phase.Handshake */), hellos.offer(p)));
47
54
  break;
48
55
  case 11 /* Discord.GatewayOpcode.HEARTBEAT_ACK */:
49
56
  effect = acks.offer(p);
50
57
  break;
51
58
  case 9 /* Discord.GatewayOpcode.INVALID_SESSION */:
52
- effect = tsplus_module_2.tap(InvalidSession.fromPayload(p, latestReady), send);
59
+ effect = tsplus_module_1.tap(InvalidSession.fromPayload(p, latestReady), send);
53
60
  break;
54
61
  case 0 /* Discord.GatewayOpcode.DISPATCH */:
55
62
  if (p.t === "READY" || p.t === "RESUMED") {
56
- effect = tsplus_module_2.zipRight(resume, hub.publish(p));
63
+ effect = tsplus_module_1.zipRight(resume, hub.publish(p));
57
64
  }
58
65
  else {
59
66
  effect = hub.publish(p);
60
67
  }
61
68
  break;
62
69
  }
63
- return tsplus_module_2.map(effect, () => void 0);
70
+ return tsplus_module_1.map(effect, () => void 0);
64
71
  });
65
- const run = tsplus_module_2.zipParLeft(tsplus_module_2.zipParLeft(tsplus_module_2.forever(tsplus_module_2.flatMap(socket.take, onPayload)), heartbeats), socket.run);
72
+ const run = tsplus_module_1.zipParLeft(tsplus_module_1.zipParLeft(tsplus_module_1.forever(tsplus_module_1.flatMap(socket.take, onPayload)), heartbeats), socket.run);
66
73
  return {
67
74
  run,
68
- connected: tsplus_module_1.get(connecting),
69
75
  send: (p) => send(p),
70
76
  reconnect: send(Reconnect),
71
77
  };
@@ -73,7 +79,7 @@ export const make = tsplus_module_2.flatMap(DiscordConfig, ({ token, gateway })
73
79
  })));
74
80
  })));
75
81
  return { connect };
76
- })));
77
- export const Shard = tsplus_module_3.Tag();
78
- export const LiveShard = tsplus_module_9.provide(tsplus_module_2.toLayer(make, Shard))((tsplus_module_9.merge(LiveRateLimiter)(LiveDiscordWS)));
82
+ }))));
83
+ export const Shard = tsplus_module_2.Tag();
84
+ export const LiveShard = tsplus_module_9.provide(tsplus_module_1.toLayer(make, Shard))((tsplus_module_9.merge(LiveRateLimiter)(LiveDiscordWS)));
79
85
  //# sourceMappingURL=Shard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Shard.js","sourceRoot":"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,EAAK,IAAI,CAAC,CAAA;4BAC7D,MAAK;wBACP;4BACE,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;gCACxC,MAAM,GAAG,yBAAA,MAAM,EAAU,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;6BACzC;iCAAM;gCACL,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;6BACxB;4BACD,MAAK;qBACR;+CAEC,MAAM;kBACR,CAAA;gBAEJ,MAAM,GAAG,GAAG,2BAAA,mDAAA,wBAAA,MAAM,CAAC,IAAI,EACZ,SAAS,CAAC,GACC,UAAU,CAAC,EACnB,MAAM,CAAC,GAAG,CAAC,CAAA;gBAEzB,OAAO;oBACL,GAAG;oBACH,IAAI,EAAE,CAAC,CAAyB,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;oBAC5C,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC;iBAClB,CAAA;;;QACV,CAAA;IAEJ,OAAO,EAAE,OAAO,EAAW,CAAA;KAC3B,CAAA;AAGF,MAAM,CAAC,MAAM,KAAK,GAAG,gBAAA,GAAG,EAAS,CAAA;AACjC,MAAM,CAAC,MAAM,SAAS,2BACiB,wBAAA,IAAI,EAAS,KAAK,CAAC,EAAxD,uBAAiB,eAAe,EAA/B,aAAa,EAAmB,CAAuB,CAAA"}
package/gateway.d.ts CHANGED
@@ -9,5 +9,5 @@ export * as WS from "./DiscordGateway/WS.js";
9
9
  export { run as runIx } from "./Interactions/gateway.js";
10
10
  export declare const MemoryRateLimit: import("@effect-http/client/_common").Layer<Log.Log, never, import("dfx").RateLimiter>;
11
11
  export declare const MemoryBot: import("@effect-http/client/_common").Layer<DiscordConfig.DiscordConfig | Log.Log | import("@effect-http/client").HttpRequestExecutor, never, import("dfx").DiscordREST | import("dfx").RateLimiter | import("./DiscordGateway.js").DiscordGateway>;
12
- export declare const makeLiveWithoutFetch: (config: Config.Wrap<DiscordConfig.MakeOpts>, debug?: boolean) => import("@effect-http/client/_common").Layer<import("@effect-http/client").HttpRequestExecutor, import("./_common.js").ConfigError, import("dfx").DiscordREST | DiscordConfig.DiscordConfig | Log.Log | import("dfx").RateLimiter | import("./DiscordGateway.js").DiscordGateway>;
13
- export declare const makeLive: (config: Config.Wrap<DiscordConfig.MakeOpts>, debug?: boolean) => import("@effect-http/client/_common").Layer<never, import("./_common.js").ConfigError, import("dfx").DiscordREST | DiscordConfig.DiscordConfig | Log.Log | import("dfx").RateLimiter | import("./DiscordGateway.js").DiscordGateway>;
12
+ export declare const makeLiveWithoutFetch: (config: Config.Wrap<DiscordConfig.MakeOpts>) => import("@effect-http/client/_common").Layer<import("@effect-http/client").HttpRequestExecutor, import("./_common.js").ConfigError, import("dfx").DiscordREST | DiscordConfig.DiscordConfig | Log.Log | import("dfx").RateLimiter | import("./DiscordGateway.js").DiscordGateway>;
13
+ export declare const makeLive: (config: Config.Wrap<DiscordConfig.MakeOpts>) => import("@effect-http/client/_common").Layer<never, import("./_common.js").ConfigError, import("dfx").DiscordREST | DiscordConfig.DiscordConfig | Log.Log | import("dfx").RateLimiter | import("./DiscordGateway.js").DiscordGateway>;
package/gateway.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as tsplus_module_1 from "@effect/io/Layer";
2
2
  import * as tsplus_module_2 from "@effect/io/Config";
3
+ import * as tsplus_module_3 from "@effect/io/Effect";
3
4
  import { LiveFetchRequestExecutor } from "@effect-http/client";
4
5
  import { DiscordConfig, LiveDiscordREST, Log } from "dfx";
5
6
  import { LiveDiscordGateway } from "./DiscordGateway.js";
@@ -15,13 +16,10 @@ export * as WS from "./DiscordGateway/WS.js";
15
16
  export { run as runIx } from "./Interactions/gateway.js";
16
17
  export const MemoryRateLimit = tsplus_module_1.provide(LiveRateLimiter)(LiveMemoryRateLimitStore);
17
18
  export const MemoryBot = tsplus_module_1.provide((tsplus_module_1.merge(MemoryRateLimit)((tsplus_module_1.provideMerge(LiveDiscordGateway)(LiveDiscordREST)))))((tsplus_module_1.merge(LiveJsonDiscordWSCodec)(tsplus_module_1.merge(LiveMemoryRateLimitStore)(LiveMemoryShardStore))));
18
- export const makeLiveWithoutFetch = (config, debug = false) => {
19
- const LiveLog = debug ? Log.LiveLogDebug : Log.LiveLog;
20
- const LiveConfig = DiscordConfig.makeFromConfig(tsplus_module_2.unwrap(config));
21
- const LiveEnv = tsplus_module_1.provideMerge(MemoryBot)(tsplus_module_1.merge(LiveConfig)(LiveLog));
22
- return LiveEnv;
23
- };
24
- export const makeLive = (config, debug = false) => {
25
- return tsplus_module_1.provide(makeLiveWithoutFetch(config, debug))(LiveFetchRequestExecutor);
26
- };
19
+ export const makeLiveWithoutFetch = (config) => tsplus_module_1.unwrapEffect(tsplus_module_3.map(tsplus_module_3.map(tsplus_module_3.config(tsplus_module_2.unwrap(config)), DiscordConfig.make), config => {
20
+ const LiveLog = config.debug ? Log.LiveLogDebug : Log.LiveLog;
21
+ const LiveConfig = tsplus_module_1.succeed(DiscordConfig.DiscordConfig, config);
22
+ return tsplus_module_1.provideMerge(MemoryBot)(tsplus_module_1.merge(LiveConfig)(LiveLog));
23
+ }));
24
+ export const makeLive = (config) => tsplus_module_1.provide(makeLiveWithoutFetch(config))(LiveFetchRequestExecutor);
27
25
  //# sourceMappingURL=gateway.js.map
package/gateway.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"gateway.js","sourceRoot":"","sources":["src/gateway.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAA;AACrE,OAA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AAK,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAA;IAC7D,MAAM,UAAU,GAAG,wBAAc,aAAa,CAAC,aAAa,EAAE,MAAM,CAAC,CAAA;IACrE,oCAA8B,SAAS,wBAAtB,UAAU,EAApB,OAAO,GAAyB;AACzC,CAAC,CAAC,CACL,CAAA;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAA2C,EAAE,EAAE,yBAC1C,oBAAoB,CAAC,MAAM,CAAC,EAAxD,wBAAwB,CAAgC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dfx",
3
- "version": "0.42.9",
3
+ "version": "0.43.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": "b08e88268d84b1ffce21cf1f4518354518902edb"
51
+ "gitHead": "eb969e6b2d8ac1c0a5ab877898feae57728b5e3c"
52
52
  }
@@ -2,6 +2,7 @@ const VERSION = 10
2
2
 
3
3
  export interface DiscordConfig {
4
4
  token: ConfigSecret
5
+ debug: boolean
5
6
  rest: {
6
7
  baseUrl: string
7
8
  globalRateLimit: {
@@ -21,12 +22,19 @@ export const DiscordConfig = Tag<DiscordConfig>()
21
22
 
22
23
  export interface MakeOpts {
23
24
  token: ConfigSecret
25
+ debug?: boolean
24
26
  rest?: Partial<DiscordConfig["rest"]>
25
27
  gateway?: Partial<DiscordConfig["gateway"]>
26
28
  }
27
29
 
28
- export const make = ({ token, rest, gateway }: MakeOpts): DiscordConfig => ({
30
+ export const make = ({
29
31
  token,
32
+ debug = false,
33
+ rest,
34
+ gateway,
35
+ }: MakeOpts): DiscordConfig => ({
36
+ token,
37
+ debug,
30
38
  rest: {
31
39
  baseUrl: `https://discord.com/api/v${VERSION}`,
32
40
  ...(rest ?? {}),
@@ -6,11 +6,19 @@ import * as Identify from "./Shard/identify.js"
6
6
  import * as InvalidSession from "./Shard/invalidSession.js"
7
7
  import * as Utils from "./Shard/utils.js"
8
8
  import { Reconnect } from "./WS.js"
9
+ import { Log } from "dfx/Log"
10
+
11
+ const enum Phase {
12
+ Connecting,
13
+ Handshake,
14
+ Connected,
15
+ }
9
16
 
10
17
  export const make = Do($ => {
11
18
  const { token, gateway } = $(DiscordConfig)
12
19
  const limiter = $(RateLimiter)
13
20
  const dws = $(DiscordWS)
21
+ const log = $(Log)
14
22
 
15
23
  const connect = (
16
24
  shard: [id: number, count: number],
@@ -19,7 +27,9 @@ export const make = Do($ => {
19
27
  Do($ => {
20
28
  const outboundQueue = $(Queue.unbounded<Message>())
21
29
  const pendingQueue = $(Queue.unbounded<Message>())
22
- const connecting = $(Ref.make(true))
30
+ const phase = $(Ref.make(Phase.Connecting))
31
+ const setPhase = (p: Phase) =>
32
+ phase.set(p).zipLeft(log.debug("Shard", shard, "phase", p))
23
33
  const outbound = outboundQueue
24
34
  .take()
25
35
  .tap(() =>
@@ -27,14 +37,22 @@ export const make = Do($ => {
27
37
  )
28
38
 
29
39
  const send = (p: Message) =>
30
- connecting.get.flatMap(_ =>
31
- _ ? pendingQueue.offer(p) : outboundQueue.offer(p),
40
+ phase.get.flatMap(_ =>
41
+ _ === Phase.Connected
42
+ ? outboundQueue.offer(p)
43
+ : pendingQueue.offer(p),
44
+ )
45
+
46
+ const heartbeatSend = (p: Message) =>
47
+ phase.get.flatMap(_ =>
48
+ _ !== Phase.Connecting
49
+ ? outboundQueue.offer(p)
50
+ : Effect.succeed(false),
32
51
  )
33
52
 
34
53
  const prioritySend = (p: Message) => outboundQueue.offer(p)
35
54
 
36
- const resume = connecting
37
- .set(false)
55
+ const resume = setPhase(Phase.Connected)
38
56
  .zipRight(pendingQueue.takeAll())
39
57
  .tap(_ => outboundQueue.offerAll(_)).asUnit
40
58
 
@@ -51,7 +69,7 @@ export const make = Do($ => {
51
69
  ),
52
70
  ),
53
71
  )
54
- .zipRight(connecting.set(true))
72
+ .zipRight(setPhase(Phase.Connecting))
55
73
 
56
74
  const socket = $(dws.connect({ outbound, onReconnect }))
57
75
 
@@ -84,7 +102,12 @@ export const make = Do($ => {
84
102
  const acks = $(Queue.unbounded<Discord.GatewayPayload>())
85
103
 
86
104
  // heartbeats
87
- const heartbeats = Heartbeats.send(hellos, acks, latestSequence, send)
105
+ const heartbeats = Heartbeats.send(
106
+ hellos,
107
+ acks,
108
+ latestSequence,
109
+ heartbeatSend,
110
+ )
88
111
 
89
112
  // identify
90
113
  const identify = Identify.identifyOrResume(
@@ -110,7 +133,9 @@ export const make = Do($ => {
110
133
 
111
134
  switch (p.op) {
112
135
  case Discord.GatewayOpcode.HELLO:
113
- effect = identify.tap(prioritySend).zipPar(hellos.offer(p))
136
+ effect = identify
137
+ .tap(prioritySend)
138
+ .zipPar(setPhase(Phase.Handshake).zipRight(hellos.offer(p)))
114
139
  break
115
140
  case Discord.GatewayOpcode.HEARTBEAT_ACK:
116
141
  effect = acks.offer(p)
@@ -137,7 +162,6 @@ export const make = Do($ => {
137
162
 
138
163
  return {
139
164
  run,
140
- connected: connecting.get,
141
165
  send: (p: Discord.GatewayPayload) => send(p),
142
166
  reconnect: send(Reconnect),
143
167
  } as const
package/src/gateway.ts CHANGED
@@ -21,18 +21,16 @@ export const MemoryBot =
21
21
 
22
22
  export const makeLiveWithoutFetch = (
23
23
  config: Config.Wrap<DiscordConfig.MakeOpts>,
24
- debug = false,
25
- ) => {
26
- const LiveLog = debug ? Log.LiveLogDebug : Log.LiveLog
27
- const LiveConfig = DiscordConfig.makeFromConfig(Config.unwrap(config))
28
- const LiveEnv = LiveLog + LiveConfig > MemoryBot
24
+ ) =>
25
+ Layer.unwrapEffect(
26
+ Config.unwrap(config)
27
+ .config.map(DiscordConfig.make)
28
+ .map(config => {
29
+ const LiveLog = config.debug ? Log.LiveLogDebug : Log.LiveLog
30
+ const LiveConfig = Layer.succeed(DiscordConfig.DiscordConfig, config)
31
+ return LiveLog + LiveConfig > MemoryBot
32
+ }),
33
+ )
29
34
 
30
- return LiveEnv
31
- }
32
-
33
- export const makeLive = (
34
- config: Config.Wrap<DiscordConfig.MakeOpts>,
35
- debug = false,
36
- ) => {
37
- return LiveFetchRequestExecutor >> makeLiveWithoutFetch(config, debug)
38
- }
35
+ export const makeLive = (config: Config.Wrap<DiscordConfig.MakeOpts>) =>
36
+ LiveFetchRequestExecutor >> makeLiveWithoutFetch(config)
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "dfx",
3
+ "version": "0.43.0",
4
+ "type": "module",
5
+ "publishConfig": {
6
+ "access": "public",
7
+ "directory": "dist"
8
+ },
9
+ "description": "Effect-TS discord library",
10
+ "author": "Tim Smart <hello@timsmart.co>",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/tim-smart/dfx.git"
14
+ },
15
+ "license": "MIT",
16
+ "scripts": {
17
+ "prepublishOnly": "make build",
18
+ "types": "discord-api-codegen ./discord-api-docs -l typescript -o 'imports=RestResponse|dfx/DiscordREST/types' 'endpointReturnType=RestResponse' > src/types.ts && prettier -w src/types.ts"
19
+ },
20
+ "exports": {
21
+ ".": "./index.js",
22
+ "./gateway": "./gateway.js",
23
+ "./webhooks": "./webhooks.js",
24
+ "./*": "./*.js"
25
+ },
26
+ "devDependencies": {
27
+ "@tim-smart/discord-api-docs-parser": "^0.5.2",
28
+ "@tsplus-types/effect__data": "0.12.2-3b576ba",
29
+ "@tsplus-types/effect__io": "0.25.8-11739c0",
30
+ "@tsplus-types/effect__stream": "0.21.1-3b576ba",
31
+ "@types/ws": "^8.5.4",
32
+ "dotenv": "^16.0.3",
33
+ "lerna": "^6.6.1",
34
+ "madge": "^6.0.0",
35
+ "typescript": "https://cdn.jsdelivr.net/npm/@tsplus/installer@0.0.171/compiler/typescript.tgz"
36
+ },
37
+ "dependencies": {
38
+ "@effect-http/client": "^0.24.2",
39
+ "@effect/data": "^0.12.2",
40
+ "@effect/io": "~0.25.8",
41
+ "@effect/stream": "~0.21.1",
42
+ "tweetnacl": "^1.0.3"
43
+ },
44
+ "optionalDependencies": {
45
+ "bufferutil": "^4.0.7",
46
+ "isomorphic-ws": "^5.0.0",
47
+ "utf-8-validate": "^6.0.3",
48
+ "ws": "^8.13.0"
49
+ },
50
+ "sideEffects": false,
51
+ "gitHead": "eb969e6b2d8ac1c0a5ab877898feae57728b5e3c"
52
+ }
package/src/webhooks.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LiveFetchRequestExecutor } from "@effect-http/client"
2
2
  import { LiveDiscordREST } from "./DiscordREST.js"
3
- import { MakeConfigOpts, makeFromConfig } from "./Interactions/webhook.js"
3
+ import { MakeConfigOpts, makeConfigLayer } from "./Interactions/webhook.js"
4
4
  import { LiveMemoryRateLimitStore, LiveRateLimiter } from "./RateLimit.js"
5
5
  import * as DiscordConfig from "dfx/DiscordConfig"
6
6
  import * as Log from "./Log.js"
@@ -20,22 +20,19 @@ export const MemoryREST = LiveMemoryRateLimitStore >> LiveDiscordREST
20
20
 
21
21
  export const makeLiveWithoutFetch = (
22
22
  options: Config.Wrap<DiscordConfig.MakeOpts & MakeConfigOpts>,
23
- debug = false,
24
- ) => {
25
- const config = Config.unwrap(options)
26
-
27
- const LiveWebhook = makeFromConfig(config)
28
- const LiveLog = debug ? Log.LiveLogDebug : Log.LiveLog
29
- const LiveConfig = DiscordConfig.makeFromConfig(config)
30
- const LiveEnv =
31
- (LiveLog + LiveConfig) >> (MemoryREST + LiveWebhook + MemoryRateLimit)
32
-
33
- return LiveEnv
34
- }
23
+ ) =>
24
+ Layer.unwrapEffect(
25
+ Config.unwrap(options).config.map(options => {
26
+ const config = DiscordConfig.make(options)
27
+ const LiveConfig = Layer.succeed(DiscordConfig.DiscordConfig, config)
28
+ const LiveWebhook = makeConfigLayer(options)
29
+ const LiveLog = config.debug ? Log.LiveLogDebug : Log.LiveLog
30
+ const LiveEnv =
31
+ (LiveLog + LiveConfig) >> (MemoryREST + LiveWebhook + MemoryRateLimit)
32
+ return LiveEnv
33
+ }),
34
+ )
35
35
 
36
36
  export const makeLive = (
37
37
  config: Config.Wrap<DiscordConfig.MakeOpts & MakeConfigOpts>,
38
- debug = false,
39
- ) => {
40
- return LiveFetchRequestExecutor >> makeLiveWithoutFetch(config, debug)
41
- }
38
+ ) => LiveFetchRequestExecutor >> makeLiveWithoutFetch(config)
package/webhooks.d.ts CHANGED
@@ -5,5 +5,5 @@ import * as Log from "./Log.js";
5
5
  export { BadWebhookSignature, makeConfigLayer, makeHandler, makeSimpleHandler, WebhookConfig, WebhookParseError, } from "./Interactions/webhook.js";
6
6
  export declare const MemoryRateLimit: import("@effect-http/client/_common").Layer<Log.Log, never, import("./RateLimit.js").RateLimiter>;
7
7
  export declare const MemoryREST: import("@effect-http/client/_common").Layer<DiscordConfig.DiscordConfig | Log.Log | import("@effect-http/client").HttpRequestExecutor, never, import("./DiscordREST.js").DiscordREST>;
8
- export declare const makeLiveWithoutFetch: (options: Config.Wrap<DiscordConfig.MakeOpts & MakeConfigOpts>, debug?: boolean) => import("@effect-http/client/_common").Layer<import("@effect-http/client").HttpRequestExecutor, import("./_common.js").ConfigError, import("./DiscordREST.js").DiscordREST | import("./RateLimit.js").RateLimiter | import("./Interactions/webhook.js").WebhookConfig>;
9
- export declare const makeLive: (config: Config.Wrap<DiscordConfig.MakeOpts & MakeConfigOpts>, debug?: boolean) => import("@effect-http/client/_common").Layer<never, import("./_common.js").ConfigError, import("./DiscordREST.js").DiscordREST | import("./RateLimit.js").RateLimiter | import("./Interactions/webhook.js").WebhookConfig>;
8
+ export declare const makeLiveWithoutFetch: (options: Config.Wrap<DiscordConfig.MakeOpts & MakeConfigOpts>) => import("@effect-http/client/_common").Layer<import("@effect-http/client").HttpRequestExecutor, import("./_common.js").ConfigError, import("./DiscordREST.js").DiscordREST | import("./RateLimit.js").RateLimiter | import("./Interactions/webhook.js").WebhookConfig>;
9
+ export declare const makeLive: (config: Config.Wrap<DiscordConfig.MakeOpts & MakeConfigOpts>) => import("@effect-http/client/_common").Layer<never, import("./_common.js").ConfigError, import("./DiscordREST.js").DiscordREST | import("./RateLimit.js").RateLimiter | import("./Interactions/webhook.js").WebhookConfig>;
package/webhooks.js CHANGED
@@ -1,23 +1,22 @@
1
1
  import * as tsplus_module_1 from "@effect/io/Layer";
2
2
  import * as tsplus_module_2 from "@effect/io/Config";
3
+ import * as tsplus_module_3 from "@effect/io/Effect";
3
4
  import { LiveFetchRequestExecutor } from "@effect-http/client";
4
5
  import { LiveDiscordREST } from "./DiscordREST.js";
5
- import { makeFromConfig } from "./Interactions/webhook.js";
6
+ import { makeConfigLayer } from "./Interactions/webhook.js";
6
7
  import { LiveMemoryRateLimitStore, LiveRateLimiter } from "./RateLimit.js";
7
8
  import * as DiscordConfig from "dfx/DiscordConfig";
8
9
  import * as Log from "./Log.js";
9
10
  export { BadWebhookSignature, makeConfigLayer, makeHandler, makeSimpleHandler, WebhookConfig, WebhookParseError, } from "./Interactions/webhook.js";
10
11
  export const MemoryRateLimit = tsplus_module_1.provide(LiveRateLimiter)(LiveMemoryRateLimitStore);
11
12
  export const MemoryREST = tsplus_module_1.provide(LiveDiscordREST)(LiveMemoryRateLimitStore);
12
- export const makeLiveWithoutFetch = (options, debug = false) => {
13
- const config = tsplus_module_2.unwrap(options);
14
- const LiveWebhook = makeFromConfig(config);
15
- const LiveLog = debug ? Log.LiveLogDebug : Log.LiveLog;
16
- const LiveConfig = DiscordConfig.makeFromConfig(config);
13
+ export const makeLiveWithoutFetch = (options) => tsplus_module_1.unwrapEffect(tsplus_module_3.map(tsplus_module_3.config(tsplus_module_2.unwrap(options)), options => {
14
+ const config = DiscordConfig.make(options);
15
+ const LiveConfig = tsplus_module_1.succeed(DiscordConfig.DiscordConfig, config);
16
+ const LiveWebhook = makeConfigLayer(options);
17
+ const LiveLog = config.debug ? Log.LiveLogDebug : Log.LiveLog;
17
18
  const LiveEnv = tsplus_module_1.provide((tsplus_module_1.merge(MemoryRateLimit)(tsplus_module_1.merge(LiveWebhook)(MemoryREST))))((tsplus_module_1.merge(LiveConfig)(LiveLog)));
18
19
  return LiveEnv;
19
- };
20
- export const makeLive = (config, debug = false) => {
21
- return tsplus_module_1.provide(makeLiveWithoutFetch(config, debug))(LiveFetchRequestExecutor);
22
- };
20
+ }));
21
+ export const makeLive = (config) => tsplus_module_1.provide(makeLiveWithoutFetch(config))(LiveFetchRequestExecutor);
23
22
  //# sourceMappingURL=webhooks.js.map
package/webhooks.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["src/webhooks.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAkB,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1E,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAC1E,OAAO,KAAK,aAAa,MAAM,mBAAmB,CAAA;AAClD,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAE/B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,iBAAiB,GAClB,MAAM,2BAA2B,CAAA;AAElC,MAAM,CAAC,MAAM,eAAe,2BAA+B,eAAe,EAA3C,wBAAwB,CAAmB,CAAA;AAE1E,MAAM,CAAC,MAAM,UAAU,2BAA+B,eAAe,EAA3C,wBAAwB,CAAmB,CAAA;AAErE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,OAA6D,EAC7D,KAAK,GAAG,KAAK,EACb,EAAE;IACF,MAAM,MAAM,GAAG,uBAAc,OAAO,CAAC,CAAA;IAErC,MAAM,WAAW,GAAG,cAAc,CAAC,MAAM,CAAC,CAAA;IAC1C,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CA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