fastevent 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1095,6 +1095,15 @@ declare class FastEventIterator<T = any> implements AsyncIterableIterator<T> {
1095
1095
  [Symbol.dispose](): void;
1096
1096
  on(): void;
1097
1097
  }
1098
+ /**
1099
+ * 创建一个异步迭代器,从 FastEvent 或 FastEventScope 订阅事件
1100
+ * @param eventEmitter FastEvent 或 FastEventScope 实例
1101
+ * @param eventName 事件名称
1102
+ * @param options 配置选项
1103
+ * @param listenerOptions 监听器配置选项
1104
+ * @returns 异步迭代器
1105
+ */
1106
+ declare function createAsyncEventIterator<T = any>(eventEmitter: FastEvent<any> | FastEventScope<any, any, any>, eventName: string, options?: FastEventIteratorOptions<T>): FastEventIterator<T>;
1098
1107
 
1099
1108
  /**
1100
1109
  * 事件相关
@@ -2019,4 +2028,4 @@ declare function isClass(target: unknown): target is new (...args: any[]) => any
2019
2028
 
2020
2029
  declare function isFastEvent(target: any): target is FastEvent;
2021
2030
 
2022
- export { AbortError, type Add, type AllowCall, type ApplyWildcardEvents, type AssertFastMessage, type AssertRecord, type AssertString, type AtPayloads, CancelError, type ChangeFieldType, type Class, type ClosestMatch, type ContainsWildcard, type Decrement, type DeepPartial, type Dict, type Equal, type Expand, type ExpandRecord, type ExpandWildcard, type ExtendWildcardEvents, type Fallback, FastEvent, type FastEventCommonListener, type FastEventCommonMessage, type FastEventEmitMessage, FastEventError, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, FastEventListenerFlags, type FastEventListenerMeta, type FastEventListenerNode, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListeners, type FastMessagePayload, type FirstObjectItem, type FirstOfUnion, type GetClosestEventName, type GetClosestEventNameTuple, type GetClosestEventPayload, type GetClosestEventTuple, type GetClosestEvents, type GetFixedPartCount, type GetMatchedEventNames, type GetPartCount, type GetPartCountAcc, type GetPayload, type GetWildcardCount, type GetWildcardEventList, type IFastEventScope, type IfNever, type IndexOfMax, type IndexOfMin, type IsAllTransformed, type IsAny, type IsAnyRecord, type IsFullWildcard, type IsMatchEventName, type IsMultiWildcard, type IsNever, type IsSemiWildcard, type IsTransformedEvent, type IsWildcardPart, type Join, type KeyOf, type Keys, type Max, type Merge, type MergeStrings, type MergeUnion, type Min, type MutableMessage, type MutableRecord, type NormalEvents, type NotEqual, type NotPayload, type ObjectKeys, type OmitTransformedEvents, type OptionalKeys, type Overloads, type OverrideOptions, type PayloadValues, type PickEqualRecord, type PickInlcudeDelimiterRecord, type PickNotEqualRecord, type PickNotInlcudeDelimiterRecord, type PickPayload, type PickTransformedEvents, type PrefixNumber, type ProcessSegments, QueueOverflowError, type RemoveEmptyObject, type ReplaceWildcard, type RequiredItems, type RequiredKeys, type ScopeEvents, type Slice, type Split, type SplitPath, type StrictEqual, TimeoutError, type ToFixedCounts, type ToKeyPrioritys, type ToWildcardMessage, type TransformedEvents, type Tuple, type TypedFastEventAnyListener, type TypedFastEventListener, type TypedFastEventMessage, type TypedFastEventMessageOptional, type UnTransformedEvents, UnboundError, type Union, type UnionToIntersection, type Unique, type ValueOf, type WildcardEvents, type WildcardKeyToObject, type WildcardKeys, type WildcardStyle, __FastEventScope__, __FastEvent__, __expandable__, expandable, isClass, type isEmpty, isExpandable, isFastEvent, isFastEventMessage, isFastEventScope, isFunction, isPathMatched, isString, isSubsctiber };
2031
+ export { AbortError, type Add, type AllowCall, type ApplyWildcardEvents, type AssertFastMessage, type AssertRecord, type AssertString, type AtPayloads, CancelError, type ChangeFieldType, type Class, type ClosestMatch, type ContainsWildcard, type Decrement, type DeepPartial, type Dict, type Equal, type Expand, type ExpandRecord, type ExpandWildcard, type ExtendWildcardEvents, type Fallback, FastEvent, type FastEventCommonListener, type FastEventCommonMessage, type FastEventEmitMessage, FastEventError, FastEventIterator, type FastEventIteratorOptions, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, FastEventListenerFlags, type FastEventListenerMeta, type FastEventListenerNode, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListeners, type FastMessagePayload, type FastQueueOverflows, type FirstObjectItem, type FirstOfUnion, type GetClosestEventName, type GetClosestEventNameTuple, type GetClosestEventPayload, type GetClosestEventTuple, type GetClosestEvents, type GetFixedPartCount, type GetMatchedEventNames, type GetPartCount, type GetPartCountAcc, type GetPayload, type GetWildcardCount, type GetWildcardEventList, type IFastEventScope, type IfNever, type IndexOfMax, type IndexOfMin, type IsAllTransformed, type IsAny, type IsAnyRecord, type IsFullWildcard, type IsMatchEventName, type IsMultiWildcard, type IsNever, type IsSemiWildcard, type IsTransformedEvent, type IsWildcardPart, type Join, type KeyOf, type Keys, type Max, type Merge, type MergeStrings, type MergeUnion, type Min, type MutableMessage, type MutableRecord, type NormalEvents, type NotEqual, type NotPayload, type ObjectKeys, type OmitTransformedEvents, type OptionalKeys, type Overloads, type OverrideOptions, type PayloadValues, type PickEqualRecord, type PickInlcudeDelimiterRecord, type PickNotEqualRecord, type PickNotInlcudeDelimiterRecord, type PickPayload, type PickTransformedEvents, type PrefixNumber, type ProcessSegments, QueueOverflowError, type RemoveEmptyObject, type ReplaceWildcard, type RequiredItems, type RequiredKeys, type ScopeEvents, type Slice, type Split, type SplitPath, type StrictEqual, TimeoutError, type ToFixedCounts, type ToKeyPrioritys, type ToWildcardMessage, type TransformedEvents, type Tuple, type TypedFastEventAnyListener, type TypedFastEventListener, type TypedFastEventMessage, type TypedFastEventMessageOptional, type UnTransformedEvents, UnboundError, type Union, type UnionToIntersection, type Unique, type ValueOf, type WildcardEvents, type WildcardKeyToObject, type WildcardKeys, type WildcardStyle, __FastEventScope__, __FastEvent__, __expandable__, createAsyncEventIterator, expandable, isClass, type isEmpty, isExpandable, isFastEvent, isFastEventMessage, isFastEventScope, isFunction, isPathMatched, isString, isSubsctiber };
package/dist/index.d.ts CHANGED
@@ -1095,6 +1095,15 @@ declare class FastEventIterator<T = any> implements AsyncIterableIterator<T> {
1095
1095
  [Symbol.dispose](): void;
1096
1096
  on(): void;
1097
1097
  }
1098
+ /**
1099
+ * 创建一个异步迭代器,从 FastEvent 或 FastEventScope 订阅事件
1100
+ * @param eventEmitter FastEvent 或 FastEventScope 实例
1101
+ * @param eventName 事件名称
1102
+ * @param options 配置选项
1103
+ * @param listenerOptions 监听器配置选项
1104
+ * @returns 异步迭代器
1105
+ */
1106
+ declare function createAsyncEventIterator<T = any>(eventEmitter: FastEvent<any> | FastEventScope<any, any, any>, eventName: string, options?: FastEventIteratorOptions<T>): FastEventIterator<T>;
1098
1107
 
1099
1108
  /**
1100
1109
  * 事件相关
@@ -2019,4 +2028,4 @@ declare function isClass(target: unknown): target is new (...args: any[]) => any
2019
2028
 
2020
2029
  declare function isFastEvent(target: any): target is FastEvent;
2021
2030
 
2022
- export { AbortError, type Add, type AllowCall, type ApplyWildcardEvents, type AssertFastMessage, type AssertRecord, type AssertString, type AtPayloads, CancelError, type ChangeFieldType, type Class, type ClosestMatch, type ContainsWildcard, type Decrement, type DeepPartial, type Dict, type Equal, type Expand, type ExpandRecord, type ExpandWildcard, type ExtendWildcardEvents, type Fallback, FastEvent, type FastEventCommonListener, type FastEventCommonMessage, type FastEventEmitMessage, FastEventError, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, FastEventListenerFlags, type FastEventListenerMeta, type FastEventListenerNode, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListeners, type FastMessagePayload, type FirstObjectItem, type FirstOfUnion, type GetClosestEventName, type GetClosestEventNameTuple, type GetClosestEventPayload, type GetClosestEventTuple, type GetClosestEvents, type GetFixedPartCount, type GetMatchedEventNames, type GetPartCount, type GetPartCountAcc, type GetPayload, type GetWildcardCount, type GetWildcardEventList, type IFastEventScope, type IfNever, type IndexOfMax, type IndexOfMin, type IsAllTransformed, type IsAny, type IsAnyRecord, type IsFullWildcard, type IsMatchEventName, type IsMultiWildcard, type IsNever, type IsSemiWildcard, type IsTransformedEvent, type IsWildcardPart, type Join, type KeyOf, type Keys, type Max, type Merge, type MergeStrings, type MergeUnion, type Min, type MutableMessage, type MutableRecord, type NormalEvents, type NotEqual, type NotPayload, type ObjectKeys, type OmitTransformedEvents, type OptionalKeys, type Overloads, type OverrideOptions, type PayloadValues, type PickEqualRecord, type PickInlcudeDelimiterRecord, type PickNotEqualRecord, type PickNotInlcudeDelimiterRecord, type PickPayload, type PickTransformedEvents, type PrefixNumber, type ProcessSegments, QueueOverflowError, type RemoveEmptyObject, type ReplaceWildcard, type RequiredItems, type RequiredKeys, type ScopeEvents, type Slice, type Split, type SplitPath, type StrictEqual, TimeoutError, type ToFixedCounts, type ToKeyPrioritys, type ToWildcardMessage, type TransformedEvents, type Tuple, type TypedFastEventAnyListener, type TypedFastEventListener, type TypedFastEventMessage, type TypedFastEventMessageOptional, type UnTransformedEvents, UnboundError, type Union, type UnionToIntersection, type Unique, type ValueOf, type WildcardEvents, type WildcardKeyToObject, type WildcardKeys, type WildcardStyle, __FastEventScope__, __FastEvent__, __expandable__, expandable, isClass, type isEmpty, isExpandable, isFastEvent, isFastEventMessage, isFastEventScope, isFunction, isPathMatched, isString, isSubsctiber };
2031
+ export { AbortError, type Add, type AllowCall, type ApplyWildcardEvents, type AssertFastMessage, type AssertRecord, type AssertString, type AtPayloads, CancelError, type ChangeFieldType, type Class, type ClosestMatch, type ContainsWildcard, type Decrement, type DeepPartial, type Dict, type Equal, type Expand, type ExpandRecord, type ExpandWildcard, type ExtendWildcardEvents, type Fallback, FastEvent, type FastEventCommonListener, type FastEventCommonMessage, type FastEventEmitMessage, FastEventError, FastEventIterator, type FastEventIteratorOptions, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, FastEventListenerFlags, type FastEventListenerMeta, type FastEventListenerNode, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListeners, type FastMessagePayload, type FastQueueOverflows, type FirstObjectItem, type FirstOfUnion, type GetClosestEventName, type GetClosestEventNameTuple, type GetClosestEventPayload, type GetClosestEventTuple, type GetClosestEvents, type GetFixedPartCount, type GetMatchedEventNames, type GetPartCount, type GetPartCountAcc, type GetPayload, type GetWildcardCount, type GetWildcardEventList, type IFastEventScope, type IfNever, type IndexOfMax, type IndexOfMin, type IsAllTransformed, type IsAny, type IsAnyRecord, type IsFullWildcard, type IsMatchEventName, type IsMultiWildcard, type IsNever, type IsSemiWildcard, type IsTransformedEvent, type IsWildcardPart, type Join, type KeyOf, type Keys, type Max, type Merge, type MergeStrings, type MergeUnion, type Min, type MutableMessage, type MutableRecord, type NormalEvents, type NotEqual, type NotPayload, type ObjectKeys, type OmitTransformedEvents, type OptionalKeys, type Overloads, type OverrideOptions, type PayloadValues, type PickEqualRecord, type PickInlcudeDelimiterRecord, type PickNotEqualRecord, type PickNotInlcudeDelimiterRecord, type PickPayload, type PickTransformedEvents, type PrefixNumber, type ProcessSegments, QueueOverflowError, type RemoveEmptyObject, type ReplaceWildcard, type RequiredItems, type RequiredKeys, type ScopeEvents, type Slice, type Split, type SplitPath, type StrictEqual, TimeoutError, type ToFixedCounts, type ToKeyPrioritys, type ToWildcardMessage, type TransformedEvents, type Tuple, type TypedFastEventAnyListener, type TypedFastEventListener, type TypedFastEventMessage, type TypedFastEventMessageOptional, type UnTransformedEvents, UnboundError, type Union, type UnionToIntersection, type Unique, type ValueOf, type WildcardEvents, type WildcardKeyToObject, type WildcardKeys, type WildcardStyle, __FastEventScope__, __FastEvent__, __expandable__, createAsyncEventIterator, expandable, isClass, type isEmpty, isExpandable, isFastEvent, isFastEventMessage, isFastEventScope, isFunction, isPathMatched, isString, isSubsctiber };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var W=Object.defineProperty;var Z=(o,e,t)=>e in o?W(o,e,{enumerable:true,configurable:true,writable:true,value:t}):o[e]=t;var n=(o,e)=>W(o,"name",{value:e,configurable:true});var p=(o,e,t)=>Z(o,typeof e!="symbol"?e+"":e,t);var ee=Symbol.for("__FastEvent__"),te=Symbol.for("__FastEventScope__"),A=class A extends Error{constructor(e){super(e);}};n(A,"FastEventError");var m=A,O=class O extends m{};n(O,"TimeoutError");var I=O,M=class M extends m{};n(M,"UnboundError");var E=M,P=class P extends m{};n(P,"AbortError");var _=P,j=class j extends m{};n(j,"CancelError");var y=j,F=class F extends m{};n(F,"QueueOverflowError");var V=F;var x=(function(o){return o[o.Transformed=1]="Transformed",o})({});function w(o,e,t,r){let s,i={},f={};return typeof o[0]=="object"?(Object.assign(f,o[0]),i=typeof o[1]=="boolean"?{retain:o[1]}:o[1]||{},s=o[0].meta):(f.type=o[0],f.payload=o[1],i=typeof o[2]=="boolean"?{retain:o[2]}:o[2]||{}),s=Object.assign({},e,t,i.meta,s),Object.keys(s).length===0?(s=void 0,delete f.meta):f.meta=s,i.executor===void 0&&(i.executor=r),[f,i]}n(w,"parseEmitArgs");function $(o){return o?typeof o=="object"&&"__FastEventScope__"in o:false}n($,"isFastEventScope");function L(o,e,t){let r=o[0],s=$(o[1])?o[1]:void 0,i=(s?o[2]:o[1])||{};return i.meta=Object.assign({},e,i?.meta),i.context=i.context!==void 0?i.context:t,[r,s,i]}n(L,"parseScopeArgs");function d(o,e){return Object.defineProperty(o,"name",{value:e||"anonymous",configurable:true}),o}n(d,"renameFn");function h(o){return o&&typeof o=="function"}n(h,"isFunction");var T=class T{constructor(e){p(this,"__FastEventScope__",true);p(this,"__events__");p(this,"__meta__");p(this,"__context__");p(this,"_options",{});p(this,"prefix","");p(this,"emitter");this._options=Object.assign({},this._initOptions(e));}get context(){return this.options.context||this}get options(){return this._options}get listeners(){return this.emitter.getListeners(this.prefix)}bind(e,t,r){this.emitter=e,this._options=Object.assign(this._options,{scope:t},r),t.length>0&&!t.endsWith(e.options.delimiter)&&(this.prefix=t+e.options.delimiter);}_initOptions(e){return e}_getScopeListener(e){let t=this.prefix;if(t.length===0)return e;if(!e)throw new Error;let r=this;return d(function(i,f){let a=f.rawEventType||i.type;if(a.startsWith(t)){let l=((f.flags||0)&x.Transformed)>0?i:Object.assign({},i,{type:a.substring(t.length)});return e.call(r.context,l,f)}},e.name)}_getScopeType(e){return e===void 0?void 0:this.prefix+e}_fixScopeType(e){return e.startsWith(this.prefix)?e.substring(this.prefix.length):e}on(){if(!this.emitter)throw new E;let e=[...arguments];return e[0]=this._getScopeType(e[0]),e[1]=this._getScopeListener(e[1]),this.emitter.on(...e)}once(){return this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",...arguments)}off(){let e=arguments;typeof e[0]=="string"&&(e[0]=this._getScopeType(e[0])),this.emitter.off(...e);}offAll(){this.emitter.offAll(this.prefix.substring(0,this.prefix.length-1));}clear(){this.emitter.clear(this.prefix.substring(0,this.prefix.length-1));}emit(){let[e,t]=w(arguments,this.emitter.options.meta,this.options.meta,this.options.executor);return this._transformMessage(e,t),e.type=this._getScopeType(e.type),this.emitter.emit(e,t)}_transformMessage(e,t){h(this._options.transform)&&(t.rawEventType=this._getScopeType(e.type),t.flags=(t.flags||0)|x.Transformed,e.payload=this._options.transform.call(this,e));}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}async waitFor(){let e=arguments[0],t=arguments[1],r=await this.emitter.waitFor(this._getScopeType(e),t);return Object.assign({},r,{type:this._fixScopeType(r.type)})}scope(){let[e,t,r]=L(arguments,this.options.meta,this.options.context),s;return t?s=t:s=new T,s.bind(this.emitter,this.prefix+e,r),s}};n(T,"FastEventScope");var S=T;function R(o,e){let t=o.length,r=e.length;if(t!==r&&(r===0||e[r-1]!=="**"))return false;if(r>0&&e[r-1]==="**"){for(let s=0;s<r-1;s++)if(e[s]!=="*"&&e[s]!==o[s])return false;return true}for(let s=0;s<t;s++)if(e[s]!=="*"&&e[s]!==o[s])return false;return true}n(R,"isPathMatched");function k(o,e){let t=[];for(let r=o.length-1;r>=0;r--)e(o[r])&&(t.push(r),o.splice(r,1));return t.reverse()}n(k,"removeItem");function We(o){return o?typeof o=="object"&&"type"in o:false}n(We,"isFastEventMessage");function U(o){return o&&typeof o=="string"}n(U,"isString");var B=Symbol.for("__expandable__");function Be(o){return o[B]=true,o}n(Be,"expandable");function q(o){return o&&o[B]}n(q,"isExpandable");function z(o){return o&&typeof o=="object"&&"off"in o&&"listener"in o}n(z,"isSubsctiber");function Ke(o){return typeof o=="function"&&(o.toString().startsWith("class ")||o.prototype?.constructor===o)}n(Ke,"isClass");function Ze(o){return o?typeof o=="object"&&"__FastEvent__"in o:false}n(Ze,"isFastEvent");var G=n(()=>(o,e,t,r)=>o.map(s=>r(s[0],e,t,true)),"parallel");function H(o){for(let e=0;e<o.length;e++){let t=o[e];Array.isArray(t)&&q(t)&&(o.splice(e,1,...t),e+=t.length-1);}return o}n(H,"expandEmitResults");function J(o,e){return o.catch(t=>(e&&e(t),Promise.resolve(t)))}n(J,"tryReturnError");var N=class N{constructor(e,t,r={}){p(this,"eventEmitter");p(this,"eventName");p(this,"buffer",[]);p(this,"resolvers",[]);p(this,"errorResolvers",[]);p(this,"isStopped",false);p(this,"error",null);p(this,"options");p(this,"currentSize");p(this,"hasNewMessage",false);p(this,"_listener");p(this,"_ready",false);p(this,"_listenOptions");p(this,"_cleanups",[]);this.eventEmitter=e,this.eventName=t;let s=20,i=100;this.options={size:r.size??s,maxExpandSize:r.maxExpandSize??i,expandOverflow:r.expandOverflow??"slide",overflow:r.overflow??"slide",lifetime:r.lifetime??0,onPush:r.onPush,onPop:r.onPop,onDrop:r.onDrop,onError:r.onError??(()=>true),signal:r.signal},this.currentSize=this.options.size,this._listener=this.onMessage.bind(this);}get listener(){return this._listener}get ready(){return this._ready}create(e){if(!this._ready){this._listenOptions=e;try{let t=this.eventEmitter.on(this.eventName,this._listener,e);if(this._cleanups.push(()=>t.off()),this.options.signal&&!this.options.signal.aborted){let r=n(()=>{this.off(!0);},"offFn");this.options.signal.addEventListener("abort",r),this._cleanups.push(()=>{this.options.signal.removeEventListener("abort",r);});}}finally{this._ready=true;}}}push(e){this.options.onPush?this.options.onPush(e,this.buffer):this.buffer.push(this.options.lifetime>0?[e,Date.now()]:[e,0]);}handleOverflow(e){switch(this.buffer.length>=this.options.maxExpandSize&&this.options.overflow==="expand"?this.options.expandOverflow:this.options.overflow){case "drop":return this.options.onDrop&&this.options.onDrop(e),false;case "expand":return this.currentSize=Math.min(this.currentSize+this.options.size,this.options.maxExpandSize),this.push(e),true;case "slide":let r=this.buffer.shift();return this.options.onDrop&&r&&this.options.onDrop(r[0]),this.push(e),true;case "throw":throw this.options.onDrop&&this.options.onDrop(e),new Error(`EventIterator queue overflow: buffer size (${this.currentSize}) exceeded`);default:return false}}onMessage(e,t){if(this.isStopped)return;let r=e;if(this.resolvers.length>0){this.resolvers.shift()({value:r,done:false});return}this.hasNewMessage=true,this.buffer.length<this.currentSize?this.push(r):this.handleOverflow(r);}off(e){this._ready&&(this.isStopped||(this.isStopped=true,this._cleanups.forEach(t=>t()),this._cleanups=[],this.buffer=[],this._ready=false,e?(this.errorResolvers.forEach(t=>{t(new _);}),this.errorResolvers=[]):(this.resolvers.forEach(t=>{t({value:void 0,done:true});}),this.resolvers=[]),this._ready=false));}async next(){if(this.error)return Promise.reject(this.error);if(this.isStopped&&this.buffer.length===0)return {value:void 0,done:true};if(this.buffer.length>0){let e,t;if(this.options.onPop){let r=this.options.onPop(this.buffer,this.hasNewMessage);r?[e,t]=r:[e,t]=this.buffer.shift()||[void 0,0];}else [e,t]=this.buffer.shift()||[void 0,0];if(this.hasNewMessage=false,e!==void 0)return this.options.lifetime>0&&Date.now()-t>this.options.lifetime?(this.options.onDrop&&this.options.onDrop(e),this.next()):{value:e,done:false}}return new Promise((e,t)=>{this.resolvers.push(e),this.errorResolvers.push(t);})}[Symbol.asyncIterator](){return this}async done(){return this.off(),{value:void 0,done:true}}async throw(e){return this.error=e,this.off(),Promise.reject(e)}async return(){return this.off(),{value:void 0,done:true}}[Symbol.dispose](){this.off();}on(){this.create(this._listenOptions),this.isStopped=false;}};n(N,"FastEventIterator");var D=N;function K(o,e,t={}){return new D(o,e,t)}n(K,"createAsyncEventIterator");function X(o,e){return Array.isArray(e)&&e.forEach(t=>{o=d(t(o),o.name);}),o}n(X,"wrapPipeListener");var C=class C{constructor(e){p(this,"__FastEvent__",true);p(this,"listeners",{__listeners:[]});p(this,"_options");p(this,"_delimiter","/");p(this,"_context");p(this,"retainedMessages",new Map);p(this,"listenerCount",0);p(this,"types",null);this._options=Object.assign({debug:false,id:Math.random().toString(36).substring(2),delimiter:"/",context:null,ignoreErrors:true,meta:void 0,expandEmitResults:true,executor:G()},this._initOptions(e)),this._delimiter=this._options.delimiter,this._context=this._options.context,this._enableDevTools();}get options(){return this._options}get context(){return this.options.context||this}get meta(){return this.options.meta}get id(){return this._options.id}_initOptions(e){return e}_addListener(e,t,r){let{count:s,prepend:i}=r,f=0;return [this._forEachNodes(e,u=>{let l=[t,s,0,r.tag,r.flags];i?(u.__listeners.splice(0,0,l),f=0):(u.__listeners.push(l),f=u.__listeners.length-1),this.listenerCount++;}),f]}_enableDevTools(){this.options.debug&&globalThis.__FASTEVENT_DEVTOOLS__&&globalThis.__FASTEVENT_DEVTOOLS__.add(this);}_forEachNodes(e,t){if(e.length===0)return;let r=this.listeners;for(let s=0;s<e.length;s++){let i=e[s];if(i in r||(r[i]={__listeners:[]}),s===e.length-1){let f=r[i];return t(f,r),f}else r=r[i];}}_removeListener(e,t,r){r&&k(e.__listeners,s=>{s=Array.isArray(s)?s[0]:s;let i=s===r;return i&&(this.listenerCount--,h(this._options.onRemoveListener)&&this._options.onRemoveListener(t.join(this._delimiter),r)),i});}_onAddListener(e,t,r){if(h(this._options.onAddListener)){let s=this._options.onAddListener(e,t,r);if(s===false)throw new y;if(z(s))return s}}on(){let e=arguments[0],t=null,r,s=!h(arguments[1]);s?r=arguments[1]||{}:(t=arguments[1],r=arguments[2]||{});let i=Object.assign({count:0,flags:0,prepend:false},r);if(e.length===0)throw new Error("event type cannot be empty");if(s||t===null){let c=Object.assign({overflow:"expand",size:10,maxExpandSize:100},i.iterable),g=K(this,e,c);return g.create(i),this._onAddListener(e,g.listener,i),g}if(h(this._options.onAddListener)){let c=this._options.onAddListener(e,t,i);if(c===false)throw new y;if(z(c))return c}let f=e.split(this._delimiter);if(i.pipes&&i.pipes.length>0&&(t=X(t,i.pipes)),h(i.filter)||h(i.off)){let c=t,g=n(()=>a&&this._removeListener(a,f,t),"off");t=d(function(b,v){if(h(i.off)&&i.off.call(this,b,v)){g();return}if(h(i.filter)){if(i.filter.call(this,b,v))return c.call(this,b,v)}else return c.call(this,b,v)},t.name);}let[a,u]=this._addListener(f,t,i),l=n(()=>a&&this._removeListener(a,f,t),"off");return this._emitRetainMessage(e,a,u),{off:l,listener:t,[Symbol.dispose](){l();}}}once(){return h(arguments[1])?this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1})):this.on(arguments[0],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",...arguments)}off(){let e=arguments,t=h(e[0])?void 0:e[0],r=h(e[0])?e[0]:e[1],s=t?t.split(this._delimiter):[],i=t?t.includes("*"):false;if(t&&!i)this._traverseToPath(this.listeners,s,f=>{r?this._removeListener(f,s,r):t&&(f.__listeners=[]);});else {let f=i?[]:s;this._traverseListeners(this.listeners,f,(a,u)=>{(r!==void 0||i&&R(a,s))&&(r?this._removeListener(u,s,r):u.__listeners=[]);});}}offAll(e){if(e){let t=e.split(this._delimiter),r=0;this._traverseListeners(this.listeners,t,(s,i)=>{r+=i.__listeners.length,i.__listeners=[];}),this.listenerCount-=r,this._removeRetainedEvents(e);}else {let t=0;this._traverseListeners(this.listeners,[],(r,s)=>{t+=s.__listeners.length;}),this.listenerCount-=t,this.retainedMessages.clear(),this.listeners={__listeners:[]};}h(this._options.onClearListeners)&&this._options.onClearListeners.call(this);}_removeRetainedEvents(e){e||this.retainedMessages.clear(),e?.endsWith(this._delimiter)&&(e+=this._delimiter),this.retainedMessages.delete(e);for(let t of this.retainedMessages.keys())t.startsWith(e)&&this.retainedMessages.delete(t);}clear(e){this.offAll(e),this._removeRetainedEvents(e);}_emitRetainMessage(e,t,r){let s=[];if(e.includes("*")){let i=e.split(this._delimiter);this.retainedMessages.forEach((f,a)=>{let u=a.split(this._delimiter);R(u,i)&&s.push(f);});}else this.retainedMessages.has(e)&&s.push(this.retainedMessages.get(e));t&&s.forEach(i=>{this._executeListeners([t],i,{},f=>f[0]===t.__listeners[r][0]);});}_traverseToPath(e,t,r,s=0,i){if(s>=t.length){r(e);return}let f=t[s];if(i===true){this._traverseToPath(e,t,r,s+1,true);return}"*"in e&&this._traverseToPath(e["*"],t,r,s+1),"**"in e&&this._traverseToPath(e["**"],t,r,s+1,true),f in e&&this._traverseToPath(e[f],t,r,s+1);}_traverseListeners(e,t,r){let s=e;t&&t.length>0&&this._traverseToPath(e,t,f=>{s=f;});let i=n((f,a,u)=>{a(u,f);for(let[l,c]of Object.entries(f))l.startsWith("__")||c&&i(c,a,[...u,l]);},"traverseNodes");i(s,r,[]);}_onListenerError(e,t,r,s){if(s instanceof Error&&(s._emitter=`${e.name||"anonymous"}:${t.type}`),h(this._options.onListenerError))try{this._options.onListenerError.call(this,s,e,t,r);}catch{}if(this._options.ignoreErrors)return s;throw s}_setListenerFlags(e,t){return !e||e===0?t:e|t}_executeListener(e,t,r,s=false){try{if(r&&r.abortSignal&&r.abortSignal.aborted)return this._onListenerError(e,t,r,new _(e.name));let i=((r?.flags||0)&x.Transformed)>0,f=e.call(this.context,i?t.payload:t,r);return s&&f&&f instanceof Promise&&(f=J(f,a=>this._onListenerError(e,t,r,a))),f}catch(i){return this._onListenerError(e,t,r,i)}}_getListenerExecutor(e){if(!e)return;let t=e.executor||this._options.executor;if(h(t))return t}_executeListeners(e,t,r,s){if(!e||e.length===0)return [];let i=[];for(let a of e){let u=0;for(let l of a.__listeners)(!s||s(l,a))&&i.push([l,u++,a.__listeners]);}this._decListenerExecCount(i);let f=this._getListenerExecutor(r);if(f){let a=f(i.map(u=>u[0]),t,r,this._executeListener.bind(this));return Array.isArray(a)?a:[a]}else return i.map(a=>this._executeListener(a[0][0],t,r,true))}_decListenerExecCount(e){for(let t=e.length-1;t>=0;t--){let r=e[t][0];r[2]++,r[1]>0&&r[1]<=r[2]&&e[t][2].splice(t,1);}}getListeners(e){let t=[],r=e.split(this._delimiter);return this._traverseToPath(this.listeners,r,s=>{t.push(s);}),t[0].__listeners}clearRetainMessages(e){e?this.retainedMessages.delete(e):this.retainedMessages.clear();}emit(){let[e,t]=w(arguments,this.options.meta);h(t.parseArgs)&&t.parseArgs(e,t);let r=e.type.split(this._delimiter);t.retain&&this.retainedMessages.set(e.type,e);let s=[],i=[];if(this._traverseToPath(this.listeners,r,f=>{i.push(f);}),h(this._options.onBeforeExecuteListener)){let f=this._options.onBeforeExecuteListener.call(this,e,t);if(Array.isArray(f))return f;if(f===false)throw new _(e.type)}return h(this._options.transform)&&(e.payload=this._options.transform.call(this,e),t.rawEventType=e.type,t.flags=(t.flags||0)|x.Transformed),s.push(...this._executeListeners(i,e,t)),h(this._options.onAfterExecuteListener)&&this._options.onAfterExecuteListener.call(this,e,s,i),this._options.expandEmitResults&&H(s),s}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}waitFor(){let e=arguments[0],t=arguments[1];return new Promise((r,s)=>{let i,f,a=n(u=>{clearTimeout(i),f?.off(),r(u);},"listener");t&&t>0&&(i=setTimeout(()=>{f?.off(),s(new Error("wait for event<"+e+"> is timeout"));},t)),f=this.on(e,a);})}scope(){let[e,t,r]=L(arguments,this.options.meta,this.options.context),s;return t?s=t:s=new S,s.bind(this,e,r),s}};n(C,"FastEvent");var Y=C;exports.AbortError=_;exports.CancelError=y;exports.FastEvent=Y;exports.FastEventError=m;exports.FastEventListenerFlags=x;exports.FastEventScope=S;exports.QueueOverflowError=V;exports.TimeoutError=I;exports.UnboundError=E;exports.__FastEventScope__=te;exports.__FastEvent__=ee;exports.__expandable__=B;exports.expandable=Be;exports.isClass=Ke;exports.isExpandable=q;exports.isFastEvent=Ze;exports.isFastEventMessage=We;exports.isFastEventScope=$;exports.isFunction=h;exports.isPathMatched=R;exports.isString=U;exports.isSubsctiber=z;//# sourceMappingURL=index.js.map
1
+ 'use strict';var W=Object.defineProperty;var Z=(o,e,t)=>e in o?W(o,e,{enumerable:true,configurable:true,writable:true,value:t}):o[e]=t;var n=(o,e)=>W(o,"name",{value:e,configurable:true});var p=(o,e,t)=>Z(o,typeof e!="symbol"?e+"":e,t);var ee=Symbol.for("__FastEvent__"),te=Symbol.for("__FastEventScope__"),A=class A extends Error{constructor(e){super(e);}};n(A,"FastEventError");var m=A,O=class O extends m{};n(O,"TimeoutError");var I=O,M=class M extends m{};n(M,"UnboundError");var E=M,P=class P extends m{};n(P,"AbortError");var _=P,j=class j extends m{};n(j,"CancelError");var y=j,F=class F extends m{};n(F,"QueueOverflowError");var V=F;var x=(function(o){return o[o.Transformed=1]="Transformed",o})({});function w(o,e,t,r){let s,i={},f={};return typeof o[0]=="object"?(Object.assign(f,o[0]),i=typeof o[1]=="boolean"?{retain:o[1]}:o[1]||{},s=o[0].meta):(f.type=o[0],f.payload=o[1],i=typeof o[2]=="boolean"?{retain:o[2]}:o[2]||{}),s=Object.assign({},e,t,i.meta,s),Object.keys(s).length===0?(s=void 0,delete f.meta):f.meta=s,i.executor===void 0&&(i.executor=r),[f,i]}n(w,"parseEmitArgs");function $(o){return o?typeof o=="object"&&"__FastEventScope__"in o:false}n($,"isFastEventScope");function L(o,e,t){let r=o[0],s=$(o[1])?o[1]:void 0,i=(s?o[2]:o[1])||{};return i.meta=Object.assign({},e,i?.meta),i.context=i.context!==void 0?i.context:t,[r,s,i]}n(L,"parseScopeArgs");function d(o,e){return Object.defineProperty(o,"name",{value:e||"anonymous",configurable:true}),o}n(d,"renameFn");function h(o){return o&&typeof o=="function"}n(h,"isFunction");var T=class T{constructor(e){p(this,"__FastEventScope__",true);p(this,"__events__");p(this,"__meta__");p(this,"__context__");p(this,"_options",{});p(this,"prefix","");p(this,"emitter");this._options=Object.assign({},this._initOptions(e));}get context(){return this.options.context||this}get options(){return this._options}get listeners(){return this.emitter.getListeners(this.prefix)}bind(e,t,r){this.emitter=e,this._options=Object.assign(this._options,{scope:t},r),t.length>0&&!t.endsWith(e.options.delimiter)&&(this.prefix=t+e.options.delimiter);}_initOptions(e){return e}_getScopeListener(e){let t=this.prefix;if(t.length===0)return e;if(!e)throw new Error;let r=this;return d(function(i,f){let a=f.rawEventType||i.type;if(a.startsWith(t)){let l=((f.flags||0)&x.Transformed)>0?i:Object.assign({},i,{type:a.substring(t.length)});return e.call(r.context,l,f)}},e.name)}_getScopeType(e){return e===void 0?void 0:this.prefix+e}_fixScopeType(e){return e.startsWith(this.prefix)?e.substring(this.prefix.length):e}on(){if(!this.emitter)throw new E;let e=[...arguments];return e[0]=this._getScopeType(e[0]),e[1]=this._getScopeListener(e[1]),this.emitter.on(...e)}once(){return this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",...arguments)}off(){let e=arguments;typeof e[0]=="string"&&(e[0]=this._getScopeType(e[0])),this.emitter.off(...e);}offAll(){this.emitter.offAll(this.prefix.substring(0,this.prefix.length-1));}clear(){this.emitter.clear(this.prefix.substring(0,this.prefix.length-1));}emit(){let[e,t]=w(arguments,this.emitter.options.meta,this.options.meta,this.options.executor);return this._transformMessage(e,t),e.type=this._getScopeType(e.type),this.emitter.emit(e,t)}_transformMessage(e,t){h(this._options.transform)&&(t.rawEventType=this._getScopeType(e.type),t.flags=(t.flags||0)|x.Transformed,e.payload=this._options.transform.call(this,e));}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}async waitFor(){let e=arguments[0],t=arguments[1],r=await this.emitter.waitFor(this._getScopeType(e),t);return Object.assign({},r,{type:this._fixScopeType(r.type)})}scope(){let[e,t,r]=L(arguments,this.options.meta,this.options.context),s;return t?s=t:s=new T,s.bind(this.emitter,this.prefix+e,r),s}};n(T,"FastEventScope");var S=T;function R(o,e){let t=o.length,r=e.length;if(t!==r&&(r===0||e[r-1]!=="**"))return false;if(r>0&&e[r-1]==="**"){for(let s=0;s<r-1;s++)if(e[s]!=="*"&&e[s]!==o[s])return false;return true}for(let s=0;s<t;s++)if(e[s]!=="*"&&e[s]!==o[s])return false;return true}n(R,"isPathMatched");function k(o,e){let t=[];for(let r=o.length-1;r>=0;r--)e(o[r])&&(t.push(r),o.splice(r,1));return t.reverse()}n(k,"removeItem");function We(o){return o?typeof o=="object"&&"type"in o:false}n(We,"isFastEventMessage");function U(o){return o&&typeof o=="string"}n(U,"isString");var B=Symbol.for("__expandable__");function Be(o){return o[B]=true,o}n(Be,"expandable");function q(o){return o&&o[B]}n(q,"isExpandable");function z(o){return o&&typeof o=="object"&&"off"in o&&"listener"in o}n(z,"isSubsctiber");function Ke(o){return typeof o=="function"&&(o.toString().startsWith("class ")||o.prototype?.constructor===o)}n(Ke,"isClass");function Ze(o){return o?typeof o=="object"&&"__FastEvent__"in o:false}n(Ze,"isFastEvent");var G=n(()=>(o,e,t,r)=>o.map(s=>r(s[0],e,t,true)),"parallel");function H(o){for(let e=0;e<o.length;e++){let t=o[e];Array.isArray(t)&&q(t)&&(o.splice(e,1,...t),e+=t.length-1);}return o}n(H,"expandEmitResults");function J(o,e){return o.catch(t=>(e&&e(t),Promise.resolve(t)))}n(J,"tryReturnError");var N=class N{constructor(e,t,r={}){p(this,"eventEmitter");p(this,"eventName");p(this,"buffer",[]);p(this,"resolvers",[]);p(this,"errorResolvers",[]);p(this,"isStopped",false);p(this,"error",null);p(this,"options");p(this,"currentSize");p(this,"hasNewMessage",false);p(this,"_listener");p(this,"_ready",false);p(this,"_listenOptions");p(this,"_cleanups",[]);this.eventEmitter=e,this.eventName=t;let s=20,i=100;this.options={size:r.size??s,maxExpandSize:r.maxExpandSize??i,expandOverflow:r.expandOverflow??"slide",overflow:r.overflow??"slide",lifetime:r.lifetime??0,onPush:r.onPush,onPop:r.onPop,onDrop:r.onDrop,onError:r.onError??(()=>true),signal:r.signal},this.currentSize=this.options.size,this._listener=this.onMessage.bind(this);}get listener(){return this._listener}get ready(){return this._ready}create(e){if(!this._ready){this._listenOptions=e;try{let t=this.eventEmitter.on(this.eventName,this._listener,e);if(this._cleanups.push(()=>t.off()),this.options.signal&&!this.options.signal.aborted){let r=n(()=>{this.off(!0);},"offFn");this.options.signal.addEventListener("abort",r),this._cleanups.push(()=>{this.options.signal.removeEventListener("abort",r);});}}finally{this._ready=true;}}}push(e){this.options.onPush?this.options.onPush(e,this.buffer):this.buffer.push(this.options.lifetime>0?[e,Date.now()]:[e,0]);}handleOverflow(e){switch(this.buffer.length>=this.options.maxExpandSize&&this.options.overflow==="expand"?this.options.expandOverflow:this.options.overflow){case "drop":return this.options.onDrop&&this.options.onDrop(e),false;case "expand":return this.currentSize=Math.min(this.currentSize+this.options.size,this.options.maxExpandSize),this.push(e),true;case "slide":let r=this.buffer.shift();return this.options.onDrop&&r&&this.options.onDrop(r[0]),this.push(e),true;case "throw":throw this.options.onDrop&&this.options.onDrop(e),new Error(`EventIterator queue overflow: buffer size (${this.currentSize}) exceeded`);default:return false}}onMessage(e,t){if(this.isStopped)return;let r=e;if(this.resolvers.length>0){this.resolvers.shift()({value:r,done:false});return}this.hasNewMessage=true,this.buffer.length<this.currentSize?this.push(r):this.handleOverflow(r);}off(e){this._ready&&(this.isStopped||(this.isStopped=true,this._cleanups.forEach(t=>t()),this._cleanups=[],this.buffer=[],this._ready=false,e?(this.errorResolvers.forEach(t=>{t(new _);}),this.errorResolvers=[]):(this.resolvers.forEach(t=>{t({value:void 0,done:true});}),this.resolvers=[]),this._ready=false));}async next(){if(this.error)return Promise.reject(this.error);if(this.isStopped&&this.buffer.length===0)return {value:void 0,done:true};if(this.buffer.length>0){let e,t;if(this.options.onPop){let r=this.options.onPop(this.buffer,this.hasNewMessage);r?[e,t]=r:[e,t]=this.buffer.shift()||[void 0,0];}else [e,t]=this.buffer.shift()||[void 0,0];if(this.hasNewMessage=false,e!==void 0)return this.options.lifetime>0&&Date.now()-t>this.options.lifetime?(this.options.onDrop&&this.options.onDrop(e),this.next()):{value:e,done:false}}return new Promise((e,t)=>{this.resolvers.push(e),this.errorResolvers.push(t);})}[Symbol.asyncIterator](){return this}async done(){return this.off(),{value:void 0,done:true}}async throw(e){return this.error=e,this.off(),Promise.reject(e)}async return(){return this.off(),{value:void 0,done:true}}[Symbol.dispose](){this.off();}on(){this.create(this._listenOptions),this.isStopped=false;}};n(N,"FastEventIterator");var D=N;function K(o,e,t={}){return new D(o,e,t)}n(K,"createAsyncEventIterator");function X(o,e){return Array.isArray(e)&&e.forEach(t=>{o=d(t(o),o.name);}),o}n(X,"wrapPipeListener");var C=class C{constructor(e){p(this,"__FastEvent__",true);p(this,"listeners",{__listeners:[]});p(this,"_options");p(this,"_delimiter","/");p(this,"_context");p(this,"retainedMessages",new Map);p(this,"listenerCount",0);p(this,"types",null);this._options=Object.assign({debug:false,id:Math.random().toString(36).substring(2),delimiter:"/",context:null,ignoreErrors:true,meta:void 0,expandEmitResults:true,executor:G()},this._initOptions(e)),this._delimiter=this._options.delimiter,this._context=this._options.context,this._enableDevTools();}get options(){return this._options}get context(){return this.options.context||this}get meta(){return this.options.meta}get id(){return this._options.id}_initOptions(e){return e}_addListener(e,t,r){let{count:s,prepend:i}=r,f=0;return [this._forEachNodes(e,u=>{let l=[t,s,0,r.tag,r.flags];i?(u.__listeners.splice(0,0,l),f=0):(u.__listeners.push(l),f=u.__listeners.length-1),this.listenerCount++;}),f]}_enableDevTools(){this.options.debug&&globalThis.__FASTEVENT_DEVTOOLS__&&globalThis.__FASTEVENT_DEVTOOLS__.add(this);}_forEachNodes(e,t){if(e.length===0)return;let r=this.listeners;for(let s=0;s<e.length;s++){let i=e[s];if(i in r||(r[i]={__listeners:[]}),s===e.length-1){let f=r[i];return t(f,r),f}else r=r[i];}}_removeListener(e,t,r){r&&k(e.__listeners,s=>{s=Array.isArray(s)?s[0]:s;let i=s===r;return i&&(this.listenerCount--,h(this._options.onRemoveListener)&&this._options.onRemoveListener(t.join(this._delimiter),r)),i});}_onAddListener(e,t,r){if(h(this._options.onAddListener)){let s=this._options.onAddListener(e,t,r);if(s===false)throw new y;if(z(s))return s}}on(){let e=arguments[0],t=null,r,s=!h(arguments[1]);s?r=arguments[1]||{}:(t=arguments[1],r=arguments[2]||{});let i=Object.assign({count:0,flags:0,prepend:false},r);if(e.length===0)throw new Error("event type cannot be empty");if(s||t===null){let c=Object.assign({overflow:"expand",size:10,maxExpandSize:100},i.iterable),g=K(this,e,c);return g.create(i),this._onAddListener(e,g.listener,i),g}if(h(this._options.onAddListener)){let c=this._options.onAddListener(e,t,i);if(c===false)throw new y;if(z(c))return c}let f=e.split(this._delimiter);if(i.pipes&&i.pipes.length>0&&(t=X(t,i.pipes)),h(i.filter)||h(i.off)){let c=t,g=n(()=>a&&this._removeListener(a,f,t),"off");t=d(function(b,v){if(h(i.off)&&i.off.call(this,b,v)){g();return}if(h(i.filter)){if(i.filter.call(this,b,v))return c.call(this,b,v)}else return c.call(this,b,v)},t.name);}let[a,u]=this._addListener(f,t,i),l=n(()=>a&&this._removeListener(a,f,t),"off");return this._emitRetainMessage(e,a,u),{off:l,listener:t,[Symbol.dispose](){l();}}}once(){return h(arguments[1])?this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1})):this.on(arguments[0],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",...arguments)}off(){let e=arguments,t=h(e[0])?void 0:e[0],r=h(e[0])?e[0]:e[1],s=t?t.split(this._delimiter):[],i=t?t.includes("*"):false;if(t&&!i)this._traverseToPath(this.listeners,s,f=>{r?this._removeListener(f,s,r):t&&(f.__listeners=[]);});else {let f=i?[]:s;this._traverseListeners(this.listeners,f,(a,u)=>{(r!==void 0||i&&R(a,s))&&(r?this._removeListener(u,s,r):u.__listeners=[]);});}}offAll(e){if(e){let t=e.split(this._delimiter),r=0;this._traverseListeners(this.listeners,t,(s,i)=>{r+=i.__listeners.length,i.__listeners=[];}),this.listenerCount-=r,this._removeRetainedEvents(e);}else {let t=0;this._traverseListeners(this.listeners,[],(r,s)=>{t+=s.__listeners.length;}),this.listenerCount-=t,this.retainedMessages.clear(),this.listeners={__listeners:[]};}h(this._options.onClearListeners)&&this._options.onClearListeners.call(this);}_removeRetainedEvents(e){e||this.retainedMessages.clear(),e?.endsWith(this._delimiter)&&(e+=this._delimiter),this.retainedMessages.delete(e);for(let t of this.retainedMessages.keys())t.startsWith(e)&&this.retainedMessages.delete(t);}clear(e){this.offAll(e),this._removeRetainedEvents(e);}_emitRetainMessage(e,t,r){let s=[];if(e.includes("*")){let i=e.split(this._delimiter);this.retainedMessages.forEach((f,a)=>{let u=a.split(this._delimiter);R(u,i)&&s.push(f);});}else this.retainedMessages.has(e)&&s.push(this.retainedMessages.get(e));t&&s.forEach(i=>{this._executeListeners([t],i,{},f=>f[0]===t.__listeners[r][0]);});}_traverseToPath(e,t,r,s=0,i){if(s>=t.length){r(e);return}let f=t[s];if(i===true){this._traverseToPath(e,t,r,s+1,true);return}"*"in e&&this._traverseToPath(e["*"],t,r,s+1),"**"in e&&this._traverseToPath(e["**"],t,r,s+1,true),f in e&&this._traverseToPath(e[f],t,r,s+1);}_traverseListeners(e,t,r){let s=e;t&&t.length>0&&this._traverseToPath(e,t,f=>{s=f;});let i=n((f,a,u)=>{a(u,f);for(let[l,c]of Object.entries(f))l.startsWith("__")||c&&i(c,a,[...u,l]);},"traverseNodes");i(s,r,[]);}_onListenerError(e,t,r,s){if(s instanceof Error&&(s._emitter=`${e.name||"anonymous"}:${t.type}`),h(this._options.onListenerError))try{this._options.onListenerError.call(this,s,e,t,r);}catch{}if(this._options.ignoreErrors)return s;throw s}_setListenerFlags(e,t){return !e||e===0?t:e|t}_executeListener(e,t,r,s=false){try{if(r&&r.abortSignal&&r.abortSignal.aborted)return this._onListenerError(e,t,r,new _(e.name));let i=((r?.flags||0)&x.Transformed)>0,f=e.call(this.context,i?t.payload:t,r);return s&&f&&f instanceof Promise&&(f=J(f,a=>this._onListenerError(e,t,r,a))),f}catch(i){return this._onListenerError(e,t,r,i)}}_getListenerExecutor(e){if(!e)return;let t=e.executor||this._options.executor;if(h(t))return t}_executeListeners(e,t,r,s){if(!e||e.length===0)return [];let i=[];for(let a of e){let u=0;for(let l of a.__listeners)(!s||s(l,a))&&i.push([l,u++,a.__listeners]);}this._decListenerExecCount(i);let f=this._getListenerExecutor(r);if(f){let a=f(i.map(u=>u[0]),t,r,this._executeListener.bind(this));return Array.isArray(a)?a:[a]}else return i.map(a=>this._executeListener(a[0][0],t,r,true))}_decListenerExecCount(e){for(let t=e.length-1;t>=0;t--){let r=e[t][0];r[2]++,r[1]>0&&r[1]<=r[2]&&e[t][2].splice(t,1);}}getListeners(e){let t=[],r=e.split(this._delimiter);return this._traverseToPath(this.listeners,r,s=>{t.push(s);}),t[0].__listeners}clearRetainMessages(e){e?this.retainedMessages.delete(e):this.retainedMessages.clear();}emit(){let[e,t]=w(arguments,this.options.meta);h(t.parseArgs)&&t.parseArgs(e,t);let r=e.type.split(this._delimiter);t.retain&&this.retainedMessages.set(e.type,e);let s=[],i=[];if(this._traverseToPath(this.listeners,r,f=>{i.push(f);}),h(this._options.onBeforeExecuteListener)){let f=this._options.onBeforeExecuteListener.call(this,e,t);if(Array.isArray(f))return f;if(f===false)throw new _(e.type)}return h(this._options.transform)&&(e.payload=this._options.transform.call(this,e),t.rawEventType=e.type,t.flags=(t.flags||0)|x.Transformed),s.push(...this._executeListeners(i,e,t)),h(this._options.onAfterExecuteListener)&&this._options.onAfterExecuteListener.call(this,e,s,i),this._options.expandEmitResults&&H(s),s}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}waitFor(){let e=arguments[0],t=arguments[1];return new Promise((r,s)=>{let i,f,a=n(u=>{clearTimeout(i),f?.off(),r(u);},"listener");t&&t>0&&(i=setTimeout(()=>{f?.off(),s(new Error("wait for event<"+e+"> is timeout"));},t)),f=this.on(e,a);})}scope(){let[e,t,r]=L(arguments,this.options.meta,this.options.context),s;return t?s=t:s=new S,s.bind(this,e,r),s}};n(C,"FastEvent");var Y=C;exports.AbortError=_;exports.CancelError=y;exports.FastEvent=Y;exports.FastEventError=m;exports.FastEventIterator=D;exports.FastEventListenerFlags=x;exports.FastEventScope=S;exports.QueueOverflowError=V;exports.TimeoutError=I;exports.UnboundError=E;exports.__FastEventScope__=te;exports.__FastEvent__=ee;exports.__expandable__=B;exports.createAsyncEventIterator=K;exports.expandable=Be;exports.isClass=Ke;exports.isExpandable=q;exports.isFastEvent=Ze;exports.isFastEventMessage=We;exports.isFastEventScope=$;exports.isFunction=h;exports.isPathMatched=R;exports.isString=U;exports.isSubsctiber=z;//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map