@noormdev/sdk 1.4.1 → 1.5.0
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/chunk-6LG4ENOJ.js +1523 -0
- package/dist/{chunk-G4B7EHL7.js → chunk-M7Q44VFJ.js} +5 -4
- package/dist/chunk-OXTXFKWJ.js +188 -0
- package/dist/{chunk-LY2F7ZFI.js → chunk-TXDGFA44.js} +3 -1518
- package/dist/{chunk-FSVO6NAJ.js → chunk-WUMCIKEQ.js} +4 -3
- package/dist/{engine-MZQ364EH.js → engine-P74UTJQO.js} +5 -4
- package/dist/index.d.ts +55 -0
- package/dist/index.js +480 -67
- package/dist/{mssql-3BQB6ACD.js → mssql-II62FO2B.js} +22 -39
- package/dist/{storage-V5I67ANZ.js → storage-FBDOY3MC.js} +5 -4
- package/package.json +1 -1
|
@@ -1852,1521 +1852,6 @@ You can either \`unset ${key("APP_PROBLEMATIC")}\` or scope all vars to \`${key(
|
|
|
1852
1852
|
};
|
|
1853
1853
|
};
|
|
1854
1854
|
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
data;
|
|
1859
|
-
func;
|
|
1860
|
-
event;
|
|
1861
|
-
stack;
|
|
1862
|
-
};
|
|
1863
|
-
var traceStackFilterRgx = new RegExp(`(${[
|
|
1864
|
-
"node_modules",
|
|
1865
|
-
"node:internal",
|
|
1866
|
-
"$spy",
|
|
1867
|
-
"makeEventTracer",
|
|
1868
|
-
"sendToSpy",
|
|
1869
|
-
"Function.spy",
|
|
1870
|
-
"Observable.Engine"
|
|
1871
|
-
].join("|")})`);
|
|
1872
|
-
var EventError = class extends Error {
|
|
1873
|
-
event;
|
|
1874
|
-
listener;
|
|
1875
|
-
data;
|
|
1876
|
-
constructor(message, opts) {
|
|
1877
|
-
super(message);
|
|
1878
|
-
this.event = opts?.event;
|
|
1879
|
-
this.listener = opts?.listener;
|
|
1880
|
-
this.data = opts?.data;
|
|
1881
|
-
}
|
|
1882
|
-
};
|
|
1883
|
-
var makeEventTracer = (event, caller, listenerOrData) => {
|
|
1884
|
-
const err = new Error();
|
|
1885
|
-
const split = err.stack.split("\n");
|
|
1886
|
-
split.shift();
|
|
1887
|
-
const filtered = split.filter((line) => !traceStackFilterRgx.test(line));
|
|
1888
|
-
const message = `EventStack (${event} ${caller.toString()}):`;
|
|
1889
|
-
filtered.unshift(message);
|
|
1890
|
-
const stack = filtered.join("\n");
|
|
1891
|
-
const tracer = new EventTrace(message);
|
|
1892
|
-
tracer.name = message;
|
|
1893
|
-
tracer.func = caller;
|
|
1894
|
-
tracer.event = event;
|
|
1895
|
-
tracer.stack = stack;
|
|
1896
|
-
tracer.listener = null;
|
|
1897
|
-
tracer.data = null;
|
|
1898
|
-
if (typeof listenerOrData === "function") {
|
|
1899
|
-
tracer.listener = listenerOrData;
|
|
1900
|
-
} else {
|
|
1901
|
-
tracer.data = listenerOrData;
|
|
1902
|
-
}
|
|
1903
|
-
return tracer;
|
|
1904
|
-
};
|
|
1905
|
-
var rgxStrToRgx = (rgxStr) => {
|
|
1906
|
-
const split = rgxStr?.replace(/^\//, "").split("/");
|
|
1907
|
-
const flags = split.pop();
|
|
1908
|
-
const expr = split.join("/");
|
|
1909
|
-
return RegExp(expr, flags);
|
|
1910
|
-
};
|
|
1911
|
-
var arrOfMatchingValues = (vals, map) => {
|
|
1912
|
-
const listeners = [];
|
|
1913
|
-
for (const key of vals) {
|
|
1914
|
-
for (const fn of map.get(key) || /* @__PURE__ */ new Set()) {
|
|
1915
|
-
listeners.push({
|
|
1916
|
-
event: key,
|
|
1917
|
-
func: fn
|
|
1918
|
-
});
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
return listeners;
|
|
1922
|
-
};
|
|
1923
|
-
var InternalEvs = /* @__PURE__ */ (function(InternalEvs2) {
|
|
1924
|
-
InternalEvs2["on"] = "on";
|
|
1925
|
-
InternalEvs2["off"] = "off";
|
|
1926
|
-
InternalEvs2["emit"] = "emit";
|
|
1927
|
-
InternalEvs2["clear"] = "clear";
|
|
1928
|
-
return InternalEvs2;
|
|
1929
|
-
})({});
|
|
1930
|
-
var InternalEvent = class extends Event {
|
|
1931
|
-
type;
|
|
1932
|
-
data;
|
|
1933
|
-
constructor(ev, data) {
|
|
1934
|
-
super(ev);
|
|
1935
|
-
this.data = data;
|
|
1936
|
-
this.type = ev;
|
|
1937
|
-
}
|
|
1938
|
-
};
|
|
1939
|
-
var validateEvent = (fn, opts) => {
|
|
1940
|
-
if (opts.event === void 0 || typeof opts.event !== "string" && opts.event instanceof RegExp === false) {
|
|
1941
|
-
throw new EventError(`observer.${fn}: Event must be a string or RegExp`, opts);
|
|
1942
|
-
}
|
|
1943
|
-
};
|
|
1944
|
-
var validateListener = (fn, opts) => {
|
|
1945
|
-
if (opts.listener !== void 0 && typeof opts.listener !== "function") {
|
|
1946
|
-
throw new EventError(`observer.${fn}: Listener must be a function`, opts);
|
|
1947
|
-
}
|
|
1948
|
-
};
|
|
1949
|
-
|
|
1950
|
-
// node_modules/@logosdx/observer/dist/esm/generator.mjs
|
|
1951
|
-
var DeferredEvent = class extends Deferred {
|
|
1952
|
-
cleanup;
|
|
1953
|
-
};
|
|
1954
|
-
var EventGenerator = class {
|
|
1955
|
-
#observer;
|
|
1956
|
-
#event;
|
|
1957
|
-
#buffer;
|
|
1958
|
-
#waiting = null;
|
|
1959
|
-
#done = false;
|
|
1960
|
-
#listener = null;
|
|
1961
|
-
#lastValue = null;
|
|
1962
|
-
#assertNotDestroyed = () => {
|
|
1963
|
-
if (this.#done === true) {
|
|
1964
|
-
throw new EventError(`Event generator for ${this.#event.toString()} has been destroyed`, {
|
|
1965
|
-
event: this.#event,
|
|
1966
|
-
listener: this.#listener,
|
|
1967
|
-
data: null
|
|
1968
|
-
});
|
|
1969
|
-
}
|
|
1970
|
-
};
|
|
1971
|
-
cleanup;
|
|
1972
|
-
next;
|
|
1973
|
-
constructor(observer2, event, options) {
|
|
1974
|
-
this.#observer = observer2;
|
|
1975
|
-
this.#event = event;
|
|
1976
|
-
this.#buffer = new PriorityQueue();
|
|
1977
|
-
this.#listener = (data) => {
|
|
1978
|
-
this.#lastValue = data;
|
|
1979
|
-
if (this.#waiting) {
|
|
1980
|
-
const defer = this.#waiting;
|
|
1981
|
-
this.#waiting = null;
|
|
1982
|
-
defer.resolve(data);
|
|
1983
|
-
} else {
|
|
1984
|
-
this.#buffer.push(data);
|
|
1985
|
-
}
|
|
1986
|
-
};
|
|
1987
|
-
const off = observer2.on(event, this.#listener);
|
|
1988
|
-
let generatorAbortCtrl;
|
|
1989
|
-
this.next = () => {
|
|
1990
|
-
this.#assertNotDestroyed();
|
|
1991
|
-
const buffered = this.#buffer.pop();
|
|
1992
|
-
if (buffered !== null) {
|
|
1993
|
-
return Promise.resolve(buffered);
|
|
1994
|
-
}
|
|
1995
|
-
if (!this.#waiting) {
|
|
1996
|
-
this.#waiting = new DeferredEvent();
|
|
1997
|
-
this.#waiting.promise.cleanup = this.cleanup;
|
|
1998
|
-
this.#waiting.promise.resolve = this.#waiting.resolve;
|
|
1999
|
-
this.#waiting.promise.reject = this.#waiting.reject;
|
|
2000
|
-
}
|
|
2001
|
-
return this.#waiting.promise;
|
|
2002
|
-
};
|
|
2003
|
-
this.cleanup = () => {
|
|
2004
|
-
if (this.#done) return;
|
|
2005
|
-
off();
|
|
2006
|
-
this.#done = true;
|
|
2007
|
-
const abortError = new EventError("Aborted", {
|
|
2008
|
-
event: this.#event,
|
|
2009
|
-
listener: this.#listener,
|
|
2010
|
-
data: null
|
|
2011
|
-
});
|
|
2012
|
-
if (this.#waiting) {
|
|
2013
|
-
this.#waiting.reject(abortError);
|
|
2014
|
-
this.#waiting = null;
|
|
2015
|
-
}
|
|
2016
|
-
this.#_iterPromise.forEach((promise) => {
|
|
2017
|
-
promise.reject?.(abortError);
|
|
2018
|
-
});
|
|
2019
|
-
this.#_iterPromise.clear();
|
|
2020
|
-
this.#buffer.clear();
|
|
2021
|
-
this.#lastValue = null;
|
|
2022
|
-
generatorAbortCtrl?.abort();
|
|
2023
|
-
};
|
|
2024
|
-
const userSignal = options?.signal;
|
|
2025
|
-
if (userSignal) {
|
|
2026
|
-
if (userSignal.aborted) {
|
|
2027
|
-
this.#done = true;
|
|
2028
|
-
return;
|
|
2029
|
-
}
|
|
2030
|
-
generatorAbortCtrl = new AbortController();
|
|
2031
|
-
userSignal.addEventListener("abort", this.cleanup, {
|
|
2032
|
-
signal: generatorAbortCtrl.signal
|
|
2033
|
-
});
|
|
2034
|
-
}
|
|
2035
|
-
}
|
|
2036
|
-
/**
|
|
2037
|
-
* Store iterator's last promise. Handles multiple promises
|
|
2038
|
-
* for when the generator is used in multiple places.
|
|
2039
|
-
*/
|
|
2040
|
-
#_iterPromise = /* @__PURE__ */ new Set();
|
|
2041
|
-
async *[Symbol.asyncIterator]() {
|
|
2042
|
-
while (!this.#done) {
|
|
2043
|
-
const promise = this.next();
|
|
2044
|
-
this.#_iterPromise.add(promise);
|
|
2045
|
-
yield await promise;
|
|
2046
|
-
this.#_iterPromise.delete(promise);
|
|
2047
|
-
}
|
|
2048
|
-
return Promise.resolve(void 0);
|
|
2049
|
-
}
|
|
2050
|
-
get lastValue() {
|
|
2051
|
-
return this.#lastValue;
|
|
2052
|
-
}
|
|
2053
|
-
get done() {
|
|
2054
|
-
return this.#done;
|
|
2055
|
-
}
|
|
2056
|
-
emit(data) {
|
|
2057
|
-
this.#assertNotDestroyed();
|
|
2058
|
-
this.#observer.emit(this.#event, data);
|
|
2059
|
-
}
|
|
2060
|
-
};
|
|
2061
|
-
|
|
2062
|
-
// node_modules/@logosdx/observer/dist/esm/queue/state.mjs
|
|
2063
|
-
var QueueStateManager = class {
|
|
2064
|
-
status = "stopped";
|
|
2065
|
-
#allowedTransitions = {
|
|
2066
|
-
["running"]: [
|
|
2067
|
-
"paused",
|
|
2068
|
-
"draining",
|
|
2069
|
-
"stopped"
|
|
2070
|
-
],
|
|
2071
|
-
["draining"]: [
|
|
2072
|
-
"stopped",
|
|
2073
|
-
"paused"
|
|
2074
|
-
],
|
|
2075
|
-
["paused"]: [
|
|
2076
|
-
"running",
|
|
2077
|
-
"draining",
|
|
2078
|
-
"stopped"
|
|
2079
|
-
],
|
|
2080
|
-
["stopped"]: [
|
|
2081
|
-
"running",
|
|
2082
|
-
"draining"
|
|
2083
|
-
]
|
|
2084
|
-
};
|
|
2085
|
-
transition(to) {
|
|
2086
|
-
assert(this.#allowedTransitions[this.status].includes(to), `Invalid transition from ${this.status} to ${to}`);
|
|
2087
|
-
this.status = to;
|
|
2088
|
-
}
|
|
2089
|
-
is(...states) {
|
|
2090
|
-
return states.includes(this.status);
|
|
2091
|
-
}
|
|
2092
|
-
get state() {
|
|
2093
|
-
return this.status;
|
|
2094
|
-
}
|
|
2095
|
-
};
|
|
2096
|
-
|
|
2097
|
-
// node_modules/@logosdx/observer/dist/esm/queue/statistics.mjs
|
|
2098
|
-
var QueueStats = class {
|
|
2099
|
-
observer;
|
|
2100
|
-
queueName;
|
|
2101
|
-
#processing;
|
|
2102
|
-
#processed;
|
|
2103
|
-
#avgProcessingTime;
|
|
2104
|
-
#success;
|
|
2105
|
-
#error;
|
|
2106
|
-
#rejected;
|
|
2107
|
-
constructor(observer2, queueName) {
|
|
2108
|
-
this.observer = observer2;
|
|
2109
|
-
this.queueName = queueName;
|
|
2110
|
-
this.#processing = 0;
|
|
2111
|
-
this.#processed = 0;
|
|
2112
|
-
this.#avgProcessingTime = 0;
|
|
2113
|
-
this.#success = 0;
|
|
2114
|
-
this.#error = 0;
|
|
2115
|
-
this.#rejected = 0;
|
|
2116
|
-
this.observer.on(`queue:${this.queueName}:processing`, () => {
|
|
2117
|
-
this.#processing++;
|
|
2118
|
-
});
|
|
2119
|
-
this.observer.on(`queue:${this.queueName}:success`, (wrapped) => {
|
|
2120
|
-
this.#processed++;
|
|
2121
|
-
this.#success++;
|
|
2122
|
-
this.#processing--;
|
|
2123
|
-
this.#calculateAvg(wrapped.data.elapsed);
|
|
2124
|
-
});
|
|
2125
|
-
this.observer.on(`queue:${this.queueName}:error`, () => {
|
|
2126
|
-
this.#processed++;
|
|
2127
|
-
this.#error++;
|
|
2128
|
-
this.#processing--;
|
|
2129
|
-
});
|
|
2130
|
-
this.observer.on(`queue:${this.queueName}:rejected`, () => this.#rejected++);
|
|
2131
|
-
}
|
|
2132
|
-
#calculateAvg(elapsed) {
|
|
2133
|
-
this.#avgProcessingTime = (this.#avgProcessingTime * (this.#success - 1) + elapsed) / this.#success;
|
|
2134
|
-
}
|
|
2135
|
-
get stats() {
|
|
2136
|
-
return {
|
|
2137
|
-
processed: this.#processed,
|
|
2138
|
-
processing: this.#processing,
|
|
2139
|
-
avgProcessingTime: this.#avgProcessingTime,
|
|
2140
|
-
success: this.#success,
|
|
2141
|
-
error: this.#error,
|
|
2142
|
-
rejected: this.#rejected
|
|
2143
|
-
};
|
|
2144
|
-
}
|
|
2145
|
-
};
|
|
2146
|
-
|
|
2147
|
-
// node_modules/@logosdx/observer/dist/esm/queue/helpers.mjs
|
|
2148
|
-
var InternalQueueEvent = class {
|
|
2149
|
-
data;
|
|
2150
|
-
constructor(data) {
|
|
2151
|
-
this.data = data;
|
|
2152
|
-
}
|
|
2153
|
-
};
|
|
2154
|
-
var QueueRejectionReason = /* @__PURE__ */ (function(QueueRejectionReason2) {
|
|
2155
|
-
QueueRejectionReason2["full"] = "Queue is full";
|
|
2156
|
-
QueueRejectionReason2["notRunning"] = "Queue is not running";
|
|
2157
|
-
return QueueRejectionReason2;
|
|
2158
|
-
})({});
|
|
2159
|
-
|
|
2160
|
-
// node_modules/@logosdx/observer/dist/esm/queue/queue.mjs
|
|
2161
|
-
var EventQueue = class {
|
|
2162
|
-
opts;
|
|
2163
|
-
#queue;
|
|
2164
|
-
#priorites;
|
|
2165
|
-
#off;
|
|
2166
|
-
#state;
|
|
2167
|
-
#stats;
|
|
2168
|
-
#rateLimiter;
|
|
2169
|
-
#idle;
|
|
2170
|
-
#waiting;
|
|
2171
|
-
#listening;
|
|
2172
|
-
#debugging;
|
|
2173
|
-
#generation;
|
|
2174
|
-
#activeRunners;
|
|
2175
|
-
#runningNodes;
|
|
2176
|
-
constructor(opts) {
|
|
2177
|
-
this.opts = opts;
|
|
2178
|
-
this.#priorites = /* @__PURE__ */ new Map();
|
|
2179
|
-
this.#off = noop;
|
|
2180
|
-
this.#state = new QueueStateManager();
|
|
2181
|
-
this.#idle = true;
|
|
2182
|
-
this.#waiting = false;
|
|
2183
|
-
this.#listening = false;
|
|
2184
|
-
this.#debugging = false;
|
|
2185
|
-
this.#generation = 0;
|
|
2186
|
-
this.#activeRunners = 0;
|
|
2187
|
-
this.#runningNodes = /* @__PURE__ */ new Set();
|
|
2188
|
-
const { observer: observer2 = new ObserverEngine(), event, process: process2, name, type = "fifo", concurrency = 1, pollIntervalMs = 100, jitterFactor = 0, rateLimitIntervalMs = 1e3, processIntervalMs = 0, taskTimeoutMs = 0, autoStart = true, debug = false } = this.opts;
|
|
2189
|
-
let { maxQueueSize = 999999999, rateLimitCapacity = 999999999 } = this.opts;
|
|
2190
|
-
assert(isPlainObject(this.opts), "Options is required to be an object");
|
|
2191
|
-
assert(isFunction(observer2?.on), "ObserverEngine is required");
|
|
2192
|
-
assert(typeof event === "string" && event.length > 0 || event instanceof RegExp, "Event is required to be a string or RegExp");
|
|
2193
|
-
assert(isFunction(process2), "Process is required to be a function");
|
|
2194
|
-
assert(name && typeof name === "string" && name.length > 0, "Name is required");
|
|
2195
|
-
assert(concurrency > 0, "Concurrency must be greater than 0");
|
|
2196
|
-
assert(pollIntervalMs > 0, "pollIntervalMs must be a number greater than 0");
|
|
2197
|
-
assert(jitterFactor >= 0 && jitterFactor <= 1, "Jitter must be a number greater than or equal to 0 and less than or equal to 1");
|
|
2198
|
-
assert(maxQueueSize > 0, "MaxQueueSize must be a number greater than 0");
|
|
2199
|
-
assert(rateLimitIntervalMs > 0, "rateLimitIntervalMs must be a number greater than 0");
|
|
2200
|
-
assert(rateLimitCapacity > 0, "rateLimitCapacity must be a number greater than 0");
|
|
2201
|
-
assert(processIntervalMs >= 0, "processIntervalMs must be a number greater than or equal to 0");
|
|
2202
|
-
assert(taskTimeoutMs >= 0, "taskTimeoutMs must be a number greater than or equal to 0");
|
|
2203
|
-
assert(type === "fifo" || type === "lifo", 'Type must be either "fifo" or "lifo"');
|
|
2204
|
-
assert(typeof autoStart === "boolean", "AutoStart must be a boolean");
|
|
2205
|
-
if (maxQueueSize === Infinity) {
|
|
2206
|
-
maxQueueSize = 999999999;
|
|
2207
|
-
}
|
|
2208
|
-
if (rateLimitCapacity === Infinity) {
|
|
2209
|
-
rateLimitCapacity = 999999999;
|
|
2210
|
-
}
|
|
2211
|
-
Object.assign(this.opts, {
|
|
2212
|
-
observer: observer2,
|
|
2213
|
-
type,
|
|
2214
|
-
concurrency,
|
|
2215
|
-
maxQueueSize,
|
|
2216
|
-
pollIntervalMs,
|
|
2217
|
-
jitterFactor,
|
|
2218
|
-
processIntervalMs,
|
|
2219
|
-
taskTimeoutMs
|
|
2220
|
-
});
|
|
2221
|
-
this.#debugging = debug;
|
|
2222
|
-
this.#stats = new QueueStats(observer2, name);
|
|
2223
|
-
this.#rateLimiter = new RateLimitTokenBucket({
|
|
2224
|
-
capacity: rateLimitCapacity,
|
|
2225
|
-
refillIntervalMs: rateLimitIntervalMs
|
|
2226
|
-
});
|
|
2227
|
-
this.#queue = new PriorityQueue({
|
|
2228
|
-
lifo: type === "lifo"
|
|
2229
|
-
});
|
|
2230
|
-
if (autoStart) {
|
|
2231
|
-
this.start();
|
|
2232
|
-
}
|
|
2233
|
-
}
|
|
2234
|
-
#listen() {
|
|
2235
|
-
if (this.#listening) return;
|
|
2236
|
-
this.#listening = true;
|
|
2237
|
-
const off = this.opts.observer.on(this.opts.event, (payload) => {
|
|
2238
|
-
const maybeInternal = payload?.data ?? payload;
|
|
2239
|
-
if (maybeInternal instanceof InternalQueueEvent) {
|
|
2240
|
-
return;
|
|
2241
|
-
}
|
|
2242
|
-
const data = payload;
|
|
2243
|
-
const item = {
|
|
2244
|
-
data,
|
|
2245
|
-
_taskId: generateId(),
|
|
2246
|
-
priority: this.#priorites.get(data) ?? 0
|
|
2247
|
-
};
|
|
2248
|
-
this.#priorites.delete(data);
|
|
2249
|
-
if (this.#queue.size() >= this.opts.maxQueueSize) {
|
|
2250
|
-
this.#emit("rejected", {
|
|
2251
|
-
...item,
|
|
2252
|
-
reason: QueueRejectionReason.full
|
|
2253
|
-
});
|
|
2254
|
-
return;
|
|
2255
|
-
}
|
|
2256
|
-
this.#emit("added", item);
|
|
2257
|
-
this.#idle = false;
|
|
2258
|
-
this.#queue.push(item, item.priority);
|
|
2259
|
-
});
|
|
2260
|
-
this.#off = () => {
|
|
2261
|
-
off();
|
|
2262
|
-
this.#listening = false;
|
|
2263
|
-
};
|
|
2264
|
-
}
|
|
2265
|
-
#emit(event, payload) {
|
|
2266
|
-
if (this.#debugging) {
|
|
2267
|
-
const args = [
|
|
2268
|
-
`[${this.name}] ${event}`,
|
|
2269
|
-
payload?._taskId ?? "",
|
|
2270
|
-
payload?.data ?? ""
|
|
2271
|
-
];
|
|
2272
|
-
if (this.#debugging === "verbose") {
|
|
2273
|
-
args[1] = payload;
|
|
2274
|
-
}
|
|
2275
|
-
console.log(...args);
|
|
2276
|
-
}
|
|
2277
|
-
this.opts.observer.emit(`queue:${this.name}:${event}`, new InternalQueueEvent(payload));
|
|
2278
|
-
}
|
|
2279
|
-
/**
|
|
2280
|
-
* Setups concurrency and begins processing items
|
|
2281
|
-
*/
|
|
2282
|
-
#launchRunners() {
|
|
2283
|
-
const generation = ++this.#generation;
|
|
2284
|
-
for (let i = 0; i < this.opts.concurrency; i++) {
|
|
2285
|
-
this.#workerLoop(generation, i);
|
|
2286
|
-
}
|
|
2287
|
-
}
|
|
2288
|
-
/**
|
|
2289
|
-
* Loops and processes items in the queue until the queue is stopped
|
|
2290
|
-
*/
|
|
2291
|
-
async #workerLoop(generation, instance) {
|
|
2292
|
-
const { pollIntervalMs, jitterFactor } = this.opts;
|
|
2293
|
-
this.#activeRunners++;
|
|
2294
|
-
while (this.#state.is("running") && this.#generation === generation) {
|
|
2295
|
-
if (!this.pending) {
|
|
2296
|
-
if (!this.#idle && !this.pending && this.#runningNodes.size === 0) {
|
|
2297
|
-
this.#idle = true;
|
|
2298
|
-
this.#emit("idle");
|
|
2299
|
-
}
|
|
2300
|
-
this.#waiting = true;
|
|
2301
|
-
await wait(pollIntervalMs * (1 + Math.random() * jitterFactor));
|
|
2302
|
-
this.#waiting = false;
|
|
2303
|
-
continue;
|
|
2304
|
-
}
|
|
2305
|
-
const data = this.#queue.pop();
|
|
2306
|
-
if (!data) continue;
|
|
2307
|
-
this.#runningNodes.add(`${generation}-${instance}`);
|
|
2308
|
-
await this.#processNext(data);
|
|
2309
|
-
if (this.opts.processIntervalMs > 0) {
|
|
2310
|
-
await wait(this.opts.processIntervalMs);
|
|
2311
|
-
}
|
|
2312
|
-
this.#runningNodes.delete(`${generation}-${instance}`);
|
|
2313
|
-
}
|
|
2314
|
-
this.#activeRunners--;
|
|
2315
|
-
}
|
|
2316
|
-
/**
|
|
2317
|
-
* Processes the next item in the queue, if the queue is not
|
|
2318
|
-
* in a state that prevents it from processing the item.
|
|
2319
|
-
*/
|
|
2320
|
-
async #processNext(item) {
|
|
2321
|
-
if (!this.#state.is("running", "draining")) {
|
|
2322
|
-
this.#queue.push(item);
|
|
2323
|
-
return;
|
|
2324
|
-
}
|
|
2325
|
-
let rateLimited = false;
|
|
2326
|
-
if (!this.#state.is("draining")) {
|
|
2327
|
-
await this.#rateLimiter.waitAndConsume(1, {
|
|
2328
|
-
onRateLimit: () => {
|
|
2329
|
-
this.#emit("rate-limited", item);
|
|
2330
|
-
rateLimited = true;
|
|
2331
|
-
}
|
|
2332
|
-
});
|
|
2333
|
-
}
|
|
2334
|
-
const startedAt = Date.now();
|
|
2335
|
-
this.#emit("processing", {
|
|
2336
|
-
...item,
|
|
2337
|
-
startedAt,
|
|
2338
|
-
rateLimited
|
|
2339
|
-
});
|
|
2340
|
-
const [, err] = await attempt(async () => {
|
|
2341
|
-
if (this.opts.taskTimeoutMs === 0) {
|
|
2342
|
-
return this.opts.process(item.data);
|
|
2343
|
-
}
|
|
2344
|
-
const result = await Promise.race([
|
|
2345
|
-
this.opts.process(item.data),
|
|
2346
|
-
wait(this.opts.taskTimeoutMs, new TimeoutError("Task timed out"))
|
|
2347
|
-
]);
|
|
2348
|
-
if (isTimeoutError(result)) {
|
|
2349
|
-
this.#emit("timeout", {
|
|
2350
|
-
...item,
|
|
2351
|
-
error: result
|
|
2352
|
-
});
|
|
2353
|
-
throw result;
|
|
2354
|
-
}
|
|
2355
|
-
return result;
|
|
2356
|
-
});
|
|
2357
|
-
const elapsed = Date.now() - startedAt;
|
|
2358
|
-
if (err) {
|
|
2359
|
-
this.#emit("error", {
|
|
2360
|
-
...item,
|
|
2361
|
-
error: err,
|
|
2362
|
-
rateLimited
|
|
2363
|
-
});
|
|
2364
|
-
} else {
|
|
2365
|
-
this.#emit("success", {
|
|
2366
|
-
...item,
|
|
2367
|
-
startedAt,
|
|
2368
|
-
elapsed,
|
|
2369
|
-
rateLimited
|
|
2370
|
-
});
|
|
2371
|
-
}
|
|
2372
|
-
if (this.#queue.size() === 0 && this.#state.is("running")) {
|
|
2373
|
-
this.#emit("empty");
|
|
2374
|
-
}
|
|
2375
|
-
}
|
|
2376
|
-
/**
|
|
2377
|
-
* Start the queue if it is not already started
|
|
2378
|
-
*/
|
|
2379
|
-
start() {
|
|
2380
|
-
if (this.#state.is("running")) return;
|
|
2381
|
-
this.#listen();
|
|
2382
|
-
this.#state.transition("running");
|
|
2383
|
-
this.#emit("start");
|
|
2384
|
-
this.#launchRunners();
|
|
2385
|
-
this.#emit("started");
|
|
2386
|
-
return Promise.resolve();
|
|
2387
|
-
}
|
|
2388
|
-
/**
|
|
2389
|
-
* Stop the queue
|
|
2390
|
-
*/
|
|
2391
|
-
stop() {
|
|
2392
|
-
if (this.#state.is("stopped")) return;
|
|
2393
|
-
this.#off();
|
|
2394
|
-
this.#state.transition("stopped");
|
|
2395
|
-
this.#emit("stopped");
|
|
2396
|
-
}
|
|
2397
|
-
/**
|
|
2398
|
-
* Pause the queue
|
|
2399
|
-
*/
|
|
2400
|
-
pause() {
|
|
2401
|
-
if (this.#state.is("paused")) return;
|
|
2402
|
-
this.#state.transition("paused");
|
|
2403
|
-
this.#emit("paused");
|
|
2404
|
-
return Promise.resolve();
|
|
2405
|
-
}
|
|
2406
|
-
/**
|
|
2407
|
-
* Resume the queue
|
|
2408
|
-
*/
|
|
2409
|
-
resume() {
|
|
2410
|
-
if (this.#state.is("running")) return;
|
|
2411
|
-
this.#listen();
|
|
2412
|
-
this.#state.transition("running");
|
|
2413
|
-
this.#launchRunners();
|
|
2414
|
-
this.#emit("resumed");
|
|
2415
|
-
return Promise.resolve();
|
|
2416
|
-
}
|
|
2417
|
-
/**
|
|
2418
|
-
* Processes a batch of items from the queue, and then
|
|
2419
|
-
* calls the before and after functions. Returns the
|
|
2420
|
-
* number of items processed.
|
|
2421
|
-
*/
|
|
2422
|
-
async #processBatch(limit = Infinity, beforeFn, afterFn) {
|
|
2423
|
-
let count = limit === Infinity ? this.#queue.size() : limit;
|
|
2424
|
-
const items = this.#queue.popMany(count);
|
|
2425
|
-
if (count < items.length) {
|
|
2426
|
-
count = items.length;
|
|
2427
|
-
}
|
|
2428
|
-
beforeFn?.(count);
|
|
2429
|
-
if (count !== 0) {
|
|
2430
|
-
for (const item of items) {
|
|
2431
|
-
await this.#processNext(item);
|
|
2432
|
-
}
|
|
2433
|
-
}
|
|
2434
|
-
afterFn?.(count);
|
|
2435
|
-
return count;
|
|
2436
|
-
}
|
|
2437
|
-
/**
|
|
2438
|
-
* Empty and process all items in the queue and
|
|
2439
|
-
* then stop the queue. Returns the number of items
|
|
2440
|
-
* processed.
|
|
2441
|
-
*/
|
|
2442
|
-
shutdown(force = false) {
|
|
2443
|
-
if (this.#state.is("draining", "stopped")) return Promise.resolve(0);
|
|
2444
|
-
if (force) {
|
|
2445
|
-
const count = this.purge();
|
|
2446
|
-
this.stop();
|
|
2447
|
-
this.#emit("shutdown", {
|
|
2448
|
-
force,
|
|
2449
|
-
pending: count
|
|
2450
|
-
});
|
|
2451
|
-
return Promise.resolve(count);
|
|
2452
|
-
}
|
|
2453
|
-
return this.#processBatch(Infinity, (pending) => {
|
|
2454
|
-
this.pause();
|
|
2455
|
-
this.#state.transition("draining");
|
|
2456
|
-
this.#off();
|
|
2457
|
-
this.#emit("drain", {
|
|
2458
|
-
pending
|
|
2459
|
-
});
|
|
2460
|
-
}, (drained) => {
|
|
2461
|
-
this.#emit("drained", force ? {
|
|
2462
|
-
pending: drained
|
|
2463
|
-
} : {
|
|
2464
|
-
drained
|
|
2465
|
-
});
|
|
2466
|
-
this.stop();
|
|
2467
|
-
this.#emit("shutdown", force ? {
|
|
2468
|
-
force,
|
|
2469
|
-
pending: drained
|
|
2470
|
-
} : {
|
|
2471
|
-
force
|
|
2472
|
-
});
|
|
2473
|
-
});
|
|
2474
|
-
}
|
|
2475
|
-
/**
|
|
2476
|
-
* Executes `limit` items in the queue
|
|
2477
|
-
* and then emits a `flush` event. Returns the number
|
|
2478
|
-
* of items processed.
|
|
2479
|
-
*/
|
|
2480
|
-
async flush(limit = Infinity) {
|
|
2481
|
-
return this.#processBatch(limit, (pending) => this.#emit("flush", {
|
|
2482
|
-
pending
|
|
2483
|
-
}), (flushed) => this.#emit("flushed", {
|
|
2484
|
-
flushed
|
|
2485
|
-
}));
|
|
2486
|
-
}
|
|
2487
|
-
/**
|
|
2488
|
-
* Clears the queue and emits a `purge` event. Returns
|
|
2489
|
-
* the number of items purged.
|
|
2490
|
-
*/
|
|
2491
|
-
purge() {
|
|
2492
|
-
const count = this.#queue.size();
|
|
2493
|
-
this.#queue.clear();
|
|
2494
|
-
this.#emit("purged", {
|
|
2495
|
-
count
|
|
2496
|
-
});
|
|
2497
|
-
return count;
|
|
2498
|
-
}
|
|
2499
|
-
/**
|
|
2500
|
-
* Emit an event to the observer, which then gets
|
|
2501
|
-
* picked up by the queue and processed.
|
|
2502
|
-
*
|
|
2503
|
-
* @param data The data to add to the queue
|
|
2504
|
-
* @param priority The priority of the data
|
|
2505
|
-
*
|
|
2506
|
-
* @note If priority is provided, it will be used to determine the order of the data in the queue.
|
|
2507
|
-
* The higher the priority, the sooner the data will be processed.
|
|
2508
|
-
*
|
|
2509
|
-
* @note If priority is not provided, the data will be added to the queue with a priority of 0.
|
|
2510
|
-
*/
|
|
2511
|
-
add(data, priority) {
|
|
2512
|
-
if (!this.#state.is("running", "paused")) {
|
|
2513
|
-
this.#emit("rejected", {
|
|
2514
|
-
data,
|
|
2515
|
-
reason: QueueRejectionReason.notRunning
|
|
2516
|
-
});
|
|
2517
|
-
return false;
|
|
2518
|
-
}
|
|
2519
|
-
if (this.#queue.size() >= this.opts.maxQueueSize) {
|
|
2520
|
-
this.#emit("rejected", {
|
|
2521
|
-
data,
|
|
2522
|
-
reason: QueueRejectionReason.full
|
|
2523
|
-
});
|
|
2524
|
-
return false;
|
|
2525
|
-
}
|
|
2526
|
-
if (priority) {
|
|
2527
|
-
this.#priorites.set(data, priority);
|
|
2528
|
-
}
|
|
2529
|
-
this.opts.observer.emit(this.opts.event, data);
|
|
2530
|
-
return true;
|
|
2531
|
-
}
|
|
2532
|
-
debug(on = false) {
|
|
2533
|
-
this.#debugging = on;
|
|
2534
|
-
}
|
|
2535
|
-
#observerForQueue() {
|
|
2536
|
-
return this.opts.observer;
|
|
2537
|
-
}
|
|
2538
|
-
on(event, listener) {
|
|
2539
|
-
return this.#observerForQueue().on(`queue:${this.name}:${event}`, listener);
|
|
2540
|
-
}
|
|
2541
|
-
once(event, listener) {
|
|
2542
|
-
return this.#observerForQueue().once(`queue:${this.name}:${event}`, listener);
|
|
2543
|
-
}
|
|
2544
|
-
off(event, listener) {
|
|
2545
|
-
return this.#observerForQueue().off(`queue:${this.name}:${event}`, listener);
|
|
2546
|
-
}
|
|
2547
|
-
/**
|
|
2548
|
-
* The name of the queue
|
|
2549
|
-
*/
|
|
2550
|
-
get name() {
|
|
2551
|
-
return this.opts.name;
|
|
2552
|
-
}
|
|
2553
|
-
/**
|
|
2554
|
-
* Whether the queue is waiting for the
|
|
2555
|
-
* the
|
|
2556
|
-
*/
|
|
2557
|
-
get isWaiting() {
|
|
2558
|
-
return this.#waiting;
|
|
2559
|
-
}
|
|
2560
|
-
/**
|
|
2561
|
-
* Whether the queue is idle
|
|
2562
|
-
*/
|
|
2563
|
-
get isIdle() {
|
|
2564
|
-
return this.#idle && this.#state.is("running");
|
|
2565
|
-
}
|
|
2566
|
-
/**
|
|
2567
|
-
* Whether the queue is running
|
|
2568
|
-
*/
|
|
2569
|
-
get isRunning() {
|
|
2570
|
-
return this.#state.is("running");
|
|
2571
|
-
}
|
|
2572
|
-
/**
|
|
2573
|
-
* Whether the queue is paused
|
|
2574
|
-
*/
|
|
2575
|
-
get isPaused() {
|
|
2576
|
-
return this.#state.is("paused");
|
|
2577
|
-
}
|
|
2578
|
-
/**
|
|
2579
|
-
* Whether the queue is stopped
|
|
2580
|
-
*/
|
|
2581
|
-
get isStopped() {
|
|
2582
|
-
return this.#state.is("stopped");
|
|
2583
|
-
}
|
|
2584
|
-
/**
|
|
2585
|
-
* Whether the queue is draining
|
|
2586
|
-
*/
|
|
2587
|
-
get isDraining() {
|
|
2588
|
-
return this.#state.is("draining");
|
|
2589
|
-
}
|
|
2590
|
-
/**
|
|
2591
|
-
* The current state of the queue
|
|
2592
|
-
*/
|
|
2593
|
-
get state() {
|
|
2594
|
-
return this.#state.state;
|
|
2595
|
-
}
|
|
2596
|
-
/**
|
|
2597
|
-
* The number of items in the queue
|
|
2598
|
-
*/
|
|
2599
|
-
get pending() {
|
|
2600
|
-
return this.#queue.size();
|
|
2601
|
-
}
|
|
2602
|
-
/**
|
|
2603
|
-
* The stats of the queue
|
|
2604
|
-
*/
|
|
2605
|
-
get stats() {
|
|
2606
|
-
return clone(this.#stats.stats);
|
|
2607
|
-
}
|
|
2608
|
-
get snapshot() {
|
|
2609
|
-
return {
|
|
2610
|
-
name: this.name,
|
|
2611
|
-
state: this.state,
|
|
2612
|
-
pending: this.pending,
|
|
2613
|
-
stats: this.stats,
|
|
2614
|
-
rateLimiter: this.#rateLimiter.snapshot,
|
|
2615
|
-
activeRunners: this.#activeRunners,
|
|
2616
|
-
runningNodes: this.#runningNodes,
|
|
2617
|
-
isIdle: this.isIdle,
|
|
2618
|
-
isWaiting: this.isWaiting,
|
|
2619
|
-
isRunning: this.isRunning,
|
|
2620
|
-
isPaused: this.isPaused,
|
|
2621
|
-
isStopped: this.isStopped,
|
|
2622
|
-
isDraining: this.isDraining,
|
|
2623
|
-
isEmpty: this.pending === 0
|
|
2624
|
-
};
|
|
2625
|
-
}
|
|
2626
|
-
};
|
|
2627
|
-
|
|
2628
|
-
// node_modules/@logosdx/observer/dist/esm/engine.mjs
|
|
2629
|
-
var ObserverEngine = class _ObserverEngine {
|
|
2630
|
-
#listenerMap = /* @__PURE__ */ new Map();
|
|
2631
|
-
#rgxListenerMap = /* @__PURE__ */ new Map();
|
|
2632
|
-
#internalListener = new EventTarget();
|
|
2633
|
-
#emitValidator;
|
|
2634
|
-
#spy;
|
|
2635
|
-
// Hidden property for holding the spy function
|
|
2636
|
-
// when debugging is enabled. Used to restore the
|
|
2637
|
-
// original spy function when debugging is disabled.
|
|
2638
|
-
#__spy;
|
|
2639
|
-
// Instance-level AbortController for cleanup
|
|
2640
|
-
#instanceController = new AbortController();
|
|
2641
|
-
#instanceSignal;
|
|
2642
|
-
constructor(options) {
|
|
2643
|
-
if (options) {
|
|
2644
|
-
assert(!options.name || typeof options.name === "string", "Observable options.name must be a string", TypeError);
|
|
2645
|
-
assert(!options.spy || typeof options.spy === "function", "Observable options.spy must be a function", TypeError);
|
|
2646
|
-
assert(!options.emitValidator || typeof options.emitValidator === "function", "Observable options.emitValidator must be a function", TypeError);
|
|
2647
|
-
this.#spy = options.spy;
|
|
2648
|
-
}
|
|
2649
|
-
this.#instanceSignal = this.#instanceController.signal;
|
|
2650
|
-
const userSignal = options?.signal;
|
|
2651
|
-
const clearOnAbort = () => this.clear();
|
|
2652
|
-
this.#instanceSignal.addEventListener("abort", clearOnAbort, {
|
|
2653
|
-
once: true
|
|
2654
|
-
});
|
|
2655
|
-
if (userSignal) {
|
|
2656
|
-
userSignal.addEventListener("abort", clearOnAbort, {
|
|
2657
|
-
once: true
|
|
2658
|
-
});
|
|
2659
|
-
}
|
|
2660
|
-
definePrivateProps(this, {
|
|
2661
|
-
on: this.on,
|
|
2662
|
-
once: this.once,
|
|
2663
|
-
emit: this.emit,
|
|
2664
|
-
off: this.off,
|
|
2665
|
-
observe: this.observe,
|
|
2666
|
-
debug: this.debug,
|
|
2667
|
-
$has: this.$has,
|
|
2668
|
-
$facts: this.$facts,
|
|
2669
|
-
$internals: this.$internals,
|
|
2670
|
-
name: options?.name || Math.random().toString(36).substring(7)
|
|
2671
|
-
});
|
|
2672
|
-
this.#emitValidator = options?.emitValidator;
|
|
2673
|
-
}
|
|
2674
|
-
name;
|
|
2675
|
-
/**
|
|
2676
|
-
* Returns facts about the the internal state of the observable instance.
|
|
2677
|
-
*/
|
|
2678
|
-
$facts() {
|
|
2679
|
-
const listenKeys = [
|
|
2680
|
-
...this.#listenerMap.keys()
|
|
2681
|
-
];
|
|
2682
|
-
const rgxKeys = [
|
|
2683
|
-
...this.#rgxListenerMap.keys()
|
|
2684
|
-
];
|
|
2685
|
-
const listenerCounts = Object.fromEntries([
|
|
2686
|
-
listenKeys.map((k) => [
|
|
2687
|
-
k,
|
|
2688
|
-
this.#listenerMap.get(k)?.size
|
|
2689
|
-
]),
|
|
2690
|
-
rgxKeys.map((k) => [
|
|
2691
|
-
k,
|
|
2692
|
-
this.#rgxListenerMap.get(k)?.size
|
|
2693
|
-
])
|
|
2694
|
-
].flat());
|
|
2695
|
-
return {
|
|
2696
|
-
listeners: listenKeys,
|
|
2697
|
-
rgxListeners: rgxKeys,
|
|
2698
|
-
listenerCounts,
|
|
2699
|
-
hasSpy: !!this.#spy
|
|
2700
|
-
};
|
|
2701
|
-
}
|
|
2702
|
-
/**
|
|
2703
|
-
* The internals of the observable instance.
|
|
2704
|
-
*
|
|
2705
|
-
* NOTE: Do not use this to try to meddle with the
|
|
2706
|
-
* internals of the observable instance. This is for
|
|
2707
|
-
* debugging purposes only.
|
|
2708
|
-
*/
|
|
2709
|
-
$internals() {
|
|
2710
|
-
return {
|
|
2711
|
-
listenerMap: clone(this.#listenerMap),
|
|
2712
|
-
rgxListenerMap: clone(this.#rgxListenerMap),
|
|
2713
|
-
internalListener: clone(this.#internalListener),
|
|
2714
|
-
name: this.name,
|
|
2715
|
-
spy: this.#spy
|
|
2716
|
-
};
|
|
2717
|
-
}
|
|
2718
|
-
$has(event) {
|
|
2719
|
-
if (event instanceof RegExp) {
|
|
2720
|
-
return this.#rgxListenerMap.has(event.toString());
|
|
2721
|
-
}
|
|
2722
|
-
return this.#listenerMap.has(event) || this.#rgxListenerMap.has(event);
|
|
2723
|
-
}
|
|
2724
|
-
#currentSpy(...args) {
|
|
2725
|
-
if (this.#spy) {
|
|
2726
|
-
this.#spy.apply(this, args);
|
|
2727
|
-
}
|
|
2728
|
-
}
|
|
2729
|
-
/**
|
|
2730
|
-
* Enables or disables debugging for the observable instance.
|
|
2731
|
-
* Works in conjunction with your spy function. Provides a
|
|
2732
|
-
* stack trace of events that are triggered, listened to, and
|
|
2733
|
-
* cleaned up.
|
|
2734
|
-
*
|
|
2735
|
-
* @param on Whether to enable or disable debugging
|
|
2736
|
-
*/
|
|
2737
|
-
debug(on = true) {
|
|
2738
|
-
const original = this.#spy;
|
|
2739
|
-
const spy = (ev) => {
|
|
2740
|
-
const { event, fn, data, listener } = ev;
|
|
2741
|
-
console.info(makeEventTracer(event, fn, data || listener));
|
|
2742
|
-
original && original(ev);
|
|
2743
|
-
};
|
|
2744
|
-
if (on) {
|
|
2745
|
-
this.#spy = spy;
|
|
2746
|
-
this.#__spy = original;
|
|
2747
|
-
return;
|
|
2748
|
-
}
|
|
2749
|
-
this.#spy = this.#__spy;
|
|
2750
|
-
}
|
|
2751
|
-
/**
|
|
2752
|
-
* Sets the spy function for the observable instance.
|
|
2753
|
-
* @param spy The spy function to set
|
|
2754
|
-
* @param force Whether to force the spy function to be set even if one is already set
|
|
2755
|
-
*/
|
|
2756
|
-
spy(spy, force = false) {
|
|
2757
|
-
assert(isFunction(spy), "spy must be a function", TypeError);
|
|
2758
|
-
assert(force || this.#spy === void 0, "you already have a spy function set", TypeError);
|
|
2759
|
-
this.#spy = spy;
|
|
2760
|
-
}
|
|
2761
|
-
/**
|
|
2762
|
-
* Observes given component as an extension of this observable instance.
|
|
2763
|
-
* @param component Component to wrap events around
|
|
2764
|
-
* @param options Optional configuration including signal for cleanup
|
|
2765
|
-
*
|
|
2766
|
-
* @example
|
|
2767
|
-
*
|
|
2768
|
-
* const obs = new ObserverEngine();
|
|
2769
|
-
*
|
|
2770
|
-
* const modal = {};
|
|
2771
|
-
*
|
|
2772
|
-
* obs.observe(modal);
|
|
2773
|
-
*
|
|
2774
|
-
* modal.on('modal-open', () => {});
|
|
2775
|
-
*
|
|
2776
|
-
* obs.trigger('modal-open'); // opens modal
|
|
2777
|
-
* modal.trigger('modal-open'); // opens modal
|
|
2778
|
-
*
|
|
2779
|
-
* modal.cleanup(); // clears all event listeners
|
|
2780
|
-
*/
|
|
2781
|
-
observe(component, options) {
|
|
2782
|
-
const self = this;
|
|
2783
|
-
const userSignal = options?.signal;
|
|
2784
|
-
if (userSignal?.aborted) {
|
|
2785
|
-
definePrivateProps(component, {
|
|
2786
|
-
on: noop,
|
|
2787
|
-
once: noop,
|
|
2788
|
-
off: noop,
|
|
2789
|
-
emit: noop,
|
|
2790
|
-
clear: noop,
|
|
2791
|
-
cleanup: noop
|
|
2792
|
-
});
|
|
2793
|
-
return component;
|
|
2794
|
-
}
|
|
2795
|
-
const track = /* @__PURE__ */ new Map();
|
|
2796
|
-
const trackListener = (event, fn) => {
|
|
2797
|
-
const _set = track.get(event) || /* @__PURE__ */ new Set();
|
|
2798
|
-
_set.add(fn);
|
|
2799
|
-
track.set(event, _set);
|
|
2800
|
-
return fn;
|
|
2801
|
-
};
|
|
2802
|
-
const rmAll = () => {
|
|
2803
|
-
for (const entry of track.entries()) {
|
|
2804
|
-
const [ev, _set] = entry;
|
|
2805
|
-
[
|
|
2806
|
-
..._set
|
|
2807
|
-
].forEach((fn) => self.off(ev, fn));
|
|
2808
|
-
track.set(ev, /* @__PURE__ */ new Set());
|
|
2809
|
-
}
|
|
2810
|
-
};
|
|
2811
|
-
const afterOff = (_event) => {
|
|
2812
|
-
const [event, callback] = _event.data;
|
|
2813
|
-
const _set = track.get(event);
|
|
2814
|
-
_set?.delete(callback);
|
|
2815
|
-
};
|
|
2816
|
-
this.#internalListener.addEventListener(InternalEvs.off, afterOff);
|
|
2817
|
-
this.#internalListener.addEventListener(InternalEvs.clear, rmAll);
|
|
2818
|
-
const on = (ev, fn) => {
|
|
2819
|
-
return self.on(ev, trackListener(ev, fn));
|
|
2820
|
-
};
|
|
2821
|
-
const once = (ev, fn) => {
|
|
2822
|
-
return self.once(ev, trackListener(ev, fn));
|
|
2823
|
-
};
|
|
2824
|
-
const off = (ev, fn) => {
|
|
2825
|
-
self.off(ev, fn);
|
|
2826
|
-
};
|
|
2827
|
-
const emit = (ev, data) => {
|
|
2828
|
-
return self.emit(ev, data);
|
|
2829
|
-
};
|
|
2830
|
-
const clear = () => rmAll();
|
|
2831
|
-
let observeAbortCtrl;
|
|
2832
|
-
const cleanup = () => {
|
|
2833
|
-
rmAll();
|
|
2834
|
-
self.#internalListener.removeEventListener(InternalEvs.off, afterOff);
|
|
2835
|
-
self.#internalListener.removeEventListener(InternalEvs.clear, rmAll);
|
|
2836
|
-
observeAbortCtrl?.abort();
|
|
2837
|
-
};
|
|
2838
|
-
if (userSignal) {
|
|
2839
|
-
observeAbortCtrl = new AbortController();
|
|
2840
|
-
const composedSignal = AbortSignal.any([
|
|
2841
|
-
this.#instanceSignal,
|
|
2842
|
-
userSignal
|
|
2843
|
-
]);
|
|
2844
|
-
composedSignal.addEventListener("abort", cleanup, {
|
|
2845
|
-
signal: observeAbortCtrl.signal
|
|
2846
|
-
});
|
|
2847
|
-
}
|
|
2848
|
-
definePrivateProps(component, {
|
|
2849
|
-
on,
|
|
2850
|
-
once,
|
|
2851
|
-
off,
|
|
2852
|
-
emit,
|
|
2853
|
-
clear,
|
|
2854
|
-
cleanup
|
|
2855
|
-
});
|
|
2856
|
-
return component;
|
|
2857
|
-
}
|
|
2858
|
-
/**
|
|
2859
|
-
* Gets information about the event, whether it's a regex or not,
|
|
2860
|
-
* the event name, and the regex itself.
|
|
2861
|
-
*/
|
|
2862
|
-
#eventInfo(event) {
|
|
2863
|
-
const isRgx = event.constructor === RegExp;
|
|
2864
|
-
const eventName = event.toString();
|
|
2865
|
-
return {
|
|
2866
|
-
isRgx,
|
|
2867
|
-
eventName,
|
|
2868
|
-
rgx: event
|
|
2869
|
-
};
|
|
2870
|
-
}
|
|
2871
|
-
/**
|
|
2872
|
-
* Returns all event names that match the regex
|
|
2873
|
-
*/
|
|
2874
|
-
#withRgxMatchKeys(rgx) {
|
|
2875
|
-
return [
|
|
2876
|
-
...this.#listenerMap.keys()
|
|
2877
|
-
].filter((k) => rgx.test(k));
|
|
2878
|
-
}
|
|
2879
|
-
/**
|
|
2880
|
-
* Returns all regexes that match the key
|
|
2881
|
-
*/
|
|
2882
|
-
#withKeyMatchRgx(key) {
|
|
2883
|
-
return [
|
|
2884
|
-
...this.#rgxListenerMap.keys()
|
|
2885
|
-
].filter((s) => rgxStrToRgx(s).test(key)).flat();
|
|
2886
|
-
}
|
|
2887
|
-
/**
|
|
2888
|
-
* Returns all event names that match the regex
|
|
2889
|
-
*/
|
|
2890
|
-
#matchStr(rgx) {
|
|
2891
|
-
const events = this.#withRgxMatchKeys(rgx);
|
|
2892
|
-
return arrOfMatchingValues(events, this.#listenerMap);
|
|
2893
|
-
}
|
|
2894
|
-
/**
|
|
2895
|
-
* Returns all regexes that match the key
|
|
2896
|
-
*/
|
|
2897
|
-
#matchRgx(str) {
|
|
2898
|
-
const events = this.#withKeyMatchRgx(str);
|
|
2899
|
-
return arrOfMatchingValues(events, this.#rgxListenerMap);
|
|
2900
|
-
}
|
|
2901
|
-
/**
|
|
2902
|
-
* Listen for an event
|
|
2903
|
-
* @param event
|
|
2904
|
-
* @param listenerOrOptions - Either a callback function or options object
|
|
2905
|
-
* @param options
|
|
2906
|
-
*/
|
|
2907
|
-
on(event, listenerOrOptions, options) {
|
|
2908
|
-
const isListenerFn = typeof listenerOrOptions === "function";
|
|
2909
|
-
const listener = isListenerFn ? listenerOrOptions : void 0;
|
|
2910
|
-
const resolvedOptions = isListenerFn ? options : listenerOrOptions;
|
|
2911
|
-
if (!resolvedOptions?.once) {
|
|
2912
|
-
validateEvent("on", {
|
|
2913
|
-
event,
|
|
2914
|
-
listener
|
|
2915
|
-
});
|
|
2916
|
-
validateListener("on", {
|
|
2917
|
-
event,
|
|
2918
|
-
listener
|
|
2919
|
-
});
|
|
2920
|
-
}
|
|
2921
|
-
if (listener === void 0) {
|
|
2922
|
-
return new EventGenerator(this, event, resolvedOptions);
|
|
2923
|
-
}
|
|
2924
|
-
const userSignal = resolvedOptions?.signal;
|
|
2925
|
-
if (userSignal?.aborted) {
|
|
2926
|
-
return () => {
|
|
2927
|
-
};
|
|
2928
|
-
}
|
|
2929
|
-
const { eventName, isRgx } = this.#eventInfo(event);
|
|
2930
|
-
const listenerMap = isRgx ? this.#rgxListenerMap : this.#listenerMap;
|
|
2931
|
-
this.#currentSpy({
|
|
2932
|
-
event,
|
|
2933
|
-
fn: resolvedOptions?.once ? "once" : "on",
|
|
2934
|
-
data: null,
|
|
2935
|
-
listener,
|
|
2936
|
-
context: this
|
|
2937
|
-
});
|
|
2938
|
-
const cbSet = listenerMap.get(eventName) || /* @__PURE__ */ new Set([
|
|
2939
|
-
listener
|
|
2940
|
-
]);
|
|
2941
|
-
if (cbSet && !cbSet.has(listener)) {
|
|
2942
|
-
cbSet.add(listener);
|
|
2943
|
-
}
|
|
2944
|
-
if (!listenerMap.has(eventName)) {
|
|
2945
|
-
listenerMap.set(eventName, cbSet);
|
|
2946
|
-
}
|
|
2947
|
-
this.#internalListener.dispatchEvent(new InternalEvent(InternalEvs.on, [
|
|
2948
|
-
event,
|
|
2949
|
-
listener
|
|
2950
|
-
]));
|
|
2951
|
-
let cleanedUp = false;
|
|
2952
|
-
const cleanup = () => {
|
|
2953
|
-
if (cleanedUp) return;
|
|
2954
|
-
cleanedUp = true;
|
|
2955
|
-
this.#currentSpy({
|
|
2956
|
-
event,
|
|
2957
|
-
fn: "cleanup",
|
|
2958
|
-
data: null,
|
|
2959
|
-
listener,
|
|
2960
|
-
context: this
|
|
2961
|
-
});
|
|
2962
|
-
cbSet.delete(listener);
|
|
2963
|
-
if (cbSet.size === 0) {
|
|
2964
|
-
listenerMap.delete(eventName);
|
|
2965
|
-
}
|
|
2966
|
-
this.#internalListener.dispatchEvent(new InternalEvent(InternalEvs.off, [
|
|
2967
|
-
event,
|
|
2968
|
-
listener
|
|
2969
|
-
]));
|
|
2970
|
-
};
|
|
2971
|
-
if (userSignal) {
|
|
2972
|
-
const abortHandler = () => {
|
|
2973
|
-
cleanup();
|
|
2974
|
-
this.#instanceSignal.removeEventListener("abort", abortHandler);
|
|
2975
|
-
};
|
|
2976
|
-
userSignal.addEventListener("abort", abortHandler, {
|
|
2977
|
-
once: true
|
|
2978
|
-
});
|
|
2979
|
-
this.#instanceSignal.addEventListener("abort", abortHandler, {
|
|
2980
|
-
once: true
|
|
2981
|
-
});
|
|
2982
|
-
const originalCleanup = cleanup;
|
|
2983
|
-
const wrappedCleanup = () => {
|
|
2984
|
-
originalCleanup();
|
|
2985
|
-
userSignal.removeEventListener("abort", abortHandler);
|
|
2986
|
-
this.#instanceSignal.removeEventListener("abort", abortHandler);
|
|
2987
|
-
};
|
|
2988
|
-
return wrappedCleanup;
|
|
2989
|
-
}
|
|
2990
|
-
return cleanup;
|
|
2991
|
-
}
|
|
2992
|
-
/**
|
|
2993
|
-
* Executes a callback once when the specified
|
|
2994
|
-
* event is emitted, or returns a promise that
|
|
2995
|
-
* resolves when the event is emitted
|
|
2996
|
-
*/
|
|
2997
|
-
once(event, listenerOrOptions, options) {
|
|
2998
|
-
const isListenerFn = typeof listenerOrOptions === "function";
|
|
2999
|
-
const listener = isListenerFn ? listenerOrOptions : void 0;
|
|
3000
|
-
const resolvedOptions = isListenerFn ? options : listenerOrOptions;
|
|
3001
|
-
validateEvent("once", {
|
|
3002
|
-
event,
|
|
3003
|
-
listener
|
|
3004
|
-
});
|
|
3005
|
-
validateListener("once", {
|
|
3006
|
-
event,
|
|
3007
|
-
listener
|
|
3008
|
-
});
|
|
3009
|
-
if (!listener) {
|
|
3010
|
-
const defer = new DeferredEvent();
|
|
3011
|
-
const userSignal = resolvedOptions?.signal;
|
|
3012
|
-
if (userSignal?.aborted) {
|
|
3013
|
-
defer.reject(userSignal.reason ?? new DOMException("Aborted", "AbortError"));
|
|
3014
|
-
defer.promise.cleanup = () => {
|
|
3015
|
-
};
|
|
3016
|
-
return defer.promise;
|
|
3017
|
-
}
|
|
3018
|
-
let promiseAbortCtrl;
|
|
3019
|
-
const cleanup = this.once(event, (data) => {
|
|
3020
|
-
defer.resolve(data);
|
|
3021
|
-
promiseAbortCtrl?.abort();
|
|
3022
|
-
}, resolvedOptions);
|
|
3023
|
-
if (userSignal) {
|
|
3024
|
-
promiseAbortCtrl = new AbortController();
|
|
3025
|
-
userSignal.addEventListener("abort", () => {
|
|
3026
|
-
cleanup();
|
|
3027
|
-
defer.reject(userSignal.reason ?? new DOMException("Aborted", "AbortError"));
|
|
3028
|
-
}, {
|
|
3029
|
-
signal: promiseAbortCtrl.signal
|
|
3030
|
-
});
|
|
3031
|
-
}
|
|
3032
|
-
defer.promise.cleanup = () => {
|
|
3033
|
-
cleanup();
|
|
3034
|
-
promiseAbortCtrl?.abort();
|
|
3035
|
-
};
|
|
3036
|
-
return defer.promise;
|
|
3037
|
-
}
|
|
3038
|
-
const self = this;
|
|
3039
|
-
const runOnce = function(...args) {
|
|
3040
|
-
const { eventName, isRgx } = self.#eventInfo(event);
|
|
3041
|
-
const listenerMap = isRgx ? self.#rgxListenerMap : self.#listenerMap;
|
|
3042
|
-
const fns = listenerMap.get(eventName);
|
|
3043
|
-
if (fns) {
|
|
3044
|
-
fns.delete(runOnce);
|
|
3045
|
-
if (fns.size === 0) listenerMap.delete(eventName);
|
|
3046
|
-
}
|
|
3047
|
-
listener.apply(self, args);
|
|
3048
|
-
};
|
|
3049
|
-
return this.on(event, runOnce, {
|
|
3050
|
-
once: true,
|
|
3051
|
-
...resolvedOptions
|
|
3052
|
-
});
|
|
3053
|
-
}
|
|
3054
|
-
/**
|
|
3055
|
-
* Stop listening for an event
|
|
3056
|
-
* @param event
|
|
3057
|
-
* @param listener
|
|
3058
|
-
*/
|
|
3059
|
-
off(event, listener) {
|
|
3060
|
-
validateEvent("off", {
|
|
3061
|
-
event,
|
|
3062
|
-
listener
|
|
3063
|
-
});
|
|
3064
|
-
this.#currentSpy({
|
|
3065
|
-
event,
|
|
3066
|
-
fn: "off",
|
|
3067
|
-
data: null,
|
|
3068
|
-
listener,
|
|
3069
|
-
context: this
|
|
3070
|
-
});
|
|
3071
|
-
const { eventName, isRgx, rgx } = this.#eventInfo(event);
|
|
3072
|
-
const matches = isRgx ? this.#withRgxMatchKeys(rgx) : [
|
|
3073
|
-
eventName
|
|
3074
|
-
];
|
|
3075
|
-
matches.forEach((_ev) => {
|
|
3076
|
-
const ev = _ev;
|
|
3077
|
-
this.#internalListener.dispatchEvent(new InternalEvent(InternalEvs.off, [
|
|
3078
|
-
ev,
|
|
3079
|
-
listener
|
|
3080
|
-
]));
|
|
3081
|
-
if (listener) {
|
|
3082
|
-
const fns = this.#listenerMap.get(ev);
|
|
3083
|
-
if (fns) {
|
|
3084
|
-
fns.delete(listener);
|
|
3085
|
-
if (fns.size === 0) this.#listenerMap.delete(ev);
|
|
3086
|
-
}
|
|
3087
|
-
return;
|
|
3088
|
-
}
|
|
3089
|
-
this.#listenerMap.delete(ev);
|
|
3090
|
-
});
|
|
3091
|
-
}
|
|
3092
|
-
/** Emits an event */
|
|
3093
|
-
emit(event, data) {
|
|
3094
|
-
validateEvent("emit", {
|
|
3095
|
-
event,
|
|
3096
|
-
data
|
|
3097
|
-
});
|
|
3098
|
-
if (this.#emitValidator) {
|
|
3099
|
-
this.#emitValidator(event, data, this);
|
|
3100
|
-
}
|
|
3101
|
-
this.#currentSpy({
|
|
3102
|
-
event,
|
|
3103
|
-
fn: "emit",
|
|
3104
|
-
data,
|
|
3105
|
-
listener: null,
|
|
3106
|
-
context: this
|
|
3107
|
-
});
|
|
3108
|
-
const { eventName, isRgx, rgx } = this.#eventInfo(event);
|
|
3109
|
-
if (!isRgx) {
|
|
3110
|
-
const cbs2 = this.#listenerMap.get(eventName);
|
|
3111
|
-
const rgxCbs = this.#matchRgx(eventName);
|
|
3112
|
-
if (cbs2) cbs2.forEach((fn) => fn.apply(this, [
|
|
3113
|
-
data,
|
|
3114
|
-
{
|
|
3115
|
-
event,
|
|
3116
|
-
listener: fn
|
|
3117
|
-
}
|
|
3118
|
-
]));
|
|
3119
|
-
if (rgxCbs) rgxCbs.forEach(({ func }) => func.apply(this, [
|
|
3120
|
-
{
|
|
3121
|
-
data,
|
|
3122
|
-
event,
|
|
3123
|
-
listener: func
|
|
3124
|
-
}
|
|
3125
|
-
]));
|
|
3126
|
-
this.#internalListener.dispatchEvent(new InternalEvent(InternalEvs.emit, [
|
|
3127
|
-
eventName,
|
|
3128
|
-
data
|
|
3129
|
-
]));
|
|
3130
|
-
return;
|
|
3131
|
-
}
|
|
3132
|
-
const cbs = this.#matchStr(rgx);
|
|
3133
|
-
if (cbs) cbs.forEach(({ event: event2, func }) => func.apply(this, [
|
|
3134
|
-
data,
|
|
3135
|
-
{
|
|
3136
|
-
event: event2,
|
|
3137
|
-
listener: func
|
|
3138
|
-
}
|
|
3139
|
-
]));
|
|
3140
|
-
this.#withRgxMatchKeys(rgx).forEach((ev) => {
|
|
3141
|
-
this.#internalListener.dispatchEvent(new InternalEvent(InternalEvs.emit, [
|
|
3142
|
-
ev,
|
|
3143
|
-
data
|
|
3144
|
-
]));
|
|
3145
|
-
});
|
|
3146
|
-
}
|
|
3147
|
-
clear() {
|
|
3148
|
-
this.#listenerMap.clear();
|
|
3149
|
-
this.#rgxListenerMap.clear();
|
|
3150
|
-
this.#internalListener.dispatchEvent(new InternalEvent(InternalEvs.clear, [
|
|
3151
|
-
"clear",
|
|
3152
|
-
null
|
|
3153
|
-
]));
|
|
3154
|
-
}
|
|
3155
|
-
queue(event, process2, options) {
|
|
3156
|
-
return new EventQueue({
|
|
3157
|
-
...options,
|
|
3158
|
-
event,
|
|
3159
|
-
process: process2,
|
|
3160
|
-
observer: this
|
|
3161
|
-
});
|
|
3162
|
-
}
|
|
3163
|
-
/**
|
|
3164
|
-
* Checks if an event key passes through the filter/exclude pipeline.
|
|
3165
|
-
* Filter narrows first, then exclude removes from that set.
|
|
3166
|
-
*/
|
|
3167
|
-
static #passesFilter(event, options) {
|
|
3168
|
-
if (!options) return true;
|
|
3169
|
-
const { filter, exclude } = options;
|
|
3170
|
-
if (filter) {
|
|
3171
|
-
const passes = filter.some((f) => f instanceof RegExp ? f.test(event) : f === event);
|
|
3172
|
-
if (!passes) return false;
|
|
3173
|
-
}
|
|
3174
|
-
if (exclude) {
|
|
3175
|
-
const blocked = exclude.some((e) => e instanceof RegExp ? e.test(event) : e === event);
|
|
3176
|
-
if (blocked) return false;
|
|
3177
|
-
}
|
|
3178
|
-
return true;
|
|
3179
|
-
}
|
|
3180
|
-
/**
|
|
3181
|
-
* Moves or copies listeners between two ObserverEngine instances.
|
|
3182
|
-
* Static methods on the same class can access # private fields directly.
|
|
3183
|
-
*/
|
|
3184
|
-
static #moveListeners(source, target, remove, options) {
|
|
3185
|
-
for (const [event, callbacks] of source.#listenerMap) {
|
|
3186
|
-
if (!_ObserverEngine.#passesFilter(event, options)) continue;
|
|
3187
|
-
const targetSet = target.#listenerMap.get(event) || /* @__PURE__ */ new Set();
|
|
3188
|
-
for (const cb of callbacks) {
|
|
3189
|
-
targetSet.add(cb);
|
|
3190
|
-
}
|
|
3191
|
-
target.#listenerMap.set(event, targetSet);
|
|
3192
|
-
if (remove) {
|
|
3193
|
-
source.#listenerMap.delete(event);
|
|
3194
|
-
}
|
|
3195
|
-
}
|
|
3196
|
-
for (const [event, callbacks] of source.#rgxListenerMap) {
|
|
3197
|
-
if (!_ObserverEngine.#passesFilter(event, options)) continue;
|
|
3198
|
-
const targetSet = target.#rgxListenerMap.get(event) || /* @__PURE__ */ new Set();
|
|
3199
|
-
for (const cb of callbacks) {
|
|
3200
|
-
targetSet.add(cb);
|
|
3201
|
-
}
|
|
3202
|
-
target.#rgxListenerMap.set(event, targetSet);
|
|
3203
|
-
if (remove) {
|
|
3204
|
-
source.#rgxListenerMap.delete(event);
|
|
3205
|
-
}
|
|
3206
|
-
}
|
|
3207
|
-
}
|
|
3208
|
-
/**
|
|
3209
|
-
* Transfers all matching listeners from source to target, removing
|
|
3210
|
-
* them from the source. Target's existing listeners are preserved.
|
|
3211
|
-
*
|
|
3212
|
-
* Useful when cloning an engine (e.g. FetchEngine) and carrying
|
|
3213
|
-
* over observability listeners to the new instance.
|
|
3214
|
-
*
|
|
3215
|
-
* @example
|
|
3216
|
-
*
|
|
3217
|
-
* const old = new ObserverEngine();
|
|
3218
|
-
* const next = new ObserverEngine();
|
|
3219
|
-
*
|
|
3220
|
-
* old.on('ready', handler);
|
|
3221
|
-
*
|
|
3222
|
-
* ObserverEngine.transfer(old, next);
|
|
3223
|
-
* // `next` now owns the 'ready' listener; `old` has none
|
|
3224
|
-
*
|
|
3225
|
-
* @example
|
|
3226
|
-
*
|
|
3227
|
-
* // Transfer only specific events
|
|
3228
|
-
* ObserverEngine.transfer(old, next, {
|
|
3229
|
-
* filter: ['ready', /^user\./]
|
|
3230
|
-
* });
|
|
3231
|
-
*/
|
|
3232
|
-
static transfer(source, target, options) {
|
|
3233
|
-
_ObserverEngine.#moveListeners(source, target, true, options);
|
|
3234
|
-
}
|
|
3235
|
-
/**
|
|
3236
|
-
* Copies all matching listeners from source to target without
|
|
3237
|
-
* removing them from the source. Target's existing listeners
|
|
3238
|
-
* are preserved.
|
|
3239
|
-
*
|
|
3240
|
-
* Useful when forking an engine so both instances react to the
|
|
3241
|
-
* same events independently.
|
|
3242
|
-
*
|
|
3243
|
-
* @example
|
|
3244
|
-
*
|
|
3245
|
-
* const primary = new ObserverEngine();
|
|
3246
|
-
* const mirror = new ObserverEngine();
|
|
3247
|
-
*
|
|
3248
|
-
* primary.on('update', handler);
|
|
3249
|
-
*
|
|
3250
|
-
* ObserverEngine.copy(primary, mirror);
|
|
3251
|
-
* // Both engines now have the 'update' listener
|
|
3252
|
-
*
|
|
3253
|
-
* @example
|
|
3254
|
-
*
|
|
3255
|
-
* // Copy everything except internal events
|
|
3256
|
-
* ObserverEngine.copy(primary, mirror, {
|
|
3257
|
-
* exclude: [/^__/]
|
|
3258
|
-
* });
|
|
3259
|
-
*/
|
|
3260
|
-
static copy(source, target, options) {
|
|
3261
|
-
_ObserverEngine.#moveListeners(source, target, false, options);
|
|
3262
|
-
}
|
|
3263
|
-
};
|
|
3264
|
-
|
|
3265
|
-
// node_modules/@logosdx/observer/dist/esm/relay.mjs
|
|
3266
|
-
var ObserverRelay = class {
|
|
3267
|
-
#pub;
|
|
3268
|
-
#sub;
|
|
3269
|
-
#subEmit;
|
|
3270
|
-
#isShutdown = false;
|
|
3271
|
-
emit;
|
|
3272
|
-
on;
|
|
3273
|
-
once;
|
|
3274
|
-
off;
|
|
3275
|
-
queue;
|
|
3276
|
-
constructor(options) {
|
|
3277
|
-
const name = options?.name;
|
|
3278
|
-
this.#pub = new ObserverEngine({
|
|
3279
|
-
name: name ? `${name}:pub` : void 0,
|
|
3280
|
-
spy: options?.spy,
|
|
3281
|
-
signal: options?.signal,
|
|
3282
|
-
emitValidator: options?.emitValidator?.pub
|
|
3283
|
-
});
|
|
3284
|
-
this.#sub = new ObserverEngine({
|
|
3285
|
-
name: name ? `${name}:sub` : void 0,
|
|
3286
|
-
spy: options?.spy,
|
|
3287
|
-
signal: options?.signal,
|
|
3288
|
-
emitValidator: options?.emitValidator?.sub
|
|
3289
|
-
});
|
|
3290
|
-
this.on = this.#sub.on.bind(this.#sub);
|
|
3291
|
-
this.once = this.#sub.once.bind(this.#sub);
|
|
3292
|
-
this.off = this.#sub.off.bind(this.#sub);
|
|
3293
|
-
this.queue = this.#sub.queue.bind(this.#sub);
|
|
3294
|
-
this.#subEmit = this.#sub.emit.bind(this.#sub);
|
|
3295
|
-
const pubEmit = this.#pub.emit.bind(this.#pub);
|
|
3296
|
-
this.emit = (event, data) => {
|
|
3297
|
-
if (this.#isShutdown) return;
|
|
3298
|
-
pubEmit(event, data);
|
|
3299
|
-
};
|
|
3300
|
-
this.#pub.on(/.+/, ({ event, data }) => this.send(event, data));
|
|
3301
|
-
if (options?.signal) {
|
|
3302
|
-
options.signal.addEventListener("abort", () => {
|
|
3303
|
-
this.#isShutdown = true;
|
|
3304
|
-
});
|
|
3305
|
-
}
|
|
3306
|
-
}
|
|
3307
|
-
receive(event, data, ctx) {
|
|
3308
|
-
if (this.#isShutdown) return;
|
|
3309
|
-
this.#subEmit(event, {
|
|
3310
|
-
data,
|
|
3311
|
-
ctx
|
|
3312
|
-
});
|
|
3313
|
-
}
|
|
3314
|
-
spy(spy) {
|
|
3315
|
-
if (this.#isShutdown) return;
|
|
3316
|
-
this.#pub.spy(spy, true);
|
|
3317
|
-
this.#sub.spy(spy, true);
|
|
3318
|
-
}
|
|
3319
|
-
$has(event) {
|
|
3320
|
-
return {
|
|
3321
|
-
pub: this.#pub.$has(event),
|
|
3322
|
-
sub: this.#sub.$has(event)
|
|
3323
|
-
};
|
|
3324
|
-
}
|
|
3325
|
-
$facts() {
|
|
3326
|
-
return {
|
|
3327
|
-
pub: this.#pub.$facts(),
|
|
3328
|
-
sub: this.#sub.$facts()
|
|
3329
|
-
};
|
|
3330
|
-
}
|
|
3331
|
-
$internals() {
|
|
3332
|
-
return {
|
|
3333
|
-
pub: this.#pub.$internals(),
|
|
3334
|
-
sub: this.#sub.$internals()
|
|
3335
|
-
};
|
|
3336
|
-
}
|
|
3337
|
-
get isShutdown() {
|
|
3338
|
-
return this.#isShutdown;
|
|
3339
|
-
}
|
|
3340
|
-
shutdown() {
|
|
3341
|
-
if (this.#isShutdown) return;
|
|
3342
|
-
this.#isShutdown = true;
|
|
3343
|
-
this.#pub.clear();
|
|
3344
|
-
this.#sub.clear();
|
|
3345
|
-
}
|
|
3346
|
-
};
|
|
3347
|
-
|
|
3348
|
-
// src/core/environment.ts
|
|
3349
|
-
function isDebug() {
|
|
3350
|
-
return isEnvTruthy(process.env["NOORM_DEBUG"]);
|
|
3351
|
-
}
|
|
3352
|
-
function isEnvTruthy(value) {
|
|
3353
|
-
if (!value) return false;
|
|
3354
|
-
const normalized = value.toLowerCase();
|
|
3355
|
-
return normalized !== "0" && normalized !== "false";
|
|
3356
|
-
}
|
|
3357
|
-
function shouldSkipConfirmations() {
|
|
3358
|
-
return isEnvTruthy(process.env["NOORM_YES"]);
|
|
3359
|
-
}
|
|
3360
|
-
function getEnvConfigName() {
|
|
3361
|
-
return process.env["NOORM_CONFIG"];
|
|
3362
|
-
}
|
|
3363
|
-
|
|
3364
|
-
// src/core/observer.ts
|
|
3365
|
-
var observer = new ObserverEngine({
|
|
3366
|
-
name: "noorm",
|
|
3367
|
-
spy: isDebug() ? (action) => console.error(`[noorm:${action.fn}] ${String(action.event)}`) : void 0
|
|
3368
|
-
});
|
|
3369
|
-
|
|
3370
|
-
export { ObserverRelay, attempt, attemptSync, clone, equals, getEnvConfigName, gigabytes, isDebug, isTimeoutError, makeNestedConfig, merge, observer, retry, runWithTimeout, shouldSkipConfirmations, wait };
|
|
3371
|
-
//# sourceMappingURL=chunk-LY2F7ZFI.js.map
|
|
3372
|
-
//# sourceMappingURL=chunk-LY2F7ZFI.js.map
|
|
1855
|
+
export { Deferred, PriorityQueue, RateLimitTokenBucket, TimeoutError, assert, attempt, attemptSync, clone, definePrivateProps, equals, generateId, gigabytes, isFunction, isPlainObject, isTimeoutError, makeNestedConfig, merge, noop, retry, runWithTimeout, wait };
|
|
1856
|
+
//# sourceMappingURL=chunk-TXDGFA44.js.map
|
|
1857
|
+
//# sourceMappingURL=chunk-TXDGFA44.js.map
|