dfx 0.87.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.
Files changed (90) hide show
  1. package/Cache/driver.d.ts.map +1 -1
  2. package/Cache/driver.js.map +1 -1
  3. package/Cache/memory.d.ts.map +1 -1
  4. package/Cache/memory.js.map +1 -1
  5. package/Cache/memoryTTL.d.ts.map +1 -1
  6. package/Cache/memoryTTL.js.map +1 -1
  7. package/Cache/prelude.d.ts +3 -3
  8. package/Cache/prelude.d.ts.map +1 -1
  9. package/Cache/prelude.js +4 -4
  10. package/Cache/prelude.js.map +1 -1
  11. package/DiscordGateway/DiscordWS.d.ts.map +1 -1
  12. package/DiscordGateway/DiscordWS.js.map +1 -1
  13. package/DiscordGateway/Shard/identify.d.ts.map +1 -1
  14. package/DiscordGateway/Shard/identify.js.map +1 -1
  15. package/DiscordGateway/Shard/utils.d.ts.map +1 -1
  16. package/DiscordGateway/Shard/utils.js.map +1 -1
  17. package/DiscordGateway/Shard.d.ts +1 -1
  18. package/DiscordGateway/ShardStore.d.ts.map +1 -1
  19. package/DiscordGateway/ShardStore.js.map +1 -1
  20. package/DiscordGateway/Sharder.d.ts +1 -1
  21. package/DiscordGateway/Sharder.d.ts.map +1 -1
  22. package/DiscordGateway/Sharder.js.map +1 -1
  23. package/DiscordGateway/WS.d.ts.map +1 -1
  24. package/DiscordGateway/WS.js.map +1 -1
  25. package/DiscordGateway.d.ts +1 -1
  26. package/DiscordREST/types.d.ts +5 -1
  27. package/DiscordREST/types.d.ts.map +1 -1
  28. package/DiscordREST.d.ts +2 -1
  29. package/DiscordREST.d.ts.map +1 -1
  30. package/DiscordREST.js +18 -1
  31. package/DiscordREST.js.map +1 -1
  32. package/Interactions/builder.d.ts +2 -2
  33. package/Interactions/builder.d.ts.map +1 -1
  34. package/Interactions/context.d.ts +1 -1
  35. package/Interactions/context.d.ts.map +1 -1
  36. package/Interactions/context.js.map +1 -1
  37. package/Interactions/definitions.d.ts +3 -1
  38. package/Interactions/definitions.d.ts.map +1 -1
  39. package/Interactions/gateway.d.ts.map +1 -1
  40. package/Interactions/gateway.js +4 -4
  41. package/Interactions/gateway.js.map +1 -1
  42. package/Interactions/handlers.d.ts.map +1 -1
  43. package/Interactions/handlers.js.map +1 -1
  44. package/Interactions/utils.d.ts.map +1 -1
  45. package/Interactions/utils.js.map +1 -1
  46. package/Interactions/webhook.d.ts.map +1 -1
  47. package/Interactions/webhook.js.map +1 -1
  48. package/mjs/Cache/driver.mjs.map +1 -1
  49. package/mjs/Cache/memory.mjs.map +1 -1
  50. package/mjs/Cache/memoryTTL.mjs.map +1 -1
  51. package/mjs/Cache/prelude.mjs +4 -4
  52. package/mjs/Cache/prelude.mjs.map +1 -1
  53. package/mjs/DiscordGateway/DiscordWS.mjs.map +1 -1
  54. package/mjs/DiscordGateway/Shard/identify.mjs.map +1 -1
  55. package/mjs/DiscordGateway/Shard/utils.mjs.map +1 -1
  56. package/mjs/DiscordGateway/ShardStore.mjs.map +1 -1
  57. package/mjs/DiscordGateway/Sharder.mjs.map +1 -1
  58. package/mjs/DiscordGateway/WS.mjs.map +1 -1
  59. package/mjs/DiscordREST.mjs +18 -1
  60. package/mjs/DiscordREST.mjs.map +1 -1
  61. package/mjs/Interactions/context.mjs.map +1 -1
  62. package/mjs/Interactions/gateway.mjs +4 -4
  63. package/mjs/Interactions/gateway.mjs.map +1 -1
  64. package/mjs/Interactions/handlers.mjs.map +1 -1
  65. package/mjs/Interactions/utils.mjs.map +1 -1
  66. package/mjs/Interactions/webhook.mjs.map +1 -1
  67. package/mjs/version.mjs +1 -1
  68. package/package.json +3 -3
  69. package/src/Cache/driver.ts +2 -8
  70. package/src/Cache/memory.ts +3 -1
  71. package/src/Cache/memoryTTL.ts +2 -3
  72. package/src/Cache/prelude.ts +8 -10
  73. package/src/DiscordGateway/DiscordWS.ts +4 -3
  74. package/src/DiscordGateway/Shard/identify.ts +4 -2
  75. package/src/DiscordGateway/Shard/utils.ts +6 -4
  76. package/src/DiscordGateway/ShardStore.ts +1 -3
  77. package/src/DiscordGateway/Sharder.ts +7 -4
  78. package/src/DiscordGateway/WS.ts +2 -5
  79. package/src/DiscordREST/types.ts +6 -1
  80. package/src/DiscordREST.ts +37 -4
  81. package/src/Interactions/context.ts +22 -17
  82. package/src/Interactions/definitions.ts +26 -21
  83. package/src/Interactions/gateway.ts +21 -12
  84. package/src/Interactions/handlers.ts +5 -1
  85. package/src/Interactions/utils.ts +11 -13
  86. package/src/Interactions/webhook.ts +11 -6
  87. package/src/utils/Effect.ts +2 -2
  88. package/src/version.ts +1 -1
  89. package/version.d.ts +1 -1
  90. package/version.js +1 -1
@@ -123,13 +123,14 @@ 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> = T extends Array<infer R>
127
- ? ReadonlyArray<DeepReadonly<R>>
128
- : T extends Function
129
- ? T
130
- : T extends object
131
- ? DeepReadonlyObject<T>
132
- : T
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
  }
@@ -173,20 +174,24 @@ export interface CommandHelper<A> {
173
174
  >,
174
175
  >(
175
176
  commands: NER,
176
- ) => Effect.Effect<Discord.InteractionResponse, [NER[keyof NER]] extends [
177
- { [Effect.EffectTypeId]: { _E: (_: never) => infer E } },
178
- ]
179
- ? E
180
- : never, | Exclude<
181
- [NER[keyof NER]] extends [
182
- { [Effect.EffectTypeId]: { _R: (_: never) => infer R } },
183
- ]
184
- ? R
185
- : never,
186
- SubCommandContext
187
- >
188
- | DiscordInteraction
189
- | DiscordApplicationCommand>
177
+ ) => Effect.Effect<
178
+ Discord.InteractionResponse,
179
+ [NER[keyof NER]] extends [
180
+ { [Effect.EffectTypeId]: { _E: (_: never) => infer E } },
181
+ ]
182
+ ? E
183
+ : never,
184
+ | Exclude<
185
+ [NER[keyof NER]] extends [
186
+ { [Effect.EffectTypeId]: { _R: (_: never) => infer R } },
187
+ ]
188
+ ? R
189
+ : never,
190
+ SubCommandContext
191
+ >
192
+ | DiscordInteraction
193
+ | DiscordApplicationCommand
194
+ >
190
195
  }
191
196
 
192
197
  export type CommandHandlerFn<R, E, A> = (
@@ -37,12 +37,20 @@ export const setInteractionsSync = (enabled: boolean) =>
37
37
  export const run =
38
38
  <R, R2, E, TE, E2>(
39
39
  postHandler: (
40
- effect: Effect.Effect<void, TE | DiscordRESTError | DefinitionNotFound, R | DiscordREST | DiscordInteraction>,
40
+ effect: Effect.Effect<
41
+ void,
42
+ TE | DiscordRESTError | DefinitionNotFound,
43
+ R | DiscordREST | DiscordInteraction
44
+ >,
41
45
  ) => Effect.Effect<void, E2, R2>,
42
46
  ) =>
43
47
  (
44
48
  ix: InteractionBuilder<R, E, TE>,
45
- ): Effect.Effect<never, E2 | DiscordRESTError | Http.error.ResponseError, DiscordREST | DiscordGateway | Exclude<R2, DiscordInteraction>> =>
49
+ ): Effect.Effect<
50
+ never,
51
+ E2 | DiscordRESTError | Http.error.ResponseError,
52
+ DiscordREST | DiscordGateway | Exclude<R2, DiscordInteraction>
53
+ > =>
46
54
  Effect.gen(function* (_) {
47
55
  const GlobalApplicationCommand = ix.definitions.pipe(
48
56
  Chunk.map(_ => _[0]),
@@ -65,8 +73,7 @@ export const run =
65
73
  const rest = yield* _(DiscordREST)
66
74
 
67
75
  const application = yield* _(
68
- rest.getCurrentBotApplicationInformation(),
69
- Effect.flatMap(a => a.json),
76
+ rest.getCurrentBotApplicationInformation().json,
70
77
  )
71
78
 
72
79
  const globalSync = rest.bulkOverwriteGlobalApplicationCommands(
@@ -76,20 +83,22 @@ export const run =
76
83
  GlobalApplicationCommand.map(_ => _.command),
77
84
  ),
78
85
  },
79
- )
86
+ ).asUnit
80
87
 
81
88
  const guildSync = GuildApplicationCommand.length
82
- ? gateway.handleDispatch("GUILD_CREATE", a =>
83
- rest.bulkOverwriteGuildApplicationCommands(
84
- application.id,
85
- a.id,
86
- GuildApplicationCommand.map(_ => _.command) as any,
87
- ),
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,
88
97
  )
89
98
  : Effect.never
90
99
 
91
100
  const handle = handlers(ix.definitions, (i, r) =>
92
- rest.createInteractionResponse(i.id, i.token, r),
101
+ rest.createInteractionResponse(i.id, i.token, r).pipe(Effect.scoped),
93
102
  )
94
103
 
95
104
  const run = gateway.handleDispatch("INTERACTION_CREATE", i =>
@@ -12,7 +12,11 @@ export class DefinitionNotFound {
12
12
  constructor(readonly interaction: Discord.Interaction) {}
13
13
  }
14
14
 
15
- type Handler<R, E, A> = Effect.Effect<A, E | DefinitionNotFound, R | Ctx.DiscordInteraction>
15
+ type Handler<R, E, A> = Effect.Effect<
16
+ A,
17
+ E | DefinitionNotFound,
18
+ R | Ctx.DiscordInteraction
19
+ >
16
20
 
17
21
  export const handlers = <R, E, TE, A, B>(
18
22
  definitions: Chunk.Chunk<
@@ -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> = D.InteractionDefinition<
8
- R,
9
- E
10
- > extends infer D
11
- ? {
12
- [K in keyof D]: K extends "handle"
13
- ? (_: Discord.Interaction) => Effect.Effect<A, TE, R>
14
- : D[K]
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>,
@@ -83,10 +81,10 @@ export const splitDefinitions = <R, E, TE, A>(
83
81
  Chunk.reduce(
84
82
  {} as Record<string, DefinitionFlattenedCommand<R, E, TE, A>>,
85
83
  (acc, d) =>
86
- (({
84
+ ({
87
85
  ...acc,
88
- [d.command.name]: d
89
- }) as any),
86
+ [d.command.name]: d,
87
+ }) as any,
90
88
  ),
91
89
  )
92
90
 
@@ -74,9 +74,10 @@ const makeConfig = ({
74
74
  export interface WebhookConfig {
75
75
  readonly _: unique symbol
76
76
  }
77
- export const WebhookConfig = GenericTag<WebhookConfig, ReturnType<typeof makeConfig>>(
78
- "dfx/Interactions/WebhookConfig",
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))
@@ -122,14 +123,18 @@ const run = <R, E>(
122
123
  return (
123
124
  headers: Headers,
124
125
  body: string,
125
- ): Effect.Effect<Discord.InteractionResponse, BadWebhookSignature | WebhookParseError | E | DefinitionNotFound, WebhookConfig | Exclude<R, DiscordInteraction>> =>
126
+ ): Effect.Effect<
127
+ Discord.InteractionResponse,
128
+ BadWebhookSignature | WebhookParseError | E | DefinitionNotFound,
129
+ WebhookConfig | Exclude<R, DiscordInteraction>
130
+ > =>
126
131
  Effect.flatMap(fromHeadersAndBody(headers, body), interaction =>
127
132
  Effect.provideService(
128
133
  handler[interaction.type](interaction),
129
134
  Interaction,
130
135
  interaction,
131
136
  ),
132
- );
137
+ )
133
138
  }
134
139
 
135
140
  export interface HandleWebhookOpts<E> {
@@ -168,7 +173,7 @@ export const makeHandler = <R, E, TE>(
168
173
  handle(headers, body).pipe(
169
174
  Effect.flatMap(success),
170
175
  Effect.catchAllCause(error),
171
- );
176
+ )
172
177
  }
173
178
 
174
179
  /**
@@ -29,7 +29,7 @@ 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<never, E, R>;
32
+ }) as Effect.Effect<never, E, R>
33
33
  })
34
34
 
35
35
  export const foreverSwitch = <R, E, A, R1, E1, X>(
@@ -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<never, E | E1, R | R1>;
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.87.0";
1
+ export const LIB_VERSION = "0.88.0";
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const LIB_VERSION = "0.87.0";
1
+ export declare const LIB_VERSION = "0.88.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.87.0";
7
+ const LIB_VERSION = exports.LIB_VERSION = "0.88.0";
8
8
  //# sourceMappingURL=version.js.map