@n8n/utils 1.18.0 → 1.19.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/assert.cjs +2 -11
- package/dist/assert.d.cts +2 -5
- package/dist/assert.d.mts +2 -0
- package/dist/assert.mjs +3 -0
- package/dist/assert2.cjs +17 -0
- package/dist/assert2.cjs.map +1 -0
- package/dist/{assert.d.ts → assert2.d.cts} +2 -2
- package/dist/assert2.d.mts +5 -0
- package/dist/{assert.js → assert2.mjs} +2 -2
- package/dist/assert2.mjs.map +1 -0
- package/dist/event-bus.cjs +2 -43
- package/dist/event-bus.d.cts +2 -14
- package/dist/event-bus.d.mts +2 -0
- package/dist/event-bus.mjs +3 -0
- package/dist/event-bus2.cjs +49 -0
- package/dist/event-bus2.cjs.map +1 -0
- package/dist/{event-bus.d.ts → event-bus2.d.cts} +2 -2
- package/dist/event-bus2.d.mts +14 -0
- package/dist/{event-bus.js → event-bus2.mjs} +2 -2
- package/dist/event-bus2.mjs.map +1 -0
- package/dist/event-queue.cjs +2 -40
- package/dist/event-queue.d.cts +2 -7
- package/dist/event-queue.d.mts +2 -0
- package/dist/event-queue.mjs +3 -0
- package/dist/event-queue2.cjs +46 -0
- package/dist/event-queue2.cjs.map +1 -0
- package/dist/{event-queue.d.ts → event-queue2.d.cts} +2 -2
- package/dist/event-queue2.d.mts +7 -0
- package/dist/{event-queue.js → event-queue2.mjs} +2 -2
- package/dist/event-queue2.mjs.map +1 -0
- package/dist/index.cjs +21 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +11 -0
- package/dist/number/smartDecimal.cjs +2 -10
- package/dist/number/smartDecimal.d.cts +2 -5
- package/dist/number/smartDecimal.d.mts +2 -0
- package/dist/number/smartDecimal.mjs +3 -0
- package/dist/reRankSearchResults.cjs +25 -0
- package/dist/reRankSearchResults.cjs.map +1 -0
- package/dist/{search/reRankSearchResults.d.ts → reRankSearchResults.d.cts} +2 -2
- package/dist/reRankSearchResults.d.mts +13 -0
- package/dist/{search/reRankSearchResults.js → reRankSearchResults.mjs} +2 -2
- package/dist/reRankSearchResults.mjs.map +1 -0
- package/dist/retry.cjs +2 -39
- package/dist/retry.d.cts +2 -6
- package/dist/retry.d.mts +2 -0
- package/dist/retry.mjs +3 -0
- package/dist/retry2.cjs +45 -0
- package/dist/retry2.cjs.map +1 -0
- package/dist/{retry.d.ts → retry2.d.cts} +2 -2
- package/dist/retry2.d.mts +6 -0
- package/dist/{retry.js → retry2.mjs} +2 -2
- package/dist/retry2.mjs.map +1 -0
- package/dist/search/reRankSearchResults.cjs +2 -19
- package/dist/search/reRankSearchResults.d.cts +2 -13
- package/dist/search/reRankSearchResults.d.mts +2 -0
- package/dist/search/reRankSearchResults.mjs +3 -0
- package/dist/search/sublimeSearch.cjs +3 -172
- package/dist/search/sublimeSearch.d.cts +2 -15
- package/dist/search/sublimeSearch.d.mts +2 -0
- package/dist/search/sublimeSearch.mjs +3 -0
- package/dist/smartDecimal.cjs +16 -0
- package/dist/smartDecimal.cjs.map +1 -0
- package/dist/{number/smartDecimal.d.ts → smartDecimal.d.cts} +2 -2
- package/dist/smartDecimal.d.mts +5 -0
- package/dist/{number/smartDecimal.js → smartDecimal.mjs} +2 -2
- package/dist/smartDecimal.mjs.map +1 -0
- package/dist/sort/sortByProperty.cjs +2 -12
- package/dist/sort/sortByProperty.d.cts +2 -5
- package/dist/sort/sortByProperty.d.mts +2 -0
- package/dist/sort/sortByProperty.mjs +3 -0
- package/dist/sortByProperty.cjs +18 -0
- package/dist/sortByProperty.cjs.map +1 -0
- package/dist/{sort/sortByProperty.d.ts → sortByProperty.d.cts} +2 -2
- package/dist/sortByProperty.d.mts +5 -0
- package/dist/{sort/sortByProperty.js → sortByProperty.mjs} +2 -2
- package/dist/sortByProperty.mjs.map +1 -0
- package/dist/string/truncate.cjs +3 -30
- package/dist/string/truncate.d.cts +2 -6
- package/dist/string/truncate.d.mts +2 -0
- package/dist/string/truncate.mjs +3 -0
- package/dist/sublimeSearch.cjs +183 -0
- package/dist/sublimeSearch.cjs.map +1 -0
- package/dist/{search/sublimeSearch.d.ts → sublimeSearch.d.cts} +2 -2
- package/dist/sublimeSearch.d.mts +15 -0
- package/dist/{search/sublimeSearch.js → sublimeSearch.mjs} +2 -2
- package/dist/sublimeSearch.mjs.map +1 -0
- package/dist/truncate.cjs +41 -0
- package/dist/truncate.cjs.map +1 -0
- package/dist/{string/truncate.d.ts → truncate.d.cts} +2 -2
- package/dist/truncate.d.mts +6 -0
- package/dist/{string/truncate.js → truncate.mjs} +2 -2
- package/dist/truncate.mjs.map +1 -0
- package/package.json +14 -6
- package/dist/assert.cjs.map +0 -1
- package/dist/assert.js.map +0 -1
- package/dist/event-bus.cjs.map +0 -1
- package/dist/event-bus.js.map +0 -1
- package/dist/event-queue.cjs.map +0 -1
- package/dist/event-queue.js.map +0 -1
- package/dist/number/smartDecimal.cjs.map +0 -1
- package/dist/number/smartDecimal.js.map +0 -1
- package/dist/retry.cjs.map +0 -1
- package/dist/retry.js.map +0 -1
- package/dist/search/reRankSearchResults.cjs.map +0 -1
- package/dist/search/reRankSearchResults.js.map +0 -1
- package/dist/search/sublimeSearch.cjs.map +0 -1
- package/dist/search/sublimeSearch.js.map +0 -1
- package/dist/sort/sortByProperty.cjs.map +0 -1
- package/dist/sort/sortByProperty.js.map +0 -1
- package/dist/string/truncate.cjs.map +0 -1
- package/dist/string/truncate.js.map +0 -1
package/dist/assert.cjs
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
+
const require_assert = require('./assert2.cjs');
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Asserts given condition
|
|
5
|
-
*/
|
|
6
|
-
function assert(condition, message) {
|
|
7
|
-
if (!condition) throw new Error(message ?? "Assertion failed");
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
//#endregion
|
|
11
|
-
exports.assert = assert;
|
|
12
|
-
//# sourceMappingURL=assert.cjs.map
|
|
3
|
+
exports.assert = require_assert.assert;
|
package/dist/assert.d.cts
CHANGED
package/dist/assert.mjs
ADDED
package/dist/assert2.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/assert.ts
|
|
3
|
+
/**
|
|
4
|
+
* Asserts given condition
|
|
5
|
+
*/
|
|
6
|
+
function assert(condition, message) {
|
|
7
|
+
if (!condition) throw new Error(message ?? "Assertion failed");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
Object.defineProperty(exports, 'assert', {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () {
|
|
14
|
+
return assert;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=assert2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert2.cjs","names":[],"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Asserts given condition\n */\nexport function assert(condition: unknown, message?: string): asserts condition {\n\tif (!condition) {\n\t\t// eslint-disable-next-line n8n-local-rules/no-plain-errors\n\t\tthrow new Error(message ?? 'Assertion failed');\n\t}\n}\n"],"mappings":";;;;;AAGA,SAAgB,OAAO,WAAoB,SAAqC;AAC/E,KAAI,CAAC,UAEJ,OAAM,IAAI,MAAM,WAAW,mBAAmB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert2.mjs","names":[],"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Asserts given condition\n */\nexport function assert(condition: unknown, message?: string): asserts condition {\n\tif (!condition) {\n\t\t// eslint-disable-next-line n8n-local-rules/no-plain-errors\n\t\tthrow new Error(message ?? 'Assertion failed');\n\t}\n}\n"],"mappings":";;;;AAGA,SAAgB,OAAO,WAAoB,SAAqC;AAC/E,KAAI,CAAC,UAEJ,OAAM,IAAI,MAAM,WAAW,mBAAmB"}
|
package/dist/event-bus.cjs
CHANGED
|
@@ -1,44 +1,3 @@
|
|
|
1
|
+
const require_event_bus = require('./event-bus2.cjs');
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates an event bus with the given listener map.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* const eventBus = createEventBus<{
|
|
9
|
-
* 'user-logged-in': { username: string };
|
|
10
|
-
* 'user-logged-out': never;
|
|
11
|
-
* }>();
|
|
12
|
-
*/
|
|
13
|
-
function createEventBus() {
|
|
14
|
-
const handlers = /* @__PURE__ */ new Map();
|
|
15
|
-
return {
|
|
16
|
-
on(eventName, fn) {
|
|
17
|
-
let eventFns = handlers.get(eventName);
|
|
18
|
-
if (!eventFns) eventFns = [fn];
|
|
19
|
-
else eventFns.push(fn);
|
|
20
|
-
handlers.set(eventName, eventFns);
|
|
21
|
-
},
|
|
22
|
-
once(eventName, fn) {
|
|
23
|
-
const handler = (payload) => {
|
|
24
|
-
this.off(eventName, handler);
|
|
25
|
-
fn(payload);
|
|
26
|
-
};
|
|
27
|
-
this.on(eventName, handler);
|
|
28
|
-
},
|
|
29
|
-
off(eventName, fn) {
|
|
30
|
-
const eventFns = handlers.get(eventName);
|
|
31
|
-
if (eventFns) eventFns.splice(eventFns.indexOf(fn) >>> 0, 1);
|
|
32
|
-
},
|
|
33
|
-
emit(eventName, event) {
|
|
34
|
-
const eventFns = handlers.get(eventName);
|
|
35
|
-
if (eventFns) eventFns.slice().forEach((handler) => {
|
|
36
|
-
handler(event);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
//#endregion
|
|
43
|
-
exports.createEventBus = createEventBus;
|
|
44
|
-
//# sourceMappingURL=event-bus.cjs.map
|
|
3
|
+
exports.createEventBus = require_event_bus.createEventBus;
|
package/dist/event-bus.d.cts
CHANGED
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
type Payloads<ListenerMap> = { [E in keyof ListenerMap]: unknown };
|
|
4
|
-
type Listener<Payload> = (payload: Payload) => void;
|
|
5
|
-
interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {
|
|
6
|
-
on<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
7
|
-
once<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
8
|
-
off<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
9
|
-
emit<EventName extends keyof ListenerMap & string>(eventName: EventName, event?: ListenerMap[EventName]): void;
|
|
10
|
-
}
|
|
11
|
-
declare function createEventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>>(): EventBus<ListenerMap>;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { CallbackFn, EventBus, createEventBus };
|
|
14
|
-
//# sourceMappingURL=event-bus.d.cts.map
|
|
1
|
+
import { n as EventBus, r as createEventBus, t as CallbackFn } from "./event-bus2.cjs";
|
|
2
|
+
export { CallbackFn, EventBus, createEventBus };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/event-bus.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates an event bus with the given listener map.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const eventBus = createEventBus<{
|
|
9
|
+
* 'user-logged-in': { username: string };
|
|
10
|
+
* 'user-logged-out': never;
|
|
11
|
+
* }>();
|
|
12
|
+
*/
|
|
13
|
+
function createEventBus() {
|
|
14
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
15
|
+
return {
|
|
16
|
+
on(eventName, fn) {
|
|
17
|
+
let eventFns = handlers.get(eventName);
|
|
18
|
+
if (!eventFns) eventFns = [fn];
|
|
19
|
+
else eventFns.push(fn);
|
|
20
|
+
handlers.set(eventName, eventFns);
|
|
21
|
+
},
|
|
22
|
+
once(eventName, fn) {
|
|
23
|
+
const handler = (payload) => {
|
|
24
|
+
this.off(eventName, handler);
|
|
25
|
+
fn(payload);
|
|
26
|
+
};
|
|
27
|
+
this.on(eventName, handler);
|
|
28
|
+
},
|
|
29
|
+
off(eventName, fn) {
|
|
30
|
+
const eventFns = handlers.get(eventName);
|
|
31
|
+
if (eventFns) eventFns.splice(eventFns.indexOf(fn) >>> 0, 1);
|
|
32
|
+
},
|
|
33
|
+
emit(eventName, event) {
|
|
34
|
+
const eventFns = handlers.get(eventName);
|
|
35
|
+
if (eventFns) eventFns.slice().forEach((handler) => {
|
|
36
|
+
handler(event);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
Object.defineProperty(exports, 'createEventBus', {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return createEventBus;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=event-bus2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bus2.cjs","names":["handler: typeof fn"],"sources":["../src/event-bus.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CallbackFn = (...args: any[]) => any;\n\ntype Payloads<ListenerMap> = {\n\t[E in keyof ListenerMap]: unknown;\n};\n\ntype Listener<Payload> = (payload: Payload) => void;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {\n\ton<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\tonce<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\toff<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\temit<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tevent?: ListenerMap[EventName],\n\t): void;\n}\n\n/**\n * Creates an event bus with the given listener map.\n *\n * @example\n * ```ts\n * const eventBus = createEventBus<{\n * 'user-logged-in': { username: string };\n * 'user-logged-out': never;\n * }>();\n */\nexport function createEventBus<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tListenerMap extends Payloads<ListenerMap> = Record<string, any>,\n>(): EventBus<ListenerMap> {\n\tconst handlers = new Map<string, CallbackFn[]>();\n\n\treturn {\n\t\ton(eventName, fn) {\n\t\t\tlet eventFns = handlers.get(eventName);\n\t\t\tif (!eventFns) {\n\t\t\t\teventFns = [fn];\n\t\t\t} else {\n\t\t\t\teventFns.push(fn);\n\t\t\t}\n\t\t\thandlers.set(eventName, eventFns);\n\t\t},\n\n\t\tonce(eventName, fn) {\n\t\t\tconst handler: typeof fn = (payload) => {\n\t\t\t\tthis.off(eventName, handler);\n\t\t\t\tfn(payload);\n\t\t\t};\n\t\t\tthis.on(eventName, handler);\n\t\t},\n\n\t\toff(eventName, fn) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.splice(eventFns.indexOf(fn) >>> 0, 1);\n\t\t\t}\n\t\t},\n\n\t\temit(eventName, event) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.slice().forEach((handler) => {\n\t\t\t\t\thandler(event);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;AA0CA,SAAgB,iBAGW;CAC1B,MAAM,2BAAW,IAAI,KAA2B;AAEhD,QAAO;EACN,GAAG,WAAW,IAAI;GACjB,IAAI,WAAW,SAAS,IAAI,UAAU;AACtC,OAAI,CAAC,SACJ,YAAW,CAAC,GAAG;OAEf,UAAS,KAAK,GAAG;AAElB,YAAS,IAAI,WAAW,SAAS;;EAGlC,KAAK,WAAW,IAAI;GACnB,MAAMA,WAAsB,YAAY;AACvC,SAAK,IAAI,WAAW,QAAQ;AAC5B,OAAG,QAAQ;;AAEZ,QAAK,GAAG,WAAW,QAAQ;;EAG5B,IAAI,WAAW,IAAI;GAClB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,SAAS,QAAQ,GAAG,KAAK,GAAG,EAAE;;EAIhD,KAAK,WAAW,OAAO;GACtB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,CAAC,SAAS,YAAY;AACrC,YAAQ,MAAM;KACb;;EAGJ"}
|
|
@@ -10,5 +10,5 @@ interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, an
|
|
|
10
10
|
}
|
|
11
11
|
declare function createEventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>>(): EventBus<ListenerMap>;
|
|
12
12
|
//#endregion
|
|
13
|
-
export {
|
|
14
|
-
//# sourceMappingURL=event-
|
|
13
|
+
export { EventBus as n, createEventBus as r, CallbackFn as t };
|
|
14
|
+
//# sourceMappingURL=event-bus2.d.cts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/event-bus.d.ts
|
|
2
|
+
type CallbackFn = (...args: any[]) => any;
|
|
3
|
+
type Payloads<ListenerMap> = { [E in keyof ListenerMap]: unknown };
|
|
4
|
+
type Listener<Payload> = (payload: Payload) => void;
|
|
5
|
+
interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {
|
|
6
|
+
on<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
7
|
+
once<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
8
|
+
off<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
9
|
+
emit<EventName extends keyof ListenerMap & string>(eventName: EventName, event?: ListenerMap[EventName]): void;
|
|
10
|
+
}
|
|
11
|
+
declare function createEventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>>(): EventBus<ListenerMap>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { EventBus as n, createEventBus as r, CallbackFn as t };
|
|
14
|
+
//# sourceMappingURL=event-bus2.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bus2.mjs","names":["handler: typeof fn"],"sources":["../src/event-bus.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CallbackFn = (...args: any[]) => any;\n\ntype Payloads<ListenerMap> = {\n\t[E in keyof ListenerMap]: unknown;\n};\n\ntype Listener<Payload> = (payload: Payload) => void;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {\n\ton<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\tonce<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\toff<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\temit<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tevent?: ListenerMap[EventName],\n\t): void;\n}\n\n/**\n * Creates an event bus with the given listener map.\n *\n * @example\n * ```ts\n * const eventBus = createEventBus<{\n * 'user-logged-in': { username: string };\n * 'user-logged-out': never;\n * }>();\n */\nexport function createEventBus<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tListenerMap extends Payloads<ListenerMap> = Record<string, any>,\n>(): EventBus<ListenerMap> {\n\tconst handlers = new Map<string, CallbackFn[]>();\n\n\treturn {\n\t\ton(eventName, fn) {\n\t\t\tlet eventFns = handlers.get(eventName);\n\t\t\tif (!eventFns) {\n\t\t\t\teventFns = [fn];\n\t\t\t} else {\n\t\t\t\teventFns.push(fn);\n\t\t\t}\n\t\t\thandlers.set(eventName, eventFns);\n\t\t},\n\n\t\tonce(eventName, fn) {\n\t\t\tconst handler: typeof fn = (payload) => {\n\t\t\t\tthis.off(eventName, handler);\n\t\t\t\tfn(payload);\n\t\t\t};\n\t\t\tthis.on(eventName, handler);\n\t\t},\n\n\t\toff(eventName, fn) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.splice(eventFns.indexOf(fn) >>> 0, 1);\n\t\t\t}\n\t\t},\n\n\t\temit(eventName, event) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.slice().forEach((handler) => {\n\t\t\t\t\thandler(event);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;AA0CA,SAAgB,iBAGW;CAC1B,MAAM,2BAAW,IAAI,KAA2B;AAEhD,QAAO;EACN,GAAG,WAAW,IAAI;GACjB,IAAI,WAAW,SAAS,IAAI,UAAU;AACtC,OAAI,CAAC,SACJ,YAAW,CAAC,GAAG;OAEf,UAAS,KAAK,GAAG;AAElB,YAAS,IAAI,WAAW,SAAS;;EAGlC,KAAK,WAAW,IAAI;GACnB,MAAMA,WAAsB,YAAY;AACvC,SAAK,IAAI,WAAW,QAAQ;AAC5B,OAAG,QAAQ;;AAEZ,QAAK,GAAG,WAAW,QAAQ;;EAG5B,IAAI,WAAW,IAAI;GAClB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,SAAS,QAAQ,GAAG,KAAK,GAAG,EAAE;;EAIhD,KAAK,WAAW,OAAO;GACtB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,CAAC,SAAS,YAAY;AACrC,YAAQ,MAAM;KACb;;EAGJ"}
|
package/dist/event-queue.cjs
CHANGED
|
@@ -1,41 +1,3 @@
|
|
|
1
|
+
const require_event_queue = require('./event-queue2.cjs');
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Create an event queue that processes events sequentially.
|
|
5
|
-
*
|
|
6
|
-
* @param processEvent - Async function that processes a single event.
|
|
7
|
-
* @returns A function that enqueues events for processing.
|
|
8
|
-
*/
|
|
9
|
-
function createEventQueue(processEvent) {
|
|
10
|
-
const queue = [];
|
|
11
|
-
let processing = false;
|
|
12
|
-
/**
|
|
13
|
-
* Process the next event in the queue (if not already processing).
|
|
14
|
-
*/
|
|
15
|
-
async function processNext() {
|
|
16
|
-
if (processing || queue.length === 0) return;
|
|
17
|
-
processing = true;
|
|
18
|
-
const currentEvent = queue.shift();
|
|
19
|
-
if (currentEvent !== void 0) try {
|
|
20
|
-
await processEvent(currentEvent);
|
|
21
|
-
} catch (error) {
|
|
22
|
-
console.error("Error processing event:", error);
|
|
23
|
-
}
|
|
24
|
-
processing = false;
|
|
25
|
-
await processNext();
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Enqueue an event and trigger processing.
|
|
29
|
-
*
|
|
30
|
-
* @param event - The event to enqueue.
|
|
31
|
-
*/
|
|
32
|
-
function enqueue(event) {
|
|
33
|
-
queue.push(event);
|
|
34
|
-
processNext();
|
|
35
|
-
}
|
|
36
|
-
return { enqueue };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
//#endregion
|
|
40
|
-
exports.createEventQueue = createEventQueue;
|
|
41
|
-
//# sourceMappingURL=event-queue.cjs.map
|
|
3
|
+
exports.createEventQueue = require_event_queue.createEventQueue;
|
package/dist/event-queue.d.cts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
enqueue: (event: T) => void;
|
|
4
|
-
};
|
|
5
|
-
//#endregion
|
|
6
|
-
export { createEventQueue };
|
|
7
|
-
//# sourceMappingURL=event-queue.d.cts.map
|
|
1
|
+
import { t as createEventQueue } from "./event-queue2.cjs";
|
|
2
|
+
export { createEventQueue };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/event-queue.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create an event queue that processes events sequentially.
|
|
5
|
+
*
|
|
6
|
+
* @param processEvent - Async function that processes a single event.
|
|
7
|
+
* @returns A function that enqueues events for processing.
|
|
8
|
+
*/
|
|
9
|
+
function createEventQueue(processEvent) {
|
|
10
|
+
const queue = [];
|
|
11
|
+
let processing = false;
|
|
12
|
+
/**
|
|
13
|
+
* Process the next event in the queue (if not already processing).
|
|
14
|
+
*/
|
|
15
|
+
async function processNext() {
|
|
16
|
+
if (processing || queue.length === 0) return;
|
|
17
|
+
processing = true;
|
|
18
|
+
const currentEvent = queue.shift();
|
|
19
|
+
if (currentEvent !== void 0) try {
|
|
20
|
+
await processEvent(currentEvent);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error("Error processing event:", error);
|
|
23
|
+
}
|
|
24
|
+
processing = false;
|
|
25
|
+
await processNext();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Enqueue an event and trigger processing.
|
|
29
|
+
*
|
|
30
|
+
* @param event - The event to enqueue.
|
|
31
|
+
*/
|
|
32
|
+
function enqueue(event) {
|
|
33
|
+
queue.push(event);
|
|
34
|
+
processNext();
|
|
35
|
+
}
|
|
36
|
+
return { enqueue };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
Object.defineProperty(exports, 'createEventQueue', {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () {
|
|
43
|
+
return createEventQueue;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=event-queue2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-queue2.cjs","names":["queue: T[]"],"sources":["../src/event-queue.ts"],"sourcesContent":["/**\n * Create an event queue that processes events sequentially.\n *\n * @param processEvent - Async function that processes a single event.\n * @returns A function that enqueues events for processing.\n */\nexport function createEventQueue<T>(processEvent: (event: T) => Promise<void>) {\n\t// The internal queue holding events.\n\tconst queue: T[] = [];\n\n\t// Flag to indicate whether an event is currently being processed.\n\tlet processing = false;\n\n\t/**\n\t * Process the next event in the queue (if not already processing).\n\t */\n\tasync function processNext(): Promise<void> {\n\t\tif (processing || queue.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tprocessing = true;\n\t\tconst currentEvent = queue.shift();\n\n\t\tif (currentEvent !== undefined) {\n\t\t\ttry {\n\t\t\t\tawait processEvent(currentEvent);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error processing event:', error);\n\t\t\t}\n\t\t}\n\n\t\tprocessing = false;\n\n\t\t// Recursively process the next event.\n\t\tawait processNext();\n\t}\n\n\t/**\n\t * Enqueue an event and trigger processing.\n\t *\n\t * @param event - The event to enqueue.\n\t */\n\tfunction enqueue(event: T): void {\n\t\tqueue.push(event);\n\t\tvoid processNext();\n\t}\n\n\treturn { enqueue };\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,iBAAoB,cAA2C;CAE9E,MAAMA,QAAa,EAAE;CAGrB,IAAI,aAAa;;;;CAKjB,eAAe,cAA6B;AAC3C,MAAI,cAAc,MAAM,WAAW,EAClC;AAGD,eAAa;EACb,MAAM,eAAe,MAAM,OAAO;AAElC,MAAI,iBAAiB,OACpB,KAAI;AACH,SAAM,aAAa,aAAa;WACxB,OAAO;AACf,WAAQ,MAAM,2BAA2B,MAAM;;AAIjD,eAAa;AAGb,QAAM,aAAa;;;;;;;CAQpB,SAAS,QAAQ,OAAgB;AAChC,QAAM,KAAK,MAAM;AACjB,EAAK,aAAa;;AAGnB,QAAO,EAAE,SAAS"}
|
|
@@ -3,5 +3,5 @@ declare function createEventQueue<T>(processEvent: (event: T) => Promise<void>):
|
|
|
3
3
|
enqueue: (event: T) => void;
|
|
4
4
|
};
|
|
5
5
|
//#endregion
|
|
6
|
-
export { createEventQueue };
|
|
7
|
-
//# sourceMappingURL=event-
|
|
6
|
+
export { createEventQueue as t };
|
|
7
|
+
//# sourceMappingURL=event-queue2.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-queue2.mjs","names":["queue: T[]"],"sources":["../src/event-queue.ts"],"sourcesContent":["/**\n * Create an event queue that processes events sequentially.\n *\n * @param processEvent - Async function that processes a single event.\n * @returns A function that enqueues events for processing.\n */\nexport function createEventQueue<T>(processEvent: (event: T) => Promise<void>) {\n\t// The internal queue holding events.\n\tconst queue: T[] = [];\n\n\t// Flag to indicate whether an event is currently being processed.\n\tlet processing = false;\n\n\t/**\n\t * Process the next event in the queue (if not already processing).\n\t */\n\tasync function processNext(): Promise<void> {\n\t\tif (processing || queue.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tprocessing = true;\n\t\tconst currentEvent = queue.shift();\n\n\t\tif (currentEvent !== undefined) {\n\t\t\ttry {\n\t\t\t\tawait processEvent(currentEvent);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error processing event:', error);\n\t\t\t}\n\t\t}\n\n\t\tprocessing = false;\n\n\t\t// Recursively process the next event.\n\t\tawait processNext();\n\t}\n\n\t/**\n\t * Enqueue an event and trigger processing.\n\t *\n\t * @param event - The event to enqueue.\n\t */\n\tfunction enqueue(event: T): void {\n\t\tqueue.push(event);\n\t\tvoid processNext();\n\t}\n\n\treturn { enqueue };\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,iBAAoB,cAA2C;CAE9E,MAAMA,QAAa,EAAE;CAGrB,IAAI,aAAa;;;;CAKjB,eAAe,cAA6B;AAC3C,MAAI,cAAc,MAAM,WAAW,EAClC;AAGD,eAAa;EACb,MAAM,eAAe,MAAM,OAAO;AAElC,MAAI,iBAAiB,OACpB,KAAI;AACH,SAAM,aAAa,aAAa;WACxB,OAAO;AACf,WAAQ,MAAM,2BAA2B,MAAM;;AAIjD,eAAa;AAGb,QAAM,aAAa;;;;;;;CAQpB,SAAS,QAAQ,OAAgB;AAChC,QAAM,KAAK,MAAM;AACjB,EAAK,aAAa;;AAGnB,QAAO,EAAE,SAAS"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const require_assert = require('./assert2.cjs');
|
|
2
|
+
const require_event_bus = require('./event-bus2.cjs');
|
|
3
|
+
const require_event_queue = require('./event-queue2.cjs');
|
|
4
|
+
const require_retry = require('./retry2.cjs');
|
|
5
|
+
const require_smartDecimal = require('./smartDecimal.cjs');
|
|
6
|
+
const require_reRankSearchResults = require('./reRankSearchResults.cjs');
|
|
7
|
+
const require_sublimeSearch = require('./sublimeSearch.cjs');
|
|
8
|
+
const require_sortByProperty = require('./sortByProperty.cjs');
|
|
9
|
+
const require_truncate = require('./truncate.cjs');
|
|
10
|
+
|
|
11
|
+
exports.DEFAULT_KEYS = require_sublimeSearch.DEFAULT_KEYS;
|
|
12
|
+
exports.assert = require_assert.assert;
|
|
13
|
+
exports.createEventBus = require_event_bus.createEventBus;
|
|
14
|
+
exports.createEventQueue = require_event_queue.createEventQueue;
|
|
15
|
+
exports.reRankSearchResults = require_reRankSearchResults.reRankSearchResults;
|
|
16
|
+
exports.retry = require_retry.retry;
|
|
17
|
+
exports.smartDecimal = require_smartDecimal.smartDecimal;
|
|
18
|
+
exports.sortByProperty = require_sortByProperty.sortByProperty;
|
|
19
|
+
exports.sublimeSearch = require_sublimeSearch.sublimeSearch;
|
|
20
|
+
exports.truncate = require_truncate.truncate;
|
|
21
|
+
exports.truncateBeforeLast = require_truncate.truncateBeforeLast;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as assert } from "./assert2.cjs";
|
|
2
|
+
import { n as EventBus, r as createEventBus, t as CallbackFn } from "./event-bus2.cjs";
|
|
3
|
+
import { t as createEventQueue } from "./event-queue2.cjs";
|
|
4
|
+
import { t as retry } from "./retry2.cjs";
|
|
5
|
+
import { t as smartDecimal } from "./smartDecimal.cjs";
|
|
6
|
+
import { t as reRankSearchResults } from "./reRankSearchResults.cjs";
|
|
7
|
+
import { n as sublimeSearch, t as DEFAULT_KEYS } from "./sublimeSearch.cjs";
|
|
8
|
+
import { t as sortByProperty } from "./sortByProperty.cjs";
|
|
9
|
+
import { n as truncateBeforeLast, t as truncate } from "./truncate.cjs";
|
|
10
|
+
export { CallbackFn, DEFAULT_KEYS, EventBus, assert, createEventBus, createEventQueue, reRankSearchResults, retry, smartDecimal, sortByProperty, sublimeSearch, truncate, truncateBeforeLast };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as assert } from "./assert2.mjs";
|
|
2
|
+
import { n as EventBus, r as createEventBus, t as CallbackFn } from "./event-bus2.mjs";
|
|
3
|
+
import { t as createEventQueue } from "./event-queue2.mjs";
|
|
4
|
+
import { t as retry } from "./retry2.mjs";
|
|
5
|
+
import { t as smartDecimal } from "./smartDecimal.mjs";
|
|
6
|
+
import { t as reRankSearchResults } from "./reRankSearchResults.mjs";
|
|
7
|
+
import { n as sublimeSearch, t as DEFAULT_KEYS } from "./sublimeSearch.mjs";
|
|
8
|
+
import { t as sortByProperty } from "./sortByProperty.mjs";
|
|
9
|
+
import { n as truncateBeforeLast, t as truncate } from "./truncate.mjs";
|
|
10
|
+
export { CallbackFn, DEFAULT_KEYS, EventBus, assert, createEventBus, createEventQueue, reRankSearchResults, retry, smartDecimal, sortByProperty, sublimeSearch, truncate, truncateBeforeLast };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { t as assert } from "./assert2.mjs";
|
|
2
|
+
import { t as createEventBus } from "./event-bus2.mjs";
|
|
3
|
+
import { t as createEventQueue } from "./event-queue2.mjs";
|
|
4
|
+
import { t as retry } from "./retry2.mjs";
|
|
5
|
+
import { t as smartDecimal } from "./smartDecimal.mjs";
|
|
6
|
+
import { t as reRankSearchResults } from "./reRankSearchResults.mjs";
|
|
7
|
+
import { n as sublimeSearch, t as DEFAULT_KEYS } from "./sublimeSearch.mjs";
|
|
8
|
+
import { t as sortByProperty } from "./sortByProperty.mjs";
|
|
9
|
+
import { n as truncateBeforeLast, t as truncate } from "./truncate.mjs";
|
|
10
|
+
|
|
11
|
+
export { DEFAULT_KEYS, assert, createEventBus, createEventQueue, reRankSearchResults, retry, smartDecimal, sortByProperty, sublimeSearch, truncate, truncateBeforeLast };
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
+
const require_smartDecimal = require('../smartDecimal.cjs');
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
const smartDecimal = (value, decimals = 2) => {
|
|
4
|
-
if (Number.isInteger(value)) return value;
|
|
5
|
-
if (value.toString().split(".")[1].length <= decimals) return value;
|
|
6
|
-
return Number(value.toFixed(decimals));
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
//#endregion
|
|
10
|
-
exports.smartDecimal = smartDecimal;
|
|
11
|
-
//# sourceMappingURL=smartDecimal.cjs.map
|
|
3
|
+
exports.smartDecimal = require_smartDecimal.smartDecimal;
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//#endregion
|
|
4
|
-
export { smartDecimal };
|
|
5
|
-
//# sourceMappingURL=smartDecimal.d.cts.map
|
|
1
|
+
import { t as smartDecimal } from "../smartDecimal.cjs";
|
|
2
|
+
export { smartDecimal };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/search/reRankSearchResults.ts
|
|
3
|
+
function reRankSearchResults(searchResults, additionalFactors) {
|
|
4
|
+
return searchResults.map(({ score, item }) => {
|
|
5
|
+
return {
|
|
6
|
+
score: score + Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {
|
|
7
|
+
const factorScore = factorScores[item.key];
|
|
8
|
+
if (factorScore) return acc + factorScore;
|
|
9
|
+
return acc;
|
|
10
|
+
}, 0),
|
|
11
|
+
item
|
|
12
|
+
};
|
|
13
|
+
}).sort((a, b) => {
|
|
14
|
+
return b.score - a.score;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
Object.defineProperty(exports, 'reRankSearchResults', {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return reRankSearchResults;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=reRankSearchResults.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reRankSearchResults.cjs","names":[],"sources":["../src/search/reRankSearchResults.ts"],"sourcesContent":["export function reRankSearchResults<T extends { key: string }>(\n\tsearchResults: Array<{ score: number; item: T }>,\n\tadditionalFactors: Record<string, Record<string, number>>,\n): Array<{ score: number; item: T }> {\n\treturn searchResults\n\t\t.map(({ score, item }) => {\n\t\t\t// For each additional factor, we check if it exists for the item and type,\n\t\t\t// and if so, we add the score to the item's score.\n\t\t\tconst additionalScore = Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {\n\t\t\t\tconst factorScore = factorScores[item.key];\n\t\t\t\tif (factorScore) {\n\t\t\t\t\treturn acc + factorScore;\n\t\t\t\t}\n\n\t\t\t\treturn acc;\n\t\t\t}, 0);\n\n\t\t\treturn {\n\t\t\t\tscore: score + additionalScore,\n\t\t\t\titem,\n\t\t\t};\n\t\t})\n\t\t.sort((a, b) => {\n\t\t\treturn b.score - a.score;\n\t\t});\n}\n"],"mappings":";;AAAA,SAAgB,oBACf,eACA,mBACoC;AACpC,QAAO,cACL,KAAK,EAAE,OAAO,WAAW;AAYzB,SAAO;GACN,OAAO,QAVgB,OAAO,QAAQ,kBAAkB,CAAC,QAAQ,KAAK,CAAC,GAAG,kBAAkB;IAC5F,MAAM,cAAc,aAAa,KAAK;AACtC,QAAI,YACH,QAAO,MAAM;AAGd,WAAO;MACL,EAAE;GAIJ;GACA;GACA,CACD,MAAM,GAAG,MAAM;AACf,SAAO,EAAE,QAAQ,EAAE;GAClB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/search/reRankSearchResults.d.ts
|
|
2
|
+
declare function reRankSearchResults<T extends {
|
|
3
|
+
key: string;
|
|
4
|
+
}>(searchResults: Array<{
|
|
5
|
+
score: number;
|
|
6
|
+
item: T;
|
|
7
|
+
}>, additionalFactors: Record<string, Record<string, number>>): Array<{
|
|
8
|
+
score: number;
|
|
9
|
+
item: T;
|
|
10
|
+
}>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { reRankSearchResults as t };
|
|
13
|
+
//# sourceMappingURL=reRankSearchResults.d.mts.map
|
|
@@ -15,5 +15,5 @@ function reRankSearchResults(searchResults, additionalFactors) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
|
-
export { reRankSearchResults };
|
|
19
|
-
//# sourceMappingURL=reRankSearchResults.
|
|
18
|
+
export { reRankSearchResults as t };
|
|
19
|
+
//# sourceMappingURL=reRankSearchResults.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reRankSearchResults.mjs","names":[],"sources":["../src/search/reRankSearchResults.ts"],"sourcesContent":["export function reRankSearchResults<T extends { key: string }>(\n\tsearchResults: Array<{ score: number; item: T }>,\n\tadditionalFactors: Record<string, Record<string, number>>,\n): Array<{ score: number; item: T }> {\n\treturn searchResults\n\t\t.map(({ score, item }) => {\n\t\t\t// For each additional factor, we check if it exists for the item and type,\n\t\t\t// and if so, we add the score to the item's score.\n\t\t\tconst additionalScore = Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {\n\t\t\t\tconst factorScore = factorScores[item.key];\n\t\t\t\tif (factorScore) {\n\t\t\t\t\treturn acc + factorScore;\n\t\t\t\t}\n\n\t\t\t\treturn acc;\n\t\t\t}, 0);\n\n\t\t\treturn {\n\t\t\t\tscore: score + additionalScore,\n\t\t\t\titem,\n\t\t\t};\n\t\t})\n\t\t.sort((a, b) => {\n\t\t\treturn b.score - a.score;\n\t\t});\n}\n"],"mappings":";AAAA,SAAgB,oBACf,eACA,mBACoC;AACpC,QAAO,cACL,KAAK,EAAE,OAAO,WAAW;AAYzB,SAAO;GACN,OAAO,QAVgB,OAAO,QAAQ,kBAAkB,CAAC,QAAQ,KAAK,CAAC,GAAG,kBAAkB;IAC5F,MAAM,cAAc,aAAa,KAAK;AACtC,QAAI,YACH,QAAO,MAAM;AAGd,WAAO;MACL,EAAE;GAIJ;GACA;GACA,CACD,MAAM,GAAG,MAAM;AACf,SAAO,EAAE,QAAQ,EAAE;GAClB"}
|
package/dist/retry.cjs
CHANGED
|
@@ -1,40 +1,3 @@
|
|
|
1
|
+
const require_retry = require('./retry2.cjs');
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A utility that retries a function every `interval` milliseconds
|
|
5
|
-
* until the function returns true or the maximum number of retries is reached.
|
|
6
|
-
*
|
|
7
|
-
* @param fn - A function that returns a boolean or a Promise resolving to a boolean.
|
|
8
|
-
* @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.
|
|
9
|
-
* @param maxRetries - The maximum number of retry attempts. Defaults to 3.
|
|
10
|
-
* @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.
|
|
11
|
-
* @returns {Promise<boolean>} - A promise that resolves to:
|
|
12
|
-
* - true: If the function returns true before reaching maxRetries.
|
|
13
|
-
* - false: If the function never returns true or if an error occurs.
|
|
14
|
-
*/
|
|
15
|
-
async function retry(fn, interval = 1e3, maxRetries = 3, backoff = "linear") {
|
|
16
|
-
let attempt = 0;
|
|
17
|
-
while (attempt < maxRetries) {
|
|
18
|
-
attempt++;
|
|
19
|
-
try {
|
|
20
|
-
if (await fn()) return true;
|
|
21
|
-
} catch (error) {
|
|
22
|
-
console.error("Error during retry:", error);
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
25
|
-
if (attempt < maxRetries) {
|
|
26
|
-
let computedInterval = interval;
|
|
27
|
-
if (backoff === "linear") computedInterval = interval * attempt;
|
|
28
|
-
else if (backoff === "exponential") {
|
|
29
|
-
computedInterval = Math.pow(2, attempt - 1) * interval;
|
|
30
|
-
computedInterval = Math.min(computedInterval, 3e4);
|
|
31
|
-
}
|
|
32
|
-
await new Promise((resolve) => setTimeout(resolve, computedInterval));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
//#endregion
|
|
39
|
-
exports.retry = retry;
|
|
40
|
-
//# sourceMappingURL=retry.cjs.map
|
|
3
|
+
exports.retry = require_retry.retry;
|
package/dist/retry.d.cts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare function retry(fn: RetryFn, interval?: number, maxRetries?: number, backoff?: 'exponential' | 'linear' | null): Promise<boolean>;
|
|
4
|
-
//#endregion
|
|
5
|
-
export { retry };
|
|
6
|
-
//# sourceMappingURL=retry.d.cts.map
|
|
1
|
+
import { t as retry } from "./retry2.cjs";
|
|
2
|
+
export { retry };
|
package/dist/retry.d.mts
ADDED