dfx 0.74.0 → 0.75.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.
@@ -2,7 +2,6 @@ import * as Chunk from "effect/Chunk"
2
2
  import { Tag } from "effect/Context"
3
3
  import * as Duration from "effect/Duration"
4
4
  import { pipe } from "effect/Function"
5
- import type { Cause } from "effect/Cause"
6
5
  import * as Effect from "effect/Effect"
7
6
  import * as Layer from "effect/Layer"
8
7
  import * as Queue from "effect/Queue"
@@ -21,6 +20,7 @@ import type { InteractionBuilder } from "dfx/Interactions/index"
21
20
  import { builder, Interaction } from "dfx/Interactions/index"
22
21
  import type * as Discord from "dfx/types"
23
22
  import * as EffectUtils from "dfx/utils/Effect"
23
+ import * as Schedule from "effect/Schedule"
24
24
 
25
25
  export interface RunOpts {
26
26
  sync?: boolean
@@ -112,55 +112,55 @@ export const run =
112
112
  )
113
113
  })
114
114
 
115
- const makeRegistry = Effect.gen(function* (_) {
116
- const ref = yield* _(
117
- Ref.make(builder as InteractionBuilder<never, never, never>),
118
- )
119
- const queue = yield* _(
120
- Queue.sliding<InteractionBuilder<never, never, never>>(1),
121
- )
122
-
123
- const register = <E>(ix: InteractionBuilder<never, E, never>) =>
124
- Effect.flatMap(
125
- Ref.updateAndGet(ref, _ => _.concat(ix as any)),
126
- _ => Queue.offer(queue, _),
115
+ const makeRegistry = (options?: RunOpts) =>
116
+ Effect.gen(function* (_) {
117
+ const ref = yield* _(
118
+ Ref.make(builder as InteractionBuilder<never, never, never>),
119
+ )
120
+ const queue = yield* _(
121
+ Queue.sliding<InteractionBuilder<never, never, never>>(1),
127
122
  )
128
123
 
129
- const run_ = <R, E>(
130
- onError: (
131
- _: Cause<DiscordRESTError | DefinitionNotFound>,
132
- ) => Effect.Effect<R, E, void>,
133
- opts?: RunOpts,
134
- ) =>
135
- EffectUtils.foreverSwitch(Queue.take(queue), ix =>
136
- Effect.delay(
137
- pipe(ix, run(Effect.catchAllCause(onError), opts)),
138
- Duration.seconds(0.1),
124
+ const register = <E>(ix: InteractionBuilder<never, E, never>) =>
125
+ Effect.flatMap(
126
+ Ref.updateAndGet(ref, _ => _.concat(ix as any)),
127
+ _ => Queue.offer(queue, _),
128
+ )
129
+
130
+ yield* _(
131
+ EffectUtils.foreverSwitch(Queue.take(queue), ix =>
132
+ pipe(
133
+ ix,
134
+ run(
135
+ Effect.catchAllCause(_ => Effect.logError("unhandled error", _)),
136
+ options,
137
+ ),
138
+ Effect.delay(Duration.seconds(0.1)),
139
+ ),
140
+ ),
141
+ Effect.tapErrorCause(_ => Effect.logError("registry error", _)),
142
+ Effect.retry(
143
+ Schedule.exponential("1 seconds").pipe(
144
+ Schedule.union(Schedule.spaced("20 seconds")),
145
+ ),
139
146
  ),
147
+ Effect.forkScoped,
140
148
  )
141
149
 
142
- return { register, run: run_ } as const
143
- })
150
+ return { register } as const
151
+ }).pipe(
152
+ Effect.annotateLogs({
153
+ package: "dfx",
154
+ service: "InteractionsRegistry",
155
+ }),
156
+ )
144
157
 
145
158
  export interface InteractionsRegistry {
146
159
  readonly register: <E>(
147
160
  ix: InteractionBuilder<never, E, never>,
148
161
  ) => Effect.Effect<never, never, void>
149
-
150
- readonly run: <R, E>(
151
- onError: (
152
- _: Cause<DiscordRESTError | DefinitionNotFound>,
153
- ) => Effect.Effect<R, E, void>,
154
- opts?: RunOpts,
155
- ) => Effect.Effect<
156
- DiscordREST | DiscordGateway | Exclude<R, Discord.Interaction>,
157
- DiscordRESTError | Http.error.ResponseError | E,
158
- never
159
- >
160
162
  }
161
163
 
162
164
  export const InteractionsRegistry = Tag<InteractionsRegistry>()
163
- export const InteractionsRegistryLive = Layer.effect(
164
- InteractionsRegistry,
165
- makeRegistry,
166
- )
165
+ export const InteractionsRegistryLive = (options?: RunOpts) =>
166
+ Layer.scoped(InteractionsRegistry, makeRegistry(options))
package/src/gateway.ts CHANGED
@@ -14,8 +14,6 @@ import * as SendEvent from "dfx/DiscordGateway/Shard/sendEvents"
14
14
  import * as ShardStore from "dfx/DiscordGateway/ShardStore"
15
15
  import { LiveMemoryShardStore } from "dfx/DiscordGateway/ShardStore"
16
16
  import * as WS from "dfx/DiscordGateway/WS"
17
- import { InteractionsRegistryLive } from "dfx/gateway"
18
- import type { InteractionsRegistry } from "dfx/gateway"
19
17
  import type { RateLimiter } from "dfx/RateLimit"
20
18
  import { LiveMemoryRateLimitStore, LiveRateLimiter } from "dfx/RateLimit"
21
19
 
@@ -43,7 +41,6 @@ export const MemoryBot = Layer.provide(
43
41
  Layer.mergeAll(
44
42
  Layer.provideMerge(LiveDiscordREST, LiveDiscordGateway),
45
43
  MemoryRateLimit,
46
- InteractionsRegistryLive,
47
44
  ),
48
45
  )
49
46
 
@@ -54,7 +51,6 @@ export const gatewayLayer = (
54
51
  ConfigError.ConfigError,
55
52
  | RateLimiter
56
53
  | Log.Log
57
- | InteractionsRegistry
58
54
  | DiscordREST
59
55
  | DiscordGateway
60
56
  | DiscordConfig.DiscordConfig
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "0.74.0";
1
+ export const LIB_VERSION = "0.75.0";
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const LIB_VERSION = "0.74.0";
1
+ export declare const LIB_VERSION = "0.75.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.LIB_VERSION = void 0;
7
- const LIB_VERSION = exports.LIB_VERSION = "0.74.0";
7
+ const LIB_VERSION = exports.LIB_VERSION = "0.75.0";
8
8
  //# sourceMappingURL=version.js.map