Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xyo-network/module-events

Package Overview
Dependencies
Maintainers
0
Versions
611
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xyo-network/module-events - npm Package Compare versions

Comparing version 2.110.13 to 2.110.14

99

dist/browser/index.js

@@ -0,1 +1,4 @@

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
// src/Events/Events.ts

@@ -8,4 +11,7 @@ import { assertEx } from "@xylabs/assert";

var resolvedPromise = Promise.resolve();
var isMetaEvent = (eventName) => eventName === "listenerAdded" || eventName === "listenerRemoved";
var isMetaEvent = /* @__PURE__ */ __name((eventName) => eventName === "listenerAdded" || eventName === "listenerRemoved", "isMetaEvent");
var Events = class _Events extends Base {
static {
__name(this, "Events");
}
static anyMap = /* @__PURE__ */ new WeakMap();

@@ -18,3 +24,5 @@ static eventsMap = /* @__PURE__ */ new WeakMap();

constructor(params = {}) {
const mutatedParams = { ...params };
const mutatedParams = {
...params
};
if (mutatedParams.debug) {

@@ -43,3 +51,5 @@ mutatedParams.debug.logger = mutatedParams.debug.logger ?? ((type, debugName, eventName, eventData) => {

}
const { env } = globalThis.process ?? { env: {} };
const { env } = globalThis.process ?? {
env: {}
};
return env.DEBUG === "events" || env.DEBUG === "*" || _Events.isGlobalDebugEnabled;

@@ -54,3 +64,5 @@ }

clearListeners(eventNames) {
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [eventNames];
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [
eventNames
];
for (const eventName of eventNamesArray) {

@@ -89,3 +101,3 @@ this.logIfDebugEnabled("clear", eventName);

}
const filterMatch = (args, filter) => {
const filterMatch = /* @__PURE__ */ __name((args, filter) => {
if (filter) {

@@ -102,9 +114,15 @@ switch (typeof filter) {

return true;
};
}, "filterMatch");
this.logIfDebugEnabled("emitSerial", eventName, eventArgs);
const listeners = this.getListeners(eventName) ?? /* @__PURE__ */ new Set();
const filteredListeners = [...listeners.values()].filter((value) => value.filter ? filterMatch(eventArgs, value.filter) : true).map((info) => info.listener);
const filteredListeners = [
...listeners.values()
].filter((value) => value.filter ? filterMatch(eventArgs, value.filter) : true).map((info) => info.listener);
const anyListeners = assertEx(_Events.anyMap.get(this));
const staticListeners = [...filteredListeners];
const staticAnyListeners = [...anyListeners];
const staticListeners = [
...filteredListeners
];
const staticAnyListeners = [
...anyListeners
];
await resolvedPromise;

@@ -120,3 +138,5 @@ for (const listener of staticListeners) {

listenerCount(eventNames) {
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [eventNames];
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [
eventNames
];
let count = 0;

@@ -141,3 +161,5 @@ for (const eventName of eventNamesArray) {

off(eventNames, listener) {
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [eventNames];
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [
eventNames
];
for (const eventName of eventNamesArray) {

@@ -154,3 +176,6 @@ const set = this.getListeners(eventName);

if (!isMetaEvent(eventName)) {
forget(this.emitMetaEvent("listenerRemoved", { eventName, listener }));
forget(this.emitMetaEvent("listenerRemoved", {
eventName,
listener
}));
}

@@ -163,6 +188,10 @@ }

typedMap?.delete(listener);
forget(this.emitMetaEvent("listenerRemoved", { listener }));
forget(this.emitMetaEvent("listenerRemoved", {
listener
}));
}
on(eventNames, listener, filter) {
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [eventNames];
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [
eventNames
];
for (const eventName of eventNamesArray) {

@@ -175,6 +204,12 @@ let set = this.getListeners(eventName);

}
set.add({ filter, listener });
set.add({
filter,
listener
});
this.logIfDebugEnabled("subscribe", eventName);
if (!isMetaEvent(eventName)) {
forget(this.emitMetaEvent("listenerAdded", { eventName, listener }));
forget(this.emitMetaEvent("listenerAdded", {
eventName,
listener
}));
}

@@ -187,10 +222,12 @@ }

_Events.anyMap.get(this)?.add(listener);
forget(this.emitMetaEvent("listenerAdded", { listener }));
forget(this.emitMetaEvent("listenerAdded", {
listener
}));
return this.offAny.bind(this, listener);
}
once(eventName, listener) {
const subListener = async (args) => {
const subListener = /* @__PURE__ */ __name(async (args) => {
this.off(eventName, subListener);
await this.safeCallListener(eventName, args, listener);
};
}, "subListener");
this.on(eventName, subListener);

@@ -205,6 +242,12 @@ return this.off.bind(this, eventName, subListener);

const listeners = this.getListeners(eventName) ?? /* @__PURE__ */ new Set();
const filteredListeners = [...listeners.values()].filter((value) => filter ? value.listener : true).map((info) => info.listener);
const filteredListeners = [
...listeners.values()
].filter((value) => filter ? value.listener : true).map((info) => info.listener);
const anyListeners = assertEx(_Events.anyMap.get(this));
const staticListeners = [...filteredListeners];
const staticAnyListeners = isMetaEvent(eventName) ? [] : [...anyListeners];
const staticListeners = [
...filteredListeners
];
const staticAnyListeners = isMetaEvent(eventName) ? [] : [
...anyListeners
];
await resolvedPromise;

@@ -228,6 +271,12 @@ await Promise.all([

const listeners = this.getListeners(eventName) ?? /* @__PURE__ */ new Set();
const filteredListeners = [...listeners.values()].map((info) => info.listener);
const filteredListeners = [
...listeners.values()
].map((info) => info.listener);
const anyListeners = assertEx(_Events.anyMap.get(this));
const staticListeners = [...filteredListeners];
const staticAnyListeners = isMetaEvent(eventName) ? [] : [...anyListeners];
const staticListeners = [
...filteredListeners
];
const staticAnyListeners = isMetaEvent(eventName) ? [] : [
...anyListeners
];
await resolvedPromise;

@@ -234,0 +283,0 @@ await Promise.all([

@@ -0,1 +1,4 @@

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
// src/Events/Events.ts

@@ -8,4 +11,7 @@ import { assertEx } from "@xylabs/assert";

var resolvedPromise = Promise.resolve();
var isMetaEvent = (eventName) => eventName === "listenerAdded" || eventName === "listenerRemoved";
var isMetaEvent = /* @__PURE__ */ __name((eventName) => eventName === "listenerAdded" || eventName === "listenerRemoved", "isMetaEvent");
var Events = class _Events extends Base {
static {
__name(this, "Events");
}
static anyMap = /* @__PURE__ */ new WeakMap();

@@ -18,3 +24,5 @@ static eventsMap = /* @__PURE__ */ new WeakMap();

constructor(params = {}) {
const mutatedParams = { ...params };
const mutatedParams = {
...params
};
if (mutatedParams.debug) {

@@ -43,3 +51,5 @@ mutatedParams.debug.logger = mutatedParams.debug.logger ?? ((type, debugName, eventName, eventData) => {

}
const { env } = globalThis.process ?? { env: {} };
const { env } = globalThis.process ?? {
env: {}
};
return env.DEBUG === "events" || env.DEBUG === "*" || _Events.isGlobalDebugEnabled;

@@ -54,3 +64,5 @@ }

clearListeners(eventNames) {
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [eventNames];
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [
eventNames
];
for (const eventName of eventNamesArray) {

@@ -89,3 +101,3 @@ this.logIfDebugEnabled("clear", eventName);

}
const filterMatch = (args, filter) => {
const filterMatch = /* @__PURE__ */ __name((args, filter) => {
if (filter) {

@@ -102,9 +114,15 @@ switch (typeof filter) {

return true;
};
}, "filterMatch");
this.logIfDebugEnabled("emitSerial", eventName, eventArgs);
const listeners = this.getListeners(eventName) ?? /* @__PURE__ */ new Set();
const filteredListeners = [...listeners.values()].filter((value) => value.filter ? filterMatch(eventArgs, value.filter) : true).map((info) => info.listener);
const filteredListeners = [
...listeners.values()
].filter((value) => value.filter ? filterMatch(eventArgs, value.filter) : true).map((info) => info.listener);
const anyListeners = assertEx(_Events.anyMap.get(this));
const staticListeners = [...filteredListeners];
const staticAnyListeners = [...anyListeners];
const staticListeners = [
...filteredListeners
];
const staticAnyListeners = [
...anyListeners
];
await resolvedPromise;

@@ -120,3 +138,5 @@ for (const listener of staticListeners) {

listenerCount(eventNames) {
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [eventNames];
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [
eventNames
];
let count = 0;

@@ -141,3 +161,5 @@ for (const eventName of eventNamesArray) {

off(eventNames, listener) {
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [eventNames];
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [
eventNames
];
for (const eventName of eventNamesArray) {

@@ -154,3 +176,6 @@ const set = this.getListeners(eventName);

if (!isMetaEvent(eventName)) {
forget(this.emitMetaEvent("listenerRemoved", { eventName, listener }));
forget(this.emitMetaEvent("listenerRemoved", {
eventName,
listener
}));
}

@@ -163,6 +188,10 @@ }

typedMap?.delete(listener);
forget(this.emitMetaEvent("listenerRemoved", { listener }));
forget(this.emitMetaEvent("listenerRemoved", {
listener
}));
}
on(eventNames, listener, filter) {
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [eventNames];
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [
eventNames
];
for (const eventName of eventNamesArray) {

@@ -175,6 +204,12 @@ let set = this.getListeners(eventName);

}
set.add({ filter, listener });
set.add({
filter,
listener
});
this.logIfDebugEnabled("subscribe", eventName);
if (!isMetaEvent(eventName)) {
forget(this.emitMetaEvent("listenerAdded", { eventName, listener }));
forget(this.emitMetaEvent("listenerAdded", {
eventName,
listener
}));
}

@@ -187,10 +222,12 @@ }

_Events.anyMap.get(this)?.add(listener);
forget(this.emitMetaEvent("listenerAdded", { listener }));
forget(this.emitMetaEvent("listenerAdded", {
listener
}));
return this.offAny.bind(this, listener);
}
once(eventName, listener) {
const subListener = async (args) => {
const subListener = /* @__PURE__ */ __name(async (args) => {
this.off(eventName, subListener);
await this.safeCallListener(eventName, args, listener);
};
}, "subListener");
this.on(eventName, subListener);

@@ -205,6 +242,12 @@ return this.off.bind(this, eventName, subListener);

const listeners = this.getListeners(eventName) ?? /* @__PURE__ */ new Set();
const filteredListeners = [...listeners.values()].filter((value) => filter ? value.listener : true).map((info) => info.listener);
const filteredListeners = [
...listeners.values()
].filter((value) => filter ? value.listener : true).map((info) => info.listener);
const anyListeners = assertEx(_Events.anyMap.get(this));
const staticListeners = [...filteredListeners];
const staticAnyListeners = isMetaEvent(eventName) ? [] : [...anyListeners];
const staticListeners = [
...filteredListeners
];
const staticAnyListeners = isMetaEvent(eventName) ? [] : [
...anyListeners
];
await resolvedPromise;

@@ -228,6 +271,12 @@ await Promise.all([

const listeners = this.getListeners(eventName) ?? /* @__PURE__ */ new Set();
const filteredListeners = [...listeners.values()].map((info) => info.listener);
const filteredListeners = [
...listeners.values()
].map((info) => info.listener);
const anyListeners = assertEx(_Events.anyMap.get(this));
const staticListeners = [...filteredListeners];
const staticAnyListeners = isMetaEvent(eventName) ? [] : [...anyListeners];
const staticListeners = [
...filteredListeners
];
const staticAnyListeners = isMetaEvent(eventName) ? [] : [
...anyListeners
];
await resolvedPromise;

@@ -234,0 +283,0 @@ await Promise.all([

@@ -0,1 +1,6 @@

var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
// src/Events/Events.ts

@@ -8,12 +13,10 @@ import { assertEx } from "@xylabs/assert";

var resolvedPromise = Promise.resolve();
var isMetaEvent = (eventName) => eventName === "listenerAdded" || eventName === "listenerRemoved";
var Events = class _Events extends Base {
static anyMap = /* @__PURE__ */ new WeakMap();
static eventsMap = /* @__PURE__ */ new WeakMap();
static canEmitMetaEvents = false;
static isGlobalDebugEnabled = false;
var isMetaEvent = /* @__PURE__ */ __name((eventName) => eventName === "listenerAdded" || eventName === "listenerRemoved", "isMetaEvent");
var _Events = class _Events extends Base {
//this is here to be able to query the type, not use
eventData = {};
constructor(params = {}) {
const mutatedParams = { ...params };
const mutatedParams = {
...params
};
if (mutatedParams.debug) {

@@ -44,3 +47,5 @@ mutatedParams.debug.logger = mutatedParams.debug.logger ?? ((type, debugName, eventName, eventData) => {

}
const { env } = globalThis.process ?? { env: {} };
const { env } = globalThis.process ?? {
env: {}
};
return env.DEBUG === "events" || env.DEBUG === "*" || _Events.isGlobalDebugEnabled;

@@ -56,3 +61,5 @@ }

var _a, _b;
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [eventNames];
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [
eventNames
];
for (const eventName of eventNamesArray) {

@@ -91,3 +98,3 @@ this.logIfDebugEnabled("clear", eventName);

}
const filterMatch = (args, filter) => {
const filterMatch = /* @__PURE__ */ __name((args, filter) => {
if (filter) {

@@ -104,9 +111,15 @@ switch (typeof filter) {

return true;
};
}, "filterMatch");
this.logIfDebugEnabled("emitSerial", eventName, eventArgs);
const listeners = this.getListeners(eventName) ?? /* @__PURE__ */ new Set();
const filteredListeners = [...listeners.values()].filter((value) => value.filter ? filterMatch(eventArgs, value.filter) : true).map((info) => info.listener);
const filteredListeners = [
...listeners.values()
].filter((value) => value.filter ? filterMatch(eventArgs, value.filter) : true).map((info) => info.listener);
const anyListeners = assertEx(_Events.anyMap.get(this));
const staticListeners = [...filteredListeners];
const staticAnyListeners = [...anyListeners];
const staticListeners = [
...filteredListeners
];
const staticAnyListeners = [
...anyListeners
];
await resolvedPromise;

@@ -123,3 +136,5 @@ for (const listener of staticListeners) {

var _a;
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [eventNames];
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [
eventNames
];
let count = 0;

@@ -145,3 +160,5 @@ for (const eventName of eventNamesArray) {

off(eventNames, listener) {
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [eventNames];
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [
eventNames
];
for (const eventName of eventNamesArray) {

@@ -158,3 +175,6 @@ const set = this.getListeners(eventName);

if (!isMetaEvent(eventName)) {
forget(this.emitMetaEvent("listenerRemoved", { eventName, listener }));
forget(this.emitMetaEvent("listenerRemoved", {
eventName,
listener
}));
}

@@ -167,6 +187,10 @@ }

typedMap == null ? void 0 : typedMap.delete(listener);
forget(this.emitMetaEvent("listenerRemoved", { listener }));
forget(this.emitMetaEvent("listenerRemoved", {
listener
}));
}
on(eventNames, listener, filter) {
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [eventNames];
const eventNamesArray = Array.isArray(eventNames) ? eventNames : [
eventNames
];
for (const eventName of eventNamesArray) {

@@ -179,6 +203,12 @@ let set = this.getListeners(eventName);

}
set.add({ filter, listener });
set.add({
filter,
listener
});
this.logIfDebugEnabled("subscribe", eventName);
if (!isMetaEvent(eventName)) {
forget(this.emitMetaEvent("listenerAdded", { eventName, listener }));
forget(this.emitMetaEvent("listenerAdded", {
eventName,
listener
}));
}

@@ -192,10 +222,12 @@ }

(_a = _Events.anyMap.get(this)) == null ? void 0 : _a.add(listener);
forget(this.emitMetaEvent("listenerAdded", { listener }));
forget(this.emitMetaEvent("listenerAdded", {
listener
}));
return this.offAny.bind(this, listener);
}
once(eventName, listener) {
const subListener = async (args) => {
const subListener = /* @__PURE__ */ __name(async (args) => {
this.off(eventName, subListener);
await this.safeCallListener(eventName, args, listener);
};
}, "subListener");
this.on(eventName, subListener);

@@ -210,6 +242,12 @@ return this.off.bind(this, eventName, subListener);

const listeners = this.getListeners(eventName) ?? /* @__PURE__ */ new Set();
const filteredListeners = [...listeners.values()].filter((value) => filter ? value.listener : true).map((info) => info.listener);
const filteredListeners = [
...listeners.values()
].filter((value) => filter ? value.listener : true).map((info) => info.listener);
const anyListeners = assertEx(_Events.anyMap.get(this));
const staticListeners = [...filteredListeners];
const staticAnyListeners = isMetaEvent(eventName) ? [] : [...anyListeners];
const staticListeners = [
...filteredListeners
];
const staticAnyListeners = isMetaEvent(eventName) ? [] : [
...anyListeners
];
await resolvedPromise;

@@ -233,6 +271,12 @@ await Promise.all([

const listeners = this.getListeners(eventName) ?? /* @__PURE__ */ new Set();
const filteredListeners = [...listeners.values()].map((info) => info.listener);
const filteredListeners = [
...listeners.values()
].map((info) => info.listener);
const anyListeners = assertEx(_Events.anyMap.get(this));
const staticListeners = [...filteredListeners];
const staticAnyListeners = isMetaEvent(eventName) ? [] : [...anyListeners];
const staticListeners = [
...filteredListeners
];
const staticAnyListeners = isMetaEvent(eventName) ? [] : [
...anyListeners
];
await resolvedPromise;

@@ -278,2 +322,8 @@ await Promise.all([

};
__name(_Events, "Events");
__publicField(_Events, "anyMap", /* @__PURE__ */ new WeakMap());
__publicField(_Events, "eventsMap", /* @__PURE__ */ new WeakMap());
__publicField(_Events, "canEmitMetaEvents", false);
__publicField(_Events, "isGlobalDebugEnabled", false);
var Events = _Events;
export {

@@ -280,0 +330,0 @@ Events

@@ -13,13 +13,13 @@ {

"dependencies": {
"@xylabs/assert": "^3.6.5",
"@xylabs/error": "^3.6.5",
"@xylabs/forget": "^3.6.5",
"@xylabs/object": "^3.6.5",
"@xylabs/promise": "^3.6.5"
"@xylabs/assert": "^3.6.6",
"@xylabs/error": "^3.6.6",
"@xylabs/forget": "^3.6.6",
"@xylabs/object": "^3.6.6",
"@xylabs/promise": "^3.6.6"
},
"devDependencies": {
"@xylabs/delay": "^3.6.5",
"@xylabs/ts-scripts-yarn3": "^3.13.9",
"@xylabs/tsconfig": "^3.13.9",
"@xylabs/tsconfig-jest": "^3.13.9",
"@xylabs/delay": "^3.6.6",
"@xylabs/ts-scripts-yarn3": "^3.14.1",
"@xylabs/tsconfig": "^3.14.1",
"@xylabs/tsconfig-jest": "^3.14.1",
"typescript": "^5.5.4"

@@ -66,4 +66,4 @@ },

"sideEffects": false,
"version": "2.110.13",
"version": "2.110.14",
"type": "module"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc