napcon 0.0.13 → 0.0.14

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.
@@ -602,7 +602,7 @@ interface ProtocolReplyFailed {
602
602
  type ProtocolReply<T = any> = ProtocolReplyOk<T> | ProtocolReplyFailed;
603
603
  //#endregion
604
604
  //#region src/types/pubsub.d.ts
605
- interface SubHalf<T extends Record<string, any[]>> {
605
+ interface SubHalf<T extends Record<string, any>> {
606
606
  on<const K extends keyof T>(type: K, ...listeners: Array<(...args: T[K]) => void>): Dispose;
607
607
  }
608
608
  interface OffHalf<T extends Record<string, any> = Record<string, any>> {
@@ -636,7 +636,7 @@ interface Transport extends TransportCommon {
636
636
  }
637
637
  //#endregion
638
638
  //#region src/types/connection.d.ts
639
- interface ConnectionBasicPubSubHandlers {
639
+ type ConnectionBasicPubSubHandlers = {
640
640
  'connection.connected': [transport: Transport, connection: Connection];
641
641
  'connection.disconnected': [transport: Transport, connection: Connection];
642
642
  'connection.reconnect': [transport: Transport, connection: Connection];
@@ -645,8 +645,7 @@ interface ConnectionBasicPubSubHandlers {
645
645
  'protocol.event': [event: ProtocolEvent, connection: Connection];
646
646
  'connection.error': [error: any, connection: Connection];
647
647
  'connection.reply.stream': [data: ProtocolReply, connection: Connection];
648
- [x: string]: any[];
649
- }
648
+ };
650
649
  type ProtocolEventHandler = (event: ProtocolEvent, connection: Connection) => void;
651
650
  type ConnectionPubSub = PubSubOff<ConnectionBasicPubSubHandlers>;
652
651
  type ConnectionStreamResult<R = any> = [stream: ProtocolReadableStream, result: Promise<ProtocolStreamCompleteMessage<R>>];
@@ -672,4 +671,4 @@ type OpenConnection = ((options: OpenConnectionOptions) => Connection) & ((trans
672
671
  declare const open: OpenConnection;
673
672
  //#endregion
674
673
  export { ProtocolNoticeEventCommon as $, ProtocolMessagePokeRecvSegment as $t, ProtocolStreamMessage as A, ProtocolRequestEventCommon as At, ProtocolMessageEvent as B, ProtocolMessageForwardRecvSegment as Bt, ProtocolReplyOk as C, ProtocolNoticeNotifyGroupPokeEvent as Ct, ProtocolStreamCompleteMessage as D, ProtocolNoticeNotifyPokeEventCommon as Dt, ProtocolRequest as E, ProtocolNoticeNotifyPokeEvent as Et, ProtocolEventNames as F, ProtocolMessageDiceSendSegment as Ft, ProtocolMessageSentEvent as G, ProtocolMessageLocationSegment as Gt, ProtocolMessageGroupEvent as H, ProtocolMessageImageSendSegment as Ht, ProtocolEventPostTypes as I, ProtocolMessageFaceSegment as It, ProtocolMetaHeartbeatEvent as J, ProtocolMessageMiniAppSegment as Jt, ProtocolMetaEvent as K, ProtocolMessageMarkdownSegment as Kt, ProtocolFriendRequestEvent as L, ProtocolMessageFileRecvSegment as Lt, ProtocolEventCommon as M, ProtocolMessageContactSendSegment as Mt, ProtocolEventHandlers as N, ProtocolMessageContentNode as Nt, ProtocolStreamDataMessage as O, ProtocolNoticeNotifyProfileLikeEvent as Ot, ProtocolEventNamePaths as P, ProtocolMessageDiceRecvSegment as Pt, ProtocolNoticeEvent as Q, ProtocolMessageOnlineFileSegment as Qt, ProtocolGroupRequestEvent as R, ProtocolMessageFileSendSegment as Rt, ProtocolReplyFailed as S, ProtocolNoticeNotifyGroupNameEvent as St, ProtocolReplyStreamResponse as T, ProtocolNoticeNotifyInputStatusEvent as Tt, ProtocolMessagePrivateEvent as U, ProtocolMessageJsonRecvSegment as Ut, ProtocolMessageEventCommon as V, ProtocolMessageImageRecvSegment as Vt, ProtocolMessagePrivateEventSubTypes as W, ProtocolMessageJsonSendSegment as Wt, ProtocolMetaLifecycleEventSubTypes as X, ProtocolMessageMusicSendSegment as Xt, ProtocolMetaLifecycleEvent as Y, ProtocolMessageMusicRecvSegment as Yt, ProtocolNoticeBotOfflineEvent as Z, ProtocolMessageNode as Zt, PubSubOff as _, Numeric as _n, ProtocolNoticeGroupRecallEvent as _t, ConnectionStreamResult as a, ProtocolMessageReplySegment as an, ProtocolNoticeGroupBanEvent as at, ProtocolReadableStream as b, ProtocolNoticeNotifyEvent as bt, ProtocolEventHandler as c, ProtocolMessageSegment as cn, ProtocolNoticeGroupDecreaseEvent as ct, Transport as d, ProtocolMessageVideoRecvSegment as dn, ProtocolNoticeGroupEssenceEventSubTypes as dt, ProtocolMessagePokeSendSegment as en, ProtocolNoticeFriendAddEvent as et, TransportCommon as f, ProtocolMessageVideoSendSegment as fn, ProtocolNoticeGroupEvent as ft, PubSub as g, MaybePromiseLike as gn, ProtocolNoticeGroupMessageEmojiLikeEvent as gt, PubHalf as h, MaybeArray as hn, ProtocolNoticeGroupIncreaseEventSubTypes as ht, ConnectionPubSub as i, ProtocolMessageRefNode as in, ProtocolNoticeGroupAdminEventSubTypes as it, ProtocolEvent as j, ProtocolMessageAtSegment as jt, ProtocolStreamErrorMessage as k, ProtocolRequestEvent as kt, TransportFactory as l, ProtocolMessageSendSegment as ln, ProtocolNoticeGroupDecreaseEventSubTypes as lt, OffHalf as m, Dispose as mn, ProtocolNoticeGroupIncreaseEvent as mt, Connection as n, ProtocolMessageRecordSendSegment as nn, ProtocolNoticeFriendRecallEvent as nt, OpenConnection as o, ProtocolMessageRpsRecvSegment as on, ProtocolNoticeGroupBanEventSubTypes as ot, TransportEventHandlers as p, ProtocolMessageXmlSegment as pn, ProtocolNoticeGroupEventCommon as pt, ProtocolMetaEventCommon as q, ProtocolMessageMfaceSendSegment as qt, ConnectionBasicPubSubHandlers as r, ProtocolMessageRecvSegment as rn, ProtocolNoticeGroupAdminEvent as rt, OpenConnectionOptions as s, ProtocolMessageRpsSendSegment as sn, ProtocolNoticeGroupCardEvent as st, open as t, ProtocolMessageRecordRecvSegment as tn, ProtocolNoticeFriendEvent as tt, ReadyState as u, ProtocolMessageTextSegment as un, ProtocolNoticeGroupEssenceEvent as ut, SubHalf as v, ProtocolNoticeGroupUploadEvent as vt, ProtocolReplyStream as w, ProtocolNoticeNotifyGroupTitleEvent as wt, ProtocolReply as x, ProtocolNoticeNotifyFriendPokeEvent as xt, SubOff as y, ProtocolNoticeGroupUploadFile as yt, ProtocolMessageEmojiLike as z, ProtocolMessageFlashTransferSegment as zt };
675
- //# sourceMappingURL=index-xpa8wXI0.d.mts.map
674
+ //# sourceMappingURL=index-VGBoCdDT.d.mts.map
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as ProtocolNoticeEventCommon, $t as ProtocolMessagePokeRecvSegment, A as ProtocolStreamMessage, At as ProtocolRequestEventCommon, B as ProtocolMessageEvent, Bt as ProtocolMessageForwardRecvSegment, C as ProtocolReplyOk, Ct as ProtocolNoticeNotifyGroupPokeEvent, D as ProtocolStreamCompleteMessage, Dt as ProtocolNoticeNotifyPokeEventCommon, E as ProtocolRequest, Et as ProtocolNoticeNotifyPokeEvent, F as ProtocolEventNames, Ft as ProtocolMessageDiceSendSegment, G as ProtocolMessageSentEvent, Gt as ProtocolMessageLocationSegment, H as ProtocolMessageGroupEvent, Ht as ProtocolMessageImageSendSegment, I as ProtocolEventPostTypes, It as ProtocolMessageFaceSegment, J as ProtocolMetaHeartbeatEvent, Jt as ProtocolMessageMiniAppSegment, K as ProtocolMetaEvent, Kt as ProtocolMessageMarkdownSegment, L as ProtocolFriendRequestEvent, Lt as ProtocolMessageFileRecvSegment, M as ProtocolEventCommon, Mt as ProtocolMessageContactSendSegment, N as ProtocolEventHandlers, Nt as ProtocolMessageContentNode, O as ProtocolStreamDataMessage, Ot as ProtocolNoticeNotifyProfileLikeEvent, P as ProtocolEventNamePaths, Pt as ProtocolMessageDiceRecvSegment, Q as ProtocolNoticeEvent, Qt as ProtocolMessageOnlineFileSegment, R as ProtocolGroupRequestEvent, Rt as ProtocolMessageFileSendSegment, S as ProtocolReplyFailed, St as ProtocolNoticeNotifyGroupNameEvent, T as ProtocolReplyStreamResponse, Tt as ProtocolNoticeNotifyInputStatusEvent, U as ProtocolMessagePrivateEvent, Ut as ProtocolMessageJsonRecvSegment, V as ProtocolMessageEventCommon, Vt as ProtocolMessageImageRecvSegment, W as ProtocolMessagePrivateEventSubTypes, Wt as ProtocolMessageJsonSendSegment, X as ProtocolMetaLifecycleEventSubTypes, Xt as ProtocolMessageMusicSendSegment, Y as ProtocolMetaLifecycleEvent, Yt as ProtocolMessageMusicRecvSegment, Z as ProtocolNoticeBotOfflineEvent, Zt as ProtocolMessageNode, _ as PubSubOff, _n as Numeric, _t as ProtocolNoticeGroupRecallEvent, a as ConnectionStreamResult, an as ProtocolMessageReplySegment, at as ProtocolNoticeGroupBanEvent, b as ProtocolReadableStream, bt as ProtocolNoticeNotifyEvent, c as ProtocolEventHandler, cn as ProtocolMessageSegment, ct as ProtocolNoticeGroupDecreaseEvent, d as Transport, dn as ProtocolMessageVideoRecvSegment, dt as ProtocolNoticeGroupEssenceEventSubTypes, en as ProtocolMessagePokeSendSegment, et as ProtocolNoticeFriendAddEvent, f as TransportCommon, fn as ProtocolMessageVideoSendSegment, ft as ProtocolNoticeGroupEvent, g as PubSub, gn as MaybePromiseLike, gt as ProtocolNoticeGroupMessageEmojiLikeEvent, h as PubHalf, hn as MaybeArray, ht as ProtocolNoticeGroupIncreaseEventSubTypes, i as ConnectionPubSub, in as ProtocolMessageRefNode, it as ProtocolNoticeGroupAdminEventSubTypes, j as ProtocolEvent, jt as ProtocolMessageAtSegment, k as ProtocolStreamErrorMessage, kt as ProtocolRequestEvent, l as TransportFactory, ln as ProtocolMessageSendSegment, lt as ProtocolNoticeGroupDecreaseEventSubTypes, m as OffHalf, mn as Dispose, mt as ProtocolNoticeGroupIncreaseEvent, n as Connection, nn as ProtocolMessageRecordSendSegment, nt as ProtocolNoticeFriendRecallEvent, o as OpenConnection, on as ProtocolMessageRpsRecvSegment, ot as ProtocolNoticeGroupBanEventSubTypes, p as TransportEventHandlers, pn as ProtocolMessageXmlSegment, pt as ProtocolNoticeGroupEventCommon, q as ProtocolMetaEventCommon, qt as ProtocolMessageMfaceSendSegment, r as ConnectionBasicPubSubHandlers, rn as ProtocolMessageRecvSegment, rt as ProtocolNoticeGroupAdminEvent, s as OpenConnectionOptions, sn as ProtocolMessageRpsSendSegment, st as ProtocolNoticeGroupCardEvent, t as open, tn as ProtocolMessageRecordRecvSegment, tt as ProtocolNoticeFriendEvent, u as ReadyState, un as ProtocolMessageTextSegment, ut as ProtocolNoticeGroupEssenceEvent, v as SubHalf, vt as ProtocolNoticeGroupUploadEvent, w as ProtocolReplyStream, wt as ProtocolNoticeNotifyGroupTitleEvent, x as ProtocolReply, xt as ProtocolNoticeNotifyFriendPokeEvent, y as SubOff, yt as ProtocolNoticeGroupUploadFile, z as ProtocolMessageEmojiLike, zt as ProtocolMessageFlashTransferSegment } from "./index-xpa8wXI0.mjs";
1
+ import { $ as ProtocolNoticeEventCommon, $t as ProtocolMessagePokeRecvSegment, A as ProtocolStreamMessage, At as ProtocolRequestEventCommon, B as ProtocolMessageEvent, Bt as ProtocolMessageForwardRecvSegment, C as ProtocolReplyOk, Ct as ProtocolNoticeNotifyGroupPokeEvent, D as ProtocolStreamCompleteMessage, Dt as ProtocolNoticeNotifyPokeEventCommon, E as ProtocolRequest, Et as ProtocolNoticeNotifyPokeEvent, F as ProtocolEventNames, Ft as ProtocolMessageDiceSendSegment, G as ProtocolMessageSentEvent, Gt as ProtocolMessageLocationSegment, H as ProtocolMessageGroupEvent, Ht as ProtocolMessageImageSendSegment, I as ProtocolEventPostTypes, It as ProtocolMessageFaceSegment, J as ProtocolMetaHeartbeatEvent, Jt as ProtocolMessageMiniAppSegment, K as ProtocolMetaEvent, Kt as ProtocolMessageMarkdownSegment, L as ProtocolFriendRequestEvent, Lt as ProtocolMessageFileRecvSegment, M as ProtocolEventCommon, Mt as ProtocolMessageContactSendSegment, N as ProtocolEventHandlers, Nt as ProtocolMessageContentNode, O as ProtocolStreamDataMessage, Ot as ProtocolNoticeNotifyProfileLikeEvent, P as ProtocolEventNamePaths, Pt as ProtocolMessageDiceRecvSegment, Q as ProtocolNoticeEvent, Qt as ProtocolMessageOnlineFileSegment, R as ProtocolGroupRequestEvent, Rt as ProtocolMessageFileSendSegment, S as ProtocolReplyFailed, St as ProtocolNoticeNotifyGroupNameEvent, T as ProtocolReplyStreamResponse, Tt as ProtocolNoticeNotifyInputStatusEvent, U as ProtocolMessagePrivateEvent, Ut as ProtocolMessageJsonRecvSegment, V as ProtocolMessageEventCommon, Vt as ProtocolMessageImageRecvSegment, W as ProtocolMessagePrivateEventSubTypes, Wt as ProtocolMessageJsonSendSegment, X as ProtocolMetaLifecycleEventSubTypes, Xt as ProtocolMessageMusicSendSegment, Y as ProtocolMetaLifecycleEvent, Yt as ProtocolMessageMusicRecvSegment, Z as ProtocolNoticeBotOfflineEvent, Zt as ProtocolMessageNode, _ as PubSubOff, _n as Numeric, _t as ProtocolNoticeGroupRecallEvent, a as ConnectionStreamResult, an as ProtocolMessageReplySegment, at as ProtocolNoticeGroupBanEvent, b as ProtocolReadableStream, bt as ProtocolNoticeNotifyEvent, c as ProtocolEventHandler, cn as ProtocolMessageSegment, ct as ProtocolNoticeGroupDecreaseEvent, d as Transport, dn as ProtocolMessageVideoRecvSegment, dt as ProtocolNoticeGroupEssenceEventSubTypes, en as ProtocolMessagePokeSendSegment, et as ProtocolNoticeFriendAddEvent, f as TransportCommon, fn as ProtocolMessageVideoSendSegment, ft as ProtocolNoticeGroupEvent, g as PubSub, gn as MaybePromiseLike, gt as ProtocolNoticeGroupMessageEmojiLikeEvent, h as PubHalf, hn as MaybeArray, ht as ProtocolNoticeGroupIncreaseEventSubTypes, i as ConnectionPubSub, in as ProtocolMessageRefNode, it as ProtocolNoticeGroupAdminEventSubTypes, j as ProtocolEvent, jt as ProtocolMessageAtSegment, k as ProtocolStreamErrorMessage, kt as ProtocolRequestEvent, l as TransportFactory, ln as ProtocolMessageSendSegment, lt as ProtocolNoticeGroupDecreaseEventSubTypes, m as OffHalf, mn as Dispose, mt as ProtocolNoticeGroupIncreaseEvent, n as Connection, nn as ProtocolMessageRecordSendSegment, nt as ProtocolNoticeFriendRecallEvent, o as OpenConnection, on as ProtocolMessageRpsRecvSegment, ot as ProtocolNoticeGroupBanEventSubTypes, p as TransportEventHandlers, pn as ProtocolMessageXmlSegment, pt as ProtocolNoticeGroupEventCommon, q as ProtocolMetaEventCommon, qt as ProtocolMessageMfaceSendSegment, r as ConnectionBasicPubSubHandlers, rn as ProtocolMessageRecvSegment, rt as ProtocolNoticeGroupAdminEvent, s as OpenConnectionOptions, sn as ProtocolMessageRpsSendSegment, st as ProtocolNoticeGroupCardEvent, t as open, tn as ProtocolMessageRecordRecvSegment, tt as ProtocolNoticeFriendEvent, u as ReadyState, un as ProtocolMessageTextSegment, ut as ProtocolNoticeGroupEssenceEvent, v as SubHalf, vt as ProtocolNoticeGroupUploadEvent, w as ProtocolReplyStream, wt as ProtocolNoticeNotifyGroupTitleEvent, x as ProtocolReply, xt as ProtocolNoticeNotifyFriendPokeEvent, y as SubOff, yt as ProtocolNoticeGroupUploadFile, z as ProtocolMessageEmojiLike, zt as ProtocolMessageFlashTransferSegment } from "./index-VGBoCdDT.mjs";
2
2
  export { Connection, ConnectionBasicPubSubHandlers, ConnectionPubSub, ConnectionStreamResult, Dispose, MaybeArray, MaybePromiseLike, Numeric, OffHalf, OpenConnection, OpenConnectionOptions, ProtocolEvent, ProtocolEventCommon, ProtocolEventHandler, ProtocolEventHandlers, ProtocolEventNamePaths, ProtocolEventNames, ProtocolEventPostTypes, ProtocolFriendRequestEvent, ProtocolGroupRequestEvent, ProtocolMessageAtSegment, ProtocolMessageContactSendSegment, ProtocolMessageContentNode, ProtocolMessageDiceRecvSegment, ProtocolMessageDiceSendSegment, ProtocolMessageEmojiLike, ProtocolMessageEvent, ProtocolMessageEventCommon, ProtocolMessageFaceSegment, ProtocolMessageFileRecvSegment, ProtocolMessageFileSendSegment, ProtocolMessageFlashTransferSegment, ProtocolMessageForwardRecvSegment, ProtocolMessageGroupEvent, ProtocolMessageImageRecvSegment, ProtocolMessageImageSendSegment, ProtocolMessageJsonRecvSegment, ProtocolMessageJsonSendSegment, ProtocolMessageLocationSegment, ProtocolMessageMarkdownSegment, ProtocolMessageMfaceSendSegment, ProtocolMessageMiniAppSegment, ProtocolMessageMusicRecvSegment, ProtocolMessageMusicSendSegment, ProtocolMessageNode, ProtocolMessageOnlineFileSegment, ProtocolMessagePokeRecvSegment, ProtocolMessagePokeSendSegment, ProtocolMessagePrivateEvent, ProtocolMessagePrivateEventSubTypes, ProtocolMessageRecordRecvSegment, ProtocolMessageRecordSendSegment, ProtocolMessageRecvSegment, ProtocolMessageRefNode, ProtocolMessageReplySegment, ProtocolMessageRpsRecvSegment, ProtocolMessageRpsSendSegment, ProtocolMessageSegment, ProtocolMessageSendSegment, ProtocolMessageSentEvent, ProtocolMessageTextSegment, ProtocolMessageVideoRecvSegment, ProtocolMessageVideoSendSegment, ProtocolMessageXmlSegment, ProtocolMetaEvent, ProtocolMetaEventCommon, ProtocolMetaHeartbeatEvent, ProtocolMetaLifecycleEvent, ProtocolMetaLifecycleEventSubTypes, ProtocolNoticeBotOfflineEvent, ProtocolNoticeEvent, ProtocolNoticeEventCommon, ProtocolNoticeFriendAddEvent, ProtocolNoticeFriendEvent, ProtocolNoticeFriendRecallEvent, ProtocolNoticeGroupAdminEvent, ProtocolNoticeGroupAdminEventSubTypes, ProtocolNoticeGroupBanEvent, ProtocolNoticeGroupBanEventSubTypes, ProtocolNoticeGroupCardEvent, ProtocolNoticeGroupDecreaseEvent, ProtocolNoticeGroupDecreaseEventSubTypes, ProtocolNoticeGroupEssenceEvent, ProtocolNoticeGroupEssenceEventSubTypes, ProtocolNoticeGroupEvent, ProtocolNoticeGroupEventCommon, ProtocolNoticeGroupIncreaseEvent, ProtocolNoticeGroupIncreaseEventSubTypes, ProtocolNoticeGroupMessageEmojiLikeEvent, ProtocolNoticeGroupRecallEvent, ProtocolNoticeGroupUploadEvent, ProtocolNoticeGroupUploadFile, ProtocolNoticeNotifyEvent, ProtocolNoticeNotifyFriendPokeEvent, ProtocolNoticeNotifyGroupNameEvent, ProtocolNoticeNotifyGroupPokeEvent, ProtocolNoticeNotifyGroupTitleEvent, ProtocolNoticeNotifyInputStatusEvent, ProtocolNoticeNotifyPokeEvent, ProtocolNoticeNotifyPokeEventCommon, ProtocolNoticeNotifyProfileLikeEvent, ProtocolReadableStream, ProtocolReply, ProtocolReplyFailed, ProtocolReplyOk, ProtocolReplyStream, ProtocolReplyStreamResponse, ProtocolRequest, ProtocolRequestEvent, ProtocolRequestEventCommon, ProtocolStreamCompleteMessage, ProtocolStreamDataMessage, ProtocolStreamErrorMessage, ProtocolStreamMessage, PubHalf, PubSub, PubSubOff, ReadyState, SubHalf, SubOff, Transport, TransportCommon, TransportEventHandlers, TransportFactory, open };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{i as e}from"./value-DBEEtS4k.mjs";var t=class{listeners=new Map;constructor(e,t){this.onerror=e,this._uncaughtEvents=t,this.onerror=e}_inner(e,t){let n=this.listeners.get(e);if(!n){if(!t)return;n=new Set,this.listeners.set(e,n)}return n}on(t,...n){let r=this._inner(t,!0);if(n.length===0)return e;if(n.length===1)return r.add(n[0]),()=>r.delete(n[0]);for(let e of n)r.add(e);return()=>{this.off(t,...n)}}off(e,...t){let n=this._inner(e);if(n){if(t.length===0)return!1;if(t.length===1)return n.delete(t[0]);{let e=!0;for(let r of t)e&&=n.delete(r);return e}}}emit(e,...t){let n=this._inner(e);if(n){let r=Promise.resolve();for(let i of n)r.then(()=>i(...t)).catch(this._uncaughtEvents?.includes(e)?null:this.onerror)}}},n=class extends t{_transport;_disposeTransportEvents;_reconnectAttempts=0;_reconnectTimer;_manualClose=!1;_isReconnecting=!1;_callbacks=new Map;_streams=new Map;constructor(e){super(e=>this._handleError(e),[`connection.error`]),this._options=e}get transport(){if(!this._transport)throw Error(`Transport not connected`);return this._transport}async connect(){this._manualClose=!1,await this._connect()}_handleError(e){this.emit(`connection.error`,e,this)}async _connect(e=!1){try{let t=await this._options.transport(this._options.token??``);this._transport=t,e&&this.emit(`connection.reconnect`,this._transport,this),this._bindTransportEvents(t)}catch(e){throw this._handleError(e),e}}_createStream(e){let t={resolve:null,reject:null},n=new Promise((e,n)=>{t.resolve=e,t.reject=n});return[new ReadableStream({start:n=>{this._streams.set(e,{enqueue:e=>n.enqueue(e),raise:e=>{t.reject?.(e),n.error(e)},complete:e=>{t.resolve?.(e),n.close()},close:()=>n.close()})},cancel:()=>{this._streams.delete(e),t.reject?.(Error(`Stream canceled`))}}),n]}request(e,t,n){return new Promise((r,i)=>{let a=crypto.randomUUID(),o={action:e,params:t,echo:a,stream:n?`stream-action`:`normal-action`};if(n){let e=this._createStream(a);try{this.emit(`connection.request`,o,this),this.transport.send(JSON.stringify(o)),r(e)}catch(e){this._streams.delete(a),this._handleError(e),i(e)}return}let s=setTimeout(()=>{if(this._callbacks.has(a)){this._callbacks.delete(a);let t=Error(`API Request Timeout: ${e}`);this._handleError(t),i(t)}},this._options.timeout);this._callbacks.set(a,{resolve:r,reject:i,timer:s});try{this.emit(`connection.request`,o,this),this.transport.send(JSON.stringify(o))}catch(e){clearTimeout(s),this._callbacks.delete(a),this._handleError(e),i(e)}})}_bindTransportEvents(e){this._disposeTransportEvents?.();let t=()=>{this.emit(`connection.connected`,e,this),this._isReconnecting&&(this._isReconnecting=!1,this._reconnectAttempts=0,clearTimeout(this._reconnectTimer))},n=e=>{let t=typeof e.data==`string`?(()=>{try{return JSON.parse(e.data)}catch{return null}})():e.data;t&&this._handleMessage(t)},r=e=>{this.emit(`connection.error`,e,this)},i=()=>{this._disposeTransportEvents?.(),this._disposeTransportEvents=void 0,this.emit(`connection.disconnected`,e,this),this._transport=void 0;for(let[e,{raise:t}]of this._streams)t(Error(`Connection closed`));this._streams.clear();for(let[e,{reject:t,timer:n}]of this._callbacks)clearTimeout(n),t(Error(`Connection closed`));this._callbacks.clear(),this._manualClose||this._scheduleReconnect()};e.addEventListener(`open`,t),e.addEventListener(`message`,n),e.addEventListener(`error`,r),e.addEventListener(`close`,i),e.readyState===1&&t(),this._disposeTransportEvents=()=>{e.removeEventListener(`open`,t),e.removeEventListener(`message`,n),e.removeEventListener(`error`,r),e.removeEventListener(`close`,i)}}_handleMessage(e){if(e){if(e.echo){if(this.emit(`connection.reply`,e,this),e.stream===`stream-action`){this.emit(`connection.reply.stream`,e,this);let t=this._streams.get(e.echo);if(!t)return;let n=e;n.status===`ok`?n.data.type===`stream`&&n.data.data_type===`data_chunk`?t.enqueue(n.data):n.data.type===`response`&&n.data.data_type===`data_complete`&&(this._streams.delete(e.echo),t.complete(n.data)):n.status===`failed`&&(this._streams.delete(e.echo),t.raise(Error(`Stream Error: ${n.message||`code ${n.retcode}`}`)));return}let t=this._callbacks.get(e.echo);if(t){clearTimeout(t.timer),this._callbacks.delete(e.echo),e.status===`ok`?t.resolve(e.data):t.reject(Error(`Request Error: ${e.message||`code ${e.retcode}`}`));return}}e.post_type&&this.emit(`protocol.event`,e,this)}}_scheduleReconnect(){let{reconnect:e}=this._options;if(!e||this._manualClose)return;let{attempts:t,interval:n}=e;if(t!==`always`&&this._reconnectAttempts>=t)return this.emit(`connection.error`,Error(`Reconnect failed`),this);this._isReconnecting=!0,this._reconnectAttempts++,this._reconnectTimer&&clearTimeout(this._reconnectTimer),this._reconnectTimer=setTimeout(()=>{this._connect(!0).catch(()=>{this._scheduleReconnect()})},n)}close(){this._manualClose=!0,this._disposeTransportEvents?.(),this._transport?.close()}[Symbol.dispose](){this.close()}};const r=function(e,t){return typeof e==`function`&&(e={transport:e,token:t}),e.reconnect??={interval:15e3,attempts:5},e.timeout??=3e4,new n(e)};export{r as open};
1
+ import{i as e}from"./value-DBEEtS4k.mjs";var t=class{listeners=new Map;constructor(e,t){this.onerror=e,this._uncaughtEvents=t,this.onerror=e}_inner(e,t){let n=this.listeners.get(e);if(!n){if(!t)return;n=new Set,this.listeners.set(e,n)}return n}on(t,...n){let r=this._inner(t,!0);if(n.length===0)return e;if(n.length===1)return r.add(n[0]),()=>r.delete(n[0]);for(let e of n)r.add(e);return()=>{this.off(t,...n)}}off(e,...t){let n=this._inner(e);if(n){if(t.length===0)return!1;if(t.length===1)return n.delete(t[0]);{let e=!0;for(let r of t)e&&=n.delete(r);return e}}}emit(e,...t){let n=this._inner(e);if(n){let r=Promise.resolve();for(let i of n)r.then(()=>i(...t)).catch(this._uncaughtEvents?.has(e)?null:this.onerror)}}},n=class extends t{_transport;_disposeTransportEvents;_reconnectAttempts=0;_reconnectTimer;_manualClose=!1;_isReconnecting=!1;_callbacks=new Map;_streams=new Map;constructor(e){super(e=>this._handleError(e),new Set([`connection.error`])),this._options=e}get transport(){if(!this._transport)throw Error(`Transport not connected`);return this._transport}async connect(){this._manualClose=!1,await this._connect()}_handleError(e){this.emit(`connection.error`,e,this)}async _connect(e=!1){try{let t=await this._options.transport(this._options.token??``);this._transport=t,e&&this.emit(`connection.reconnect`,this._transport,this),this._bindTransportEvents(t)}catch(e){throw this._handleError(e),e}}_createStream(e){let t={resolve:null,reject:null},n=new Promise((e,n)=>{t.resolve=e,t.reject=n});return[new ReadableStream({start:n=>{this._streams.set(e,{enqueue:e=>n.enqueue(e),raise:e=>{t.reject?.(e),n.error(e)},complete:e=>{t.resolve?.(e),n.close()},close:()=>n.close()})},cancel:()=>{this._streams.delete(e),t.reject?.(Error(`Stream canceled`))}}),n]}request(e,t,n){return new Promise((r,i)=>{let a=crypto.randomUUID(),o={action:e,params:t,echo:a,stream:n?`stream-action`:`normal-action`};if(n){let e=this._createStream(a);try{this.emit(`connection.request`,o,this),this.transport.send(JSON.stringify(o)),r(e)}catch(e){this._streams.delete(a),this._handleError(e),i(e)}return}let s=setTimeout(()=>{if(this._callbacks.has(a)){this._callbacks.delete(a);let t=Error(`API Request Timeout: ${e}`);this._handleError(t),i(t)}},this._options.timeout);this._callbacks.set(a,{resolve:r,reject:i,timer:s});try{this.emit(`connection.request`,o,this),this.transport.send(JSON.stringify(o))}catch(e){clearTimeout(s),this._callbacks.delete(a),this._handleError(e),i(e)}})}_bindTransportEvents(e){this._disposeTransportEvents?.();let t=()=>{this.emit(`connection.connected`,e,this),this._isReconnecting&&(this._isReconnecting=!1,this._reconnectAttempts=0,clearTimeout(this._reconnectTimer))},n=e=>{let t=typeof e.data==`string`?(()=>{try{return JSON.parse(e.data)}catch{return null}})():e.data;t&&this._handleMessage(t)},r=e=>{this.emit(`connection.error`,e,this)},i=()=>{this._disposeTransportEvents?.(),this._disposeTransportEvents=void 0,this.emit(`connection.disconnected`,e,this),this._transport=void 0;for(let[e,{raise:t}]of this._streams)t(Error(`Connection closed`));this._streams.clear();for(let[e,{reject:t,timer:n}]of this._callbacks)clearTimeout(n),t(Error(`Connection closed`));this._callbacks.clear(),this._manualClose||this._scheduleReconnect()};e.addEventListener(`open`,t),e.addEventListener(`message`,n),e.addEventListener(`error`,r),e.addEventListener(`close`,i),e.readyState===1&&t(),this._disposeTransportEvents=()=>{e.removeEventListener(`open`,t),e.removeEventListener(`message`,n),e.removeEventListener(`error`,r),e.removeEventListener(`close`,i)}}_handleMessage(e){if(e){if(e.echo){if(this.emit(`connection.reply`,e,this),e.stream===`stream-action`){this.emit(`connection.reply.stream`,e,this);let t=this._streams.get(e.echo);if(!t)return;let n=e;n.status===`ok`?n.data.type===`stream`&&n.data.data_type===`data_chunk`?t.enqueue(n.data):n.data.type===`response`&&n.data.data_type===`data_complete`&&(this._streams.delete(e.echo),t.complete(n.data)):n.status===`failed`&&(this._streams.delete(e.echo),t.raise(Error(`Stream Error: ${n.message||`code ${n.retcode}`}`)));return}let t=this._callbacks.get(e.echo);if(t){clearTimeout(t.timer),this._callbacks.delete(e.echo),e.status===`ok`?t.resolve(e.data):t.reject(Error(`Request Error: ${e.message||`code ${e.retcode}`}`));return}}e.post_type&&this.emit(`protocol.event`,e,this)}}_scheduleReconnect(){let{reconnect:e}=this._options;if(!e||this._manualClose)return;let{attempts:t,interval:n}=e;if(t!==`always`&&this._reconnectAttempts>=t)return this.emit(`connection.error`,Error(`Reconnect failed`),this);this._isReconnecting=!0,this._reconnectAttempts++,this._reconnectTimer&&clearTimeout(this._reconnectTimer),this._reconnectTimer=setTimeout(()=>{this._connect(!0).catch(()=>{this._scheduleReconnect()})},n)}close(){this._manualClose=!0,this._disposeTransportEvents?.(),this._transport?.close()}[Symbol.dispose](){this.close()}};const r=function(e,t){return typeof e==`function`&&(e={transport:e,token:t}),e.reconnect??={interval:15e3,attempts:5},e.timeout??=3e4,new n(e)};export{r as open};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/utils/pubsub.ts","../src/connection/index.ts"],"sourcesContent":["import type { PubSubOff } from '@/types/pubsub'\nimport { noop } from './value'\n\nexport class PubSubImpl<T extends Record<string, any[]> = Record<string, any[]>> implements PubSubOff<T> {\n private readonly listeners = new Map<keyof T, Set<(...args: any[]) => any>>()\n\n constructor(private onerror?: (error: Error) => void, private _uncaughtEvents?: (keyof T)[]) {\n this.onerror = onerror\n }\n\n private _inner(type: keyof T, create?: boolean) {\n let listeners = this.listeners.get(type)\n if (!listeners) {\n if (!create) {\n return\n }\n listeners = new Set()\n this.listeners.set(type, listeners)\n }\n return listeners\n }\n\n on<const K extends keyof T>(type: K, ...listeners: Array<(...args: T[K]) => void>) {\n const inner = this._inner(type, true)!\n if (listeners.length === 0) {\n return noop\n }\n else if (listeners.length === 1) {\n inner.add(listeners[0]!)\n return () => inner.delete(listeners[0]!)\n }\n else {\n for (const fn of listeners) {\n inner.add(fn)\n }\n return () => {\n this.off(type, ...listeners)\n }\n }\n }\n\n off(type: keyof T, ...listeners: Array<(...args: any[]) => any>) {\n const inner = this._inner(type)\n if (inner) {\n if (listeners.length === 0) {\n return false\n }\n else if (listeners.length === 1) {\n return inner.delete(listeners[0]!)\n }\n else {\n let success = true\n for (const listener of listeners) {\n success &&= inner.delete(listener)\n }\n return success\n }\n }\n }\n\n emit<const K extends keyof T>(type: K, ...args: T[K]) {\n const listeners = this._inner(type)\n if (listeners) {\n const p = Promise.resolve()\n for (const listener of listeners) {\n p.then(() => listener(...args))\n .catch(this._uncaughtEvents?.includes(type) ? null : this.onerror)\n }\n }\n }\n}\n","import type { Dispose } from '@/types/common'\nimport type { Connection, ConnectionBasicPubSubHandlers, OpenConnection, OpenConnectionOptions, TransportFactory } from '@/types/connection'\nimport type { ProtocolReadableStream, ProtocolReplyStream, ProtocolRequest, ProtocolStreamCompleteMessage } from '@/types/protocol'\nimport type { Transport } from '@/types/transport'\nimport { PubSubImpl } from '@/utils/pubsub'\n\nexport class ConnectionImpl extends PubSubImpl<ConnectionBasicPubSubHandlers> implements Connection {\n private _transport: Transport | undefined\n private _disposeTransportEvents: Dispose | undefined\n private _reconnectAttempts = 0\n private _reconnectTimer: any | undefined\n private _manualClose = false\n private _isReconnecting = false\n private _callbacks = new Map<string, { resolve: (data: any) => void, reject: (err: any) => void, timer: NodeJS.Timeout }>()\n private _streams = new Map<string, { enqueue: (data: any) => void, raise: (err: any) => void, complete: (value: any) => void, close: () => void }>()\n\n constructor(private readonly _options: OpenConnectionOptions) {\n super(err => this._handleError(err), ['connection.error'])\n }\n\n get transport(): Transport {\n if (!this._transport) {\n throw new Error('Transport not connected')\n }\n return this._transport\n }\n\n async connect(): Promise<void> {\n this._manualClose = false\n await this._connect()\n }\n\n private _handleError(error: any) {\n this.emit('connection.error', error, this)\n }\n\n private async _connect(reconnecting = false): Promise<void> {\n try {\n const transportOrPromise = this._options.transport(this._options.token ?? '')\n const transport = await transportOrPromise\n this._transport = transport\n if (reconnecting) {\n this.emit('connection.reconnect', this._transport, this)\n }\n this._bindTransportEvents(transport)\n }\n catch (error) {\n this._handleError(error)\n throw error\n }\n }\n\n private _createStream(echo: string): [ReadableStream<any>, Promise<any>] {\n const deferred = { resolve: null, reject: null } as any\n const promise = new Promise<any>((res, rej) => {\n deferred.resolve = res\n deferred.reject = rej\n })\n\n return [new ReadableStream<any>({\n start: (controller) => {\n this._streams.set(echo, {\n enqueue: data => controller.enqueue(data),\n raise: (err) => {\n deferred.reject?.(err)\n controller.error(err)\n },\n complete: (value) => {\n deferred.resolve?.(value)\n controller.close()\n },\n close: () => controller.close(),\n })\n },\n cancel: () => {\n this._streams.delete(echo)\n deferred.reject?.(new Error('Stream canceled'))\n },\n }), promise]\n }\n\n request<const P, R = any>(method: string, args: P, stream?: false): Promise<R>\n request<const P, R = any>(method: string, args: P, stream: true): Promise<[ProtocolReadableStream, Promise<ProtocolStreamCompleteMessage<R>>]>\n request<P, R = any>(method: string, args?: P, stream?: boolean): Promise<R> | Promise<[ProtocolReadableStream, Promise<ProtocolStreamCompleteMessage<R>>]> {\n return new Promise<any>((resolve, reject) => {\n const echo = crypto.randomUUID()\n const request: ProtocolRequest = {\n action: method,\n params: args,\n echo,\n stream: stream ? 'stream-action' : 'normal-action',\n }\n\n if (stream) {\n const result = this._createStream(echo)\n try {\n this.emit('connection.request', request, this)\n this.transport.send(JSON.stringify(request))\n resolve(result)\n }\n catch (error) {\n this._streams.delete(echo)\n this._handleError(error)\n reject(error)\n }\n return\n }\n\n const timer = setTimeout(() => {\n if (this._callbacks.has(echo)) {\n this._callbacks.delete(echo)\n const error = new Error(`API Request Timeout: ${method}`)\n\n this._handleError(error)\n reject(error)\n }\n }, this._options.timeout)\n\n this._callbacks.set(echo, { resolve, reject, timer })\n\n try {\n this.emit('connection.request', request, this)\n this.transport.send(JSON.stringify(request))\n }\n catch (error) {\n clearTimeout(timer)\n this._callbacks.delete(echo)\n this._handleError(error)\n reject(error)\n }\n })\n }\n\n private _bindTransportEvents(transport: Transport) {\n this._disposeTransportEvents?.()\n\n const onOpen = () => {\n this.emit('connection.connected', transport, this)\n if (this._isReconnecting) {\n this._isReconnecting = false\n this._reconnectAttempts = 0\n clearTimeout(this._reconnectTimer)\n }\n }\n\n const onMessage = (event: { data: any }) => {\n const data = typeof event.data === 'string'\n ? (() => {\n try {\n return JSON.parse(event.data)\n }\n catch {\n return null\n }\n })()\n : event.data\n\n if (data) {\n this._handleMessage(data)\n }\n }\n\n const onError = (error: any) => {\n this.emit('connection.error', error, this)\n }\n\n const onClose = () => {\n this._disposeTransportEvents?.()\n this._disposeTransportEvents = undefined\n\n this.emit('connection.disconnected', transport, this)\n this._transport = undefined\n\n // Clear all pending streams\n for (const [_, { raise }] of this._streams) {\n raise(new Error('Connection closed'))\n }\n this._streams.clear()\n\n // Clear all pending requests\n for (const [_, { reject, timer }] of this._callbacks) {\n clearTimeout(timer)\n reject(new Error('Connection closed'))\n }\n this._callbacks.clear()\n\n if (!this._manualClose) {\n this._scheduleReconnect()\n }\n }\n\n transport.addEventListener('open', onOpen)\n transport.addEventListener('message', onMessage)\n transport.addEventListener('error', onError)\n transport.addEventListener('close', onClose)\n\n if (transport.readyState === 1 /* OPEN */) {\n onOpen()\n }\n\n this._disposeTransportEvents = () => {\n transport.removeEventListener('open', onOpen)\n transport.removeEventListener('message', onMessage)\n transport.removeEventListener('error', onError)\n transport.removeEventListener('close', onClose)\n }\n }\n\n private _handleMessage(data: any) {\n if (!data)\n return\n\n // Handle Reply\n if (data.echo) {\n this.emit('connection.reply', data, this)\n if (data.stream === 'stream-action') {\n this.emit('connection.reply.stream', data, this)\n\n const stream = this._streams.get(data.echo)\n if (!stream)\n return\n\n const message = data as ProtocolReplyStream\n if (message.status === 'ok') {\n if (message.data!.type === 'stream' && message.data!.data_type === 'data_chunk') {\n stream.enqueue(message.data!)\n }\n else if (message.data!.type === 'response' && message.data!.data_type === 'data_complete') {\n this._streams.delete(data.echo)\n stream.complete(message.data!)\n }\n }\n else if (message.status === 'failed') {\n this._streams.delete(data.echo)\n stream.raise(new Error(`Stream Error: ${message.message || `code ${message.retcode}`}`))\n }\n return\n }\n\n const pending = this._callbacks.get(data.echo)\n if (pending) {\n clearTimeout(pending.timer)\n this._callbacks.delete(data.echo)\n\n if (data.status === 'ok') {\n pending.resolve(data.data)\n }\n else {\n pending.reject(new Error(`Request Error: ${data.message || `code ${data.retcode}`}`))\n }\n return\n }\n }\n\n // Handle Event\n if (data.post_type) {\n this.emit('protocol.event', data, this)\n }\n }\n\n private _scheduleReconnect() {\n const { reconnect } = this._options\n if (!reconnect || this._manualClose)\n return\n\n const { attempts, interval } = reconnect\n\n if (attempts !== 'always' && this._reconnectAttempts >= attempts) {\n // Reconnect failed\n return this.emit('connection.error', new Error('Reconnect failed'), this)\n }\n\n this._isReconnecting = true\n this._reconnectAttempts++\n\n if (this._reconnectTimer)\n clearTimeout(this._reconnectTimer)\n\n this._reconnectTimer = setTimeout(() => {\n this._connect(true).catch(() => {\n this._scheduleReconnect()\n })\n }, interval)\n }\n\n close() {\n this._manualClose = true\n this._disposeTransportEvents?.()\n this._transport?.close()\n }\n\n [Symbol.dispose]() {\n this.close()\n }\n}\n\nexport const open: OpenConnection = function open(options: OpenConnectionOptions | TransportFactory, token?: string): Connection {\n if (typeof options === 'function') {\n options = { transport: options, token }\n }\n\n options.reconnect ??= {\n interval: 15000,\n attempts: 5,\n }\n\n options.timeout ??= 30000\n\n const conn = new ConnectionImpl(options)\n return conn\n}\n"],"mappings":"yCAGA,IAAa,EAAb,KAAyG,CACvG,UAA6B,IAAI,IAEjC,YAAY,EAA0C,EAAuC,CAAzE,KAAA,QAAA,EAA0C,KAAA,gBAAA,EAC5D,KAAK,QAAU,EAGjB,OAAe,EAAe,EAAkB,CAC9C,IAAI,EAAY,KAAK,UAAU,IAAI,EAAK,CACxC,GAAI,CAAC,EAAW,CACd,GAAI,CAAC,EACH,OAEF,EAAY,IAAI,IAChB,KAAK,UAAU,IAAI,EAAM,EAAU,CAErC,OAAO,EAGT,GAA4B,EAAS,GAAG,EAA2C,CACjF,IAAM,EAAQ,KAAK,OAAO,EAAM,GAAK,CACrC,GAAI,EAAU,SAAW,EACvB,OAAO,KAEA,EAAU,SAAW,EAE5B,OADA,EAAM,IAAI,EAAU,GAAI,KACX,EAAM,OAAO,EAAU,GAAI,CAGxC,IAAK,IAAM,KAAM,EACf,EAAM,IAAI,EAAG,CAEf,UAAa,CACX,KAAK,IAAI,EAAM,GAAG,EAAU,EAKlC,IAAI,EAAe,GAAG,EAA2C,CAC/D,IAAM,EAAQ,KAAK,OAAO,EAAK,CAC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AK,iBACP,aAAa,KAAK,gBAAgB,CAEpC,KAAK,gBAAkB,eAAiB,CACtC,KAAK,SAAS,GAAK,CAAC,UAAY,CAC9B,KAAK,oBAAoB,EACzB,EACD,EAAS,CAGd,OAAQ,CACN,KAAK,aAAe,GACpB,KAAK,2BAA2B,CAChC,KAAK,YAAY,OAAO,CAG1B,CAAC,OAAO,UAAW,CACjB,KAAK,OAAO,GAIhB,MAAa,EAAuB,SAAc,EAAmD,EAA4B,CAa/H,OAZI,OAAO,GAAY,aACrB,EAAU,CAAE,UAAW,EAAS,QAAO,EAGzC,EAAQ,YAAc,CACpB,SAAU,KACV,SAAU,EACX,CAED,EAAQ,UAAY,IAEP,IAAI,EAAe,EAAQ"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/utils/pubsub.ts","../src/connection/index.ts"],"sourcesContent":["import type { PubSubOff } from '@/types/pubsub'\nimport { noop } from './value'\n\nexport class PubSubImpl<T extends Record<string, any[]> = Record<string, any[]>> implements PubSubOff<T> {\n private readonly listeners = new Map<keyof T, Set<(...args: any[]) => any>>()\n\n constructor(private onerror?: (error: Error) => void, private _uncaughtEvents?: Set<keyof T>) {\n this.onerror = onerror\n }\n\n private _inner(type: keyof T, create?: boolean) {\n let listeners = this.listeners.get(type)\n if (!listeners) {\n if (!create) {\n return\n }\n listeners = new Set()\n this.listeners.set(type, listeners)\n }\n return listeners\n }\n\n on<const K extends keyof T>(type: K, ...listeners: Array<(...args: T[K]) => void>) {\n const inner = this._inner(type, true)!\n if (listeners.length === 0) {\n return noop\n }\n else if (listeners.length === 1) {\n inner.add(listeners[0]!)\n return () => inner.delete(listeners[0]!)\n }\n else {\n for (const fn of listeners) {\n inner.add(fn)\n }\n return () => {\n this.off(type, ...listeners)\n }\n }\n }\n\n off(type: keyof T, ...listeners: Array<(...args: any[]) => any>) {\n const inner = this._inner(type)\n if (inner) {\n if (listeners.length === 0) {\n return false\n }\n else if (listeners.length === 1) {\n return inner.delete(listeners[0]!)\n }\n else {\n let success = true\n for (const listener of listeners) {\n success &&= inner.delete(listener)\n }\n return success\n }\n }\n }\n\n emit<const K extends keyof T>(type: K, ...args: T[K]) {\n const listeners = this._inner(type)\n if (listeners) {\n const p = Promise.resolve()\n for (const listener of listeners) {\n p.then(() => listener(...args))\n .catch(this._uncaughtEvents?.has(type) ? null : this.onerror)\n }\n }\n }\n}\n","import type { Dispose } from '@/types/common'\nimport type { Connection, ConnectionBasicPubSubHandlers, OpenConnection, OpenConnectionOptions, TransportFactory } from '@/types/connection'\nimport type { ProtocolReadableStream, ProtocolReplyStream, ProtocolRequest, ProtocolStreamCompleteMessage } from '@/types/protocol'\nimport type { Transport } from '@/types/transport'\nimport { PubSubImpl } from '@/utils/pubsub'\n\nexport class ConnectionImpl extends PubSubImpl<ConnectionBasicPubSubHandlers> implements Connection {\n private _transport: Transport | undefined\n private _disposeTransportEvents: Dispose | undefined\n private _reconnectAttempts = 0\n private _reconnectTimer: any | undefined\n private _manualClose = false\n private _isReconnecting = false\n private _callbacks = new Map<string, { resolve: (data: any) => void, reject: (err: any) => void, timer: NodeJS.Timeout }>()\n private _streams = new Map<string, { enqueue: (data: any) => void, raise: (err: any) => void, complete: (value: any) => void, close: () => void }>()\n\n constructor(private readonly _options: OpenConnectionOptions) {\n super(err => this._handleError(err), new Set(['connection.error']))\n }\n\n get transport(): Transport {\n if (!this._transport) {\n throw new Error('Transport not connected')\n }\n return this._transport\n }\n\n async connect(): Promise<void> {\n this._manualClose = false\n await this._connect()\n }\n\n private _handleError(error: any) {\n this.emit('connection.error', error, this)\n }\n\n private async _connect(reconnecting = false): Promise<void> {\n try {\n const transportOrPromise = this._options.transport(this._options.token ?? '')\n const transport = await transportOrPromise\n this._transport = transport\n if (reconnecting) {\n this.emit('connection.reconnect', this._transport, this)\n }\n this._bindTransportEvents(transport)\n }\n catch (error) {\n this._handleError(error)\n throw error\n }\n }\n\n private _createStream(echo: string): [ReadableStream<any>, Promise<any>] {\n const deferred = { resolve: null, reject: null } as any\n const promise = new Promise<any>((res, rej) => {\n deferred.resolve = res\n deferred.reject = rej\n })\n\n return [new ReadableStream<any>({\n start: (controller) => {\n this._streams.set(echo, {\n enqueue: data => controller.enqueue(data),\n raise: (err) => {\n deferred.reject?.(err)\n controller.error(err)\n },\n complete: (value) => {\n deferred.resolve?.(value)\n controller.close()\n },\n close: () => controller.close(),\n })\n },\n cancel: () => {\n this._streams.delete(echo)\n deferred.reject?.(new Error('Stream canceled'))\n },\n }), promise]\n }\n\n request<const P, R = any>(method: string, args: P, stream?: false): Promise<R>\n request<const P, R = any>(method: string, args: P, stream: true): Promise<[ProtocolReadableStream, Promise<ProtocolStreamCompleteMessage<R>>]>\n request<P, R = any>(method: string, args?: P, stream?: boolean): Promise<R> | Promise<[ProtocolReadableStream, Promise<ProtocolStreamCompleteMessage<R>>]> {\n return new Promise<any>((resolve, reject) => {\n const echo = crypto.randomUUID()\n const request: ProtocolRequest = {\n action: method,\n params: args,\n echo,\n stream: stream ? 'stream-action' : 'normal-action',\n }\n\n if (stream) {\n const result = this._createStream(echo)\n try {\n this.emit('connection.request', request, this)\n this.transport.send(JSON.stringify(request))\n resolve(result)\n }\n catch (error) {\n this._streams.delete(echo)\n this._handleError(error)\n reject(error)\n }\n return\n }\n\n const timer = setTimeout(() => {\n if (this._callbacks.has(echo)) {\n this._callbacks.delete(echo)\n const error = new Error(`API Request Timeout: ${method}`)\n\n this._handleError(error)\n reject(error)\n }\n }, this._options.timeout)\n\n this._callbacks.set(echo, { resolve, reject, timer })\n\n try {\n this.emit('connection.request', request, this)\n this.transport.send(JSON.stringify(request))\n }\n catch (error) {\n clearTimeout(timer)\n this._callbacks.delete(echo)\n this._handleError(error)\n reject(error)\n }\n })\n }\n\n private _bindTransportEvents(transport: Transport) {\n this._disposeTransportEvents?.()\n\n const onOpen = () => {\n this.emit('connection.connected', transport, this)\n if (this._isReconnecting) {\n this._isReconnecting = false\n this._reconnectAttempts = 0\n clearTimeout(this._reconnectTimer)\n }\n }\n\n const onMessage = (event: { data: any }) => {\n const data = typeof event.data === 'string'\n ? (() => {\n try {\n return JSON.parse(event.data)\n }\n catch {\n return null\n }\n })()\n : event.data\n\n if (data) {\n this._handleMessage(data)\n }\n }\n\n const onError = (error: any) => {\n this.emit('connection.error', error, this)\n }\n\n const onClose = () => {\n this._disposeTransportEvents?.()\n this._disposeTransportEvents = undefined\n\n this.emit('connection.disconnected', transport, this)\n this._transport = undefined\n\n // Clear all pending streams\n for (const [_, { raise }] of this._streams) {\n raise(new Error('Connection closed'))\n }\n this._streams.clear()\n\n // Clear all pending requests\n for (const [_, { reject, timer }] of this._callbacks) {\n clearTimeout(timer)\n reject(new Error('Connection closed'))\n }\n this._callbacks.clear()\n\n if (!this._manualClose) {\n this._scheduleReconnect()\n }\n }\n\n transport.addEventListener('open', onOpen)\n transport.addEventListener('message', onMessage)\n transport.addEventListener('error', onError)\n transport.addEventListener('close', onClose)\n\n if (transport.readyState === 1 /* OPEN */) {\n onOpen()\n }\n\n this._disposeTransportEvents = () => {\n transport.removeEventListener('open', onOpen)\n transport.removeEventListener('message', onMessage)\n transport.removeEventListener('error', onError)\n transport.removeEventListener('close', onClose)\n }\n }\n\n private _handleMessage(data: any) {\n if (!data)\n return\n\n // Handle Reply\n if (data.echo) {\n this.emit('connection.reply', data, this)\n if (data.stream === 'stream-action') {\n this.emit('connection.reply.stream', data, this)\n\n const stream = this._streams.get(data.echo)\n if (!stream)\n return\n\n const message = data as ProtocolReplyStream\n if (message.status === 'ok') {\n if (message.data!.type === 'stream' && message.data!.data_type === 'data_chunk') {\n stream.enqueue(message.data!)\n }\n else if (message.data!.type === 'response' && message.data!.data_type === 'data_complete') {\n this._streams.delete(data.echo)\n stream.complete(message.data!)\n }\n }\n else if (message.status === 'failed') {\n this._streams.delete(data.echo)\n stream.raise(new Error(`Stream Error: ${message.message || `code ${message.retcode}`}`))\n }\n return\n }\n\n const pending = this._callbacks.get(data.echo)\n if (pending) {\n clearTimeout(pending.timer)\n this._callbacks.delete(data.echo)\n\n if (data.status === 'ok') {\n pending.resolve(data.data)\n }\n else {\n pending.reject(new Error(`Request Error: ${data.message || `code ${data.retcode}`}`))\n }\n return\n }\n }\n\n // Handle Event\n if (data.post_type) {\n this.emit('protocol.event', data, this)\n }\n }\n\n private _scheduleReconnect() {\n const { reconnect } = this._options\n if (!reconnect || this._manualClose)\n return\n\n const { attempts, interval } = reconnect\n\n if (attempts !== 'always' && this._reconnectAttempts >= attempts) {\n // Reconnect failed\n return this.emit('connection.error', new Error('Reconnect failed'), this)\n }\n\n this._isReconnecting = true\n this._reconnectAttempts++\n\n if (this._reconnectTimer)\n clearTimeout(this._reconnectTimer)\n\n this._reconnectTimer = setTimeout(() => {\n this._connect(true).catch(() => {\n this._scheduleReconnect()\n })\n }, interval)\n }\n\n close() {\n this._manualClose = true\n this._disposeTransportEvents?.()\n this._transport?.close()\n }\n\n [Symbol.dispose]() {\n this.close()\n }\n}\n\nexport const open: OpenConnection = function open(options: OpenConnectionOptions | TransportFactory, token?: string): Connection {\n if (typeof options === 'function') {\n options = { transport: options, token }\n }\n\n options.reconnect ??= {\n interval: 15000,\n attempts: 5,\n }\n\n options.timeout ??= 30000\n\n const conn = new ConnectionImpl(options)\n return conn\n}\n"],"mappings":"yCAGA,IAAa,EAAb,KAAyG,CACvG,UAA6B,IAAI,IAEjC,YAAY,EAA0C,EAAwC,CAA1E,KAAA,QAAA,EAA0C,KAAA,gBAAA,EAC5D,KAAK,QAAU,EAGjB,OAAe,EAAe,EAAkB,CAC9C,IAAI,EAAY,KAAK,UAAU,IAAI,EAAK,CACxC,GAAI,CAAC,EAAW,CACd,GAAI,CAAC,EACH,OAEF,EAAY,IAAI,IAChB,KAAK,UAAU,IAAI,EAAM,EAAU,CAErC,OAAO,EAGT,GAA4B,EAAS,GAAG,EAA2C,CACjF,IAAM,EAAQ,KAAK,OAAO,EAAM,GAAK,CACrC,GAAI,EAAU,SAAW,EACvB,OAAO,KAEA,EAAU,SAAW,EAE5B,OADA,EAAM,I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AAM,CAAE,aAAc,KAAK,SAC3B,GAAI,CAAC,GAAa,KAAK,aACrB,OAEF,GAAM,CAAE,WAAU,YAAa,EAE/B,GAAI,IAAa,UAAY,KAAK,oBAAsB,EAEtD,OAAO,KAAK,KAAK,mBAAwB,MAAM,mBAAmB,CAAE,KAAK,CAG3E,KAAK,gBAAkB,GACvB,KAAK,qBAED,KAAK,iBACP,aAAa,KAAK,gBAAgB,CAEpC,KAAK,gBAAkB,eAAiB,CACtC,KAAK,SAAS,GAAK,CAAC,UAAY,CAC9B,KAAK,oBAAoB,EACzB,EACD,EAAS,CAGd,OAAQ,CACN,KAAK,aAAe,GACpB,KAAK,2BAA2B,CAChC,KAAK,YAAY,OAAO,CAG1B,CAAC,OAAO,UAAW,CACjB,KAAK,OAAO,GAIhB,MAAa,EAAuB,SAAc,EAAmD,EAA4B,CAa/H,OAZI,OAAO,GAAY,aACrB,EAAU,CAAE,UAAW,EAAS,QAAO,EAGzC,EAAQ,YAAc,CACpB,SAAU,KACV,SAAU,EACX,CAED,EAAQ,UAAY,IAEP,IAAI,EAAe,EAAQ"}
@@ -1,4 +1,4 @@
1
- import { Ft as ProtocolMessageDiceSendSegment, Gt as ProtocolMessageLocationSegment, Ht as ProtocolMessageImageSendSegment, It as ProtocolMessageFaceSegment, Jt as ProtocolMessageMiniAppSegment, Kt as ProtocolMessageMarkdownSegment, Mt as ProtocolMessageContactSendSegment, Qt as ProtocolMessageOnlineFileSegment, Rt as ProtocolMessageFileSendSegment, Wt as ProtocolMessageJsonSendSegment, Xt as ProtocolMessageMusicSendSegment, _n as Numeric, an as ProtocolMessageReplySegment, en as ProtocolMessagePokeSendSegment, fn as ProtocolMessageVideoSendSegment, jt as ProtocolMessageAtSegment, nn as ProtocolMessageRecordSendSegment, pn as ProtocolMessageXmlSegment, qt as ProtocolMessageMfaceSendSegment, sn as ProtocolMessageRpsSendSegment, un as ProtocolMessageTextSegment, zt as ProtocolMessageFlashTransferSegment } from "../index-xpa8wXI0.mjs";
1
+ import { Ft as ProtocolMessageDiceSendSegment, Gt as ProtocolMessageLocationSegment, Ht as ProtocolMessageImageSendSegment, It as ProtocolMessageFaceSegment, Jt as ProtocolMessageMiniAppSegment, Kt as ProtocolMessageMarkdownSegment, Mt as ProtocolMessageContactSendSegment, Qt as ProtocolMessageOnlineFileSegment, Rt as ProtocolMessageFileSendSegment, Wt as ProtocolMessageJsonSendSegment, Xt as ProtocolMessageMusicSendSegment, _n as Numeric, an as ProtocolMessageReplySegment, en as ProtocolMessagePokeSendSegment, fn as ProtocolMessageVideoSendSegment, jt as ProtocolMessageAtSegment, nn as ProtocolMessageRecordSendSegment, pn as ProtocolMessageXmlSegment, qt as ProtocolMessageMfaceSendSegment, sn as ProtocolMessageRpsSendSegment, un as ProtocolMessageTextSegment, zt as ProtocolMessageFlashTransferSegment } from "../index-VGBoCdDT.mjs";
2
2
 
3
3
  //#region src/utils/builder.d.ts
4
4
  declare namespace builder_d_exports {
@@ -1,4 +1,4 @@
1
- import { C as ProtocolReplyOk, N as ProtocolEventHandlers, _n as Numeric, a as ConnectionStreamResult, c as ProtocolEventHandler, cn as ProtocolMessageSegment, hn as MaybeArray, ln as ProtocolMessageSendSegment, n as Connection, r as ConnectionBasicPubSubHandlers } from "../index-xpa8wXI0.mjs";
1
+ import { C as ProtocolReplyOk, N as ProtocolEventHandlers, _n as Numeric, a as ConnectionStreamResult, c as ProtocolEventHandler, cn as ProtocolMessageSegment, hn as MaybeArray, ln as ProtocolMessageSendSegment, n as Connection, r as ConnectionBasicPubSubHandlers } from "../index-VGBoCdDT.mjs";
2
2
  import { t as builder_d_exports } from "./builder.mjs";
3
3
  import { ZodType } from "zod";
4
4
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "napcon",
3
3
  "type": "module",
4
- "version": "0.0.13",
4
+ "version": "0.0.14",
5
5
  "packageManager": "bun@1.3.9",
6
6
  "description": "Lightweight NapCat/Onebot v11 TypeScript library",
7
7
  "license": "LGPL-2.1-or-later",