{"version":3,"file":"wsAsync.cjs","sources":["../../../../src/websockets/wsAsync.ts"],"sourcesContent":["import type {\n  RpcSubscriptions,\n  SolanaRpcSubscriptionsApi,\n  Commitment,\n  Address,\n  Signature,\n} from \"@solana/kit\";\n\ntype WsRaw = RpcSubscriptions<SolanaRpcSubscriptionsApi>;\n\ntype LogsReq = ReturnType<WsRaw[\"logsNotifications\"]>;\ntype SlotReq = ReturnType<WsRaw[\"slotNotifications\"]>;\ntype SignatureReq = ReturnType<WsRaw[\"signatureNotifications\"]>;\ntype ProgramReq = ReturnType<WsRaw[\"programNotifications\"]>;\ntype AccountReq = ReturnType<WsRaw[\"accountNotifications\"]>;\n\n/** Filter for `logsNotifications` — subscribe to all logs or logs mentioning a specific address. */\nexport type LogsFilter =\n  | \"all\"\n  | \"allWithVotes\"\n  | Readonly<{ mentions: readonly [Address] }>;\n\n/** Configuration options for WebSocket subscriptions. */\nexport type LogsConfig = Readonly<{ commitment?: Commitment }>;\n\n/**\n * WebSocket RPC subscription client. Provides promisified access to\n * Solana's WebSocket subscriptions (logs, slots, signatures, programs, accounts).\n *\n * All subscription methods return a `Promise` that resolves to a subscription\n * object with an async iterator.\n */\nexport interface WsAsync {\n  /** Subscribe to transaction logs. */\n  logsNotifications(filter: LogsFilter, config?: LogsConfig): Promise<LogsReq>;\n  /** Subscribe to slot updates. */\n  slotNotifications(config?: LogsConfig): Promise<SlotReq>;\n  /** Subscribe to signature confirmation status. */\n  signatureNotifications(\n    signature: Signature | string,\n    config?: LogsConfig\n  ): Promise<SignatureReq>;\n  /** Subscribe to program account updates. */\n  programNotifications(\n    ...args: Parameters<WsRaw[\"programNotifications\"]>\n  ): Promise<ProgramReq>;\n  /** Subscribe to account updates. */\n  accountNotifications(\n    ...args: Parameters<WsRaw[\"accountNotifications\"]>\n  ): Promise<AccountReq>;\n\n  /** Manually close the underlying WebSocket connection. */\n  close(): void;\n}\n\nconst importWs = async () =>\n  (await import(\"@solana/kit\")).createSolanaRpcSubscriptions;\n\n/** Create a promisified WebSocket RPC subscription client. */\nexport const makeWsAsync = (wsUrl: string): WsAsync => {\n  let _raw: WsRaw | undefined;\n\n  const raw = async (): Promise<WsRaw> => {\n    if (_raw) return _raw;\n\n    const ctor = await importWs();\n    _raw = ctor(wsUrl);\n\n    return _raw;\n  };\n\n  return {\n    logsNotifications: (filter, config) =>\n      raw().then((r) => r.logsNotifications(filter as any, config)),\n\n    slotNotifications: (config) =>\n      raw().then((r) => (r.slotNotifications as any)(config)),\n\n    signatureNotifications: (sig, config) =>\n      raw().then((r) => r.signatureNotifications(sig as Signature, config)),\n\n    programNotifications: (...args) =>\n      raw().then((r) => (r.programNotifications as any)(...args)),\n\n    accountNotifications: (...args) =>\n      raw().then((r) => (r.accountNotifications as any)(...args)),\n\n    close() {\n      // `@solana/kit` exposes `.dispose()`; but we fall back to `.close()` or noop\n      if (_raw && typeof (_raw as any).dispose === \"function\") {\n        (_raw as any).dispose();\n      } else if (_raw && typeof (_raw as any).close === \"function\") {\n        (_raw as any).close();\n      }\n      _raw = undefined;\n    },\n  };\n};\n"],"names":[],"mappings":";;AAuDA,MAAM,QAAQ,GAAG,YACf,CAAC,MAAM,OAAO,aAAa,CAAC,EAAE,4BAA4B;AAE5D;AACO,MAAM,WAAW,GAAG,CAAC,KAAa,KAAa;AACpD,IAAA,IAAI,IAAuB;AAE3B,IAAA,MAAM,GAAG,GAAG,YAA2B;AACrC,QAAA,IAAI,IAAI;AAAE,YAAA,OAAO,IAAI;AAErB,QAAA,MAAM,IAAI,GAAG,MAAM,QAAQ,EAAE;AAC7B,QAAA,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;AAElB,QAAA,OAAO,IAAI;AACb,IAAA,CAAC;IAED,OAAO;QACL,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,KAChC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,iBAAiB,CAAC,MAAa,EAAE,MAAM,CAAC,CAAC;QAE/D,iBAA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