@openfeature/web-sdk
Advanced tools
Comparing version 0.4.14 to 0.4.15
@@ -34,371 +34,181 @@ "use strict"; | ||
// ../../node_modules/events/events.js | ||
var require_events = __commonJS({ | ||
"../../node_modules/events/events.js"(exports, module2) { | ||
// ../../node_modules/eventemitter3/index.js | ||
var require_eventemitter3 = __commonJS({ | ||
"../../node_modules/eventemitter3/index.js"(exports, module2) { | ||
"use strict"; | ||
var R = typeof Reflect === "object" ? Reflect : null; | ||
var ReflectApply = R && typeof R.apply === "function" ? R.apply : function ReflectApply2(target, receiver, args) { | ||
return Function.prototype.apply.call(target, receiver, args); | ||
}; | ||
var ReflectOwnKeys; | ||
if (R && typeof R.ownKeys === "function") { | ||
ReflectOwnKeys = R.ownKeys; | ||
} else if (Object.getOwnPropertySymbols) { | ||
ReflectOwnKeys = function ReflectOwnKeys2(target) { | ||
return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target)); | ||
}; | ||
} else { | ||
ReflectOwnKeys = function ReflectOwnKeys2(target) { | ||
return Object.getOwnPropertyNames(target); | ||
}; | ||
var has = Object.prototype.hasOwnProperty; | ||
var prefix = "~"; | ||
function Events() { | ||
} | ||
function ProcessEmitWarning(warning) { | ||
if (console && console.warn) | ||
console.warn(warning); | ||
if (Object.create) { | ||
Events.prototype = /* @__PURE__ */ Object.create(null); | ||
if (!new Events().__proto__) | ||
prefix = false; | ||
} | ||
var NumberIsNaN = Number.isNaN || function NumberIsNaN2(value) { | ||
return value !== value; | ||
}; | ||
function EventEmitter2() { | ||
EventEmitter2.init.call(this); | ||
function EE(fn, context, once) { | ||
this.fn = fn; | ||
this.context = context; | ||
this.once = once || false; | ||
} | ||
module2.exports = EventEmitter2; | ||
module2.exports.once = once; | ||
EventEmitter2.EventEmitter = EventEmitter2; | ||
EventEmitter2.prototype._events = void 0; | ||
EventEmitter2.prototype._eventsCount = 0; | ||
EventEmitter2.prototype._maxListeners = void 0; | ||
var defaultMaxListeners = 10; | ||
function checkListener(listener) { | ||
if (typeof listener !== "function") { | ||
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener); | ||
function addListener(emitter, event, fn, context, once) { | ||
if (typeof fn !== "function") { | ||
throw new TypeError("The listener must be a function"); | ||
} | ||
var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event; | ||
if (!emitter._events[evt]) | ||
emitter._events[evt] = listener, emitter._eventsCount++; | ||
else if (!emitter._events[evt].fn) | ||
emitter._events[evt].push(listener); | ||
else | ||
emitter._events[evt] = [emitter._events[evt], listener]; | ||
return emitter; | ||
} | ||
Object.defineProperty(EventEmitter2, "defaultMaxListeners", { | ||
enumerable: true, | ||
get: function() { | ||
return defaultMaxListeners; | ||
}, | ||
set: function(arg) { | ||
if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) { | ||
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + "."); | ||
} | ||
defaultMaxListeners = arg; | ||
function clearEvent(emitter, evt) { | ||
if (--emitter._eventsCount === 0) | ||
emitter._events = new Events(); | ||
else | ||
delete emitter._events[evt]; | ||
} | ||
function EventEmitter2() { | ||
this._events = new Events(); | ||
this._eventsCount = 0; | ||
} | ||
EventEmitter2.prototype.eventNames = function eventNames() { | ||
var names = [], events, name; | ||
if (this._eventsCount === 0) | ||
return names; | ||
for (name in events = this._events) { | ||
if (has.call(events, name)) | ||
names.push(prefix ? name.slice(1) : name); | ||
} | ||
}); | ||
EventEmitter2.init = function() { | ||
if (this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) { | ||
this._events = /* @__PURE__ */ Object.create(null); | ||
this._eventsCount = 0; | ||
if (Object.getOwnPropertySymbols) { | ||
return names.concat(Object.getOwnPropertySymbols(events)); | ||
} | ||
this._maxListeners = this._maxListeners || void 0; | ||
return names; | ||
}; | ||
EventEmitter2.prototype.setMaxListeners = function setMaxListeners(n) { | ||
if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) { | ||
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + "."); | ||
EventEmitter2.prototype.listeners = function listeners(event) { | ||
var evt = prefix ? prefix + event : event, handlers = this._events[evt]; | ||
if (!handlers) | ||
return []; | ||
if (handlers.fn) | ||
return [handlers.fn]; | ||
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) { | ||
ee[i] = handlers[i].fn; | ||
} | ||
this._maxListeners = n; | ||
return this; | ||
return ee; | ||
}; | ||
function _getMaxListeners(that) { | ||
if (that._maxListeners === void 0) | ||
return EventEmitter2.defaultMaxListeners; | ||
return that._maxListeners; | ||
} | ||
EventEmitter2.prototype.getMaxListeners = function getMaxListeners() { | ||
return _getMaxListeners(this); | ||
EventEmitter2.prototype.listenerCount = function listenerCount(event) { | ||
var evt = prefix ? prefix + event : event, listeners = this._events[evt]; | ||
if (!listeners) | ||
return 0; | ||
if (listeners.fn) | ||
return 1; | ||
return listeners.length; | ||
}; | ||
EventEmitter2.prototype.emit = function emit(type) { | ||
var args = []; | ||
for (var i = 1; i < arguments.length; i++) | ||
args.push(arguments[i]); | ||
var doError = type === "error"; | ||
var events = this._events; | ||
if (events !== void 0) | ||
doError = doError && events.error === void 0; | ||
else if (!doError) | ||
EventEmitter2.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { | ||
var evt = prefix ? prefix + event : event; | ||
if (!this._events[evt]) | ||
return false; | ||
if (doError) { | ||
var er; | ||
if (args.length > 0) | ||
er = args[0]; | ||
if (er instanceof Error) { | ||
throw er; | ||
var listeners = this._events[evt], len = arguments.length, args, i; | ||
if (listeners.fn) { | ||
if (listeners.once) | ||
this.removeListener(event, listeners.fn, void 0, true); | ||
switch (len) { | ||
case 1: | ||
return listeners.fn.call(listeners.context), true; | ||
case 2: | ||
return listeners.fn.call(listeners.context, a1), true; | ||
case 3: | ||
return listeners.fn.call(listeners.context, a1, a2), true; | ||
case 4: | ||
return listeners.fn.call(listeners.context, a1, a2, a3), true; | ||
case 5: | ||
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; | ||
case 6: | ||
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; | ||
} | ||
var err = new Error("Unhandled error." + (er ? " (" + er.message + ")" : "")); | ||
err.context = er; | ||
throw err; | ||
} | ||
var handler = events[type]; | ||
if (handler === void 0) | ||
return false; | ||
if (typeof handler === "function") { | ||
ReflectApply(handler, this, args); | ||
} else { | ||
var len = handler.length; | ||
var listeners = arrayClone(handler, len); | ||
for (var i = 0; i < len; ++i) | ||
ReflectApply(listeners[i], this, args); | ||
} | ||
return true; | ||
}; | ||
function _addListener(target, type, listener, prepend) { | ||
var m; | ||
var events; | ||
var existing; | ||
checkListener(listener); | ||
events = target._events; | ||
if (events === void 0) { | ||
events = target._events = /* @__PURE__ */ Object.create(null); | ||
target._eventsCount = 0; | ||
} else { | ||
if (events.newListener !== void 0) { | ||
target.emit( | ||
"newListener", | ||
type, | ||
listener.listener ? listener.listener : listener | ||
); | ||
events = target._events; | ||
for (i = 1, args = new Array(len - 1); i < len; i++) { | ||
args[i - 1] = arguments[i]; | ||
} | ||
existing = events[type]; | ||
} | ||
if (existing === void 0) { | ||
existing = events[type] = listener; | ||
++target._eventsCount; | ||
listeners.fn.apply(listeners.context, args); | ||
} else { | ||
if (typeof existing === "function") { | ||
existing = events[type] = prepend ? [listener, existing] : [existing, listener]; | ||
} else if (prepend) { | ||
existing.unshift(listener); | ||
} else { | ||
existing.push(listener); | ||
var length = listeners.length, j; | ||
for (i = 0; i < length; i++) { | ||
if (listeners[i].once) | ||
this.removeListener(event, listeners[i].fn, void 0, true); | ||
switch (len) { | ||
case 1: | ||
listeners[i].fn.call(listeners[i].context); | ||
break; | ||
case 2: | ||
listeners[i].fn.call(listeners[i].context, a1); | ||
break; | ||
case 3: | ||
listeners[i].fn.call(listeners[i].context, a1, a2); | ||
break; | ||
case 4: | ||
listeners[i].fn.call(listeners[i].context, a1, a2, a3); | ||
break; | ||
default: | ||
if (!args) | ||
for (j = 1, args = new Array(len - 1); j < len; j++) { | ||
args[j - 1] = arguments[j]; | ||
} | ||
listeners[i].fn.apply(listeners[i].context, args); | ||
} | ||
} | ||
m = _getMaxListeners(target); | ||
if (m > 0 && existing.length > m && !existing.warned) { | ||
existing.warned = true; | ||
var w = new Error("Possible EventEmitter memory leak detected. " + existing.length + " " + String(type) + " listeners added. Use emitter.setMaxListeners() to increase limit"); | ||
w.name = "MaxListenersExceededWarning"; | ||
w.emitter = target; | ||
w.type = type; | ||
w.count = existing.length; | ||
ProcessEmitWarning(w); | ||
} | ||
} | ||
return target; | ||
} | ||
EventEmitter2.prototype.addListener = function addListener(type, listener) { | ||
return _addListener(this, type, listener, false); | ||
return true; | ||
}; | ||
EventEmitter2.prototype.on = EventEmitter2.prototype.addListener; | ||
EventEmitter2.prototype.prependListener = function prependListener(type, listener) { | ||
return _addListener(this, type, listener, true); | ||
EventEmitter2.prototype.on = function on(event, fn, context) { | ||
return addListener(this, event, fn, context, false); | ||
}; | ||
function onceWrapper() { | ||
if (!this.fired) { | ||
this.target.removeListener(this.type, this.wrapFn); | ||
this.fired = true; | ||
if (arguments.length === 0) | ||
return this.listener.call(this.target); | ||
return this.listener.apply(this.target, arguments); | ||
} | ||
} | ||
function _onceWrap(target, type, listener) { | ||
var state = { fired: false, wrapFn: void 0, target, type, listener }; | ||
var wrapped = onceWrapper.bind(state); | ||
wrapped.listener = listener; | ||
state.wrapFn = wrapped; | ||
return wrapped; | ||
} | ||
EventEmitter2.prototype.once = function once2(type, listener) { | ||
checkListener(listener); | ||
this.on(type, _onceWrap(this, type, listener)); | ||
return this; | ||
EventEmitter2.prototype.once = function once(event, fn, context) { | ||
return addListener(this, event, fn, context, true); | ||
}; | ||
EventEmitter2.prototype.prependOnceListener = function prependOnceListener(type, listener) { | ||
checkListener(listener); | ||
this.prependListener(type, _onceWrap(this, type, listener)); | ||
return this; | ||
}; | ||
EventEmitter2.prototype.removeListener = function removeListener(type, listener) { | ||
var list, events, position, i, originalListener; | ||
checkListener(listener); | ||
events = this._events; | ||
if (events === void 0) | ||
EventEmitter2.prototype.removeListener = function removeListener(event, fn, context, once) { | ||
var evt = prefix ? prefix + event : event; | ||
if (!this._events[evt]) | ||
return this; | ||
list = events[type]; | ||
if (list === void 0) | ||
if (!fn) { | ||
clearEvent(this, evt); | ||
return this; | ||
if (list === listener || list.listener === listener) { | ||
if (--this._eventsCount === 0) | ||
this._events = /* @__PURE__ */ Object.create(null); | ||
else { | ||
delete events[type]; | ||
if (events.removeListener) | ||
this.emit("removeListener", type, list.listener || listener); | ||
} | ||
var listeners = this._events[evt]; | ||
if (listeners.fn) { | ||
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) { | ||
clearEvent(this, evt); | ||
} | ||
} else if (typeof list !== "function") { | ||
position = -1; | ||
for (i = list.length - 1; i >= 0; i--) { | ||
if (list[i] === listener || list[i].listener === listener) { | ||
originalListener = list[i].listener; | ||
position = i; | ||
break; | ||
} else { | ||
for (var i = 0, events = [], length = listeners.length; i < length; i++) { | ||
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) { | ||
events.push(listeners[i]); | ||
} | ||
} | ||
if (position < 0) | ||
return this; | ||
if (position === 0) | ||
list.shift(); | ||
else { | ||
spliceOne(list, position); | ||
} | ||
if (list.length === 1) | ||
events[type] = list[0]; | ||
if (events.removeListener !== void 0) | ||
this.emit("removeListener", type, originalListener || listener); | ||
if (events.length) | ||
this._events[evt] = events.length === 1 ? events[0] : events; | ||
else | ||
clearEvent(this, evt); | ||
} | ||
return this; | ||
}; | ||
EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener; | ||
EventEmitter2.prototype.removeAllListeners = function removeAllListeners(type) { | ||
var listeners, events, i; | ||
events = this._events; | ||
if (events === void 0) | ||
return this; | ||
if (events.removeListener === void 0) { | ||
if (arguments.length === 0) { | ||
this._events = /* @__PURE__ */ Object.create(null); | ||
this._eventsCount = 0; | ||
} else if (events[type] !== void 0) { | ||
if (--this._eventsCount === 0) | ||
this._events = /* @__PURE__ */ Object.create(null); | ||
else | ||
delete events[type]; | ||
} | ||
return this; | ||
} | ||
if (arguments.length === 0) { | ||
var keys = Object.keys(events); | ||
var key; | ||
for (i = 0; i < keys.length; ++i) { | ||
key = keys[i]; | ||
if (key === "removeListener") | ||
continue; | ||
this.removeAllListeners(key); | ||
} | ||
this.removeAllListeners("removeListener"); | ||
this._events = /* @__PURE__ */ Object.create(null); | ||
EventEmitter2.prototype.removeAllListeners = function removeAllListeners(event) { | ||
var evt; | ||
if (event) { | ||
evt = prefix ? prefix + event : event; | ||
if (this._events[evt]) | ||
clearEvent(this, evt); | ||
} else { | ||
this._events = new Events(); | ||
this._eventsCount = 0; | ||
return this; | ||
} | ||
listeners = events[type]; | ||
if (typeof listeners === "function") { | ||
this.removeListener(type, listeners); | ||
} else if (listeners !== void 0) { | ||
for (i = listeners.length - 1; i >= 0; i--) { | ||
this.removeListener(type, listeners[i]); | ||
} | ||
} | ||
return this; | ||
}; | ||
function _listeners(target, type, unwrap) { | ||
var events = target._events; | ||
if (events === void 0) | ||
return []; | ||
var evlistener = events[type]; | ||
if (evlistener === void 0) | ||
return []; | ||
if (typeof evlistener === "function") | ||
return unwrap ? [evlistener.listener || evlistener] : [evlistener]; | ||
return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); | ||
EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener; | ||
EventEmitter2.prototype.addListener = EventEmitter2.prototype.on; | ||
EventEmitter2.prefixed = prefix; | ||
EventEmitter2.EventEmitter = EventEmitter2; | ||
if ("undefined" !== typeof module2) { | ||
module2.exports = EventEmitter2; | ||
} | ||
EventEmitter2.prototype.listeners = function listeners(type) { | ||
return _listeners(this, type, true); | ||
}; | ||
EventEmitter2.prototype.rawListeners = function rawListeners(type) { | ||
return _listeners(this, type, false); | ||
}; | ||
EventEmitter2.listenerCount = function(emitter, type) { | ||
if (typeof emitter.listenerCount === "function") { | ||
return emitter.listenerCount(type); | ||
} else { | ||
return listenerCount.call(emitter, type); | ||
} | ||
}; | ||
EventEmitter2.prototype.listenerCount = listenerCount; | ||
function listenerCount(type) { | ||
var events = this._events; | ||
if (events !== void 0) { | ||
var evlistener = events[type]; | ||
if (typeof evlistener === "function") { | ||
return 1; | ||
} else if (evlistener !== void 0) { | ||
return evlistener.length; | ||
} | ||
} | ||
return 0; | ||
} | ||
EventEmitter2.prototype.eventNames = function eventNames() { | ||
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; | ||
}; | ||
function arrayClone(arr, n) { | ||
var copy = new Array(n); | ||
for (var i = 0; i < n; ++i) | ||
copy[i] = arr[i]; | ||
return copy; | ||
} | ||
function spliceOne(list, index) { | ||
for (; index + 1 < list.length; index++) | ||
list[index] = list[index + 1]; | ||
list.pop(); | ||
} | ||
function unwrapListeners(arr) { | ||
var ret = new Array(arr.length); | ||
for (var i = 0; i < ret.length; ++i) { | ||
ret[i] = arr[i].listener || arr[i]; | ||
} | ||
return ret; | ||
} | ||
function once(emitter, name) { | ||
return new Promise(function(resolve, reject) { | ||
function errorListener(err) { | ||
emitter.removeListener(name, resolver); | ||
reject(err); | ||
} | ||
function resolver() { | ||
if (typeof emitter.removeListener === "function") { | ||
emitter.removeListener("error", errorListener); | ||
} | ||
resolve([].slice.call(arguments)); | ||
} | ||
; | ||
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true }); | ||
if (name !== "error") { | ||
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); | ||
} | ||
}); | ||
} | ||
function addErrorHandlerIfEventEmitter(emitter, handler, flags) { | ||
if (typeof emitter.on === "function") { | ||
eventTargetAgnosticAddListener(emitter, "error", handler, flags); | ||
} | ||
} | ||
function eventTargetAgnosticAddListener(emitter, name, listener, flags) { | ||
if (typeof emitter.on === "function") { | ||
if (flags.once) { | ||
emitter.once(name, listener); | ||
} else { | ||
emitter.on(name, listener); | ||
} | ||
} else if (typeof emitter.addEventListener === "function") { | ||
emitter.addEventListener(name, function wrapListener(arg) { | ||
if (flags.once) { | ||
emitter.removeEventListener(name, wrapListener); | ||
} | ||
listener(arg); | ||
}); | ||
} else { | ||
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); | ||
} | ||
} | ||
} | ||
@@ -429,10 +239,11 @@ }); | ||
var import_core = require("@openfeature/core"); | ||
var import_events = __toESM(require_events()); | ||
// ../../node_modules/eventemitter3/index.mjs | ||
var import_index = __toESM(require_eventemitter3(), 1); | ||
// src/events/open-feature-event-emitter.ts | ||
var OpenFeatureEventEmitter = class extends import_core.GenericEventEmitter { | ||
eventEmitter = new import_events.EventEmitter({ captureRejections: true }); | ||
eventEmitter = new import_index.default(); | ||
constructor() { | ||
super(); | ||
this.eventEmitter.on("error", (err) => { | ||
this._logger?.error("Error running event handler:", err); | ||
}); | ||
} | ||
@@ -439,0 +250,0 @@ }; |
@@ -27,371 +27,181 @@ var __create = Object.create; | ||
// ../../node_modules/events/events.js | ||
var require_events = __commonJS({ | ||
"../../node_modules/events/events.js"(exports, module) { | ||
// ../../node_modules/eventemitter3/index.js | ||
var require_eventemitter3 = __commonJS({ | ||
"../../node_modules/eventemitter3/index.js"(exports, module) { | ||
"use strict"; | ||
var R = typeof Reflect === "object" ? Reflect : null; | ||
var ReflectApply = R && typeof R.apply === "function" ? R.apply : function ReflectApply2(target, receiver, args) { | ||
return Function.prototype.apply.call(target, receiver, args); | ||
}; | ||
var ReflectOwnKeys; | ||
if (R && typeof R.ownKeys === "function") { | ||
ReflectOwnKeys = R.ownKeys; | ||
} else if (Object.getOwnPropertySymbols) { | ||
ReflectOwnKeys = function ReflectOwnKeys2(target) { | ||
return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target)); | ||
}; | ||
} else { | ||
ReflectOwnKeys = function ReflectOwnKeys2(target) { | ||
return Object.getOwnPropertyNames(target); | ||
}; | ||
var has = Object.prototype.hasOwnProperty; | ||
var prefix = "~"; | ||
function Events() { | ||
} | ||
function ProcessEmitWarning(warning) { | ||
if (console && console.warn) | ||
console.warn(warning); | ||
if (Object.create) { | ||
Events.prototype = /* @__PURE__ */ Object.create(null); | ||
if (!new Events().__proto__) | ||
prefix = false; | ||
} | ||
var NumberIsNaN = Number.isNaN || function NumberIsNaN2(value) { | ||
return value !== value; | ||
}; | ||
function EventEmitter2() { | ||
EventEmitter2.init.call(this); | ||
function EE(fn, context, once) { | ||
this.fn = fn; | ||
this.context = context; | ||
this.once = once || false; | ||
} | ||
module.exports = EventEmitter2; | ||
module.exports.once = once; | ||
EventEmitter2.EventEmitter = EventEmitter2; | ||
EventEmitter2.prototype._events = void 0; | ||
EventEmitter2.prototype._eventsCount = 0; | ||
EventEmitter2.prototype._maxListeners = void 0; | ||
var defaultMaxListeners = 10; | ||
function checkListener(listener) { | ||
if (typeof listener !== "function") { | ||
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener); | ||
function addListener(emitter, event, fn, context, once) { | ||
if (typeof fn !== "function") { | ||
throw new TypeError("The listener must be a function"); | ||
} | ||
var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event; | ||
if (!emitter._events[evt]) | ||
emitter._events[evt] = listener, emitter._eventsCount++; | ||
else if (!emitter._events[evt].fn) | ||
emitter._events[evt].push(listener); | ||
else | ||
emitter._events[evt] = [emitter._events[evt], listener]; | ||
return emitter; | ||
} | ||
Object.defineProperty(EventEmitter2, "defaultMaxListeners", { | ||
enumerable: true, | ||
get: function() { | ||
return defaultMaxListeners; | ||
}, | ||
set: function(arg) { | ||
if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) { | ||
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + "."); | ||
} | ||
defaultMaxListeners = arg; | ||
function clearEvent(emitter, evt) { | ||
if (--emitter._eventsCount === 0) | ||
emitter._events = new Events(); | ||
else | ||
delete emitter._events[evt]; | ||
} | ||
function EventEmitter2() { | ||
this._events = new Events(); | ||
this._eventsCount = 0; | ||
} | ||
EventEmitter2.prototype.eventNames = function eventNames() { | ||
var names = [], events, name; | ||
if (this._eventsCount === 0) | ||
return names; | ||
for (name in events = this._events) { | ||
if (has.call(events, name)) | ||
names.push(prefix ? name.slice(1) : name); | ||
} | ||
}); | ||
EventEmitter2.init = function() { | ||
if (this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) { | ||
this._events = /* @__PURE__ */ Object.create(null); | ||
this._eventsCount = 0; | ||
if (Object.getOwnPropertySymbols) { | ||
return names.concat(Object.getOwnPropertySymbols(events)); | ||
} | ||
this._maxListeners = this._maxListeners || void 0; | ||
return names; | ||
}; | ||
EventEmitter2.prototype.setMaxListeners = function setMaxListeners(n) { | ||
if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) { | ||
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + "."); | ||
EventEmitter2.prototype.listeners = function listeners(event) { | ||
var evt = prefix ? prefix + event : event, handlers = this._events[evt]; | ||
if (!handlers) | ||
return []; | ||
if (handlers.fn) | ||
return [handlers.fn]; | ||
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) { | ||
ee[i] = handlers[i].fn; | ||
} | ||
this._maxListeners = n; | ||
return this; | ||
return ee; | ||
}; | ||
function _getMaxListeners(that) { | ||
if (that._maxListeners === void 0) | ||
return EventEmitter2.defaultMaxListeners; | ||
return that._maxListeners; | ||
} | ||
EventEmitter2.prototype.getMaxListeners = function getMaxListeners() { | ||
return _getMaxListeners(this); | ||
EventEmitter2.prototype.listenerCount = function listenerCount(event) { | ||
var evt = prefix ? prefix + event : event, listeners = this._events[evt]; | ||
if (!listeners) | ||
return 0; | ||
if (listeners.fn) | ||
return 1; | ||
return listeners.length; | ||
}; | ||
EventEmitter2.prototype.emit = function emit(type) { | ||
var args = []; | ||
for (var i = 1; i < arguments.length; i++) | ||
args.push(arguments[i]); | ||
var doError = type === "error"; | ||
var events = this._events; | ||
if (events !== void 0) | ||
doError = doError && events.error === void 0; | ||
else if (!doError) | ||
EventEmitter2.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { | ||
var evt = prefix ? prefix + event : event; | ||
if (!this._events[evt]) | ||
return false; | ||
if (doError) { | ||
var er; | ||
if (args.length > 0) | ||
er = args[0]; | ||
if (er instanceof Error) { | ||
throw er; | ||
var listeners = this._events[evt], len = arguments.length, args, i; | ||
if (listeners.fn) { | ||
if (listeners.once) | ||
this.removeListener(event, listeners.fn, void 0, true); | ||
switch (len) { | ||
case 1: | ||
return listeners.fn.call(listeners.context), true; | ||
case 2: | ||
return listeners.fn.call(listeners.context, a1), true; | ||
case 3: | ||
return listeners.fn.call(listeners.context, a1, a2), true; | ||
case 4: | ||
return listeners.fn.call(listeners.context, a1, a2, a3), true; | ||
case 5: | ||
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; | ||
case 6: | ||
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; | ||
} | ||
var err = new Error("Unhandled error." + (er ? " (" + er.message + ")" : "")); | ||
err.context = er; | ||
throw err; | ||
} | ||
var handler = events[type]; | ||
if (handler === void 0) | ||
return false; | ||
if (typeof handler === "function") { | ||
ReflectApply(handler, this, args); | ||
} else { | ||
var len = handler.length; | ||
var listeners = arrayClone(handler, len); | ||
for (var i = 0; i < len; ++i) | ||
ReflectApply(listeners[i], this, args); | ||
} | ||
return true; | ||
}; | ||
function _addListener(target, type, listener, prepend) { | ||
var m; | ||
var events; | ||
var existing; | ||
checkListener(listener); | ||
events = target._events; | ||
if (events === void 0) { | ||
events = target._events = /* @__PURE__ */ Object.create(null); | ||
target._eventsCount = 0; | ||
} else { | ||
if (events.newListener !== void 0) { | ||
target.emit( | ||
"newListener", | ||
type, | ||
listener.listener ? listener.listener : listener | ||
); | ||
events = target._events; | ||
for (i = 1, args = new Array(len - 1); i < len; i++) { | ||
args[i - 1] = arguments[i]; | ||
} | ||
existing = events[type]; | ||
} | ||
if (existing === void 0) { | ||
existing = events[type] = listener; | ||
++target._eventsCount; | ||
listeners.fn.apply(listeners.context, args); | ||
} else { | ||
if (typeof existing === "function") { | ||
existing = events[type] = prepend ? [listener, existing] : [existing, listener]; | ||
} else if (prepend) { | ||
existing.unshift(listener); | ||
} else { | ||
existing.push(listener); | ||
var length = listeners.length, j; | ||
for (i = 0; i < length; i++) { | ||
if (listeners[i].once) | ||
this.removeListener(event, listeners[i].fn, void 0, true); | ||
switch (len) { | ||
case 1: | ||
listeners[i].fn.call(listeners[i].context); | ||
break; | ||
case 2: | ||
listeners[i].fn.call(listeners[i].context, a1); | ||
break; | ||
case 3: | ||
listeners[i].fn.call(listeners[i].context, a1, a2); | ||
break; | ||
case 4: | ||
listeners[i].fn.call(listeners[i].context, a1, a2, a3); | ||
break; | ||
default: | ||
if (!args) | ||
for (j = 1, args = new Array(len - 1); j < len; j++) { | ||
args[j - 1] = arguments[j]; | ||
} | ||
listeners[i].fn.apply(listeners[i].context, args); | ||
} | ||
} | ||
m = _getMaxListeners(target); | ||
if (m > 0 && existing.length > m && !existing.warned) { | ||
existing.warned = true; | ||
var w = new Error("Possible EventEmitter memory leak detected. " + existing.length + " " + String(type) + " listeners added. Use emitter.setMaxListeners() to increase limit"); | ||
w.name = "MaxListenersExceededWarning"; | ||
w.emitter = target; | ||
w.type = type; | ||
w.count = existing.length; | ||
ProcessEmitWarning(w); | ||
} | ||
} | ||
return target; | ||
} | ||
EventEmitter2.prototype.addListener = function addListener(type, listener) { | ||
return _addListener(this, type, listener, false); | ||
return true; | ||
}; | ||
EventEmitter2.prototype.on = EventEmitter2.prototype.addListener; | ||
EventEmitter2.prototype.prependListener = function prependListener(type, listener) { | ||
return _addListener(this, type, listener, true); | ||
EventEmitter2.prototype.on = function on(event, fn, context) { | ||
return addListener(this, event, fn, context, false); | ||
}; | ||
function onceWrapper() { | ||
if (!this.fired) { | ||
this.target.removeListener(this.type, this.wrapFn); | ||
this.fired = true; | ||
if (arguments.length === 0) | ||
return this.listener.call(this.target); | ||
return this.listener.apply(this.target, arguments); | ||
} | ||
} | ||
function _onceWrap(target, type, listener) { | ||
var state = { fired: false, wrapFn: void 0, target, type, listener }; | ||
var wrapped = onceWrapper.bind(state); | ||
wrapped.listener = listener; | ||
state.wrapFn = wrapped; | ||
return wrapped; | ||
} | ||
EventEmitter2.prototype.once = function once2(type, listener) { | ||
checkListener(listener); | ||
this.on(type, _onceWrap(this, type, listener)); | ||
return this; | ||
EventEmitter2.prototype.once = function once(event, fn, context) { | ||
return addListener(this, event, fn, context, true); | ||
}; | ||
EventEmitter2.prototype.prependOnceListener = function prependOnceListener(type, listener) { | ||
checkListener(listener); | ||
this.prependListener(type, _onceWrap(this, type, listener)); | ||
return this; | ||
}; | ||
EventEmitter2.prototype.removeListener = function removeListener(type, listener) { | ||
var list, events, position, i, originalListener; | ||
checkListener(listener); | ||
events = this._events; | ||
if (events === void 0) | ||
EventEmitter2.prototype.removeListener = function removeListener(event, fn, context, once) { | ||
var evt = prefix ? prefix + event : event; | ||
if (!this._events[evt]) | ||
return this; | ||
list = events[type]; | ||
if (list === void 0) | ||
if (!fn) { | ||
clearEvent(this, evt); | ||
return this; | ||
if (list === listener || list.listener === listener) { | ||
if (--this._eventsCount === 0) | ||
this._events = /* @__PURE__ */ Object.create(null); | ||
else { | ||
delete events[type]; | ||
if (events.removeListener) | ||
this.emit("removeListener", type, list.listener || listener); | ||
} | ||
var listeners = this._events[evt]; | ||
if (listeners.fn) { | ||
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) { | ||
clearEvent(this, evt); | ||
} | ||
} else if (typeof list !== "function") { | ||
position = -1; | ||
for (i = list.length - 1; i >= 0; i--) { | ||
if (list[i] === listener || list[i].listener === listener) { | ||
originalListener = list[i].listener; | ||
position = i; | ||
break; | ||
} else { | ||
for (var i = 0, events = [], length = listeners.length; i < length; i++) { | ||
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) { | ||
events.push(listeners[i]); | ||
} | ||
} | ||
if (position < 0) | ||
return this; | ||
if (position === 0) | ||
list.shift(); | ||
else { | ||
spliceOne(list, position); | ||
} | ||
if (list.length === 1) | ||
events[type] = list[0]; | ||
if (events.removeListener !== void 0) | ||
this.emit("removeListener", type, originalListener || listener); | ||
if (events.length) | ||
this._events[evt] = events.length === 1 ? events[0] : events; | ||
else | ||
clearEvent(this, evt); | ||
} | ||
return this; | ||
}; | ||
EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener; | ||
EventEmitter2.prototype.removeAllListeners = function removeAllListeners(type) { | ||
var listeners, events, i; | ||
events = this._events; | ||
if (events === void 0) | ||
return this; | ||
if (events.removeListener === void 0) { | ||
if (arguments.length === 0) { | ||
this._events = /* @__PURE__ */ Object.create(null); | ||
this._eventsCount = 0; | ||
} else if (events[type] !== void 0) { | ||
if (--this._eventsCount === 0) | ||
this._events = /* @__PURE__ */ Object.create(null); | ||
else | ||
delete events[type]; | ||
} | ||
return this; | ||
} | ||
if (arguments.length === 0) { | ||
var keys = Object.keys(events); | ||
var key; | ||
for (i = 0; i < keys.length; ++i) { | ||
key = keys[i]; | ||
if (key === "removeListener") | ||
continue; | ||
this.removeAllListeners(key); | ||
} | ||
this.removeAllListeners("removeListener"); | ||
this._events = /* @__PURE__ */ Object.create(null); | ||
EventEmitter2.prototype.removeAllListeners = function removeAllListeners(event) { | ||
var evt; | ||
if (event) { | ||
evt = prefix ? prefix + event : event; | ||
if (this._events[evt]) | ||
clearEvent(this, evt); | ||
} else { | ||
this._events = new Events(); | ||
this._eventsCount = 0; | ||
return this; | ||
} | ||
listeners = events[type]; | ||
if (typeof listeners === "function") { | ||
this.removeListener(type, listeners); | ||
} else if (listeners !== void 0) { | ||
for (i = listeners.length - 1; i >= 0; i--) { | ||
this.removeListener(type, listeners[i]); | ||
} | ||
} | ||
return this; | ||
}; | ||
function _listeners(target, type, unwrap) { | ||
var events = target._events; | ||
if (events === void 0) | ||
return []; | ||
var evlistener = events[type]; | ||
if (evlistener === void 0) | ||
return []; | ||
if (typeof evlistener === "function") | ||
return unwrap ? [evlistener.listener || evlistener] : [evlistener]; | ||
return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); | ||
EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener; | ||
EventEmitter2.prototype.addListener = EventEmitter2.prototype.on; | ||
EventEmitter2.prefixed = prefix; | ||
EventEmitter2.EventEmitter = EventEmitter2; | ||
if ("undefined" !== typeof module) { | ||
module.exports = EventEmitter2; | ||
} | ||
EventEmitter2.prototype.listeners = function listeners(type) { | ||
return _listeners(this, type, true); | ||
}; | ||
EventEmitter2.prototype.rawListeners = function rawListeners(type) { | ||
return _listeners(this, type, false); | ||
}; | ||
EventEmitter2.listenerCount = function(emitter, type) { | ||
if (typeof emitter.listenerCount === "function") { | ||
return emitter.listenerCount(type); | ||
} else { | ||
return listenerCount.call(emitter, type); | ||
} | ||
}; | ||
EventEmitter2.prototype.listenerCount = listenerCount; | ||
function listenerCount(type) { | ||
var events = this._events; | ||
if (events !== void 0) { | ||
var evlistener = events[type]; | ||
if (typeof evlistener === "function") { | ||
return 1; | ||
} else if (evlistener !== void 0) { | ||
return evlistener.length; | ||
} | ||
} | ||
return 0; | ||
} | ||
EventEmitter2.prototype.eventNames = function eventNames() { | ||
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; | ||
}; | ||
function arrayClone(arr, n) { | ||
var copy = new Array(n); | ||
for (var i = 0; i < n; ++i) | ||
copy[i] = arr[i]; | ||
return copy; | ||
} | ||
function spliceOne(list, index) { | ||
for (; index + 1 < list.length; index++) | ||
list[index] = list[index + 1]; | ||
list.pop(); | ||
} | ||
function unwrapListeners(arr) { | ||
var ret = new Array(arr.length); | ||
for (var i = 0; i < ret.length; ++i) { | ||
ret[i] = arr[i].listener || arr[i]; | ||
} | ||
return ret; | ||
} | ||
function once(emitter, name) { | ||
return new Promise(function(resolve, reject) { | ||
function errorListener(err) { | ||
emitter.removeListener(name, resolver); | ||
reject(err); | ||
} | ||
function resolver() { | ||
if (typeof emitter.removeListener === "function") { | ||
emitter.removeListener("error", errorListener); | ||
} | ||
resolve([].slice.call(arguments)); | ||
} | ||
; | ||
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true }); | ||
if (name !== "error") { | ||
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); | ||
} | ||
}); | ||
} | ||
function addErrorHandlerIfEventEmitter(emitter, handler, flags) { | ||
if (typeof emitter.on === "function") { | ||
eventTargetAgnosticAddListener(emitter, "error", handler, flags); | ||
} | ||
} | ||
function eventTargetAgnosticAddListener(emitter, name, listener, flags) { | ||
if (typeof emitter.on === "function") { | ||
if (flags.once) { | ||
emitter.once(name, listener); | ||
} else { | ||
emitter.on(name, listener); | ||
} | ||
} else if (typeof emitter.addEventListener === "function") { | ||
emitter.addEventListener(name, function wrapListener(arg) { | ||
if (flags.once) { | ||
emitter.removeEventListener(name, wrapListener); | ||
} | ||
listener(arg); | ||
}); | ||
} else { | ||
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); | ||
} | ||
} | ||
} | ||
@@ -419,11 +229,12 @@ }); | ||
// src/events/open-feature-event-emitter.ts | ||
var import_events = __toESM(require_events()); | ||
import { GenericEventEmitter } from "@openfeature/core"; | ||
// ../../node_modules/eventemitter3/index.mjs | ||
var import_index = __toESM(require_eventemitter3(), 1); | ||
// src/events/open-feature-event-emitter.ts | ||
var OpenFeatureEventEmitter = class extends GenericEventEmitter { | ||
eventEmitter = new import_events.EventEmitter({ captureRejections: true }); | ||
eventEmitter = new import_index.default(); | ||
constructor() { | ||
super(); | ||
this.eventEmitter.on("error", (err) => { | ||
this._logger?.error("Error running event handler:", err); | ||
}); | ||
} | ||
@@ -430,0 +241,0 @@ }; |
@@ -145,25 +145,135 @@ import * as _openfeature_core from '@openfeature/core'; | ||
type Listener = (...args: any[]) => void; | ||
/** | ||
* Minimal `EventEmitter` interface that is molded against the Node.js | ||
* `EventEmitter` interface. | ||
*/ | ||
declare class EventEmitter< | ||
EventTypes extends EventEmitter.ValidEventTypes = string | symbol, | ||
Context extends any = any | ||
> { | ||
static prefixed: string | boolean; | ||
declare class EventEmitter { | ||
static listenerCount(emitter: EventEmitter, type: string | number): number; | ||
static defaultMaxListeners: number; | ||
/** | ||
* Return an array listing the events for which the emitter has registered | ||
* listeners. | ||
*/ | ||
eventNames(): Array<EventEmitter.EventNames<EventTypes>>; | ||
eventNames(): Array<string | number>; | ||
setMaxListeners(n: number): this; | ||
getMaxListeners(): number; | ||
emit(type: string | number, ...args: any[]): boolean; | ||
addListener(type: string | number, listener: Listener): this; | ||
on(type: string | number, listener: Listener): this; | ||
once(type: string | number, listener: Listener): this; | ||
prependListener(type: string | number, listener: Listener): this; | ||
prependOnceListener(type: string | number, listener: Listener): this; | ||
removeListener(type: string | number, listener: Listener): this; | ||
off(type: string | number, listener: Listener): this; | ||
removeAllListeners(type?: string | number): this; | ||
listeners(type: string | number): Listener[]; | ||
listenerCount(type: string | number): number; | ||
rawListeners(type: string | number): Listener[]; | ||
/** | ||
* Return the listeners registered for a given event. | ||
*/ | ||
listeners<T extends EventEmitter.EventNames<EventTypes>>( | ||
event: T | ||
): Array<EventEmitter.EventListener<EventTypes, T>>; | ||
/** | ||
* Return the number of listeners listening to a given event. | ||
*/ | ||
listenerCount(event: EventEmitter.EventNames<EventTypes>): number; | ||
/** | ||
* Calls each of the listeners registered for a given event. | ||
*/ | ||
emit<T extends EventEmitter.EventNames<EventTypes>>( | ||
event: T, | ||
...args: EventEmitter.EventArgs<EventTypes, T> | ||
): boolean; | ||
/** | ||
* Add a listener for a given event. | ||
*/ | ||
on<T extends EventEmitter.EventNames<EventTypes>>( | ||
event: T, | ||
fn: EventEmitter.EventListener<EventTypes, T>, | ||
context?: Context | ||
): this; | ||
addListener<T extends EventEmitter.EventNames<EventTypes>>( | ||
event: T, | ||
fn: EventEmitter.EventListener<EventTypes, T>, | ||
context?: Context | ||
): this; | ||
/** | ||
* Add a one-time listener for a given event. | ||
*/ | ||
once<T extends EventEmitter.EventNames<EventTypes>>( | ||
event: T, | ||
fn: EventEmitter.EventListener<EventTypes, T>, | ||
context?: Context | ||
): this; | ||
/** | ||
* Remove the listeners of a given event. | ||
*/ | ||
removeListener<T extends EventEmitter.EventNames<EventTypes>>( | ||
event: T, | ||
fn?: EventEmitter.EventListener<EventTypes, T>, | ||
context?: Context, | ||
once?: boolean | ||
): this; | ||
off<T extends EventEmitter.EventNames<EventTypes>>( | ||
event: T, | ||
fn?: EventEmitter.EventListener<EventTypes, T>, | ||
context?: Context, | ||
once?: boolean | ||
): this; | ||
/** | ||
* Remove all listeners, or those of the specified event. | ||
*/ | ||
removeAllListeners(event?: EventEmitter.EventNames<EventTypes>): this; | ||
} | ||
declare namespace EventEmitter { | ||
export interface ListenerFn<Args extends any[] = any[]> { | ||
(...args: Args): void; | ||
} | ||
export interface EventEmitterStatic { | ||
new < | ||
EventTypes extends ValidEventTypes = string | symbol, | ||
Context = any | ||
>(): EventEmitter<EventTypes, Context>; | ||
} | ||
/** | ||
* `object` should be in either of the following forms: | ||
* ``` | ||
* interface EventTypes { | ||
* 'event-with-parameters': any[] | ||
* 'event-with-example-handler': (...args: any[]) => void | ||
* } | ||
* ``` | ||
*/ | ||
export type ValidEventTypes = string | symbol | object; | ||
export type EventNames<T extends ValidEventTypes> = T extends string | symbol | ||
? T | ||
: keyof T; | ||
export type ArgumentMap<T extends object> = { | ||
[K in keyof T]: T[K] extends (...args: any[]) => void | ||
? Parameters<T[K]> | ||
: T[K] extends any[] | ||
? T[K] | ||
: any[]; | ||
}; | ||
export type EventListener< | ||
T extends ValidEventTypes, | ||
K extends EventNames<T> | ||
> = T extends string | symbol | ||
? (...args: any[]) => void | ||
: ( | ||
...args: ArgumentMap<Exclude<T, string | symbol>>[Extract<K, keyof T>] | ||
) => void; | ||
export type EventArgs< | ||
T extends ValidEventTypes, | ||
K extends EventNames<T> | ||
> = Parameters<EventListener<T, K>>; | ||
export const EventEmitter: EventEmitterStatic; | ||
} | ||
/** | ||
@@ -182,3 +292,3 @@ * A subset of events that can be directly emitted by providers. | ||
declare class OpenFeatureEventEmitter extends GenericEventEmitter<ProviderEmittableEvents> { | ||
protected readonly eventEmitter: EventEmitter; | ||
protected readonly eventEmitter: EventEmitter<string | symbol, any>; | ||
constructor(); | ||
@@ -185,0 +295,0 @@ } |
{ | ||
"name": "@openfeature/web-sdk", | ||
"version": "0.4.14", | ||
"version": "0.4.15", | ||
"description": "OpenFeature SDK for Web", | ||
@@ -49,7 +49,7 @@ "main": "./dist/cjs/index.js", | ||
"peerDependencies": { | ||
"@openfeature/core": "0.0.27" | ||
"@openfeature/core": "0.0.28" | ||
}, | ||
"devDependencies": { | ||
"@openfeature/core": "0.0.27" | ||
"@openfeature/core": "0.0.28" | ||
} | ||
} |
@@ -19,4 +19,4 @@ <!-- markdownlint-disable MD033 --> | ||
<!-- x-release-please-start-version --> | ||
<a href="https://github.com/open-feature/js-sdk/releases/tag/web-sdk-v0.4.14"> | ||
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v0.4.14&color=blue&style=for-the-badge" /> | ||
<a href="https://github.com/open-feature/js-sdk/releases/tag/web-sdk-v0.4.15"> | ||
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v0.4.15&color=blue&style=for-the-badge" /> | ||
</a> | ||
@@ -23,0 +23,0 @@ <!-- x-release-please-end --> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
218814
1953