@verdaccio/search 7.0.0-next.1 → 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.
Files changed (3) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/build/dist.js +288 -133
  3. package/package.json +4 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
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
+
3
13
  ## 7.0.0-next.1
4
14
 
5
15
  ### Patch 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.2.1/node_modules/@orama/orama/dist/components/tokenizer/languages.js
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.2.1/node_modules/@orama/orama/dist/utils.js
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.2.1/node_modules/@orama/orama/dist/errors.js
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.",
@@ -1016,7 +1026,8 @@ Supported languages are:
1016
1026
  INVALID_VECTOR_SIZE: `Vector size must be a number greater than 0. Got "%s" instead.`,
1017
1027
  INVALID_VECTOR_VALUE: `Vector value must be a number greater than 0. Got "%s" instead.`,
1018
1028
  INVALID_INPUT_VECTOR: `Property "%s" was declared as a %s-dimentional vector, but got a %s-dimentional vector instead.
1019
- Input vectors must be of the size declared in the schema, as calculating similarity between vectors of different sizes can lead to unexpected results.`
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.`
1020
1031
  };
1021
1032
  function createError(code, ...args) {
1022
1033
  var _a2;
@@ -1028,7 +1039,7 @@ function createError(code, ...args) {
1028
1039
  return error;
1029
1040
  }
1030
1041
 
1031
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/defaults.js
1042
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/defaults.js
1032
1043
  async function formatElapsedTime(n) {
1033
1044
  return {
1034
1045
  raw: Number(n),
@@ -1051,6 +1062,9 @@ async function validateSchema(doc, schema) {
1051
1062
  if (typeOfValue === "undefined") {
1052
1063
  continue;
1053
1064
  }
1065
+ if (type === "enum" && (typeOfValue === "string" || typeOfValue === "number")) {
1066
+ continue;
1067
+ }
1054
1068
  const typeOfType = typeof type;
1055
1069
  if (isVectorType(type)) {
1056
1070
  const vectorSize = getVectorSize(type);
@@ -1092,6 +1106,7 @@ var IS_ARRAY_TYPE = {
1092
1106
  string: false,
1093
1107
  number: false,
1094
1108
  boolean: false,
1109
+ enum: false,
1095
1110
  "string[]": true,
1096
1111
  "number[]": true,
1097
1112
  "boolean[]": true
@@ -1122,7 +1137,7 @@ function getVectorSize(type) {
1122
1137
  }
1123
1138
  }
1124
1139
 
1125
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/internal-document-id-store.js
1140
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/internal-document-id-store.js
1126
1141
  function createInternalDocumentIDStore() {
1127
1142
  return {
1128
1143
  idToInternalId: /* @__PURE__ */ new Map(),
@@ -1168,7 +1183,7 @@ function getDocumentIdFromInternalId(store2, internalId) {
1168
1183
  return store2.internalIdToId[internalId - 1];
1169
1184
  }
1170
1185
 
1171
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/documents-store.js
1186
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/documents-store.js
1172
1187
  async function create(_, sharedInternalDocumentStore) {
1173
1188
  return {
1174
1189
  sharedInternalDocumentStore,
@@ -1242,7 +1257,7 @@ async function createDocumentsStore() {
1242
1257
  };
1243
1258
  }
1244
1259
 
1245
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/hooks.js
1260
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/hooks.js
1246
1261
  var OBJECT_COMPONENTS = [
1247
1262
  "tokenizer",
1248
1263
  "index",
@@ -1283,7 +1298,7 @@ async function runAfterSearch(hooks, db, params, language, results) {
1283
1298
  }
1284
1299
  }
1285
1300
 
1286
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/trees/avl.js
1301
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/trees/avl.js
1287
1302
  var BALANCE_STATE = {
1288
1303
  UNBALANCED_RIGHT: -2,
1289
1304
  SLIGHTLY_UNBALANCED_RIGHT: -1,
@@ -1323,7 +1338,7 @@ function rangeSearch(node, min, max) {
1323
1338
  traverse(node2.left);
1324
1339
  }
1325
1340
  if (node2.key >= min && node2.key <= max) {
1326
- result.push(...node2.value);
1341
+ safeArrayPush(result, node2.value);
1327
1342
  }
1328
1343
  if (node2.key < max) {
1329
1344
  traverse(node2.right);
@@ -1342,10 +1357,10 @@ function greaterThan(node, key, inclusive = false) {
1342
1357
  return;
1343
1358
  }
1344
1359
  if (inclusive && node2.key >= key) {
1345
- result.push(...node2.value);
1360
+ safeArrayPush(result, node2.value);
1346
1361
  }
1347
1362
  if (!inclusive && node2.key > key) {
1348
- result.push(...node2.value);
1363
+ safeArrayPush(result, node2.value);
1349
1364
  }
1350
1365
  traverse(node2.left);
1351
1366
  traverse(node2.right);
@@ -1363,10 +1378,10 @@ function lessThan(node, key, inclusive = false) {
1363
1378
  return;
1364
1379
  }
1365
1380
  if (inclusive && node2.key <= key) {
1366
- result.push(...node2.value);
1381
+ safeArrayPush(result, node2.value);
1367
1382
  }
1368
1383
  if (!inclusive && node2.key < key) {
1369
- result.push(...node2.value);
1384
+ safeArrayPush(result, node2.value);
1370
1385
  }
1371
1386
  traverse(node2.left);
1372
1387
  traverse(node2.right);
@@ -1516,6 +1531,9 @@ function remove2(root, key) {
1516
1531
  }
1517
1532
  function removeDocument(root, id, key) {
1518
1533
  const node = getNodeByKey(root, key);
1534
+ if (!node) {
1535
+ return;
1536
+ }
1519
1537
  if (node.value.length === 1) {
1520
1538
  remove2(root, key);
1521
1539
  return;
@@ -1523,7 +1541,7 @@ function removeDocument(root, id, key) {
1523
1541
  node.value.splice(node.value.indexOf(id), 1);
1524
1542
  }
1525
1543
 
1526
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/levenshtein.js
1544
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/levenshtein.js
1527
1545
  function _boundedLevenshtein(a, b, tolerance) {
1528
1546
  if (a === b) {
1529
1547
  return 0;
@@ -1612,7 +1630,7 @@ function syncBoundedLevenshtein(a, b, tolerance) {
1612
1630
  };
1613
1631
  }
1614
1632
 
1615
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/trees/radix.js
1633
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/trees/radix.js
1616
1634
  var Node = class {
1617
1635
  constructor(key, subWord, end) {
1618
1636
  this.key = key;
@@ -1790,7 +1808,73 @@ function removeDocumentByWord(root, term, docID, exact = true) {
1790
1808
  return true;
1791
1809
  }
1792
1810
 
1793
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/algorithms.js
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
1794
1878
  function prioritizeTokenScores(arrays, boost, threshold = 1, keywordsCount) {
1795
1879
  if (boost === 0) {
1796
1880
  throw createError("INVALID_BOOST_VALUE");
@@ -1854,7 +1938,7 @@ function BM25(tf, matchingCount, docsCount, fieldLength, averageFieldLength, BM2
1854
1938
  return idf * (d + tf * (k + 1)) / (tf + k * (1 - b + b * fieldLength / averageFieldLength));
1855
1939
  }
1856
1940
 
1857
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/cosine-similarity.js
1941
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/cosine-similarity.js
1858
1942
  function getMagnitude(vector, vectorLength) {
1859
1943
  let magnitude = 0;
1860
1944
  for (let i = 0; i < vectorLength; i++) {
@@ -1863,7 +1947,7 @@ function getMagnitude(vector, vectorLength) {
1863
1947
  return Math.sqrt(magnitude);
1864
1948
  }
1865
1949
 
1866
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/index.js
1950
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/index.js
1867
1951
  async function insertDocumentScoreParameters(index, prop, id, tokens, docsCount) {
1868
1952
  var _a2;
1869
1953
  const internalId = getInternalDocumentId(index.sharedInternalDocumentStore, id);
@@ -1918,7 +2002,7 @@ async function calculateResultScores(context, index, prop, term, ids) {
1918
2002
  }
1919
2003
  return scoreList;
1920
2004
  }
1921
- async function create4(orama, sharedInternalDocumentStore, schema, index, prefix = "") {
2005
+ async function create5(orama, sharedInternalDocumentStore, schema, index, prefix = "") {
1922
2006
  if (!index) {
1923
2007
  index = {
1924
2008
  sharedInternalDocumentStore,
@@ -1936,7 +2020,7 @@ async function create4(orama, sharedInternalDocumentStore, schema, index, prefix
1936
2020
  const typeActualType = typeof type;
1937
2021
  const path = `${prefix}${prefix ? "." : ""}${prop}`;
1938
2022
  if (typeActualType === "object" && !Array.isArray(type)) {
1939
- create4(orama, sharedInternalDocumentStore, type, index, path);
2023
+ create5(orama, sharedInternalDocumentStore, type, index, path);
1940
2024
  continue;
1941
2025
  }
1942
2026
  if (isVectorType(type)) {
@@ -1951,22 +2035,37 @@ async function create4(orama, sharedInternalDocumentStore, schema, index, prefix
1951
2035
  case "boolean":
1952
2036
  case "boolean[]":
1953
2037
  index.indexes[path] = {
1954
- true: [],
1955
- false: []
2038
+ type: "Bool",
2039
+ node: {
2040
+ true: [],
2041
+ false: []
2042
+ }
1956
2043
  };
1957
2044
  break;
1958
2045
  case "number":
1959
2046
  case "number[]":
1960
- index.indexes[path] = create2(0, []);
2047
+ index.indexes[path] = {
2048
+ type: "AVL",
2049
+ node: create2(0, [])
2050
+ };
1961
2051
  break;
1962
2052
  case "string":
1963
2053
  case "string[]":
1964
- index.indexes[path] = create3();
2054
+ index.indexes[path] = {
2055
+ type: "Radix",
2056
+ node: create3()
2057
+ };
1965
2058
  index.avgFieldLength[path] = 0;
1966
2059
  index.frequencies[path] = {};
1967
2060
  index.tokenOccurrences[path] = {};
1968
2061
  index.fieldLengths[path] = {};
1969
2062
  break;
2063
+ case "enum":
2064
+ index.indexes[path] = {
2065
+ type: "Flat",
2066
+ node: create4()
2067
+ };
2068
+ break;
1970
2069
  default:
1971
2070
  throw createError("INVALID_SCHEMA_TYPE", Array.isArray(type) ? "array" : type, path);
1972
2071
  }
@@ -1978,29 +2077,33 @@ async function create4(orama, sharedInternalDocumentStore, schema, index, prefix
1978
2077
  }
1979
2078
  async function insertScalar(implementation, index, prop, id, value, schemaType, language, tokenizer, docsCount) {
1980
2079
  const internalId = getInternalDocumentId(index.sharedInternalDocumentStore, id);
1981
- switch (schemaType) {
1982
- case "boolean": {
1983
- const booleanIndex = index.indexes[prop];
1984
- booleanIndex[value ? "true" : "false"].push(internalId);
2080
+ const { type, node } = index.indexes[prop];
2081
+ switch (type) {
2082
+ case "Bool": {
2083
+ node[value ? "true" : "false"].push(internalId);
1985
2084
  break;
1986
2085
  }
1987
- case "number":
1988
- insert(index.indexes[prop], value, [
2086
+ case "AVL":
2087
+ insert(node, value, [
1989
2088
  internalId
1990
2089
  ]);
1991
2090
  break;
1992
- case "string": {
2091
+ case "Radix": {
1993
2092
  const tokens = await tokenizer.tokenize(value, language, prop);
1994
2093
  await implementation.insertDocumentScoreParameters(index, prop, internalId, tokens, docsCount);
1995
2094
  for (const token of tokens) {
1996
2095
  await implementation.insertTokenScoreParameters(index, prop, internalId, tokens, token);
1997
- insert2(index.indexes[prop], token, internalId);
2096
+ insert2(node, token, internalId);
1998
2097
  }
1999
2098
  break;
2000
2099
  }
2100
+ case "Flat": {
2101
+ insert3(node, value, internalId);
2102
+ break;
2103
+ }
2001
2104
  }
2002
2105
  }
2003
- async function insert3(implementation, index, prop, id, value, schemaType, language, tokenizer, docsCount) {
2106
+ async function insert4(implementation, index, prop, id, value, schemaType, language, tokenizer, docsCount) {
2004
2107
  if (isVectorType(schemaType)) {
2005
2108
  return insertVector(index, prop, value, id);
2006
2109
  }
@@ -2027,26 +2130,31 @@ function insertVector(index, prop, value, id) {
2027
2130
  }
2028
2131
  async function removeScalar(implementation, index, prop, id, value, schemaType, language, tokenizer, docsCount) {
2029
2132
  const internalId = getInternalDocumentId(index.sharedInternalDocumentStore, id);
2030
- switch (schemaType) {
2031
- case "number": {
2032
- removeDocument(index.indexes[prop], internalId, value);
2133
+ const { type, node } = index.indexes[prop];
2134
+ switch (type) {
2135
+ case "AVL": {
2136
+ removeDocument(node, internalId, value);
2033
2137
  return true;
2034
2138
  }
2035
- case "boolean": {
2139
+ case "Bool": {
2036
2140
  const booleanKey = value ? "true" : "false";
2037
- const position = index.indexes[prop][booleanKey].indexOf(internalId);
2038
- index.indexes[prop][value ? "true" : "false"].splice(position, 1);
2141
+ const position = node[booleanKey].indexOf(internalId);
2142
+ node[value ? "true" : "false"].splice(position, 1);
2039
2143
  return true;
2040
2144
  }
2041
- case "string": {
2145
+ case "Radix": {
2042
2146
  const tokens = await tokenizer.tokenize(value, language, prop);
2043
2147
  await implementation.removeDocumentScoreParameters(index, prop, id, docsCount);
2044
2148
  for (const token of tokens) {
2045
2149
  await implementation.removeTokenScoreParameters(index, prop, token);
2046
- removeDocumentByWord(index.indexes[prop], token, internalId);
2150
+ removeDocumentByWord(node, token, internalId);
2047
2151
  }
2048
2152
  return true;
2049
2153
  }
2154
+ case "Flat": {
2155
+ removeDocument3(node, internalId, value);
2156
+ return true;
2157
+ }
2050
2158
  }
2051
2159
  }
2052
2160
  async function remove3(implementation, index, prop, id, value, schemaType, language, tokenizer, docsCount) {
@@ -2065,9 +2173,12 @@ async function search(context, index, prop, term) {
2065
2173
  if (!(prop in index.tokenOccurrences)) {
2066
2174
  return [];
2067
2175
  }
2068
- const rootNode = index.indexes[prop];
2176
+ const { node, type } = index.indexes[prop];
2177
+ if (type !== "Radix") {
2178
+ throw createError("WRONG_SEARCH_PROPERTY_TYPE", prop);
2179
+ }
2069
2180
  const { exact, tolerance } = context.params;
2070
- const searchResult = find2(rootNode, {
2181
+ const searchResult = find2(node, {
2071
2182
  term,
2072
2183
  exact,
2073
2184
  tolerance
@@ -2088,29 +2199,28 @@ async function searchByWhereClause(context, index, filters) {
2088
2199
  }, acc), {});
2089
2200
  for (const param of filterKeys) {
2090
2201
  const operation = filters[param];
2091
- if (typeof operation === "boolean") {
2092
- const idx = index.indexes[param];
2093
- if (typeof idx === "undefined") {
2094
- throw createError("UNKNOWN_FILTER_PROPERTY", param);
2095
- }
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;
2096
2208
  const filteredIDs = idx[operation.toString()];
2097
- filtersMap[param].push(...filteredIDs);
2209
+ safeArrayPush(filtersMap[param], filteredIDs);
2098
2210
  continue;
2099
2211
  }
2100
- if (typeof operation === "string" || Array.isArray(operation)) {
2101
- const idx = index.indexes[param];
2102
- if (typeof idx === "undefined") {
2103
- throw createError("UNKNOWN_FILTER_PROPERTY", param);
2104
- }
2212
+ if (type === "Radix" && (typeof operation === "string" || Array.isArray(operation))) {
2105
2213
  for (const raw of [
2106
2214
  operation
2107
2215
  ].flat()) {
2108
2216
  const term = await context.tokenizer.tokenize(raw, context.language, param);
2109
- const filteredIDsResults = find2(idx, {
2110
- term: term[0],
2111
- exact: true
2112
- });
2113
- filtersMap[param].push(...Object.values(filteredIDsResults).flat());
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
+ }
2114
2224
  }
2115
2225
  continue;
2116
2226
  }
@@ -2118,43 +2228,42 @@ async function searchByWhereClause(context, index, filters) {
2118
2228
  if (operationKeys.length > 1) {
2119
2229
  throw createError("INVALID_FILTER_OPERATION", operationKeys.length);
2120
2230
  }
2121
- const operationOpt = operationKeys[0];
2122
- const operationValue = operation[operationOpt];
2123
- const AVLNode = index.indexes[param];
2124
- if (typeof AVLNode === "undefined") {
2125
- throw createError("UNKNOWN_FILTER_PROPERTY", param);
2231
+ if (type === "Flat") {
2232
+ filtersMap[param].push(...filter(node, operation));
2233
+ continue;
2126
2234
  }
2127
- switch (operationOpt) {
2128
- case "gt": {
2129
- const filteredIDs = greaterThan(AVLNode, operationValue, false);
2130
- filtersMap[param].push(...filteredIDs);
2131
- break;
2132
- }
2133
- case "gte": {
2134
- const filteredIDs = greaterThan(AVLNode, operationValue, true);
2135
- filtersMap[param].push(...filteredIDs);
2136
- break;
2137
- }
2138
- case "lt": {
2139
- const filteredIDs = lessThan(AVLNode, operationValue, false);
2140
- filtersMap[param].push(...filteredIDs);
2141
- break;
2142
- }
2143
- case "lte": {
2144
- const filteredIDs = lessThan(AVLNode, operationValue, true);
2145
- filtersMap[param].push(...filteredIDs);
2146
- break;
2147
- }
2148
- case "eq": {
2149
- const filteredIDs = (_a2 = find(AVLNode, operationValue)) != null ? _a2 : [];
2150
- filtersMap[param].push(...filteredIDs);
2151
- break;
2152
- }
2153
- case "between": {
2154
- const [min, max] = operationValue;
2155
- const filteredIDs = rangeSearch(AVLNode, min, max);
2156
- filtersMap[param].push(...filteredIDs);
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
+ }
2157
2265
  }
2266
+ safeArrayPush(filtersMap[param], filteredIDs);
2158
2267
  }
2159
2268
  }
2160
2269
  const result = intersect(Object.values(filtersMap));
@@ -2166,26 +2275,45 @@ async function getSearchableProperties(index) {
2166
2275
  async function getSearchablePropertiesWithTypes(index) {
2167
2276
  return index.searchablePropertiesWithTypes;
2168
2277
  }
2169
- function loadNode(node) {
2278
+ function loadRadixNode(node) {
2170
2279
  const convertedNode = create3(node.end, node.subWord, node.key);
2171
2280
  convertedNode.docs = node.docs;
2172
2281
  convertedNode.word = node.word;
2173
2282
  for (const childrenKey of Object.keys(node.children)) {
2174
- convertedNode.children[childrenKey] = loadNode(node.children[childrenKey]);
2283
+ convertedNode.children[childrenKey] = loadRadixNode(node.children[childrenKey]);
2175
2284
  }
2176
2285
  return convertedNode;
2177
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
+ }
2178
2295
  async function load3(sharedInternalDocumentStore, raw) {
2179
2296
  const { indexes: rawIndexes, vectorIndexes: rawVectorIndexes, searchableProperties, searchablePropertiesWithTypes, frequencies, tokenOccurrences, avgFieldLength, fieldLengths } = raw;
2180
2297
  const indexes = {};
2181
2298
  const vectorIndexes = {};
2182
2299
  for (const prop of Object.keys(rawIndexes)) {
2183
- const value = rawIndexes[prop];
2184
- if (!("word" in value)) {
2185
- indexes[prop] = value;
2186
- continue;
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];
2187
2316
  }
2188
- indexes[prop] = loadNode(value);
2189
2317
  }
2190
2318
  for (const idx of Object.keys(rawVectorIndexes)) {
2191
2319
  const vectors = rawVectorIndexes[idx].vectors;
@@ -2228,8 +2356,20 @@ async function save3(index) {
2228
2356
  vectors
2229
2357
  };
2230
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
+ }
2231
2371
  return {
2232
- indexes,
2372
+ indexes: savedIndexes,
2233
2373
  vectorIndexes: vectorIndexesAsArrays,
2234
2374
  searchableProperties,
2235
2375
  searchablePropertiesWithTypes,
@@ -2241,8 +2381,8 @@ async function save3(index) {
2241
2381
  }
2242
2382
  async function createIndex() {
2243
2383
  return {
2244
- create: create4,
2245
- insert: insert3,
2384
+ create: create5,
2385
+ insert: insert4,
2246
2386
  remove: remove3,
2247
2387
  insertDocumentScoreParameters,
2248
2388
  insertTokenScoreParameters,
@@ -2258,7 +2398,7 @@ async function createIndex() {
2258
2398
  };
2259
2399
  }
2260
2400
 
2261
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/tokenizer/diacritics.js
2401
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/tokenizer/diacritics.js
2262
2402
  var DIACRITICS_CHARCODE_START = 192;
2263
2403
  var DIACRITICS_CHARCODE_END = 383;
2264
2404
  var CHARCODE_REPLACE_MAPPING = [
@@ -2468,7 +2608,7 @@ function replaceDiacritics(str) {
2468
2608
  return String.fromCharCode(...stringCharCode);
2469
2609
  }
2470
2610
 
2471
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/tokenizer/english-stemmer.js
2611
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/tokenizer/english-stemmer.js
2472
2612
  var step2List = {
2473
2613
  ational: "ate",
2474
2614
  tional: "tion",
@@ -2628,7 +2768,7 @@ function stemmer(w) {
2628
2768
  return w;
2629
2769
  }
2630
2770
 
2631
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/tokenizer/index.js
2771
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/tokenizer/index.js
2632
2772
  function normalizeToken(prop, token) {
2633
2773
  var _this_stopWords;
2634
2774
  const key = `${this.language}:${prop}:${token}`;
@@ -2664,8 +2804,15 @@ function tokenize(input, language, prop) {
2664
2804
  input
2665
2805
  ];
2666
2806
  }
2667
- const splitRule = SPLITTERS[this.language];
2668
- const tokens = input.toLowerCase().split(splitRule).map(this.normalizeToken.bind(this, prop != null ? prop : "")).filter(Boolean);
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
+ }
2669
2816
  const trimTokens = trim(tokens);
2670
2817
  if (!this.allowDuplicates) {
2671
2818
  return Array.from(new Set(trimTokens));
@@ -2719,6 +2866,9 @@ async function createTokenizer(config = {}) {
2719
2866
  stemmerSkipProperties: new Set(config.stemmerSkipProperties ? [
2720
2867
  config.stemmerSkipProperties
2721
2868
  ].flat() : []),
2869
+ tokenizeSkipProperties: new Set(config.tokenizeSkipProperties ? [
2870
+ config.tokenizeSkipProperties
2871
+ ].flat() : []),
2722
2872
  stopWords,
2723
2873
  allowDuplicates: Boolean(config.allowDuplicates),
2724
2874
  normalizeToken,
@@ -2729,7 +2879,7 @@ async function createTokenizer(config = {}) {
2729
2879
  return tokenizer;
2730
2880
  }
2731
2881
 
2732
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/sorter.js
2882
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/sorter.js
2733
2883
  function innerCreate(orama, sharedInternalDocumentStore, schema, sortableDeniedProperties, prefix) {
2734
2884
  const sorter = {
2735
2885
  language: orama.tokenizer.language,
@@ -2767,6 +2917,7 @@ function innerCreate(orama, sharedInternalDocumentStore, schema, sortableDeniedP
2767
2917
  type
2768
2918
  };
2769
2919
  break;
2920
+ case "enum":
2770
2921
  case "boolean[]":
2771
2922
  case "number[]":
2772
2923
  case "string[]":
@@ -2778,7 +2929,7 @@ function innerCreate(orama, sharedInternalDocumentStore, schema, sortableDeniedP
2778
2929
  }
2779
2930
  return sorter;
2780
2931
  }
2781
- async function create5(orama, sharedInternalDocumentStore, schema, config) {
2932
+ async function create6(orama, sharedInternalDocumentStore, schema, config) {
2782
2933
  const isSortEnabled = (config === null || config === void 0 ? void 0 : config.enabled) !== false;
2783
2934
  if (!isSortEnabled) {
2784
2935
  return {
@@ -2787,7 +2938,7 @@ async function create5(orama, sharedInternalDocumentStore, schema, config) {
2787
2938
  }
2788
2939
  return innerCreate(orama, sharedInternalDocumentStore, schema, (config || {}).unsortableProperties || [], "");
2789
2940
  }
2790
- async function insert4(sorter, prop, id, value) {
2941
+ async function insert5(sorter, prop, id, value) {
2791
2942
  if (!sorter.enabled) {
2792
2943
  return;
2793
2944
  }
@@ -2968,8 +3119,8 @@ async function save4(sorter) {
2968
3119
  }
2969
3120
  async function createSorter() {
2970
3121
  return {
2971
- create: create5,
2972
- insert: insert4,
3122
+ create: create6,
3123
+ insert: insert5,
2973
3124
  remove: remove4,
2974
3125
  save: save4,
2975
3126
  load: load4,
@@ -2979,7 +3130,7 @@ async function createSorter() {
2979
3130
  };
2980
3131
  }
2981
3132
 
2982
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/methods/create.js
3133
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/methods/create.js
2983
3134
  function validateComponents(components) {
2984
3135
  const defaultComponents = {
2985
3136
  formatElapsedTime,
@@ -3019,7 +3170,7 @@ function validateComponents(components) {
3019
3170
  }
3020
3171
  }
3021
3172
  }
3022
- async function create6({ schema, sort, language, components, id }) {
3173
+ async function create7({ schema, sort, language, components, id }) {
3023
3174
  if (!components) {
3024
3175
  components = {};
3025
3176
  }
@@ -3082,11 +3233,11 @@ async function create6({ schema, sort, language, components, id }) {
3082
3233
  return orama;
3083
3234
  }
3084
3235
 
3085
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/types.js
3236
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/types.js
3086
3237
  var kInsertions = Symbol("orama.insertions");
3087
3238
  var kRemovals = Symbol("orama.removals");
3088
3239
 
3089
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/sync-blocking-checker.js
3240
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/sync-blocking-checker.js
3090
3241
  var _globalThis_process;
3091
3242
  var _a;
3092
3243
  var warn = (_a = (_globalThis_process = globalThis.process) === null || _globalThis_process === void 0 ? void 0 : _globalThis_process.emitWarning) != null ? _a : function emitWarning(message, options) {
@@ -3125,8 +3276,8 @@ function trackRemoval(orama) {
3125
3276
  }
3126
3277
  }
3127
3278
 
3128
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/methods/insert.js
3129
- async function insert5(orama, doc, language, skipHooks) {
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) {
3130
3281
  const errorProperty = await orama.validateSchema(doc, orama.schema);
3131
3282
  if (errorProperty) {
3132
3283
  throw createError("SCHEMA_VALIDATION_FAILURE", errorProperty);
@@ -3161,6 +3312,9 @@ async function innerInsert(orama, doc, language, skipHooks) {
3161
3312
  if (isArrayType(expectedType) && Array.isArray(value)) {
3162
3313
  continue;
3163
3314
  }
3315
+ if (expectedType === "enum" && (actualType === "string" || actualType === "number")) {
3316
+ continue;
3317
+ }
3164
3318
  if (actualType !== expectedType) {
3165
3319
  throw createError("INVALID_DOCUMENT_PROPERTY", key, expectedType, actualType);
3166
3320
  }
@@ -3194,7 +3348,7 @@ async function innerInsert(orama, doc, language, skipHooks) {
3194
3348
  return id;
3195
3349
  }
3196
3350
 
3197
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/methods/remove.js
3351
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/methods/remove.js
3198
3352
  async function remove5(orama, id, language, skipHooks) {
3199
3353
  let result = true;
3200
3354
  const { index, docs } = orama.data;
@@ -3239,7 +3393,7 @@ async function remove5(orama, id, language, skipHooks) {
3239
3393
  return result;
3240
3394
  }
3241
3395
 
3242
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/facets.js
3396
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/facets.js
3243
3397
  function sortingPredicate(order = "desc", a, b) {
3244
3398
  if (order.toLowerCase() === "asc") {
3245
3399
  return a[1] - b[1];
@@ -3348,7 +3502,7 @@ function calculateBooleanOrStringFacet(values, facetValue, propertyType, already
3348
3502
  }
3349
3503
  }
3350
3504
 
3351
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/filters.js
3505
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/filters.js
3352
3506
  function intersectFilteredIDs(filtered, lookedUp) {
3353
3507
  const map = /* @__PURE__ */ new Map();
3354
3508
  const result = [];
@@ -3367,7 +3521,7 @@ function intersectFilteredIDs(filtered, lookedUp) {
3367
3521
  return result;
3368
3522
  }
3369
3523
 
3370
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/components/groups.js
3524
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/components/groups.js
3371
3525
  var DEFAULT_REDUCE = {
3372
3526
  reducer: (_, acc, res, index) => {
3373
3527
  acc[index] = res;
@@ -3488,16 +3642,17 @@ function calculateCombination(arrs, index = 0) {
3488
3642
  const combinations = [];
3489
3643
  for (const value of head) {
3490
3644
  for (const combination of c2) {
3491
- combinations.push([
3492
- value,
3493
- ...combination
3494
- ]);
3645
+ const result = [
3646
+ value
3647
+ ];
3648
+ safeArrayPush(result, combination);
3649
+ combinations.push(result);
3495
3650
  }
3496
3651
  }
3497
3652
  return combinations;
3498
3653
  }
3499
3654
 
3500
- // ../../node_modules/.pnpm/@orama+orama@1.2.1/node_modules/@orama/orama/dist/methods/search.js
3655
+ // ../../node_modules/.pnpm/@orama+orama@1.2.4/node_modules/@orama/orama/dist/methods/search.js
3501
3656
  var defaultBM25Params = {
3502
3657
  k: 1.2,
3503
3658
  b: 0.75,
@@ -3567,7 +3722,7 @@ async function search2(orama, params, language) {
3567
3722
  for (let j = 0; j < tokensLength2; j++) {
3568
3723
  const term2 = tokens[j];
3569
3724
  const scoreList = await orama.index.search(context, index, prop, term2);
3570
- context.indexMap[prop][term2].push(...scoreList);
3725
+ safeArrayPush(context.indexMap[prop][term2], scoreList);
3571
3726
  }
3572
3727
  const docIds = context.indexMap[prop];
3573
3728
  const vals = Object.values(docIds);
@@ -3754,7 +3909,7 @@ var SearchMemoryIndexer = class {
3754
3909
  keywords: this.prepareKeywords(pkg.keywords),
3755
3910
  author: pkg._npmUser ? pkg._npmUser.name : ""
3756
3911
  };
3757
- await insert5(this.database, item);
3912
+ await insert6(this.database, item);
3758
3913
  }
3759
3914
  }
3760
3915
  async remove(name) {
@@ -3789,7 +3944,7 @@ var SearchMemoryIndexer = class {
3789
3944
  }
3790
3945
  async init(logger) {
3791
3946
  this.logger = logger;
3792
- this.database = await create6({
3947
+ this.database = await create7({
3793
3948
  schema: {
3794
3949
  id: "string",
3795
3950
  name: "string",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdaccio/search",
3
- "version": "7.0.0-next.1",
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.0",
34
- "@orama/orama": "1.2.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
  },