@n8n/utils 1.17.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 -9
- package/dist/assert.d.cts +2 -3
- 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/assert2.d.cts +5 -0
- package/dist/assert2.d.mts +5 -0
- package/dist/assert2.mjs +11 -0
- package/dist/assert2.mjs.map +1 -0
- package/dist/event-bus.cjs +2 -39
- 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-bus2.d.cts +14 -0
- package/dist/event-bus2.d.mts +14 -0
- package/dist/event-bus2.mjs +43 -0
- package/dist/event-bus2.mjs.map +1 -0
- package/dist/event-queue.cjs +2 -29
- package/dist/event-queue.d.cts +2 -5
- 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-queue2.d.cts +7 -0
- package/dist/event-queue2.d.mts +7 -0
- package/dist/event-queue2.mjs +40 -0
- 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 -13
- package/dist/number/smartDecimal.d.cts +2 -3
- 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/reRankSearchResults.d.cts +13 -0
- package/dist/reRankSearchResults.d.mts +13 -0
- package/dist/reRankSearchResults.mjs +19 -0
- package/dist/reRankSearchResults.mjs.map +1 -0
- package/dist/retry.cjs +2 -30
- package/dist/retry.d.cts +2 -4
- 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} +4 -2
- package/dist/retry2.d.mts +6 -0
- package/dist/retry2.mjs +39 -0
- package/dist/retry2.mjs.map +1 -0
- package/dist/search/reRankSearchResults.cjs +2 -21
- package/dist/search/reRankSearchResults.d.cts +2 -11
- package/dist/search/reRankSearchResults.d.mts +2 -0
- package/dist/search/reRankSearchResults.mjs +3 -0
- package/dist/search/sublimeSearch.cjs +3 -197
- package/dist/search/sublimeSearch.d.cts +2 -13
- 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/smartDecimal.d.cts +5 -0
- package/dist/smartDecimal.d.mts +5 -0
- package/dist/smartDecimal.mjs +10 -0
- package/dist/smartDecimal.mjs.map +1 -0
- package/dist/sort/sortByProperty.cjs +2 -11
- package/dist/sort/sortByProperty.d.cts +2 -3
- 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/sortByProperty.d.cts +5 -0
- package/dist/sortByProperty.d.mts +5 -0
- package/dist/sortByProperty.mjs +12 -0
- package/dist/sortByProperty.mjs.map +1 -0
- package/dist/string/truncate.cjs +3 -30
- package/dist/string/truncate.d.cts +2 -4
- 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/sublimeSearch.d.cts +15 -0
- package/dist/sublimeSearch.d.mts +15 -0
- package/dist/sublimeSearch.mjs +171 -0
- 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} +4 -2
- package/dist/truncate.d.mts +6 -0
- package/dist/truncate.mjs +29 -0
- package/dist/truncate.mjs.map +1 -0
- package/package.json +20 -12
- package/dist/assert.cjs.map +0 -1
- package/dist/assert.d.ts +0 -3
- package/dist/assert.js +0 -10
- package/dist/assert.js.map +0 -1
- package/dist/event-bus.cjs.map +0 -1
- package/dist/event-bus.d.ts +0 -14
- package/dist/event-bus.js +0 -40
- package/dist/event-bus.js.map +0 -1
- package/dist/event-queue.cjs.map +0 -1
- package/dist/event-queue.d.ts +0 -5
- package/dist/event-queue.js +0 -30
- package/dist/event-queue.js.map +0 -1
- package/dist/number/smartDecimal.cjs.map +0 -1
- package/dist/number/smartDecimal.d.ts +0 -3
- package/dist/number/smartDecimal.js +0 -14
- package/dist/number/smartDecimal.js.map +0 -1
- package/dist/retry.cjs.map +0 -1
- package/dist/retry.js +0 -31
- package/dist/retry.js.map +0 -1
- package/dist/search/reRankSearchResults.cjs.map +0 -1
- package/dist/search/reRankSearchResults.d.ts +0 -11
- package/dist/search/reRankSearchResults.js +0 -22
- package/dist/search/reRankSearchResults.js.map +0 -1
- package/dist/search/sublimeSearch.cjs.map +0 -1
- package/dist/search/sublimeSearch.d.ts +0 -13
- package/dist/search/sublimeSearch.js +0 -198
- package/dist/search/sublimeSearch.js.map +0 -1
- package/dist/sort/sortByProperty.cjs.map +0 -1
- package/dist/sort/sortByProperty.d.ts +0 -3
- package/dist/sort/sortByProperty.js +0 -12
- package/dist/sort/sortByProperty.js.map +0 -1
- package/dist/string/truncate.cjs.map +0 -1
- package/dist/string/truncate.js +0 -31
- package/dist/string/truncate.js.map +0 -1
package/dist/assert.cjs
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
function assert(condition, message) {
|
|
3
|
-
if (!condition) {
|
|
4
|
-
throw new Error(_nullishCoalesce(message, () => ( "Assertion failed")));
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
const require_assert = require('./assert2.cjs');
|
|
7
2
|
|
|
8
|
-
|
|
9
|
-
exports.assert = assert;
|
|
10
|
-
//# sourceMappingURL=assert.cjs.map
|
|
3
|
+
exports.assert = require_assert.assert;
|
package/dist/assert.d.cts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { assert };
|
|
1
|
+
import { t as assert } from "./assert2.cjs";
|
|
2
|
+
export { assert };
|
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"}
|
package/dist/assert2.mjs
ADDED
|
@@ -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,40 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
function createEventBus() {
|
|
3
|
-
const handlers = /* @__PURE__ */ new Map();
|
|
4
|
-
return {
|
|
5
|
-
on(eventName, fn) {
|
|
6
|
-
let eventFns = handlers.get(eventName);
|
|
7
|
-
if (!eventFns) {
|
|
8
|
-
eventFns = [fn];
|
|
9
|
-
} else {
|
|
10
|
-
eventFns.push(fn);
|
|
11
|
-
}
|
|
12
|
-
handlers.set(eventName, eventFns);
|
|
13
|
-
},
|
|
14
|
-
once(eventName, fn) {
|
|
15
|
-
const handler = (payload) => {
|
|
16
|
-
this.off(eventName, handler);
|
|
17
|
-
fn(payload);
|
|
18
|
-
};
|
|
19
|
-
this.on(eventName, handler);
|
|
20
|
-
},
|
|
21
|
-
off(eventName, fn) {
|
|
22
|
-
const eventFns = handlers.get(eventName);
|
|
23
|
-
if (eventFns) {
|
|
24
|
-
eventFns.splice(eventFns.indexOf(fn) >>> 0, 1);
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
emit(eventName, event) {
|
|
28
|
-
const eventFns = handlers.get(eventName);
|
|
29
|
-
if (eventFns) {
|
|
30
|
-
eventFns.slice().forEach((handler) => {
|
|
31
|
-
handler(event);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
1
|
+
const require_event_bus = require('./event-bus2.cjs');
|
|
37
2
|
|
|
38
|
-
|
|
39
|
-
exports.createEventBus = createEventBus;
|
|
40
|
-
//# 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
|
-
[E in keyof ListenerMap]: unknown;
|
|
4
|
-
};
|
|
5
|
-
type Listener<Payload> = (payload: Payload) => void;
|
|
6
|
-
interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {
|
|
7
|
-
on<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
8
|
-
once<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
9
|
-
off<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
10
|
-
emit<EventName extends keyof ListenerMap & string>(eventName: EventName, event?: ListenerMap[EventName]): void;
|
|
11
|
-
}
|
|
12
|
-
declare function createEventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>>(): EventBus<ListenerMap>;
|
|
13
|
-
|
|
14
|
-
export { type CallbackFn, type EventBus, createEventBus };
|
|
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"}
|
|
@@ -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.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,43 @@
|
|
|
1
|
+
//#region src/event-bus.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates an event bus with the given listener map.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const eventBus = createEventBus<{
|
|
8
|
+
* 'user-logged-in': { username: string };
|
|
9
|
+
* 'user-logged-out': never;
|
|
10
|
+
* }>();
|
|
11
|
+
*/
|
|
12
|
+
function createEventBus() {
|
|
13
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
14
|
+
return {
|
|
15
|
+
on(eventName, fn) {
|
|
16
|
+
let eventFns = handlers.get(eventName);
|
|
17
|
+
if (!eventFns) eventFns = [fn];
|
|
18
|
+
else eventFns.push(fn);
|
|
19
|
+
handlers.set(eventName, eventFns);
|
|
20
|
+
},
|
|
21
|
+
once(eventName, fn) {
|
|
22
|
+
const handler = (payload) => {
|
|
23
|
+
this.off(eventName, handler);
|
|
24
|
+
fn(payload);
|
|
25
|
+
};
|
|
26
|
+
this.on(eventName, handler);
|
|
27
|
+
},
|
|
28
|
+
off(eventName, fn) {
|
|
29
|
+
const eventFns = handlers.get(eventName);
|
|
30
|
+
if (eventFns) eventFns.splice(eventFns.indexOf(fn) >>> 0, 1);
|
|
31
|
+
},
|
|
32
|
+
emit(eventName, event) {
|
|
33
|
+
const eventFns = handlers.get(eventName);
|
|
34
|
+
if (eventFns) eventFns.slice().forEach((handler) => {
|
|
35
|
+
handler(event);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { createEventBus as t };
|
|
43
|
+
//# sourceMappingURL=event-bus2.mjs.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,30 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
function createEventQueue(processEvent) {
|
|
3
|
-
const queue = [];
|
|
4
|
-
let processing = false;
|
|
5
|
-
async function processNext() {
|
|
6
|
-
if (processing || queue.length === 0) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
processing = true;
|
|
10
|
-
const currentEvent = queue.shift();
|
|
11
|
-
if (currentEvent !== void 0) {
|
|
12
|
-
try {
|
|
13
|
-
await processEvent(currentEvent);
|
|
14
|
-
} catch (error) {
|
|
15
|
-
console.error("Error processing event:", error);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
processing = false;
|
|
19
|
-
await processNext();
|
|
20
|
-
}
|
|
21
|
-
function enqueue(event) {
|
|
22
|
-
queue.push(event);
|
|
23
|
-
void processNext();
|
|
24
|
-
}
|
|
25
|
-
return { enqueue };
|
|
26
|
-
}
|
|
1
|
+
const require_event_queue = require('./event-queue2.cjs');
|
|
27
2
|
|
|
28
|
-
|
|
29
|
-
exports.createEventQueue = createEventQueue;
|
|
30
|
-
//# sourceMappingURL=event-queue.cjs.map
|
|
3
|
+
exports.createEventQueue = require_event_queue.createEventQueue;
|
package/dist/event-queue.d.cts
CHANGED
|
@@ -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"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/event-queue.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create an event queue that processes events sequentially.
|
|
4
|
+
*
|
|
5
|
+
* @param processEvent - Async function that processes a single event.
|
|
6
|
+
* @returns A function that enqueues events for processing.
|
|
7
|
+
*/
|
|
8
|
+
function createEventQueue(processEvent) {
|
|
9
|
+
const queue = [];
|
|
10
|
+
let processing = false;
|
|
11
|
+
/**
|
|
12
|
+
* Process the next event in the queue (if not already processing).
|
|
13
|
+
*/
|
|
14
|
+
async function processNext() {
|
|
15
|
+
if (processing || queue.length === 0) return;
|
|
16
|
+
processing = true;
|
|
17
|
+
const currentEvent = queue.shift();
|
|
18
|
+
if (currentEvent !== void 0) try {
|
|
19
|
+
await processEvent(currentEvent);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error("Error processing event:", error);
|
|
22
|
+
}
|
|
23
|
+
processing = false;
|
|
24
|
+
await processNext();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Enqueue an event and trigger processing.
|
|
28
|
+
*
|
|
29
|
+
* @param event - The event to enqueue.
|
|
30
|
+
*/
|
|
31
|
+
function enqueue(event) {
|
|
32
|
+
queue.push(event);
|
|
33
|
+
processNext();
|
|
34
|
+
}
|
|
35
|
+
return { enqueue };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { createEventQueue as t };
|
|
40
|
+
//# sourceMappingURL=event-queue2.mjs.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,14 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
var smartDecimal = (value, decimals = 2) => {
|
|
3
|
-
if (Number.isInteger(value)) {
|
|
4
|
-
return value;
|
|
5
|
-
}
|
|
6
|
-
if (value.toString().split(".")[1].length <= decimals) {
|
|
7
|
-
return value;
|
|
8
|
-
}
|
|
9
|
-
return Number(value.toFixed(decimals));
|
|
10
|
-
};
|
|
1
|
+
const require_smartDecimal = require('../smartDecimal.cjs');
|
|
11
2
|
|
|
12
|
-
|
|
13
|
-
exports.smartDecimal = smartDecimal;
|
|
14
|
-
//# sourceMappingURL=smartDecimal.cjs.map
|
|
3
|
+
exports.smartDecimal = require_smartDecimal.smartDecimal;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { smartDecimal };
|
|
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.cts.map
|
|
@@ -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
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/search/reRankSearchResults.ts
|
|
2
|
+
function reRankSearchResults(searchResults, additionalFactors) {
|
|
3
|
+
return searchResults.map(({ score, item }) => {
|
|
4
|
+
return {
|
|
5
|
+
score: score + Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {
|
|
6
|
+
const factorScore = factorScores[item.key];
|
|
7
|
+
if (factorScore) return acc + factorScore;
|
|
8
|
+
return acc;
|
|
9
|
+
}, 0),
|
|
10
|
+
item
|
|
11
|
+
};
|
|
12
|
+
}).sort((a, b) => {
|
|
13
|
+
return b.score - a.score;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { reRankSearchResults as t };
|
|
19
|
+
//# sourceMappingURL=reRankSearchResults.mjs.map
|