@verdaccio/search 7.0.0-next.0 → 7.0.0-next.2
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/CHANGELOG.md +16 -0
- package/build/dist.js +446 -183
- package/build/indexer.d.ts +5 -3
- package/package.json +5 -6
- package/src/indexer.ts +26 -11
- package/test/index.spec.ts +47 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @verdaccio/proxy
|
|
2
2
|
|
|
3
|
+
## 7.0.0-next.2
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- e7ebccb61: update major dependencies, remove old nodejs support
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- daceb6d87: restore legacy support
|
|
12
|
+
|
|
13
|
+
## 7.0.0-next.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 35cc57b79: fix: keyword undefined errors
|
|
18
|
+
|
|
3
19
|
## 7.0.0-next.0
|
|
4
20
|
|
|
5
21
|
### Major Changes
|
package/build/dist.js
CHANGED
|
@@ -786,7 +786,7 @@ __export(src_exports, {
|
|
|
786
786
|
SearchMemoryIndexer: () => indexer_default
|
|
787
787
|
});
|
|
788
788
|
|
|
789
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
789
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/tokenizer/languages.js
|
|
790
790
|
var STEMMERS = {
|
|
791
791
|
arabic: "ar",
|
|
792
792
|
armenian: "am",
|
|
@@ -849,12 +849,22 @@ var SPLITTERS = {
|
|
|
849
849
|
};
|
|
850
850
|
var SUPPORTED_LANGUAGES = Object.keys(STEMMERS);
|
|
851
851
|
|
|
852
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
852
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/utils.js
|
|
853
853
|
var baseId = Date.now().toString().slice(5);
|
|
854
854
|
var lastId = 0;
|
|
855
855
|
var nano = BigInt(1e3);
|
|
856
856
|
var milli = BigInt(1e6);
|
|
857
857
|
var second = BigInt(1e9);
|
|
858
|
+
var MAX_ARGUMENT_FOR_STACK = 65535;
|
|
859
|
+
function safeArrayPush(arr, newArr) {
|
|
860
|
+
if (newArr.length < MAX_ARGUMENT_FOR_STACK) {
|
|
861
|
+
Array.prototype.push.apply(arr, newArr);
|
|
862
|
+
} else {
|
|
863
|
+
for (let i = 0; i < newArr.length; i += MAX_ARGUMENT_FOR_STACK) {
|
|
864
|
+
Array.prototype.push.apply(arr, newArr.slice(i, i + MAX_ARGUMENT_FOR_STACK));
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
858
868
|
function sprintf(template, ...args) {
|
|
859
869
|
return template.replace(/%(?:(?<position>\d+)\$)?(?<width>-?\d*\.?\d*)(?<type>[dfs])/g, function(...replaceArgs) {
|
|
860
870
|
const groups = replaceArgs[replaceArgs.length - 1];
|
|
@@ -983,7 +993,7 @@ async function getNested(obj, path) {
|
|
|
983
993
|
return props[path];
|
|
984
994
|
}
|
|
985
995
|
|
|
986
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
996
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/errors.js
|
|
987
997
|
var allLanguages = SUPPORTED_LANGUAGES.join("\n - ");
|
|
988
998
|
var errors = {
|
|
989
999
|
NO_LANGUAGE_WITH_CUSTOM_TOKENIZER: "Do not pass the language option to create when using a custom tokenizer.",
|
|
@@ -1012,7 +1022,12 @@ Supported languages are:
|
|
|
1012
1022
|
SORT_DISABLED: `Sort is disabled. Please read the documentation at https://docs.oramasearch for more information.`,
|
|
1013
1023
|
UNKNOWN_GROUP_BY_PROPERTY: `Unknown groupBy property "%s".`,
|
|
1014
1024
|
INVALID_GROUP_BY_PROPERTY: `Invalid groupBy property "%s". Allowed types: "%s", but given "%s".`,
|
|
1015
|
-
UNKNOWN_FILTER_PROPERTY: `Unknown filter property "%s"
|
|
1025
|
+
UNKNOWN_FILTER_PROPERTY: `Unknown filter property "%s".`,
|
|
1026
|
+
INVALID_VECTOR_SIZE: `Vector size must be a number greater than 0. Got "%s" instead.`,
|
|
1027
|
+
INVALID_VECTOR_VALUE: `Vector value must be a number greater than 0. Got "%s" instead.`,
|
|
1028
|
+
INVALID_INPUT_VECTOR: `Property "%s" was declared as a %s-dimentional vector, but got a %s-dimentional vector instead.
|
|
1029
|
+
Input vectors must be of the size declared in the schema, as calculating similarity between vectors of different sizes can lead to unexpected results.`,
|
|
1030
|
+
WRONG_SEARCH_PROPERTY_TYPE: `Property "%s" is not searchable. Only "string" properties are searchable.`
|
|
1016
1031
|
};
|
|
1017
1032
|
function createError(code, ...args) {
|
|
1018
1033
|
var _a2;
|
|
@@ -1024,7 +1039,7 @@ function createError(code, ...args) {
|
|
|
1024
1039
|
return error;
|
|
1025
1040
|
}
|
|
1026
1041
|
|
|
1027
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
1042
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/defaults.js
|
|
1028
1043
|
async function formatElapsedTime(n) {
|
|
1029
1044
|
return {
|
|
1030
1045
|
raw: Number(n),
|
|
@@ -1047,7 +1062,17 @@ async function validateSchema(doc, schema) {
|
|
|
1047
1062
|
if (typeOfValue === "undefined") {
|
|
1048
1063
|
continue;
|
|
1049
1064
|
}
|
|
1065
|
+
if (type === "enum" && (typeOfValue === "string" || typeOfValue === "number")) {
|
|
1066
|
+
continue;
|
|
1067
|
+
}
|
|
1050
1068
|
const typeOfType = typeof type;
|
|
1069
|
+
if (isVectorType(type)) {
|
|
1070
|
+
const vectorSize = getVectorSize(type);
|
|
1071
|
+
if (!Array.isArray(value) || value.length !== vectorSize) {
|
|
1072
|
+
throw createError("INVALID_INPUT_VECTOR", prop, vectorSize, value.length);
|
|
1073
|
+
}
|
|
1074
|
+
continue;
|
|
1075
|
+
}
|
|
1051
1076
|
if (typeOfType === "string" && isArrayType(type)) {
|
|
1052
1077
|
if (!Array.isArray(value)) {
|
|
1053
1078
|
return prop;
|
|
@@ -1081,6 +1106,7 @@ var IS_ARRAY_TYPE = {
|
|
|
1081
1106
|
string: false,
|
|
1082
1107
|
number: false,
|
|
1083
1108
|
boolean: false,
|
|
1109
|
+
enum: false,
|
|
1084
1110
|
"string[]": true,
|
|
1085
1111
|
"number[]": true,
|
|
1086
1112
|
"boolean[]": true
|
|
@@ -1090,14 +1116,28 @@ var INNER_TYPE = {
|
|
|
1090
1116
|
"number[]": "number",
|
|
1091
1117
|
"boolean[]": "boolean"
|
|
1092
1118
|
};
|
|
1119
|
+
function isVectorType(type) {
|
|
1120
|
+
return /^vector\[\d+\]$/.test(type);
|
|
1121
|
+
}
|
|
1093
1122
|
function isArrayType(type) {
|
|
1094
1123
|
return IS_ARRAY_TYPE[type];
|
|
1095
1124
|
}
|
|
1096
1125
|
function getInnerType(type) {
|
|
1097
1126
|
return INNER_TYPE[type];
|
|
1098
1127
|
}
|
|
1128
|
+
function getVectorSize(type) {
|
|
1129
|
+
const size = Number(type.slice(7, -1));
|
|
1130
|
+
switch (true) {
|
|
1131
|
+
case isNaN(size):
|
|
1132
|
+
throw createError("INVALID_VECTOR_VALUE", type);
|
|
1133
|
+
case size <= 0:
|
|
1134
|
+
throw createError("INVALID_VECTOR_SIZE", type);
|
|
1135
|
+
default:
|
|
1136
|
+
return size;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1099
1139
|
|
|
1100
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
1140
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/internal-document-id-store.js
|
|
1101
1141
|
function createInternalDocumentIDStore() {
|
|
1102
1142
|
return {
|
|
1103
1143
|
idToInternalId: /* @__PURE__ */ new Map(),
|
|
@@ -1143,7 +1183,7 @@ function getDocumentIdFromInternalId(store2, internalId) {
|
|
|
1143
1183
|
return store2.internalIdToId[internalId - 1];
|
|
1144
1184
|
}
|
|
1145
1185
|
|
|
1146
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
1186
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/documents-store.js
|
|
1147
1187
|
async function create(_, sharedInternalDocumentStore) {
|
|
1148
1188
|
return {
|
|
1149
1189
|
sharedInternalDocumentStore,
|
|
@@ -1217,7 +1257,7 @@ async function createDocumentsStore() {
|
|
|
1217
1257
|
};
|
|
1218
1258
|
}
|
|
1219
1259
|
|
|
1220
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
1260
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/hooks.js
|
|
1221
1261
|
var OBJECT_COMPONENTS = [
|
|
1222
1262
|
"tokenizer",
|
|
1223
1263
|
"index",
|
|
@@ -1258,7 +1298,7 @@ async function runAfterSearch(hooks, db, params, language, results) {
|
|
|
1258
1298
|
}
|
|
1259
1299
|
}
|
|
1260
1300
|
|
|
1261
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
1301
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/trees/avl.js
|
|
1262
1302
|
var BALANCE_STATE = {
|
|
1263
1303
|
UNBALANCED_RIGHT: -2,
|
|
1264
1304
|
SLIGHTLY_UNBALANCED_RIGHT: -1,
|
|
@@ -1298,7 +1338,7 @@ function rangeSearch(node, min, max) {
|
|
|
1298
1338
|
traverse(node2.left);
|
|
1299
1339
|
}
|
|
1300
1340
|
if (node2.key >= min && node2.key <= max) {
|
|
1301
|
-
result
|
|
1341
|
+
safeArrayPush(result, node2.value);
|
|
1302
1342
|
}
|
|
1303
1343
|
if (node2.key < max) {
|
|
1304
1344
|
traverse(node2.right);
|
|
@@ -1317,10 +1357,10 @@ function greaterThan(node, key, inclusive = false) {
|
|
|
1317
1357
|
return;
|
|
1318
1358
|
}
|
|
1319
1359
|
if (inclusive && node2.key >= key) {
|
|
1320
|
-
result
|
|
1360
|
+
safeArrayPush(result, node2.value);
|
|
1321
1361
|
}
|
|
1322
1362
|
if (!inclusive && node2.key > key) {
|
|
1323
|
-
result
|
|
1363
|
+
safeArrayPush(result, node2.value);
|
|
1324
1364
|
}
|
|
1325
1365
|
traverse(node2.left);
|
|
1326
1366
|
traverse(node2.right);
|
|
@@ -1338,10 +1378,10 @@ function lessThan(node, key, inclusive = false) {
|
|
|
1338
1378
|
return;
|
|
1339
1379
|
}
|
|
1340
1380
|
if (inclusive && node2.key <= key) {
|
|
1341
|
-
result
|
|
1381
|
+
safeArrayPush(result, node2.value);
|
|
1342
1382
|
}
|
|
1343
1383
|
if (!inclusive && node2.key < key) {
|
|
1344
|
-
result
|
|
1384
|
+
safeArrayPush(result, node2.value);
|
|
1345
1385
|
}
|
|
1346
1386
|
traverse(node2.left);
|
|
1347
1387
|
traverse(node2.right);
|
|
@@ -1491,6 +1531,9 @@ function remove2(root, key) {
|
|
|
1491
1531
|
}
|
|
1492
1532
|
function removeDocument(root, id, key) {
|
|
1493
1533
|
const node = getNodeByKey(root, key);
|
|
1534
|
+
if (!node) {
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1494
1537
|
if (node.value.length === 1) {
|
|
1495
1538
|
remove2(root, key);
|
|
1496
1539
|
return;
|
|
@@ -1498,7 +1541,7 @@ function removeDocument(root, id, key) {
|
|
|
1498
1541
|
node.value.splice(node.value.indexOf(id), 1);
|
|
1499
1542
|
}
|
|
1500
1543
|
|
|
1501
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
1544
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/levenshtein.js
|
|
1502
1545
|
function _boundedLevenshtein(a, b, tolerance) {
|
|
1503
1546
|
if (a === b) {
|
|
1504
1547
|
return 0;
|
|
@@ -1587,7 +1630,7 @@ function syncBoundedLevenshtein(a, b, tolerance) {
|
|
|
1587
1630
|
};
|
|
1588
1631
|
}
|
|
1589
1632
|
|
|
1590
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
1633
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/trees/radix.js
|
|
1591
1634
|
var Node = class {
|
|
1592
1635
|
constructor(key, subWord, end) {
|
|
1593
1636
|
this.key = key;
|
|
@@ -1765,7 +1808,73 @@ function removeDocumentByWord(root, term, docID, exact = true) {
|
|
|
1765
1808
|
return true;
|
|
1766
1809
|
}
|
|
1767
1810
|
|
|
1768
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
1811
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/trees/flat.js
|
|
1812
|
+
function create4() {
|
|
1813
|
+
return {
|
|
1814
|
+
numberToDocumentId: /* @__PURE__ */ new Map()
|
|
1815
|
+
};
|
|
1816
|
+
}
|
|
1817
|
+
function insert3(root, key, value) {
|
|
1818
|
+
if (root.numberToDocumentId.has(key)) {
|
|
1819
|
+
root.numberToDocumentId.get(key).push(value);
|
|
1820
|
+
return root;
|
|
1821
|
+
}
|
|
1822
|
+
root.numberToDocumentId.set(key, [
|
|
1823
|
+
value
|
|
1824
|
+
]);
|
|
1825
|
+
return root;
|
|
1826
|
+
}
|
|
1827
|
+
function removeDocument3(root, id, key) {
|
|
1828
|
+
var _a2;
|
|
1829
|
+
var _root_numberToDocumentId_get, _root_numberToDocumentId_get1;
|
|
1830
|
+
root === null || root === void 0 ? void 0 : root.numberToDocumentId.set(key, (_a2 = (_root_numberToDocumentId_get = root === null || root === void 0 ? void 0 : root.numberToDocumentId.get(key)) === null || _root_numberToDocumentId_get === void 0 ? void 0 : _root_numberToDocumentId_get.filter((v2) => v2 !== id)) != null ? _a2 : []);
|
|
1831
|
+
if (((_root_numberToDocumentId_get1 = root === null || root === void 0 ? void 0 : root.numberToDocumentId.get(key)) === null || _root_numberToDocumentId_get1 === void 0 ? void 0 : _root_numberToDocumentId_get1.length) === 0) {
|
|
1832
|
+
root === null || root === void 0 ? void 0 : root.numberToDocumentId.delete(key);
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
function filter(root, operation) {
|
|
1836
|
+
var _a2;
|
|
1837
|
+
const operationKeys = Object.keys(operation);
|
|
1838
|
+
if (operationKeys.length !== 1) {
|
|
1839
|
+
throw new Error("Invalid operation");
|
|
1840
|
+
}
|
|
1841
|
+
const operationType = operationKeys[0];
|
|
1842
|
+
switch (operationType) {
|
|
1843
|
+
case "eq": {
|
|
1844
|
+
const value = operation[operationType];
|
|
1845
|
+
return (_a2 = root.numberToDocumentId.get(value)) != null ? _a2 : [];
|
|
1846
|
+
}
|
|
1847
|
+
case "in": {
|
|
1848
|
+
const value = operation[operationType];
|
|
1849
|
+
const result = [];
|
|
1850
|
+
for (const v2 of value) {
|
|
1851
|
+
const ids = root.numberToDocumentId.get(v2);
|
|
1852
|
+
if (ids) {
|
|
1853
|
+
result.push(...ids);
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
return result;
|
|
1857
|
+
}
|
|
1858
|
+
case "nin": {
|
|
1859
|
+
const value = operation[operationType];
|
|
1860
|
+
const result = [];
|
|
1861
|
+
const keys = root.numberToDocumentId.keys();
|
|
1862
|
+
for (const key of keys) {
|
|
1863
|
+
if (value.includes(key)) {
|
|
1864
|
+
continue;
|
|
1865
|
+
}
|
|
1866
|
+
const ids = root.numberToDocumentId.get(key);
|
|
1867
|
+
if (ids) {
|
|
1868
|
+
result.push(...ids);
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
return result;
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
throw new Error("Invalid operation");
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/algorithms.js
|
|
1769
1878
|
function prioritizeTokenScores(arrays, boost, threshold = 1, keywordsCount) {
|
|
1770
1879
|
if (boost === 0) {
|
|
1771
1880
|
throw createError("INVALID_BOOST_VALUE");
|
|
@@ -1829,7 +1938,16 @@ function BM25(tf, matchingCount, docsCount, fieldLength, averageFieldLength, BM2
|
|
|
1829
1938
|
return idf * (d + tf * (k + 1)) / (tf + k * (1 - b + b * fieldLength / averageFieldLength));
|
|
1830
1939
|
}
|
|
1831
1940
|
|
|
1832
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
1941
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/cosine-similarity.js
|
|
1942
|
+
function getMagnitude(vector, vectorLength) {
|
|
1943
|
+
let magnitude = 0;
|
|
1944
|
+
for (let i = 0; i < vectorLength; i++) {
|
|
1945
|
+
magnitude += vector[i] * vector[i];
|
|
1946
|
+
}
|
|
1947
|
+
return Math.sqrt(magnitude);
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/index.js
|
|
1833
1951
|
async function insertDocumentScoreParameters(index, prop, id, tokens, docsCount) {
|
|
1834
1952
|
var _a2;
|
|
1835
1953
|
const internalId = getInternalDocumentId(index.sharedInternalDocumentStore, id);
|
|
@@ -1884,11 +2002,12 @@ async function calculateResultScores(context, index, prop, term, ids) {
|
|
|
1884
2002
|
}
|
|
1885
2003
|
return scoreList;
|
|
1886
2004
|
}
|
|
1887
|
-
async function
|
|
2005
|
+
async function create5(orama, sharedInternalDocumentStore, schema, index, prefix = "") {
|
|
1888
2006
|
if (!index) {
|
|
1889
2007
|
index = {
|
|
1890
2008
|
sharedInternalDocumentStore,
|
|
1891
2009
|
indexes: {},
|
|
2010
|
+
vectorIndexes: {},
|
|
1892
2011
|
searchableProperties: [],
|
|
1893
2012
|
searchablePropertiesWithTypes: {},
|
|
1894
2013
|
frequencies: {},
|
|
@@ -1901,62 +2020,93 @@ async function create4(orama, sharedInternalDocumentStore, schema, index, prefix
|
|
|
1901
2020
|
const typeActualType = typeof type;
|
|
1902
2021
|
const path = `${prefix}${prefix ? "." : ""}${prop}`;
|
|
1903
2022
|
if (typeActualType === "object" && !Array.isArray(type)) {
|
|
1904
|
-
|
|
2023
|
+
create5(orama, sharedInternalDocumentStore, type, index, path);
|
|
1905
2024
|
continue;
|
|
1906
2025
|
}
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
2026
|
+
if (isVectorType(type)) {
|
|
2027
|
+
index.searchableProperties.push(path);
|
|
2028
|
+
index.searchablePropertiesWithTypes[path] = type;
|
|
2029
|
+
index.vectorIndexes[path] = {
|
|
2030
|
+
size: getVectorSize(type),
|
|
2031
|
+
vectors: {}
|
|
2032
|
+
};
|
|
2033
|
+
} else {
|
|
2034
|
+
switch (type) {
|
|
2035
|
+
case "boolean":
|
|
2036
|
+
case "boolean[]":
|
|
2037
|
+
index.indexes[path] = {
|
|
2038
|
+
type: "Bool",
|
|
2039
|
+
node: {
|
|
2040
|
+
true: [],
|
|
2041
|
+
false: []
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
break;
|
|
2045
|
+
case "number":
|
|
2046
|
+
case "number[]":
|
|
2047
|
+
index.indexes[path] = {
|
|
2048
|
+
type: "AVL",
|
|
2049
|
+
node: create2(0, [])
|
|
2050
|
+
};
|
|
2051
|
+
break;
|
|
2052
|
+
case "string":
|
|
2053
|
+
case "string[]":
|
|
2054
|
+
index.indexes[path] = {
|
|
2055
|
+
type: "Radix",
|
|
2056
|
+
node: create3()
|
|
2057
|
+
};
|
|
2058
|
+
index.avgFieldLength[path] = 0;
|
|
2059
|
+
index.frequencies[path] = {};
|
|
2060
|
+
index.tokenOccurrences[path] = {};
|
|
2061
|
+
index.fieldLengths[path] = {};
|
|
2062
|
+
break;
|
|
2063
|
+
case "enum":
|
|
2064
|
+
index.indexes[path] = {
|
|
2065
|
+
type: "Flat",
|
|
2066
|
+
node: create4()
|
|
2067
|
+
};
|
|
2068
|
+
break;
|
|
2069
|
+
default:
|
|
2070
|
+
throw createError("INVALID_SCHEMA_TYPE", Array.isArray(type) ? "array" : type, path);
|
|
2071
|
+
}
|
|
2072
|
+
index.searchableProperties.push(path);
|
|
2073
|
+
index.searchablePropertiesWithTypes[path] = type;
|
|
1929
2074
|
}
|
|
1930
|
-
index.searchableProperties.push(path);
|
|
1931
|
-
index.searchablePropertiesWithTypes[path] = type;
|
|
1932
2075
|
}
|
|
1933
2076
|
return index;
|
|
1934
2077
|
}
|
|
1935
2078
|
async function insertScalar(implementation, index, prop, id, value, schemaType, language, tokenizer, docsCount) {
|
|
1936
2079
|
const internalId = getInternalDocumentId(index.sharedInternalDocumentStore, id);
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
2080
|
+
const { type, node } = index.indexes[prop];
|
|
2081
|
+
switch (type) {
|
|
2082
|
+
case "Bool": {
|
|
2083
|
+
node[value ? "true" : "false"].push(internalId);
|
|
1941
2084
|
break;
|
|
1942
2085
|
}
|
|
1943
|
-
case "
|
|
1944
|
-
insert(
|
|
2086
|
+
case "AVL":
|
|
2087
|
+
insert(node, value, [
|
|
1945
2088
|
internalId
|
|
1946
2089
|
]);
|
|
1947
2090
|
break;
|
|
1948
|
-
case "
|
|
2091
|
+
case "Radix": {
|
|
1949
2092
|
const tokens = await tokenizer.tokenize(value, language, prop);
|
|
1950
2093
|
await implementation.insertDocumentScoreParameters(index, prop, internalId, tokens, docsCount);
|
|
1951
2094
|
for (const token of tokens) {
|
|
1952
2095
|
await implementation.insertTokenScoreParameters(index, prop, internalId, tokens, token);
|
|
1953
|
-
insert2(
|
|
2096
|
+
insert2(node, token, internalId);
|
|
1954
2097
|
}
|
|
1955
2098
|
break;
|
|
1956
2099
|
}
|
|
2100
|
+
case "Flat": {
|
|
2101
|
+
insert3(node, value, internalId);
|
|
2102
|
+
break;
|
|
2103
|
+
}
|
|
1957
2104
|
}
|
|
1958
2105
|
}
|
|
1959
|
-
async function
|
|
2106
|
+
async function insert4(implementation, index, prop, id, value, schemaType, language, tokenizer, docsCount) {
|
|
2107
|
+
if (isVectorType(schemaType)) {
|
|
2108
|
+
return insertVector(index, prop, value, id);
|
|
2109
|
+
}
|
|
1960
2110
|
if (!isArrayType(schemaType)) {
|
|
1961
2111
|
return insertScalar(implementation, index, prop, id, value, schemaType, language, tokenizer, docsCount);
|
|
1962
2112
|
}
|
|
@@ -1967,28 +2117,44 @@ async function insert3(implementation, index, prop, id, value, schemaType, langu
|
|
|
1967
2117
|
await insertScalar(implementation, index, prop, id, elements[i], innerSchemaType, language, tokenizer, docsCount);
|
|
1968
2118
|
}
|
|
1969
2119
|
}
|
|
2120
|
+
function insertVector(index, prop, value, id) {
|
|
2121
|
+
if (!(value instanceof Float32Array)) {
|
|
2122
|
+
value = new Float32Array(value);
|
|
2123
|
+
}
|
|
2124
|
+
const size = index.vectorIndexes[prop].size;
|
|
2125
|
+
const magnitude = getMagnitude(value, size);
|
|
2126
|
+
index.vectorIndexes[prop].vectors[id] = [
|
|
2127
|
+
magnitude,
|
|
2128
|
+
value
|
|
2129
|
+
];
|
|
2130
|
+
}
|
|
1970
2131
|
async function removeScalar(implementation, index, prop, id, value, schemaType, language, tokenizer, docsCount) {
|
|
1971
2132
|
const internalId = getInternalDocumentId(index.sharedInternalDocumentStore, id);
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
2133
|
+
const { type, node } = index.indexes[prop];
|
|
2134
|
+
switch (type) {
|
|
2135
|
+
case "AVL": {
|
|
2136
|
+
removeDocument(node, internalId, value);
|
|
1975
2137
|
return true;
|
|
1976
2138
|
}
|
|
1977
|
-
case "
|
|
2139
|
+
case "Bool": {
|
|
1978
2140
|
const booleanKey = value ? "true" : "false";
|
|
1979
|
-
const position =
|
|
1980
|
-
|
|
2141
|
+
const position = node[booleanKey].indexOf(internalId);
|
|
2142
|
+
node[value ? "true" : "false"].splice(position, 1);
|
|
1981
2143
|
return true;
|
|
1982
2144
|
}
|
|
1983
|
-
case "
|
|
2145
|
+
case "Radix": {
|
|
1984
2146
|
const tokens = await tokenizer.tokenize(value, language, prop);
|
|
1985
2147
|
await implementation.removeDocumentScoreParameters(index, prop, id, docsCount);
|
|
1986
2148
|
for (const token of tokens) {
|
|
1987
2149
|
await implementation.removeTokenScoreParameters(index, prop, token);
|
|
1988
|
-
removeDocumentByWord(
|
|
2150
|
+
removeDocumentByWord(node, token, internalId);
|
|
1989
2151
|
}
|
|
1990
2152
|
return true;
|
|
1991
2153
|
}
|
|
2154
|
+
case "Flat": {
|
|
2155
|
+
removeDocument3(node, internalId, value);
|
|
2156
|
+
return true;
|
|
2157
|
+
}
|
|
1992
2158
|
}
|
|
1993
2159
|
}
|
|
1994
2160
|
async function remove3(implementation, index, prop, id, value, schemaType, language, tokenizer, docsCount) {
|
|
@@ -2007,9 +2173,12 @@ async function search(context, index, prop, term) {
|
|
|
2007
2173
|
if (!(prop in index.tokenOccurrences)) {
|
|
2008
2174
|
return [];
|
|
2009
2175
|
}
|
|
2010
|
-
const
|
|
2176
|
+
const { node, type } = index.indexes[prop];
|
|
2177
|
+
if (type !== "Radix") {
|
|
2178
|
+
throw createError("WRONG_SEARCH_PROPERTY_TYPE", prop);
|
|
2179
|
+
}
|
|
2011
2180
|
const { exact, tolerance } = context.params;
|
|
2012
|
-
const searchResult = find2(
|
|
2181
|
+
const searchResult = find2(node, {
|
|
2013
2182
|
term,
|
|
2014
2183
|
exact,
|
|
2015
2184
|
tolerance
|
|
@@ -2030,29 +2199,28 @@ async function searchByWhereClause(context, index, filters) {
|
|
|
2030
2199
|
}, acc), {});
|
|
2031
2200
|
for (const param of filterKeys) {
|
|
2032
2201
|
const operation = filters[param];
|
|
2033
|
-
if (typeof
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2202
|
+
if (typeof index.indexes[param] === "undefined") {
|
|
2203
|
+
throw createError("UNKNOWN_FILTER_PROPERTY", param);
|
|
2204
|
+
}
|
|
2205
|
+
const { node, type } = index.indexes[param];
|
|
2206
|
+
if (type === "Bool") {
|
|
2207
|
+
const idx = node;
|
|
2038
2208
|
const filteredIDs = idx[operation.toString()];
|
|
2039
|
-
filtersMap[param]
|
|
2209
|
+
safeArrayPush(filtersMap[param], filteredIDs);
|
|
2040
2210
|
continue;
|
|
2041
2211
|
}
|
|
2042
|
-
if (typeof operation === "string" || Array.isArray(operation)) {
|
|
2043
|
-
const idx = index.indexes[param];
|
|
2044
|
-
if (typeof idx === "undefined") {
|
|
2045
|
-
throw createError("UNKNOWN_FILTER_PROPERTY", param);
|
|
2046
|
-
}
|
|
2212
|
+
if (type === "Radix" && (typeof operation === "string" || Array.isArray(operation))) {
|
|
2047
2213
|
for (const raw of [
|
|
2048
2214
|
operation
|
|
2049
2215
|
].flat()) {
|
|
2050
2216
|
const term = await context.tokenizer.tokenize(raw, context.language, param);
|
|
2051
|
-
const
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2217
|
+
for (const t of term) {
|
|
2218
|
+
const filteredIDsResults = find2(node, {
|
|
2219
|
+
term: t,
|
|
2220
|
+
exact: true
|
|
2221
|
+
});
|
|
2222
|
+
safeArrayPush(filtersMap[param], Object.values(filteredIDsResults).flat());
|
|
2223
|
+
}
|
|
2056
2224
|
}
|
|
2057
2225
|
continue;
|
|
2058
2226
|
}
|
|
@@ -2060,43 +2228,42 @@ async function searchByWhereClause(context, index, filters) {
|
|
|
2060
2228
|
if (operationKeys.length > 1) {
|
|
2061
2229
|
throw createError("INVALID_FILTER_OPERATION", operationKeys.length);
|
|
2062
2230
|
}
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
if (typeof AVLNode === "undefined") {
|
|
2067
|
-
throw createError("UNKNOWN_FILTER_PROPERTY", param);
|
|
2231
|
+
if (type === "Flat") {
|
|
2232
|
+
filtersMap[param].push(...filter(node, operation));
|
|
2233
|
+
continue;
|
|
2068
2234
|
}
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2235
|
+
if (type === "AVL") {
|
|
2236
|
+
const operationOpt = operationKeys[0];
|
|
2237
|
+
const operationValue = operation[operationOpt];
|
|
2238
|
+
let filteredIDs = [];
|
|
2239
|
+
switch (operationOpt) {
|
|
2240
|
+
case "gt": {
|
|
2241
|
+
filteredIDs = greaterThan(node, operationValue, false);
|
|
2242
|
+
break;
|
|
2243
|
+
}
|
|
2244
|
+
case "gte": {
|
|
2245
|
+
filteredIDs = greaterThan(node, operationValue, true);
|
|
2246
|
+
break;
|
|
2247
|
+
}
|
|
2248
|
+
case "lt": {
|
|
2249
|
+
filteredIDs = lessThan(node, operationValue, false);
|
|
2250
|
+
break;
|
|
2251
|
+
}
|
|
2252
|
+
case "lte": {
|
|
2253
|
+
filteredIDs = lessThan(node, operationValue, true);
|
|
2254
|
+
break;
|
|
2255
|
+
}
|
|
2256
|
+
case "eq": {
|
|
2257
|
+
filteredIDs = (_a2 = find(node, operationValue)) != null ? _a2 : [];
|
|
2258
|
+
break;
|
|
2259
|
+
}
|
|
2260
|
+
case "between": {
|
|
2261
|
+
const [min, max] = operationValue;
|
|
2262
|
+
filteredIDs = rangeSearch(node, min, max);
|
|
2263
|
+
break;
|
|
2264
|
+
}
|
|
2099
2265
|
}
|
|
2266
|
+
safeArrayPush(filtersMap[param], filteredIDs);
|
|
2100
2267
|
}
|
|
2101
2268
|
}
|
|
2102
2269
|
const result = intersect(Object.values(filtersMap));
|
|
@@ -2108,29 +2275,63 @@ async function getSearchableProperties(index) {
|
|
|
2108
2275
|
async function getSearchablePropertiesWithTypes(index) {
|
|
2109
2276
|
return index.searchablePropertiesWithTypes;
|
|
2110
2277
|
}
|
|
2111
|
-
function
|
|
2278
|
+
function loadRadixNode(node) {
|
|
2112
2279
|
const convertedNode = create3(node.end, node.subWord, node.key);
|
|
2113
2280
|
convertedNode.docs = node.docs;
|
|
2114
2281
|
convertedNode.word = node.word;
|
|
2115
2282
|
for (const childrenKey of Object.keys(node.children)) {
|
|
2116
|
-
convertedNode.children[childrenKey] =
|
|
2283
|
+
convertedNode.children[childrenKey] = loadRadixNode(node.children[childrenKey]);
|
|
2117
2284
|
}
|
|
2118
2285
|
return convertedNode;
|
|
2119
2286
|
}
|
|
2287
|
+
function loadFlatNode(node) {
|
|
2288
|
+
return {
|
|
2289
|
+
numberToDocumentId: new Map(node)
|
|
2290
|
+
};
|
|
2291
|
+
}
|
|
2292
|
+
function saveFlatNode(node) {
|
|
2293
|
+
return Array.from(node.numberToDocumentId.entries());
|
|
2294
|
+
}
|
|
2120
2295
|
async function load3(sharedInternalDocumentStore, raw) {
|
|
2121
|
-
const { indexes: rawIndexes, searchableProperties, searchablePropertiesWithTypes, frequencies, tokenOccurrences, avgFieldLength, fieldLengths } = raw;
|
|
2296
|
+
const { indexes: rawIndexes, vectorIndexes: rawVectorIndexes, searchableProperties, searchablePropertiesWithTypes, frequencies, tokenOccurrences, avgFieldLength, fieldLengths } = raw;
|
|
2122
2297
|
const indexes = {};
|
|
2298
|
+
const vectorIndexes = {};
|
|
2123
2299
|
for (const prop of Object.keys(rawIndexes)) {
|
|
2124
|
-
const
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2300
|
+
const { node, type } = rawIndexes[prop];
|
|
2301
|
+
switch (type) {
|
|
2302
|
+
case "Radix":
|
|
2303
|
+
indexes[prop] = {
|
|
2304
|
+
type: "Radix",
|
|
2305
|
+
node: loadRadixNode(node)
|
|
2306
|
+
};
|
|
2307
|
+
break;
|
|
2308
|
+
case "Flat":
|
|
2309
|
+
indexes[prop] = {
|
|
2310
|
+
type: "Flat",
|
|
2311
|
+
node: loadFlatNode(node)
|
|
2312
|
+
};
|
|
2313
|
+
break;
|
|
2314
|
+
default:
|
|
2315
|
+
indexes[prop] = rawIndexes[prop];
|
|
2128
2316
|
}
|
|
2129
|
-
|
|
2317
|
+
}
|
|
2318
|
+
for (const idx of Object.keys(rawVectorIndexes)) {
|
|
2319
|
+
const vectors = rawVectorIndexes[idx].vectors;
|
|
2320
|
+
for (const vec in vectors) {
|
|
2321
|
+
vectors[vec] = [
|
|
2322
|
+
vectors[vec][0],
|
|
2323
|
+
new Float32Array(vectors[vec][1])
|
|
2324
|
+
];
|
|
2325
|
+
}
|
|
2326
|
+
vectorIndexes[idx] = {
|
|
2327
|
+
size: rawVectorIndexes[idx].size,
|
|
2328
|
+
vectors
|
|
2329
|
+
};
|
|
2130
2330
|
}
|
|
2131
2331
|
return {
|
|
2132
2332
|
sharedInternalDocumentStore,
|
|
2133
2333
|
indexes,
|
|
2334
|
+
vectorIndexes,
|
|
2134
2335
|
searchableProperties,
|
|
2135
2336
|
searchablePropertiesWithTypes,
|
|
2136
2337
|
frequencies,
|
|
@@ -2140,9 +2341,36 @@ async function load3(sharedInternalDocumentStore, raw) {
|
|
|
2140
2341
|
};
|
|
2141
2342
|
}
|
|
2142
2343
|
async function save3(index) {
|
|
2143
|
-
const { indexes, searchableProperties, searchablePropertiesWithTypes, frequencies, tokenOccurrences, avgFieldLength, fieldLengths } = index;
|
|
2344
|
+
const { indexes, vectorIndexes, searchableProperties, searchablePropertiesWithTypes, frequencies, tokenOccurrences, avgFieldLength, fieldLengths } = index;
|
|
2345
|
+
const vectorIndexesAsArrays = {};
|
|
2346
|
+
for (const idx of Object.keys(vectorIndexes)) {
|
|
2347
|
+
const vectors = vectorIndexes[idx].vectors;
|
|
2348
|
+
for (const vec in vectors) {
|
|
2349
|
+
vectors[vec] = [
|
|
2350
|
+
vectors[vec][0],
|
|
2351
|
+
Array.from(vectors[vec][1])
|
|
2352
|
+
];
|
|
2353
|
+
}
|
|
2354
|
+
vectorIndexesAsArrays[idx] = {
|
|
2355
|
+
size: vectorIndexes[idx].size,
|
|
2356
|
+
vectors
|
|
2357
|
+
};
|
|
2358
|
+
}
|
|
2359
|
+
const savedIndexes = {};
|
|
2360
|
+
for (const name of Object.keys(indexes)) {
|
|
2361
|
+
const { type, node } = indexes[name];
|
|
2362
|
+
if (type !== "Flat") {
|
|
2363
|
+
savedIndexes[name] = indexes[name];
|
|
2364
|
+
continue;
|
|
2365
|
+
}
|
|
2366
|
+
savedIndexes[name] = {
|
|
2367
|
+
type: "Flat",
|
|
2368
|
+
node: saveFlatNode(node)
|
|
2369
|
+
};
|
|
2370
|
+
}
|
|
2144
2371
|
return {
|
|
2145
|
-
indexes,
|
|
2372
|
+
indexes: savedIndexes,
|
|
2373
|
+
vectorIndexes: vectorIndexesAsArrays,
|
|
2146
2374
|
searchableProperties,
|
|
2147
2375
|
searchablePropertiesWithTypes,
|
|
2148
2376
|
frequencies,
|
|
@@ -2153,8 +2381,8 @@ async function save3(index) {
|
|
|
2153
2381
|
}
|
|
2154
2382
|
async function createIndex() {
|
|
2155
2383
|
return {
|
|
2156
|
-
create:
|
|
2157
|
-
insert:
|
|
2384
|
+
create: create5,
|
|
2385
|
+
insert: insert4,
|
|
2158
2386
|
remove: remove3,
|
|
2159
2387
|
insertDocumentScoreParameters,
|
|
2160
2388
|
insertTokenScoreParameters,
|
|
@@ -2170,7 +2398,7 @@ async function createIndex() {
|
|
|
2170
2398
|
};
|
|
2171
2399
|
}
|
|
2172
2400
|
|
|
2173
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
2401
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/tokenizer/diacritics.js
|
|
2174
2402
|
var DIACRITICS_CHARCODE_START = 192;
|
|
2175
2403
|
var DIACRITICS_CHARCODE_END = 383;
|
|
2176
2404
|
var CHARCODE_REPLACE_MAPPING = [
|
|
@@ -2380,7 +2608,7 @@ function replaceDiacritics(str) {
|
|
|
2380
2608
|
return String.fromCharCode(...stringCharCode);
|
|
2381
2609
|
}
|
|
2382
2610
|
|
|
2383
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
2611
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/tokenizer/english-stemmer.js
|
|
2384
2612
|
var step2List = {
|
|
2385
2613
|
ational: "ate",
|
|
2386
2614
|
tional: "tion",
|
|
@@ -2540,7 +2768,7 @@ function stemmer(w) {
|
|
|
2540
2768
|
return w;
|
|
2541
2769
|
}
|
|
2542
2770
|
|
|
2543
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
2771
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/tokenizer/index.js
|
|
2544
2772
|
function normalizeToken(prop, token) {
|
|
2545
2773
|
var _this_stopWords;
|
|
2546
2774
|
const key = `${this.language}:${prop}:${token}`;
|
|
@@ -2576,8 +2804,15 @@ function tokenize(input, language, prop) {
|
|
|
2576
2804
|
input
|
|
2577
2805
|
];
|
|
2578
2806
|
}
|
|
2579
|
-
|
|
2580
|
-
|
|
2807
|
+
let tokens;
|
|
2808
|
+
if (prop && this.tokenizeSkipProperties.has(prop)) {
|
|
2809
|
+
tokens = [
|
|
2810
|
+
this.normalizeToken.bind(this, prop != null ? prop : "")(input)
|
|
2811
|
+
];
|
|
2812
|
+
} else {
|
|
2813
|
+
const splitRule = SPLITTERS[this.language];
|
|
2814
|
+
tokens = input.toLowerCase().split(splitRule).map(this.normalizeToken.bind(this, prop != null ? prop : "")).filter(Boolean);
|
|
2815
|
+
}
|
|
2581
2816
|
const trimTokens = trim(tokens);
|
|
2582
2817
|
if (!this.allowDuplicates) {
|
|
2583
2818
|
return Array.from(new Set(trimTokens));
|
|
@@ -2631,6 +2866,9 @@ async function createTokenizer(config = {}) {
|
|
|
2631
2866
|
stemmerSkipProperties: new Set(config.stemmerSkipProperties ? [
|
|
2632
2867
|
config.stemmerSkipProperties
|
|
2633
2868
|
].flat() : []),
|
|
2869
|
+
tokenizeSkipProperties: new Set(config.tokenizeSkipProperties ? [
|
|
2870
|
+
config.tokenizeSkipProperties
|
|
2871
|
+
].flat() : []),
|
|
2634
2872
|
stopWords,
|
|
2635
2873
|
allowDuplicates: Boolean(config.allowDuplicates),
|
|
2636
2874
|
normalizeToken,
|
|
@@ -2641,7 +2879,7 @@ async function createTokenizer(config = {}) {
|
|
|
2641
2879
|
return tokenizer;
|
|
2642
2880
|
}
|
|
2643
2881
|
|
|
2644
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
2882
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/sorter.js
|
|
2645
2883
|
function innerCreate(orama, sharedInternalDocumentStore, schema, sortableDeniedProperties, prefix) {
|
|
2646
2884
|
const sorter = {
|
|
2647
2885
|
language: orama.tokenizer.language,
|
|
@@ -2665,30 +2903,33 @@ function innerCreate(orama, sharedInternalDocumentStore, schema, sortableDeniedP
|
|
|
2665
2903
|
sorter.sortablePropertiesWithTypes = __spreadValues(__spreadValues({}, sorter.sortablePropertiesWithTypes), ret.sortablePropertiesWithTypes);
|
|
2666
2904
|
continue;
|
|
2667
2905
|
}
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2906
|
+
if (!isVectorType(type)) {
|
|
2907
|
+
switch (type) {
|
|
2908
|
+
case "boolean":
|
|
2909
|
+
case "number":
|
|
2910
|
+
case "string":
|
|
2911
|
+
sorter.sortableProperties.push(path);
|
|
2912
|
+
sorter.sortablePropertiesWithTypes[path] = type;
|
|
2913
|
+
sorter.sorts[path] = {
|
|
2914
|
+
docs: /* @__PURE__ */ new Map(),
|
|
2915
|
+
orderedDocsToRemove: /* @__PURE__ */ new Map(),
|
|
2916
|
+
orderedDocs: [],
|
|
2917
|
+
type
|
|
2918
|
+
};
|
|
2919
|
+
break;
|
|
2920
|
+
case "enum":
|
|
2921
|
+
case "boolean[]":
|
|
2922
|
+
case "number[]":
|
|
2923
|
+
case "string[]":
|
|
2924
|
+
continue;
|
|
2925
|
+
default:
|
|
2926
|
+
throw createError("INVALID_SORT_SCHEMA_TYPE", Array.isArray(type) ? "array" : type, path);
|
|
2927
|
+
}
|
|
2687
2928
|
}
|
|
2688
2929
|
}
|
|
2689
2930
|
return sorter;
|
|
2690
2931
|
}
|
|
2691
|
-
async function
|
|
2932
|
+
async function create6(orama, sharedInternalDocumentStore, schema, config) {
|
|
2692
2933
|
const isSortEnabled = (config === null || config === void 0 ? void 0 : config.enabled) !== false;
|
|
2693
2934
|
if (!isSortEnabled) {
|
|
2694
2935
|
return {
|
|
@@ -2697,7 +2938,7 @@ async function create5(orama, sharedInternalDocumentStore, schema, config) {
|
|
|
2697
2938
|
}
|
|
2698
2939
|
return innerCreate(orama, sharedInternalDocumentStore, schema, (config || {}).unsortableProperties || [], "");
|
|
2699
2940
|
}
|
|
2700
|
-
async function
|
|
2941
|
+
async function insert5(sorter, prop, id, value) {
|
|
2701
2942
|
if (!sorter.enabled) {
|
|
2702
2943
|
return;
|
|
2703
2944
|
}
|
|
@@ -2878,8 +3119,8 @@ async function save4(sorter) {
|
|
|
2878
3119
|
}
|
|
2879
3120
|
async function createSorter() {
|
|
2880
3121
|
return {
|
|
2881
|
-
create:
|
|
2882
|
-
insert:
|
|
3122
|
+
create: create6,
|
|
3123
|
+
insert: insert5,
|
|
2883
3124
|
remove: remove4,
|
|
2884
3125
|
save: save4,
|
|
2885
3126
|
load: load4,
|
|
@@ -2889,7 +3130,7 @@ async function createSorter() {
|
|
|
2889
3130
|
};
|
|
2890
3131
|
}
|
|
2891
3132
|
|
|
2892
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
3133
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/methods/create.js
|
|
2893
3134
|
function validateComponents(components) {
|
|
2894
3135
|
const defaultComponents = {
|
|
2895
3136
|
formatElapsedTime,
|
|
@@ -2929,7 +3170,7 @@ function validateComponents(components) {
|
|
|
2929
3170
|
}
|
|
2930
3171
|
}
|
|
2931
3172
|
}
|
|
2932
|
-
async function
|
|
3173
|
+
async function create7({ schema, sort, language, components, id }) {
|
|
2933
3174
|
if (!components) {
|
|
2934
3175
|
components = {};
|
|
2935
3176
|
}
|
|
@@ -2992,11 +3233,11 @@ async function create6({ schema, sort, language, components, id }) {
|
|
|
2992
3233
|
return orama;
|
|
2993
3234
|
}
|
|
2994
3235
|
|
|
2995
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
3236
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/types.js
|
|
2996
3237
|
var kInsertions = Symbol("orama.insertions");
|
|
2997
3238
|
var kRemovals = Symbol("orama.removals");
|
|
2998
3239
|
|
|
2999
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
3240
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/sync-blocking-checker.js
|
|
3000
3241
|
var _globalThis_process;
|
|
3001
3242
|
var _a;
|
|
3002
3243
|
var warn = (_a = (_globalThis_process = globalThis.process) === null || _globalThis_process === void 0 ? void 0 : _globalThis_process.emitWarning) != null ? _a : function emitWarning(message, options) {
|
|
@@ -3035,8 +3276,8 @@ function trackRemoval(orama) {
|
|
|
3035
3276
|
}
|
|
3036
3277
|
}
|
|
3037
3278
|
|
|
3038
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
3039
|
-
async function
|
|
3279
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/methods/insert.js
|
|
3280
|
+
async function insert6(orama, doc, language, skipHooks) {
|
|
3040
3281
|
const errorProperty = await orama.validateSchema(doc, orama.schema);
|
|
3041
3282
|
if (errorProperty) {
|
|
3042
3283
|
throw createError("SCHEMA_VALIDATION_FAILURE", errorProperty);
|
|
@@ -3065,9 +3306,15 @@ async function innerInsert(orama, doc, language, skipHooks) {
|
|
|
3065
3306
|
}
|
|
3066
3307
|
const actualType = typeof value;
|
|
3067
3308
|
const expectedType = indexablePropertiesWithTypes[key];
|
|
3309
|
+
if (isVectorType(expectedType) && Array.isArray(value)) {
|
|
3310
|
+
continue;
|
|
3311
|
+
}
|
|
3068
3312
|
if (isArrayType(expectedType) && Array.isArray(value)) {
|
|
3069
3313
|
continue;
|
|
3070
3314
|
}
|
|
3315
|
+
if (expectedType === "enum" && (actualType === "string" || actualType === "number")) {
|
|
3316
|
+
continue;
|
|
3317
|
+
}
|
|
3071
3318
|
if (actualType !== expectedType) {
|
|
3072
3319
|
throw createError("INVALID_DOCUMENT_PROPERTY", key, expectedType, actualType);
|
|
3073
3320
|
}
|
|
@@ -3101,7 +3348,7 @@ async function innerInsert(orama, doc, language, skipHooks) {
|
|
|
3101
3348
|
return id;
|
|
3102
3349
|
}
|
|
3103
3350
|
|
|
3104
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
3351
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/methods/remove.js
|
|
3105
3352
|
async function remove5(orama, id, language, skipHooks) {
|
|
3106
3353
|
let result = true;
|
|
3107
3354
|
const { index, docs } = orama.data;
|
|
@@ -3146,7 +3393,7 @@ async function remove5(orama, id, language, skipHooks) {
|
|
|
3146
3393
|
return result;
|
|
3147
3394
|
}
|
|
3148
3395
|
|
|
3149
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
3396
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/facets.js
|
|
3150
3397
|
function sortingPredicate(order = "desc", a, b) {
|
|
3151
3398
|
if (order.toLowerCase() === "asc") {
|
|
3152
3399
|
return a[1] - b[1];
|
|
@@ -3255,7 +3502,7 @@ function calculateBooleanOrStringFacet(values, facetValue, propertyType, already
|
|
|
3255
3502
|
}
|
|
3256
3503
|
}
|
|
3257
3504
|
|
|
3258
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
3505
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/filters.js
|
|
3259
3506
|
function intersectFilteredIDs(filtered, lookedUp) {
|
|
3260
3507
|
const map = /* @__PURE__ */ new Map();
|
|
3261
3508
|
const result = [];
|
|
@@ -3274,7 +3521,7 @@ function intersectFilteredIDs(filtered, lookedUp) {
|
|
|
3274
3521
|
return result;
|
|
3275
3522
|
}
|
|
3276
3523
|
|
|
3277
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
3524
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/groups.js
|
|
3278
3525
|
var DEFAULT_REDUCE = {
|
|
3279
3526
|
reducer: (_, acc, res, index) => {
|
|
3280
3527
|
acc[index] = res;
|
|
@@ -3395,16 +3642,17 @@ function calculateCombination(arrs, index = 0) {
|
|
|
3395
3642
|
const combinations = [];
|
|
3396
3643
|
for (const value of head) {
|
|
3397
3644
|
for (const combination of c2) {
|
|
3398
|
-
|
|
3399
|
-
value
|
|
3400
|
-
|
|
3401
|
-
|
|
3645
|
+
const result = [
|
|
3646
|
+
value
|
|
3647
|
+
];
|
|
3648
|
+
safeArrayPush(result, combination);
|
|
3649
|
+
combinations.push(result);
|
|
3402
3650
|
}
|
|
3403
3651
|
}
|
|
3404
3652
|
return combinations;
|
|
3405
3653
|
}
|
|
3406
3654
|
|
|
3407
|
-
// ../../node_modules/.pnpm/@orama+orama@1.
|
|
3655
|
+
// ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/methods/search.js
|
|
3408
3656
|
var defaultBM25Params = {
|
|
3409
3657
|
k: 1.2,
|
|
3410
3658
|
b: 0.75,
|
|
@@ -3474,7 +3722,7 @@ async function search2(orama, params, language) {
|
|
|
3474
3722
|
for (let j = 0; j < tokensLength2; j++) {
|
|
3475
3723
|
const term2 = tokens[j];
|
|
3476
3724
|
const scoreList = await orama.index.search(context, index, prop, term2);
|
|
3477
|
-
context.indexMap[prop][term2]
|
|
3725
|
+
safeArrayPush(context.indexMap[prop][term2], scoreList);
|
|
3478
3726
|
}
|
|
3479
3727
|
const docIds = context.indexMap[prop];
|
|
3480
3728
|
const vals = Object.values(docIds);
|
|
@@ -3628,6 +3876,7 @@ var debug = (0, import_debug.default)("verdaccio:search:indexer");
|
|
|
3628
3876
|
var SearchMemoryIndexer = class {
|
|
3629
3877
|
database;
|
|
3630
3878
|
storage;
|
|
3879
|
+
logger;
|
|
3631
3880
|
configureStorage(storage) {
|
|
3632
3881
|
this.storage = storage;
|
|
3633
3882
|
}
|
|
@@ -3635,24 +3884,32 @@ var SearchMemoryIndexer = class {
|
|
|
3635
3884
|
if (this.database) {
|
|
3636
3885
|
debug("searching %s at indexer", term);
|
|
3637
3886
|
const searchResult = await search2(this.database, {
|
|
3638
|
-
term
|
|
3639
|
-
properties: "*"
|
|
3887
|
+
term
|
|
3640
3888
|
});
|
|
3641
3889
|
return searchResult;
|
|
3642
3890
|
}
|
|
3643
3891
|
}
|
|
3892
|
+
prepareKeywords(keywords) {
|
|
3893
|
+
if (typeof keywords === "undefined") {
|
|
3894
|
+
return "";
|
|
3895
|
+
} else if (typeof keywords === "string") {
|
|
3896
|
+
return keywords;
|
|
3897
|
+
}
|
|
3898
|
+
return keywords.join(",");
|
|
3899
|
+
}
|
|
3644
3900
|
async add(pkg) {
|
|
3645
3901
|
if (this.database) {
|
|
3646
3902
|
const name = pkg.name;
|
|
3647
3903
|
debug("adding item %s to the indexer", name);
|
|
3648
|
-
|
|
3904
|
+
const item = {
|
|
3649
3905
|
id: name,
|
|
3650
3906
|
name,
|
|
3651
3907
|
description: pkg.description,
|
|
3652
|
-
version:
|
|
3653
|
-
keywords: pkg.keywords,
|
|
3654
|
-
author: pkg._npmUser ? pkg._npmUser.name : "
|
|
3655
|
-
}
|
|
3908
|
+
version: pkg.version,
|
|
3909
|
+
keywords: this.prepareKeywords(pkg.keywords),
|
|
3910
|
+
author: pkg._npmUser ? pkg._npmUser.name : ""
|
|
3911
|
+
};
|
|
3912
|
+
await insert6(this.database, item);
|
|
3656
3913
|
}
|
|
3657
3914
|
}
|
|
3658
3915
|
async remove(name) {
|
|
@@ -3661,10 +3918,11 @@ var SearchMemoryIndexer = class {
|
|
|
3661
3918
|
await remove5(this.database, name);
|
|
3662
3919
|
}
|
|
3663
3920
|
}
|
|
3664
|
-
reindex() {
|
|
3921
|
+
async reindex() {
|
|
3665
3922
|
var _a2;
|
|
3666
3923
|
debug("reindexing search indexer");
|
|
3667
|
-
(_a2 = this.storage) == null ? void 0 : _a2.getLocalDatabase((error, packages) => {
|
|
3924
|
+
(_a2 = this.storage) == null ? void 0 : _a2.getLocalDatabase(async (error, packages) => {
|
|
3925
|
+
var _a3;
|
|
3668
3926
|
if (error) {
|
|
3669
3927
|
throw error;
|
|
3670
3928
|
}
|
|
@@ -3675,13 +3933,18 @@ var SearchMemoryIndexer = class {
|
|
|
3675
3933
|
while (i--) {
|
|
3676
3934
|
const pkg = packages[i];
|
|
3677
3935
|
debug("indexing package %s", pkg == null ? void 0 : pkg.name);
|
|
3678
|
-
|
|
3936
|
+
try {
|
|
3937
|
+
await this.add(pkg);
|
|
3938
|
+
} catch (err) {
|
|
3939
|
+
(_a3 = this.logger) == null ? void 0 : _a3.error({ err: err.message }, "error @{err} indexing package");
|
|
3940
|
+
}
|
|
3679
3941
|
}
|
|
3680
3942
|
debug("reindexed search indexer");
|
|
3681
3943
|
});
|
|
3682
3944
|
}
|
|
3683
|
-
async init() {
|
|
3684
|
-
this.
|
|
3945
|
+
async init(logger) {
|
|
3946
|
+
this.logger = logger;
|
|
3947
|
+
this.database = await create7({
|
|
3685
3948
|
schema: {
|
|
3686
3949
|
id: "string",
|
|
3687
3950
|
name: "string",
|
package/build/indexer.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Version } from '@verdaccio/types';
|
|
1
|
+
import { Logger, Version } from '@verdaccio/types';
|
|
2
2
|
type Results = any;
|
|
3
3
|
declare class SearchMemoryIndexer {
|
|
4
4
|
private database;
|
|
5
5
|
private storage;
|
|
6
|
+
private logger;
|
|
6
7
|
/**
|
|
7
8
|
* Set up the {Storage}
|
|
8
9
|
* @param {*} storage An storage reference.
|
|
@@ -16,6 +17,7 @@ declare class SearchMemoryIndexer {
|
|
|
16
17
|
* @return {Array} list of results.
|
|
17
18
|
*/
|
|
18
19
|
query(term: string): Promise<Results | void>;
|
|
20
|
+
private prepareKeywords;
|
|
19
21
|
/**
|
|
20
22
|
* Add a new element to index
|
|
21
23
|
* @param {*} pkg the package
|
|
@@ -29,8 +31,8 @@ declare class SearchMemoryIndexer {
|
|
|
29
31
|
/**
|
|
30
32
|
* Force a re-index.
|
|
31
33
|
*/
|
|
32
|
-
reindex(): void
|
|
33
|
-
init(): Promise<void>;
|
|
34
|
+
reindex(): Promise<void>;
|
|
35
|
+
init(logger: Logger): Promise<void>;
|
|
34
36
|
}
|
|
35
37
|
declare const _default: SearchMemoryIndexer;
|
|
36
38
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/search",
|
|
3
|
-
"version": "7.0.0-next.
|
|
3
|
+
"version": "7.0.0-next.2",
|
|
4
4
|
"description": "verdaccio search utitlity tools",
|
|
5
5
|
"main": "./build/dist.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -26,12 +26,11 @@
|
|
|
26
26
|
"verdaccio"
|
|
27
27
|
],
|
|
28
28
|
"engines": {
|
|
29
|
-
"node": ">=12"
|
|
30
|
-
"npm": ">=6"
|
|
29
|
+
"node": ">=12"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
|
-
"@verdaccio/types": "12.0.0-next.
|
|
34
|
-
"@orama/orama": "1.
|
|
32
|
+
"@verdaccio/types": "12.0.0-next.1",
|
|
33
|
+
"@orama/orama": "1.2.4",
|
|
35
34
|
"debug": "4.3.4",
|
|
36
35
|
"esbuild": "0.14.10"
|
|
37
36
|
},
|
|
@@ -41,7 +40,7 @@
|
|
|
41
40
|
},
|
|
42
41
|
"scripts": {
|
|
43
42
|
"clean": "rimraf ./build",
|
|
44
|
-
"test": "
|
|
43
|
+
"test": "vitest run",
|
|
45
44
|
"type-check": "tsc --noEmit -p tsconfig.build.json",
|
|
46
45
|
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
|
|
47
46
|
"build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
|
package/src/indexer.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { create, insert, remove, search } from '@orama/orama';
|
|
2
2
|
import buildDebug from 'debug';
|
|
3
3
|
|
|
4
|
-
import { Version } from '@verdaccio/types';
|
|
4
|
+
import { Logger, Version } from '@verdaccio/types';
|
|
5
5
|
|
|
6
6
|
const debug = buildDebug('verdaccio:search:indexer');
|
|
7
7
|
|
|
@@ -10,6 +10,7 @@ type Results = any;
|
|
|
10
10
|
class SearchMemoryIndexer {
|
|
11
11
|
private database: any | undefined;
|
|
12
12
|
private storage: any;
|
|
13
|
+
private logger: Logger | undefined;
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Set up the {Storage}
|
|
@@ -31,13 +32,21 @@ class SearchMemoryIndexer {
|
|
|
31
32
|
debug('searching %s at indexer', term);
|
|
32
33
|
const searchResult = await search(this.database, {
|
|
33
34
|
term,
|
|
34
|
-
properties: '*',
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
return searchResult;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
private prepareKeywords(keywords?: string[] | string): string {
|
|
42
|
+
if (typeof keywords === 'undefined') {
|
|
43
|
+
return '';
|
|
44
|
+
} else if (typeof keywords === 'string') {
|
|
45
|
+
return keywords;
|
|
46
|
+
}
|
|
47
|
+
return keywords.join(',');
|
|
48
|
+
}
|
|
49
|
+
|
|
41
50
|
/**
|
|
42
51
|
* Add a new element to index
|
|
43
52
|
* @param {*} pkg the package
|
|
@@ -46,14 +55,15 @@ class SearchMemoryIndexer {
|
|
|
46
55
|
if (this.database) {
|
|
47
56
|
const name = pkg.name;
|
|
48
57
|
debug('adding item %s to the indexer', name);
|
|
49
|
-
|
|
58
|
+
const item = {
|
|
50
59
|
id: name,
|
|
51
60
|
name: name,
|
|
52
61
|
description: pkg.description,
|
|
53
|
-
version:
|
|
54
|
-
keywords: pkg.keywords,
|
|
55
|
-
author: pkg._npmUser ? pkg._npmUser.name : '
|
|
56
|
-
}
|
|
62
|
+
version: pkg.version,
|
|
63
|
+
keywords: this.prepareKeywords(pkg.keywords),
|
|
64
|
+
author: pkg._npmUser ? pkg._npmUser.name : '',
|
|
65
|
+
};
|
|
66
|
+
await insert(this.database, item);
|
|
57
67
|
}
|
|
58
68
|
}
|
|
59
69
|
|
|
@@ -71,9 +81,9 @@ class SearchMemoryIndexer {
|
|
|
71
81
|
/**
|
|
72
82
|
* Force a re-index.
|
|
73
83
|
*/
|
|
74
|
-
public reindex(): void {
|
|
84
|
+
public async reindex(): Promise<void> {
|
|
75
85
|
debug('reindexing search indexer');
|
|
76
|
-
this.storage?.getLocalDatabase((error, packages): void => {
|
|
86
|
+
this.storage?.getLocalDatabase(async (error, packages): Promise<void> => {
|
|
77
87
|
if (error) {
|
|
78
88
|
// that function shouldn't produce any
|
|
79
89
|
throw error;
|
|
@@ -86,13 +96,18 @@ class SearchMemoryIndexer {
|
|
|
86
96
|
while (i--) {
|
|
87
97
|
const pkg = packages[i];
|
|
88
98
|
debug('indexing package %s', pkg?.name);
|
|
89
|
-
|
|
99
|
+
try {
|
|
100
|
+
await this.add(pkg);
|
|
101
|
+
} catch (err: any) {
|
|
102
|
+
this.logger?.error({ err: err.message }, 'error @{err} indexing package');
|
|
103
|
+
}
|
|
90
104
|
}
|
|
91
105
|
debug('reindexed search indexer');
|
|
92
106
|
});
|
|
93
107
|
}
|
|
94
108
|
|
|
95
|
-
public async init() {
|
|
109
|
+
public async init(logger: Logger) {
|
|
110
|
+
this.logger = logger;
|
|
96
111
|
this.database = await create({
|
|
97
112
|
schema: {
|
|
98
113
|
id: 'string',
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { expect, test } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { Logger } from '@verdaccio/types';
|
|
4
|
+
|
|
5
|
+
import { SearchMemoryIndexer } from '../src';
|
|
6
|
+
|
|
7
|
+
class MockStore {
|
|
8
|
+
getLocalDatabase(cb) {
|
|
9
|
+
return cb(null, [
|
|
10
|
+
{
|
|
11
|
+
name: 'verdaccio-search',
|
|
12
|
+
version: '1.0.0',
|
|
13
|
+
readme: 'foo',
|
|
14
|
+
description: 'foo',
|
|
15
|
+
keywords: ['foo', 'bar'],
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'verdaccio-utils',
|
|
19
|
+
version: '2.0.0',
|
|
20
|
+
readme: 'foo',
|
|
21
|
+
description: 'foo',
|
|
22
|
+
keywords: 'some',
|
|
23
|
+
},
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const logger = {
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
error: (...arg) => console.error(...arg),
|
|
31
|
+
} as Logger;
|
|
32
|
+
|
|
33
|
+
test('should search', async () => {
|
|
34
|
+
const store = new MockStore();
|
|
35
|
+
|
|
36
|
+
SearchMemoryIndexer.configureStorage(store);
|
|
37
|
+
await SearchMemoryIndexer.init(logger);
|
|
38
|
+
// @ts-expect-error
|
|
39
|
+
await SearchMemoryIndexer.add({
|
|
40
|
+
name: 'verdaccio',
|
|
41
|
+
version: '2.0.0',
|
|
42
|
+
readme: 'foo',
|
|
43
|
+
description: '',
|
|
44
|
+
});
|
|
45
|
+
const query = await SearchMemoryIndexer.query('verdaccio');
|
|
46
|
+
expect(query.hits.map((item) => item.id)).toEqual(['verdaccio', 'verdaccio-utils']);
|
|
47
|
+
});
|