dfx 0.18.0 → 0.18.2
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/Cache/driver.d.ts +4 -4
- package/Cache/driver.js.map +1 -1
- package/Cache/gateway.d.ts +15 -15
- package/Cache/gateway.js +26 -34
- package/Cache/gateway.js.map +1 -1
- package/Cache/index.d.ts +29 -29
- package/Cache/index.js +2 -2
- package/Cache/index.js.map +1 -1
- package/Cache/memory.d.ts +2 -2
- package/Cache/memoryTTL.d.ts +2 -4
- package/Cache/memoryTTL.js +3 -3
- package/Cache/memoryTTL.js.map +1 -1
- package/Cache/prelude.d.ts +14 -28
- package/Cache/prelude.js +18 -25
- package/Cache/prelude.js.map +1 -1
- package/DiscordGateway/DiscordWS/index.d.ts +1 -1
- package/DiscordGateway/Shard/index.d.ts +1 -1
- package/DiscordGateway/Sharder/index.d.ts +14 -6
- package/DiscordGateway/Sharder/index.js +48 -47
- package/DiscordGateway/Sharder/index.js.map +1 -1
- package/DiscordGateway/index.d.ts +3 -11
- package/DiscordGateway/index.js +3 -7
- package/DiscordGateway/index.js.map +1 -1
- package/DiscordREST/index.d.ts +4 -4
- package/DiscordREST/index.js +61 -61
- package/DiscordREST/index.js.map +1 -1
- package/DiscordREST/types.d.ts +1 -2
- package/Http/index.d.ts +14 -7
- package/Http/index.js +17 -10
- package/Http/index.js.map +1 -1
- package/Interactions/gateway.d.ts +1 -1
- package/Interactions/gateway.js +7 -7
- package/Interactions/gateway.js.map +1 -1
- package/Interactions/index.d.ts +4 -2
- package/Interactions/index.js +17 -10
- package/Interactions/index.js.map +1 -1
- package/gateway.d.ts +6 -5
- package/gateway.js +10 -5
- package/gateway.js.map +1 -1
- package/global.d.ts +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +2 -2
- package/utils/effect.d.ts +19 -0
- package/utils/effect.js +19 -1
- package/utils/effect.js.map +1 -1
- package/webhooks.d.ts +3 -3
- package/webhooks.js +4 -3
- package/webhooks.js.map +1 -1
|
@@ -1,49 +1,50 @@
|
|
|
1
1
|
import * as tsplus_module_1 from "callbag-effect-ts/Source/fromEffect";
|
|
2
|
-
import * as tsplus_module_2 from "callbag-effect-ts/Source/
|
|
3
|
-
import * as tsplus_module_3 from "callbag-effect-ts/Source/
|
|
4
|
-
import * as tsplus_module_4 from "
|
|
5
|
-
import * as tsplus_module_5 from "@
|
|
6
|
-
import * as tsplus_module_6 from "
|
|
7
|
-
import * as tsplus_module_7 from "
|
|
8
|
-
import * as tsplus_module_8 from "callbag-effect-ts/Source/
|
|
9
|
-
import * as tsplus_module_9 from "
|
|
10
|
-
import * as tsplus_module_10 from "callbag-effect-ts/Source/
|
|
11
|
-
import * as tsplus_module_11 from "callbag-effect-ts/Source/
|
|
12
|
-
import * as tsplus_module_12 from "callbag-effect-ts/Source/
|
|
13
|
-
import * as tsplus_module_13 from "
|
|
14
|
-
import * as tsplus_module_14 from "
|
|
15
|
-
import * as tsplus_module_15 from "callbag-effect-ts/Source/
|
|
16
|
-
import * as tsplus_module_16 from "callbag-effect-ts/Source/
|
|
17
|
-
import * as tsplus_module_17 from "
|
|
2
|
+
import * as tsplus_module_2 from "callbag-effect-ts/Source/drain";
|
|
3
|
+
import * as tsplus_module_3 from "callbag-effect-ts/Source/of";
|
|
4
|
+
import * as tsplus_module_4 from "callbag-effect-ts/Source/merge";
|
|
5
|
+
import * as tsplus_module_5 from "@effect/io/Effect";
|
|
6
|
+
import * as tsplus_module_6 from "dfx/gateway";
|
|
7
|
+
import * as tsplus_module_7 from "callbag-effect-ts/Source/tap";
|
|
8
|
+
import * as tsplus_module_8 from "callbag-effect-ts/Source/mapEffect";
|
|
9
|
+
import * as tsplus_module_9 from "callbag-effect-ts/Source/map";
|
|
10
|
+
import * as tsplus_module_10 from "callbag-effect-ts/Source/groupBy";
|
|
11
|
+
import * as tsplus_module_11 from "callbag-effect-ts/Source/chainPar";
|
|
12
|
+
import * as tsplus_module_12 from "callbag-effect-ts/Source/share";
|
|
13
|
+
import * as tsplus_module_13 from "@fp-ts/data/Duration";
|
|
14
|
+
import * as tsplus_module_14 from "@fp-ts/data/Option";
|
|
15
|
+
import * as tsplus_module_15 from "callbag-effect-ts/Source/empty";
|
|
16
|
+
import * as tsplus_module_16 from "callbag-effect-ts/Source/resource";
|
|
17
|
+
import * as tsplus_module_17 from "dfx";
|
|
18
|
+
import * as tsplus_module_18 from "@fp-ts/data/Context";
|
|
18
19
|
import { millis } from "@fp-ts/data/Duration";
|
|
19
20
|
import { overridePull } from "callbag-effect-ts/Source";
|
|
20
21
|
import { ShardStore } from "../ShardStore/index.js";
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
tsplus_module_5.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
tsplus_module_5.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
id
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
})(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
})
|
|
46
|
-
|
|
22
|
+
const make = tsplus_module_5.flatMap(store => tsplus_module_5.flatMap(({ routes: rest }) => tsplus_module_5.flatMap(({ gateway: config }) => tsplus_module_5.flatMap(limiter => {
|
|
23
|
+
const configs = (totalCount) => {
|
|
24
|
+
const claimId = (sharderCount) => tsplus_module_5.flatMap((a) => tsplus_module_14.match(() => tsplus_module_5.delay(tsplus_module_13.minutes(3))(tsplus_module_5.succeed([
|
|
25
|
+
tsplus_module_14.some(sharderCount),
|
|
26
|
+
tsplus_module_15.empty,
|
|
27
|
+
])), (id) => tsplus_module_5.succeed([
|
|
28
|
+
tsplus_module_14.some(sharderCount + 1),
|
|
29
|
+
tsplus_module_3.of(id),
|
|
30
|
+
]))(a))(store
|
|
31
|
+
.claimId({
|
|
32
|
+
totalCount,
|
|
33
|
+
sharderCount,
|
|
34
|
+
}));
|
|
35
|
+
return tsplus_module_9.map((id) => ({
|
|
36
|
+
id,
|
|
37
|
+
totalCount,
|
|
38
|
+
}))(tsplus_module_16.resource(0, (sharderCount) => tsplus_module_1.fromEffect(claimId(sharderCount))));
|
|
39
|
+
};
|
|
40
|
+
return tsplus_module_5.flatMap(gateway => {
|
|
41
|
+
const [source, pull] = overridePull(configs(config.shardCount ?? gateway.shards), gateway.session_start_limit.max_concurrency);
|
|
42
|
+
return tsplus_module_5.map(shards => ({ shards }))(tsplus_module_12.share(tsplus_module_11.chainPar((shard) => tsplus_module_4.merge(tsplus_module_2.drain(tsplus_module_1.fromEffect(shard.run)))(tsplus_module_3.of(shard)))(tsplus_module_7.tap(() => tsplus_module_5.sync(pull))(tsplus_module_11.chainPar(([shardConfig, key]) => tsplus_module_8.mapEffect((c) => tsplus_module_6.Shard.make([c.id, c.totalCount]))(tsplus_module_7.tap(() => limiter.maybeWait(`dfx.sharder.${key}`, millis(config.identifyRateLimit[0]), config.identifyRateLimit[1]))(shardConfig)))(tsplus_module_10.groupBy((c) => c.id % c.concurrency)(tsplus_module_9.map((config) => ({
|
|
43
|
+
...config,
|
|
44
|
+
url: gateway.url,
|
|
45
|
+
concurrency: gateway.session_start_limit.max_concurrency,
|
|
46
|
+
}))(source)))))));
|
|
47
|
+
})(tsplus_module_5.catchAll(() => tsplus_module_5.succeed({
|
|
47
48
|
url: "wss://gateway.discord.gg/",
|
|
48
49
|
shards: 1,
|
|
49
50
|
session_start_limit: {
|
|
@@ -52,9 +53,9 @@ const spawnEffect = tsplus_module_7.map(({ gateway, config, configs, limiter })
|
|
|
52
53
|
reset_after: 0,
|
|
53
54
|
max_concurrency: 1,
|
|
54
55
|
},
|
|
55
|
-
}))(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
export const
|
|
56
|
+
}))(tsplus_module_5.flatMap((r) => r.json)(rest
|
|
57
|
+
.getGatewayBot())));
|
|
58
|
+
})(tsplus_module_5.service(tsplus_module_17.RateLimit.RateLimiter)))(tsplus_module_5.service(tsplus_module_17.Config.DiscordConfig)))(tsplus_module_5.service(tsplus_module_17.DiscordREST)))(tsplus_module_5.service(ShardStore));
|
|
59
|
+
export const Sharder = tsplus_module_18.Tag();
|
|
60
|
+
export const LiveSharder = tsplus_module_5.toLayer(Sharder)(make);
|
|
60
61
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/DiscordGateway/Sharder/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/DiscordGateway/Sharder/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEnD,MAAM,IAAI,2BACF,KAAK,6BACL,EAAE,MAAM,EAAE,IAAI,EAAE,8BAChB,EAAE,OAAO,EAAE,MAAM,EAAE,6BACnB,OAAO;IAEb,MAAM,OAAO,GAAG,CAAC,UAAkB,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,CAAC,YAAoB,EAAE,EAAE,CACvC,wBAMI,CACE,CAAC,EAKD,EAAE,CACF,uBACE,GAAG,EAAE,CACH,sBAGkB,yBAAiB,CAAC,CAAC,EAHrC,wBAAe;YACb,sBAAW,YAAY,CAAC;;SAEhB,CAAC,CAA2B,EACxC,CAAC,EAAE,EAAE,EAAE,CACL,wBAAe;YACb,sBAAW,YAAY,GAAG,CAAC,CAAC;YAC5B,mBAAgB,EAAE,CAAC;SACpB,CAAC,EAVN,CAAC,CAWA,EAxBP,KAAK;aACF,OAAO,CAAC;YACP,UAAU;YACV,YAAY;SACb,CAAC,CAqBD,CAAA;QAEL,O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EAAE,OAAO,CAAC,mBAAmB,CAAC,eAAe;SACzD,CAAC,EALJ,MAAM,CAKD,CACkC,CAWpC,CAC4B,CAG5B;OA5CH,yBAGY,GAAG,EAAE,CACb,wBAA8C;QAC5C,GAAG,EAAE,2BAA2B;QAChC,MAAM,EAAE,CAAC;QACT,mBAAmB,EAAE;YACnB,KAAK,EAAE,CAAC;YACR,SAAS,EAAE,CAAC;YACZ,WAAW,EAAE,CAAC;YACd,eAAe,EAAE,CAAC;SACnB;KACF,CAAC,EAbN,wBAEW,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAFxB,IAAI;SACD,aAAa,EAAE,CACO,CAYtB;GAtDa,wBAAe,iBAAA,SAAS,CAAC,WAAW,CAAC,GADzB,wBAAe,iBAAA,MAAM,CAAC,aAAa,CAAC,GADvC,yCAAe,WAAW,CAAC,GADtC,wBAAe,UAAU,CAAC,CA2F1C,CAAA;AAGF,MAAM,CAAC,MAAM,OAAO,GAAG,iBAAA,GAAG,EAAW,CAAA;AACrC,MAAM,CAAC,MAAM,WAAW,GAAG,wBAAa,OAAO,EAApB,IAAI,CAAiB,CAAA"}
|
|
@@ -2,14 +2,8 @@ import { EffectSource } from "callbag-effect-ts/Source";
|
|
|
2
2
|
import { Discord } from "dfx";
|
|
3
3
|
import { Effect } from "@effect/io/Effect";
|
|
4
4
|
import { Success } from "dfx/utils/effect";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
run: import("../global.js").Effect<never, never, void>;
|
|
8
|
-
raw: import("callbag-effect-ts/Source").EffectSource<never, never, import("../types.js").GatewayPayload<any>>;
|
|
9
|
-
dispatch: import("callbag-effect-ts/Source").EffectSource<never, never, import("../types.js").GatewayPayload<import("../types.js").ReceiveEvent>>;
|
|
10
|
-
send: (p: import("../types.js").GatewayPayload<any>) => import("../global.js").Effect<never, never, boolean>;
|
|
11
|
-
reconnect: import("../global.js").Effect<never, never, boolean>;
|
|
12
|
-
}>;
|
|
5
|
+
import { Sharder } from "./Sharder/index.js";
|
|
6
|
+
export declare const make: import("../global.js").Effect<Sharder, never, {
|
|
13
7
|
raw: import("callbag-effect-ts/Source").EffectSource<never, never, import("../types.js").GatewayPayload<any>>;
|
|
14
8
|
dispatch: import("callbag-effect-ts/Source").EffectSource<never, never, import("../types.js").GatewayPayload<import("../types.js").ReceiveEvent>>;
|
|
15
9
|
fromDispatch: <K extends keyof import("../types.js").ReceiveEvents>(event: K) => import("callbag-effect-ts/Source").EffectSource<never, never, import("../types.js").ReceiveEvents[K]>;
|
|
@@ -18,6 +12,4 @@ export declare const make: import("../global.js").Effect<import("../Log/index.js
|
|
|
18
12
|
export interface DiscordGateway extends Success<typeof make> {
|
|
19
13
|
}
|
|
20
14
|
export declare const DiscordGateway: import("../global.js").Tag<DiscordGateway>;
|
|
21
|
-
export declare const LiveDiscordGateway: import("../global.js").Layer<
|
|
22
|
-
export declare const fromDispatch: <K extends keyof import("../types.js").ReceiveEvents>(event: K) => import("callbag-effect-ts/Source").EffectSource<DiscordGateway, never, import("../types.js").ReceiveEvents[K]>;
|
|
23
|
-
export declare const handleDispatch: <K extends keyof import("../types.js").ReceiveEvents, R1, E1, A>(event: K, handle: (event: import("../types.js").ReceiveEvents[K]) => import("../global.js").Effect<R1, E1, A>) => import("../global.js").Effect<DiscordGateway | R1, E1, void>;
|
|
15
|
+
export declare const LiveDiscordGateway: import("../global.js").Layer<Sharder, never, DiscordGateway>;
|
package/DiscordGateway/index.js
CHANGED
|
@@ -7,23 +7,19 @@ import * as tsplus_module_6 from "callbag-effect-ts/Source/share";
|
|
|
7
7
|
import * as tsplus_module_7 from "@effect/io/Effect";
|
|
8
8
|
import * as tsplus_module_8 from "@fp-ts/data/Context";
|
|
9
9
|
import * as tsplus_module_9 from "@effect/io/Layer";
|
|
10
|
-
import
|
|
11
|
-
import { spawn } from "./Sharder/index.js";
|
|
10
|
+
import { Sharder } from "./Sharder/index.js";
|
|
12
11
|
const fromDispatchFactory = (source) => (event) => tsplus_module_2.map((p) => p.d)(tsplus_module_1.filter((p) => p.t === event)(source));
|
|
13
12
|
const handleDispatchFactory = (source) => (event, handle) => tsplus_module_5.runDrain(tsplus_module_4.chainPar((a) => tsplus_module_3.fromEffect(handle(a.d)))(tsplus_module_1.filter((p) => p.t === event)(source)));
|
|
14
|
-
export const make = tsplus_module_7.flatMap(
|
|
13
|
+
export const make = tsplus_module_7.flatMap(sharder => tsplus_module_7.flatMap(raw => tsplus_module_7.map(dispatch => {
|
|
15
14
|
const fromDispatch = fromDispatchFactory(dispatch);
|
|
16
15
|
const handleDispatch = handleDispatchFactory(dispatch);
|
|
17
16
|
return {
|
|
18
|
-
shards,
|
|
19
17
|
raw,
|
|
20
18
|
dispatch,
|
|
21
19
|
fromDispatch,
|
|
22
20
|
handleDispatch,
|
|
23
21
|
};
|
|
24
|
-
})(tsplus_module_6.share(tsplus_module_4.chainPar((s) => s.dispatch)(shards))))(tsplus_module_6.share(tsplus_module_4.chainPar((s) => s.raw)(shards))))(
|
|
22
|
+
})(tsplus_module_6.share(tsplus_module_4.chainPar((s) => s.dispatch)(sharder.shards))))(tsplus_module_6.share(tsplus_module_4.chainPar((s) => s.raw)(sharder.shards))))(tsplus_module_7.service(Sharder));
|
|
25
23
|
export const DiscordGateway = tsplus_module_8.Tag();
|
|
26
24
|
export const LiveDiscordGateway = tsplus_module_9.fromEffect(DiscordGateway)(make);
|
|
27
|
-
export const fromDispatch = (event) => tsplus_module_10.unwrap(tsplus_module_7.serviceWith(DiscordGateway)((a) => a.fromDispatch(event)));
|
|
28
|
-
export const handleDispatch = (event, handle) => tsplus_module_7.serviceWithEffect(DiscordGateway)((a) => a.handleDispatch(event, handle));
|
|
29
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/DiscordGateway/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/DiscordGateway/index.ts"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C,CAAC,IAAI,CAAC,CAAA"}
|
package/DiscordREST/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { RateLimit, Http } from "dfx";
|
|
1
|
+
import { RateLimit, Http, Discord } from "dfx";
|
|
2
2
|
import { Effect } from "@effect/io/Effect";
|
|
3
3
|
import { Success } from "dfx/utils/effect";
|
|
4
4
|
import { ResponseWithData } from "./types.js";
|
|
5
|
-
declare const make: import("../global.js").Effect<import("../Log/index.js").Log | import("../
|
|
5
|
+
declare const make: import("../global.js").Effect<import("../Log/index.js").Log | import("../DiscordConfig/index.js").DiscordConfig | import("../Http/index.js").Http | import("../RateLimit/index.js").RateLimitStore | import("../RateLimit/index.js").RateLimiter, never, {
|
|
6
6
|
request: <A = unknown>(path: string, init?: RequestInit) => import("../global.js").Effect<never, import("../Http/index.js").FetchError | import("../Http/index.js").StatusCodeError | import("../Http/index.js").JsonParseError, ResponseWithData<A>>;
|
|
7
|
+
routes: import("../types.js").Endpoints<RequestInit>;
|
|
7
8
|
}>;
|
|
8
9
|
export interface DiscordREST extends Success<typeof make> {
|
|
9
10
|
}
|
|
10
11
|
export declare const DiscordREST: import("../global.js").Tag<DiscordREST>;
|
|
11
|
-
export declare const LiveDiscordREST: import("../global.js").Layer<import("../Log/index.js").Log | import("../
|
|
12
|
-
export declare const rest: import("../types.js").Endpoints<RequestInit>;
|
|
12
|
+
export declare const LiveDiscordREST: import("../global.js").Layer<import("../Log/index.js").Log | import("../DiscordConfig/index.js").DiscordConfig | import("../Http/index.js").Http | import("../RateLimit/index.js").RateLimitStore | import("../RateLimit/index.js").RateLimiter, never, DiscordREST>;
|
|
13
13
|
export {};
|
package/DiscordREST/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as tsplus_module_1 from "
|
|
2
|
-
import * as tsplus_module_2 from "@
|
|
3
|
-
import * as tsplus_module_3 from "@fp-ts/data/
|
|
4
|
-
import * as tsplus_module_4 from "
|
|
1
|
+
import * as tsplus_module_1 from "dfx";
|
|
2
|
+
import * as tsplus_module_2 from "@effect/io/Effect";
|
|
3
|
+
import * as tsplus_module_3 from "@fp-ts/data/Duration";
|
|
4
|
+
import * as tsplus_module_4 from "@fp-ts/data/Option";
|
|
5
5
|
import * as tsplus_module_5 from "@fp-ts/data/HashSet";
|
|
6
6
|
import * as tsplus_module_6 from "@effect/io/Ref";
|
|
7
7
|
import * as tsplus_module_7 from "@fp-ts/data/Context";
|
|
@@ -9,41 +9,41 @@ import * as tsplus_module_8 from "@effect/io/Layer";
|
|
|
9
9
|
import { millis } from "@fp-ts/data/Duration";
|
|
10
10
|
import { rateLimitFromHeaders, routeFromConfig, retryAfter } from "./utils.js";
|
|
11
11
|
import Pkg from "../package.json" assert { type: "json" };
|
|
12
|
-
const make =
|
|
12
|
+
const make = tsplus_module_2.flatMap(http => tsplus_module_2.flatMap(({ token, rest }) => tsplus_module_2.flatMap(log => tsplus_module_2.flatMap(store => tsplus_module_2.flatMap(({ maybeWait }) => {
|
|
13
13
|
const globalRateLimit = maybeWait("dfx.rest.global", rest.globalRateLimit.window, rest.globalRateLimit.limit);
|
|
14
|
-
return
|
|
15
|
-
const addBadRoute = (route) =>
|
|
14
|
+
return tsplus_module_2.map(badRoutesRef => {
|
|
15
|
+
const addBadRoute = (route) => tsplus_module_2.collectAllParDiscard([
|
|
16
16
|
log.info("DiscordREST", "addBadRoute", route),
|
|
17
17
|
tsplus_module_6.update((s) => tsplus_module_5.add(route)(s))(badRoutesRef),
|
|
18
|
-
store.incrementCounter("dfx.rest.invalid",
|
|
18
|
+
store.incrementCounter("dfx.rest.invalid", tsplus_module_3.minutes(10).millis, 10000),
|
|
19
19
|
]);
|
|
20
|
-
const isBadRoute = (route) =>
|
|
20
|
+
const isBadRoute = (route) => tsplus_module_2.map((s) => tsplus_module_5.has(route)(s))(tsplus_module_6.get(badRoutesRef));
|
|
21
21
|
const removeBadRoute = (route) => tsplus_module_6.update((s) => tsplus_module_5.remove(route)(s))(badRoutesRef);
|
|
22
|
-
const invalidRateLimit = (route) =>
|
|
23
|
-
? maybeWait("dfx.rest.invalid",
|
|
24
|
-
:
|
|
22
|
+
const invalidRateLimit = (route) => tsplus_module_2.asUnit(tsplus_module_2.tap((invalid) => invalid
|
|
23
|
+
? maybeWait("dfx.rest.invalid", tsplus_module_3.minutes(10), 10000)
|
|
24
|
+
: tsplus_module_2.unit())(isBadRoute(route)));
|
|
25
25
|
// Request rate limiting
|
|
26
26
|
const requestRateLimit = (path, init) => (() => {
|
|
27
27
|
const route = routeFromConfig(path, init);
|
|
28
|
-
return
|
|
29
|
-
const bucket =
|
|
28
|
+
return tsplus_module_2.flatMap(maybeBucket => {
|
|
29
|
+
const bucket = tsplus_module_4.getOrElse(() => ({
|
|
30
30
|
key: `?.${route}`,
|
|
31
31
|
resetAfter: 5000,
|
|
32
32
|
limit: 1,
|
|
33
33
|
}))(maybeBucket);
|
|
34
34
|
const resetAfter = millis(bucket.resetAfter);
|
|
35
|
-
return
|
|
35
|
+
return tsplus_module_2.flatMap(() => tsplus_module_2.map(() => void 0)(maybeWait(`dfx.rest.${bucket.key}`, resetAfter, bucket.limit)))(invalidRateLimit(route));
|
|
36
36
|
})(store.getBucketForRoute(route));
|
|
37
37
|
})();
|
|
38
38
|
// Update rate limit buckets
|
|
39
|
-
const updateBuckets = (path, init, response) =>
|
|
39
|
+
const updateBuckets = (path, init, response) => tsplus_module_2.ignore((() => {
|
|
40
40
|
const route = routeFromConfig(path, init);
|
|
41
|
-
return
|
|
41
|
+
return tsplus_module_2.flatMap(({ bucket, retryAfter, limit, remaining }) => {
|
|
42
42
|
const effectsToRun = [
|
|
43
43
|
removeBadRoute(route),
|
|
44
44
|
store.putBucketRoute(route, bucket),
|
|
45
45
|
];
|
|
46
|
-
return
|
|
46
|
+
return tsplus_module_2.flatMap(hasBucket => {
|
|
47
47
|
if (!hasBucket || limit - 1 === remaining) {
|
|
48
48
|
effectsToRun.push(store.putBucket({
|
|
49
49
|
key: bucket,
|
|
@@ -51,28 +51,28 @@ const make = tsplus_module_1.flatMap(({ token, rest }) => tsplus_module_1.flatMa
|
|
|
51
51
|
limit: !hasBucket && remaining > 0 ? remaining : limit,
|
|
52
52
|
}));
|
|
53
53
|
}
|
|
54
|
-
return
|
|
54
|
+
return tsplus_module_2.map(() => void 0)(tsplus_module_2.collectAllParDiscard(effectsToRun));
|
|
55
55
|
})(store.hasBucket(bucket));
|
|
56
|
-
})(
|
|
56
|
+
})(tsplus_module_2.fromOption(rateLimitFromHeaders(response.headers)));
|
|
57
57
|
})());
|
|
58
|
-
const request = (path, init = {}) =>
|
|
58
|
+
const request = (path, init = {}) => tsplus_module_2.catchTag("StatusCodeError", (e) => {
|
|
59
59
|
switch (e.code) {
|
|
60
60
|
case 403:
|
|
61
|
-
return
|
|
61
|
+
return tsplus_module_2.flatMap(() => tsplus_module_2.fail(e))(tsplus_module_2.collectAllParDiscard([
|
|
62
62
|
log.info("DiscordREST", "403", path),
|
|
63
63
|
addBadRoute(routeFromConfig(path, init)),
|
|
64
64
|
updateBuckets(path, init, e.response),
|
|
65
65
|
]));
|
|
66
66
|
case 429:
|
|
67
|
-
return
|
|
67
|
+
return tsplus_module_2.flatMap(() => request(path, init))(tsplus_module_2.collectAllParDiscard([
|
|
68
68
|
log.info("DiscordREST", "429", path),
|
|
69
69
|
addBadRoute(routeFromConfig(path, init)),
|
|
70
70
|
updateBuckets(path, init, e.response),
|
|
71
|
-
|
|
71
|
+
tsplus_module_2.sleep(tsplus_module_4.getOrElse(() => tsplus_module_3.seconds(5))(retryAfter(e.response.headers))),
|
|
72
72
|
]));
|
|
73
73
|
}
|
|
74
|
-
return
|
|
75
|
-
})(
|
|
74
|
+
return tsplus_module_2.fail(e);
|
|
75
|
+
})(tsplus_module_2.flatMap(() => tsplus_module_2.flatMap(() => tsplus_module_2.flatMap(response => tsplus_module_2.map(() => response)(updateBuckets(path, init, response.response)))(http.requestWithJson(`${rest.baseUrl}${path}`, {
|
|
76
76
|
...init,
|
|
77
77
|
headers: {
|
|
78
78
|
...(init?.headers ?? {}),
|
|
@@ -80,42 +80,42 @@ const make = tsplus_module_1.flatMap(({ token, rest }) => tsplus_module_1.flatMa
|
|
|
80
80
|
"User-Agent": `DiscordBot (https://github.com/tim-smart/dfx, ${Pkg.version})`,
|
|
81
81
|
},
|
|
82
82
|
})))(globalRateLimit))(requestRateLimit(path, init)));
|
|
83
|
-
|
|
83
|
+
const routes = tsplus_module_1.Discord.createRoutes(({ method, url, params, options = {}, }) => {
|
|
84
|
+
const hasBody = method !== "GET" && method !== "DELETE";
|
|
85
|
+
let hasFormData = typeof options?.body?.append === "function";
|
|
86
|
+
let body = undefined;
|
|
87
|
+
const headers = {};
|
|
88
|
+
if (hasBody && !hasFormData) {
|
|
89
|
+
headers["content-type"] = "application/json";
|
|
90
|
+
}
|
|
91
|
+
const qs = new URLSearchParams();
|
|
92
|
+
if (!hasBody) {
|
|
93
|
+
Object.entries((params ?? {})).forEach(([key, value]) => {
|
|
94
|
+
qs.append(key, value);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else if (hasFormData) {
|
|
98
|
+
body = options.body;
|
|
99
|
+
if (params) {
|
|
100
|
+
;
|
|
101
|
+
body.append("payload_json", JSON.stringify(params));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (params) {
|
|
105
|
+
body = JSON.stringify(params);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
body = options.body;
|
|
109
|
+
}
|
|
110
|
+
return request(`${url}?${qs.toString()}`, {
|
|
111
|
+
method,
|
|
112
|
+
headers,
|
|
113
|
+
body,
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
return { request, routes };
|
|
84
117
|
})(tsplus_module_6.make(tsplus_module_5.empty()));
|
|
85
|
-
})(
|
|
118
|
+
})(tsplus_module_2.service(tsplus_module_1.RateLimit.RateLimiter)))(tsplus_module_2.service(tsplus_module_1.RateLimit.RateLimitStore)))(tsplus_module_2.service(tsplus_module_1.Log.Log)))(tsplus_module_2.service(tsplus_module_1.Config.DiscordConfig)))(tsplus_module_2.service(tsplus_module_1.Http.Http));
|
|
86
119
|
export const DiscordREST = tsplus_module_7.Tag();
|
|
87
120
|
export const LiveDiscordREST = tsplus_module_8.fromEffect(DiscordREST)(make);
|
|
88
|
-
export const rest = tsplus_module_4.Discord.createRoutes(({ method, url, params, options = {} }) => tsplus_module_1.serviceWithEffect(DiscordREST)(({ request }) => {
|
|
89
|
-
const hasBody = method !== "GET" && method !== "DELETE";
|
|
90
|
-
let hasFormData = typeof options?.body?.append === "function";
|
|
91
|
-
let body = undefined;
|
|
92
|
-
const headers = {};
|
|
93
|
-
if (hasBody && !hasFormData) {
|
|
94
|
-
headers["content-type"] = "application/json";
|
|
95
|
-
}
|
|
96
|
-
const qs = new URLSearchParams();
|
|
97
|
-
if (!hasBody) {
|
|
98
|
-
Object.entries((params ?? {})).forEach(([key, value]) => {
|
|
99
|
-
qs.append(key, value);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
else if (hasFormData) {
|
|
103
|
-
body = options.body;
|
|
104
|
-
if (params) {
|
|
105
|
-
;
|
|
106
|
-
body.append("payload_json", JSON.stringify(params));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else if (params) {
|
|
110
|
-
body = JSON.stringify(params);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
body = options.body;
|
|
114
|
-
}
|
|
115
|
-
return request(`${url}?${qs.toString()}`, {
|
|
116
|
-
method,
|
|
117
|
-
headers,
|
|
118
|
-
body,
|
|
119
|
-
});
|
|
120
|
-
}));
|
|
121
121
|
//# sourceMappingURL=index.js.map
|
package/DiscordREST/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/DiscordREST/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE7C,OAAO,EA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ect } from "@effect/io/Effect";
|
|
2
2
|
import { Http } from "dfx";
|
|
3
|
-
import { DiscordREST } from "./index.js";
|
|
4
3
|
export interface ResponseWithData<A> {
|
|
5
4
|
response: Response;
|
|
6
5
|
json: Effect<never, Http.JsonParseError, A>;
|
|
7
6
|
text: Effect<never, never, string>;
|
|
8
7
|
blob: Effect<never, Http.BlobError, Blob>;
|
|
9
8
|
}
|
|
10
|
-
export type RestResponse<T> = Effect<
|
|
9
|
+
export type RestResponse<T> = Effect<never, Http.FetchError | Http.StatusCodeError | Http.JsonParseError, ResponseWithData<T>>;
|
package/Http/index.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
declare const make: () => {
|
|
2
|
+
request: (url: URL | string, init?: RequestInit) => import("../global.js").Effect<never, FetchError | StatusCodeError, Response>;
|
|
3
|
+
requestWithJson: <A = unknown>(url: URL | string, init?: RequestInit) => import("../global.js").Effect<never, FetchError | StatusCodeError, {
|
|
4
|
+
response: Response;
|
|
5
|
+
json: import("../global.js").Effect<never, JsonParseError, A>;
|
|
6
|
+
blob: import("../global.js").Effect<never, BlobError, Blob>;
|
|
7
|
+
text: import("../global.js").Effect<never, never, string>;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
export interface Http extends ReturnType<typeof make> {
|
|
11
|
+
}
|
|
12
|
+
export declare const Http: import("../global.js").Tag<Http>;
|
|
13
|
+
export declare const LiveHttp: import("../global.js").Layer<never, never, Http>;
|
|
1
14
|
export declare class FetchError {
|
|
2
15
|
readonly reason: unknown;
|
|
3
16
|
readonly _tag = "FetchError";
|
|
@@ -9,7 +22,6 @@ export declare class StatusCodeError {
|
|
|
9
22
|
readonly code: number;
|
|
10
23
|
constructor(response: Response);
|
|
11
24
|
}
|
|
12
|
-
export declare const request: (url: URL | string, init?: RequestInit) => import("../global.js").Effect<never, FetchError | StatusCodeError, Response>;
|
|
13
25
|
export declare class JsonParseError {
|
|
14
26
|
readonly reason: unknown;
|
|
15
27
|
readonly _tag = "JsonParseError";
|
|
@@ -22,9 +34,4 @@ export declare class BlobError {
|
|
|
22
34
|
constructor(reason: unknown);
|
|
23
35
|
}
|
|
24
36
|
export declare const blob: (r: Response) => import("../global.js").Effect<never, BlobError, Blob>;
|
|
25
|
-
export
|
|
26
|
-
response: Response;
|
|
27
|
-
json: import("../global.js").Effect<never, JsonParseError, A>;
|
|
28
|
-
blob: import("../global.js").Effect<never, BlobError, Blob>;
|
|
29
|
-
text: import("../global.js").Effect<never, never, string>;
|
|
30
|
-
}>;
|
|
37
|
+
export {};
|
package/Http/index.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import * as tsplus_module_1 from "@effect/io/Effect";
|
|
2
|
+
import * as tsplus_module_2 from "@fp-ts/data/Context";
|
|
3
|
+
import * as tsplus_module_3 from "@effect/io/Layer";
|
|
4
|
+
const make = () => {
|
|
5
|
+
const request = (url, init = {}) => tsplus_module_1.filterOrElseWith((r) => r.status < 300, (r) => tsplus_module_1.fail(new StatusCodeError(r)))(tsplus_module_1.tryCatchPromiseAbort((signal) => fetch(url, {
|
|
6
|
+
...init,
|
|
7
|
+
signal,
|
|
8
|
+
}), (e) => new FetchError(e)));
|
|
9
|
+
const requestWithJson = (url, init = {}) => tsplus_module_1.map((response) => ({
|
|
10
|
+
response,
|
|
11
|
+
json: json(response),
|
|
12
|
+
blob: blob(response),
|
|
13
|
+
text: tsplus_module_1.promise(() => response.text()),
|
|
14
|
+
}))(request(url, init));
|
|
15
|
+
return { request, requestWithJson };
|
|
16
|
+
};
|
|
17
|
+
export const Http = tsplus_module_2.Tag();
|
|
18
|
+
export const LiveHttp = tsplus_module_3.sync(Http)(make);
|
|
2
19
|
export class FetchError {
|
|
3
20
|
reason;
|
|
4
21
|
_tag = "FetchError";
|
|
@@ -15,10 +32,6 @@ export class StatusCodeError {
|
|
|
15
32
|
this.code = response.status;
|
|
16
33
|
}
|
|
17
34
|
}
|
|
18
|
-
export const request = (url, init = {}) => tsplus_module_1.filterOrElseWith((r) => r.status < 300, (r) => tsplus_module_1.fail(new StatusCodeError(r)))(tsplus_module_1.tryCatchPromiseAbort((signal) => fetch(url, {
|
|
19
|
-
...init,
|
|
20
|
-
signal,
|
|
21
|
-
}), (e) => new FetchError(e)));
|
|
22
35
|
export class JsonParseError {
|
|
23
36
|
reason;
|
|
24
37
|
_tag = "JsonParseError";
|
|
@@ -35,10 +48,4 @@ export class BlobError {
|
|
|
35
48
|
}
|
|
36
49
|
}
|
|
37
50
|
export const blob = (r) => tsplus_module_1.tryCatchPromise(() => r.blob(), (reason) => new BlobError(reason));
|
|
38
|
-
export const requestWithJson = (url, init = {}) => tsplus_module_1.map((response) => ({
|
|
39
|
-
response,
|
|
40
|
-
json: json(response),
|
|
41
|
-
blob: blob(response),
|
|
42
|
-
text: tsplus_module_1.promise(() => response.text()),
|
|
43
|
-
}))(request(url, init));
|
|
44
51
|
//# sourceMappingURL=index.js.map
|
package/Http/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Http/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Http/index.ts"],"names":[],"mappings":";;;AAAA,MAAM,IAAI,GAAG,GAAG,EAAE;IAChB,MAAM,OAAO,GAAG,CAAC,GAAiB,EAAE,OAAoB,EAAE,EAAE,EAAE,CAC5D,iCAQE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,GAAG,EACrB,CAAC,CAAC,EAAE,EAAE,CAAC,qBAAY,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC,EAT5C,qCACE,CAAC,MAAM,EAAE,EAAE,CACT,KAAK,CAAC,GAAG,EAAE;QACT,GAAG,IAAI;QACP,MAAM;KACP,CAAC,EACJ,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CACzB,CAGA,CAAA;IAEH,MAAM,eAAe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,SAAS;IAEC;IADZ,IAAI,GAAG,WAAW,CAAA;IAC3B,YAAqB,MAAe;QAAf,WAAM,GAAN,MAAM,CAAS;IAAG,CAAC;CACzC;AAED,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAW,EAAE,EAAE,CAClC,gCACE,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,EACd,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC,CAClC,CAAA"}
|
|
@@ -5,4 +5,4 @@ import { InteractionBuilder } from "./index.js";
|
|
|
5
5
|
export interface RunOpts {
|
|
6
6
|
sync?: boolean;
|
|
7
7
|
}
|
|
8
|
-
export declare const run: <R, R2, E, E2>(postHandler: (effect: import("../global.js").Effect<import("../
|
|
8
|
+
export declare const run: <R, R2, E, E2>(postHandler: (effect: import("../global.js").Effect<import("../index.js").DiscordREST | import("../types.js").Interaction | R, import("../Http/index.js").FetchError | import("../Http/index.js").StatusCodeError | import("../Http/index.js").JsonParseError | DefinitionNotFound | E, void>) => import("../global.js").Effect<R2, E2, void>, { sync }?: RunOpts) => (ix: InteractionBuilder<R, E>) => import("../global.js").Effect<import("../index.js").DiscordREST | import("../DiscordGateway/index.js").DiscordGateway | Exclude<R2, import("../types.js").Interaction>, import("../Http/index.js").FetchError | import("../Http/index.js").StatusCodeError | import("../Http/index.js").JsonParseError | E2, void>;
|
package/Interactions/gateway.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import * as tsplus_module_1 from "@effect/io/Effect";
|
|
2
|
-
import * as tsplus_module_2 from "
|
|
3
|
-
import * as tsplus_module_3 from "
|
|
2
|
+
import * as tsplus_module_2 from "@fp-ts/data/Function";
|
|
3
|
+
import * as tsplus_module_3 from "dfx";
|
|
4
4
|
import * as tsplus_module_4 from "dfx/gateway";
|
|
5
5
|
import { handlers } from "./handlers.js";
|
|
6
6
|
import { InteractionContext } from "./index.js";
|
|
7
7
|
import { splitDefinitions } from "./utils.js";
|
|
8
8
|
export const run = (postHandler, { sync = true } = {}) => (ix) => (() => {
|
|
9
9
|
const { GlobalApplicationCommand, GuildApplicationCommand } = splitDefinitions(ix.definitions);
|
|
10
|
-
return tsplus_module_1.flatMap(application => {
|
|
11
|
-
const globalSync =
|
|
10
|
+
return tsplus_module_1.flatMap(gateway => tsplus_module_1.flatMap(({ routes: rest }) => tsplus_module_1.flatMap(application => {
|
|
11
|
+
const globalSync = rest.bulkOverwriteGlobalApplicationCommands(application.id, {
|
|
12
12
|
body: JSON.stringify(GlobalApplicationCommand.map((a) => a.command)),
|
|
13
13
|
});
|
|
14
14
|
const guildSync = GuildApplicationCommand.length
|
|
15
|
-
?
|
|
15
|
+
? gateway.handleDispatch("GUILD_CREATE", (a) => rest.bulkOverwriteGuildApplicationCommands(application.id, a.id, GuildApplicationCommand.map((a) => a.command)))
|
|
16
16
|
: tsplus_module_1.unit();
|
|
17
17
|
const handle = handlers(ix.definitions);
|
|
18
|
-
const run =
|
|
18
|
+
const run = gateway.handleDispatch("INTERACTION_CREATE", (i) => tsplus_module_2.pipe(tsplus_module_1.tap((r) => rest.createInteractionResponse(i.id, i.token, r))(handle[i.type](i)), postHandler, tsplus_module_1.provideService(InteractionContext)(i)));
|
|
19
19
|
return tsplus_module_1.map(() => void 0)(sync ? tsplus_module_1.zipPar(guildSync)(tsplus_module_1.zipPar(globalSync)(run)) : run);
|
|
20
|
-
})(tsplus_module_1.flatMap((a) => a.json)(
|
|
20
|
+
})(tsplus_module_1.flatMap((a) => a.json)(rest.getCurrentBotApplicationInformation())))(tsplus_module_1.service(tsplus_module_3.DiscordREST)))(tsplus_module_1.service(tsplus_module_4.Gateway.DiscordGateway));
|
|
21
21
|
})();
|
|
22
22
|
//# sourceMappingURL=gateway.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../src/Interactions/gateway.ts"],"names":[],"mappings":";;;;AAAA,OAAO,EAAsB,QAAQ,EAAE,M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