@effect-uai/discord 0.17.0 → 0.19.0-dev-20261109183959

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 (32) hide show
  1. package/README.md +2 -2
  2. package/dist/Discord.d.mts +3 -3
  3. package/dist/Discord.d.mts.map +1 -1
  4. package/dist/Discord.mjs +7 -5
  5. package/dist/Discord.mjs.map +1 -1
  6. package/dist/dist-DHer1cql.mjs +1533 -0
  7. package/dist/dist-DHer1cql.mjs.map +1 -0
  8. package/dist/{gateway-C_Ae1HYB.d.mts → gateway-CYyZYm4m.d.mts} +3 -2
  9. package/dist/gateway-CYyZYm4m.d.mts.map +1 -0
  10. package/dist/{test.DNmyFkvJ-N3QqMRwZ.mjs → index.C4tKZ0yW-CUBm3Bmz.mjs} +9446 -5818
  11. package/dist/index.C4tKZ0yW-CUBm3Bmz.mjs.map +1 -0
  12. package/dist/internal/events.test.mjs +1 -1
  13. package/dist/internal/gateway.d.mts +1 -1
  14. package/dist/internal/gateway.mjs +23 -14
  15. package/dist/internal/gateway.mjs.map +1 -1
  16. package/dist/internal/gateway.test.mjs +278 -7
  17. package/dist/internal/gateway.test.mjs.map +1 -1
  18. package/dist/internal/rest.d.mts +1 -1
  19. package/dist/internal/rest.mjs +2 -2
  20. package/dist/internal/rest.mjs.map +1 -1
  21. package/dist/{rest-CZSW-VJK.d.mts → rest-SmIBt9Nh.d.mts} +2 -2
  22. package/dist/{rest-CZSW-VJK.d.mts.map → rest-SmIBt9Nh.d.mts.map} +1 -1
  23. package/dist/{rolldown-runtime-D7D4PA-g.mjs → rolldown-runtime-EAsCxrDo.mjs} +2 -1
  24. package/package.json +5 -5
  25. package/src/Discord.ts +7 -4
  26. package/src/internal/gateway.test.ts +87 -1
  27. package/src/internal/gateway.ts +32 -22
  28. package/src/internal/rest.ts +2 -2
  29. package/dist/gateway-C_Ae1HYB.d.mts.map +0 -1
  30. package/dist/magic-string.es-CUAnjKYC.mjs +0 -1014
  31. package/dist/magic-string.es-CUAnjKYC.mjs.map +0 -1
  32. package/dist/test.DNmyFkvJ-N3QqMRwZ.mjs.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { Dispatch, toEvents } from "./events.mjs";
2
- import { n as describe, r as it, t as globalExpect } from "../test.DNmyFkvJ-N3QqMRwZ.mjs";
2
+ import { n as globalExpect, o as describe, s as it } from "../index.C4tKZ0yW-CUBm3Bmz.mjs";
3
3
  import { Schema } from "effect";
4
4
  //#region src/internal/events.test.ts
5
5
  const events = toEvents({
@@ -1,2 +1,2 @@
1
- import { a as Ready, c as closeReason, i as Incoming, l as connect, n as Config, o as Session, r as GatewayInfo, s as classifyClose, t as CloseAction } from "../gateway-C_Ae1HYB.mjs";
1
+ import { a as Ready, c as closeReason, i as Incoming, l as connect, n as Config, o as Session, r as GatewayInfo, s as classifyClose, t as CloseAction } from "../gateway-CYyZYm4m.mjs";
2
2
  export { CloseAction, Config, GatewayInfo, Incoming, Ready, Session, classifyClose, closeReason, connect };
@@ -1,8 +1,9 @@
1
1
  import { Dispatch } from "./events.mjs";
2
2
  import { provider } from "./rest.mjs";
3
- import { Deferred, Duration, Effect, Match, Option, Queue, Redacted, Ref, Schedule, Schema } from "effect";
3
+ import { Deferred, Duration, Effect, Match, Option, Queue, Redacted, Ref, Schedule, Schema, Stream } from "effect";
4
+ import * as Socket from "effect/socket/Socket";
4
5
  import * as MessengerError from "@effect-uai/core/MessengerError";
5
- import * as Socket from "effect/unstable/socket/Socket";
6
+ import { isCleanClose } from "@effect-uai/core/WebSocketSession";
6
7
  //#region src/internal/gateway.ts
7
8
  const Payload = Schema.Struct({
8
9
  op: Schema.Number,
@@ -51,6 +52,19 @@ const closeReason = (code, reason) => fatalReasons[code] ?? (reason === void 0 |
51
52
  const RESUMABLE_CLOSE = 4e3;
52
53
  const socketCode = (error) => error.reason._tag === "SocketCloseError" ? error.reason.code : 1006;
53
54
  const socketReason = (error) => error.reason._tag === "SocketCloseError" ? error.reason.closeReason ?? error.reason.message : error.reason.message;
55
+ const endedBy = (error) => {
56
+ if (isCleanClose(error)) return {
57
+ action: "resume",
58
+ code: 1e3,
59
+ reason: "closed"
60
+ };
61
+ const code = socketCode(error);
62
+ return {
63
+ action: classifyClose(code),
64
+ code,
65
+ reason: closeReason(code, socketReason(error))
66
+ };
67
+ };
54
68
  const freshSessionDelay = Effect.sync(() => Duration.millis(1e3 + Math.random() * 4e3));
55
69
  const backoff = (attempt) => Duration.millis(Math.min(6e4, 500 * 2 ** attempt));
56
70
  const identity = {
@@ -71,16 +85,18 @@ const connect = (cfg) => Effect.gen(function* () {
71
85
  const ready = yield* Deferred.make();
72
86
  const resume = yield* Ref.make(Option.none());
73
87
  const attempts = yield* Ref.make(0);
88
+ const seq = yield* Ref.make(Option.none());
74
89
  const once = Effect.gen(function* () {
75
90
  const from = yield* Ref.get(resume);
76
91
  const host = Option.match(from, {
77
92
  onNone: () => cfg.url,
78
93
  onSome: (r) => r.url
79
94
  });
80
- const socket = yield* Socket.makeWebSocket(`${host}/?v=10&encoding=json`, { closeCodeIsError: (code) => code !== 1e3 && code !== 1001 && code !== 1005 }).pipe(Effect.provide(Socket.layerWebSocketConstructorGlobal));
81
- const write = yield* socket.writer;
95
+ const socket = yield* Socket.makeWebSocket(`${host}/?v=10&encoding=json`);
96
+ const writer = yield* socket.writer;
97
+ const closed = yield* Ref.make(false);
98
+ const write = (chunk) => Effect.flatMap(Ref.get(closed), (isClosed) => isClosed ? Effect.void : writer.write(chunk));
82
99
  const send = (payload) => write(JSON.stringify(payload));
83
- const seq = yield* Ref.make(Option.none());
84
100
  const acked = yield* Ref.make(true);
85
101
  const requested = yield* Ref.make(Option.none());
86
102
  const heartbeat = Effect.gen(function* () {
@@ -161,18 +177,11 @@ const connect = (cfg) => Effect.gen(function* () {
161
177
  const message = payload.value;
162
178
  yield* Match.value(message.op).pipe(Match.when(OP.dispatch, () => onDispatch(message)), Match.when(OP.hello, () => hello(message.d)), Match.when(OP.heartbeatAck, () => Ref.set(acked, true)), Match.when(OP.heartbeat, () => heartbeat), Match.when(OP.reconnect, () => write(new Socket.CloseEvent(RESUMABLE_CLOSE, "reconnect requested"))), Match.when(OP.invalidSession, () => invalidSession(message.d)), Match.orElse(() => Effect.void));
163
179
  }).pipe(Effect.ignore);
164
- const ended = yield* socket.runString(handle).pipe(Effect.as({
180
+ const ended = yield* Stream.fromPull(Socket.readerString(socket)).pipe(Stream.scoped, Stream.runForEach(handle), Effect.ensuring(Ref.set(closed, true)), Effect.as({
165
181
  action: "resume",
166
182
  code: 1e3,
167
183
  reason: "closed"
168
- }), Effect.catch((error) => {
169
- const code = socketCode(error);
170
- return Effect.succeed({
171
- action: classifyClose(code),
172
- code,
173
- reason: closeReason(code, socketReason(error))
174
- });
175
- }));
184
+ }), Effect.catch((error) => Effect.succeed(endedBy(error))));
176
185
  const override = yield* Ref.get(requested);
177
186
  return Option.match(override, {
178
187
  onNone: () => ended,
@@ -1 +1 @@
1
- {"version":3,"file":"gateway.mjs","names":["Events.Dispatch"],"sources":["../../src/internal/gateway.ts"],"sourcesContent":["import {\n type Cause,\n Deferred,\n Duration,\n Effect,\n Match,\n Option,\n Queue,\n Redacted,\n Ref,\n Schedule,\n Schema,\n type Scope,\n} from \"effect\"\nimport * as Socket from \"effect/unstable/socket/Socket\"\nimport * as MessengerError from \"@effect-uai/core/MessengerError\"\nimport * as Events from \"./events.js\"\nimport { provider } from \"./rest.js\"\n\n// ---------------------------------------------------------------------------\n// Wire shapes\n// ---------------------------------------------------------------------------\n\nconst Payload = Schema.Struct({\n op: Schema.Number,\n d: Schema.optional(Schema.Unknown),\n s: Schema.optional(Schema.NullOr(Schema.Number)),\n t: Schema.optional(Schema.NullOr(Schema.String)),\n})\ntype Payload = typeof Payload.Type\n\nconst decodeFrame = Schema.decodeUnknownEffect(Schema.fromJsonString(Payload))\n\nconst Hello = Schema.Struct({ heartbeat_interval: Schema.Number })\n\nexport const Ready = Schema.Struct({\n user: Schema.Struct({ id: Schema.String, username: Schema.String }),\n session_id: Schema.String,\n resume_gateway_url: Schema.String,\n})\nexport type Ready = typeof Ready.Type\n\n/** `GET /gateway/bot`, the only REST call the session needs. */\nexport const GatewayInfo = Schema.Struct({ url: Schema.String })\n\n// Send: 1 heartbeat, 2 identify, 6 resume. Receive: 0 dispatch, 7 reconnect,\n// 9 invalid session, 10 hello, 11 heartbeat ack.\nconst OP = {\n dispatch: 0,\n heartbeat: 1,\n identify: 2,\n resume: 6,\n reconnect: 7,\n invalidSession: 9,\n hello: 10,\n heartbeatAck: 11,\n} as const\n\n// ---------------------------------------------------------------------------\n// Close codes\n// ---------------------------------------------------------------------------\n\n/** What the session does once a connection is gone. */\nexport type CloseAction = \"resume\" | \"reidentify\" | \"fatal\"\n\n// Fatal: nothing about reconnecting would change the answer.\nconst fatalReasons: Record<number, string> = {\n 4004: \"authentication failed: the bot token was rejected\",\n 4010: \"invalid shard\",\n 4011: \"sharding required\",\n 4012: \"invalid API version\",\n 4013: \"invalid intents\",\n 4014: \"disallowed intents: enable the privileged intent in the developer portal\",\n}\n\n// The session is gone but the token is fine: identify fresh.\nconst staleSessionCodes = [4007, 4009]\n\n/**\n * Everything else, transport drops included, resumes: Discord only names the\n * codes that must not be retried, so an unknown code is a reconnect.\n */\nexport const classifyClose = (code: number): CloseAction =>\n Match.value(code).pipe(\n Match.when(\n (c) => c in fatalReasons,\n (): CloseAction => \"fatal\",\n ),\n Match.when(\n (c) => staleSessionCodes.includes(c),\n (): CloseAction => \"reidentify\",\n ),\n Match.orElse((): CloseAction => \"resume\"),\n )\n\n/** Discord's own words for a fatal code, since its close frames carry no reason. */\nexport const closeReason = (code: number, reason?: string): string =>\n fatalReasons[code] ??\n (reason === undefined || reason === \"\" ? `gateway closed with ${code}` : reason)\n\n// A close we send ourselves. Anything but 1000/1001 keeps the session alive on\n// Discord's side, which is what makes the next connection resumable.\nconst RESUMABLE_CLOSE = 4000\n\n// ---------------------------------------------------------------------------\n// Session\n// ---------------------------------------------------------------------------\n\nexport type Config = {\n readonly token: Redacted.Redacted\n readonly intents: number\n /** From `GET /gateway/bot`. Resumes go to `resume_gateway_url` instead. */\n readonly url: string\n}\n\n/** A decoded dispatch beside the payload it came from, which `raw` carries. */\nexport type Incoming = {\n readonly dispatch: Events.Dispatch\n readonly raw: unknown\n}\n\nexport type Session = {\n readonly bot: Events.BotIdentity\n /**\n * Dispatches in arrival order, ended when the scope closes and failed with\n * `MessengerTransportClosed` on a fatal gateway close.\n */\n readonly dispatches: Queue.Queue<Incoming, MessengerError.MessengerError | Cause.Done>\n}\n\ntype Resume = { readonly id: string; readonly url: string }\n\ntype Ended = { readonly action: CloseAction; readonly code: number; readonly reason: string }\n\nconst socketCode = (error: Socket.SocketError): number =>\n error.reason._tag === \"SocketCloseError\" ? error.reason.code : 1006\n\nconst socketReason = (error: Socket.SocketError): string =>\n error.reason._tag === \"SocketCloseError\"\n ? (error.reason.closeReason ?? error.reason.message)\n : error.reason.message\n\n// Discord asks for a random 1-5 s pause before identifying on a fresh session.\nconst freshSessionDelay = Effect.sync(() => Duration.millis(1000 + Math.random() * 4000))\n\n// Capped exponential, from a beat to a minute. Reset once a connection is live.\nconst backoff = (attempt: number): Duration.Duration =>\n Duration.millis(Math.min(60_000, 500 * 2 ** attempt))\n\nconst identity = { os: \"effect-uai\", browser: \"effect-uai\", device: \"effect-uai\" }\n\n/**\n * One gateway session: connect, identify, heartbeat, resume, reconnect.\n *\n * Returns once `READY` has arrived, so a bad token or a disallowed intent is\n * a `MessengerConnectFailed` at layer build rather than a stream that dies a\n * moment later. From then on reconnects are silent and only a fatal close\n * ends `dispatches`.\n */\nexport const connect = (\n cfg: Config,\n): Effect.Effect<Session, MessengerError.MessengerConnectFailed, Scope.Scope> =>\n Effect.gen(function* () {\n const dispatches = yield* Queue.unbounded<\n Incoming,\n MessengerError.MessengerError | Cause.Done\n >()\n const ready = yield* Deferred.make<Events.BotIdentity, MessengerError.MessengerConnectFailed>()\n const resume = yield* Ref.make(Option.none<Resume>())\n const attempts = yield* Ref.make(0)\n\n // -- one connection ----------------------------------------------------\n\n const once = Effect.gen(function* () {\n const from = yield* Ref.get(resume)\n // A resumable session has its own host; a fresh one starts at the URL\n // `GET /gateway/bot` gave us.\n const host = Option.match(from, { onNone: () => cfg.url, onSome: (r: Resume) => r.url })\n const socket = yield* Socket.makeWebSocket(`${host}/?v=10&encoding=json`, {\n // Effect treats every close as an error by default; the standard clean\n // codes are not, and Discord's 4xxx ones are what drives `classifyClose`.\n closeCodeIsError: (code: number) => code !== 1000 && code !== 1001 && code !== 1005,\n // The gateway takes its token in the identify payload, not a header,\n // so every runtime's global `WebSocket` is enough.\n }).pipe(Effect.provide(Socket.layerWebSocketConstructorGlobal))\n const write = yield* socket.writer\n const send = (payload: unknown) => write(JSON.stringify(payload))\n const seq = yield* Ref.make(Option.none<number>())\n const acked = yield* Ref.make(true)\n // Set by op 9 with `d: false`, the one case the close code cannot express.\n const requested = yield* Ref.make(Option.none<CloseAction>())\n\n const heartbeat = Effect.gen(function* () {\n const s = yield* Ref.get(seq)\n return yield* send({ op: OP.heartbeat, d: Option.getOrNull(s) })\n })\n\n // A beat with no ACK since the last one means the connection is a zombie:\n // close it non-cleanly so the next connection resumes.\n const beat = Effect.gen(function* () {\n const alive = yield* Ref.getAndSet(acked, false)\n if (!alive) {\n yield* write(new Socket.CloseEvent(RESUMABLE_CLOSE, \"no heartbeat ack\"))\n return false\n }\n yield* heartbeat\n return true\n })\n\n // Discord asks for the first beat to land at a random point in the\n // interval, so a fleet of bots does not beat in lockstep.\n const beating = (interval: number) =>\n Effect.sleep(Duration.millis(interval * Math.random())).pipe(\n Effect.andThen(\n beat.pipe(\n Effect.repeat({\n schedule: Schedule.spaced(Duration.millis(interval)),\n while: (alive: boolean) => alive,\n }),\n ),\n ),\n Effect.ignore,\n Effect.forkScoped,\n )\n\n const hello = (d: unknown) =>\n Effect.gen(function* () {\n const { heartbeat_interval } = yield* Schema.decodeUnknownEffect(Hello)(d)\n yield* beating(heartbeat_interval)\n const from = yield* Ref.get(resume)\n const s = yield* Ref.get(seq)\n return yield* Option.match(from, {\n onNone: () =>\n send({\n op: OP.identify,\n d: {\n token: Redacted.value(cfg.token),\n intents: cfg.intents,\n properties: identity,\n },\n }),\n onSome: (r) =>\n send({\n op: OP.resume,\n d: {\n token: Redacted.value(cfg.token),\n session_id: r.id,\n seq: Option.getOrNull(s),\n },\n }),\n })\n })\n\n const onReady = (d: unknown) =>\n Effect.gen(function* () {\n const info = yield* Schema.decodeUnknownEffect(Ready)(d)\n yield* Ref.set(resume, Option.some({ id: info.session_id, url: info.resume_gateway_url }))\n yield* Ref.set(attempts, 0)\n yield* Deferred.succeed(ready, info.user)\n })\n\n const onDispatch = (payload: Payload) =>\n Effect.gen(function* () {\n if (payload.s != null) yield* Ref.set(seq, Option.some(payload.s))\n if (payload.t === \"READY\") return yield* onReady(payload.d)\n if (payload.t === \"RESUMED\") return yield* Ref.set(attempts, 0)\n const dispatch = yield* Schema.decodeUnknownEffect(Events.Dispatch)({\n t: payload.t,\n d: payload.d,\n }).pipe(Effect.option)\n if (Option.isSome(dispatch)) {\n yield* Queue.offer(dispatches, { dispatch: dispatch.value, raw: payload.d })\n }\n })\n\n // `d: true` keeps the session, `d: false` drops it; both mean reconnect.\n const invalidSession = (d: unknown) =>\n Effect.gen(function* () {\n if (d !== true) {\n yield* Ref.set(resume, Option.none())\n yield* Ref.set(requested, Option.some<CloseAction>(\"reidentify\"))\n }\n yield* write(new Socket.CloseEvent(RESUMABLE_CLOSE, \"invalid session\"))\n })\n\n const handle = (raw: string) =>\n Effect.gen(function* () {\n const payload = yield* decodeFrame(raw).pipe(Effect.option)\n if (Option.isNone(payload)) return\n const message = payload.value\n yield* Match.value(message.op).pipe(\n Match.when(OP.dispatch, () => onDispatch(message)),\n Match.when(OP.hello, () => hello(message.d)),\n Match.when(OP.heartbeatAck, () => Ref.set(acked, true)),\n Match.when(OP.heartbeat, () => heartbeat),\n Match.when(OP.reconnect, () =>\n write(new Socket.CloseEvent(RESUMABLE_CLOSE, \"reconnect requested\")),\n ),\n Match.when(OP.invalidSession, () => invalidSession(message.d)),\n Match.orElse(() => Effect.void),\n )\n }).pipe(Effect.ignore)\n\n // A clean 1000 is only ever our own teardown; anything else carries the\n // close code the classifier reads.\n const ended = yield* socket.runString(handle).pipe(\n Effect.as<Ended>({ action: \"resume\", code: 1000, reason: \"closed\" }),\n Effect.catch((error: Socket.SocketError) => {\n const code = socketCode(error)\n return Effect.succeed<Ended>({\n action: classifyClose(code),\n code,\n reason: closeReason(code, socketReason(error)),\n })\n }),\n )\n const override = yield* Ref.get(requested)\n return Option.match(override, {\n onNone: (): Ended => ended,\n onSome: (action): Ended => ({ ...ended, action }),\n })\n }).pipe(Effect.scoped)\n\n // -- the reconnect loop ------------------------------------------------\n\n const cycle = Effect.gen(function* () {\n const ended = yield* once\n if (ended.action === \"fatal\") {\n return yield* new MessengerError.MessengerTransportClosed({\n provider,\n reason: ended.reason,\n raw: { code: ended.code },\n })\n }\n const attempt = yield* Ref.get(attempts)\n yield* Ref.set(attempts, attempt + 1)\n const wait = ended.action === \"reidentify\" ? yield* freshSessionDelay : backoff(attempt)\n // Reconnects never reach `events`, so this is the only sign of one. A\n // dropped connection is noticed only when a heartbeat goes unacked,\n // which is up to two intervals after the network actually went away.\n yield* Effect.logDebug(\"gateway reconnecting\", {\n code: ended.code,\n action: ended.action,\n attempt,\n in: Duration.toSeconds(wait),\n })\n yield* Effect.sleep(wait)\n })\n\n // Failing the deferred is a no-op once `READY` has landed, so the same\n // fatal close is a connect failure before it and a transport close after.\n yield* Effect.forever(cycle).pipe(\n Effect.catch((closed: MessengerError.MessengerTransportClosed) =>\n Deferred.fail(\n ready,\n new MessengerError.MessengerConnectFailed({\n provider,\n reason: closed.reason,\n raw: closed.raw,\n }),\n ).pipe(Effect.andThen(Queue.fail(dispatches, closed))),\n ),\n Effect.ensuring(Queue.end(dispatches)),\n Effect.forkScoped,\n )\n\n return { bot: yield* Deferred.await(ready), dispatches }\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,IAAI;EAC7B,CAAC;EACD,OAAO,OAAO,MAAM,IAAI;CAC1B,CAAC;CAID,OAAO,OAAO,QAAQ,KAAK,CAAC,CAAC,KAC3B,OAAO,OAAO,WACZ,SAAS,KACP,OACA,IAAI,eAAe,uBAAuB;EACxC;EACA,QAAQ,OAAO;EACf,KAAK,OAAO;CACd,CAAC,CACH,CAAC,CAAC,KAAK,OAAO,QAAQ,MAAM,KAAK,YAAY,MAAM,CAAC,CAAC,CACvD,GACA,OAAO,SAAS,MAAM,IAAI,UAAU,CAAC,GACrC,OAAO,UACT;CAEA,OAAO;EAAE,KAAK,OAAO,SAAS,MAAM,KAAK;EAAG;CAAW;AACzD,CAAC"}
1
+ {"version":3,"file":"gateway.mjs","names":["Events.Dispatch"],"sources":["../../src/internal/gateway.ts"],"sourcesContent":["import {\n type Cause,\n Deferred,\n Duration,\n Effect,\n Match,\n Option,\n Queue,\n Redacted,\n Ref,\n Schedule,\n Schema,\n type Scope,\n Stream,\n} from \"effect\"\nimport * as Socket from \"effect/socket/Socket\"\nimport * as MessengerError from \"@effect-uai/core/MessengerError\"\nimport { isCleanClose } from \"@effect-uai/core/WebSocketSession\"\nimport * as Events from \"./events.js\"\nimport { provider } from \"./rest.js\"\n\n// ---------------------------------------------------------------------------\n// Wire shapes\n// ---------------------------------------------------------------------------\n\nconst Payload = Schema.Struct({\n op: Schema.Number,\n d: Schema.optional(Schema.Unknown),\n s: Schema.optional(Schema.NullOr(Schema.Number)),\n t: Schema.optional(Schema.NullOr(Schema.String)),\n})\ntype Payload = typeof Payload.Type\n\nconst decodeFrame = Schema.decodeUnknownEffect(Schema.fromJsonString(Payload))\n\nconst Hello = Schema.Struct({ heartbeat_interval: Schema.Number })\n\nexport const Ready = Schema.Struct({\n user: Schema.Struct({ id: Schema.String, username: Schema.String }),\n session_id: Schema.String,\n resume_gateway_url: Schema.String,\n})\nexport type Ready = typeof Ready.Type\n\n/** `GET /gateway/bot`, the only REST call the session needs. */\nexport const GatewayInfo = Schema.Struct({ url: Schema.String })\n\n// Send: 1 heartbeat, 2 identify, 6 resume. Receive: 0 dispatch, 7 reconnect,\n// 9 invalid session, 10 hello, 11 heartbeat ack.\nconst OP = {\n dispatch: 0,\n heartbeat: 1,\n identify: 2,\n resume: 6,\n reconnect: 7,\n invalidSession: 9,\n hello: 10,\n heartbeatAck: 11,\n} as const\n\n// ---------------------------------------------------------------------------\n// Close codes\n// ---------------------------------------------------------------------------\n\n/** What the session does once a connection is gone. */\nexport type CloseAction = \"resume\" | \"reidentify\" | \"fatal\"\n\n// Fatal: nothing about reconnecting would change the answer.\nconst fatalReasons: Record<number, string> = {\n 4004: \"authentication failed: the bot token was rejected\",\n 4010: \"invalid shard\",\n 4011: \"sharding required\",\n 4012: \"invalid API version\",\n 4013: \"invalid intents\",\n 4014: \"disallowed intents: enable the privileged intent in the developer portal\",\n}\n\n// The session is gone but the token is fine: identify fresh.\nconst staleSessionCodes = [4007, 4009]\n\n/**\n * Everything else, transport drops included, resumes: Discord only names the\n * codes that must not be retried, so an unknown code is a reconnect.\n */\nexport const classifyClose = (code: number): CloseAction =>\n Match.value(code).pipe(\n Match.when(\n (c) => c in fatalReasons,\n (): CloseAction => \"fatal\",\n ),\n Match.when(\n (c) => staleSessionCodes.includes(c),\n (): CloseAction => \"reidentify\",\n ),\n Match.orElse((): CloseAction => \"resume\"),\n )\n\n/** Discord's own words for a fatal code, since its close frames carry no reason. */\nexport const closeReason = (code: number, reason?: string): string =>\n fatalReasons[code] ??\n (reason === undefined || reason === \"\" ? `gateway closed with ${code}` : reason)\n\n// A close we send ourselves. Anything but 1000/1001 keeps the session alive on\n// Discord's side, which is what makes the next connection resumable.\nconst RESUMABLE_CLOSE = 4000\n\n// ---------------------------------------------------------------------------\n// Session\n// ---------------------------------------------------------------------------\n\nexport type Config = {\n readonly token: Redacted.Redacted\n readonly intents: number\n /** From `GET /gateway/bot`. Resumes go to `resume_gateway_url` instead. */\n readonly url: string\n}\n\n/** A decoded dispatch beside the payload it came from, which `raw` carries. */\nexport type Incoming = {\n readonly dispatch: Events.Dispatch\n readonly raw: unknown\n}\n\nexport type Session = {\n readonly bot: Events.BotIdentity\n /**\n * Dispatches in arrival order, ended when the scope closes and failed with\n * `MessengerTransportClosed` on a fatal gateway close.\n */\n readonly dispatches: Queue.Queue<Incoming, MessengerError.MessengerError | Cause.Done>\n}\n\ntype Resume = { readonly id: string; readonly url: string }\n\ntype Ended = { readonly action: CloseAction; readonly code: number; readonly reason: string }\n\nconst socketCode = (error: Socket.SocketError): number =>\n error.reason._tag === \"SocketCloseError\" ? error.reason.code : 1006\n\nconst socketReason = (error: Socket.SocketError): string =>\n error.reason._tag === \"SocketCloseError\"\n ? (error.reason.closeReason ?? error.reason.message)\n : error.reason.message\n\n// Effect's `Socket` fails on every close. A clean one is only ever our own\n// teardown; anything else carries the close code the classifier reads.\nconst endedBy = (error: Socket.SocketError): Ended => {\n if (isCleanClose(error)) return { action: \"resume\", code: 1000, reason: \"closed\" }\n const code = socketCode(error)\n return { action: classifyClose(code), code, reason: closeReason(code, socketReason(error)) }\n}\n\n// Discord asks for a random 1-5 s pause before identifying on a fresh session.\nconst freshSessionDelay = Effect.sync(() => Duration.millis(1000 + Math.random() * 4000))\n\n// Capped exponential, from a beat to a minute. Reset once a connection is live.\nconst backoff = (attempt: number): Duration.Duration =>\n Duration.millis(Math.min(60_000, 500 * 2 ** attempt))\n\nconst identity = { os: \"effect-uai\", browser: \"effect-uai\", device: \"effect-uai\" }\n\n/**\n * One gateway session: connect, identify, heartbeat, resume, reconnect.\n *\n * Returns once `READY` has arrived, so a bad token or a disallowed intent is\n * a `MessengerConnectFailed` at layer build rather than a stream that dies a\n * moment later. From then on reconnects are silent and only a fatal close\n * ends `dispatches`.\n */\nexport const connect = (\n cfg: Config,\n): Effect.Effect<\n Session,\n MessengerError.MessengerConnectFailed,\n Scope.Scope | Socket.WebSocketConstructor\n> =>\n Effect.gen(function* () {\n const dispatches = yield* Queue.unbounded<\n Incoming,\n MessengerError.MessengerError | Cause.Done\n >()\n const ready = yield* Deferred.make<Events.BotIdentity, MessengerError.MessengerConnectFailed>()\n const resume = yield* Ref.make(Option.none<Resume>())\n const attempts = yield* Ref.make(0)\n // Outlives a connection: a resume replays from the last sequence seen.\n const seq = yield* Ref.make(Option.none<number>())\n\n // -- one connection ----------------------------------------------------\n\n const once = Effect.gen(function* () {\n const from = yield* Ref.get(resume)\n // A resumable session has its own host; a fresh one starts at the URL\n // `GET /gateway/bot` gave us.\n const host = Option.match(from, { onNone: () => cfg.url, onSome: (r: Resume) => r.url })\n const socket = yield* Socket.makeWebSocket(`${host}/?v=10&encoding=json`)\n const writer = yield* socket.writer\n // The writer waits for the next connection rather than failing, so a\n // beat or handshake after this one's reader ended is dropped here.\n const closed = yield* Ref.make(false)\n const write = (chunk: string | Socket.CloseEvent) =>\n Effect.flatMap(Ref.get(closed), (isClosed) =>\n isClosed ? Effect.void : writer.write(chunk),\n )\n const send = (payload: unknown) => write(JSON.stringify(payload))\n const acked = yield* Ref.make(true)\n // Set by op 9 with `d: false`, the one case the close code cannot express.\n const requested = yield* Ref.make(Option.none<CloseAction>())\n\n const heartbeat = Effect.gen(function* () {\n const s = yield* Ref.get(seq)\n return yield* send({ op: OP.heartbeat, d: Option.getOrNull(s) })\n })\n\n // A beat with no ACK since the last one means the connection is a zombie:\n // close it non-cleanly so the next connection resumes.\n const beat = Effect.gen(function* () {\n const alive = yield* Ref.getAndSet(acked, false)\n if (!alive) {\n yield* write(new Socket.CloseEvent(RESUMABLE_CLOSE, \"no heartbeat ack\"))\n return false\n }\n yield* heartbeat\n return true\n })\n\n // Discord asks for the first beat to land at a random point in the\n // interval, so a fleet of bots does not beat in lockstep.\n const beating = (interval: number) =>\n Effect.sleep(Duration.millis(interval * Math.random())).pipe(\n Effect.andThen(\n beat.pipe(\n Effect.repeat({\n schedule: Schedule.spaced(Duration.millis(interval)),\n while: (alive: boolean) => alive,\n }),\n ),\n ),\n Effect.ignore,\n Effect.forkScoped,\n )\n\n const hello = (d: unknown) =>\n Effect.gen(function* () {\n const { heartbeat_interval } = yield* Schema.decodeUnknownEffect(Hello)(d)\n yield* beating(heartbeat_interval)\n const from = yield* Ref.get(resume)\n const s = yield* Ref.get(seq)\n return yield* Option.match(from, {\n onNone: () =>\n send({\n op: OP.identify,\n d: {\n token: Redacted.value(cfg.token),\n intents: cfg.intents,\n properties: identity,\n },\n }),\n onSome: (r) =>\n send({\n op: OP.resume,\n d: {\n token: Redacted.value(cfg.token),\n session_id: r.id,\n seq: Option.getOrNull(s),\n },\n }),\n })\n })\n\n const onReady = (d: unknown) =>\n Effect.gen(function* () {\n const info = yield* Schema.decodeUnknownEffect(Ready)(d)\n yield* Ref.set(resume, Option.some({ id: info.session_id, url: info.resume_gateway_url }))\n yield* Ref.set(attempts, 0)\n yield* Deferred.succeed(ready, info.user)\n })\n\n const onDispatch = (payload: Payload) =>\n Effect.gen(function* () {\n if (payload.s != null) yield* Ref.set(seq, Option.some(payload.s))\n if (payload.t === \"READY\") return yield* onReady(payload.d)\n if (payload.t === \"RESUMED\") return yield* Ref.set(attempts, 0)\n const dispatch = yield* Schema.decodeUnknownEffect(Events.Dispatch)({\n t: payload.t,\n d: payload.d,\n }).pipe(Effect.option)\n if (Option.isSome(dispatch)) {\n yield* Queue.offer(dispatches, { dispatch: dispatch.value, raw: payload.d })\n }\n })\n\n // `d: true` keeps the session, `d: false` drops it; both mean reconnect.\n const invalidSession = (d: unknown) =>\n Effect.gen(function* () {\n if (d !== true) {\n yield* Ref.set(resume, Option.none())\n yield* Ref.set(requested, Option.some<CloseAction>(\"reidentify\"))\n }\n yield* write(new Socket.CloseEvent(RESUMABLE_CLOSE, \"invalid session\"))\n })\n\n const handle = (raw: string) =>\n Effect.gen(function* () {\n const payload = yield* decodeFrame(raw).pipe(Effect.option)\n if (Option.isNone(payload)) return\n const message = payload.value\n yield* Match.value(message.op).pipe(\n Match.when(OP.dispatch, () => onDispatch(message)),\n Match.when(OP.hello, () => hello(message.d)),\n Match.when(OP.heartbeatAck, () => Ref.set(acked, true)),\n Match.when(OP.heartbeat, () => heartbeat),\n Match.when(OP.reconnect, () =>\n write(new Socket.CloseEvent(RESUMABLE_CLOSE, \"reconnect requested\")),\n ),\n Match.when(OP.invalidSession, () => invalidSession(message.d)),\n Match.orElse(() => Effect.void),\n )\n }).pipe(Effect.ignore)\n\n const ended = yield* Stream.fromPull(Socket.readerString(socket)).pipe(\n Stream.scoped,\n Stream.runForEach(handle),\n Effect.ensuring(Ref.set(closed, true)),\n Effect.as<Ended>({ action: \"resume\", code: 1000, reason: \"closed\" }),\n Effect.catch((error: Socket.SocketError) => Effect.succeed(endedBy(error))),\n )\n const override = yield* Ref.get(requested)\n return Option.match(override, {\n onNone: (): Ended => ended,\n onSome: (action): Ended => ({ ...ended, action }),\n })\n }).pipe(Effect.scoped)\n\n // -- the reconnect loop ------------------------------------------------\n\n const cycle = Effect.gen(function* () {\n const ended = yield* once\n if (ended.action === \"fatal\") {\n return yield* new MessengerError.MessengerTransportClosed({\n provider,\n reason: ended.reason,\n raw: { code: ended.code },\n })\n }\n const attempt = yield* Ref.get(attempts)\n yield* Ref.set(attempts, attempt + 1)\n const wait = ended.action === \"reidentify\" ? yield* freshSessionDelay : backoff(attempt)\n // Reconnects never reach `events`, so this is the only sign of one. A\n // dropped connection is noticed only when a heartbeat goes unacked,\n // which is up to two intervals after the network actually went away.\n yield* Effect.logDebug(\"gateway reconnecting\", {\n code: ended.code,\n action: ended.action,\n attempt,\n in: Duration.toSeconds(wait),\n })\n yield* Effect.sleep(wait)\n })\n\n // Failing the deferred is a no-op once `READY` has landed, so the same\n // fatal close is a connect failure before it and a transport close after.\n yield* Effect.forever(cycle).pipe(\n Effect.catch((closed: MessengerError.MessengerTransportClosed) =>\n Deferred.fail(\n ready,\n new MessengerError.MessengerConnectFailed({\n provider,\n reason: closed.reason,\n raw: closed.raw,\n }),\n ).pipe(Effect.andThen(Queue.fail(dispatches, closed))),\n ),\n Effect.ensuring(Queue.end(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,QAAQ,MAAM;GACd,KAAK,EAAE,MAAM,MAAM,KAAK;EAC1B,CAAC;EAEH,MAAM,UAAU,OAAO,IAAI,IAAI,QAAQ;EACvC,OAAO,IAAI,IAAI,UAAU,UAAU,CAAC;EACpC,MAAM,OAAO,MAAM,WAAW,eAAe,OAAO,oBAAoB,QAAQ,OAAO;EAIvF,OAAO,OAAO,SAAS,wBAAwB;GAC7C,MAAM,MAAM;GACZ,QAAQ,MAAM;GACd;GACA,IAAI,SAAS,UAAU,IAAI;EAC7B,CAAC;EACD,OAAO,OAAO,MAAM,IAAI;CAC1B,CAAC;CAID,OAAO,OAAO,QAAQ,KAAK,CAAC,CAAC,KAC3B,OAAO,OAAO,WACZ,SAAS,KACP,OACA,IAAI,eAAe,uBAAuB;EACxC;EACA,QAAQ,OAAO;EACf,KAAK,OAAO;CACd,CAAC,CACH,CAAC,CAAC,KAAK,OAAO,QAAQ,MAAM,KAAK,YAAY,MAAM,CAAC,CAAC,CACvD,GACA,OAAO,SAAS,MAAM,IAAI,UAAU,CAAC,GACrC,OAAO,UACT;CAEA,OAAO;EAAE,KAAK,OAAO,SAAS,MAAM,KAAK;EAAG;CAAW;AACzD,CAAC"}
@@ -1,8 +1,197 @@
1
- import { classifyClose, closeReason } from "./gateway.mjs";
2
- import { n as describe, r as it, t as globalExpect } from "../test.DNmyFkvJ-N3QqMRwZ.mjs";
1
+ import { classifyClose, closeReason, connect } from "./gateway.mjs";
2
+ import { a as beforeEach, i as beforeAll, n as globalExpect, o as describe, r as afterAll, s as it$2, t as TestRunner } from "../index.C4tKZ0yW-CUBm3Bmz.mjs";
3
+ import { Effect, Layer, Queue, Redacted } from "effect";
4
+ import * as Socket from "effect/socket/Socket";
5
+ import * as Arbitrary from "effect/Arbitrary";
6
+ import * as Cause$1 from "effect/Cause";
7
+ import * as Duration$1 from "effect/Duration";
8
+ import * as Effect$1 from "effect/Effect";
9
+ import * as Exit from "effect/Exit";
10
+ import "effect/Fiber";
11
+ import { constVoid, flow, pipe } from "effect/Function";
12
+ import * as Layer$1 from "effect/Layer";
13
+ import * as Schedule$1 from "effect/Schedule";
14
+ import * as Scope$1 from "effect/Scope";
15
+ import * as TestClock from "effect/testing/TestClock";
16
+ import * as TestConsole from "effect/testing/TestConsole";
17
+ import * as FakeWebSocket from "@effect-uai/core/testing/FakeWebSocket";
18
+ //#region ../../../node_modules/.pnpm/@effect+vitest@4.1.2_effect@4.1.2_vitest@5.0.3_@types+node@26.2.0_vite@7.3.2_@types+nod_a2fffe0deec250ef9d6207b86a9a1ab8/node_modules/@effect/vitest/dist/internal/internal.js
19
+ /**
20
+ * @since 4.0.0
21
+ */
22
+ const getCurrentSuite = TestRunner.getCurrentSuite;
23
+ const runPromise = (effect, ctx) => Effect$1.runPromise(Effect$1.uninterruptibleMask((restore) => Effect$1.gen(function* () {
24
+ const exit = yield* Effect$1.exit(restore(effect));
25
+ if (Exit.isFailure(exit)) {
26
+ const errors = Cause$1.prettyErrors(exit.cause);
27
+ for (let i = 0; i < errors.length; i++) yield* Effect$1.logError(errors[i]);
28
+ }
29
+ return yield* exit;
30
+ })), { signal: ctx?.signal });
31
+ const settleOnAbort = (ctx, promise) => {
32
+ const onAbort = () => ctx.onTestFinished(() => promise.then(constVoid, constVoid));
33
+ ctx.signal.addEventListener("abort", onAbort, { once: true });
34
+ const cleanup = () => ctx.signal.removeEventListener("abort", onAbort);
35
+ promise.then(cleanup, cleanup);
36
+ if (ctx.signal.aborted) onAbort();
37
+ return promise;
38
+ };
39
+ /** @internal */
40
+ const runTest = (ctx) => (effect) => {
41
+ const promise = runPromise(effect, ctx);
42
+ return ctx ? settleOnAbort(ctx, promise) : promise;
43
+ };
44
+ const TestEnv = /*#__PURE__*/ Layer$1.mergeAll(TestConsole.layer, /*#__PURE__*/ TestClock.layer());
45
+ /** @internal */
46
+ const testOptions = (timeout) => typeof timeout === "number" ? { timeout } : timeout ?? {};
47
+ const hookTimeout = (timeout) => timeout === void 0 ? void 0 : Duration$1.toMillis(Duration$1.fromInputUnsafe(timeout));
48
+ const propertyTestOptions = (timeout) => typeof timeout === "number" ? void 0 : timeout;
49
+ const checkOptions = (timeout) => propertyTestOptions(timeout)?.arbitrary;
50
+ const compileArbitraryInput = (input) => Arbitrary.isArbitrary(input) ? input : Arbitrary.schema(input);
51
+ const makeArbitrary = (arbitraries) => Arbitrary.all(Array.isArray(arbitraries) ? arbitraries.map(compileArbitraryInput) : Object.fromEntries(Object.entries(arbitraries).map(([key, input]) => [key, compileArbitraryInput(input)])));
52
+ const normalizeProperty = (property, value) => Effect$1.catchCause(Effect$1.suspend(() => {
53
+ const output = property(value);
54
+ return Effect$1.isEffect(output) ? output : Effect$1.succeed(output);
55
+ }), (cause) => Cause$1.hasInterrupts(cause) ? Effect$1.failCause(cause) : Effect$1.fail(cause));
56
+ const runCheck = (ctx, arbitrary, property, options) => runTest(ctx)(Effect$1.flatMapEager(Arbitrary.checkEffect(arbitrary, (value) => normalizeProperty(property, value), options), (result) => {
57
+ const failure = Arbitrary.formatCheckFailure(result);
58
+ return failure === void 0 ? Effect$1.void : Effect$1.die(new Error(failure));
59
+ }));
60
+ const withFixturesOf = (source, f) => Object.defineProperty(f, "toString", { value: () => source.toString() });
61
+ const makeItProxy = (it, overrides) => new Proxy(it, {
62
+ apply(target, thisArg, argArray) {
63
+ return Reflect.apply(target, thisArg, argArray);
64
+ },
65
+ get(target, property, receiver) {
66
+ if (Object.hasOwn(overrides, property)) return Reflect.get(overrides, property);
67
+ return Reflect.get(target, property, receiver);
68
+ }
69
+ });
70
+ const collectTasks = (tasks, acc = []) => {
71
+ for (let i = 0; i < tasks.length; i++) {
72
+ const task = tasks[i];
73
+ if (task.type === "test" && task.mode !== "skip" && task.mode !== "todo") acc.push(task);
74
+ else if (task.tasks !== void 0) collectTasks(task.tasks, acc);
75
+ }
76
+ return acc;
77
+ };
78
+ const runsMoreThanOnce = (task) => {
79
+ return ((typeof task.retry === "number" ? task.retry : task.retry?.count) ?? 0) > 0 || (task.repeats ?? 0) > 0;
80
+ };
81
+ const registerProp = (it, name, arbitraries, property, timeout) => {
82
+ const arbitrary = makeArbitrary(arbitraries);
83
+ it(name, testOptions(timeout), withFixturesOf(() => {}, (ctx) => runCheck(ctx, arbitrary, (values) => property(values, ctx), checkOptions(timeout))));
84
+ };
85
+ const makeTester = (mapEffect, it) => {
86
+ const run = (ctx, args, self) => pipe(Effect$1.suspend(() => self(...args)), mapEffect, runTest(ctx));
87
+ const register = (test) => (name, self, timeout) => test(name, testOptions(timeout), withFixturesOf(self, (ctx) => run(ctx, [ctx], self)));
88
+ const each = (cases) => (name, self, timeout) => it.for(cases)(name, testOptions(timeout), withFixturesOf(self, (args, ctx) => run(ctx, [args, ctx], self).then(constVoid)));
89
+ const prop = (name, arbitraries, self, timeout) => registerProp(it, name, arbitraries, (values, ctx) => Effect$1.mapEager(mapEffect(Effect$1.suspend(() => self(values, ctx))), (value) => value !== false), timeout);
90
+ return Object.assign(register(it), {
91
+ skip: register(it.skip),
92
+ skipIf: (condition) => register(it.skipIf(condition)),
93
+ runIf: (condition) => register(it.runIf(condition)),
94
+ only: register(it.only),
95
+ each,
96
+ fails: register(it.fails),
97
+ prop
98
+ });
99
+ };
100
+ const makeProp = (it) => (name, arbitraries, self, timeout) => registerProp(it, name, arbitraries, (values, ctx) => {
101
+ const result = self(values, ctx);
102
+ if (result !== void 0 && typeof result !== "boolean") throw new TypeError("it.prop callbacks must return boolean or void. Use it.effect.prop for Effect callbacks.");
103
+ return result !== false;
104
+ }, timeout);
105
+ const makeLayer = (it) => (layer_, options) => (...args) => {
106
+ const excludeTestServices = options?.excludeTestServices ?? false;
107
+ const withTestEnv = excludeTestServices ? layer_ : Layer$1.provideMerge(layer_, TestEnv);
108
+ const memoMap = options?.memoMap ?? Effect$1.runSync(Layer$1.makeMemoMap);
109
+ const buildPerTest = options?.buildPerTest ?? false;
110
+ const suiteOptions = options?.concurrent === void 0 ? {} : { concurrent: options.concurrent };
111
+ const makeBlockMethods = (provide) => makeItProxy(it, {
112
+ effect: makeTester((effect) => provide(Effect$1.scoped(effect)), it),
113
+ prop: makeProp(it),
114
+ flakyTest,
115
+ layer(nestedLayer, nestedOptions) {
116
+ return makeLayer(it)(Layer$1.provideMerge(nestedLayer, withTestEnv), {
117
+ ...nestedOptions,
118
+ memoMap: Layer$1.forkMemoMapUnsafe(memoMap),
119
+ excludeTestServices,
120
+ buildPerTest: buildPerTest || nestedOptions?.buildPerTest === true
121
+ });
122
+ }
123
+ });
124
+ if (buildPerTest) {
125
+ const methods = makeBlockMethods((effect) => Effect$1.scopedWith((scope) => Layer$1.buildWithMemoMap(withTestEnv, Layer$1.forkMemoMapUnsafe(memoMap), scope).pipe(Effect$1.orDie, Effect$1.flatMap((context) => Effect$1.provide(effect, context)))));
126
+ if (args.length === 1) return args[0](methods);
127
+ return describe(args[0], suiteOptions, () => args[1](methods));
128
+ }
129
+ const scope = Effect$1.runSync(Scope$1.make());
130
+ const contextEffect = Layer$1.buildWithMemoMap(withTestEnv, memoMap, scope).pipe(Effect$1.orDie, Effect$1.cached, Effect$1.runSync);
131
+ let closed = false;
132
+ const closeScope = () => {
133
+ if (closed) return Promise.resolve();
134
+ closed = true;
135
+ return runPromise(Scope$1.close(scope, Exit.void));
136
+ };
137
+ const methods = makeBlockMethods((effect) => Effect$1.flatMap(contextEffect, (context) => Effect$1.provide(effect, context)));
138
+ if (args.length === 1) {
139
+ const currentSuite = getCurrentSuite();
140
+ const previousTasks = new Set(currentSuite.tasks);
141
+ args[0](methods);
142
+ const blockTasks = collectTasks(currentSuite.tasks.filter((task) => !previousTasks.has(task)));
143
+ if (blockTasks.length === 0) {
144
+ afterAll(() => closeScope(), hookTimeout(options?.timeout));
145
+ return;
146
+ }
147
+ const blockTaskSet = new Set(blockTasks);
148
+ const releaseAfterLastTest = !blockTasks.some(runsMoreThanOnce);
149
+ let remaining = blockTasks.length;
150
+ beforeEach(({ onTestFinished, signal, task }) => {
151
+ if (!blockTaskSet.has(task)) return;
152
+ if (releaseAfterLastTest) onTestFinished(() => {
153
+ remaining--;
154
+ if (remaining === 0) return closeScope();
155
+ });
156
+ return runPromise(Effect$1.asVoid(contextEffect), { signal });
157
+ }, hookTimeout(options?.timeout));
158
+ afterAll(() => closeScope(), hookTimeout(options?.timeout));
159
+ return;
160
+ }
161
+ return describe(args[0], suiteOptions, () => {
162
+ beforeAll(() => runPromise(Effect$1.asVoid(contextEffect)), hookTimeout(options?.timeout));
163
+ afterAll(() => closeScope(), hookTimeout(options?.timeout));
164
+ return args[1](methods);
165
+ });
166
+ };
167
+ /** @internal */
168
+ const flakyTest = (self, timeout = Duration$1.seconds(30)) => pipe(self, Effect$1.scoped, Effect$1.sandbox, Effect$1.retry(pipe(Schedule$1.recurs(10), Schedule$1.while((_) => Effect$1.succeed(Duration$1.isLessThanOrEqualTo(Duration$1.fromInputUnsafe(_.elapsed), Duration$1.fromInputUnsafe(timeout)))))), Effect$1.orDie);
169
+ /** @internal */
170
+ const makeMethods = (it) => makeItProxy(it, {
171
+ effect: makeTester(flow(Effect$1.scoped, Effect$1.provide(TestEnv)), it),
172
+ live: makeTester(Effect$1.scoped, it),
173
+ flakyTest,
174
+ layer: makeLayer(it),
175
+ prop: makeProp(it)
176
+ });
177
+ /** @internal */
178
+ const it$1 = /*#__PURE__*/ makeMethods(it$2);
179
+ /** @internal */
180
+ const { effect, layer, live, prop } = it$1;
181
+ //#endregion
182
+ //#region ../../../node_modules/.pnpm/@effect+vitest@4.1.2_effect@4.1.2_vitest@5.0.3_@types+node@26.2.0_vite@7.3.2_@types+nod_a2fffe0deec250ef9d6207b86a9a1ab8/node_modules/@effect/vitest/dist/index.js
183
+ /**
184
+ * Vitest test API extended with Effect test helpers.
185
+ *
186
+ * @stability unstable
187
+ * @category testing
188
+ * @since 4.0.0
189
+ */
190
+ const it = it$1;
191
+ //#endregion
3
192
  //#region src/internal/gateway.test.ts
4
193
  describe("classifyClose", () => {
5
- it("never retries a close reconnecting cannot fix", () => {
194
+ it$2("never retries a close reconnecting cannot fix", () => {
6
195
  globalExpect([
7
196
  4004,
8
197
  4010,
@@ -12,10 +201,10 @@ describe("classifyClose", () => {
12
201
  4014
13
202
  ].map(classifyClose)).toEqual(Array(6).fill("fatal"));
14
203
  });
15
- it("identifies fresh only where the session itself is gone", () => {
204
+ it$2("identifies fresh only where the session itself is gone", () => {
16
205
  globalExpect([4007, 4009].map(classifyClose)).toEqual(["reidentify", "reidentify"]);
17
206
  });
18
- it("resumes on everything else, transport drops included", () => {
207
+ it$2("resumes on everything else, transport drops included", () => {
19
208
  globalExpect([
20
209
  4e3,
21
210
  4003,
@@ -27,13 +216,95 @@ describe("classifyClose", () => {
27
216
  });
28
217
  });
29
218
  describe("closeReason", () => {
30
- it("names a fatal code, since Discord's close frames carry no reason", () => {
219
+ it$2("names a fatal code, since Discord's close frames carry no reason", () => {
31
220
  globalExpect(closeReason(4014, "")).toContain("privileged intent");
32
221
  });
33
- it("falls back to whatever the socket reported", () => {
222
+ it$2("falls back to whatever the socket reported", () => {
34
223
  globalExpect(closeReason(1006, "connection reset")).toBe("connection reset");
35
224
  });
36
225
  });
226
+ const cfg = {
227
+ token: Redacted.make("token"),
228
+ intents: 0,
229
+ url: "wss://gateway.test"
230
+ };
231
+ const HELLO = {
232
+ op: 10,
233
+ d: { heartbeat_interval: 36e5 }
234
+ };
235
+ const answers = {
236
+ 2: [{
237
+ op: 0,
238
+ t: "READY",
239
+ s: 1,
240
+ d: {
241
+ user: {
242
+ id: "1",
243
+ username: "bot"
244
+ },
245
+ session_id: "session",
246
+ resume_gateway_url: "wss://resume.test"
247
+ }
248
+ }],
249
+ 6: [{
250
+ op: 0,
251
+ t: "RESUMED",
252
+ s: 2
253
+ }]
254
+ };
255
+ const gateway = FakeWebSocket.make({
256
+ greeting: [HELLO],
257
+ reply: (frame) => Effect.succeed(answers[frame.op] ?? [])
258
+ });
259
+ /** One fake per connection, in dial order; the last one takes any extra dials. */
260
+ const dialing = (servers) => {
261
+ const urls = [];
262
+ return {
263
+ urls,
264
+ layer: Layer.succeed(Socket.WebSocketConstructor)((url, protocols) => {
265
+ const server = servers[Math.min(urls.length, servers.length - 1)];
266
+ urls.push(url);
267
+ return server.connect(url, protocols);
268
+ })
269
+ };
270
+ };
271
+ describe("gateway close handling", () => {
272
+ it.live.each([1e3, 4e3])("resumes on the resume host after a %i close", (code) => Effect.gen(function* () {
273
+ const first = yield* gateway;
274
+ const second = yield* gateway;
275
+ const { urls, layer } = dialing([first, second]);
276
+ const session = yield* connect(cfg).pipe(Effect.provide(layer));
277
+ globalExpect(session.bot.username).toBe("bot");
278
+ yield* first.close(code);
279
+ yield* second.awaitSent(1);
280
+ globalExpect(urls[1]).toMatch(/^wss:\/\/resume\.test\//);
281
+ globalExpect(yield* second.sent).toEqual([{
282
+ op: 6,
283
+ d: {
284
+ token: "token",
285
+ session_id: "session",
286
+ seq: 1
287
+ }
288
+ }]);
289
+ }));
290
+ it.live("fails the dispatches on a fatal close after READY", () => Effect.gen(function* () {
291
+ const server = yield* gateway;
292
+ const session = yield* connect(cfg).pipe(Effect.provide(dialing([server]).layer));
293
+ yield* server.close(4014);
294
+ const error = yield* Queue.take(session.dispatches).pipe(Effect.flip);
295
+ globalExpect(error).toMatchObject({
296
+ _tag: "MessengerTransportClosed",
297
+ raw: { code: 4014 }
298
+ });
299
+ }));
300
+ it.live("fails the connect on a fatal close before READY", () => Effect.gen(function* () {
301
+ const server = yield* FakeWebSocket.make({ greeting: [HELLO] });
302
+ yield* server.awaitSent(1).pipe(Effect.andThen(server.close(4004)), Effect.forkScoped);
303
+ const error = yield* connect(cfg).pipe(Effect.provide(dialing([server]).layer), Effect.flip);
304
+ globalExpect(error._tag).toBe("MessengerConnectFailed");
305
+ globalExpect(error.reason).toContain("authentication failed");
306
+ }));
307
+ });
37
308
  //#endregion
38
309
  export {};
39
310
 
@@ -1 +1 @@
1
- {"version":3,"file":"gateway.test.mjs","names":[],"sources":["../../src/internal/gateway.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\"\nimport { classifyClose, closeReason } from \"./gateway.js\"\n\ndescribe(\"classifyClose\", () => {\n it(\"never retries a close reconnecting cannot fix\", () => {\n expect([4004, 4010, 4011, 4012, 4013, 4014].map(classifyClose)).toEqual(Array(6).fill(\"fatal\"))\n })\n\n it(\"identifies fresh only where the session itself is gone\", () => {\n expect([4007, 4009].map(classifyClose)).toEqual([\"reidentify\", \"reidentify\"])\n })\n\n it(\"resumes on everything else, transport drops included\", () => {\n // 1006 is a dropped connection, 4000 the code the zombie check sends.\n expect([4000, 4003, 4005, 4008, 1006, 1011].map(classifyClose)).toEqual(Array(6).fill(\"resume\"))\n })\n})\n\ndescribe(\"closeReason\", () => {\n it(\"names a fatal code, since Discord's close frames carry no reason\", () => {\n expect(closeReason(4014, \"\")).toContain(\"privileged intent\")\n })\n\n it(\"falls back to whatever the socket reported\", () => {\n expect(closeReason(1006, \"connection reset\")).toBe(\"connection reset\")\n })\n})\n"],"mappings":";;;AAGA,SAAS,uBAAuB;CAC9B,GAAG,uDAAuD;EACxD,aAAO;GAAC;GAAM;GAAM;GAAM;GAAM;GAAM;EAAI,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,QAAQ,MAAM,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;CAChG,CAAC;CAED,GAAG,gEAAgE;EACjE,aAAO,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,cAAc,YAAY,CAAC;CAC9E,CAAC;CAED,GAAG,8DAA8D;EAE/D,aAAO;GAAC;GAAM;GAAM;GAAM;GAAM;GAAM;EAAI,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,QAAQ,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC;CACjG,CAAC;AACH,CAAC;AAED,SAAS,qBAAqB;CAC5B,GAAG,0EAA0E;EAC3E,aAAO,YAAY,MAAM,EAAE,CAAC,CAAC,CAAC,UAAU,mBAAmB;CAC7D,CAAC;CAED,GAAG,oDAAoD;EACrD,aAAO,YAAY,MAAM,kBAAkB,CAAC,CAAC,CAAC,KAAK,kBAAkB;CACvE,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"gateway.test.mjs","names":["Effect","Cause","Duration","Layer","V.describe","Scope","Schedule","it","V.it","internal.it"],"sources":["../../../../../node_modules/.pnpm/@effect+vitest@4.1.2_effect@4.1.2_vitest@5.0.3_@types+node@26.2.0_vite@7.3.2_@types+nod_a2fffe0deec250ef9d6207b86a9a1ab8/node_modules/@effect/vitest/dist/internal/internal.js","../../../../../node_modules/.pnpm/@effect+vitest@4.1.2_effect@4.1.2_vitest@5.0.3_@types+node@26.2.0_vite@7.3.2_@types+nod_a2fffe0deec250ef9d6207b86a9a1ab8/node_modules/@effect/vitest/dist/index.js","../../src/internal/gateway.test.ts"],"sourcesContent":["/**\n * @since 4.0.0\n */\nimport * as Arbitrary from \"effect/Arbitrary\";\nimport * as Cause from \"effect/Cause\";\nimport * as Duration from \"effect/Duration\";\nimport * as Effect from \"effect/Effect\";\nimport * as Exit from \"effect/Exit\";\nimport * as Fiber from \"effect/Fiber\";\nimport { constVoid, flow, pipe } from \"effect/Function\";\nimport * as Layer from \"effect/Layer\";\nimport * as Schedule from \"effect/Schedule\";\nimport * as Scope from \"effect/Scope\";\nimport * as TestClock from \"effect/testing/TestClock\";\nimport * as TestConsole from \"effect/testing/TestConsole\";\nimport * as V from \"vitest\";\nconst getCurrentSuite = V.TestRunner.getCurrentSuite;\nconst runPromise = (effect, ctx) => Effect.runPromise(\n// Only the test is interruptible: once the signal aborts, the fiber stops\n// at its next interruptible step, which would skip reporting the defects\n// raised by finalizers.\nEffect.uninterruptibleMask(restore => Effect.gen(function* () {\n const exit = yield* Effect.exit(restore(effect));\n if (Exit.isFailure(exit)) {\n const errors = Cause.prettyErrors(exit.cause);\n for (let i = 0; i < errors.length; i++) {\n yield* Effect.logError(errors[i]);\n }\n }\n return yield* exit;\n})), {\n signal: ctx?.signal\n});\nconst settleOnAbort = (ctx, promise) => {\n // Vitest stops awaiting the promise once the signal aborts (timeout or\n // cancellation), so only then add a hook that waits for the finalizers.\n // Registering it unconditionally would change the teardown of every test.\n const onAbort = () => ctx.onTestFinished(() => promise.then(constVoid, constVoid));\n ctx.signal.addEventListener(\"abort\", onAbort, {\n once: true\n });\n const cleanup = () => ctx.signal.removeEventListener(\"abort\", onAbort);\n promise.then(cleanup, cleanup);\n // A retry after a timed-out attempt reuses the aborted signal, so no event fires.\n if (ctx.signal.aborted) onAbort();\n return promise;\n};\n/** @internal */\nconst runTest = ctx => effect => {\n const promise = runPromise(effect, ctx);\n return ctx ? settleOnAbort(ctx, promise) : promise;\n};\nconst TestEnv = /*#__PURE__*/Layer.mergeAll(TestConsole.layer, /*#__PURE__*/TestClock.layer());\n/** @internal */\nexport const addEqualityTesters = () => {\n V.expect.addEqualityTesters([]);\n};\n/** @internal */\nconst testOptions = timeout => typeof timeout === \"number\" ? {\n timeout\n} : timeout ?? {};\nconst hookTimeout = timeout => timeout === undefined ? undefined : Duration.toMillis(Duration.fromInputUnsafe(timeout));\nconst propertyTestOptions = timeout => typeof timeout === \"number\" ? undefined : timeout;\nconst checkOptions = timeout => propertyTestOptions(timeout)?.arbitrary;\nconst compileArbitraryInput = input => Arbitrary.isArbitrary(input) ? input : Arbitrary.schema(input);\nconst makeArbitrary = arbitraries => Arbitrary.all(Array.isArray(arbitraries) ? arbitraries.map(compileArbitraryInput) : Object.fromEntries(Object.entries(arbitraries).map(([key, input]) => [key, compileArbitraryInput(input)])));\nconst normalizeProperty = (property, value) => Effect.catchCause(Effect.suspend(() => {\n const output = property(value);\n return Effect.isEffect(output) ? output : Effect.succeed(output);\n}), cause => Cause.hasInterrupts(cause) ? Effect.failCause(cause) : Effect.fail(cause));\nconst runCheck = (ctx, arbitrary, property, options) => runTest(ctx)(Effect.flatMapEager(Arbitrary.checkEffect(arbitrary, value => normalizeProperty(property, value), options), result => {\n const failure = Arbitrary.formatCheckFailure(result);\n return failure === undefined ? Effect.void : Effect.die(new Error(failure));\n}));\n// Vitest decides which fixtures to set up by parsing the source of a test\n// function's context parameter, and there is no public API to supply the names\n// for a wrapper, so wrappers expose the source of the function they call.\nconst withFixturesOf = (source, f) => Object.defineProperty(f, \"toString\", {\n value: () => source.toString()\n});\nconst runHook = (fn, run) => withFixturesOf(fn, (...args) => {\n const result = fn(...args);\n if (!Effect.isEffect(result)) {\n return result;\n }\n const scope = Scope.makeUnsafe();\n // Everything the hook leaves behind lives in the scope: the resources it\n // acquired and, ahead of them, a cleanup function it returned. On failure\n // the scope closes inside the fiber, so interrupting it awaits the release.\n const effect = Scope.provide(result, scope).pipe(Effect.flatMap(cleanup => typeof cleanup === \"function\" ? Scope.addFinalizer(scope, Effect.promise(async () => await cleanup())) : Effect.void), Effect.onError(cause => Scope.close(scope, Exit.failCause(cause))));\n return run(args, effect, scope);\n});\n// Closing must outlive an already-aborted signal, so it runs without one.\nconst closeHookScope = scope => runPromise(Scope.close(scope, Exit.void));\n/** @internal */\nexport const beforeAll = (fn, timeout) => {\n let dispose = () => Promise.resolve();\n // Vitest drops the cleanup of a setup that outlives its timeout, so the\n // scope is disposed by the cleanup of a hook registered just before this\n // one. It runs in the same cleanup phase, in the slot next to this hook's,\n // with this hook's timeout.\n V.beforeAll(() => () => dispose(), timeout);\n V.beforeAll(runHook(fn, (_, effect, scope) => {\n const fiber = Effect.runFork(effect);\n // Interrupting a setup that Vitest stopped waiting for awaits its release.\n dispose = () => runPromise(Effect.andThen(Fiber.interrupt(fiber), Scope.close(scope, Exit.void)));\n return runPromise(Fiber.join(fiber));\n }), timeout);\n};\n/** @internal */\nexport const beforeEach = (fn, timeout) => V.beforeEach(runHook(fn, ([ctx], effect, scope) =>\n// The scope closes when Vitest runs the hook's cleanup after the test,\n// and the next test waits for it even if that cleanup times out.\nrunTest(ctx)(effect).then(() => () => settleOnAbort(ctx, closeHookScope(scope)))), timeout);\nconst makeItProxy = (it, overrides) => new Proxy(it, {\n apply(target, thisArg, argArray) {\n return Reflect.apply(target, thisArg, argArray);\n },\n get(target, property, receiver) {\n if (Object.hasOwn(overrides, property)) {\n return Reflect.get(overrides, property);\n }\n // do not bind: binding would strip vitest's static helpers (e.g. `describe.each`)\n return Reflect.get(target, property, receiver);\n }\n});\nconst collectTasks = (tasks, acc = []) => {\n for (let i = 0; i < tasks.length; i++) {\n const task = tasks[i];\n if (task.type === \"test\" && task.mode !== \"skip\" && task.mode !== \"todo\") {\n acc.push(task);\n } else if (task.tasks !== undefined) {\n collectTasks(task.tasks, acc);\n }\n }\n return acc;\n};\nconst runsMoreThanOnce = task => {\n const retry = typeof task.retry === \"number\" ? task.retry : task.retry?.count;\n return (retry ?? 0) > 0 || (task.repeats ?? 0) > 0;\n};\nconst registerProp = (it, name, arbitraries, property, timeout) => {\n const arbitrary = makeArbitrary(arbitraries);\n // Property callbacks receive only the base context; the empty source requests no fixtures.\n it(name, testOptions(timeout), withFixturesOf(() => {}, ctx => runCheck(ctx, arbitrary, values => property(values, ctx), checkOptions(timeout))));\n};\nconst makeTester = (mapEffect, it) => {\n const run = (ctx, args, self) => pipe(Effect.suspend(() => self(...args)), mapEffect, runTest(ctx));\n const register = test => (name, self, timeout) => test(name, testOptions(timeout), withFixturesOf(self, ctx => run(ctx, [ctx], self)));\n const each = cases => (name, self, timeout) => it.for(cases)(name, testOptions(timeout), withFixturesOf(self, (args, ctx) => run(ctx, [args, ctx], self).then(constVoid)));\n const prop = (name, arbitraries, self, timeout) => registerProp(it, name, arbitraries, (values, ctx) => Effect.mapEager(mapEffect(Effect.suspend(() => self(values, ctx))), value => value !== false), timeout);\n return Object.assign(register(it), {\n skip: register(it.skip),\n skipIf: condition => register(it.skipIf(condition)),\n runIf: condition => register(it.runIf(condition)),\n only: register(it.only),\n each,\n fails: register(it.fails),\n prop\n });\n};\nconst makeProp = it => (name, arbitraries, self, timeout) => registerProp(it, name, arbitraries, (values, ctx) => {\n const result = self(values, ctx);\n if (result !== undefined && typeof result !== \"boolean\") {\n throw new TypeError(\"it.prop callbacks must return boolean or void. Use it.effect.prop for Effect callbacks.\");\n }\n return result !== false;\n}, timeout);\nconst makeLayer = it => (layer_, options) => (...args) => {\n const excludeTestServices = options?.excludeTestServices ?? false;\n const withTestEnv = excludeTestServices ? layer_ : Layer.provideMerge(layer_, TestEnv);\n const memoMap = options?.memoMap ?? Effect.runSync(Layer.makeMemoMap);\n const buildPerTest = options?.buildPerTest ?? false;\n const suiteOptions = options?.concurrent === undefined ? {} : {\n concurrent: options.concurrent\n };\n const makeBlockMethods = provide => makeItProxy(it, {\n effect: makeTester(effect => provide(Effect.scoped(effect)), it),\n prop: makeProp(it),\n flakyTest,\n layer(nestedLayer, nestedOptions) {\n return makeLayer(it)(Layer.provideMerge(nestedLayer, withTestEnv), {\n ...nestedOptions,\n memoMap: Layer.forkMemoMapUnsafe(memoMap),\n excludeTestServices,\n // The services of a per-test block only exist during a test, so\n // blocks nested in it are built per test as well.\n buildPerTest: buildPerTest || nestedOptions?.buildPerTest === true\n });\n }\n });\n if (buildPerTest) {\n // Each test builds into its own fork of the memo map, so it reuses the\n // services of enclosing blocks and releases the rest when it finishes.\n const methods = makeBlockMethods(effect => Effect.scopedWith(scope => Layer.buildWithMemoMap(withTestEnv, Layer.forkMemoMapUnsafe(memoMap), scope).pipe(Effect.orDie, Effect.flatMap(context => Effect.provide(effect, context)))));\n if (args.length === 1) {\n return args[0](methods);\n }\n return V.describe(args[0], suiteOptions, () => args[1](methods));\n }\n const scope = Effect.runSync(Scope.make());\n const contextEffect = Layer.buildWithMemoMap(withTestEnv, memoMap, scope).pipe(Effect.orDie, Effect.cached, Effect.runSync);\n let closed = false;\n const closeScope = () => {\n if (closed) {\n return Promise.resolve();\n }\n closed = true;\n // Layer cleanup must outlive the last test's already-aborted signal.\n return runPromise(Scope.close(scope, Exit.void));\n };\n const methods = makeBlockMethods(effect => Effect.flatMap(contextEffect, context => Effect.provide(effect, context)));\n if (args.length === 1) {\n const currentSuite = getCurrentSuite();\n const previousTasks = new Set(currentSuite.tasks);\n args[0](methods);\n const blockTasks = collectTasks(currentSuite.tasks.filter(task => !previousTasks.has(task)));\n if (blockTasks.length === 0) {\n V.afterAll(() => closeScope(), hookTimeout(options?.timeout));\n return;\n }\n const blockTaskSet = new Set(blockTasks);\n // Vitest runs hooks once per retry and repeat attempt, so a test's last\n // attempt cannot be counted. Blocks with such tests are released by `afterAll`.\n const releaseAfterLastTest = !blockTasks.some(runsMoreThanOnce);\n let remaining = blockTasks.length;\n V.beforeEach(\n // Destructured so Vitest can parse the hook once the suite defines fixtures.\n ({\n onTestFinished,\n signal,\n task\n }) => {\n if (!blockTaskSet.has(task)) {\n return;\n }\n if (releaseAfterLastTest) {\n onTestFinished(() => {\n remaining--;\n if (remaining === 0) {\n return closeScope();\n }\n });\n }\n return runPromise(Effect.asVoid(contextEffect), {\n signal\n });\n }, hookTimeout(options?.timeout));\n V.afterAll(() => closeScope(), hookTimeout(options?.timeout));\n return;\n }\n return V.describe(args[0], suiteOptions, () => {\n V.beforeAll(() => runPromise(Effect.asVoid(contextEffect)), hookTimeout(options?.timeout));\n V.afterAll(() => closeScope(), hookTimeout(options?.timeout));\n return args[1](methods);\n });\n};\n/** @internal */\nexport const flakyTest = (self, timeout = Duration.seconds(30)) => pipe(self, Effect.scoped, Effect.sandbox, Effect.retry(pipe(Schedule.recurs(10), Schedule.while(_ => Effect.succeed(Duration.isLessThanOrEqualTo(Duration.fromInputUnsafe(_.elapsed), Duration.fromInputUnsafe(timeout)))))), Effect.orDie);\n/** @internal */\nexport const makeMethods = it => makeItProxy(it, {\n effect: makeTester(flow(Effect.scoped, Effect.provide(TestEnv)), it),\n live: makeTester(Effect.scoped, it),\n flakyTest,\n layer: makeLayer(it),\n prop: makeProp(it)\n});\n/** @internal */\nexport const it = /*#__PURE__*/makeMethods(V.it);\n/** @internal */\nexport const {\n /** @internal */\n effect,\n /** @internal */\n layer,\n /** @internal */\n live,\n /** @internal */\n prop\n} = it;\n/** @internal */\nexport const describeWrapped = (name, f) => V.describe(name, () => f(it));\n//# sourceMappingURL=internal.js.map","import * as internal from \"./internal/internal.js\";\n/**\n * Re-exports the `vitest` API unchanged.\n *\n * @stability unstable\n * @since 4.0.0\n */\nexport * from \"vitest\";\n/**\n * Invokes the Effect Vitest equality-tester registration hook.\n *\n * @stability unstable\n * @category utils\n * @since 4.0.0\n */\nexport const addEqualityTesters = internal.addEqualityTesters;\n/**\n * Registers a callback to run once before all tests in the current suite. If\n * the callback returns an `Effect`, it is run and awaited with a `Scope` that\n * closes in a cleanup after the suite's `afterAll` hooks, within the hook's\n * timeout. The `Effect` must not require any other services.\n *\n * **Details**\n *\n * If Vitest stops waiting for the setup, the setup is interrupted before the\n * `Scope` closes. As with any `beforeAll` cleanup, Vitest reports a closing\n * that exceeds the hook's timeout and does not wait for it.\n *\n * @stability unstable\n * @category hooks\n * @since 4.0.0\n */\nexport const beforeAll = internal.beforeAll;\n/**\n * Registers a callback to run before each test in the current suite. If the\n * callback returns an `Effect`, it is run and awaited with a `Scope` that\n * closes when the test finishes, and interrupted if the hook times out. The\n * `Effect` must not require any other services.\n *\n * @stability unstable\n * @category hooks\n * @since 4.0.0\n */\nexport const beforeEach = internal.beforeEach;\n/**\n * Runs a scoped Effect test with test clock and console services.\n *\n * @stability unstable\n * @category testing\n * @since 4.0.0\n */\nexport const effect = internal.effect;\n/**\n * Runs a scoped Effect test with live services.\n *\n * @stability unstable\n * @category testing\n * @since 4.0.0\n */\nexport const live = internal.live;\n/**\n * Share a `Layer` between multiple tests, optionally wrapping\n * the tests in a `describe` block if a name is provided.\n *\n * **Details**\n *\n * Named layers accept `concurrent` to override inherited suite concurrency.\n * Anonymous layers always inherit the enclosing suite's concurrency.\n * Use `ctx.expect` in concurrent tests for test-local snapshots and assertion counts.\n *\n * Pass `buildPerTest: true` to build the layer once per test instead of once\n * per block. Each test gets new services, released when the test finishes,\n * while services from an enclosing `layer` block stay shared. A build failure\n * fails only that test. Blocks nested inside a per-test block are built per\n * test as well. `timeout` has no effect on a per-test block, since the test's\n * own timeout covers the build.\n *\n * **Example** (Sharing layers between tests)\n *\n * ```ts\n * import { assert, layer } from \"@effect/vitest\"\n * import { Effect, Layer, Context } from \"effect\"\n *\n * class Foo extends Context.Service<Foo, \"foo\">()(\"Foo\") {\n * static layer = Layer.succeed(Foo, \"foo\")\n * }\n *\n * class Bar extends Context.Service<Bar, \"bar\">()(\"Bar\") {\n * static layer = Layer.effect(\n * Bar,\n * Effect.map(Foo, () => \"bar\" as const)\n * )\n * }\n *\n * layer(Foo.layer)(\"layer\", (it) => {\n * it.effect(\"adds context\", () =>\n * Effect.gen(function*() {\n * const foo = yield* Foo\n * assert.strictEqual(foo, \"foo\")\n * }))\n *\n * it.layer(Bar.layer)(\"nested\", (it) => {\n * it.effect(\"adds context\", () =>\n * Effect.gen(function*() {\n * const foo = yield* Foo\n * const bar = yield* Bar\n * assert.strictEqual(foo, \"foo\")\n * assert.strictEqual(bar, \"bar\")\n * }))\n * })\n * })\n * ```\n *\n * **Example** (Building a layer for each test)\n *\n * ```ts\n * import { assert, layer } from \"@effect/vitest\"\n * import { Effect, Layer, Context, Ref } from \"effect\"\n *\n * class Database extends Context.Service<Database, \"database\">()(\"Database\") {\n * static layer = Layer.succeed(Database, \"database\")\n * }\n *\n * class Cache extends Context.Service<Cache, Ref.Ref<Array<string>>>()(\"Cache\") {\n * static layer = Layer.effect(\n * Cache,\n * Effect.andThen(Database, Ref.make<Array<string>>([]))\n * )\n * }\n *\n * layer(Database.layer)(\"repository\", (it) => {\n * // Database is shared, Cache is built for each test\n * it.layer(Cache.layer, { buildPerTest: true })((it) => {\n * it.effect(\"writes to the cache\", () =>\n * Effect.gen(function*() {\n * const cache = yield* Cache\n * yield* Ref.update(cache, (keys) => [...keys, \"a\"])\n * assert.deepStrictEqual(yield* Ref.get(cache), [\"a\"])\n * }))\n *\n * it.effect(\"starts with an empty cache\", () =>\n * Effect.gen(function*() {\n * const cache = yield* Cache\n * assert.deepStrictEqual(yield* Ref.get(cache), [])\n * }))\n * })\n * })\n * ```\n *\n * @stability unstable\n * @category testing\n * @since 4.0.0\n */\nexport const layer = internal.layer;\n/**\n * Retries a scoped Effect to tolerate intermittent test failures, dying on exhausted retries.\n *\n * @stability unstable\n * @category testing\n * @since 4.0.0\n */\nexport const flakyTest = internal.flakyTest;\n/**\n * Runs a synchronous property test using schemas or arbitraries.\n *\n * @stability unstable\n * @category testing\n * @since 4.0.0\n */\nexport const prop = internal.prop;\n/**\n * Vitest test API extended with Effect test helpers.\n *\n * @stability unstable\n * @category testing\n * @since 4.0.0\n */\nexport const it = internal.it;\n/**\n * Creates the Effect test helpers for a Vitest test API, such as one extended with fixtures.\n *\n * **Details**\n *\n * Tests receive the fixtures they destructure from their context. Vitest sets them up before the test and tears\n * them down after the test's scope closes, as it does for its own tests. `it.effect.each` passes the context\n * after the test case, and named and anonymous `it.layer` blocks keep the fixtures.\n *\n * **Gotchas**\n *\n * Vitest reads the destructured names to decide which fixtures to set up. Once any fixture is defined, a test that\n * takes the whole context as a plain parameter, such as `(ctx) =>`, fails with a `FixtureParseError`. Property\n * tests receive only the base test context and cannot request fixtures; auto fixtures still run.\n *\n * **Example** (Using a Vitest fixture in an Effect test)\n *\n * ```ts\n * import { assert, makeMethods, test } from \"@effect/vitest\"\n * import { Effect } from \"effect\"\n *\n * const it = makeMethods(\n * test.extend(\"config\", { scope: \"file\" }, () => ({ port: 3000 }))\n * )\n *\n * it.effect(\"reads the config fixture\", ({ config }) =>\n * Effect.sync(() => {\n * assert.strictEqual(config.port, 3000)\n * }))\n * ```\n *\n * @stability unstable\n * @category constructors\n * @since 4.0.0\n */\nexport const makeMethods = internal.makeMethods;\n/**\n * Creates a named Vitest suite whose callback receives Effect test helpers.\n *\n * @stability unstable\n * @category testing\n * @since 4.0.0\n */\nexport const describeWrapped = internal.describeWrapped;\n//# sourceMappingURL=index.js.map","import { it as effect } from \"@effect/vitest\"\nimport { Effect, Layer, Queue, Redacted } from \"effect\"\nimport * as Socket from \"effect/socket/Socket\"\nimport * as FakeWebSocket from \"@effect-uai/core/testing/FakeWebSocket\"\nimport { describe, expect, it } from \"vitest\"\nimport { classifyClose, closeReason, connect } from \"./gateway.js\"\n\ndescribe(\"classifyClose\", () => {\n it(\"never retries a close reconnecting cannot fix\", () => {\n expect([4004, 4010, 4011, 4012, 4013, 4014].map(classifyClose)).toEqual(Array(6).fill(\"fatal\"))\n })\n\n it(\"identifies fresh only where the session itself is gone\", () => {\n expect([4007, 4009].map(classifyClose)).toEqual([\"reidentify\", \"reidentify\"])\n })\n\n it(\"resumes on everything else, transport drops included\", () => {\n // 1006 is a dropped connection, 4000 the code the zombie check sends.\n expect([4000, 4003, 4005, 4008, 1006, 1011].map(classifyClose)).toEqual(Array(6).fill(\"resume\"))\n })\n})\n\ndescribe(\"closeReason\", () => {\n it(\"names a fatal code, since Discord's close frames carry no reason\", () => {\n expect(closeReason(4014, \"\")).toContain(\"privileged intent\")\n })\n\n it(\"falls back to whatever the socket reported\", () => {\n expect(closeReason(1006, \"connection reset\")).toBe(\"connection reset\")\n })\n})\n\nconst cfg = { token: Redacted.make(\"token\"), intents: 0, url: \"wss://gateway.test\" }\n\n// Long enough that no heartbeat lands mid-test.\nconst HELLO = { op: 10, d: { heartbeat_interval: 3_600_000 } }\n\nconst READY = {\n op: 0,\n t: \"READY\",\n s: 1,\n d: {\n user: { id: \"1\", username: \"bot\" },\n session_id: \"session\",\n resume_gateway_url: \"wss://resume.test\",\n },\n}\n\n// Identify gets READY, resume gets RESUMED.\nconst answers: Record<number, ReadonlyArray<unknown>> = {\n 2: [READY],\n 6: [{ op: 0, t: \"RESUMED\", s: 2 }],\n}\n\nconst gateway = FakeWebSocket.make({\n greeting: [HELLO],\n reply: (frame) => Effect.succeed(answers[(frame as { op: number }).op] ?? []),\n})\n\n/** One fake per connection, in dial order; the last one takes any extra dials. */\nconst dialing = (servers: ReadonlyArray<FakeWebSocket.FakeWebSocketServer>) => {\n const urls: Array<string> = []\n const layer = Layer.succeed(Socket.WebSocketConstructor)((url, protocols) => {\n const server = servers[Math.min(urls.length, servers.length - 1)]!\n urls.push(url)\n return server.connect(url, protocols)\n })\n return { urls, layer }\n}\n\ndescribe(\"gateway close handling\", () => {\n effect.live.each([1000, 4000])(\"resumes on the resume host after a %i close\", (code) =>\n Effect.gen(function* () {\n const first = yield* gateway\n const second = yield* gateway\n const { urls, layer } = dialing([first, second])\n const session = yield* connect(cfg).pipe(Effect.provide(layer))\n expect(session.bot.username).toBe(\"bot\")\n\n yield* first.close(code)\n yield* second.awaitSent(1)\n\n expect(urls[1]).toMatch(/^wss:\\/\\/resume\\.test\\//)\n expect(yield* second.sent).toEqual([\n { op: 6, d: { token: \"token\", session_id: \"session\", seq: 1 } },\n ])\n }),\n )\n\n effect.live(\"fails the dispatches on a fatal close after READY\", () =>\n Effect.gen(function* () {\n const server = yield* gateway\n const session = yield* connect(cfg).pipe(Effect.provide(dialing([server]).layer))\n\n yield* server.close(4014)\n const error = yield* Queue.take(session.dispatches).pipe(Effect.flip)\n\n expect(error).toMatchObject({ _tag: \"MessengerTransportClosed\", raw: { code: 4014 } })\n }),\n )\n\n effect.live(\"fails the connect on a fatal close before READY\", () =>\n Effect.gen(function* () {\n const server = yield* FakeWebSocket.make({ greeting: [HELLO] })\n yield* server.awaitSent(1).pipe(Effect.andThen(server.close(4004)), Effect.forkScoped)\n\n const error = yield* connect(cfg).pipe(Effect.provide(dialing([server]).layer), Effect.flip)\n\n expect(error._tag).toBe(\"MessengerConnectFailed\")\n expect(error.reason).toContain(\"authentication failed\")\n }),\n )\n})\n"],"x_google_ignoreList":[0,1],"mappings":";;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,kBAAA,WAA+B;AACrC,MAAM,cAAc,QAAQ,QAAQA,SAAO,WAI3CA,SAAO,qBAAoB,YAAWA,SAAO,IAAI,aAAa;CAC5D,MAAM,OAAO,OAAOA,SAAO,KAAK,QAAQ,MAAM,CAAC;CAC/C,IAAI,KAAK,UAAU,IAAI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,GAAG,CAAC,CAAC,KAAK,OAAO,QAAQ,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,OAAO,IAAI;EAE3F,aAAO,MAAM,IAAI,CAAC,CAAC,KAAK,wBAAwB;EAChD,aAAO,MAAM,MAAM,CAAC,CAAC,UAAU,uBAAuB;CACxD,CAAC,CACH;AACF,CAAC"}
@@ -1,2 +1,2 @@
1
- import { a as Method, c as decoded, i as Fields, l as provider, n as ApiFailure, o as Upload, r as Config, s as call, t as ApiError, u as upload } from "../rest-CZSW-VJK.mjs";
1
+ import { a as Method, c as decoded, i as Fields, l as provider, n as ApiFailure, o as Upload, r as Config, s as call, t as ApiError, u as upload } from "../rest-SmIBt9Nh.mjs";
2
2
  export { ApiError, ApiFailure, Config, Fields, Method, Upload, call, decoded, provider, upload };
@@ -1,11 +1,11 @@
1
1
  import { Data, Duration, Effect, Redacted, Schema } from "effect";
2
- import { HttpClient, HttpClientRequest } from "effect/unstable/http";
2
+ import { HttpClient, HttpClientRequest } from "effect/http";
3
3
  import * as MessengerError from "@effect-uai/core/MessengerError";
4
4
  import * as Multipart from "@effect-uai/core/Multipart";
5
5
  //#region src/internal/rest.ts
6
6
  const provider = "discord";
7
7
  /** Tracks the package version; Discord requires a `DiscordBot (url, version)` agent. */
8
- const userAgent = "DiscordBot (https://effect-uai.betalyra.com, 0.14.0)";
8
+ const userAgent = "DiscordBot (https://effect-uai.com, 0.14.0)";
9
9
  /**
10
10
  * A REST call that came back non-2xx or never came back at all. `code` is
11
11
  * Discord's own JSON error code, `status` the HTTP one; each verb maps this