@delali/narsil 0.3.1-next.156 → 0.3.1-next.160

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 (564) hide show
  1. package/dist/adapters/filesystem.mjs +3 -3
  2. package/dist/adapters/gcs.mjs +3 -3
  3. package/dist/adapters/indexeddb.mjs +1 -1
  4. package/dist/adapters/s3.mjs +3 -3
  5. package/dist/browser/{chunk-3V7DNNZL.mjs → chunk-4RNSFVWI.mjs} +20997 -19899
  6. package/dist/browser/chunk-MMHIIL5B.mjs +564 -0
  7. package/dist/browser/chunk-MZHQ65VI.mjs +1228 -0
  8. package/dist/browser/chunk-WC2DEXWU.mjs +29 -0
  9. package/dist/browser/{chunk-VLJQW4J6.mjs → core-leaf-TJAGWPZZ.mjs} +4674 -3102
  10. package/dist/browser/{durability-config-TIYKW6XX.mjs → durability-config-SGB5ZP5K.mjs} +8 -3
  11. package/dist/browser/embed-RF2MPGAO.mjs +222 -0
  12. package/dist/{geo-index-MRH5JMIR.mjs → browser/geo-index-GNHY4PUB.mjs} +190 -93
  13. package/dist/{react-native/chunks/module-TTEVPRCW.mjs → browser/module-362VSIGR.mjs} +1570 -275
  14. package/dist/browser/msgpack-leaf-44XNWSSY.mjs +302 -0
  15. package/dist/browser/optional-reads-XMVPG6HG.mjs +3230 -0
  16. package/dist/browser/optional-writes-WMZX4OEC.mjs +3196 -0
  17. package/dist/browser/phrase-module-22TKMXWI.mjs +616 -0
  18. package/dist/browser/resolve-vector-text-KI65IHMD.mjs +60 -0
  19. package/dist/{react-native/chunks/restore-hooks-IBGIY3DR.mjs → browser/restore-queue-S4BWOGMU.mjs} +98 -36
  20. package/dist/{react-native/chunks/runtime-R5E3TB3J.mjs → browser/runtime-NU6VOVH2.mjs} +61 -25
  21. package/dist/browser/segment-codec-leaf-A427QJUX.mjs +554 -0
  22. package/dist/browser/segment-merge-leaf-7BZ54JPI.mjs +1636 -0
  23. package/dist/browser/storage-leaf-X6CNRHJS.mjs +18221 -0
  24. package/dist/browser/store-leaf-AEMTAVHX.mjs +2069 -0
  25. package/dist/browser/{chunk-SSTPBZZX.mjs → suggestions-leaf-3Y6MR6OF.mjs} +441 -119
  26. package/dist/browser/worker-copies-WQCPP3TS.mjs +2750 -0
  27. package/dist/{capabilities-Da4ywVVl.d.ts → capabilities-BKDrry0z.d.ts} +2 -2
  28. package/dist/chunk-2JRERUNZ.mjs +217 -0
  29. package/dist/chunk-2RIS76RJ.mjs +212 -0
  30. package/dist/chunk-3B775F3C.mjs +252 -0
  31. package/dist/{chunk-K5QFDYST.mjs → chunk-3D6RZGJH.mjs} +3 -3
  32. package/dist/{chunk-INJYO3BU.mjs → chunk-4CAMH7FO.mjs} +1 -1
  33. package/dist/{chunk-U476IXKQ.mjs → chunk-4PY4JYMY.mjs} +2 -1
  34. package/dist/chunk-6EZW2GQL.mjs +978 -0
  35. package/dist/chunk-75UNINFA.mjs +271 -0
  36. package/dist/chunk-77AUVDQ5.mjs +7 -0
  37. package/dist/{browser/chunk-23XRXIBW.mjs → chunk-7MWYORQC.mjs} +10 -3
  38. package/dist/{chunk-TGP5M5R7.mjs → chunk-7T4LAYT4.mjs} +1 -1
  39. package/dist/{chunk-XIHUI4KB.mjs → chunk-AB27FWZM.mjs} +8 -3
  40. package/dist/{chunk-XAXKV65G.mjs → chunk-BXM7XM4G.mjs} +7 -3
  41. package/dist/{chunk-HJJI72X7.mjs → chunk-C7YQHCSO.mjs} +1 -1
  42. package/dist/{chunk-RVGRFOGN.mjs → chunk-D456ZFPQ.mjs} +2 -1
  43. package/dist/{chunk-KKQC526K.mjs → chunk-E2F6LZR3.mjs} +19 -21
  44. package/dist/{chunk-I2KPOLOZ.mjs → chunk-FE3MRIBN.mjs} +104 -13
  45. package/dist/{chunk-KYYABCSW.mjs → chunk-FETZYCH7.mjs} +15 -1
  46. package/dist/{chunk-ZKP7G7TV.mjs → chunk-FVZ5DB6Y.mjs} +3 -2
  47. package/dist/{chunk-2UV4QBHW.mjs → chunk-GF4K7IUK.mjs} +317 -120
  48. package/dist/chunk-GXCDWLQI.mjs +193 -0
  49. package/dist/{chunk-25KDNIZZ.mjs → chunk-H64YDF5M.mjs} +3 -3
  50. package/dist/{browser/chunk-CRE3G7F3.mjs → chunk-HOOR4CP5.mjs} +63 -7
  51. package/dist/chunk-IB4BYLE3.mjs +127 -0
  52. package/dist/{chunk-3C7MTCCI.mjs → chunk-IE3Q62QD.mjs} +2 -2
  53. package/dist/chunk-IH3G6SJO.mjs +40 -0
  54. package/dist/chunk-JV74RKCY.mjs +3041 -0
  55. package/dist/{chunk-FRBFVQFN.mjs → chunk-K67I3RF4.mjs} +261 -101
  56. package/dist/chunk-KLVMK3R5.mjs +47 -0
  57. package/dist/{chunk-5VV4R6P7.mjs → chunk-LAWIJRMJ.mjs} +4154 -2577
  58. package/dist/chunk-LF4GB4PO.mjs +281 -0
  59. package/dist/chunk-NC4QLCZC.mjs +59 -0
  60. package/dist/chunk-OOO54OVC.mjs +627 -0
  61. package/dist/chunk-OUWZKNO3.mjs +207 -0
  62. package/dist/{chunk-FJKKCV4D.mjs → chunk-P5YLI5ED.mjs} +343 -182
  63. package/dist/{chunk-6I6AYAXS.mjs → chunk-PTTMGRG5.mjs} +9 -10
  64. package/dist/{browser/chunk-SRMZXJSL.mjs → chunk-Q3ZZH5Z7.mjs} +6 -0
  65. package/dist/chunk-QBVTYY4J.mjs +54 -0
  66. package/dist/{react-native/chunks/chunk-GXX3DQXP.mjs → chunk-R4CE4IVU.mjs} +352 -165
  67. package/dist/chunk-S2POFTLN.mjs +10 -0
  68. package/dist/{chunk-KJ3RTZDJ.mjs → chunk-S3BSDBF7.mjs} +10 -3
  69. package/dist/{chunk-FAKFUDZZ.mjs → chunk-SHGN3QIF.mjs} +80 -13
  70. package/dist/chunk-SXIRM4MX.mjs +3549 -0
  71. package/dist/{react-native/chunks/chunk-EJ33LCHV.mjs → chunk-TGPKS2UM.mjs} +47 -1
  72. package/dist/chunk-TINW4BSH.mjs +31301 -0
  73. package/dist/{cold-module-6MO2XJF2.mjs → chunk-TSLV5P2J.mjs} +397 -79
  74. package/dist/{chunk-HHBUCIUY.mjs → chunk-TW543F33.mjs} +3 -3
  75. package/dist/chunk-U6B7DUQW.mjs +788 -0
  76. package/dist/{chunk-FYOVBEMM.mjs → chunk-V3SGPXWQ.mjs} +8 -9
  77. package/dist/chunk-W34VJXY7.mjs +4723 -0
  78. package/dist/chunk-YETKPX5M.mjs +5 -0
  79. package/dist/chunk-ZQ6QY42L.mjs +59 -0
  80. package/dist/{client-DRv7UVeY.d.ts → client-CTp8RRiK.d.ts} +16 -4
  81. package/dist/client.d.ts +8 -8
  82. package/dist/client.mjs +70 -18
  83. package/dist/{config-DMwffLKn.d.ts → config-PCNzWjHL.d.ts} +6 -3
  84. package/dist/{config-CoSig5Ox.d.ts → config-_WT5grSL.d.ts} +3 -3
  85. package/dist/core-leaf-KXFGP74A.mjs +7 -0
  86. package/dist/digest-leaf-KXBGKYHZ.mjs +1 -0
  87. package/dist/direct-executor-MKTZBR26.mjs +16 -0
  88. package/dist/distribution/coordinator/etcd.d.ts +2 -2
  89. package/dist/distribution/coordinator/etcd.mjs +7 -4
  90. package/dist/distribution/coordinator/in-memory.d.ts +2 -2
  91. package/dist/distribution/coordinator/in-memory.mjs +1 -2
  92. package/dist/distribution/transport/grpc.mjs +7 -2
  93. package/dist/distribution/transport/tcp.mjs +7 -1
  94. package/dist/distribution.d.ts +7 -7
  95. package/dist/distribution.mjs +1192 -1077
  96. package/dist/{react-native/chunks/durability-config-QXVZEO7T.mjs → durability-config-XV4XR7Y4.mjs} +7 -3
  97. package/dist/embed-4H7RTBVL.mjs +221 -0
  98. package/dist/embeddings/openai.mjs +2 -2
  99. package/dist/{engine-CFxPYqEk.d.ts → engine-DBRVR_d-.d.ts} +1252 -1239
  100. package/dist/{browser/geo-index-HHWGMNIS.mjs → geo-index-2ZMMWWSK.mjs} +190 -92
  101. package/dist/{index-C4AmUnl1.d.ts → index-Ck9w5WHz.d.ts} +1 -1
  102. package/dist/index.browser.mjs +4 -15
  103. package/dist/index.d.ts +1495 -78
  104. package/dist/index.mjs +14 -50
  105. package/dist/index.react-native.mjs +11 -28
  106. package/dist/invalidation/filesystem.mjs +1 -2
  107. package/dist/languages/albanian.mjs +1 -1
  108. package/dist/languages/amharic.mjs +1 -1
  109. package/dist/languages/arabic.mjs +1 -1
  110. package/dist/languages/armenian.mjs +1 -1
  111. package/dist/languages/azerbaijani.mjs +1 -1
  112. package/dist/languages/bambara.mjs +1 -1
  113. package/dist/languages/basque.mjs +1 -1
  114. package/dist/languages/belarusian.mjs +1 -1
  115. package/dist/languages/bengali.mjs +1 -1
  116. package/dist/languages/bosnian.mjs +1 -1
  117. package/dist/languages/breton.mjs +1 -1
  118. package/dist/languages/bulgarian.mjs +1 -1
  119. package/dist/languages/burmese.mjs +1 -1
  120. package/dist/languages/catalan.mjs +1 -1
  121. package/dist/languages/chinese.mjs +1 -1
  122. package/dist/languages/croatian.mjs +1 -1
  123. package/dist/languages/czech.mjs +1 -1
  124. package/dist/languages/dagbani.mjs +1 -1
  125. package/dist/languages/danish.mjs +1 -1
  126. package/dist/languages/dutch.mjs +1 -1
  127. package/dist/languages/english.mjs +1 -1
  128. package/dist/languages/esperanto.mjs +1 -1
  129. package/dist/languages/estonian.mjs +1 -1
  130. package/dist/languages/ewe.mjs +1 -1
  131. package/dist/languages/faroese.mjs +1 -1
  132. package/dist/languages/fijian.mjs +1 -1
  133. package/dist/languages/finnish.mjs +1 -1
  134. package/dist/languages/french.mjs +1 -1
  135. package/dist/languages/ga.mjs +1 -1
  136. package/dist/languages/galician.mjs +1 -1
  137. package/dist/languages/georgian.mjs +1 -1
  138. package/dist/languages/german.mjs +1 -1
  139. package/dist/languages/greek.mjs +1 -1
  140. package/dist/languages/guarani.mjs +1 -1
  141. package/dist/languages/gujarati.mjs +1 -1
  142. package/dist/languages/haitian-creole.mjs +1 -1
  143. package/dist/languages/hausa.mjs +1 -1
  144. package/dist/languages/hawaiian.mjs +1 -1
  145. package/dist/languages/hebrew.mjs +1 -1
  146. package/dist/languages/hindi.mjs +1 -1
  147. package/dist/languages/hungarian.mjs +1 -1
  148. package/dist/languages/icelandic.mjs +1 -1
  149. package/dist/languages/igbo.mjs +1 -1
  150. package/dist/languages/indonesian.mjs +1 -1
  151. package/dist/languages/irish.mjs +1 -1
  152. package/dist/languages/italian.mjs +1 -1
  153. package/dist/languages/japanese.mjs +1 -1
  154. package/dist/languages/kannada.mjs +1 -1
  155. package/dist/languages/kazakh.mjs +1 -1
  156. package/dist/languages/khmer.mjs +1 -1
  157. package/dist/languages/kinyarwanda.mjs +1 -1
  158. package/dist/languages/kirundi.mjs +1 -1
  159. package/dist/languages/korean.mjs +1 -1
  160. package/dist/languages/kurmanji.mjs +1 -1
  161. package/dist/languages/kyrgyz.mjs +1 -1
  162. package/dist/languages/lao.mjs +1 -1
  163. package/dist/languages/latin.mjs +1 -1
  164. package/dist/languages/latvian.mjs +1 -1
  165. package/dist/languages/lingala.mjs +1 -1
  166. package/dist/languages/lithuanian.mjs +1 -1
  167. package/dist/languages/luxembourgish.mjs +1 -1
  168. package/dist/languages/macedonian.mjs +1 -1
  169. package/dist/languages/malagasy.mjs +1 -1
  170. package/dist/languages/malay.mjs +1 -1
  171. package/dist/languages/malayalam.mjs +1 -1
  172. package/dist/languages/maltese.mjs +1 -1
  173. package/dist/languages/maori.mjs +1 -1
  174. package/dist/languages/marathi.mjs +1 -1
  175. package/dist/languages/nepali.mjs +1 -1
  176. package/dist/languages/norwegian.mjs +1 -1
  177. package/dist/languages/oromo.mjs +1 -1
  178. package/dist/languages/persian.mjs +1 -1
  179. package/dist/languages/polish.mjs +1 -1
  180. package/dist/languages/portuguese.mjs +1 -1
  181. package/dist/languages/punjabi.mjs +1 -1
  182. package/dist/languages/romanian.mjs +1 -1
  183. package/dist/languages/russian.mjs +1 -1
  184. package/dist/languages/samoan.mjs +1 -1
  185. package/dist/languages/sanskrit.mjs +1 -1
  186. package/dist/languages/scottish-gaelic.mjs +1 -1
  187. package/dist/languages/serbian.mjs +1 -1
  188. package/dist/languages/shona.mjs +1 -1
  189. package/dist/languages/sinhala.mjs +1 -1
  190. package/dist/languages/slovak.mjs +1 -1
  191. package/dist/languages/slovenian.mjs +1 -1
  192. package/dist/languages/sorani.mjs +1 -1
  193. package/dist/languages/spanish.mjs +1 -1
  194. package/dist/languages/swahili.mjs +1 -1
  195. package/dist/languages/swedish.mjs +1 -1
  196. package/dist/languages/tagalog.mjs +1 -1
  197. package/dist/languages/tamil.mjs +1 -1
  198. package/dist/languages/tatar.mjs +1 -1
  199. package/dist/languages/telugu.mjs +1 -1
  200. package/dist/languages/thai.mjs +1 -1
  201. package/dist/languages/tibetan.mjs +1 -1
  202. package/dist/languages/tigrinya.mjs +1 -1
  203. package/dist/languages/tongan.mjs +1 -1
  204. package/dist/languages/turkish.mjs +1 -1
  205. package/dist/languages/twi.mjs +1 -1
  206. package/dist/languages/ukrainian.mjs +1 -1
  207. package/dist/languages/urdu.mjs +1 -1
  208. package/dist/languages/vietnamese.mjs +1 -1
  209. package/dist/languages/welsh.mjs +1 -1
  210. package/dist/languages/wolof.mjs +1 -1
  211. package/dist/languages/xhosa.mjs +1 -1
  212. package/dist/languages/yoruba.mjs +1 -1
  213. package/dist/languages/zulu.mjs +1 -1
  214. package/dist/{long-query-thread-YA4IAYSY.mjs → long-query-thread-JMGNGF6V.mjs} +74 -58
  215. package/dist/{module-N55W4Q5C.mjs → module-ZJ6ARG6V.mjs} +444 -111
  216. package/dist/msgpack-leaf-5WFRP6JM.mjs +9 -0
  217. package/dist/optional-reads-BR3BOVZW.mjs +3373 -0
  218. package/dist/optional-writes-DDFHYUOH.mjs +218 -0
  219. package/dist/{paged-partition-archive-PXW5XAYU.mjs → paged-partition-archive-G576XGVE.mjs} +29 -69
  220. package/dist/partial-words.browser.mjs +1649 -0
  221. package/dist/partial-words.mjs +15 -14
  222. package/dist/{chunk-CITFCZKF.mjs → pattern.browser.mjs} +153 -186
  223. package/dist/pattern.mjs +6 -8
  224. package/dist/persistence/durability/checkpoint-worker.d.ts +32 -24
  225. package/dist/persistence/durability/checkpoint-worker.mjs +27 -58
  226. package/dist/phrase-module-XK3T44VU.mjs +634 -0
  227. package/dist/query-actions-OMXJEC2J.mjs +118 -0
  228. package/dist/query-suggestions/merge-worker.mjs +18 -54
  229. package/dist/query-suggestions.browser.mjs +26 -226
  230. package/dist/query-suggestions.d.ts +2 -2
  231. package/dist/query-suggestions.mjs +16 -67
  232. package/dist/react-native/chunks/chunk-4EXKQ2IB.mjs +565 -0
  233. package/dist/react-native/chunks/chunk-52QD7CBJ.mjs +52 -0
  234. package/dist/react-native/chunks/chunk-72OKYHZL.mjs +969 -0
  235. package/dist/react-native/chunks/chunk-AQOWRH2C.mjs +802 -0
  236. package/dist/react-native/chunks/chunk-FTQ7JNMU.mjs +898 -0
  237. package/dist/react-native/chunks/chunk-G3CUQ333.mjs +42 -0
  238. package/dist/{chunk-TBC3XUL2.mjs → react-native/chunks/chunk-HRDMIQ63.mjs} +53 -1
  239. package/dist/react-native/chunks/{chunk-KV46CT4D.mjs → chunk-IY6U6HRA.mjs} +63 -7
  240. package/dist/react-native/chunks/chunk-J2NQW353.mjs +212 -0
  241. package/dist/react-native/chunks/chunk-L4R5ITVG.mjs +29047 -0
  242. package/dist/react-native/chunks/chunk-OK3WUA6N.mjs +54 -0
  243. package/dist/react-native/chunks/{chunk-MVXELMJX.mjs → chunk-PVMEHBQO.mjs} +1 -1
  244. package/dist/react-native/chunks/{chunk-DZ7H7D2C.mjs → chunk-TQ26BKBH.mjs} +6 -0
  245. package/dist/react-native/chunks/{chunk-6VBXNFLE.mjs → chunk-VUJCSQG5.mjs} +3 -1
  246. package/dist/react-native/chunks/{chunk-ENLMYKSX.mjs → chunk-XEGKQKLY.mjs} +5385 -3114
  247. package/dist/react-native/chunks/chunk-YOTP2FPE.mjs +232 -0
  248. package/dist/react-native/chunks/chunk-ZIU6TWXG.mjs +127 -0
  249. package/dist/react-native/chunks/core-leaf-5B4JXCVA.mjs +6 -0
  250. package/dist/react-native/chunks/digest-leaf-X6OIFDIU.mjs +1 -0
  251. package/dist/{durability-config-GE4U7MCZ.mjs → react-native/chunks/durability-config-3IOXIPYZ.mjs} +7 -3
  252. package/dist/react-native/chunks/embed-3WQ2CCR5.mjs +221 -0
  253. package/dist/react-native/chunks/{geo-index-PX3BIHAH.mjs → geo-index-QEYKEVPH.mjs} +190 -93
  254. package/dist/react-native/chunks/{chunk-CKNRFDTZ.mjs → gzip.react-native-DLO4WW27.mjs} +2 -1
  255. package/dist/{browser/module-TCT66FWA.mjs → react-native/chunks/module-VUA27HZZ.mjs} +1018 -540
  256. package/dist/react-native/chunks/msgpack-leaf-TR66ZVAX.mjs +7 -0
  257. package/dist/react-native/chunks/optional-reads-WDTLLHUT.mjs +3364 -0
  258. package/dist/react-native/chunks/optional-writes-FZV3QW34.mjs +267 -0
  259. package/dist/react-native/chunks/phrase-module-KCQWVXYZ.mjs +635 -0
  260. package/dist/react-native/chunks/resolve-vector-text-LXRYXF7M.mjs +59 -0
  261. package/dist/react-native/chunks/restore-queue-EI2V2I4S.mjs +179 -0
  262. package/dist/{browser/runtime-OTAGEFQW.mjs → react-native/chunks/runtime-BUCSAK4U.mjs} +61 -25
  263. package/dist/react-native/chunks/segment-codec-leaf-6ULP7H3I.mjs +12 -0
  264. package/dist/react-native/chunks/segment-merge-leaf-F4GQZNK6.mjs +13 -0
  265. package/dist/react-native/chunks/storage-leaf-OAXBU2L6.mjs +18042 -0
  266. package/dist/react-native/chunks/store-leaf-GY2ZZFXB.mjs +14 -0
  267. package/dist/react-native/chunks/{chunk-UQ4OAXKU.mjs → suggestions-leaf-SQEZ4IBS.mjs} +332 -118
  268. package/dist/react-native/chunks/worker-copies-EEHSCFJW.mjs +2627 -0
  269. package/dist/react-native/partial-words.mjs +954 -35
  270. package/dist/react-native/pattern.mjs +238 -111
  271. package/dist/react-native/query-suggestions.mjs +33 -239
  272. package/dist/react-native/sync.mjs +127 -50
  273. package/dist/react-native/synonyms.mjs +256 -112
  274. package/dist/react.d.ts +9 -9
  275. package/dist/react.mjs +6 -0
  276. package/dist/{rerank-MQ37IYRV.mjs → rerank-Y6MWBMTT.mjs} +17 -8
  277. package/dist/rerankers/http.mjs +2 -2
  278. package/dist/resolve-vector-text-4PDRTPNQ.mjs +2 -0
  279. package/dist/restore-queue-KPYSRJ4A.mjs +184 -0
  280. package/dist/runtime-4GKUIAKV.mjs +595 -0
  281. package/dist/{schema-Jwt928nJ.d.ts → schema-C_7yRJLt.d.ts} +1 -1
  282. package/dist/segment-codec-leaf-6IFBSBPN.mjs +17 -0
  283. package/dist/segment-merge-leaf-VE3FUSVE.mjs +17 -0
  284. package/dist/server.d.ts +35 -13
  285. package/dist/server.mjs +90 -101
  286. package/dist/{browser/durability-wiring-A7BVG2DW.mjs → storage-leaf-HMIIOUYN.mjs} +2348 -902
  287. package/dist/store-leaf-M7T7SUZJ.mjs +19 -0
  288. package/dist/stored-values-BWIMpiT_.d.ts +25 -0
  289. package/dist/suggestions-leaf-Q3Q5D6XV.mjs +53 -0
  290. package/dist/sync/filesystem.d.ts +3 -3
  291. package/dist/sync/filesystem.mjs +27 -11
  292. package/dist/sync/indexeddb.browser.mjs +287 -0
  293. package/dist/sync/indexeddb.d.ts +3 -3
  294. package/dist/sync/indexeddb.mjs +7 -2
  295. package/dist/sync.browser.mjs +120 -70
  296. package/dist/sync.d.ts +4 -4
  297. package/dist/sync.mjs +121 -57
  298. package/dist/{chunk-I5B7RXU7.mjs → synonyms.browser.mjs} +248 -135
  299. package/dist/synonyms.mjs +15 -11
  300. package/dist/{tasks-qrJojgST.d.ts → tasks-B4tT4vmP.d.ts} +4 -4
  301. package/dist/thread-SNILJXX3.mjs +30 -0
  302. package/dist/{types-BZCGjfLn.d.ts → types-CTg0KaMy.d.ts} +2 -2
  303. package/dist/vector/search-worker.d.ts +7 -1
  304. package/dist/vector/search-worker.mjs +9 -13
  305. package/dist/worker-copies-ZLZS2CUM.mjs +2152 -0
  306. package/dist/workers/entry.mjs +60 -30
  307. package/openapi.json +137 -50
  308. package/package.json +233 -8
  309. package/dist/analysis-change-5BQOQ4BF.mjs +0 -55
  310. package/dist/analysis-change-entry-TXX6JSMX.mjs +0 -1
  311. package/dist/archive-history-E4R73RWD.mjs +0 -29
  312. package/dist/browser/analysis-change-435CUEPZ.mjs +0 -933
  313. package/dist/browser/analysis-change-entry-HZXKPPGV.mjs +0 -1
  314. package/dist/browser/archive-history-4IP5XQZY.mjs +0 -29
  315. package/dist/browser/chunk-2CFI5VVV.mjs +0 -241
  316. package/dist/browser/chunk-2TI4SSUP.mjs +0 -315
  317. package/dist/browser/chunk-3I27KXQD.mjs +0 -34
  318. package/dist/browser/chunk-3SSRJMFN.mjs +0 -100
  319. package/dist/browser/chunk-4NGKC4H4.mjs +0 -2635
  320. package/dist/browser/chunk-4RD3AFSB.mjs +0 -32
  321. package/dist/browser/chunk-5W3MMTLG.mjs +0 -19
  322. package/dist/browser/chunk-6LWDPLTB.mjs +0 -177
  323. package/dist/browser/chunk-7IGKGWSQ.mjs +0 -79
  324. package/dist/browser/chunk-7U3WVJUP.mjs +0 -150
  325. package/dist/browser/chunk-ATEBYXP6.mjs +0 -10
  326. package/dist/browser/chunk-BHFQATSC.mjs +0 -432
  327. package/dist/browser/chunk-DSXIBE6N.mjs +0 -78
  328. package/dist/browser/chunk-EA63E3D2.mjs +0 -857
  329. package/dist/browser/chunk-ELV4OZOI.mjs +0 -29
  330. package/dist/browser/chunk-EXQZGUQH.mjs +0 -193
  331. package/dist/browser/chunk-G64Q6OJF.mjs +0 -96
  332. package/dist/browser/chunk-GPPOG6PT.mjs +0 -9
  333. package/dist/browser/chunk-HOZW3PKP.mjs +0 -9
  334. package/dist/browser/chunk-IZXVW2ZJ.mjs +0 -217
  335. package/dist/browser/chunk-JPTQZWJQ.mjs +0 -10
  336. package/dist/browser/chunk-K4Q6KX3R.mjs +0 -2528
  337. package/dist/browser/chunk-KZWSX6BH.mjs +0 -645
  338. package/dist/browser/chunk-MGI4BCXC.mjs +0 -63
  339. package/dist/browser/chunk-ML7THVLJ.mjs +0 -38
  340. package/dist/browser/chunk-MOG4OVDK.mjs +0 -51
  341. package/dist/browser/chunk-NLWTBAGB.mjs +0 -111
  342. package/dist/browser/chunk-NQAME3RK.mjs +0 -21
  343. package/dist/browser/chunk-NXQG7DRA.mjs +0 -318
  344. package/dist/browser/chunk-OEDCEZXJ.mjs +0 -92
  345. package/dist/browser/chunk-OIZS5KIX.mjs +0 -6
  346. package/dist/browser/chunk-RA6LSBCM.mjs +0 -43
  347. package/dist/browser/chunk-STOWQFT3.mjs +0 -1829
  348. package/dist/browser/chunk-TK63WFXK.mjs +0 -90
  349. package/dist/browser/chunk-TY7L6OXO.mjs +0 -69
  350. package/dist/browser/chunk-U3JOQGWX.mjs +0 -19
  351. package/dist/browser/chunk-U4YDIBUT.mjs +0 -653
  352. package/dist/browser/chunk-VI7BQR4U.mjs +0 -21
  353. package/dist/browser/chunk-WI4MR75E.mjs +0 -86
  354. package/dist/browser/chunk-WN464PTL.mjs +0 -375
  355. package/dist/browser/chunk-WXLBZJMT.mjs +0 -25
  356. package/dist/browser/chunk-XAWNZ4G2.mjs +0 -151
  357. package/dist/browser/chunk-ZI2V4VD7.mjs +0 -21
  358. package/dist/browser/cold-module-2EHCIV4K.mjs +0 -759
  359. package/dist/browser/engine-hooks-E4UD67JD.mjs +0 -17
  360. package/dist/browser/gzip-5S7ROJFJ.mjs +0 -1
  361. package/dist/browser/import-DXYB6756.mjs +0 -19
  362. package/dist/browser/methods-KTQCSIN4.mjs +0 -30
  363. package/dist/browser/module-NIYMEA5R.mjs +0 -23
  364. package/dist/browser/operations-OJ3BXS55.mjs +0 -5
  365. package/dist/browser/phrase-module-HAT3TLZN.mjs +0 -328
  366. package/dist/browser/pool-3JLET5RO.mjs +0 -297
  367. package/dist/browser/release-76MXRPGV.mjs +0 -33
  368. package/dist/browser/restore-hooks-YPN4ZFCY.mjs +0 -114
  369. package/dist/browser/restore-queue-G3RQGL3Y.mjs +0 -55
  370. package/dist/browser/retention-ZWVMNC3Q.mjs +0 -210
  371. package/dist/browser/snapshot-VEQNIE6C.mjs +0 -963
  372. package/dist/browser/start-BM442C6R.mjs +0 -25
  373. package/dist/browser/sync-state-P5XG6LTQ.mjs +0 -15
  374. package/dist/browser/write-2EVMZWDE.mjs +0 -194
  375. package/dist/chunk-2NE7VCYE.mjs +0 -212
  376. package/dist/chunk-37CD3OKS.mjs +0 -87
  377. package/dist/chunk-3HYC4JRF.mjs +0 -50
  378. package/dist/chunk-3MXV3VHR.mjs +0 -46
  379. package/dist/chunk-3OH67G7R.mjs +0 -214
  380. package/dist/chunk-46KY2PJD.mjs +0 -905
  381. package/dist/chunk-4KKXNJM6.mjs +0 -242
  382. package/dist/chunk-5YNRKI2C.mjs +0 -81
  383. package/dist/chunk-6HTGOXIK.mjs +0 -875
  384. package/dist/chunk-6OEGXLBX.mjs +0 -57
  385. package/dist/chunk-6RC4K46J.mjs +0 -86
  386. package/dist/chunk-7GFE3PEY.mjs +0 -40
  387. package/dist/chunk-7GXJUJ24.mjs +0 -49
  388. package/dist/chunk-7LXHHCXZ.mjs +0 -1397
  389. package/dist/chunk-7V5IUP2T.mjs +0 -63
  390. package/dist/chunk-A4L7YTKX.mjs +0 -458
  391. package/dist/chunk-BEZH7VEH.mjs +0 -23
  392. package/dist/chunk-BTPGQC6Z.mjs +0 -27
  393. package/dist/chunk-BU4SAIC4.mjs +0 -196
  394. package/dist/chunk-BWZ3P4MU.mjs +0 -20
  395. package/dist/chunk-CSLGFPFQ.mjs +0 -218
  396. package/dist/chunk-CZQ33DLW.mjs +0 -78
  397. package/dist/chunk-DP5C7YFQ.mjs +0 -543
  398. package/dist/chunk-DWEPMFJE.mjs +0 -240
  399. package/dist/chunk-EEBCDP36.mjs +0 -32
  400. package/dist/chunk-EFBDHH5P.mjs +0 -7081
  401. package/dist/chunk-FB6463IN.mjs +0 -1499
  402. package/dist/chunk-FCJ553HS.mjs +0 -655
  403. package/dist/chunk-FNGAM5B7.mjs +0 -2639
  404. package/dist/chunk-FOCV4CBZ.mjs +0 -87
  405. package/dist/chunk-FQBFZAWG.mjs +0 -27
  406. package/dist/chunk-G6HRSGOU.mjs +0 -74
  407. package/dist/chunk-GES7U2PM.mjs +0 -68
  408. package/dist/chunk-GH4WQ22V.mjs +0 -34
  409. package/dist/chunk-GQPTDQCL.mjs +0 -54
  410. package/dist/chunk-HFPMMRQT.mjs +0 -206
  411. package/dist/chunk-HJSN7UYG.mjs +0 -10
  412. package/dist/chunk-I53G4JAU.mjs +0 -1974
  413. package/dist/chunk-I54T6CQP.mjs +0 -117
  414. package/dist/chunk-IPN7S4KX.mjs +0 -130
  415. package/dist/chunk-J4IJTTEX.mjs +0 -226
  416. package/dist/chunk-JDJBQLRO.mjs +0 -1126
  417. package/dist/chunk-JWRUUCWD.mjs +0 -151
  418. package/dist/chunk-K4ZIGL2O.mjs +0 -290
  419. package/dist/chunk-KAKQ74LS.mjs +0 -53
  420. package/dist/chunk-KF4EXSM4.mjs +0 -21
  421. package/dist/chunk-KHKIRS5D.mjs +0 -113
  422. package/dist/chunk-KOKM4PQN.mjs +0 -52
  423. package/dist/chunk-KP7TYHWT.mjs +0 -92
  424. package/dist/chunk-KZ3NX2P7.mjs +0 -21
  425. package/dist/chunk-L5ORED7V.mjs +0 -25
  426. package/dist/chunk-L6V6BST3.mjs +0 -1435
  427. package/dist/chunk-LHKOSI2J.mjs +0 -58
  428. package/dist/chunk-LQG5G2LY.mjs +0 -39
  429. package/dist/chunk-MATMVH65.mjs +0 -9
  430. package/dist/chunk-MP7ABPTD.mjs +0 -189
  431. package/dist/chunk-MQOJIO5B.mjs +0 -316
  432. package/dist/chunk-NF4DT3IH.mjs +0 -85
  433. package/dist/chunk-ORN5BLL7.mjs +0 -11
  434. package/dist/chunk-P5ZI2P2W.mjs +0 -7481
  435. package/dist/chunk-PELHVTO7.mjs +0 -24
  436. package/dist/chunk-PWC4VB3Q.mjs +0 -106
  437. package/dist/chunk-Q2UL2TPC.mjs +0 -21
  438. package/dist/chunk-QHPYS427.mjs +0 -66
  439. package/dist/chunk-QJVOLKU6.mjs +0 -111
  440. package/dist/chunk-QOW2JPUI.mjs +0 -634
  441. package/dist/chunk-QYRNLLLI.mjs +0 -99
  442. package/dist/chunk-RDXO6JST.mjs +0 -63
  443. package/dist/chunk-RFBLQLLZ.mjs +0 -16
  444. package/dist/chunk-RLOES5SX.mjs +0 -31
  445. package/dist/chunk-RZWWB2XR.mjs +0 -96
  446. package/dist/chunk-S5LN746F.mjs +0 -10
  447. package/dist/chunk-SA5LOGO3.mjs +0 -470
  448. package/dist/chunk-SQJWAIF4.mjs +0 -12
  449. package/dist/chunk-TDIK6NTV.mjs +0 -10
  450. package/dist/chunk-TGS5UXBE.mjs +0 -216
  451. package/dist/chunk-TQXHPFWT.mjs +0 -177
  452. package/dist/chunk-TZ3355VS.mjs +0 -121
  453. package/dist/chunk-TZTRKM33.mjs +0 -74
  454. package/dist/chunk-U55XJEIG.mjs +0 -18
  455. package/dist/chunk-UHICS3JI.mjs +0 -83
  456. package/dist/chunk-VD7J552I.mjs +0 -28
  457. package/dist/chunk-VTTRFF2C.mjs +0 -3711
  458. package/dist/chunk-WX4LAO6M.mjs +0 -656
  459. package/dist/chunk-WZ7YV54N.mjs +0 -152
  460. package/dist/chunk-X5CV2E2B.mjs +0 -1
  461. package/dist/chunk-XXHN7J46.mjs +0 -101
  462. package/dist/chunk-Y4WPNHMC.mjs +0 -50
  463. package/dist/chunk-YEKL4JBK.mjs +0 -96
  464. package/dist/chunk-YTWZVGCB.mjs +0 -382
  465. package/dist/chunk-Z2KAFCRT.mjs +0 -30
  466. package/dist/chunk-ZXNQEW43.mjs +0 -18
  467. package/dist/chunk-ZYAY26KG.mjs +0 -29
  468. package/dist/direct-executor-FTMYY3TI.mjs +0 -34
  469. package/dist/durability-wiring-VIF5MOSY.mjs +0 -4064
  470. package/dist/engine-hooks-EGUGNZYE.mjs +0 -54
  471. package/dist/gzip-F4HMIEEQ.mjs +0 -1
  472. package/dist/import-XKDPJQDP.mjs +0 -56
  473. package/dist/methods-7IOINERF.mjs +0 -30
  474. package/dist/module-FQ4JWNQJ.mjs +0 -62
  475. package/dist/operations-G5EP6JPX.mjs +0 -5
  476. package/dist/phrase-module-XW5MKWP5.mjs +0 -330
  477. package/dist/pool-Y4A46T36.mjs +0 -298
  478. package/dist/react-native/chunks/analysis-change-LT5QBQ3H.mjs +0 -926
  479. package/dist/react-native/chunks/analysis-change-entry-SCVWK6OU.mjs +0 -1
  480. package/dist/react-native/chunks/archive-history-MJKUQLSU.mjs +0 -29
  481. package/dist/react-native/chunks/chunk-2PRHILX3.mjs +0 -529
  482. package/dist/react-native/chunks/chunk-3JWDECAZ.mjs +0 -858
  483. package/dist/react-native/chunks/chunk-3NQOVO3K.mjs +0 -1
  484. package/dist/react-native/chunks/chunk-3WI35N75.mjs +0 -226
  485. package/dist/react-native/chunks/chunk-4DII3ZSM.mjs +0 -73
  486. package/dist/react-native/chunks/chunk-4J74WHQM.mjs +0 -177
  487. package/dist/react-native/chunks/chunk-4JYO3JD2.mjs +0 -242
  488. package/dist/react-native/chunks/chunk-5CQX3XXV.mjs +0 -17
  489. package/dist/react-native/chunks/chunk-6WA3C3DV.mjs +0 -85
  490. package/dist/react-native/chunks/chunk-AAAETEJK.mjs +0 -27
  491. package/dist/react-native/chunks/chunk-AM7RSBPF.mjs +0 -32
  492. package/dist/react-native/chunks/chunk-C5G6TJ7A.mjs +0 -140
  493. package/dist/react-native/chunks/chunk-CHPTFFJM.mjs +0 -43
  494. package/dist/react-native/chunks/chunk-DIYDOIM4.mjs +0 -10
  495. package/dist/react-native/chunks/chunk-DNXOMPAQ.mjs +0 -191
  496. package/dist/react-native/chunks/chunk-DVDX4SDR.mjs +0 -375
  497. package/dist/react-native/chunks/chunk-DXRSEWA2.mjs +0 -12
  498. package/dist/react-native/chunks/chunk-F753DA54.mjs +0 -23
  499. package/dist/react-native/chunks/chunk-FHPW7P2O.mjs +0 -40
  500. package/dist/react-native/chunks/chunk-FTZHMRD2.mjs +0 -18
  501. package/dist/react-native/chunks/chunk-G43IPIDG.mjs +0 -151
  502. package/dist/react-native/chunks/chunk-HJBJBH26.mjs +0 -34
  503. package/dist/react-native/chunks/chunk-IO2SMUQD.mjs +0 -10
  504. package/dist/react-native/chunks/chunk-IYNT75CE.mjs +0 -111
  505. package/dist/react-native/chunks/chunk-JDOEEMEF.mjs +0 -38
  506. package/dist/react-native/chunks/chunk-JWUCMVRK.mjs +0 -15
  507. package/dist/react-native/chunks/chunk-LU3Y3P63.mjs +0 -68
  508. package/dist/react-native/chunks/chunk-LVIKKAA6.mjs +0 -93
  509. package/dist/react-native/chunks/chunk-LZSLNSUN.mjs +0 -193
  510. package/dist/react-native/chunks/chunk-MIP4SOR6.mjs +0 -22803
  511. package/dist/react-native/chunks/chunk-MJDQU5MW.mjs +0 -1225
  512. package/dist/react-native/chunks/chunk-MUWD2H2S.mjs +0 -21
  513. package/dist/react-native/chunks/chunk-NB3LP33V.mjs +0 -315
  514. package/dist/react-native/chunks/chunk-NNE4VDMM.mjs +0 -8
  515. package/dist/react-native/chunks/chunk-NVVRSRX5.mjs +0 -78
  516. package/dist/react-native/chunks/chunk-PB2YXVQW.mjs +0 -29
  517. package/dist/react-native/chunks/chunk-PDRWWPKV.mjs +0 -2532
  518. package/dist/react-native/chunks/chunk-PJHAB5ZY.mjs +0 -79
  519. package/dist/react-native/chunks/chunk-POPDAGH6.mjs +0 -2636
  520. package/dist/react-native/chunks/chunk-PSWKQVVT.mjs +0 -9
  521. package/dist/react-native/chunks/chunk-QUKQNI3H.mjs +0 -647
  522. package/dist/react-native/chunks/chunk-RDWG33MM.mjs +0 -79
  523. package/dist/react-native/chunks/chunk-SK2PWYDH.mjs +0 -654
  524. package/dist/react-native/chunks/chunk-SUPXRTMD.mjs +0 -96
  525. package/dist/react-native/chunks/chunk-TP6KCKER.mjs +0 -63
  526. package/dist/react-native/chunks/chunk-U4KSKA4Z.mjs +0 -23
  527. package/dist/react-native/chunks/chunk-UNUFZ2QY.mjs +0 -68
  528. package/dist/react-native/chunks/chunk-VWUDIOT6.mjs +0 -218
  529. package/dist/react-native/chunks/chunk-WBYQRHDY.mjs +0 -86
  530. package/dist/react-native/chunks/chunk-YH7QY657.mjs +0 -288
  531. package/dist/react-native/chunks/chunk-YZW4CHM6.mjs +0 -562
  532. package/dist/react-native/chunks/chunk-ZLWVW734.mjs +0 -100
  533. package/dist/react-native/chunks/chunk-ZXZFN7FI.mjs +0 -432
  534. package/dist/react-native/chunks/chunk-ZZT7CEN7.mjs +0 -92
  535. package/dist/react-native/chunks/cold-module-KVZYUGRY.mjs +0 -772
  536. package/dist/react-native/chunks/durability-wiring-34OYO32E.mjs +0 -4942
  537. package/dist/react-native/chunks/engine-hooks-M7JV46NH.mjs +0 -30
  538. package/dist/react-native/chunks/gzip.react-native-HLEPDKZ3.mjs +0 -3
  539. package/dist/react-native/chunks/import-H6AQREWI.mjs +0 -32
  540. package/dist/react-native/chunks/methods-6W5U4C3H.mjs +0 -30
  541. package/dist/react-native/chunks/module-LBZPGOWH.mjs +0 -36
  542. package/dist/react-native/chunks/operations-GNRMD6EX.mjs +0 -5
  543. package/dist/react-native/chunks/phrase-module-QK22HSQ2.mjs +0 -329
  544. package/dist/react-native/chunks/pool-JR3NJCAF.mjs +0 -297
  545. package/dist/react-native/chunks/release-D7ZTIANM.mjs +0 -33
  546. package/dist/react-native/chunks/restore-queue-ZZX54AH7.mjs +0 -55
  547. package/dist/react-native/chunks/retention-EW4TTDFB.mjs +0 -223
  548. package/dist/react-native/chunks/snapshot-REYVIN3X.mjs +0 -975
  549. package/dist/react-native/chunks/start-BQK6KN3R.mjs +0 -38
  550. package/dist/react-native/chunks/sync-state-PASCIHHT.mjs +0 -15
  551. package/dist/react-native/chunks/write-FQAYCZF5.mjs +0 -207
  552. package/dist/release-BH3DKW3T.mjs +0 -33
  553. package/dist/restore-hooks-CDERDEF4.mjs +0 -153
  554. package/dist/restore-queue-7NNSTROA.mjs +0 -55
  555. package/dist/retention-QSVBBNRM.mjs +0 -66
  556. package/dist/runtime-COIUORCN.mjs +0 -177
  557. package/dist/snapshot-RH4NSKIZ.mjs +0 -782
  558. package/dist/start-MCKCOGIW.mjs +0 -66
  559. package/dist/sync-state-ZWHLAFLE.mjs +0 -15
  560. package/dist/thread-O4SBJJJS.mjs +0 -50
  561. package/dist/write-3FK7NG3Y.mjs +0 -232
  562. /package/dist/browser/{chunk-M3MQE2X7.mjs → digest-leaf-64IPRPZD.mjs} +0 -0
  563. /package/dist/browser/{chunk-JNOAKDUM.mjs → gzip-JF3S6PPT.mjs} +0 -0
  564. /package/dist/{chunk-ZXNNR73R.mjs → gzip-2UCZW2MM.mjs} +0 -0
@@ -1,1435 +0,0 @@
1
- import { MAX_LATITUDE_DEGREES, MAX_LONGITUDE_DEGREES } from './chunk-SQJWAIF4.mjs';
2
- import { PARTIAL_WORD_MIN_CODE_POINTS, PARTIAL_WORDS_ADDED_PER_QUERY, DEFAULT_FUZZY_PREFIX_LENGTH } from './chunk-FQBFZAWG.mjs';
3
- import { flattenSchema, encodeDocument } from './chunk-BU4SAIC4.mjs';
4
- import { fuzzyTermMatches } from './chunk-GES7U2PM.mjs';
5
- import { isWordIndexedBase, parseFieldType } from './chunk-I54T6CQP.mjs';
6
- import { encodeStringBlob } from './chunk-G6HRSGOU.mjs';
7
- import { DEFAULT_PATTERN_VALUE_LIMIT, isPlainObject, MAX_DOCUMENT_BYTES, MAX_DOCUMENT_NESTING_DEPTH, VECTOR_PATTERN } from './chunk-L5ORED7V.mjs';
8
- import { tokenize, resolveStopWords, transformToken, visitTokens, visitSurfaceSpellings } from './chunk-A4L7YTKX.mjs';
9
- import { EARLIER_RELEASE_MIN_M, MIN_M, MAX_M } from './chunk-ZXX5GZEX.mjs';
10
- import { NarsilError, ErrorCodes } from './chunk-MP7ABPTD.mjs';
11
- import { compareCodePoints, codePointCount, holdsUnpairedSurrogate, exceedsCodePoints } from './chunk-TBC3XUL2.mjs';
12
-
13
- // src/geo/coordinates.ts
14
- function isLatitude(value) {
15
- return value >= -MAX_LATITUDE_DEGREES && value <= MAX_LATITUDE_DEGREES;
16
- }
17
- function isLongitude(value) {
18
- return value >= -MAX_LONGITUDE_DEGREES && value <= MAX_LONGITUDE_DEGREES;
19
- }
20
-
21
- // src/schema/validator/field-values.ts
22
- function validateGeopoint(path, value) {
23
- if (!isPlainObject(value)) {
24
- throw new NarsilError(
25
- ErrorCodes.SCHEMA_INVALID_GEOPOINT,
26
- `Field "${path}" expected a geopoint object with lat and lon`,
27
- {
28
- field: path,
29
- received: Array.isArray(value) ? "array" : typeof value
30
- }
31
- );
32
- }
33
- if (typeof value.lat !== "number" || typeof value.lon !== "number" || Number.isNaN(value.lat) || Number.isNaN(value.lon)) {
34
- throw new NarsilError(ErrorCodes.SCHEMA_INVALID_GEOPOINT, `Field "${path}" geopoint requires numeric lat and lon`, {
35
- field: path,
36
- lat: Number.isNaN(value.lat) ? "NaN" : typeof value.lat,
37
- lon: Number.isNaN(value.lon) ? "NaN" : typeof value.lon
38
- });
39
- }
40
- if (!isLatitude(value.lat)) {
41
- throw new NarsilError(
42
- ErrorCodes.SCHEMA_INVALID_GEOPOINT,
43
- `Field "${path}" geopoint lat must be between -90 and 90`,
44
- {
45
- field: path,
46
- lat: value.lat
47
- }
48
- );
49
- }
50
- if (!isLongitude(value.lon)) {
51
- throw new NarsilError(
52
- ErrorCodes.SCHEMA_INVALID_GEOPOINT,
53
- `Field "${path}" geopoint lon must be between -180 and 180`,
54
- {
55
- field: path,
56
- lon: value.lon
57
- }
58
- );
59
- }
60
- }
61
- function validateVector(path, value, expectedDimension) {
62
- const isArray = Array.isArray(value);
63
- const isFloat32 = value instanceof Float32Array;
64
- if (!isArray && !isFloat32) {
65
- throw new NarsilError(
66
- ErrorCodes.DOC_VALIDATION_FAILED,
67
- `Field "${path}" expected a vector (Array or Float32Array)`,
68
- { field: path, received: typeof value }
69
- );
70
- }
71
- const arr = value;
72
- if (arr.length !== expectedDimension) {
73
- throw new NarsilError(
74
- ErrorCodes.DOC_VALIDATION_FAILED,
75
- `Field "${path}" expected vector of dimension ${expectedDimension}, got ${arr.length}`,
76
- { field: path, expected: expectedDimension, received: arr.length }
77
- );
78
- }
79
- for (let i = 0; i < arr.length; i++) {
80
- if (typeof arr[i] !== "number" || !Number.isFinite(arr[i])) {
81
- throw new NarsilError(
82
- ErrorCodes.DOC_VALIDATION_FAILED,
83
- `Field "${path}" vector element at index ${i} is not a valid number`,
84
- { field: path, index: i, value: arr[i] }
85
- );
86
- }
87
- }
88
- }
89
- function validateTypedArray(path, value, elementType) {
90
- if (!Array.isArray(value)) {
91
- throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `Field "${path}" expected an array`, {
92
- field: path,
93
- received: typeof value
94
- });
95
- }
96
- for (let i = 0; i < value.length; i++) {
97
- const el = value[i];
98
- if (typeof el !== elementType) {
99
- throw new NarsilError(
100
- ErrorCodes.DOC_VALIDATION_FAILED,
101
- `Field "${path}" array element at index ${i} expected ${elementType}, got ${typeof el}`,
102
- { field: path, index: i, expected: elementType, received: typeof el }
103
- );
104
- }
105
- if (elementType === "number" && !Number.isFinite(el)) {
106
- throw new NarsilError(
107
- ErrorCodes.DOC_VALIDATION_FAILED,
108
- `Field "${path}" array element at index ${i} is ${String(el)}, while a number field holds finite numbers alone`,
109
- { field: path, index: i }
110
- );
111
- }
112
- }
113
- }
114
- function validatePatternValue(path, value, patternValueLimit, index) {
115
- if (!exceedsCodePoints(value, patternValueLimit)) return;
116
- const subject = index === void 0 ? `The value of field "${path}"` : `Element ${index} of field "${path}"`;
117
- throw new NarsilError(
118
- ErrorCodes.DOC_VALIDATION_FAILED,
119
- `${subject} is longer than ${patternValueLimit} code points, which is the pattern value limit of this index`,
120
- { field: path, limit: patternValueLimit, ...index === void 0 ? {} : { index } }
121
- );
122
- }
123
- function validateFieldValue(path, value, type, patternValueLimit) {
124
- switch (type.base) {
125
- case "string":
126
- case "verbatim":
127
- if (typeof value !== "string") {
128
- throw new NarsilError(
129
- ErrorCodes.DOC_VALIDATION_FAILED,
130
- `Field "${path}" expected string, got ${typeof value}`,
131
- {
132
- field: path,
133
- expected: "string",
134
- received: typeof value
135
- }
136
- );
137
- }
138
- if (type.pattern) validatePatternValue(path, value, patternValueLimit);
139
- return;
140
- case "number":
141
- if (typeof value !== "number" || !Number.isFinite(value)) {
142
- throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `Field "${path}" expected a finite number`, {
143
- field: path,
144
- expected: "number",
145
- received: typeof value === "number" ? String(value) : typeof value
146
- });
147
- }
148
- return;
149
- case "boolean":
150
- if (typeof value !== "boolean") {
151
- throw new NarsilError(
152
- ErrorCodes.DOC_VALIDATION_FAILED,
153
- `Field "${path}" expected boolean, got ${typeof value}`,
154
- {
155
- field: path,
156
- expected: "boolean",
157
- received: typeof value
158
- }
159
- );
160
- }
161
- return;
162
- case "enum":
163
- if (typeof value !== "string") {
164
- throw new NarsilError(
165
- ErrorCodes.DOC_VALIDATION_FAILED,
166
- `Field "${path}" expected enum (string), got ${typeof value}`,
167
- {
168
- field: path,
169
- expected: "enum",
170
- received: typeof value
171
- }
172
- );
173
- }
174
- return;
175
- case "geopoint":
176
- validateGeopoint(path, value);
177
- return;
178
- case "string[]":
179
- case "verbatim[]":
180
- validateTypedArray(path, value, "string");
181
- if (type.pattern) {
182
- const elements = value;
183
- for (let i = 0; i < elements.length; i++) validatePatternValue(path, elements[i], patternValueLimit, i);
184
- }
185
- return;
186
- case "number[]":
187
- validateTypedArray(path, value, "number");
188
- return;
189
- case "boolean[]":
190
- validateTypedArray(path, value, "boolean");
191
- return;
192
- case "enum[]":
193
- validateTypedArray(path, value, "string");
194
- return;
195
- case "vector":
196
- validateVector(path, value, type.dimension);
197
- return;
198
- }
199
- }
200
-
201
- // src/schema/validator/storable.ts
202
- var RESERVED_OBJECT_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
203
- var UNPAIRED_SURROGATE_REASON = "holds an unpaired surrogate, the half of a character such as an emoji whose other half is missing, so the engine cannot store it as UTF-8";
204
- function reject(path, reason) {
205
- throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `Field "${path === "" ? "(document)" : path}" ${reason}`, {
206
- field: path
207
- });
208
- }
209
- function isPlainObject2(value) {
210
- const proto = Object.getPrototypeOf(value);
211
- return proto === Object.prototype || proto === null;
212
- }
213
- function walkStorable(value, path, depth, ancestors, skip) {
214
- if (value === null || value === void 0) return;
215
- const kind = typeof value;
216
- if (kind === "string") {
217
- if (holdsUnpairedSurrogate(value)) reject(path, UNPAIRED_SURROGATE_REASON);
218
- return;
219
- }
220
- if (kind === "boolean" || kind === "number") return;
221
- if (kind === "bigint" || kind === "symbol" || kind === "function") {
222
- reject(path, `holds a ${kind}, which cannot be stored or recovered`);
223
- }
224
- const container = value;
225
- if (container instanceof Date) {
226
- if (Number.isNaN(container.getTime())) reject(path, "holds an invalid date, which the engine cannot store");
227
- return;
228
- }
229
- if (container instanceof Uint8Array) return;
230
- const isArray = Array.isArray(container);
231
- if (!isArray && !isPlainObject2(container)) {
232
- reject(
233
- path,
234
- "holds a value that does not survive storage; use plain objects, arrays, strings, numbers, booleans, dates, or Uint8Array bytes"
235
- );
236
- }
237
- if (depth >= MAX_DOCUMENT_NESTING_DEPTH) {
238
- reject(path, `nests deeper than ${MAX_DOCUMENT_NESTING_DEPTH} levels`);
239
- }
240
- if (ancestors.has(container)) {
241
- reject(path, "refers back to one of its own ancestors");
242
- }
243
- ancestors.add(container);
244
- if (isArray) {
245
- const items = container;
246
- for (let i = 0; i < items.length; i++) {
247
- walkStorable(items[i], `${path}[${i}]`, depth + 1, ancestors, skip);
248
- }
249
- } else {
250
- const record = container;
251
- for (const key of Object.keys(record)) {
252
- const keyPath = path === "" ? key : `${path}.${key}`;
253
- if (RESERVED_OBJECT_KEYS.has(key)) {
254
- reject(keyPath, "uses a reserved object key");
255
- }
256
- if (holdsUnpairedSurrogate(key)) reject(keyPath, `has a name that ${UNPAIRED_SURROGATE_REASON}`);
257
- if (skip.has(keyPath)) continue;
258
- walkStorable(record[key], keyPath, depth + 1, ancestors, skip);
259
- }
260
- }
261
- ancestors.delete(container);
262
- }
263
- function assertStorableDocument(document, skipFieldPaths) {
264
- walkStorable(document, "", 0, /* @__PURE__ */ new Set(), skipFieldPaths ?? /* @__PURE__ */ new Set());
265
- }
266
-
267
- // src/schema/validator/document.ts
268
- var vectorPathCache = /* @__PURE__ */ new WeakMap();
269
- function vectorFieldPaths(schema) {
270
- let paths = vectorPathCache.get(schema);
271
- if (paths !== void 0) return paths;
272
- paths = /* @__PURE__ */ new Set();
273
- const collect = (level, prefix) => {
274
- for (const [field, type] of Object.entries(level)) {
275
- const path = prefix === "" ? field : `${prefix}.${field}`;
276
- if (typeof type === "string" && VECTOR_PATTERN.test(type)) {
277
- paths?.add(path);
278
- } else if (isPlainObject(type)) {
279
- collect(type, path);
280
- }
281
- }
282
- };
283
- collect(schema, "");
284
- vectorPathCache.set(schema, paths);
285
- return paths;
286
- }
287
- var parsedLevelCache = /* @__PURE__ */ new WeakMap();
288
- function parsedLevel(schema, prefix) {
289
- let entries = parsedLevelCache.get(schema);
290
- if (entries !== void 0) return entries;
291
- entries = Object.entries(schema).map(([field, type]) => {
292
- if (isPlainObject(type)) return { field, nested: type, type: null };
293
- const path = prefix ? `${prefix}.${field}` : field;
294
- return { field, nested: null, type: parseFieldType(type, path) };
295
- });
296
- parsedLevelCache.set(schema, entries);
297
- return entries;
298
- }
299
- function validateDocumentFields(doc, schema, prefix, patternValueLimit) {
300
- for (const { field, nested, type } of parsedLevel(schema, prefix)) {
301
- const value = doc[field];
302
- if (value === void 0 || value === null) continue;
303
- const path = prefix ? `${prefix}.${field}` : field;
304
- if (nested !== null) {
305
- if (!isPlainObject(value)) {
306
- throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, `Field "${path}" expected an object`, {
307
- field: path,
308
- received: Array.isArray(value) ? "array" : typeof value
309
- });
310
- }
311
- validateDocumentFields(value, nested, path, patternValueLimit);
312
- continue;
313
- }
314
- if (type !== null) validateFieldValue(path, value, type, patternValueLimit);
315
- }
316
- }
317
- function validateDocument(document, schema, patternValueLimit = DEFAULT_PATTERN_VALUE_LIMIT) {
318
- if (!isPlainObject(document)) {
319
- throw new NarsilError(ErrorCodes.DOC_VALIDATION_FAILED, "Document must be a plain object", {
320
- received: typeof document
321
- });
322
- }
323
- requireIdFieldKey(document);
324
- assertStorableDocument(document, vectorFieldPaths(schema));
325
- validateDocumentFields(document, schema, "", patternValueLimit);
326
- }
327
- function requireIdFieldKey(document) {
328
- if (!Object.hasOwn(document, "id")) return;
329
- const id = document.id;
330
- if (typeof id === "string" && id.length > 0) return;
331
- throw new NarsilError(
332
- ErrorCodes.DOC_VALIDATION_FAILED,
333
- `Field "id" holds ${typeof id === "string" ? "an empty string" : id === null ? "null" : `a ${typeof id}`}, while the engine stores a document under its id field, so that field must hold a non-empty string`,
334
- { field: "id", received: id === null ? "null" : typeof id }
335
- );
336
- }
337
- function collectExtraFields(doc, schema, prefix, extras) {
338
- for (const key of Object.keys(doc)) {
339
- if (key === "id") continue;
340
- const path = prefix ? `${prefix}.${key}` : key;
341
- if (!Object.hasOwn(schema, key)) {
342
- extras.push(path);
343
- continue;
344
- }
345
- const schemaType = schema[key];
346
- if (isPlainObject(schemaType) && isPlainObject(doc[key])) {
347
- collectExtraFields(doc[key], schemaType, path, extras);
348
- }
349
- }
350
- }
351
- function validateDocumentStrict(document, schema) {
352
- const extras = [];
353
- collectExtraFields(document, schema, "", extras);
354
- if (extras.length > 0) {
355
- throw new NarsilError(
356
- ErrorCodes.DOC_VALIDATION_FAILED,
357
- `Document contains fields not defined in schema: ${extras.join(", ")}`,
358
- { extraFields: extras }
359
- );
360
- }
361
- }
362
- function resolveNestedValue(document, path) {
363
- if (!path.includes(".")) return document[path];
364
- const segments = path.split(".");
365
- let current = document;
366
- for (const segment of segments) {
367
- if (current === null || current === void 0 || typeof current !== "object") return void 0;
368
- current = current[segment];
369
- }
370
- return current;
371
- }
372
- function validateRequiredFields(document, required) {
373
- if (required.length === 0) return;
374
- for (const field of required) {
375
- const value = resolveNestedValue(document, field);
376
- if (value === void 0 || value === null) {
377
- throw new NarsilError(ErrorCodes.DOC_MISSING_REQUIRED_FIELD, `Document is missing required field "${field}"`, {
378
- field
379
- });
380
- }
381
- }
382
- }
383
-
384
- // src/schema/validator/document-size.ts
385
- var LARGEST_HEADER_BYTES = 5;
386
- var LARGEST_NUMBER_BYTES = 9;
387
- var LARGEST_TIMESTAMP_BYTES = 15;
388
- var LARGEST_UTF8_BYTES_PER_UNIT = 3;
389
- function upperBoundBytes(value, budget, depth) {
390
- if (value === null || value === void 0 || typeof value === "boolean") return 1;
391
- if (typeof value === "number") return LARGEST_NUMBER_BYTES;
392
- if (typeof value === "string") return LARGEST_HEADER_BYTES + value.length * LARGEST_UTF8_BYTES_PER_UNIT;
393
- if (value instanceof Date) return LARGEST_TIMESTAMP_BYTES;
394
- if (ArrayBuffer.isView(value)) return LARGEST_HEADER_BYTES + value.byteLength;
395
- if (typeof value !== "object" || depth > MAX_DOCUMENT_NESTING_DEPTH) return LARGEST_NUMBER_BYTES;
396
- let total = LARGEST_HEADER_BYTES;
397
- if (Array.isArray(value)) {
398
- for (const item of value) {
399
- total += upperBoundBytes(item, budget - total, depth + 1);
400
- if (total > budget) return total;
401
- }
402
- return total;
403
- }
404
- const record = value;
405
- for (const key of Object.keys(record)) {
406
- total += LARGEST_HEADER_BYTES + key.length * LARGEST_UTF8_BYTES_PER_UNIT;
407
- total += upperBoundBytes(record[key], budget - total, depth + 1);
408
- if (total > budget) return total;
409
- }
410
- return total;
411
- }
412
- function messagePackUpperBoundBytes(value) {
413
- return upperBoundBytes(value, Number.POSITIVE_INFINITY, 0);
414
- }
415
- function encodedBytesOf(document) {
416
- try {
417
- return encodeDocument(document).byteLength;
418
- } catch {
419
- return null;
420
- }
421
- }
422
- function requireDocumentWithinSizeLimit(document) {
423
- if (upperBoundBytes(document, MAX_DOCUMENT_BYTES, 0) <= MAX_DOCUMENT_BYTES) return;
424
- const encodedBytes = encodedBytesOf(document);
425
- if (encodedBytes === null || encodedBytes <= MAX_DOCUMENT_BYTES) return;
426
- throw new NarsilError(
427
- ErrorCodes.DOC_VALIDATION_FAILED,
428
- `The document takes ${encodedBytes} bytes as MessagePack, vector values included, but a document may take at most ${MAX_DOCUMENT_BYTES}`,
429
- { bytes: encodedBytes, maximum: MAX_DOCUMENT_BYTES }
430
- );
431
- }
432
-
433
- // src/schema/validator/vector-promotion.ts
434
- var QUANTIZATION_MODES = /* @__PURE__ */ new Set(["osq8", "osq4", "osq2", "osq1", "none"]);
435
- var STORAGE_MODES = /* @__PURE__ */ new Set(["memory", "disk"]);
436
- function fail(message, details) {
437
- throw new NarsilError(ErrorCodes.CONFIG_INVALID, message, details);
438
- }
439
- function isPositiveInteger(value) {
440
- return Number.isInteger(value) && value >= 1;
441
- }
442
- function isQuantizationMode(value) {
443
- return typeof value === "string" && QUANTIZATION_MODES.has(value);
444
- }
445
- function isStorageMode(value) {
446
- return typeof value === "string" && STORAGE_MODES.has(value);
447
- }
448
- function validateVectorStorage(config, filesystemDurability) {
449
- if (config?.storage === "disk" && !filesystemDurability) {
450
- fail("vectorPromotion.storage 'disk' needs filesystem durability, because a checkpoint file holds the vectors", {
451
- storage: config.storage
452
- });
453
- }
454
- }
455
- function validateTextStorage(textStorage, filesystemDurability) {
456
- if (textStorage === void 0 || textStorage === "memory" || textStorage === "disk" && filesystemDurability) return;
457
- fail("textStorage must be 'memory', or 'disk' with filesystem durability", { textStorage });
458
- }
459
- function raiseEarlierReleaseGraphSetting(config) {
460
- if (typeof config !== "object" || config === null) return config;
461
- const hnsw = config.hnswConfig;
462
- if (typeof hnsw !== "object" || hnsw === null) return config;
463
- if (hnsw.m !== EARLIER_RELEASE_MIN_M) return config;
464
- return { ...config, hnswConfig: { ...hnsw, m: MIN_M } };
465
- }
466
- function validateVectorPromotion(config) {
467
- if (config === void 0) return;
468
- if (config.threshold !== void 0 && !isPositiveInteger(config.threshold)) {
469
- fail("vectorPromotion.threshold must be a positive integer", { threshold: config.threshold });
470
- }
471
- const quantization = config.quantization;
472
- if (quantization !== void 0 && !isQuantizationMode(quantization)) {
473
- fail("vectorPromotion.quantization must be 'osq8', 'osq4', 'osq2', 'osq1', or 'none'", { quantization });
474
- }
475
- const storage = config.storage;
476
- if (storage !== void 0 && !isStorageMode(storage)) {
477
- fail("vectorPromotion.storage must be 'memory' or 'disk'", { storage });
478
- }
479
- const hnsw = config.hnswConfig;
480
- if (hnsw === void 0) return;
481
- if (hnsw.m !== void 0 && (!Number.isInteger(hnsw.m) || hnsw.m < MIN_M || hnsw.m > MAX_M)) {
482
- fail(`vectorPromotion.hnswConfig.m must be a whole number from ${MIN_M} to ${MAX_M}`, { m: hnsw.m });
483
- }
484
- if (hnsw.efConstruction !== void 0 && !isPositiveInteger(hnsw.efConstruction)) {
485
- fail("vectorPromotion.hnswConfig.efConstruction must be a positive integer", {
486
- efConstruction: hnsw.efConstruction
487
- });
488
- }
489
- const metric = hnsw.metric;
490
- if (metric !== void 0 && metric !== "cosine" && metric !== "dotProduct" && metric !== "euclidean") {
491
- fail("vectorPromotion.hnswConfig.metric must be 'cosine', 'dotProduct', or 'euclidean'", { metric });
492
- }
493
- }
494
-
495
- // src/core/partition/utils.ts
496
- function getOrCreateFieldNameIndex(table, fieldName) {
497
- const existing = table.indexMap.get(fieldName);
498
- if (existing !== void 0) return existing;
499
- const idx = table.names.length;
500
- table.names.push(fieldName);
501
- table.indexMap.set(fieldName, idx);
502
- return idx;
503
- }
504
- var VECTOR_PATTERN2 = /^vector\[(\d+)]$/;
505
- function getNestedValue(obj, path) {
506
- const parts = path.split(".");
507
- let current = obj;
508
- for (let i = 0; i < parts.length; i++) {
509
- if (current === null || current === void 0 || typeof current !== "object") return void 0;
510
- if (!Object.hasOwn(current, parts[i])) return void 0;
511
- current = current[parts[i]];
512
- }
513
- return current;
514
- }
515
- function stringArraysEqual(a, b) {
516
- if (a === b) return true;
517
- if (!a || !b) return false;
518
- if (a.length !== b.length) return false;
519
- for (let i = 0; i < a.length; i++) {
520
- if (a[i] !== b[i]) return false;
521
- }
522
- return true;
523
- }
524
- function textFieldsChanged(oldDoc, newDoc, fields) {
525
- for (const { path, base } of fields) {
526
- if (!isWordIndexedBase(base)) continue;
527
- const oldVal = getNestedValue(oldDoc, path);
528
- const newVal = getNestedValue(newDoc, path);
529
- if (base === "string") {
530
- if (oldVal !== newVal) return true;
531
- } else {
532
- if (!stringArraysEqual(oldVal, newVal)) return true;
533
- }
534
- }
535
- return false;
536
- }
537
- function parseVectorDimension(fieldType) {
538
- const match = VECTOR_PATTERN2.exec(fieldType);
539
- return match ? Number.parseInt(match[1], 10) : null;
540
- }
541
- function tokenizeOptions(options) {
542
- return {
543
- stem: true,
544
- removeStopWords: true,
545
- collectSurfaces: options?.collectSurfaces === true,
546
- stopWordOverride: options?.stopWordOverride,
547
- customTokenizer: options?.customTokenizer
548
- };
549
- }
550
- function getFlatSchema(state, schema) {
551
- if (state.lastSchemaRef === schema && state.flatSchemaCache) return state.flatSchemaCache;
552
- state.flatSchemaCache = flattenSchema(schema);
553
- state.lastSchemaRef = schema;
554
- return state.flatSchemaCache;
555
- }
556
-
557
- // src/core/partition/suggestions.ts
558
- function verbatimOccurrences(state, token) {
559
- const postingList = state.invertedIdx.lookup(token);
560
- if (!postingList) return 0;
561
- const derived = postingList.totalTermFrequency - state.surfaceRegistry.stemChangedTotalFor(token);
562
- return derived > 0 ? derived : 0;
563
- }
564
- function suggestDisplayTerms(state, surfacePrefix, stemmedPrefix, limit) {
565
- if (limit <= 0 || surfacePrefix.length === 0) return [];
566
- const groups = /* @__PURE__ */ new Map();
567
- for (const candidate of state.surfaceRegistry.candidatesForPrefix(surfacePrefix)) {
568
- const postingList = state.invertedIdx.lookup(candidate.token);
569
- if (!postingList || postingList.docIdSet.size === 0) continue;
570
- let group = groups.get(candidate.token);
571
- if (!group) {
572
- group = { documentFrequency: postingList.docIdSet.size, surfaces: [] };
573
- groups.set(candidate.token, group);
574
- }
575
- group.surfaces.push({ surface: candidate.surface, occurrences: candidate.occurrences });
576
- }
577
- const termPrefixes = state.surfaceRegistry.size() === 0 && stemmedPrefix !== surfacePrefix && stemmedPrefix.length > 0 ? [surfacePrefix, stemmedPrefix] : [surfacePrefix];
578
- for (const prefix of termPrefixes) {
579
- for (const suggestion of state.invertedIdx.prefixSearch(prefix, Number.MAX_SAFE_INTEGER)) {
580
- const occurrences = verbatimOccurrences(state, suggestion.term);
581
- if (occurrences === 0) continue;
582
- let group = groups.get(suggestion.term);
583
- if (!group) {
584
- group = { documentFrequency: suggestion.documentFrequency, surfaces: [] };
585
- groups.set(suggestion.term, group);
586
- } else if (group.surfaces.some((s) => s.surface === suggestion.term)) {
587
- continue;
588
- }
589
- group.surfaces.push({ surface: suggestion.term, occurrences });
590
- }
591
- }
592
- const results = [];
593
- for (const [token, group] of groups) {
594
- results.push({ token, documentFrequency: group.documentFrequency, surfaces: group.surfaces });
595
- }
596
- results.sort((a, b) => b.documentFrequency - a.documentFrequency || compareCodePoints(a.token, b.token));
597
- if (results.length > limit) results.length = limit;
598
- return results;
599
- }
600
- function partitionDocumentFrequency(subs, token) {
601
- let documents = 0;
602
- for (const sub of subs) documents += sub.invertedIdx.documentFrequency(token);
603
- return documents;
604
- }
605
- function expandTermPrefix(subs, surfacePrefix, stemmedToken, maxExpansions) {
606
- if (maxExpansions <= 0 || surfacePrefix.length === 0) return [];
607
- const candidates = /* @__PURE__ */ new Set();
608
- const holdsSurfaceForms = subs.some((sub) => sub.surfaceRegistry.size() > 0);
609
- const termPrefixes = !holdsSurfaceForms && stemmedToken !== surfacePrefix && stemmedToken.length > 0 ? [surfacePrefix, stemmedToken] : [surfacePrefix];
610
- for (const sub of subs) {
611
- for (const candidate of sub.surfaceRegistry.candidatesForPrefix(surfacePrefix)) candidates.add(candidate.token);
612
- for (const prefix of termPrefixes) {
613
- for (const suggestion of sub.invertedIdx.prefixSearch(prefix, Number.MAX_SAFE_INTEGER)) {
614
- if (candidates.has(suggestion.term)) continue;
615
- if (verbatimOccurrences(sub, suggestion.term) > 0) candidates.add(suggestion.term);
616
- }
617
- }
618
- }
619
- const ranked = [];
620
- for (const token of candidates) {
621
- const documents = partitionDocumentFrequency(subs, token);
622
- if (documents > 0) ranked.push({ token, documents });
623
- }
624
- ranked.sort((a, b) => b.documents - a.documents || compareCodePoints(a.token, b.token));
625
- if (ranked.length > maxExpansions) ranked.length = maxExpansions;
626
- return ranked.map((entry) => entry.token);
627
- }
628
-
629
- // src/core/partition/partial-words/text.ts
630
- var encoder = new TextEncoder();
631
- var LAST_BASIC_PLANE_CODE_POINT = 65535;
632
- var BASIC_PLANE_SIZE = 65536;
633
- var UTF8_CONTINUATION_MASK = 192;
634
- var UTF8_CONTINUATION_BITS = 128;
635
- function codePointsOf(text) {
636
- const points = [];
637
- let index = 0;
638
- while (index < text.length) {
639
- const point = text.codePointAt(index) ?? text.charCodeAt(index);
640
- points.push(point);
641
- index += point > LAST_BASIC_PLANE_CODE_POINT ? 2 : 1;
642
- }
643
- return points;
644
- }
645
- function runKeyAt(points, at) {
646
- return String.fromCodePoint(points[at], points[at + 1], points[at + 2]);
647
- }
648
- function packedRunKeyAt(points, at) {
649
- const first = points[at];
650
- const second = points[at + 1];
651
- const third = points[at + 2];
652
- if ((first | second | third) > LAST_BASIC_PLANE_CODE_POINT) return String.fromCodePoint(first, second, third);
653
- return first * BASIC_PLANE_SIZE * BASIC_PLANE_SIZE + second * BASIC_PLANE_SIZE + third;
654
- }
655
- function partialWordProbe(text) {
656
- return { text, codePoints: codePointsOf(text), utf8: encoder.encode(text) };
657
- }
658
- function utf8Contains(haystack, start, end, needle) {
659
- const last = end - needle.length;
660
- for (let from = start; from <= last; from++) {
661
- let at = 0;
662
- while (at < needle.length && haystack[from + at] === needle[at]) at++;
663
- if (at === needle.length) return true;
664
- }
665
- return false;
666
- }
667
- function utf8CodePointCount(bytes, start, end) {
668
- let count = 0;
669
- for (let at = start; at < end; at++) {
670
- if ((bytes[at] & UTF8_CONTINUATION_MASK) !== UTF8_CONTINUATION_BITS) count++;
671
- }
672
- return count;
673
- }
674
-
675
- // src/core/partition/partial-words/expansion.ts
676
- function excludedFromRequest(request, token) {
677
- if (token === request.ownToken) return true;
678
- return request.tolerance > 0 && fuzzyTermMatches(request.ownToken, token, request.tolerance, request.prefixLength);
679
- }
680
- function addedWordsFor(subs, readers, request) {
681
- if (request.share <= 0) return [];
682
- const probe = partialWordProbe(request.written);
683
- const shortestSpelling = /* @__PURE__ */ new Map();
684
- for (const reader of readers) {
685
- reader.forEachContaining(probe, (token, spellingLength) => {
686
- const known = shortestSpelling.get(token);
687
- if (known === void 0 || spellingLength < known) shortestSpelling.set(token, spellingLength);
688
- });
689
- }
690
- const ranked = [];
691
- for (const [token, spellingLength] of shortestSpelling) {
692
- if (excludedFromRequest(request, token)) continue;
693
- const documents = partitionDocumentFrequency(subs, token);
694
- if (documents > 0) ranked.push({ token, documents, spellingLength });
695
- }
696
- ranked.sort((a, b) => b.documents - a.documents || compareCodePoints(a.token, b.token));
697
- if (ranked.length > request.share) ranked.length = request.share;
698
- const writtenLength = probe.codePoints.length;
699
- return ranked.map((word) => ({ token: word.token, factor: writtenLength / word.spellingLength }));
700
- }
701
- function expandPartialWords(subs, analysis, requests) {
702
- const readers = [];
703
- for (const sub of subs) {
704
- const reader = sub.partialWords.readerFor(analysis);
705
- if (reader !== null) readers.push(reader);
706
- }
707
- return requests.map((request) => readers.length === 0 ? [] : addedWordsFor(subs, readers, request));
708
- }
709
-
710
- // src/core/partition/partial-words/constants.ts
711
- var PARTIAL_WORD_RUN_CODE_POINTS = 3;
712
- var GROWING_PARTIAL_ENTRY_BYTES = 104;
713
- var GROWING_PARTIAL_PENDING_ENTRY_BYTES = 8;
714
- var GROWING_PARTIAL_PENDING_ENTRIES_PER_ENTRY = 2;
715
- var GROWING_PARTIAL_RUN_BYTES = 120;
716
- var GROWING_PARTIAL_RUN_MEMBER_BYTES = 24;
717
- var FROZEN_PARTIAL_REMOVED_ENTRY_BYTES = 48;
718
-
719
- // src/core/partition/partial-words/spellings.ts
720
- var LAST_BASIC_PLANE_CODE_POINT2 = 65535;
721
- function codePointCountOf(text) {
722
- let count = 0;
723
- for (let index = 0; index < text.length; count++) {
724
- index += (text.codePointAt(index) ?? 0) > LAST_BASIC_PLANE_CODE_POINT2 ? 2 : 1;
725
- }
726
- return count;
727
- }
728
- function holdsRun(spelling) {
729
- if (spelling.length > 2 * PARTIAL_WORD_RUN_CODE_POINTS) return true;
730
- if (spelling.length <= PARTIAL_WORD_RUN_CODE_POINTS) return false;
731
- return codePointCountOf(spelling) > PARTIAL_WORD_RUN_CODE_POINTS;
732
- }
733
- function countSpelling(counts, token, spelling, change) {
734
- if (!holdsRun(spelling)) return;
735
- let byToken = counts.get(token);
736
- if (byToken === void 0) {
737
- if (change <= 0) return;
738
- byToken = /* @__PURE__ */ new Map();
739
- counts.set(token, byToken);
740
- }
741
- const next = (byToken.get(spelling) ?? 0) + change;
742
- if (next > 0) {
743
- byToken.set(spelling, next);
744
- return;
745
- }
746
- byToken.delete(spelling);
747
- if (byToken.size === 0) counts.delete(token);
748
- }
749
- function textsOf(value) {
750
- if (typeof value === "string") return [value];
751
- if (!Array.isArray(value)) return [];
752
- return value.filter((element) => typeof element === "string");
753
- }
754
- function visitFieldTexts(document, fields, visit) {
755
- for (const field of fields) {
756
- for (const text of textsOf(getNestedValue(document, field))) visit(text);
757
- }
758
- }
759
- function visitDocumentSpellings(document, analysis, visit) {
760
- const tokenizing = { ...tokenizeOptions(analysis.options), collectSurfaces: true };
761
- const visitOccurrence = (token, _position, surface) => {
762
- visit(token, surface ?? token);
763
- };
764
- visitFieldTexts(document, analysis.fields, (text) => visitTokens(text, analysis.language, tokenizing, visitOccurrence));
765
- }
766
- function visitDocumentSurfaceSpellings(document, analysis, visit) {
767
- if (analysis.options?.customTokenizer !== void 0) return;
768
- visitFieldTexts(document, analysis.fields, (text) => visitSurfaceSpellings(text, analysis.language, visit));
769
- }
770
- function countDocumentSpellings(counts, document, analysis, direction) {
771
- visitDocumentSpellings(document, analysis, (token, spelling) => countSpelling(counts, token, spelling, direction));
772
- }
773
- function spellingCountsOf(documents, analysis) {
774
- const counts = /* @__PURE__ */ new Map();
775
- for (const document of documents) countDocumentSpellings(counts, document, analysis, 1);
776
- return counts;
777
- }
778
- function encodePartialSpellings(fields, counts) {
779
- const encoded = { fields: [...fields], tokens: [], spellings: [], counts: [] };
780
- for (const [token, byToken] of counts) {
781
- for (const [spelling, count] of byToken) {
782
- encoded.tokens.push(token);
783
- encoded.spellings.push(spelling);
784
- encoded.counts.push(count);
785
- }
786
- }
787
- return encoded;
788
- }
789
- function sameFields(left, right) {
790
- if (left.length !== right.length) return false;
791
- for (let at = 0; at < left.length; at++) {
792
- if (left[at] !== right[at]) return false;
793
- }
794
- return true;
795
- }
796
-
797
- // src/core/partition/partial-words/frozen-table.ts
798
- var decoder = new TextDecoder();
799
- function compareEntries(left, right) {
800
- return compareCodePoints(left.spelling, right.spelling) || left.tokenIndex - right.tokenIndex;
801
- }
802
- function orderedEntriesOf(source, tokenTable) {
803
- const entries = [];
804
- for (let at = 0; at < source.tokens.length; at++) {
805
- if (source.counts[at] <= 0) continue;
806
- const tokenIndex = tokenTable.find(source.tokens[at]);
807
- if (tokenIndex >= 0) entries.push({ spelling: source.spellings[at], tokenIndex, count: source.counts[at] });
808
- }
809
- entries.sort(compareEntries);
810
- const distinct = [];
811
- for (const entry of entries) {
812
- const last = distinct[distinct.length - 1];
813
- if (last !== void 0 && compareEntries(last, entry) === 0) last.count += entry.count;
814
- else distinct.push(entry);
815
- }
816
- return distinct;
817
- }
818
- function buildPartialWordTable(source, tokenTable) {
819
- const spellings = [];
820
- const spellingTokens = [];
821
- const spellingCounts = [];
822
- const runLists = /* @__PURE__ */ new Map();
823
- const addSpelling = (spelling, tokenIndex, count) => {
824
- const points = codePointsOf(spelling);
825
- if (points.length <= PARTIAL_WORD_RUN_CODE_POINTS) return;
826
- const entry = spellings.length;
827
- spellings.push(spelling);
828
- spellingTokens.push(tokenIndex);
829
- spellingCounts.push(count);
830
- for (let at = 0; at + PARTIAL_WORD_RUN_CODE_POINTS <= points.length; at++) {
831
- const key = runKeyAt(points, at);
832
- const list = runLists.get(key);
833
- if (list === void 0) runLists.set(key, [entry]);
834
- else if (list[list.length - 1] !== entry) list.push(entry);
835
- }
836
- };
837
- for (const entry of orderedEntriesOf(source, tokenTable)) addSpelling(entry.spelling, entry.tokenIndex, entry.count);
838
- const runKeys = [...runLists.keys()].sort(compareCodePoints);
839
- const runs = new Uint32Array(runKeys.length * PARTIAL_WORD_RUN_CODE_POINTS);
840
- const runOffsets = new Uint32Array(runKeys.length + 1);
841
- let memberCount = 0;
842
- for (const key of runKeys) memberCount += runLists.get(key)?.length ?? 0;
843
- const runEntries = new Uint32Array(memberCount);
844
- let cursor = 0;
845
- for (let run = 0; run < runKeys.length; run++) {
846
- const points = codePointsOf(runKeys[run]);
847
- runs.set(points, run * PARTIAL_WORD_RUN_CODE_POINTS);
848
- for (const entry of runLists.get(runKeys[run]) ?? []) runEntries[cursor++] = entry;
849
- runOffsets[run + 1] = cursor;
850
- }
851
- const spellingBlob = encodeStringBlob(spellings);
852
- return {
853
- fields: [...source.fields],
854
- spellings: spellingBlob.blob,
855
- spellingOffsets: spellingBlob.offsets,
856
- spellingTokens: Uint32Array.from(spellingTokens),
857
- spellingCounts: Uint32Array.from(spellingCounts),
858
- runs,
859
- runOffsets,
860
- runEntries
861
- };
862
- }
863
- function countTableSpellings(counts, table, tokenTable) {
864
- const { spellings, spellingOffsets, spellingTokens, spellingCounts } = table;
865
- for (let entry = 0; entry < spellingTokens.length; entry++) {
866
- const spelling = decoder.decode(spellings.subarray(spellingOffsets[entry], spellingOffsets[entry + 1]));
867
- countSpelling(counts, tokenTable.tokenAt(spellingTokens[entry]), spelling, spellingCounts[entry]);
868
- }
869
- }
870
- function findRun(runs, first, second, third) {
871
- let low = 0;
872
- let high = runs.length / PARTIAL_WORD_RUN_CODE_POINTS;
873
- while (low < high) {
874
- const middle = low + high >>> 1;
875
- const at = middle * PARTIAL_WORD_RUN_CODE_POINTS;
876
- const difference = runs[at] - first || runs[at + 1] - second || runs[at + 2] - third;
877
- if (difference === 0) return middle;
878
- if (difference < 0) low = middle + 1;
879
- else high = middle;
880
- }
881
- return -1;
882
- }
883
- function partialWordTableBytes(table) {
884
- return table.spellings.byteLength + table.spellingOffsets.byteLength + table.spellingTokens.byteLength + table.spellingCounts.byteLength + table.runs.byteLength + table.runOffsets.byteLength + table.runEntries.byteLength;
885
- }
886
- function readPartialWordTable(table, tokenTable, removedCounts) {
887
- const { spellings, spellingOffsets, spellingTokens, spellingCounts, runs, runOffsets, runEntries } = table;
888
- function narrowestRun(points) {
889
- let narrowest = -1;
890
- let narrowestLength = Number.POSITIVE_INFINITY;
891
- for (let at = 0; at + PARTIAL_WORD_RUN_CODE_POINTS <= points.length; at++) {
892
- const run = findRun(runs, points[at], points[at + 1], points[at + 2]);
893
- if (run < 0) return -1;
894
- const length = runOffsets[run + 1] - runOffsets[run];
895
- if (length < narrowestLength) {
896
- narrowest = run;
897
- narrowestLength = length;
898
- }
899
- }
900
- return narrowest;
901
- }
902
- return {
903
- forEachContaining(probe, visit) {
904
- if (probe.codePoints.length < PARTIAL_WORD_RUN_CODE_POINTS) return;
905
- const run = narrowestRun(probe.codePoints);
906
- if (run < 0) return;
907
- for (let member = runOffsets[run]; member < runOffsets[run + 1]; member++) {
908
- const entry = runEntries[member];
909
- const start = spellingOffsets[entry];
910
- const end = spellingOffsets[entry + 1];
911
- if (end - start <= probe.utf8.length) continue;
912
- if ((removedCounts.get(entry) ?? 0) >= spellingCounts[entry]) continue;
913
- if (!utf8Contains(spellings, start, end, probe.utf8)) continue;
914
- const length = utf8CodePointCount(spellings, start, end);
915
- if (length <= probe.codePoints.length) continue;
916
- visit(tokenTable.tokenAt(spellingTokens[entry]), length);
917
- }
918
- },
919
- entryOf(spelling) {
920
- const probe = partialWordProbe(spelling);
921
- if (probe.codePoints.length <= PARTIAL_WORD_RUN_CODE_POINTS) return -1;
922
- const run = narrowestRun(probe.codePoints);
923
- if (run < 0) return -1;
924
- let exhausted = -1;
925
- for (let member = runOffsets[run]; member < runOffsets[run + 1]; member++) {
926
- const entry = runEntries[member];
927
- const start = spellingOffsets[entry];
928
- const end = spellingOffsets[entry + 1];
929
- if (end - start !== probe.utf8.length || !utf8Contains(spellings, start, end, probe.utf8)) continue;
930
- if ((removedCounts.get(entry) ?? 0) < spellingCounts[entry]) return entry;
931
- if (exhausted < 0) exhausted = entry;
932
- }
933
- return exhausted;
934
- },
935
- bytes() {
936
- return partialWordTableBytes(table);
937
- }
938
- };
939
- }
940
-
941
- // src/core/partition/partial-words/frozen-slot.ts
942
- function tombstonedOrdinalsOf(documents) {
943
- let marks = null;
944
- for (let ordinal = 0; ordinal < documents.count; ordinal++) {
945
- if (!documents.isTombstoned(ordinal)) continue;
946
- marks ??= new Uint8Array(documents.count);
947
- marks[ordinal] = 1;
948
- }
949
- return marks;
950
- }
951
- function addCounts(target, source) {
952
- for (const [token, bySpelling] of source) {
953
- for (const [spelling, count] of bySpelling) countSpelling(target, token, spelling, count);
954
- }
955
- }
956
- function countRemovedSpellings(removed, document, analysis) {
957
- const count = (spelling) => {
958
- removed.set(spelling, (removed.get(spelling) ?? 0) + 1);
959
- };
960
- if (analysis.options?.customTokenizer !== void 0) {
961
- visitDocumentSpellings(document, analysis, (_token, spelling) => count(spelling));
962
- return;
963
- }
964
- visitDocumentSurfaceSpellings(document, analysis, count);
965
- }
966
- function unstemmedSpellingsOf(analysis) {
967
- const { language } = analysis;
968
- if (language.normalizer === void 0 || language.tokenizer?.normalizeDiacritics === true) return () => null;
969
- const stopWords = resolveStopWords(language, analysis.options?.stopWordOverride);
970
- return (spelling) => {
971
- if (stopWords.has(spelling)) return null;
972
- const normalized = transformToken(spelling, language, false, false);
973
- return normalized === spelling ? null : normalized;
974
- };
975
- }
976
- function subtractRemovedSpellings(counts, removed, analysis) {
977
- const tokenOf = /* @__PURE__ */ new Map();
978
- for (const [token, bySpelling] of counts) {
979
- for (const spelling of bySpelling.keys()) tokenOf.set(spelling, token);
980
- }
981
- const unstemmedSpelling = unstemmedSpellingsOf(analysis);
982
- for (const [spelling, count] of removed) {
983
- const stored = tokenOf.has(spelling) ? spelling : unstemmedSpelling(spelling) ?? spelling;
984
- const token = tokenOf.get(stored);
985
- if (token !== void 0) countSpelling(counts, token, stored, -count);
986
- }
987
- }
988
- function createFrozenPartialWordSlot(initial, tokenTable, documents) {
989
- let table = initial;
990
- let uncounted = null;
991
- let removedCounts = /* @__PURE__ */ new Map();
992
- let reader = initial === null ? null : readPartialWordTable(initial, tokenTable, removedCounts);
993
- let pendingRemovals = [];
994
- function isCounted(ordinal) {
995
- return uncounted === null || uncounted[ordinal] === 0;
996
- }
997
- function subtractPendingRemovals(current, analysis) {
998
- if (pendingRemovals.length === 0) return;
999
- const removed = /* @__PURE__ */ new Map();
1000
- for (const ordinal of pendingRemovals) countRemovedSpellings(removed, documents.documentAt(ordinal), analysis);
1001
- pendingRemovals = [];
1002
- const unstemmedSpelling = unstemmedSpellingsOf(analysis);
1003
- for (const [spelling, count] of removed) {
1004
- let entry = current.entryOf(spelling);
1005
- if (entry < 0) {
1006
- const fallback = unstemmedSpelling(spelling);
1007
- if (fallback !== null) entry = current.entryOf(fallback);
1008
- }
1009
- if (entry >= 0) removedCounts.set(entry, (removedCounts.get(entry) ?? 0) + count);
1010
- }
1011
- }
1012
- function rebuild(analysis) {
1013
- uncounted = tombstonedOrdinalsOf(documents);
1014
- const counts = /* @__PURE__ */ new Map();
1015
- for (let ordinal = 0; ordinal < documents.count; ordinal++) {
1016
- if (isCounted(ordinal)) countDocumentSpellings(counts, documents.documentAt(ordinal), analysis, 1);
1017
- }
1018
- const rebuilt = buildPartialWordTable(encodePartialSpellings(analysis.fields, counts), tokenTable);
1019
- table = rebuilt;
1020
- removedCounts = /* @__PURE__ */ new Map();
1021
- pendingRemovals = [];
1022
- const rebuiltReader = readPartialWordTable(rebuilt, tokenTable, removedCounts);
1023
- reader = rebuiltReader;
1024
- return rebuiltReader;
1025
- }
1026
- function correctionsAgainstTable(mergedOrdinals) {
1027
- let corrections = 0;
1028
- for (let ordinal = 0; ordinal < mergedOrdinals.length; ordinal++) {
1029
- if (mergedOrdinals[ordinal] >= 0 !== isCounted(ordinal)) corrections += 1;
1030
- }
1031
- return corrections;
1032
- }
1033
- function keptCount(mergedOrdinals) {
1034
- let kept = 0;
1035
- for (let ordinal = 0; ordinal < mergedOrdinals.length; ordinal++) {
1036
- if (mergedOrdinals[ordinal] >= 0) kept += 1;
1037
- }
1038
- return kept;
1039
- }
1040
- return {
1041
- readerFor(analysis) {
1042
- if (analysis.fields.length === 0) return null;
1043
- if (table === null || reader === null || !sameFields(table.fields, analysis.fields)) return rebuild(analysis);
1044
- subtractPendingRemovals(reader, analysis);
1045
- return reader;
1046
- },
1047
- afterRemoval(ordinal) {
1048
- if (table !== null) pendingRemovals.push(ordinal);
1049
- },
1050
- tableOfEveryDocument(analysis) {
1051
- if (table === null || uncounted !== null || !sameFields(table.fields, analysis.fields)) return null;
1052
- return table;
1053
- },
1054
- countKeptSpellings(counts, analysis, mergedOrdinals) {
1055
- if (table === null || !sameFields(table.fields, analysis.fields) || correctionsAgainstTable(mergedOrdinals) > keptCount(mergedOrdinals)) {
1056
- for (let ordinal = 0; ordinal < mergedOrdinals.length; ordinal++) {
1057
- if (mergedOrdinals[ordinal] >= 0) countDocumentSpellings(counts, documents.documentAt(ordinal), analysis, 1);
1058
- }
1059
- return;
1060
- }
1061
- const corrected = /* @__PURE__ */ new Map();
1062
- countTableSpellings(corrected, table, tokenTable);
1063
- const removed = /* @__PURE__ */ new Map();
1064
- const returned = [];
1065
- for (let ordinal = 0; ordinal < mergedOrdinals.length; ordinal++) {
1066
- const kept = mergedOrdinals[ordinal] >= 0;
1067
- if (kept === isCounted(ordinal)) continue;
1068
- if (kept) returned.push(ordinal);
1069
- else countRemovedSpellings(removed, documents.documentAt(ordinal), analysis);
1070
- }
1071
- subtractRemovedSpellings(corrected, removed, analysis);
1072
- for (const ordinal of returned) countDocumentSpellings(corrected, documents.documentAt(ordinal), analysis, 1);
1073
- addCounts(counts, corrected);
1074
- },
1075
- spellings() {
1076
- return null;
1077
- },
1078
- bytes() {
1079
- if (table === null) return 0;
1080
- return partialWordTableBytes(table) + removedCounts.size * FROZEN_PARTIAL_REMOVED_ENTRY_BYTES;
1081
- }
1082
- };
1083
- }
1084
-
1085
- // src/core/partition/partial-words/growing-slot.ts
1086
- function createGrowingPartialWordSlot(view) {
1087
- let fields = [];
1088
- let everyDocumentPending = false;
1089
- const pending = /* @__PURE__ */ new Set();
1090
- const entriesByToken = /* @__PURE__ */ new Map();
1091
- const entrySpellings = [];
1092
- const entryTokens = [];
1093
- const entryLengths = [];
1094
- const entryCounts = [];
1095
- const entryInRuns = [];
1096
- const freeEntries = [];
1097
- const entriesOutsideRuns = [];
1098
- const runs = /* @__PURE__ */ new Map();
1099
- let liveEntries = 0;
1100
- let runMembers = 0;
1101
- function resetSpellings() {
1102
- pending.clear();
1103
- entriesByToken.clear();
1104
- entrySpellings.length = 0;
1105
- entryTokens.length = 0;
1106
- entryLengths.length = 0;
1107
- entryCounts.length = 0;
1108
- entryInRuns.length = 0;
1109
- freeEntries.length = 0;
1110
- entriesOutsideRuns.length = 0;
1111
- runs.clear();
1112
- liveEntries = 0;
1113
- runMembers = 0;
1114
- }
1115
- function addEntry(byToken, token, spelling, count) {
1116
- const length = codePointCountOf(spelling);
1117
- if (length <= PARTIAL_WORD_RUN_CODE_POINTS) return;
1118
- const entry = freeEntries.pop() ?? entrySpellings.length;
1119
- entrySpellings[entry] = spelling;
1120
- entryTokens[entry] = token;
1121
- entryLengths[entry] = length;
1122
- entryCounts[entry] = count;
1123
- entryInRuns[entry] = false;
1124
- entriesOutsideRuns.push(entry);
1125
- if (entriesOutsideRuns.length > GROWING_PARTIAL_PENDING_ENTRIES_PER_ENTRY * entrySpellings.length) {
1126
- dropFreedAndRepeatedPendingEntries();
1127
- }
1128
- byToken.set(spelling, entry);
1129
- liveEntries++;
1130
- }
1131
- function dropFreedAndRepeatedPendingEntries() {
1132
- let kept = 0;
1133
- for (const entry of entriesOutsideRuns) {
1134
- if (entryLengths[entry] === 0 || entryInRuns[entry]) continue;
1135
- entryInRuns[entry] = true;
1136
- entriesOutsideRuns[kept++] = entry;
1137
- }
1138
- entriesOutsideRuns.length = kept;
1139
- for (let at = 0; at < kept; at++) entryInRuns[entriesOutsideRuns[at]] = false;
1140
- }
1141
- function addToRuns(entry) {
1142
- const points = codePointsOf(entrySpellings[entry]);
1143
- for (let at = 0; at + PARTIAL_WORD_RUN_CODE_POINTS <= points.length; at++) {
1144
- const key = packedRunKeyAt(points, at);
1145
- let members = runs.get(key);
1146
- if (members === void 0) {
1147
- members = /* @__PURE__ */ new Set();
1148
- runs.set(key, members);
1149
- }
1150
- const size = members.size;
1151
- members.add(entry);
1152
- if (members.size !== size) runMembers++;
1153
- }
1154
- entryInRuns[entry] = true;
1155
- }
1156
- function addEntriesToRuns() {
1157
- for (const entry of entriesOutsideRuns) {
1158
- if (entryLengths[entry] > 0 && !entryInRuns[entry]) addToRuns(entry);
1159
- }
1160
- entriesOutsideRuns.length = 0;
1161
- }
1162
- function removeFromRuns(entry) {
1163
- const points = codePointsOf(entrySpellings[entry]);
1164
- for (let at = 0; at + PARTIAL_WORD_RUN_CODE_POINTS <= points.length; at++) {
1165
- const key = packedRunKeyAt(points, at);
1166
- const members = runs.get(key);
1167
- if (members === void 0 || !members.delete(entry)) continue;
1168
- runMembers--;
1169
- if (members.size === 0) runs.delete(key);
1170
- }
1171
- entryInRuns[entry] = false;
1172
- }
1173
- function removeEntry(byToken, token, spelling, entry) {
1174
- if (entryInRuns[entry]) removeFromRuns(entry);
1175
- byToken.delete(spelling);
1176
- if (byToken.size === 0) entriesByToken.delete(token);
1177
- entrySpellings[entry] = "";
1178
- entryTokens[entry] = "";
1179
- entryLengths[entry] = 0;
1180
- entryCounts[entry] = 0;
1181
- freeEntries.push(entry);
1182
- liveEntries--;
1183
- }
1184
- function change(token, spelling, delta) {
1185
- let byToken = entriesByToken.get(token);
1186
- const entry = byToken?.get(spelling);
1187
- if (byToken !== void 0 && entry !== void 0) {
1188
- const after = entryCounts[entry] + delta;
1189
- if (after > 0) entryCounts[entry] = after;
1190
- else removeEntry(byToken, token, spelling, entry);
1191
- return;
1192
- }
1193
- if (delta <= 0) return;
1194
- if (byToken === void 0) {
1195
- byToken = /* @__PURE__ */ new Map();
1196
- entriesByToken.set(token, byToken);
1197
- }
1198
- addEntry(byToken, token, spelling, delta);
1199
- if (byToken.size === 0) entriesByToken.delete(token);
1200
- }
1201
- function encodedSpellings() {
1202
- const encoded = { fields: [...fields], tokens: [], spellings: [], counts: [] };
1203
- for (const [token, byToken] of entriesByToken) {
1204
- for (const [spelling, entry] of byToken) {
1205
- encoded.tokens.push(token);
1206
- encoded.spellings.push(spelling);
1207
- encoded.counts.push(entryCounts[entry]);
1208
- }
1209
- }
1210
- return encoded;
1211
- }
1212
- function applyCounts(source, direction) {
1213
- for (const [token, byToken] of source) {
1214
- for (const [spelling, count] of byToken) change(token, spelling, count * direction);
1215
- }
1216
- }
1217
- function adoptFields(next) {
1218
- if (sameFields(fields, next)) return;
1219
- fields = [...next];
1220
- resetSpellings();
1221
- everyDocumentPending = fields.length > 0;
1222
- }
1223
- function documentAt(internalId) {
1224
- const docId = view.docStore.getExternalId(internalId);
1225
- return docId === void 0 ? void 0 : view.docStore.get(docId)?.fields;
1226
- }
1227
- function resolvePending(analysis) {
1228
- if (everyDocumentPending) {
1229
- resetSpellings();
1230
- const derived2 = /* @__PURE__ */ new Map();
1231
- for (const [, stored] of view.docStore.all()) countDocumentSpellings(derived2, stored.fields, analysis, 1);
1232
- applyCounts(derived2, 1);
1233
- everyDocumentPending = false;
1234
- return;
1235
- }
1236
- if (pending.size === 0) return;
1237
- const derived = /* @__PURE__ */ new Map();
1238
- for (const internalId of pending) {
1239
- const document = documentAt(internalId);
1240
- if (document !== void 0) countDocumentSpellings(derived, document, analysis, 1);
1241
- }
1242
- pending.clear();
1243
- applyCounts(derived, 1);
1244
- }
1245
- const reader = {
1246
- forEachContaining(probe, visit) {
1247
- const points = probe.codePoints;
1248
- if (points.length < PARTIAL_WORD_RUN_CODE_POINTS) return;
1249
- let narrowest = null;
1250
- for (let at = 0; at + PARTIAL_WORD_RUN_CODE_POINTS <= points.length; at++) {
1251
- const members = runs.get(packedRunKeyAt(points, at));
1252
- if (members === void 0) return;
1253
- if (narrowest === null || members.size < narrowest.size) narrowest = members;
1254
- }
1255
- if (narrowest === null) return;
1256
- for (const entry of narrowest) {
1257
- const length = entryLengths[entry];
1258
- if (length <= points.length) continue;
1259
- if (!entrySpellings[entry].includes(probe.text)) continue;
1260
- visit(entryTokens[entry], length);
1261
- }
1262
- },
1263
- bytes() {
1264
- return slot.bytes();
1265
- }
1266
- };
1267
- const slot = {
1268
- readerFor(analysis) {
1269
- if (analysis.fields.length === 0) return null;
1270
- adoptFields(analysis.fields);
1271
- resolvePending(analysis);
1272
- addEntriesToRuns();
1273
- return reader;
1274
- },
1275
- spellings() {
1276
- if (fields.length === 0 || everyDocumentPending || pending.size > 0) return null;
1277
- return encodedSpellings();
1278
- },
1279
- afterDocument(documentFields, internalId, spellings, direction) {
1280
- if (documentFields.length === 0) return;
1281
- if (!sameFields(fields, documentFields)) {
1282
- const holdsOnlyThisDocument = direction === 1 && view.docStore.count() === 1;
1283
- adoptFields(documentFields);
1284
- if (holdsOnlyThisDocument) everyDocumentPending = false;
1285
- }
1286
- if (everyDocumentPending) return;
1287
- if (direction === -1 && pending.delete(internalId)) return;
1288
- if (spellings !== null) {
1289
- applyCounts(spellings, direction);
1290
- } else if (direction === 1) {
1291
- pending.add(internalId);
1292
- } else {
1293
- everyDocumentPending = true;
1294
- }
1295
- },
1296
- afterMerge(spellings, internalIds) {
1297
- if (internalIds.length === 0) return;
1298
- if (fields.length === 0 && spellings !== null && view.docStore.count() === internalIds.length) {
1299
- adoptFields(spellings.fields);
1300
- everyDocumentPending = false;
1301
- }
1302
- if (fields.length === 0 || everyDocumentPending) return;
1303
- if (spellings === null || !sameFields(fields, spellings.fields)) {
1304
- for (const internalId of internalIds) pending.add(internalId);
1305
- return;
1306
- }
1307
- for (let at = 0; at < spellings.tokens.length; at++) {
1308
- change(spellings.tokens[at], spellings.spellings[at], spellings.counts[at]);
1309
- }
1310
- },
1311
- forgetSpellings() {
1312
- resetSpellings();
1313
- everyDocumentPending = fields.length > 0;
1314
- },
1315
- clear() {
1316
- fields = [];
1317
- everyDocumentPending = false;
1318
- resetSpellings();
1319
- },
1320
- bytes() {
1321
- return liveEntries * GROWING_PARTIAL_ENTRY_BYTES + runs.size * GROWING_PARTIAL_RUN_BYTES + runMembers * GROWING_PARTIAL_RUN_MEMBER_BYTES + entriesOutsideRuns.length * GROWING_PARTIAL_PENDING_ENTRY_BYTES;
1322
- }
1323
- };
1324
- return slot;
1325
- }
1326
-
1327
- // src/core/partition/partial-words/highlight.ts
1328
- function containsPartialWord(spelling, words) {
1329
- for (const word of words) {
1330
- if (spelling.length > word.length && spelling.includes(word)) return true;
1331
- }
1332
- return false;
1333
- }
1334
- function partialWordMatcher(text, language, partial) {
1335
- const indexed = tokenize(text, language, {
1336
- stem: true,
1337
- removeStopWords: true,
1338
- collectSurfaces: true,
1339
- customTokenizer: partial.customTokenizer,
1340
- stopWordOverride: partial.stopWordOverride
1341
- });
1342
- const positions = /* @__PURE__ */ new Set();
1343
- const spellings = /* @__PURE__ */ new Set();
1344
- for (let at = 0; at < indexed.tokens.length; at++) {
1345
- const spelling = indexed.surfaces?.[at] ?? indexed.tokens[at].token;
1346
- if (!containsPartialWord(spelling, partial.words)) continue;
1347
- positions.add(indexed.tokens[at].position);
1348
- spellings.add(spelling);
1349
- }
1350
- if (partial.customTokenizer !== void 0) return (_position, fieldToken) => spellings.has(fieldToken);
1351
- return (position) => positions.has(position);
1352
- }
1353
-
1354
- // src/core/partition/partial-words/query.ts
1355
- function addPartialWords(group, added) {
1356
- const membersByToken = /* @__PURE__ */ new Map();
1357
- for (const member of group.members) membersByToken.set(member.token, member);
1358
- for (const word of added) {
1359
- const member = membersByToken.get(word.token);
1360
- if (member === void 0) {
1361
- group.members.push({ token: word.token, factor: 0, partialFactor: word.factor });
1362
- } else if (word.factor > member.partialFactor) {
1363
- member.partialFactor = word.factor;
1364
- }
1365
- }
1366
- }
1367
- function partialWordRequests(query) {
1368
- const eligible = [];
1369
- for (const queryToken of query.queryTokens) {
1370
- const word = query.written.get(queryToken.position);
1371
- if (word === void 0 || codePointCount(word) < PARTIAL_WORD_MIN_CODE_POINTS) continue;
1372
- eligible.push({ token: queryToken.token, written: word });
1373
- if (eligible.length === PARTIAL_WORDS_ADDED_PER_QUERY) break;
1374
- }
1375
- const count = eligible.length;
1376
- if (count === 0) return [];
1377
- const evenShare = Math.floor(PARTIAL_WORDS_ADDED_PER_QUERY / count);
1378
- const remainder = PARTIAL_WORDS_ADDED_PER_QUERY % count;
1379
- return eligible.map((entry, order) => ({
1380
- token: entry.token,
1381
- request: {
1382
- written: entry.written,
1383
- ownToken: entry.token,
1384
- share: evenShare + (order < remainder ? 1 : 0),
1385
- tolerance: entry.token === query.prefixToken ? 0 : query.tolerance,
1386
- prefixLength: query.prefixLength ?? DEFAULT_FUZZY_PREFIX_LENGTH
1387
- }
1388
- }));
1389
- }
1390
- function addPartialWordMembers(query, expand, groupOf) {
1391
- const requests = partialWordRequests(query);
1392
- const added = expand(
1393
- query.analysis,
1394
- requests.map((entry) => entry.request)
1395
- );
1396
- for (let at = 0; at < requests.length; at++) {
1397
- if (added[at].length === 0) continue;
1398
- const token = requests[at].token;
1399
- addPartialWords(groupOf(token, token !== query.prefixToken), added[at]);
1400
- }
1401
- }
1402
- function partialWordsToHighlight(queryTokens, writtenWords) {
1403
- const writtenAt = /* @__PURE__ */ new Map();
1404
- for (const word of writtenWords) {
1405
- if (!writtenAt.has(word.position)) writtenAt.set(word.position, word.token);
1406
- }
1407
- const seenTokens = /* @__PURE__ */ new Set();
1408
- const words = [];
1409
- for (const queryToken of queryTokens) {
1410
- if (seenTokens.has(queryToken.token)) continue;
1411
- seenTokens.add(queryToken.token);
1412
- const word = writtenAt.get(queryToken.position);
1413
- if (word === void 0 || codePointCount(word) < PARTIAL_WORD_MIN_CODE_POINTS) continue;
1414
- words.push(word);
1415
- if (words.length === PARTIAL_WORDS_ADDED_PER_QUERY) break;
1416
- }
1417
- return words;
1418
- }
1419
-
1420
- // src/core/partition/partial-words/module.ts
1421
- var partialWordSearchModule = {
1422
- name: "partialWords",
1423
- createGrowingSlot: createGrowingPartialWordSlot,
1424
- createFrozenSlot: createFrozenPartialWordSlot,
1425
- buildTable: buildPartialWordTable,
1426
- expand: expandPartialWords,
1427
- countSpelling,
1428
- encodeSpellings: encodePartialSpellings,
1429
- spellingCountsOf,
1430
- highlightMatcher: partialWordMatcher,
1431
- addTermMembers: addPartialWordMembers,
1432
- highlightWords: partialWordsToHighlight
1433
- };
1434
-
1435
- export { expandTermPrefix, getFlatSchema, getNestedValue, getOrCreateFieldNameIndex, isLatitude, isLongitude, isQuantizationMode, isStorageMode, messagePackUpperBoundBytes, parseVectorDimension, partialWordSearchModule, partitionDocumentFrequency, raiseEarlierReleaseGraphSetting, requireDocumentWithinSizeLimit, sameFields, suggestDisplayTerms, textFieldsChanged, tokenizeOptions, validateDocument, validateDocumentStrict, validateRequiredFields, validateTextStorage, validateVectorPromotion, validateVectorStorage, visitDocumentSpellings, visitDocumentSurfaceSpellings };