dfx 0.0.2 → 0.0.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.
Files changed (51) hide show
  1. package/DiscordREST/types.d.ts +7 -0
  2. package/DiscordShard/commands.d.ts +7 -0
  3. package/DiscordShard/commands.js +38 -0
  4. package/DiscordShard/commands.js.map +1 -0
  5. package/DiscordShard/commands.ts +40 -0
  6. package/DiscordShard/heartbeats.d.ts +7 -0
  7. package/DiscordShard/heartbeats.js +33 -0
  8. package/DiscordShard/heartbeats.js.map +1 -0
  9. package/DiscordShard/heartbeats.ts +70 -0
  10. package/DiscordShard/identify.d.ts +16 -0
  11. package/DiscordShard/identify.js +35 -0
  12. package/DiscordShard/identify.js.map +1 -0
  13. package/DiscordShard/identify.ts +76 -0
  14. package/DiscordShard/index.d.ts +32 -0
  15. package/DiscordShard/index.js +60 -0
  16. package/DiscordShard/index.js.map +1 -0
  17. package/DiscordShard/index.ts +110 -0
  18. package/DiscordShard/invalidSession.d.ts +7 -0
  19. package/DiscordShard/invalidSession.js +17 -0
  20. package/DiscordShard/invalidSession.js.map +1 -0
  21. package/DiscordShard/invalidSession.ts +25 -0
  22. package/DiscordShard/utils.d.ts +9 -0
  23. package/DiscordShard/utils.js +24 -0
  24. package/DiscordShard/utils.js.map +1 -0
  25. package/DiscordShard/utils.ts +47 -0
  26. package/DiscordWS/index.d.ts +32 -0
  27. package/DiscordWS/index.js +35 -0
  28. package/DiscordWS/index.js.map +1 -1
  29. package/DiscordWS/index.ts +79 -0
  30. package/Log/index.d.ts +12 -0
  31. package/Log/index.js +19 -0
  32. package/Log/index.js.map +1 -0
  33. package/Log/index.ts +20 -0
  34. package/WS/index.d.ts +32 -0
  35. package/WS/index.js +12 -13
  36. package/WS/index.js.map +1 -1
  37. package/WS/index.ts +19 -27
  38. package/bot.d.ts +1 -0
  39. package/bot.js +33 -0
  40. package/bot.js.map +1 -0
  41. package/bot.ts +51 -0
  42. package/mod.d.ts +3 -0
  43. package/mod.js +5 -7
  44. package/mod.js.map +1 -1
  45. package/mod.ts +6 -22
  46. package/package.json +22 -3
  47. package/types.d.ts +3584 -0
  48. package/discord-api-docs/ci/checkLinks.ts +0 -177
  49. package/discord-api-docs/index.js +0 -1
  50. package/websocket.js +0 -11
  51. package/websocket.js.map +0 -1
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fromDispatch = exports.latest = exports.opCode = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
6
+ const fileName_1 = "DiscordShard/utils.ts";
7
+ const T = tslib_1.__importStar(require("@effect-ts/core/Effect"));
8
+ const S = tslib_1.__importStar(require("@effect-ts/core/Effect/Experimental/Stream"));
9
+ const R = tslib_1.__importStar(require("@effect-ts/core/Effect/Ref"));
10
+ const Function_1 = require("@effect-ts/core/Function");
11
+ const O = tslib_1.__importStar(require("@effect-ts/core/Option"));
12
+ const opCode = (hub) => (code) => (S.filter_(S.fromHub_(hub), (p) => p.op === code));
13
+ exports.opCode = opCode;
14
+ const latest = (f) => T.gen(function* (_) {
15
+ const ref = yield* _(R.makeRef(O.none), fileName_1 + ":24:25");
16
+ return [
17
+ ref,
18
+ S.tap((0, Function_1.flow)(f, O.fold(() => T.unit, (a) => R.set_(ref, O.some(a))))),
19
+ ];
20
+ }, fileName_1 + ":23:8");
21
+ exports.latest = latest;
22
+ const fromDispatch = (hub) => (event) => (S.map_(S.filter_(S.fromHub_(hub), (p) => p.t === event), (p) => p.d));
23
+ exports.fromDispatch = fromDispatch;
24
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA2C;AAC3C,sFAA+D;AAE/D,sEAA+C;AAC/C,uDAAqD;AACrD,kEAA2C;AAQpC,MAAM,MAAM,GACjB,CAAC,GAA0B,EAAE,EAAE,CAC/B,CAAU,IAAmB,EAA4B,EAAE,EAGvD,CAAC,SADD,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EACN,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,EAC9B,CAAA;AANQ,QAAA,MAAM,UAMd;AAEE,MAAM,MAAM,GAAG,CAAI,CAAqC,EAAE,EAAE,CACjE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;IAChB,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAc,CAAC,CAAC,IAAI,CAAC,wBAAC,CAAA;IAEpD,OAAO;QACL,GAAG;QACH,CAAC,CAAC,GAAG,CACH,IAAA,eAAI,EACF,CAAC,EACD,CAAC,CAAC,IAAI,CACJ,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,EACZ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAC9B,CACF,CACF;KACO,CAAA;AACZ,CAAC,uBAAC,CAAA;AAhBS,QAAA,MAAM,UAgBf;AAEG,MAAM,YAAY,GACvB,CAAC,GAAwC,EAAE,EAAE,CAC7C,CAAgC,KAAQ,EAAE,EAAE,EAIxC,CAAC,MADD,CAAC,SADD,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EACN,CAAC,CAAC,EAAyC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,GAC9D,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAqB,EACrC,CAAA;AAPQ,QAAA,YAAY,gBAOpB"}
@@ -0,0 +1,47 @@
1
+ import * as T from "@effect-ts/core/Effect"
2
+ import * as S from "@effect-ts/core/Effect/Experimental/Stream"
3
+ import * as H from "@effect-ts/core/Effect/Hub"
4
+ import * as R from "@effect-ts/core/Effect/Ref"
5
+ import { flow, pipe } from "@effect-ts/core/Function"
6
+ import * as O from "@effect-ts/core/Option"
7
+ import {
8
+ GatewayEvent,
9
+ GatewayEvents,
10
+ GatewayOpcode,
11
+ GatewayPayload,
12
+ } from "../types"
13
+
14
+ export const opCode =
15
+ (hub: H.Hub<GatewayPayload>) =>
16
+ <T = any>(code: GatewayOpcode): S.UIO<GatewayPayload<T>> =>
17
+ pipe(
18
+ S.fromHub_(hub),
19
+ S.filter((p) => p.op === code)
20
+ )
21
+
22
+ export const latest = <T>(f: (p: GatewayPayload) => O.Option<T>) =>
23
+ T.gen(function* (_) {
24
+ const ref = yield* _(R.makeRef<O.Option<T>>(O.none))
25
+
26
+ return [
27
+ ref,
28
+ S.tap(
29
+ flow(
30
+ f,
31
+ O.fold(
32
+ () => T.unit,
33
+ (a) => R.set_(ref, O.some(a))
34
+ )
35
+ )
36
+ ),
37
+ ] as const
38
+ })
39
+
40
+ export const fromDispatch =
41
+ (hub: H.Hub<GatewayPayload<GatewayEvent>>) =>
42
+ <K extends keyof GatewayEvents>(event: K) =>
43
+ pipe(
44
+ S.fromHub_(hub),
45
+ S.filter((p): p is GatewayPayload<GatewayEvents[K]> => p.t === event),
46
+ S.map((p) => p.d as GatewayEvents[K])
47
+ )
@@ -0,0 +1,32 @@
1
+ /// <reference types="node" />
2
+ import * as T from "@effect-ts/core/Effect";
3
+ import * as S from "@effect-ts/core/Effect/Experimental/Stream";
4
+ import { RawData } from "ws";
5
+ import { GatewayPayload } from "../types";
6
+ import * as WS from "../WS";
7
+ export declare type Message = GatewayPayload | WS.Reconnect;
8
+ export interface OpenOpts {
9
+ url?: string;
10
+ version?: number;
11
+ encoding?: Encoding;
12
+ outgoing: WS.OutboundStream<Message>;
13
+ }
14
+ export interface Encoding {
15
+ type: "json" | "etf";
16
+ encode: (p: GatewayPayload) => string | Buffer | ArrayBuffer;
17
+ decode: (p: RawData) => GatewayPayload;
18
+ }
19
+ export declare const jsonEncoding: Encoding;
20
+ declare const openImpl: ({ url, version, encoding, outgoing, }: OpenOpts) => S.Stream<import("@effect-ts/system/Has").Has<WS.WS> & import("@effect-ts/system/Clock").HasClock & import("@effect-ts/system/Has").Has<import("../Log").Log>, unknown, GatewayPayload<any>>;
21
+ export declare type Connection = ReturnType<typeof openImpl>;
22
+ declare const service: {
23
+ readonly _tag: "DiscordWSService";
24
+ readonly open: ({ url, version, encoding, outgoing, }: OpenOpts) => S.Stream<import("@effect-ts/system/Has").Has<WS.WS> & import("@effect-ts/system/Clock").HasClock & import("@effect-ts/system/Has").Has<import("../Log").Log>, unknown, GatewayPayload<any>>;
25
+ };
26
+ declare type Service = typeof service;
27
+ export interface DiscordWS extends Service {
28
+ }
29
+ export declare const DiscordWS: import("@effect-ts/system/Has").Tag<DiscordWS>;
30
+ export declare const LiveDiscordWS: import("@effect-ts/system/Layer").Layer<unknown, never, import("@effect-ts/system/Has").Has<DiscordWS>>;
31
+ export declare const open: (opts: OpenOpts) => T.Effect<import("@effect-ts/system/Has").Has<DiscordWS>, never, S.Stream<import("@effect-ts/system/Has").Has<WS.WS> & import("@effect-ts/system/Clock").HasClock & import("@effect-ts/system/Has").Has<import("../Log").Log>, unknown, GatewayPayload<any>>>;
32
+ export {};
@@ -1,2 +1,37 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.open = exports.LiveDiscordWS = exports.DiscordWS = exports.jsonEncoding = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
6
+ const fileName_1 = "DiscordWS/index.ts";
7
+ const T = tslib_1.__importStar(require("@effect-ts/core/Effect"));
8
+ const S = tslib_1.__importStar(require("@effect-ts/core/Effect/Experimental/Stream"));
9
+ const SC = tslib_1.__importStar(require("@effect-ts/core/Effect/Schedule"));
10
+ const Function_1 = require("@effect-ts/core/Function");
11
+ const Has_1 = require("@effect-ts/core/Has");
12
+ const Log_1 = require("../Log");
13
+ const WS = tslib_1.__importStar(require("../WS"));
14
+ exports.jsonEncoding = {
15
+ type: "json",
16
+ encode: (p) => JSON.stringify(p),
17
+ decode: (p) => JSON.parse(p.toString("utf8")),
18
+ };
19
+ const makeOutgoing = (s, e) => (S.map_(s, (data) => {
20
+ if (data === WS.Reconnect) {
21
+ return data;
22
+ }
23
+ return e.encode(data);
24
+ }));
25
+ const openImpl = ({ url = "wss://gateway.discord.gg/", version = 9, encoding = exports.jsonEncoding, outgoing, }) => (S.map_(S.retry_(S.onError_(S.unwrap(WS.open(`${url}?v=${version}&encoding=${encoding.type}`, makeOutgoing(outgoing, encoding))), (e) => e._tag === "Fail" ? (0, Log_1.log)(serviceTag, "error", e.value) : T.unit), SC.exponential(250)), encoding.decode));
26
+ // Service definition
27
+ const serviceTag = "DiscordWSService";
28
+ const service = {
29
+ _tag: serviceTag,
30
+ open: openImpl,
31
+ };
32
+ exports.DiscordWS = (0, Has_1.tag)();
33
+ exports.LiveDiscordWS = T.toLayer(exports.DiscordWS)(T.succeed(service, fileName_1 + ":75:60"));
34
+ // Helpers
35
+ const open = (opts) => T.accessService(exports.DiscordWS)(({ open }) => open(opts), fileName_1 + ":79:29");
36
+ exports.open = open;
2
37
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA2C;AAC3C,sFAA+D;AAC/D,4EAAqD;AACrD,uDAA+C;AAC/C,6CAAyC;AAGzC,gCAA4B;AAE5B,kDAA2B;AAiBd,QAAA,YAAY,GAAa;IACpC,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAChC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,MAA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,IAAc,EAAE,EAAE,CACrC,CAAC,CAAC,aAAa,CAAC,iBAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,wBAAC,CAAA;AADzC,QAAA,IAAI,QACqC"}
@@ -0,0 +1,79 @@
1
+ import * as T from "@effect-ts/core/Effect"
2
+ import * as S from "@effect-ts/core/Effect/Experimental/Stream"
3
+ import * as SC from "@effect-ts/core/Effect/Schedule"
4
+ import { pipe } from "@effect-ts/core/Function"
5
+ import { tag } from "@effect-ts/core/Has"
6
+ import { _A } from "@effect-ts/core/Utils"
7
+ import { RawData } from "ws"
8
+ import { log } from "../Log"
9
+ import { GatewayPayload } from "../types"
10
+ import * as WS from "../WS"
11
+
12
+ export type Message = GatewayPayload | WS.Reconnect
13
+
14
+ export interface OpenOpts {
15
+ url?: string
16
+ version?: number
17
+ encoding?: Encoding
18
+ outgoing: WS.OutboundStream<Message>
19
+ }
20
+
21
+ export interface Encoding {
22
+ type: "json" | "etf"
23
+ encode: (p: GatewayPayload) => string | Buffer | ArrayBuffer
24
+ decode: (p: RawData) => GatewayPayload
25
+ }
26
+
27
+ export const jsonEncoding: Encoding = {
28
+ type: "json",
29
+ encode: (p) => JSON.stringify(p),
30
+ decode: (p) => JSON.parse(p.toString("utf8")),
31
+ }
32
+
33
+ const makeOutgoing = (s: S.UIO<Message>, e: Encoding): WS.OutboundStream =>
34
+ pipe(
35
+ s,
36
+ S.map((data) => {
37
+ if (data === WS.Reconnect) {
38
+ return data
39
+ }
40
+
41
+ return e.encode(data)
42
+ })
43
+ )
44
+
45
+ const openImpl = ({
46
+ url = "wss://gateway.discord.gg/",
47
+ version = 9,
48
+ encoding = jsonEncoding,
49
+ outgoing,
50
+ }: OpenOpts) =>
51
+ pipe(
52
+ WS.open(
53
+ `${url}?v=${version}&encoding=${encoding.type}`,
54
+ makeOutgoing(outgoing, encoding)
55
+ ),
56
+ S.unwrap,
57
+ S.onError((e) =>
58
+ e._tag === "Fail" ? log(serviceTag, "error", e.value) : T.unit
59
+ ),
60
+ S.retry(SC.exponential(250)),
61
+ S.map(encoding.decode)
62
+ )
63
+
64
+ export type Connection = ReturnType<typeof openImpl>
65
+
66
+ // Service definition
67
+ const serviceTag = "DiscordWSService" as const
68
+ const service = {
69
+ _tag: serviceTag,
70
+ open: openImpl,
71
+ } as const
72
+ type Service = typeof service
73
+ export interface DiscordWS extends Service {}
74
+ export const DiscordWS = tag<DiscordWS>()
75
+ export const LiveDiscordWS = T.toLayer(DiscordWS)(T.succeed(service))
76
+
77
+ // Helpers
78
+ export const open = (opts: OpenOpts) =>
79
+ T.accessService(DiscordWS)(({ open }) => open(opts))
package/Log/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import * as T from "@effect-ts/core/Effect";
2
+ declare const service: {
3
+ readonly _tag: "LogService";
4
+ readonly log: (...args: any[]) => T.UIO<void>;
5
+ };
6
+ declare type Service = typeof service;
7
+ export interface Log extends Service {
8
+ }
9
+ export declare const Log: import("@effect-ts/system/Has").Tag<Log>;
10
+ export declare const LiveLog: import("@effect-ts/system/Layer").Layer<unknown, never, import("@effect-ts/system/Has").Has<Log>>;
11
+ export declare const log: (...args: any[]) => T.Effect<import("@effect-ts/system/Has").Has<Log>, never, void>;
12
+ export {};
package/Log/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.log = exports.LiveLog = exports.Log = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
6
+ const fileName_1 = "Log/index.ts";
7
+ const T = tslib_1.__importStar(require("@effect-ts/core/Effect"));
8
+ const Has_1 = require("@effect-ts/core/Has");
9
+ const service = {
10
+ _tag: "LogService",
11
+ log: (...args) => T.succeedWith(() => {
12
+ console.error(...args);
13
+ }, fileName_1 + ":8:18"),
14
+ };
15
+ exports.Log = (0, Has_1.tag)();
16
+ exports.LiveLog = T.toLayer(exports.Log)(T.succeed(service, fileName_1 + ":17:48"));
17
+ const log = (...args) => T.accessServiceM(exports.Log)(({ log }) => log(...args), fileName_1 + ":20:24");
18
+ exports.log = log;
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA2C;AAC3C,6CAAyC;AAGzC,MAAM,OAAO,GAAG;IACd,IAAI,EAAE,YAAY;IAClB,GAAG,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE,CACtB,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE;QACjB,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;IACxB,CAAC,uBAAC;CACI,CAAA;AAKG,QAAA,GAAG,GAAG,IAAA,SAAG,GAAO,CAAA;AAChB,QAAA,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,WAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,wBAAC,CAAC,CAAA;AAElD,MAAM,GAAG,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE,CACpC,CAAC,CAAC,cAAc,CAAC,WAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,wBAAC,CAAA;AADrC,QAAA,GAAG,OACkC"}
package/Log/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ import * as T from "@effect-ts/core/Effect"
2
+ import { tag } from "@effect-ts/core/Has"
3
+ import { _A } from "@effect-ts/core/Utils"
4
+
5
+ const service = {
6
+ _tag: "LogService",
7
+ log: (...args: any[]) =>
8
+ T.succeedWith(() => {
9
+ console.error(...args)
10
+ }),
11
+ } as const
12
+
13
+ type Service = typeof service
14
+
15
+ export interface Log extends Service {}
16
+ export const Log = tag<Log>()
17
+ export const LiveLog = T.toLayer(Log)(T.succeed(service))
18
+
19
+ export const log = (...args: any[]) =>
20
+ T.accessServiceM(Log)(({ log }) => log(...args))
package/WS/index.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ /// <reference types="node" />
2
+ import * as T from "@effect-ts/core/Effect";
3
+ import * as S from "@effect-ts/core/Effect/Experimental/Stream";
4
+ import type { _A } from "@effect-ts/core/Utils";
5
+ import { HasClock } from "@effect-ts/system/Clock";
6
+ import * as Ws from "ws";
7
+ export declare type WsError = {
8
+ _tag: "close";
9
+ code: number;
10
+ reason: string;
11
+ } | {
12
+ _tag: "error";
13
+ cause: unknown;
14
+ } | {
15
+ _tag: "write";
16
+ cause: unknown;
17
+ };
18
+ export declare type WebSocketStream<T = Ws.RawData> = S.Stream<HasClock, WsError, T>;
19
+ export declare const Reconnect: unique symbol;
20
+ export declare type Reconnect = typeof Reconnect;
21
+ export declare type Message = string | Buffer | ArrayBuffer | Reconnect;
22
+ export declare type OutboundStream<T = Message> = S.UIO<T>;
23
+ declare const makeWS: T.Effect<unknown, never, {
24
+ readonly _tag: "WSService";
25
+ readonly open: (url: string, out: OutboundStream<Message>, options?: Ws.ClientOptions | undefined) => WebSocketStream<Ws.RawData>;
26
+ }>;
27
+ export interface WS extends _A<typeof makeWS> {
28
+ }
29
+ export declare const WS: import("@effect-ts/system/Has").Tag<WS>;
30
+ export declare const LiveWS: import("@effect-ts/system/Layer").Layer<unknown, never, import("@effect-ts/system/Has").Has<WS>>;
31
+ export declare const open: (url: string, out: OutboundStream<Message>, options?: Ws.ClientOptions | undefined) => T.Effect<import("@effect-ts/system/Has").Has<WS>, never, WebSocketStream<Ws.RawData>>;
32
+ export {};
package/WS/index.js CHANGED
@@ -1,22 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LiveWS = exports.WS = exports.Reconnect = void 0;
3
+ exports.open = exports.LiveWS = exports.WS = exports.Reconnect = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
6
6
  const fileName_1 = "WS/index.ts";
7
7
  const T = tslib_1.__importStar(require("@effect-ts/core/Effect"));
8
8
  const S = tslib_1.__importStar(require("@effect-ts/core/Effect/Experimental/Stream"));
9
9
  const M = tslib_1.__importStar(require("@effect-ts/core/Effect/Managed"));
10
- const Q = tslib_1.__importStar(require("@effect-ts/core/Effect/Queue"));
11
10
  const SC = tslib_1.__importStar(require("@effect-ts/core/Effect/Schedule"));
12
11
  const Function_1 = require("@effect-ts/core/Function");
13
12
  const Has_1 = require("@effect-ts/core/Has");
14
13
  const Ws = tslib_1.__importStar(require("ws"));
15
14
  exports.Reconnect = Symbol();
16
- const open = (url, options) => (M.makeExit_(T.succeedWith(() => new Ws.WebSocket(url, options), fileName_1 + ":29:18"), (ws) => T.succeedWith(() => {
15
+ const openSocket = (url, options) => (M.makeExit_(T.succeedWith(() => new Ws.WebSocket(url, options), fileName_1 + ":25:18"), (ws) => T.succeedWith(() => {
17
16
  ws.removeAllListeners();
18
17
  ws.close();
19
- }, fileName_1 + ":31:20"), fileName_1 + ":30:15"));
18
+ }, fileName_1 + ":27:20"), fileName_1 + ":26:15"));
20
19
  const recv = (ws) => S.async((emit) => {
21
20
  ws.on("message", (message) => emit.single(message));
22
21
  ws.on("error", (cause) => {
@@ -40,32 +39,32 @@ const send = (out) => (ws) => (S.drain(S.tap_(S.unwrap(T.map_(T.effectAsync((cb)
40
39
  cb(T.unit);
41
40
  });
42
41
  }
43
- }, fileName_1 + ":58:18"), () => S.fromQueue()(out), fileName_1 + ":67:10")), (data) => T.effectAsync((cb) => {
42
+ }, fileName_1 + ":54:18"), () => out, fileName_1 + ":63:10")), (data) => T.effectAsync((cb) => {
44
43
  if (data === exports.Reconnect) {
45
44
  ws.close(1012, "reconnecting");
46
45
  cb(T.unit);
47
46
  }
48
47
  else {
48
+ console.error(data);
49
49
  ws.send(data, (err) => {
50
50
  if (err) {
51
- cb(T.fail({ _tag: "write", cause: err }, fileName_1 + ":77:24"));
51
+ cb(T.fail({ _tag: "write", cause: err }, fileName_1 + ":74:24"));
52
52
  }
53
53
  else {
54
54
  cb(T.unit);
55
55
  }
56
56
  });
57
57
  }
58
- }, fileName_1 + ":70:20"))));
58
+ }, fileName_1 + ":66:20"))));
59
59
  const duplex = (out) => (ws) => (S.mergeTerminateLeft_(recv(ws), send(out)(ws)));
60
- const openDuplexWithQueue = (url, out, options) => (S.retry_(S.unwrapManaged(M.map_(open(url, options), duplex(out), fileName_1 + ":98:10")), SC.recurWhile((e) => e._tag === "close" && e.code === 1012)));
61
- const openDuplex = (url, options) => (T.map_(Q.makeUnbounded(), (write) => ({
62
- read: openDuplexWithQueue(url, write, options),
63
- write,
64
- }), fileName_1 + ":109:10"));
60
+ const openDuplex = (url, out, options) => (S.retry_(S.unwrapManaged(M.map_(openSocket(url, options), duplex(out), fileName_1 + ":95:10")), SC.recurWhile((e) => e._tag === "close" && e.code === 1012)));
65
61
  const makeWS = T.succeed({
66
62
  _tag: "WSService",
67
63
  open: openDuplex,
68
- }, fileName_1 + ":115:25");
64
+ }, fileName_1 + ":100:25");
69
65
  exports.WS = (0, Has_1.tag)();
70
66
  exports.LiveWS = T.toLayer(exports.WS)(makeWS);
67
+ // Helpers
68
+ const open = (url, out, options) => T.accessService(exports.WS)(({ open }) => open(url, out, options), fileName_1 + ":114:25");
69
+ exports.open = open;
71
70
  //# sourceMappingURL=index.js.map
package/WS/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA2C;AAC3C,sFAA+D;AAC/D,0EAAmD;AACnD,wEAAiD;AACjD,4EAAqD;AACrD,uDAA+C;AAC/C,6CAAyC;AAGzC,+CAAwB;AASX,QAAA,SAAS,GAAG,MAAM,EAAE,CAAA;AAQjC,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,OAA0B,EAAE,EAAE,EAGrD,CAAC,WADD,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CA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AW,EACX,GAAmB,EACnB,OAA0B,EAC1B,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,UAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,yBAAC,CAAA;AAJlD,QAAA,IAAI,QAI8C"}
package/WS/index.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import * as T from "@effect-ts/core/Effect"
2
2
  import * as S from "@effect-ts/core/Effect/Experimental/Stream"
3
3
  import * as M from "@effect-ts/core/Effect/Managed"
4
- import * as Q from "@effect-ts/core/Effect/Queue"
5
4
  import * as SC from "@effect-ts/core/Effect/Schedule"
6
5
  import { pipe } from "@effect-ts/core/Function"
7
6
  import { tag } from "@effect-ts/core/Has"
@@ -14,17 +13,14 @@ export type WsError =
14
13
  | { _tag: "error"; cause: unknown }
15
14
  | { _tag: "write"; cause: unknown }
16
15
 
17
- type WebSocketStream = S.Stream<HasClock, WsError, Ws.RawData>
16
+ export type WebSocketStream<T = Ws.RawData> = S.Stream<HasClock, WsError, T>
18
17
 
19
18
  export const Reconnect = Symbol()
20
- export type Message = Ws.RawData | typeof Reconnect
19
+ export type Reconnect = typeof Reconnect
20
+ export type Message = string | Buffer | ArrayBuffer | Reconnect
21
+ export type OutboundStream<T = Message> = S.UIO<T>
21
22
 
22
- export interface WebSocketConnection {
23
- read: WebSocketStream
24
- write: Q.Queue<Message>
25
- }
26
-
27
- const open = (url: string, options?: Ws.ClientOptions) =>
23
+ const openSocket = (url: string, options?: Ws.ClientOptions) =>
28
24
  pipe(
29
25
  T.succeedWith(() => new Ws.WebSocket(url, options)),
30
26
  M.makeExit((ws) =>
@@ -53,7 +49,7 @@ const recv = (ws: Ws.WebSocket): WebSocketStream =>
53
49
  )
54
50
  })
55
51
 
56
- const send = (out: Q.Queue<Message>) => (ws: Ws.WebSocket) =>
52
+ const send = (out: OutboundStream) => (ws: Ws.WebSocket) =>
57
53
  pipe(
58
54
  T.effectAsync<unknown, WsError, void>((cb) => {
59
55
  if (ws.readyState & ws.OPEN) {
@@ -64,7 +60,7 @@ const send = (out: Q.Queue<Message>) => (ws: Ws.WebSocket) =>
64
60
  })
65
61
  }
66
62
  }),
67
- T.map(() => S.fromQueue()(out)),
63
+ T.map(() => out),
68
64
  S.unwrap,
69
65
  S.tap((data) =>
70
66
  T.effectAsync<unknown, WsError, void>((cb) => {
@@ -72,6 +68,7 @@ const send = (out: Q.Queue<Message>) => (ws: Ws.WebSocket) =>
72
68
  ws.close(1012, "reconnecting")
73
69
  cb(T.unit)
74
70
  } else {
71
+ console.error(data)
75
72
  ws.send(data, (err) => {
76
73
  if (err) {
77
74
  cb(T.fail({ _tag: "write", cause: err }))
@@ -85,33 +82,21 @@ const send = (out: Q.Queue<Message>) => (ws: Ws.WebSocket) =>
85
82
  S.drain
86
83
  )
87
84
 
88
- const duplex = (out: Q.Queue<Message>) => (ws: Ws.WebSocket) =>
85
+ const duplex = (out: OutboundStream) => (ws: Ws.WebSocket) =>
89
86
  pipe(recv(ws), S.mergeTerminateLeft(send(out)(ws)))
90
87
 
91
- const openDuplexWithQueue = (
88
+ const openDuplex = (
92
89
  url: string,
93
- out: Q.Queue<Message>,
90
+ out: OutboundStream,
94
91
  options?: Ws.ClientOptions
95
92
  ): WebSocketStream =>
96
93
  pipe(
97
- open(url, options),
94
+ openSocket(url, options),
98
95
  M.map(duplex(out)),
99
96
  S.unwrapManaged,
100
97
  S.retry(SC.recurWhile((e) => e._tag === "close" && e.code === 1012))
101
98
  )
102
99
 
103
- const openDuplex = (
104
- url: string,
105
- options?: Ws.ClientOptions
106
- ): T.UIO<WebSocketConnection> =>
107
- pipe(
108
- Q.makeUnbounded<Message>(),
109
- T.map((write) => ({
110
- read: openDuplexWithQueue(url, write, options),
111
- write,
112
- }))
113
- )
114
-
115
100
  const makeWS = T.succeed({
116
101
  _tag: "WSService",
117
102
  open: openDuplex,
@@ -120,3 +105,10 @@ const makeWS = T.succeed({
120
105
  export interface WS extends _A<typeof makeWS> {}
121
106
  export const WS = tag<WS>()
122
107
  export const LiveWS = T.toLayer(WS)(makeWS)
108
+
109
+ // Helpers
110
+ export const open = (
111
+ url: string,
112
+ out: OutboundStream,
113
+ options?: Ws.ClientOptions
114
+ ) => T.accessService(WS)(({ open }) => open(url, out, options))
package/bot.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/bot.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
5
+ const fileName_1 = "bot.ts";
6
+ const T = tslib_1.__importStar(require("@effect-ts/core/Effect"));
7
+ const S = tslib_1.__importStar(require("@effect-ts/core/Effect/Experimental/Stream"));
8
+ const M = tslib_1.__importStar(require("@effect-ts/core/Effect/Managed"));
9
+ const Function_1 = require("@effect-ts/core/Function");
10
+ const Has_1 = require("@effect-ts/core/Has");
11
+ const R = tslib_1.__importStar(require("@effect-ts/node/Runtime"));
12
+ const Dotemv = tslib_1.__importStar(require("dotenv"));
13
+ const _1 = require(".");
14
+ const Shard = tslib_1.__importStar(require("./DiscordShard"));
15
+ const Log_1 = require("./Log");
16
+ const types_1 = require("./types");
17
+ Dotemv.config();
18
+ const makeBot = (M.map_(Shard.make({
19
+ token: process.env.DISCORD_BOT_TOKEN,
20
+ intents: types_1.GatewayIntents.GUILDS | types_1.GatewayIntents.GUILD_MESSAGES,
21
+ shard: [0, 1],
22
+ }), (bot) => ({
23
+ _tag: "BotService",
24
+ bot,
25
+ }), fileName_1 + ":22:8"));
26
+ const Bot = (0, Has_1.tag)();
27
+ const LiveBot = M.toLayer_(makeBot, Bot);
28
+ const bot = T.accessService(Bot)(({ bot }) => bot, fileName_1 + ":34:33");
29
+ const runBot = T.accessServiceM(Bot)(({ bot }) => bot.run, fileName_1 + ":35:37");
30
+ // logger
31
+ const logger = T.chain_(bot, ({ raw }) => (S.forEach_(S.fromHub_(raw), (p) => (0, Log_1.log)(p))), fileName_1 + ":38:24");
32
+ (R.runMain(T.provideSomeLayer(_1.DefaultEnv[">+>"](LiveBot))(T.zipPar(runBot, fileName_1 + ":47:11")(logger))));
33
+ //# sourceMappingURL=bot.js.map
package/bot.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bot.js","sourceRoot":"","sources":["bot.ts"],"names":[],"mappings":";;;;;AAAA,kEAA2C;AAC3C,sFAA+D;AAC/D,0EAAmD;AACnD,uDAA+C;AAC/C,6CAAyC;AAEzC,mEAA4C;AAC5C,uDAAgC;AAChC,wBAA8B;AAC9B,8DAAuC;AACvC,+BAA2B;AAC3B,mCAAwC;AAExC,MAAM,CAAC,MAAM,EAAE,CAAA;AAEf,MAAM,OAAO,IAMX,CAAC,MALD,KAAK,CAAC,IAAI,CAAC;IACT,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAkB;IACrC,OAAO,EAAE,sBAAc,CAAC,MAAM,GAAG,sBAAc,CAAC,cAAc;IAC9D,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;CACd,CAAC,EAEA,CAAC,GAAG,EAAE,EAAE,CACN,CAAC;IACC,IAAI,EAAE,YAAY;IAClB,GAAG;CACM,CAAA,wBAEhB,CAAA;AAGD,MAAM,GAAG,GAAG,IAAA,SAAG,GAAO,CAAA;AACtB,MAAM,OAAO,GAAG,CAAC,UAAc,OAAO,EAAZ,GAAG,CAAU,CAAA;AACvC,MAAM,GAAG,GAAG,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,wBAAC,CAAA;AAClD,MAAM,MAAM,GAAG,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,wBAAC,CAAA;AAE1D,SAAS;AACT,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,EAGrC,CAAC,UADD,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EACL,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,SAAG,EAAC,CAAC,CAAC,EACxB,wBACF,CAAA;AAED,CAKE,CAAC,CAAC,OAAO,CADT,CAAC,CAAC,gBAAgB,CAAC,aAAU,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAF9C,CAAC,CAAC,MAAM,CAAC,MAAM,wBAAC,CADhB,MAAM,KAKP"}
package/bot.ts ADDED
@@ -0,0 +1,51 @@
1
+ import * as T from "@effect-ts/core/Effect"
2
+ import * as S from "@effect-ts/core/Effect/Experimental/Stream"
3
+ import * as M from "@effect-ts/core/Effect/Managed"
4
+ import { pipe } from "@effect-ts/core/Function"
5
+ import { tag } from "@effect-ts/core/Has"
6
+ import { _A } from "@effect-ts/core/Utils"
7
+ import * as R from "@effect-ts/node/Runtime"
8
+ import * as Dotemv from "dotenv"
9
+ import { DefaultEnv } from "."
10
+ import * as Shard from "./DiscordShard"
11
+ import { log } from "./Log"
12
+ import { GatewayIntents } from "./types"
13
+
14
+ Dotemv.config()
15
+
16
+ const makeBot = pipe(
17
+ Shard.make({
18
+ token: process.env.DISCORD_BOT_TOKEN!,
19
+ intents: GatewayIntents.GUILDS | GatewayIntents.GUILD_MESSAGES,
20
+ shard: [0, 1],
21
+ }),
22
+ M.map(
23
+ (bot) =>
24
+ ({
25
+ _tag: "BotService",
26
+ bot,
27
+ } as const)
28
+ )
29
+ )
30
+
31
+ interface Bot extends _A<typeof makeBot> {}
32
+ const Bot = tag<Bot>()
33
+ const LiveBot = M.toLayer(Bot)(makeBot)
34
+ const bot = T.accessService(Bot)(({ bot }) => bot)
35
+ const runBot = T.accessServiceM(Bot)(({ bot }) => bot.run)
36
+
37
+ // logger
38
+ const logger = T.chain_(bot, ({ raw }) =>
39
+ pipe(
40
+ S.fromHub_(raw),
41
+ S.forEach((p) => log(p))
42
+ )
43
+ )
44
+
45
+ pipe(
46
+ logger,
47
+ T.zipPar(runBot),
48
+
49
+ T.provideSomeLayer(DefaultEnv[">+>"](LiveBot)),
50
+ R.runMain
51
+ )
package/mod.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import * as Shard from "./DiscordShard";
2
+ import * as WS from "./WS";
3
+ export declare const DefaultEnv: import("@effect-ts/system/Layer").Layer<unknown, never, import("@effect-ts/system/Has").Has<WS.WS> & import("@effect-ts/system/Has").Has<import("./DiscordWS").DiscordWS> & import("@effect-ts/system/Has").Has<Shard.DiscordShard> & import("@effect-ts/system/Has").Has<import("./Log").Log>>;
package/mod.js CHANGED
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultEnv = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
5
6
  const fileName_1 = "mod.ts";
6
- const core_1 = require("@effect-ts/core");
7
- const S = tslib_1.__importStar(require("@effect-ts/core/Effect/Experimental/Stream"));
8
- const Schedule_1 = require("@effect-ts/core/Effect/Schedule");
9
- const R = tslib_1.__importStar(require("@effect-ts/node/Runtime"));
7
+ const Shard = tslib_1.__importStar(require("./DiscordShard"));
8
+ const DiscordWS_1 = require("./DiscordWS");
9
+ const Log_1 = require("./Log");
10
10
  const WS = tslib_1.__importStar(require("./WS"));
11
- (R.runMain(core_1.Effect.provideSomeLayer(WS.LiveWS)(core_1.Effect.chain_(core_1.Effect.accessServiceM(WS.WS)(({ open }) => open("wss://gateway.discord.gg/?v=9&encoding=json"), fileName_1 + ":8:26"), ({ read, write }) => (S.forEach_(S.retry_(read, (0, Schedule_1.exponential)(10)), (data) => core_1.Effect.succeedWith(() => {
12
- console.error(data.toString("utf8"));
13
- }, fileName_1 + ":16:22"))), fileName_1 + ":11:10"))));
11
+ exports.DefaultEnv = WS.LiveWS[">+>"](DiscordWS_1.LiveDiscordWS)[">+>"](Shard.LiveDiscordShard)["+++"](Log_1.LiveLog);
14
12
  //# sourceMappingURL=mod.js.map
package/mod.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["mod.ts"],"names":[],"mappings":";;;;;AAAA,0CAAmD;AACnD,sFAA+D;AAC/D,8DAA6D;AAC7D,mEAA4C;AAC5C,iDAA0B;AAE1B,CAgBE,CAAC,CAAC,OAAO,CADT,aAAC,CAAC,gBAAgB,CAAC,EAAE,CAAC,MAAM,CAAC,CAX7B,aAAC,QAHD,aAAC,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CACnC,IAAI,CAAC,6CAA6C,CAAC,uBACpD,EACO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,EAIxB,CAAC,UADD,CAAC,QADD,IAAI,EACI,IAAA,sBAAW,EAAC,EAAE,CAAC,GACb,CAAC,IAAI,EAAE,EAAE,CACjB,aAAC,CAAC,WAAW,CAAC,GAAG,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAA;AACtC,CAAC,wBAAC,EAEL,4BAIJ"}
1
+ {"version":3,"file":"mod.js","sourceRoot":"","sources":["mod.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAuC;AACvC,2CAA2C;AAC3C,+BAA+B;AAC/B,iDAA0B;AAEb,QAAA,UAAU,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,yBAAa,CAAC,CACtD,KAAK,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAC9B,KAAK,CAAC,CAAC,aAAO,CAAC,CAAA"}