@delali/narsil 0.4.1 → 0.4.2-next.273

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 (158) hide show
  1. package/README.md +1 -1
  2. package/dist/adapters/filesystem.d.ts +1 -1
  3. package/dist/adapters/filesystem.mjs +9 -3
  4. package/dist/adapters/gcs.d.ts +1 -1
  5. package/dist/adapters/indexeddb.d.ts +6 -1
  6. package/dist/adapters/indexeddb.mjs +20 -26
  7. package/dist/adapters/memory.d.ts +1 -1
  8. package/dist/adapters/s3.d.ts +1 -1
  9. package/dist/{adapters-pljAqmrC.d.ts → adapters-8LcdNB77.d.ts} +18 -1
  10. package/dist/browser/{chunk-QAOVAYAG.mjs → chunk-56UNHLAF.mjs} +1 -1
  11. package/dist/browser/{chunk-GBJSEHVJ.mjs → chunk-EKISQBV2.mjs} +283 -244
  12. package/dist/browser/{chunk-YINZFPLT.mjs → chunk-VAPCFSMX.mjs} +1 -1
  13. package/dist/browser/{chunk-4E5APHTM.mjs → chunk-VIVG3OXM.mjs} +1 -1
  14. package/dist/browser/{durability-config-75NSFCQN.mjs → durability-config-UP3OTUMB.mjs} +34 -2
  15. package/dist/browser/{msgpack-leaf-44XNWSSY.mjs → msgpack-leaf-76Q5SZ5S.mjs} +23 -10
  16. package/dist/browser/{optional-reads-6LN3HMUH.mjs → optional-reads-NQO5DKM4.mjs} +18 -16
  17. package/dist/browser/{optional-writes-76DWMRQH.mjs → optional-writes-3HKIVZFU.mjs} +295 -106
  18. package/dist/browser/{segment-codec-leaf-A427QJUX.mjs → segment-codec-leaf-GXSRX5VT.mjs} +47 -30
  19. package/dist/browser/{storage-leaf-5UTR5K7J.mjs → storage-leaf-42IZEOJJ.mjs} +1473 -305
  20. package/dist/{capabilities-BOFFMx84.d.ts → capabilities-BoWiLNv7.d.ts} +76 -61
  21. package/dist/{chunk-Z7XSHKOF.mjs → chunk-35RWLUVY.mjs} +63 -144
  22. package/dist/{chunk-6GHX35ZM.mjs → chunk-43T3P3BE.mjs} +1 -1
  23. package/dist/{chunk-IL5DRCNU.mjs → chunk-4JLHHEBN.mjs} +1 -1
  24. package/dist/{chunk-DKIMHIBC.mjs → chunk-4YIVY3PB.mjs} +2 -2
  25. package/dist/{react-native/chunks/chunk-ZUJCUPVS.mjs → chunk-5SHWA6PE.mjs} +1 -1
  26. package/dist/{chunk-2K24MEYV.mjs → chunk-6LVQ3GLT.mjs} +3 -3
  27. package/dist/{chunk-DDUXEJXW.mjs → chunk-6SIEVWMG.mjs} +45 -22
  28. package/dist/{chunk-WM5KJSQV.mjs → chunk-ACNHJOGC.mjs} +1 -1
  29. package/dist/{chunk-755NM4PL.mjs → chunk-BWPVDIRN.mjs} +183 -21
  30. package/dist/{chunk-SMQPZHPS.mjs → chunk-C57GWAXN.mjs} +1 -1
  31. package/dist/{chunk-357KIU5E.mjs → chunk-DRZP5MSG.mjs} +5 -5
  32. package/dist/{chunk-MYN4K5IS.mjs → chunk-DZMD4OMD.mjs} +1 -1
  33. package/dist/{chunk-7P5YWDRQ.mjs → chunk-EY5U4P5V.mjs} +1 -1
  34. package/dist/{chunk-X3EQCQLP.mjs → chunk-EZJ6HBG7.mjs} +2 -2
  35. package/dist/{chunk-WC5KAWXQ.mjs → chunk-FE2XILWN.mjs} +4 -4
  36. package/dist/{chunk-CERPUGRK.mjs → chunk-G3KVEHIW.mjs} +2 -2
  37. package/dist/{chunk-B3MO37YF.mjs → chunk-GTGQLCEI.mjs} +1 -1
  38. package/dist/{chunk-MSJD74GN.mjs → chunk-H23FB267.mjs} +5 -5
  39. package/dist/{chunk-UNEEFTEU.mjs → chunk-HZ3OAUTL.mjs} +2 -1
  40. package/dist/{chunk-M3B7SGJB.mjs → chunk-KL4ORYJW.mjs} +6 -6
  41. package/dist/{chunk-WTMCGZ74.mjs → chunk-KXA77DPZ.mjs} +2 -2
  42. package/dist/{chunk-6I6OO6B2.mjs → chunk-LRIJ7U3T.mjs} +4 -4
  43. package/dist/{chunk-3IE3A74H.mjs → chunk-PNFP5THV.mjs} +3 -3
  44. package/dist/{react-native/chunks/chunk-4FUCRLSA.mjs → chunk-PQWK7KXS.mjs} +1 -1
  45. package/dist/{chunk-P4F4UWLC.mjs → chunk-PSO7V7VW.mjs} +17 -3
  46. package/dist/{chunk-OGYSPNL2.mjs → chunk-QNZJYMCF.mjs} +7 -7
  47. package/dist/{chunk-DBC4EJWB.mjs → chunk-R3PFPFME.mjs} +1 -1
  48. package/dist/{chunk-MSIN4NM3.mjs → chunk-S3JHYPH7.mjs} +6 -1
  49. package/dist/{chunk-MI6UZGUR.mjs → chunk-SPA7GXST.mjs} +3 -3
  50. package/dist/{chunk-PP3W5PQQ.mjs → chunk-WYH3QHBK.mjs} +698 -451
  51. package/dist/{chunk-D456ZFPQ.mjs → chunk-X5V25BPN.mjs} +2 -2
  52. package/dist/{chunk-GXCDWLQI.mjs → chunk-Y7GXGJFZ.mjs} +23 -10
  53. package/dist/{chunk-NCIGNQJE.mjs → chunk-YGRJLI2Z.mjs} +930 -387
  54. package/dist/{react-native/chunks/chunk-MMPBO4WR.mjs → chunk-ZO7VLAIT.mjs} +2 -2
  55. package/dist/{chunk-AXDB6KUQ.mjs → chunk-ZTB7AWTW.mjs} +4 -4
  56. package/dist/chunk-ZYEEOZTT.mjs +52 -0
  57. package/dist/{client-BhNxHtcZ.d.ts → client-B0NPZSKY.d.ts} +4 -4
  58. package/dist/client.d.ts +9 -9
  59. package/dist/client.mjs +2 -2
  60. package/dist/{config-P9zW3Zz7.d.ts → config-B3-sw887.d.ts} +3 -3
  61. package/dist/{config-BJSL7piq.d.ts → config-DL_nkguq.d.ts} +4 -4
  62. package/dist/{direct-executor-GWJXDFLD.mjs → direct-executor-7G57AYXH.mjs} +4 -4
  63. package/dist/distribution/coordinator/etcd.d.ts +3 -3
  64. package/dist/distribution/coordinator/etcd.mjs +33 -3
  65. package/dist/distribution/coordinator/in-memory.d.ts +3 -3
  66. package/dist/distribution/transport/grpc.mjs +4 -4
  67. package/dist/distribution/transport/in-memory.mjs +1 -1
  68. package/dist/distribution/transport/tcp.mjs +12 -7
  69. package/dist/distribution.d.ts +8 -8
  70. package/dist/distribution.mjs +167 -91
  71. package/dist/{durability-config-VWS2K24E.mjs → durability-config-HWKWP35M.mjs} +34 -2
  72. package/dist/embeddings/openai.d.ts +7 -3
  73. package/dist/embeddings/openai.mjs +37 -31
  74. package/dist/{engine-DoFnkRoF.d.ts → engine-DGG_yX0p.d.ts} +3 -3
  75. package/dist/{index-B_vmxpgW.d.ts → index-fX_FbuRT.d.ts} +1 -1
  76. package/dist/index.browser.mjs +3 -3
  77. package/dist/index.d.ts +7 -7
  78. package/dist/index.mjs +4 -4
  79. package/dist/index.react-native.mjs +4 -4
  80. package/dist/invalidation/broadcast-channel.d.ts +1 -1
  81. package/dist/invalidation/filesystem.d.ts +1 -1
  82. package/dist/invalidation/noop.d.ts +1 -1
  83. package/dist/{long-query-thread-GNTDYDOZ.mjs → long-query-thread-KPN7NSOC.mjs} +14 -14
  84. package/dist/msgpack-leaf-LIT7TKZW.mjs +9 -0
  85. package/dist/{optional-reads-UCS23AWP.mjs → optional-reads-ESDVS225.mjs} +18 -16
  86. package/dist/{optional-writes-2AHJCGTY.mjs → optional-writes-CSULLISE.mjs} +9 -8
  87. package/dist/{paged-partition-archive-GBAHDT55.mjs → paged-partition-archive-BKQADXOT.mjs} +13 -13
  88. package/dist/partial-words.browser.mjs +3 -3
  89. package/dist/partial-words.mjs +4 -4
  90. package/dist/pattern.browser.mjs +2 -2
  91. package/dist/pattern.mjs +2 -2
  92. package/dist/persistence/durability/checkpoint-worker.d.ts +2 -2
  93. package/dist/persistence/durability/checkpoint-worker.mjs +14 -14
  94. package/dist/{query-actions-IDCUA7UV.mjs → query-actions-HTSJKZRU.mjs} +4 -4
  95. package/dist/query-suggestions/merge-worker.mjs +7 -7
  96. package/dist/query-suggestions.browser.mjs +3 -3
  97. package/dist/query-suggestions.d.ts +3 -3
  98. package/dist/query-suggestions.mjs +5 -5
  99. package/dist/react-native/chunks/{chunk-MRH36RN3.mjs → chunk-AOLLV37A.mjs} +1 -1
  100. package/dist/react-native/chunks/{chunk-UO44MA5M.mjs → chunk-DN4FT62B.mjs} +23 -10
  101. package/dist/react-native/chunks/{chunk-TG56N5JC.mjs → chunk-EF4Y5C3Y.mjs} +2 -2
  102. package/dist/react-native/chunks/{chunk-HTBY4GON.mjs → chunk-ESVBC3AT.mjs} +1 -1
  103. package/dist/{chunk-F26DOOUH.mjs → react-native/chunks/chunk-H6LK5WCF.mjs} +1 -1
  104. package/dist/react-native/chunks/{chunk-LPX26NNL.mjs → chunk-JEYZQA4Z.mjs} +699 -451
  105. package/dist/react-native/chunks/{chunk-AJAH6X7W.mjs → chunk-KJQ3BUVM.mjs} +4 -4
  106. package/dist/{chunk-UHLFCGZ3.mjs → react-native/chunks/chunk-QYVRD6C5.mjs} +2 -2
  107. package/dist/react-native/chunks/{chunk-SCGBU47K.mjs → chunk-X3VY2YT4.mjs} +2 -2
  108. package/dist/{chunk-R2PJKSNL.mjs → react-native/chunks/chunk-ZF3VSGEI.mjs} +1 -1
  109. package/dist/react-native/chunks/{durability-config-FCSD4MXY.mjs → durability-config-HJETGZVB.mjs} +34 -2
  110. package/dist/react-native/chunks/msgpack-leaf-FOUPTT7J.mjs +7 -0
  111. package/dist/react-native/chunks/{optional-reads-4XCJ34QG.mjs → optional-reads-TN3PT6M4.mjs} +18 -16
  112. package/dist/react-native/chunks/{optional-writes-XYZVTBFB.mjs → optional-writes-MGFFGKYQ.mjs} +8 -7
  113. package/dist/react-native/chunks/{restore-queue-NOKQZJ2Z.mjs → restore-queue-MVJTP3E4.mjs} +7 -7
  114. package/dist/react-native/chunks/{segment-codec-leaf-3ZXBJVKH.mjs → segment-codec-leaf-PSWHL55A.mjs} +5 -5
  115. package/dist/react-native/chunks/{segment-merge-leaf-3Z7MMPWE.mjs → segment-merge-leaf-WOJWSDLW.mjs} +6 -6
  116. package/dist/react-native/chunks/{storage-leaf-KJOX3MMW.mjs → storage-leaf-ZUN6Y44X.mjs} +1481 -314
  117. package/dist/react-native/chunks/{store-leaf-QGLVSO5X.mjs → store-leaf-K5XG46FV.mjs} +6 -6
  118. package/dist/react-native/chunks/{suggestions-leaf-6GI5ZSW6.mjs → suggestions-leaf-KDPM3P27.mjs} +6 -6
  119. package/dist/react-native/chunks/{worker-copies-ALOD7TSP.mjs → worker-copies-FVFMBBH6.mjs} +5 -5
  120. package/dist/react-native/partial-words.mjs +4 -4
  121. package/dist/react-native/pattern.mjs +2 -2
  122. package/dist/react-native/query-suggestions.mjs +4 -4
  123. package/dist/react-native/sync.mjs +4 -4
  124. package/dist/react-native/synonyms.mjs +4 -4
  125. package/dist/react.d.ts +10 -10
  126. package/dist/react.mjs +0 -2
  127. package/dist/{rerank-HB6DU6GS.mjs → rerank-3QEJNMFH.mjs} +4 -4
  128. package/dist/rerankers/http.d.ts +1 -1
  129. package/dist/rerankers/http.mjs +19 -15
  130. package/dist/{restore-queue-VUQHGCXE.mjs → restore-queue-Q76Q4S35.mjs} +7 -7
  131. package/dist/{schema-CzG9OUw5.d.ts → schema-CFnQ-WI3.d.ts} +1 -1
  132. package/dist/{segment-codec-leaf-TW2FPAAT.mjs → segment-codec-leaf-BSDDR7DQ.mjs} +5 -5
  133. package/dist/{segment-merge-leaf-BS3QV5PZ.mjs → segment-merge-leaf-6TT66HC5.mjs} +5 -5
  134. package/dist/server.d.ts +86 -12
  135. package/dist/server.mjs +2243 -1918
  136. package/dist/{storage-leaf-5IG2HPNY.mjs → storage-leaf-R5JQ2X2M.mjs} +1193 -219
  137. package/dist/{store-leaf-ZWSOK2DV.mjs → store-leaf-NCGETZYY.mjs} +6 -6
  138. package/dist/{suggestions-leaf-MUZNKQVF.mjs → suggestions-leaf-TX3GTD6S.mjs} +8 -8
  139. package/dist/sync/filesystem.d.ts +4 -4
  140. package/dist/sync/filesystem.mjs +12 -12
  141. package/dist/sync/indexeddb.browser.mjs +1 -1
  142. package/dist/sync/indexeddb.d.ts +4 -4
  143. package/dist/sync/indexeddb.mjs +2 -2
  144. package/dist/sync.browser.mjs +4 -4
  145. package/dist/sync.d.ts +5 -5
  146. package/dist/sync.mjs +4 -4
  147. package/dist/synonyms.browser.mjs +3 -3
  148. package/dist/synonyms.mjs +4 -4
  149. package/dist/{tasks-DrLiolTG.d.ts → tasks-B2MDjPL0.d.ts} +4 -4
  150. package/dist/{thread-6ZBCENAP.mjs → thread-VLVPAUWC.mjs} +13 -13
  151. package/dist/{types-pS-mAJmX.d.ts → types-DGjk684l.d.ts} +2 -2
  152. package/dist/vector/search-worker.d.ts +2 -2
  153. package/dist/{worker-copies-32HWFUH7.mjs → worker-copies-NZSBQZKG.mjs} +7 -7
  154. package/dist/workers/entry.mjs +16 -16
  155. package/package.json +12 -12
  156. package/dist/chunk-HLPRHOSO.mjs +0 -17
  157. package/dist/msgpack-leaf-H5ZYW7S7.mjs +0 -9
  158. package/dist/react-native/chunks/msgpack-leaf-JMNGSTRW.mjs +0 -7
@@ -56,11 +56,37 @@ function filesystemBackedDirectory(config) {
56
56
  }
57
57
  return null;
58
58
  }
59
+ function indexedDBLocationOf(config) {
60
+ const location = config.persistence?.indexedDB;
61
+ if (location === void 0) return null;
62
+ const { databaseName, storeName } = location;
63
+ if (typeof databaseName !== "string" || databaseName.length === 0) {
64
+ throw configError("persistence.indexedDB.databaseName must be a non-empty string");
65
+ }
66
+ if (typeof storeName !== "string" || storeName.length === 0) {
67
+ throw configError("persistence.indexedDB.storeName must be a non-empty string");
68
+ }
69
+ return { databaseName, storeName };
70
+ }
71
+ function requireNoLogFieldsOnSharedStore(durability) {
72
+ for (const field of WAL_ONLY_FIELDS) {
73
+ if (durability?.[field] !== void 0) {
74
+ throw configError(
75
+ `durability.${field} applies to the write-ahead log, which an IndexedDB store that an invalidation adapter shares between tabs cannot keep. Remove durability.${field}, or remove the invalidation adapter`
76
+ );
77
+ }
78
+ }
79
+ }
59
80
  function resolveDurabilityTier(config) {
60
81
  const filesystemDirectory = filesystemBackedDirectory(config);
82
+ const indexedDB = filesystemDirectory === null ? indexedDBLocationOf(config) : null;
61
83
  if (config.durability) {
62
84
  requireValidDurabilityConfig(config.durability);
63
85
  }
86
+ if (indexedDB !== null && config.persistence !== void 0 && config.invalidation !== void 0 && config.durability?.tier === void 0) {
87
+ requireNoLogFieldsOnSharedStore(config.durability);
88
+ return { kind: "snapshot", config: { ...config.durability }, adapter: config.persistence };
89
+ }
64
90
  if (config.durability?.tier === "snapshot") {
65
91
  if (config.persistence === void 0) {
66
92
  throw configError(
@@ -76,13 +102,16 @@ function resolveDurabilityTier(config) {
76
102
  if (filesystemDirectory !== null) {
77
103
  return { kind: "wal", config: { ...config.durability, directory: filesystemDirectory } };
78
104
  }
105
+ if (indexedDB !== null) {
106
+ return { kind: "wal", config: { ...config.durability }, indexedDB };
107
+ }
79
108
  if (config.persistence !== void 0) {
80
109
  throw configError(
81
- "WAL durability requires a filesystem directory, but the configured persistence adapter is not filesystem-backed. Use a filesystem persistence adapter or set durability.directory"
110
+ 'WAL durability requires a filesystem directory or the IndexedDB persistence adapter, and the configured persistence adapter is neither. Use one of those adapters, set durability.directory, or set durability.tier to "snapshot"'
82
111
  );
83
112
  }
84
113
  throw configError(
85
- "Durability requires a directory. Set durability.directory explicitly, or configure a filesystem persistence adapter"
114
+ "Durability requires a directory. Set durability.directory explicitly, or configure a filesystem or IndexedDB persistence adapter"
86
115
  );
87
116
  }
88
117
  if (config.persistence === void 0) {
@@ -91,6 +120,9 @@ function resolveDurabilityTier(config) {
91
120
  if (filesystemDirectory !== null) {
92
121
  return { kind: "wal", config: { directory: filesystemDirectory } };
93
122
  }
123
+ if (indexedDB !== null) {
124
+ return { kind: "wal", config: {}, indexedDB };
125
+ }
94
126
  return { kind: "snapshot", config: {}, adapter: config.persistence };
95
127
  }
96
128
 
@@ -62,24 +62,31 @@ function encodeDocument(document) {
62
62
  }
63
63
 
64
64
  // src/serialization/msgpack-header.ts
65
- function headerAt(view, offset) {
65
+ function headerOf(headerBytes, bodyBytes, children, into) {
66
+ if (into === void 0) return { headerBytes, bodyBytes, children };
67
+ into.headerBytes = headerBytes;
68
+ into.bodyBytes = bodyBytes;
69
+ into.children = children;
70
+ return into;
71
+ }
72
+ function headerAt(view, offset, into) {
66
73
  if (offset >= view.byteLength) return null;
67
74
  const tag = view.getUint8(offset);
68
- if (tag <= 127 || tag >= 224) return { headerBytes: 1, bodyBytes: 0, children: 0 };
69
- if (tag <= 143) return { headerBytes: 1, bodyBytes: 0, children: (tag & 15) * 2 };
70
- if (tag <= 159) return { headerBytes: 1, bodyBytes: 0, children: tag & 15 };
71
- if (tag <= 191) return { headerBytes: 1, bodyBytes: tag & 31, children: 0 };
75
+ if (tag <= 127 || tag >= 224) return headerOf(1, 0, 0, into);
76
+ if (tag <= 143) return headerOf(1, 0, (tag & 15) * 2, into);
77
+ if (tag <= 159) return headerOf(1, 0, tag & 15, into);
78
+ if (tag <= 191) return headerOf(1, tag & 31, 0, into);
72
79
  const lengthBytes = LENGTH_BYTES_BY_TAG.get(tag);
73
80
  if (lengthBytes !== void 0) {
74
81
  if (offset + 1 + lengthBytes > view.byteLength) return null;
75
82
  const length = lengthBytes === 1 ? view.getUint8(offset + 1) : lengthBytes === 2 ? view.getUint16(offset + 1, false) : view.getUint32(offset + 1, false);
76
83
  const headerBytes = 1 + lengthBytes;
77
- if (ARRAY_TAGS.has(tag)) return { headerBytes, bodyBytes: 0, children: length };
78
- if (MAP_TAGS.has(tag)) return { headerBytes, bodyBytes: 0, children: length * 2 };
79
- return { headerBytes, bodyBytes: length + (EXT_TAGS.has(tag) ? 1 : 0), children: 0 };
84
+ if (ARRAY_TAGS.has(tag)) return headerOf(headerBytes, 0, length, into);
85
+ if (MAP_TAGS.has(tag)) return headerOf(headerBytes, 0, length * 2, into);
86
+ return headerOf(headerBytes, length + (EXT_TAGS.has(tag) ? 1 : 0), 0, into);
80
87
  }
81
88
  const fixedBytes = FIXED_BODY_BYTES_BY_TAG.get(tag);
82
- return fixedBytes === void 0 ? null : { headerBytes: 1, bodyBytes: fixedBytes, children: 0 };
89
+ return fixedBytes === void 0 ? null : headerOf(1, fixedBytes, 0, into);
83
90
  }
84
91
  var LENGTH_BYTES_BY_TAG = /* @__PURE__ */ new Map([
85
92
  [196, 1],
@@ -244,6 +251,12 @@ function decode(bytes) {
244
251
  sharedDecoder ??= new Decoder();
245
252
  return sharedDecoder.decode(bytes);
246
253
  }
254
+ function decodeBoundedMessage(bytes) {
255
+ if (scanStrings(bytes, 0, null, Number.POSITIVE_INFINITY) === null) {
256
+ throw new RangeError("Invalid MessagePack value header");
257
+ }
258
+ return decode(bytes);
259
+ }
247
260
  function decodeMulti(bytes) {
248
261
  return new Decoder().decodeMulti(bytes);
249
262
  }
@@ -299,4 +312,4 @@ function restoreVectorFields(document, vectorFieldPaths) {
299
312
  }
300
313
  }
301
314
 
302
- export { Decoder, MAP_TAGS, bindMsgpackHost, decode, decodeMulti, encodeDocument, headerAt, restoreVectorFields, setNestedValue };
315
+ export { Decoder, MAP_TAGS, bindMsgpackHost, decode, decodeBoundedMessage, decodeMulti, encodeDocument, headerAt, restoreVectorFields, setNestedValue };
@@ -1619,8 +1619,11 @@ function hitsKeptPerGroup(maxPerGroup) {
1619
1619
  return Math.floor(maxPerGroup);
1620
1620
  }
1621
1621
  function applyGrouping(hits, group, documents) {
1622
+ const keptPerGroup = hitsKeptPerGroup(group.maxPerGroup);
1623
+ const limit = group.limit !== void 0 && Number.isFinite(group.limit) && group.limit >= 0 ? Math.min(Math.floor(group.limit), hits.length) : null;
1622
1624
  if (!group.fields || group.fields.length === 0) {
1623
- return [{ values: {}, hits }];
1625
+ if (hits.length === 0 || limit === 0) return [];
1626
+ return [reducedGroup({ values: {}, hits: hits.slice(0, keptPerGroup) }, group, hits, documents)];
1624
1627
  }
1625
1628
  if (hits.length > 4294967295)
1626
1629
  throw new NarsilError(ErrorCodes.CONFIG_INVALID, "The hit count exceeds the group layout");
@@ -1638,8 +1641,6 @@ function applyGrouping(hits, group, documents) {
1638
1641
  if (at > 0 && hits[order[at - 1]].id !== hits[order[at]].id) rank++;
1639
1642
  idRanks[order[at]] = rank;
1640
1643
  }
1641
- const keptPerGroup = hitsKeptPerGroup(group.maxPerGroup);
1642
- const limit = group.limit !== void 0 && Number.isFinite(group.limit) && group.limit >= 0 ? Math.min(Math.floor(group.limit), hits.length) : null;
1643
1644
  const heads = new Uint32Array(hits.length);
1644
1645
  const offsets = new Uint32Array(hits.length + 1);
1645
1646
  const positions = new Uint32Array(hits.length);
@@ -1664,23 +1665,24 @@ function applyGrouping(hits, group, documents) {
1664
1665
  for (let field = 0; field < group.fields.length; field++) values[group.fields[field]] = row?.[field] ?? null;
1665
1666
  const everyHit = [];
1666
1667
  for (let member = offsets[at]; member < offsets[at + 1]; member++) everyHit.push(hits[positions[member]]);
1667
- const result = { values, hits: everyHit.slice(0, keptPerGroup) };
1668
- if (group.reduce) {
1669
- const folded = foldGroupReducer(
1670
- group.reduce,
1671
- everyHit.map((hit) => ({ document: documents.document(hit.id), score: hit.score ?? 0 }))
1672
- );
1673
- if (folded.reducerError !== void 0) {
1674
- result.reducerError = folded.reducerError;
1675
- } else {
1676
- result.reduced = folded.reduced;
1677
- }
1678
- }
1679
- groups.push(result);
1668
+ groups.push(reducedGroup({ values, hits: everyHit.slice(0, keptPerGroup) }, group, everyHit, documents));
1680
1669
  }
1681
1670
  if (limit !== null && groups.length > limit) groups.length = limit;
1682
1671
  return groups;
1683
1672
  }
1673
+ function reducedGroup(result, group, everyHit, documents) {
1674
+ if (!group.reduce) return result;
1675
+ const folded = foldGroupReducer(
1676
+ group.reduce,
1677
+ everyHit.map((hit) => ({ document: documents.document(hit.id), score: hit.score ?? 0 }))
1678
+ );
1679
+ if (folded.reducerError !== void 0) {
1680
+ result.reducerError = folded.reducerError;
1681
+ } else {
1682
+ result.reduced = folded.reduced;
1683
+ }
1684
+ return result;
1685
+ }
1684
1686
  function foldGroupReducer(reduce, rows) {
1685
1687
  try {
1686
1688
  let accumulator = reduce.initialValue();