@n8n/utils 1.17.0 → 1.18.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 +7 -5
- package/dist/assert.cjs.map +1 -1
- package/dist/assert.d.cts +3 -1
- package/dist/assert.d.ts +3 -1
- package/dist/assert.js +8 -7
- package/dist/assert.js.map +1 -1
- package/dist/event-bus.cjs +39 -35
- package/dist/event-bus.cjs.map +1 -1
- package/dist/event-bus.d.cts +9 -9
- package/dist/event-bus.d.ts +9 -9
- package/dist/event-bus.js +40 -37
- package/dist/event-bus.js.map +1 -1
- package/dist/event-queue.cjs +36 -25
- package/dist/event-queue.cjs.map +1 -1
- package/dist/event-queue.d.cts +4 -2
- package/dist/event-queue.d.ts +4 -2
- package/dist/event-queue.js +37 -27
- package/dist/event-queue.js.map +1 -1
- package/dist/number/smartDecimal.cjs +7 -10
- package/dist/number/smartDecimal.cjs.map +1 -1
- package/dist/number/smartDecimal.d.cts +3 -1
- package/dist/number/smartDecimal.d.ts +3 -1
- package/dist/number/smartDecimal.js +8 -12
- package/dist/number/smartDecimal.js.map +1 -1
- package/dist/retry.cjs +35 -26
- package/dist/retry.cjs.map +1 -1
- package/dist/retry.d.cts +3 -1
- package/dist/retry.d.ts +3 -1
- package/dist/retry.js +36 -28
- package/dist/retry.js.map +1 -1
- package/dist/search/reRankSearchResults.cjs +15 -17
- package/dist/search/reRankSearchResults.cjs.map +1 -1
- package/dist/search/reRankSearchResults.d.cts +8 -6
- package/dist/search/reRankSearchResults.d.ts +8 -6
- package/dist/search/reRankSearchResults.js +16 -19
- package/dist/search/reRankSearchResults.js.map +1 -1
- package/dist/search/sublimeSearch.cjs +161 -186
- package/dist/search/sublimeSearch.cjs.map +1 -1
- package/dist/search/sublimeSearch.d.cts +9 -7
- package/dist/search/sublimeSearch.d.ts +9 -7
- package/dist/search/sublimeSearch.js +160 -187
- package/dist/search/sublimeSearch.js.map +1 -1
- package/dist/sort/sortByProperty.cjs +9 -8
- package/dist/sort/sortByProperty.cjs.map +1 -1
- package/dist/sort/sortByProperty.d.cts +3 -1
- package/dist/sort/sortByProperty.d.ts +3 -1
- package/dist/sort/sortByProperty.js +10 -10
- package/dist/sort/sortByProperty.js.map +1 -1
- package/dist/string/truncate.cjs +27 -27
- package/dist/string/truncate.cjs.map +1 -1
- package/dist/string/truncate.d.cts +3 -1
- package/dist/string/truncate.d.ts +3 -1
- package/dist/string/truncate.js +26 -28
- package/dist/string/truncate.js.map +1 -1
- package/package.json +8 -8
package/dist/retry.cjs
CHANGED
|
@@ -1,31 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/retry.ts
|
|
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
|
+
*/
|
|
2
15
|
async function retry(fn, interval = 1e3, maxRetries = 3, backoff = "linear") {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
await new Promise((resolve) => setTimeout(resolve, computedInterval));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
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;
|
|
27
36
|
}
|
|
28
37
|
|
|
29
|
-
|
|
38
|
+
//#endregion
|
|
30
39
|
exports.retry = retry;
|
|
31
40
|
//# sourceMappingURL=retry.cjs.map
|
package/dist/retry.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"retry.cjs","names":[],"sources":["../src/retry.ts"],"sourcesContent":["type RetryFn = () => boolean | Promise<boolean>;\n\n/**\n * A utility that retries a function every `interval` milliseconds\n * until the function returns true or the maximum number of retries is reached.\n *\n * @param fn - A function that returns a boolean or a Promise resolving to a boolean.\n * @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.\n * @param maxRetries - The maximum number of retry attempts. Defaults to 3.\n * @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.\n * @returns {Promise<boolean>} - A promise that resolves to:\n * - true: If the function returns true before reaching maxRetries.\n * - false: If the function never returns true or if an error occurs.\n */\nexport async function retry(\n\tfn: RetryFn,\n\tinterval: number = 1000,\n\tmaxRetries: number = 3,\n\tbackoff: 'exponential' | 'linear' | null = 'linear',\n): Promise<boolean> {\n\tlet attempt = 0;\n\n\twhile (attempt < maxRetries) {\n\t\tattempt++;\n\t\ttry {\n\t\t\tconst result = await fn();\n\t\t\tif (result) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error('Error during retry:', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\t// Wait for the specified interval before the next attempt, if any attempts remain.\n\t\tif (attempt < maxRetries) {\n\t\t\tlet computedInterval = interval;\n\n\t\t\tif (backoff === 'linear') {\n\t\t\t\tcomputedInterval = interval * attempt;\n\t\t\t} else if (backoff === 'exponential') {\n\t\t\t\tcomputedInterval = Math.pow(2, attempt - 1) * interval;\n\t\t\t\tcomputedInterval = Math.min(computedInterval, 30000); // Cap the maximum interval to 30 seconds\n\t\t\t}\n\n\t\t\tawait new Promise<void>((resolve) => setTimeout(resolve, computedInterval));\n\t\t}\n\t}\n\n\treturn false;\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,eAAsB,MACrB,IACA,WAAmB,KACnB,aAAqB,GACrB,UAA2C,UACxB;CACnB,IAAI,UAAU;AAEd,QAAO,UAAU,YAAY;AAC5B;AACA,MAAI;AAEH,OADe,MAAM,IAAI,CAExB,QAAO;WAEA,OAAO;AACf,WAAQ,MAAM,uBAAuB,MAAM;AAC3C,SAAM;;AAIP,MAAI,UAAU,YAAY;GACzB,IAAI,mBAAmB;AAEvB,OAAI,YAAY,SACf,oBAAmB,WAAW;YACpB,YAAY,eAAe;AACrC,uBAAmB,KAAK,IAAI,GAAG,UAAU,EAAE,GAAG;AAC9C,uBAAmB,KAAK,IAAI,kBAAkB,IAAM;;AAGrD,SAAM,IAAI,SAAe,YAAY,WAAW,SAAS,iBAAiB,CAAC;;;AAI7E,QAAO"}
|
package/dist/retry.d.cts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
//#region src/retry.d.ts
|
|
1
2
|
type RetryFn = () => boolean | Promise<boolean>;
|
|
2
3
|
declare function retry(fn: RetryFn, interval?: number, maxRetries?: number, backoff?: 'exponential' | 'linear' | null): Promise<boolean>;
|
|
3
|
-
|
|
4
|
+
//#endregion
|
|
4
5
|
export { retry };
|
|
6
|
+
//# sourceMappingURL=retry.d.cts.map
|
package/dist/retry.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
//#region src/retry.d.ts
|
|
1
2
|
type RetryFn = () => boolean | Promise<boolean>;
|
|
2
3
|
declare function retry(fn: RetryFn, interval?: number, maxRetries?: number, backoff?: 'exponential' | 'linear' | null): Promise<boolean>;
|
|
3
|
-
|
|
4
|
+
//#endregion
|
|
4
5
|
export { retry };
|
|
6
|
+
//# sourceMappingURL=retry.d.ts.map
|
package/dist/retry.js
CHANGED
|
@@ -1,31 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/retry.ts
|
|
2
|
+
/**
|
|
3
|
+
* A utility that retries a function every `interval` milliseconds
|
|
4
|
+
* until the function returns true or the maximum number of retries is reached.
|
|
5
|
+
*
|
|
6
|
+
* @param fn - A function that returns a boolean or a Promise resolving to a boolean.
|
|
7
|
+
* @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.
|
|
8
|
+
* @param maxRetries - The maximum number of retry attempts. Defaults to 3.
|
|
9
|
+
* @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.
|
|
10
|
+
* @returns {Promise<boolean>} - A promise that resolves to:
|
|
11
|
+
* - true: If the function returns true before reaching maxRetries.
|
|
12
|
+
* - false: If the function never returns true or if an error occurs.
|
|
13
|
+
*/
|
|
2
14
|
async function retry(fn, interval = 1e3, maxRetries = 3, backoff = "linear") {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
await new Promise((resolve) => setTimeout(resolve, computedInterval));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
15
|
+
let attempt = 0;
|
|
16
|
+
while (attempt < maxRetries) {
|
|
17
|
+
attempt++;
|
|
18
|
+
try {
|
|
19
|
+
if (await fn()) return true;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error("Error during retry:", error);
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
if (attempt < maxRetries) {
|
|
25
|
+
let computedInterval = interval;
|
|
26
|
+
if (backoff === "linear") computedInterval = interval * attempt;
|
|
27
|
+
else if (backoff === "exponential") {
|
|
28
|
+
computedInterval = Math.pow(2, attempt - 1) * interval;
|
|
29
|
+
computedInterval = Math.min(computedInterval, 3e4);
|
|
30
|
+
}
|
|
31
|
+
await new Promise((resolve) => setTimeout(resolve, computedInterval));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
27
35
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { retry };
|
|
31
39
|
//# sourceMappingURL=retry.js.map
|
package/dist/retry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/retry.ts"],"sourcesContent":["type RetryFn = () => boolean | Promise<boolean>;\n\n/**\n * A utility that retries a function every `interval` milliseconds\n * until the function returns true or the maximum number of retries is reached.\n *\n * @param fn - A function that returns a boolean or a Promise resolving to a boolean.\n * @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.\n * @param maxRetries - The maximum number of retry attempts. Defaults to 3.\n * @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.\n * @returns {Promise<boolean>} - A promise that resolves to:\n * - true: If the function returns true before reaching maxRetries.\n * - false: If the function never returns true or if an error occurs.\n */\nexport async function retry(\n\tfn: RetryFn,\n\tinterval: number = 1000,\n\tmaxRetries: number = 3,\n\tbackoff: 'exponential' | 'linear' | null = 'linear',\n): Promise<boolean> {\n\tlet attempt = 0;\n\n\twhile (attempt < maxRetries) {\n\t\tattempt++;\n\t\ttry {\n\t\t\tconst result = await fn();\n\t\t\tif (result) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error('Error during retry:', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\t// Wait for the specified interval before the next attempt, if any attempts remain.\n\t\tif (attempt < maxRetries) {\n\t\t\tlet computedInterval = interval;\n\n\t\t\tif (backoff === 'linear') {\n\t\t\t\tcomputedInterval = interval * attempt;\n\t\t\t} else if (backoff === 'exponential') {\n\t\t\t\tcomputedInterval = Math.pow(2, attempt - 1) * interval;\n\t\t\t\tcomputedInterval = Math.min(computedInterval, 30000); // Cap the maximum interval to 30 seconds\n\t\t\t}\n\n\t\t\tawait new Promise<void>((resolve) => setTimeout(resolve, computedInterval));\n\t\t}\n\t}\n\n\treturn false;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"retry.js","names":[],"sources":["../src/retry.ts"],"sourcesContent":["type RetryFn = () => boolean | Promise<boolean>;\n\n/**\n * A utility that retries a function every `interval` milliseconds\n * until the function returns true or the maximum number of retries is reached.\n *\n * @param fn - A function that returns a boolean or a Promise resolving to a boolean.\n * @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.\n * @param maxRetries - The maximum number of retry attempts. Defaults to 3.\n * @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.\n * @returns {Promise<boolean>} - A promise that resolves to:\n * - true: If the function returns true before reaching maxRetries.\n * - false: If the function never returns true or if an error occurs.\n */\nexport async function retry(\n\tfn: RetryFn,\n\tinterval: number = 1000,\n\tmaxRetries: number = 3,\n\tbackoff: 'exponential' | 'linear' | null = 'linear',\n): Promise<boolean> {\n\tlet attempt = 0;\n\n\twhile (attempt < maxRetries) {\n\t\tattempt++;\n\t\ttry {\n\t\t\tconst result = await fn();\n\t\t\tif (result) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error('Error during retry:', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\t// Wait for the specified interval before the next attempt, if any attempts remain.\n\t\tif (attempt < maxRetries) {\n\t\t\tlet computedInterval = interval;\n\n\t\t\tif (backoff === 'linear') {\n\t\t\t\tcomputedInterval = interval * attempt;\n\t\t\t} else if (backoff === 'exponential') {\n\t\t\t\tcomputedInterval = Math.pow(2, attempt - 1) * interval;\n\t\t\t\tcomputedInterval = Math.min(computedInterval, 30000); // Cap the maximum interval to 30 seconds\n\t\t\t}\n\n\t\t\tawait new Promise<void>((resolve) => setTimeout(resolve, computedInterval));\n\t\t}\n\t}\n\n\treturn false;\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,eAAsB,MACrB,IACA,WAAmB,KACnB,aAAqB,GACrB,UAA2C,UACxB;CACnB,IAAI,UAAU;AAEd,QAAO,UAAU,YAAY;AAC5B;AACA,MAAI;AAEH,OADe,MAAM,IAAI,CAExB,QAAO;WAEA,OAAO;AACf,WAAQ,MAAM,uBAAuB,MAAM;AAC3C,SAAM;;AAIP,MAAI,UAAU,YAAY;GACzB,IAAI,mBAAmB;AAEvB,OAAI,YAAY,SACf,oBAAmB,WAAW;YACpB,YAAY,eAAe;AACrC,uBAAmB,KAAK,IAAI,GAAG,UAAU,EAAE,GAAG;AAC9C,uBAAmB,KAAK,IAAI,kBAAkB,IAAM;;AAGrD,SAAM,IAAI,SAAe,YAAY,WAAW,SAAS,iBAAiB,CAAC;;;AAI7E,QAAO"}
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/search/reRankSearchResults.ts
|
|
2
3
|
function reRankSearchResults(searchResults, additionalFactors) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}).sort((a, b) => {
|
|
16
|
-
return b.score - a.score;
|
|
17
|
-
});
|
|
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
|
+
});
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
//#endregion
|
|
21
19
|
exports.reRankSearchResults = reRankSearchResults;
|
|
22
20
|
//# sourceMappingURL=reRankSearchResults.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
//#region src/search/reRankSearchResults.d.ts
|
|
1
2
|
declare function reRankSearchResults<T extends {
|
|
2
|
-
|
|
3
|
+
key: string;
|
|
3
4
|
}>(searchResults: Array<{
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
score: number;
|
|
6
|
+
item: T;
|
|
6
7
|
}>, additionalFactors: Record<string, Record<string, number>>): Array<{
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
score: number;
|
|
9
|
+
item: T;
|
|
9
10
|
}>;
|
|
10
|
-
|
|
11
|
+
//#endregion
|
|
11
12
|
export { reRankSearchResults };
|
|
13
|
+
//# sourceMappingURL=reRankSearchResults.d.cts.map
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
//#region src/search/reRankSearchResults.d.ts
|
|
1
2
|
declare function reRankSearchResults<T extends {
|
|
2
|
-
|
|
3
|
+
key: string;
|
|
3
4
|
}>(searchResults: Array<{
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
score: number;
|
|
6
|
+
item: T;
|
|
6
7
|
}>, additionalFactors: Record<string, Record<string, number>>): Array<{
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
score: number;
|
|
9
|
+
item: T;
|
|
9
10
|
}>;
|
|
10
|
-
|
|
11
|
+
//#endregion
|
|
11
12
|
export { reRankSearchResults };
|
|
13
|
+
//# sourceMappingURL=reRankSearchResults.d.ts.map
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/search/reRankSearchResults.ts
|
|
2
2
|
function reRankSearchResults(searchResults, additionalFactors) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}).sort((a, b) => {
|
|
16
|
-
return b.score - a.score;
|
|
17
|
-
});
|
|
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
|
+
});
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { reRankSearchResults };
|
|
22
19
|
//# sourceMappingURL=reRankSearchResults.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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":";
|
|
1
|
+
{"version":3,"file":"reRankSearchResults.js","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"}
|