@delali/narsil 0.3.1-next.99 → 0.4.1-next.211

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 (426) hide show
  1. package/NOTICE +45 -0
  2. package/README.md +30 -11
  3. package/dist/adapters/filesystem.d.ts +1 -1
  4. package/dist/adapters/filesystem.mjs +101 -13
  5. package/dist/adapters/gcs.d.ts +49 -0
  6. package/dist/adapters/gcs.mjs +213 -0
  7. package/dist/adapters/indexeddb.d.ts +1 -1
  8. package/dist/adapters/indexeddb.mjs +2 -7
  9. package/dist/adapters/memory.d.ts +1 -1
  10. package/dist/adapters/memory.mjs +5 -0
  11. package/dist/adapters/s3.d.ts +53 -0
  12. package/dist/adapters/s3.mjs +263 -0
  13. package/dist/{adapters-BQFQ4PRz.d.ts → adapters-pljAqmrC.d.ts} +33 -0
  14. package/dist/browser/chunk-4E5APHTM.mjs +1459 -0
  15. package/dist/browser/chunk-NDYADQ4Y.mjs +23426 -0
  16. package/dist/browser/chunk-QAOVAYAG.mjs +564 -0
  17. package/dist/browser/chunk-WC2DEXWU.mjs +29 -0
  18. package/dist/browser/chunk-YINZFPLT.mjs +1239 -0
  19. package/dist/browser/chunk-YJHGOJAC.mjs +15 -0
  20. package/dist/browser/{chunk-Z7QH2XHB.mjs → core-leaf-HWAXCEWX.mjs} +3987 -2103
  21. package/dist/browser/custom-token-results-R5BIX7SL.mjs +59 -0
  22. package/dist/browser/digest-leaf-64IPRPZD.mjs +151 -0
  23. package/dist/browser/durability-config-75NSFCQN.mjs +97 -0
  24. package/dist/browser/embed-GG6PS3EA.mjs +264 -0
  25. package/dist/browser/geo-index-GNHY4PUB.mjs +1484 -0
  26. package/dist/browser/gzip-JF3S6PPT.mjs +31 -0
  27. package/dist/browser/module-ZZTNG5JZ.mjs +5762 -0
  28. package/dist/browser/msgpack-leaf-44XNWSSY.mjs +302 -0
  29. package/dist/browser/optional-reads-XMVPG6HG.mjs +3230 -0
  30. package/dist/browser/optional-writes-76DWMRQH.mjs +3603 -0
  31. package/dist/browser/phrase-module-6UGFVW5J.mjs +617 -0
  32. package/dist/browser/resolve-vector-text-XRR2OVHE.mjs +85 -0
  33. package/dist/browser/restore-queue-SG5O735W.mjs +196 -0
  34. package/dist/browser/{runtime-NYE5TB6O.mjs → runtime-OMKE7DF4.mjs} +83 -25
  35. package/dist/browser/segment-codec-leaf-A427QJUX.mjs +554 -0
  36. package/dist/browser/segment-merge-leaf-7BZ54JPI.mjs +1636 -0
  37. package/dist/browser/storage-leaf-5UTR5K7J.mjs +19829 -0
  38. package/dist/browser/store-leaf-3L33V35P.mjs +2070 -0
  39. package/dist/browser/suggestions-leaf-UBNDVKBD.mjs +1430 -0
  40. package/dist/browser/worker-copies-JXSGYR5X.mjs +2951 -0
  41. package/dist/{capabilities-BTTIs96E.d.ts → capabilities-DMte5K9_.d.ts} +162 -18
  42. package/dist/chunk-2AFZE7Y3.mjs +72 -0
  43. package/dist/chunk-2CKDCC65.mjs +47 -0
  44. package/dist/chunk-3ECIRFS5.mjs +61 -0
  45. package/dist/chunk-44W3CBNG.mjs +7 -0
  46. package/dist/chunk-4H4RG2FR.mjs +13 -0
  47. package/dist/chunk-4PY4JYMY.mjs +11 -0
  48. package/dist/chunk-4ZPVAHWF.mjs +1289 -0
  49. package/dist/chunk-5EI5CXO6.mjs +197 -0
  50. package/dist/chunk-5F5MXWS5.mjs +283 -0
  51. package/dist/{chunk-OHP7QR33.mjs → chunk-5FLRXF73.mjs} +25 -4
  52. package/dist/chunk-6FOENO4E.mjs +273 -0
  53. package/dist/chunk-6GHX35ZM.mjs +108 -0
  54. package/dist/chunk-6MSZ543Y.mjs +32 -0
  55. package/dist/chunk-6N6HHBCQ.mjs +4596 -0
  56. package/dist/{chunk-LXPIXDUJ.mjs → chunk-7P5YWDRQ.mjs} +403 -169
  57. package/dist/{chunk-TGP5M5R7.mjs → chunk-7T4LAYT4.mjs} +1 -1
  58. package/dist/{chunk-GGSH6KBQ.mjs → chunk-ASZLNVWW.mjs} +23 -3
  59. package/dist/chunk-AVBPB3MI.mjs +602 -0
  60. package/dist/{chunk-UCDF35PU.mjs → chunk-AVGUEEQ3.mjs} +494 -245
  61. package/dist/chunk-BUMREPLU.mjs +15 -0
  62. package/dist/chunk-BY6NALRK.mjs +31921 -0
  63. package/dist/chunk-C4ZMXXTL.mjs +92 -0
  64. package/dist/{chunk-2WYMG3OZ.mjs → chunk-C74KPRR7.mjs} +274 -19
  65. package/dist/{chunk-RSRVGAIQ.mjs → chunk-D456ZFPQ.mjs} +3 -2
  66. package/dist/chunk-DXZ6JDWG.mjs +797 -0
  67. package/dist/chunk-FJXJZUWF.mjs +209 -0
  68. package/dist/chunk-FS3HPPSC.mjs +212 -0
  69. package/dist/chunk-FT4KLZXW.mjs +1164 -0
  70. package/dist/chunk-GR5GMFJJ.mjs +104 -0
  71. package/dist/chunk-GXCDWLQI.mjs +193 -0
  72. package/dist/chunk-GXED6R3Q.mjs +271 -0
  73. package/dist/chunk-HLPRHOSO.mjs +17 -0
  74. package/dist/chunk-IL5DRCNU.mjs +3041 -0
  75. package/dist/{chunk-P36MUFEJ.mjs → chunk-JDDXV6UF.mjs} +2 -1
  76. package/dist/chunk-K5HSUPYS.mjs +11 -0
  77. package/dist/chunk-KYIRXTCA.mjs +100 -0
  78. package/dist/chunk-LFXS6OF7.mjs +289 -0
  79. package/dist/chunk-LNGE7SLY.mjs +151 -0
  80. package/dist/chunk-M2Z5WVWW.mjs +194 -0
  81. package/dist/{chunk-45AVKHMJ.mjs → chunk-M3B7SGJB.mjs} +63 -50
  82. package/dist/chunk-M3OW2XSP.mjs +40 -0
  83. package/dist/chunk-MFPSQZ6P.mjs +127 -0
  84. package/dist/chunk-MRCJBWJZ.mjs +1292 -0
  85. package/dist/chunk-MSIN4NM3.mjs +25 -0
  86. package/dist/chunk-MW3CJVGP.mjs +219 -0
  87. package/dist/chunk-MYM6CAVK.mjs +76 -0
  88. package/dist/chunk-NJJN4FMM.mjs +84 -0
  89. package/dist/chunk-NM7I3BM7.mjs +59 -0
  90. package/dist/chunk-OIJ64LGT.mjs +19 -0
  91. package/dist/{chunk-K7D4ZTSW.mjs → chunk-P4F4UWLC.mjs} +1 -1
  92. package/dist/chunk-Q2AP2FSN.mjs +15 -0
  93. package/dist/chunk-R2PJKSNL.mjs +54 -0
  94. package/dist/{chunk-HXJBSHXF.mjs → chunk-R724DJSG.mjs} +5056 -2619
  95. package/dist/chunk-S2POFTLN.mjs +10 -0
  96. package/dist/chunk-S5QMWECL.mjs +7 -0
  97. package/dist/chunk-SLAC5PAB.mjs +5008 -0
  98. package/dist/chunk-T4HMSZCX.mjs +5 -0
  99. package/dist/chunk-TACP6VK6.mjs +111 -0
  100. package/dist/chunk-TGPKS2UM.mjs +125 -0
  101. package/dist/chunk-TKKXPKEO.mjs +979 -0
  102. package/dist/chunk-V6EUBAIT.mjs +19 -0
  103. package/dist/chunk-XL56L4IR.mjs +228 -0
  104. package/dist/chunk-XQIAMDAG.mjs +3076 -0
  105. package/dist/chunk-YTUZ4R22.mjs +1063 -0
  106. package/dist/{chunk-KV3AZFT3.mjs → chunk-ZKOQR7EA.mjs} +45 -1
  107. package/dist/chunk-ZPJFGGGI.mjs +638 -0
  108. package/dist/chunk-ZXX5GZEX.mjs +17 -0
  109. package/dist/{client-i9eLJrw5.d.ts → client-BKqtl0_V.d.ts} +442 -22
  110. package/dist/client.d.ts +11 -10
  111. package/dist/client.mjs +8 -898
  112. package/dist/config-Bnl7L-0H.d.ts +608 -0
  113. package/dist/{config-P__Diiy4.d.ts → config-CJ-jfI0a.d.ts} +119 -9
  114. package/dist/core-leaf-6JVHEVFB.mjs +8 -0
  115. package/dist/custom-token-results-NXHBVY7U.mjs +59 -0
  116. package/dist/digest-leaf-KXBGKYHZ.mjs +1 -0
  117. package/dist/direct-executor-V3WOYU2Y.mjs +17 -0
  118. package/dist/distribution/coordinator/etcd.d.ts +63 -7
  119. package/dist/distribution/coordinator/etcd.mjs +725 -81
  120. package/dist/distribution/coordinator/in-memory.d.ts +3 -3
  121. package/dist/distribution/coordinator/in-memory.mjs +65 -10
  122. package/dist/distribution/transport/grpc.d.ts +2 -2
  123. package/dist/distribution/transport/grpc.mjs +39 -10
  124. package/dist/distribution/transport/in-memory.d.ts +2 -2
  125. package/dist/distribution/transport/in-memory.mjs +9 -6
  126. package/dist/distribution/transport/tcp.d.ts +2 -2
  127. package/dist/distribution/transport/tcp.mjs +20 -15
  128. package/dist/distribution.d.ts +267 -56
  129. package/dist/distribution.mjs +23156 -11362
  130. package/dist/durability-config-VWS2K24E.mjs +96 -0
  131. package/dist/embed-4PHHKGBK.mjs +263 -0
  132. package/dist/embeddings/openai.d.ts +1 -1
  133. package/dist/embeddings/openai.mjs +2 -2
  134. package/dist/{memory-CUEDwr-F.d.ts → engine-qjAxJSKk.d.ts} +2254 -1123
  135. package/dist/geo-index-2ZMMWWSK.mjs +1484 -0
  136. package/dist/gzip-2UCZW2MM.mjs +31 -0
  137. package/dist/{index-lcdGLyJH.d.ts → index-B_vmxpgW.d.ts} +260 -102
  138. package/dist/index.browser.mjs +4 -4
  139. package/dist/index.d.ts +2133 -57
  140. package/dist/index.mjs +16 -32
  141. package/dist/index.react-native.mjs +12 -0
  142. package/dist/invalidation/broadcast-channel.d.ts +1 -1
  143. package/dist/invalidation/filesystem.d.ts +1 -1
  144. package/dist/invalidation/filesystem.mjs +1 -2
  145. package/dist/invalidation/noop.d.ts +1 -1
  146. package/dist/languages/albanian.mjs +1 -1
  147. package/dist/languages/amharic.mjs +1 -1
  148. package/dist/languages/arabic.mjs +1 -1
  149. package/dist/languages/armenian.mjs +1 -1
  150. package/dist/languages/azerbaijani.mjs +1 -1
  151. package/dist/languages/bambara.mjs +1 -1
  152. package/dist/languages/basque.mjs +1 -1
  153. package/dist/languages/belarusian.mjs +1 -1
  154. package/dist/languages/bengali.mjs +1 -1
  155. package/dist/languages/bosnian.mjs +1 -1
  156. package/dist/languages/breton.mjs +1 -1
  157. package/dist/languages/bulgarian.mjs +1 -1
  158. package/dist/languages/burmese.mjs +1 -1
  159. package/dist/languages/catalan.mjs +1 -1
  160. package/dist/languages/chinese.mjs +1 -1
  161. package/dist/languages/croatian.mjs +1 -1
  162. package/dist/languages/czech.mjs +1 -1
  163. package/dist/languages/dagbani.mjs +1 -1
  164. package/dist/languages/danish.mjs +1 -1
  165. package/dist/languages/dutch.mjs +1 -1
  166. package/dist/languages/english.mjs +1 -1
  167. package/dist/languages/esperanto.mjs +1 -1
  168. package/dist/languages/estonian.mjs +1 -1
  169. package/dist/languages/ewe.mjs +1 -1
  170. package/dist/languages/faroese.mjs +1 -1
  171. package/dist/languages/fijian.mjs +1 -1
  172. package/dist/languages/finnish.mjs +1 -1
  173. package/dist/languages/french.mjs +1 -1
  174. package/dist/languages/ga.mjs +1 -1
  175. package/dist/languages/galician.mjs +1 -1
  176. package/dist/languages/georgian.mjs +1 -1
  177. package/dist/languages/german.mjs +1 -1
  178. package/dist/languages/greek.mjs +1 -1
  179. package/dist/languages/guarani.mjs +1 -1
  180. package/dist/languages/gujarati.mjs +1 -1
  181. package/dist/languages/haitian-creole.mjs +1 -1
  182. package/dist/languages/hausa.mjs +1 -1
  183. package/dist/languages/hawaiian.mjs +1 -1
  184. package/dist/languages/hebrew.mjs +1 -1
  185. package/dist/languages/hindi.mjs +1 -1
  186. package/dist/languages/hungarian.mjs +1 -1
  187. package/dist/languages/icelandic.mjs +1 -1
  188. package/dist/languages/igbo.mjs +1 -1
  189. package/dist/languages/indonesian.mjs +1 -1
  190. package/dist/languages/irish.mjs +1 -1
  191. package/dist/languages/italian.mjs +1 -1
  192. package/dist/languages/japanese.mjs +1 -1
  193. package/dist/languages/kannada.mjs +1 -1
  194. package/dist/languages/kazakh.mjs +1 -1
  195. package/dist/languages/khmer.mjs +1 -1
  196. package/dist/languages/kinyarwanda.mjs +1 -1
  197. package/dist/languages/kirundi.mjs +1 -1
  198. package/dist/languages/korean.mjs +1 -1
  199. package/dist/languages/kurmanji.mjs +1 -1
  200. package/dist/languages/kyrgyz.mjs +1 -1
  201. package/dist/languages/lao.mjs +1 -1
  202. package/dist/languages/latin.mjs +1 -1
  203. package/dist/languages/latvian.mjs +1 -1
  204. package/dist/languages/lingala.mjs +1 -1
  205. package/dist/languages/lithuanian.mjs +1 -1
  206. package/dist/languages/luxembourgish.mjs +1 -1
  207. package/dist/languages/macedonian.mjs +1 -1
  208. package/dist/languages/malagasy.mjs +1 -1
  209. package/dist/languages/malay.mjs +1 -1
  210. package/dist/languages/malayalam.mjs +1 -1
  211. package/dist/languages/maltese.mjs +1 -1
  212. package/dist/languages/maori.mjs +1 -1
  213. package/dist/languages/marathi.mjs +1 -1
  214. package/dist/languages/nepali.mjs +1 -1
  215. package/dist/languages/norwegian.mjs +1 -1
  216. package/dist/languages/oromo.mjs +1 -1
  217. package/dist/languages/persian.mjs +1 -1
  218. package/dist/languages/polish.mjs +1 -1
  219. package/dist/languages/portuguese.mjs +1 -1
  220. package/dist/languages/punjabi.mjs +1 -1
  221. package/dist/languages/romanian.mjs +1 -1
  222. package/dist/languages/russian.mjs +1 -1
  223. package/dist/languages/samoan.mjs +1 -1
  224. package/dist/languages/sanskrit.mjs +1 -1
  225. package/dist/languages/scottish-gaelic.mjs +1 -1
  226. package/dist/languages/serbian.mjs +1 -1
  227. package/dist/languages/shona.mjs +1 -1
  228. package/dist/languages/sinhala.mjs +1 -1
  229. package/dist/languages/slovak.mjs +1 -1
  230. package/dist/languages/slovenian.mjs +1 -1
  231. package/dist/languages/sorani.mjs +1 -1
  232. package/dist/languages/spanish.mjs +1 -1
  233. package/dist/languages/swahili.mjs +1 -1
  234. package/dist/languages/swedish.mjs +1 -1
  235. package/dist/languages/tagalog.mjs +1 -1
  236. package/dist/languages/tamil.mjs +1 -1
  237. package/dist/languages/tatar.mjs +1 -1
  238. package/dist/languages/telugu.mjs +1 -1
  239. package/dist/languages/thai.mjs +1 -1
  240. package/dist/languages/tibetan.mjs +1 -1
  241. package/dist/languages/tigrinya.mjs +1 -1
  242. package/dist/languages/tongan.mjs +1 -1
  243. package/dist/languages/turkish.mjs +1 -1
  244. package/dist/languages/twi.mjs +1 -1
  245. package/dist/languages/ukrainian.mjs +1 -1
  246. package/dist/languages/urdu.mjs +1 -1
  247. package/dist/languages/vietnamese.mjs +1 -1
  248. package/dist/languages/welsh.mjs +1 -1
  249. package/dist/languages/wolof.mjs +1 -1
  250. package/dist/languages/xhosa.mjs +1 -1
  251. package/dist/languages/yoruba.mjs +1 -1
  252. package/dist/languages/zulu.mjs +1 -1
  253. package/dist/long-query-thread-UCRK7MSI.mjs +154 -0
  254. package/dist/module-5ZSLUQII.mjs +3729 -0
  255. package/dist/msgpack-leaf-H5ZYW7S7.mjs +9 -0
  256. package/dist/optional-reads-5HFMF2QZ.mjs +3373 -0
  257. package/dist/optional-writes-4UOQKETU.mjs +247 -0
  258. package/dist/paged-partition-archive-BBRLZCIF.mjs +253 -0
  259. package/dist/partial-words.browser.mjs +1650 -0
  260. package/dist/partial-words.mjs +17 -11
  261. package/dist/{chunk-ASY5PHYI.mjs → pattern.browser.mjs} +253 -311
  262. package/dist/pattern.mjs +6 -7
  263. package/dist/persistence/durability/checkpoint-worker.d.ts +93 -25
  264. package/dist/persistence/durability/checkpoint-worker.mjs +51 -41
  265. package/dist/phrase-module-EFESWOCR.mjs +635 -0
  266. package/dist/query-actions-HMJUVWGT.mjs +119 -0
  267. package/dist/query-suggestions/merge-worker.d.ts +55 -0
  268. package/dist/query-suggestions/merge-worker.mjs +53 -0
  269. package/dist/query-suggestions-CBYkrQ5T.d.ts +311 -0
  270. package/dist/query-suggestions.browser.mjs +47 -0
  271. package/dist/query-suggestions.d.ts +20 -0
  272. package/dist/query-suggestions.mjs +19 -0
  273. package/dist/react-native/chunks/chunk-3OEFSHVV.mjs +970 -0
  274. package/dist/{browser/chunk-RELZRJNR.mjs → react-native/chunks/chunk-43R4GCM7.mjs} +49 -50
  275. package/dist/react-native/chunks/chunk-AKRYHAVG.mjs +6729 -0
  276. package/dist/react-native/chunks/chunk-CW2ZFXSE.mjs +14 -0
  277. package/dist/react-native/chunks/chunk-G3WCDTOF.mjs +29640 -0
  278. package/dist/react-native/chunks/chunk-GXXHHA2T.mjs +212 -0
  279. package/dist/react-native/chunks/chunk-H3MDVPBO.mjs +151 -0
  280. package/dist/react-native/chunks/chunk-HQEVQEDJ.mjs +52 -0
  281. package/dist/react-native/chunks/chunk-HRDMIQ63.mjs +131 -0
  282. package/dist/react-native/chunks/chunk-HTBY4GON.mjs +565 -0
  283. package/dist/react-native/chunks/chunk-LX62Y4B5.mjs +61 -0
  284. package/dist/react-native/chunks/chunk-MRH36RN3.mjs +902 -0
  285. package/dist/react-native/chunks/chunk-Q32DDFKX.mjs +19 -0
  286. package/dist/react-native/chunks/chunk-UE4ANHSX.mjs +127 -0
  287. package/dist/react-native/chunks/chunk-UNZPWLVL.mjs +1063 -0
  288. package/dist/react-native/chunks/chunk-UO44MA5M.mjs +232 -0
  289. package/dist/react-native/chunks/chunk-UYKIV2KT.mjs +42 -0
  290. package/dist/react-native/chunks/chunk-VUJCSQG5.mjs +11 -0
  291. package/dist/react-native/chunks/chunk-WVHF4ZAK.mjs +802 -0
  292. package/dist/react-native/chunks/chunk-ZUJCUPVS.mjs +54 -0
  293. package/dist/react-native/chunks/core-leaf-S2KNBWDY.mjs +7 -0
  294. package/dist/react-native/chunks/custom-token-results-3OZEMRE7.mjs +59 -0
  295. package/dist/react-native/chunks/digest-leaf-X6OIFDIU.mjs +1 -0
  296. package/dist/react-native/chunks/durability-config-FCSD4MXY.mjs +96 -0
  297. package/dist/react-native/chunks/embed-HA2I7RCF.mjs +263 -0
  298. package/dist/react-native/chunks/geo-index-QEYKEVPH.mjs +1484 -0
  299. package/dist/react-native/chunks/gzip.react-native-CVM4NQG2.mjs +12 -0
  300. package/dist/react-native/chunks/module-FMBX75GP.mjs +5209 -0
  301. package/dist/react-native/chunks/msgpack-leaf-JMNGSTRW.mjs +7 -0
  302. package/dist/react-native/chunks/optional-reads-AFPO2FEB.mjs +3364 -0
  303. package/dist/react-native/chunks/optional-writes-XOH25XZI.mjs +296 -0
  304. package/dist/react-native/chunks/phrase-module-IGYBK7XH.mjs +636 -0
  305. package/dist/react-native/chunks/replace-IMZUVUOE.mjs +57 -0
  306. package/dist/react-native/chunks/resolve-vector-text-GE2CRJKI.mjs +84 -0
  307. package/dist/react-native/chunks/restore-queue-LLNMYB4Z.mjs +187 -0
  308. package/dist/react-native/chunks/runtime-UOHD2XUJ.mjs +615 -0
  309. package/dist/react-native/chunks/segment-codec-leaf-VR6O5GLC.mjs +13 -0
  310. package/dist/react-native/chunks/segment-merge-leaf-LLMWU4EW.mjs +14 -0
  311. package/dist/react-native/chunks/storage-leaf-JD7PIDO4.mjs +19633 -0
  312. package/dist/react-native/chunks/store-leaf-4UVCMYGN.mjs +15 -0
  313. package/dist/react-native/chunks/suggestions-leaf-J5VT5RHY.mjs +1321 -0
  314. package/dist/react-native/chunks/worker-copies-ZYHY7FKJ.mjs +2831 -0
  315. package/dist/react-native/partial-words.mjs +1658 -0
  316. package/dist/react-native/pattern.mjs +2570 -0
  317. package/dist/react-native/query-suggestions.mjs +55 -0
  318. package/dist/react-native/sync.mjs +2759 -0
  319. package/dist/react-native/synonyms.mjs +676 -0
  320. package/dist/react.d.ts +12 -8
  321. package/dist/react.mjs +45 -1
  322. package/dist/{rerank-NWTKK636.mjs → rerank-RI2PMNOD.mjs} +22 -12
  323. package/dist/rerankers/http.d.ts +1 -1
  324. package/dist/rerankers/http.mjs +2 -2
  325. package/dist/resolve-vector-text-OD4J3WHF.mjs +3 -0
  326. package/dist/restore-queue-PCKWDAKQ.mjs +192 -0
  327. package/dist/runtime-USQYKN3I.mjs +615 -0
  328. package/dist/{schema-4W_7tk1f.d.ts → schema-CzG9OUw5.d.ts} +70 -30
  329. package/dist/segment-codec-leaf-QJM7I6QG.mjs +18 -0
  330. package/dist/segment-merge-leaf-4BJGIJHY.mjs +18 -0
  331. package/dist/server.d.ts +348 -22
  332. package/dist/server.mjs +2211 -327
  333. package/dist/storage-leaf-GRRRI7UV.mjs +5962 -0
  334. package/dist/store-leaf-6VMMSVBE.mjs +20 -0
  335. package/dist/stored-values-BWIMpiT_.d.ts +25 -0
  336. package/dist/suggestions-leaf-4KPTMPTL.mjs +54 -0
  337. package/dist/sync/filesystem.d.ts +30 -0
  338. package/dist/sync/filesystem.mjs +288 -0
  339. package/dist/sync/indexeddb.browser.mjs +287 -0
  340. package/dist/sync/indexeddb.d.ts +30 -0
  341. package/dist/sync/indexeddb.mjs +242 -0
  342. package/dist/sync.browser.mjs +1271 -0
  343. package/dist/sync.d.ts +23 -0
  344. package/dist/sync.mjs +2712 -0
  345. package/dist/synonyms.browser.mjs +658 -0
  346. package/dist/synonyms.mjs +17 -7
  347. package/dist/tasks-65b6t6lk.d.ts +782 -0
  348. package/dist/thread-UJ3W5LVI.mjs +31 -0
  349. package/dist/{types-B3b68nfF.d.ts → types-Ck97nB3D.d.ts} +1 -1
  350. package/dist/types-CpCg-Gq-.d.ts +227 -0
  351. package/dist/{types-Cb9kiY5P.d.ts → types-DvncmvuQ.d.ts} +12 -1
  352. package/dist/vector/search-worker.d.ts +10 -2
  353. package/dist/vector/search-worker.mjs +11 -11
  354. package/dist/worker-copies-YSXZXIGC.mjs +2232 -0
  355. package/dist/workers/entry.mjs +75 -15
  356. package/openapi.json +6840 -0
  357. package/package.json +404 -19
  358. package/dist/browser/chunk-CN4I4FZU.mjs +0 -602
  359. package/dist/browser/chunk-HOZW3PKP.mjs +0 -9
  360. package/dist/browser/chunk-JPTQZWJQ.mjs +0 -10
  361. package/dist/browser/chunk-LD55ZGU3.mjs +0 -347
  362. package/dist/browser/chunk-NAFT3K6X.mjs +0 -24546
  363. package/dist/browser/chunk-NNG3EEB6.mjs +0 -2728
  364. package/dist/browser/chunk-QWES44AW.mjs +0 -473
  365. package/dist/browser/durability-wiring-PY3L7DES.mjs +0 -3679
  366. package/dist/browser/module-PDXYHT75.mjs +0 -2822
  367. package/dist/browser/release-76MXRPGV.mjs +0 -33
  368. package/dist/browser/restore-queue-DVIYJ7RU.mjs +0 -35
  369. package/dist/browser/snapshot-J57MZK6L.mjs +0 -1207
  370. package/dist/browser/write-L7FAQA47.mjs +0 -208
  371. package/dist/chunk-37CD3OKS.mjs +0 -87
  372. package/dist/chunk-5XNIRLFC.mjs +0 -96
  373. package/dist/chunk-7X5JST5L.mjs +0 -114
  374. package/dist/chunk-AV4IJKD2.mjs +0 -35
  375. package/dist/chunk-AY3AQ3UH.mjs +0 -73
  376. package/dist/chunk-BKB3XTMI.mjs +0 -707
  377. package/dist/chunk-C7SLA6CM.mjs +0 -19
  378. package/dist/chunk-COVCQ73F.mjs +0 -587
  379. package/dist/chunk-DJHHF2L5.mjs +0 -17
  380. package/dist/chunk-E74YLAIG.mjs +0 -24
  381. package/dist/chunk-FMWRCP2C.mjs +0 -57
  382. package/dist/chunk-GES7U2PM.mjs +0 -68
  383. package/dist/chunk-HJSN7UYG.mjs +0 -10
  384. package/dist/chunk-JFRNNBOM.mjs +0 -35
  385. package/dist/chunk-K25LZA54.mjs +0 -8484
  386. package/dist/chunk-KEHK2O6P.mjs +0 -13
  387. package/dist/chunk-KOKM4PQN.mjs +0 -52
  388. package/dist/chunk-KZ3NX2P7.mjs +0 -21
  389. package/dist/chunk-L3L5YFXC.mjs +0 -614
  390. package/dist/chunk-L5ORED7V.mjs +0 -25
  391. package/dist/chunk-LH4NZNJJ.mjs +0 -1731
  392. package/dist/chunk-LU2CE5AE.mjs +0 -507
  393. package/dist/chunk-LXWDQLTW.mjs +0 -30
  394. package/dist/chunk-MHOSCQCQ.mjs +0 -948
  395. package/dist/chunk-NKRBEGJZ.mjs +0 -1705
  396. package/dist/chunk-NTRMFARG.mjs +0 -462
  397. package/dist/chunk-NW4XDSP2.mjs +0 -212
  398. package/dist/chunk-OOEXLUGR.mjs +0 -117
  399. package/dist/chunk-ORBLD3EL.mjs +0 -6
  400. package/dist/chunk-OWNZYMRE.mjs +0 -3591
  401. package/dist/chunk-PPY2GSIB.mjs +0 -44
  402. package/dist/chunk-QY7GC2MW.mjs +0 -33
  403. package/dist/chunk-R6A773WK.mjs +0 -226
  404. package/dist/chunk-R6PR4WYZ.mjs +0 -68
  405. package/dist/chunk-R7EEKAJE.mjs +0 -593
  406. package/dist/chunk-RONEOEON.mjs +0 -426
  407. package/dist/chunk-VWULPWRJ.mjs +0 -7469
  408. package/dist/chunk-WCJKUGHB.mjs +0 -262
  409. package/dist/chunk-WQBCBKY3.mjs +0 -8
  410. package/dist/chunk-X5CV2E2B.mjs +0 -1
  411. package/dist/chunk-YA7XLE2R.mjs +0 -1256
  412. package/dist/chunk-YTJCGKM4.mjs +0 -56
  413. package/dist/chunk-ZG477IPV.mjs +0 -526
  414. package/dist/chunk-ZYNAMIYX.mjs +0 -113
  415. package/dist/config-BGB_fDtq.d.ts +0 -237
  416. package/dist/direct-executor-CXZ66ACP.mjs +0 -22
  417. package/dist/durability-wiring-QTHOGFMZ.mjs +0 -3229
  418. package/dist/engine-BGCEm9E_.d.ts +0 -577
  419. package/dist/module-3NONKBZX.mjs +0 -1860
  420. package/dist/release-BH3DKW3T.mjs +0 -33
  421. package/dist/restore-queue-JPRBUYII.mjs +0 -35
  422. package/dist/runtime-ZKYZFJJC.mjs +0 -177
  423. package/dist/snapshot-HOGXNO5W.mjs +0 -793
  424. package/dist/tasks-HG3rlxx6.d.ts +0 -302
  425. package/dist/thread-B657LQXK.mjs +0 -692
  426. package/dist/write-XLIGTXBU.mjs +0 -238
@@ -1,1256 +0,0 @@
1
- import { nativeSearchCoreIsEnabled } from './chunk-DJHHF2L5.mjs';
2
- import { DEFAULT_RERANK_WINDOW } from './chunk-HJSN7UYG.mjs';
3
- import { loadNativeCore } from './chunk-GGSH6KBQ.mjs';
4
- import { MAX_FILTER_DEPTH } from './chunk-WQBCBKY3.mjs';
5
- import { MAX_SORT_FIELDS } from './chunk-E74YLAIG.mjs';
6
- import { NarsilError, ServerErrorCodes, ErrorCodes } from './chunk-KV3AZFT3.mjs';
7
- import { mkdtemp, open, rm } from 'fs/promises';
8
- import { tmpdir } from 'os';
9
- import path from 'path';
10
-
11
- // src/server/capabilities.ts
12
- var ASYNC_IMPORT_CAPABILITY = "documents.import.async";
13
- var TASK_CANCEL_CAPABILITY = "tasks.cancel";
14
- var TASK_FILTER_CAPABILITY = "tasks.filter";
15
- var REBUILD_ANALYSIS_CAPABILITY = "indexes.rebuildAnalysis";
16
- var INDEX_LIFECYCLE_CAPABILITY = "indexes.lifecycle";
17
- var DOCUMENT_EXPORT_CAPABILITY = "indexes.documentExport";
18
- var SYNONYMS_CAPABILITY = "indexes.synonyms";
19
- var SERVER_CAPABILITIES = [
20
- ASYNC_IMPORT_CAPABILITY,
21
- TASK_CANCEL_CAPABILITY,
22
- TASK_FILTER_CAPABILITY,
23
- REBUILD_ANALYSIS_CAPABILITY,
24
- INDEX_LIFECYCLE_CAPABILITY,
25
- DOCUMENT_EXPORT_CAPABILITY,
26
- SYNONYMS_CAPABILITY
27
- ];
28
-
29
- // src/server/concurrency-gate.ts
30
- var MAIN_THREAD_GATE_SLOT = 0;
31
- function gateSlotOfWorker(workerId) {
32
- return workerId + 1;
33
- }
34
- function createSharedGateBuffer(slotCount) {
35
- return new SharedArrayBuffer(slotCount * Int32Array.BYTES_PER_ELEMENT);
36
- }
37
- function clearGateSlot(buffer, slot) {
38
- const counters = new Int32Array(buffer);
39
- if (slot >= 0 && slot < counters.length) Atomics.store(counters, slot, 0);
40
- }
41
- function createSharedRequestGate(buffer, max, slot) {
42
- const counters = new Int32Array(buffer);
43
- function inFlight() {
44
- let total = 0;
45
- for (let at = 0; at < counters.length; at++) total += Atomics.load(counters, at);
46
- return total;
47
- }
48
- return {
49
- tryAcquire() {
50
- if (max <= 0) return true;
51
- if (inFlight() >= max) return false;
52
- Atomics.add(counters, slot, 1);
53
- if (inFlight() <= max) return true;
54
- Atomics.sub(counters, slot, 1);
55
- return false;
56
- },
57
- release() {
58
- if (max <= 0) return;
59
- if (Atomics.load(counters, slot) > 0) Atomics.sub(counters, slot, 1);
60
- }
61
- };
62
- }
63
-
64
- // src/server/cors.ts
65
- function resolveCors(cors) {
66
- if (!cors) return null;
67
- if (cors === true) {
68
- return { origin: "*", methods: "GET, POST, PUT, PATCH, DELETE, OPTIONS", headers: "Content-Type, Authorization" };
69
- }
70
- return {
71
- origin: cors.origin ?? "*",
72
- methods: cors.methods?.join(", ") ?? "GET, POST, PUT, PATCH, DELETE, OPTIONS",
73
- headers: cors.headers?.join(", ") ?? "Content-Type, Authorization"
74
- };
75
- }
76
- function matchOrigin(cors, requestOrigin) {
77
- if (cors.origin === "*") return "*";
78
- if (typeof cors.origin === "string") return cors.origin;
79
- return cors.origin.includes(requestOrigin) ? requestOrigin : null;
80
- }
81
- function corsOriginHeaders(cors, requestOrigin) {
82
- const allowed = matchOrigin(cors, requestOrigin);
83
- const variesByOrigin = Array.isArray(cors.origin);
84
- if (!allowed) return variesByOrigin ? [["Vary", "Origin"]] : [];
85
- if (!variesByOrigin) return [["Access-Control-Allow-Origin", allowed]];
86
- return [
87
- ["Access-Control-Allow-Origin", allowed],
88
- ["Vary", "Origin"]
89
- ];
90
- }
91
- function writeCorsOrigin(res, cors, requestOrigin) {
92
- for (const [key, value] of corsOriginHeaders(cors, requestOrigin)) res.writeHeader(key, value);
93
- }
94
- function corsHeaderReader(cors) {
95
- return (req) => corsOriginHeaders(cors, req.getHeader("origin"));
96
- }
97
-
98
- // src/server/errors.ts
99
- var STATUS_BY_CODE = {
100
- INVALID_REQUEST: 400,
101
- INVALID_JSON: 400,
102
- EMPTY_BODY: 400,
103
- PAYLOAD_TOO_LARGE: 413,
104
- NOT_FOUND: 404,
105
- TASK_NOT_FOUND: 404,
106
- TASK_NOT_CANCELLABLE: 409,
107
- TASK_OWNED_BY_ANOTHER_INSTANCE: 409,
108
- TASK_INTERRUPTED: 503,
109
- TOO_MANY_REQUESTS: 429,
110
- HOOK_ERROR: 500,
111
- INTERNAL_ERROR: 500,
112
- ENVELOPE_INVALID_MAGIC: 400,
113
- ENVELOPE_VERSION_MISMATCH: 400,
114
- SCHEMA_INVALID_TYPE: 400,
115
- SCHEMA_DEPTH_EXCEEDED: 400,
116
- SCHEMA_INVALID_VECTOR_DIMENSION: 400,
117
- SCHEMA_INVALID_GEOPOINT: 400,
118
- DOC_VALIDATION_FAILED: 400,
119
- DOC_MISSING_REQUIRED_FIELD: 400,
120
- SEARCH_INVALID_FIELD: 400,
121
- VECTOR_DIMENSION_MISMATCH: 400,
122
- SEARCH_INVALID_FILTER: 400,
123
- SEARCH_INVALID_MODE: 400,
124
- SEARCH_INVALID_CURSOR: 400,
125
- SEARCH_RESULT_WINDOW_EXCEEDED: 400,
126
- SEARCH_WORK_CAP_EXCEEDED: 400,
127
- LANGUAGE_NOT_SUPPORTED: 400,
128
- CONFIG_INVALID: 400,
129
- EMBEDDING_DIMENSION_MISMATCH: 400,
130
- EMBEDDING_NO_SOURCE: 400,
131
- EMBEDDING_CONFIG_INVALID: 400,
132
- RERANK_CONFIG_INVALID: 400,
133
- INDEX_NOT_FOUND: 404,
134
- DOC_NOT_FOUND: 404,
135
- INDEX_ALREADY_EXISTS: 409,
136
- INDEX_ORPHANED: 409,
137
- INDEX_REOPEN_CAPACITY_EXHAUSTED: 503,
138
- INSTANCE_SHUT_DOWN: 503,
139
- DOC_ALREADY_EXISTS: 409,
140
- PARTITION_REBALANCING_BACKPRESSURE: 409,
141
- PARTITION_CAPACITY_EXCEEDED: 409,
142
- RESTORE_MEMORY_EXCEEDED: 507,
143
- WORKER_BUSY: 429,
144
- PARTITION_CORRUPTED: 503,
145
- WORKER_CRASHED: 503,
146
- WORKER_TIMEOUT: 503,
147
- WORKER_ACTION_FAILED: 500,
148
- PERSISTENCE_SAVE_FAILED: 503,
149
- PERSISTENCE_LOAD_FAILED: 503,
150
- PERSISTENCE_DELETE_FAILED: 503,
151
- PERSISTENCE_CRC_MISMATCH: 503,
152
- PERSISTENCE_WAL_CORRUPT: 503,
153
- PERSISTENCE_FSYNC_FAILED: 503,
154
- EMBEDDING_FAILED: 503,
155
- RERANK_FAILED: 503,
156
- QUERY_ROUTING_FAILED: 503,
157
- QUERY_PARTIAL_FAILURE: 503,
158
- QUERY_NODE_TIMEOUT: 503,
159
- QUERY_NO_ACTIVE_REPLICA: 503,
160
- CLUSTER_OPERATION_UNSUPPORTED: 501,
161
- CLUSTER_WRITE_BLOCKED: 429,
162
- REPLICATION_ENTRY_INVALID: 503,
163
- REPLICATION_INSYNC_REMOVAL_FAILED: 503,
164
- REPLICATION_ROLLBACK_FAILED: 503,
165
- REPLICATION_LOG_FULL: 503,
166
- REPLICATION_ENTRY_CORRUPT: 503,
167
- REPLICATION_SNAPSHOT_CORRUPT: 503,
168
- REPLICATION_TERM_MISMATCH: 503,
169
- REPLICATION_SYNC_FAILED: 503,
170
- PARTITION_NOT_PRIMARY: 503,
171
- PARTITION_UNASSIGNED: 503,
172
- INSUFFICIENT_REPLICAS: 503,
173
- TRANSPORT_DEPENDENCY_MISSING: 500,
174
- ALLOCATION_INVALID_CONFIG: 400,
175
- ALLOCATION_NO_DATA_NODES: 503,
176
- ALLOCATION_FAILED: 503,
177
- NODE_ALREADY_JOINED: 409,
178
- NODE_NOT_JOINED: 503,
179
- NODE_NOT_READY: 503,
180
- NODE_NOT_CONTROLLER: 503,
181
- NODE_BOOTSTRAP_FAILED: 503,
182
- COORDINATOR_DEPENDENCY_MISSING: 500,
183
- SNAPSHOT_SYNC_UNAUTHORIZED: 403,
184
- SNAPSHOT_SYNC_REQUEST_INVALID: 400,
185
- SNAPSHOT_SYNC_HEADER_INVALID: 400,
186
- SNAPSHOT_SYNC_FRAME_INVALID: 400,
187
- SNAPSHOT_SYNC_INDEX_NOT_FOUND: 404,
188
- SNAPSHOT_SYNC_CHUNK_SIZE_EXCEEDED: 413,
189
- SNAPSHOT_SYNC_ABORTED: 409,
190
- SNAPSHOT_SYNC_CAPACITY_EXHAUSTED: 503,
191
- SNAPSHOT_SYNC_SNAPSHOT_FAILED: 503,
192
- SNAPSHOT_SYNC_DECODE_FAILED: 503,
193
- SNAPSHOT_SYNC_HEADER_MISMATCH: 503,
194
- SNAPSHOT_SYNC_CHUNK_OUT_OF_ORDER: 503,
195
- SNAPSHOT_SYNC_CHUNK_OVERFLOW: 503,
196
- SNAPSHOT_SYNC_CHUNK_MISSING: 503,
197
- SNAPSHOT_SYNC_END_MISSING: 503,
198
- SNAPSHOT_SYNC_CHECKSUM_MISMATCH: 503,
199
- SNAPSHOT_SYNC_PRIMARY_ERROR: 503,
200
- SNAPSHOT_SYNC_NO_TARGETS: 503,
201
- SNAPSHOT_SYNC_TRANSPORT_FAILED: 503,
202
- SNAPSHOT_SYNC_SCHEMA_UNAVAILABLE: 503,
203
- SNAPSHOT_SYNC_RESTORE_FAILED: 503,
204
- SNAPSHOT_SYNC_RESTORE_CLEANUP_FAILED: 503,
205
- SNAPSHOT_SYNC_TIMEOUT: 503,
206
- SNAPSHOT_SYNC_ALLOCATION_UNAVAILABLE: 503,
207
- SNAPSHOT_SYNC_NOT_ASSIGNED: 503,
208
- CONTROLLER_METADATA_INVALID: 500
209
- };
210
- function httpStatusForNarsilError(code) {
211
- return STATUS_BY_CODE[code] ?? 500;
212
- }
213
- function serializeNarsilError(err) {
214
- const hasDetails = err.details && Object.keys(err.details).length > 0;
215
- return hasDetails ? { code: err.code, message: err.message, details: err.details } : { code: err.code, message: err.message };
216
- }
217
- function toHttpError(err) {
218
- if (err instanceof NarsilError) {
219
- return { status: httpStatusForNarsilError(err.code), body: serializeNarsilError(err) };
220
- }
221
- return {
222
- status: 500,
223
- body: { code: ServerErrorCodes.INTERNAL_ERROR, message: "An unexpected error occurred" }
224
- };
225
- }
226
-
227
- // src/json-encoding.ts
228
- function toPlainNumbers(key, value) {
229
- if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
230
- return Array.from(value);
231
- }
232
- return value;
233
- }
234
- function encodeJson(value) {
235
- return JSON.stringify(value, toPlainNumbers);
236
- }
237
-
238
- // src/server/constants.ts
239
- var BYTES_PER_MB = 1024 * 1024;
240
- var DEFAULT_MAX_BODY_BYTES = 16 * BYTES_PER_MB;
241
- var DEFAULT_MAX_IMPORT_BYTES = 100 * BYTES_PER_MB;
242
- var DEFAULT_MAX_RESTORE_BYTES = 64 * 1024 * BYTES_PER_MB;
243
- var SPOOL_PAUSE_ABOVE_BYTES = 8 * BYTES_PER_MB;
244
- var SNAPSHOT_ARCHIVE_CONTENT_TYPE = "application/x-tar";
245
- var DOCUMENT_EXPORT_CONTENT_TYPE = "application/x-ndjson";
246
- var RELAY_STREAM_CHUNKS_IN_FLIGHT = 4;
247
- var DEFAULT_MAX_LINE_BYTES = 4 * BYTES_PER_MB;
248
- var DEFAULT_IMPORT_BATCH_SIZE = 1e3;
249
- var IMPORT_FLUSHES_IN_FLIGHT = 4;
250
- var DEFAULT_MAX_CONCURRENT_REQUESTS = 0;
251
- var DEFAULT_MAX_RESULT_WINDOW = 1e4;
252
- var DEFAULT_MAX_RERANK_WINDOW = 100;
253
- var DEFAULT_MAX_FETCH_DOCUMENTS = 1e4;
254
- var DEFAULT_MAX_IMPORT_ERRORS = 100;
255
- var DEFAULT_MAX_TASK_PAGE_SIZE = 1e3;
256
- var DEFAULT_MAX_CONCURRENT_TASKS = 4;
257
- var MIN_COUNTED_SERVER_LIMIT = 1;
258
- var MIN_UNBOUNDED_SERVER_LIMIT = 0;
259
- var RESPONSE_STREAM_THRESHOLD_BYTES = 64 * 1024;
260
- var MAX_INDEX_TOUCH_INTERVAL_MS = 1e3;
261
- var INDEX_TOUCH_INTERVALS_PER_IDLE_TIMEOUT = 4;
262
- var REQUEST_THREAD_DEPARTURE_DRAIN_MS = 100;
263
- var DEFAULT_MAX_RETAINED_TASKS = 1e3;
264
- var DEFAULT_TASK_PAGE_SIZE = 20;
265
- var TASK_PROGRESS_WRITE_INTERVAL_MS = 250;
266
- var RUNNING_TASK_TTL_MS = 24 * 60 * 60 * 1e3;
267
- var TERMINAL_TASK_TTL_MS = 60 * 60 * 1e3;
268
-
269
- // src/server/response.ts
270
- var STATUS_TEXT = {
271
- 200: "200 OK",
272
- 201: "201 Created",
273
- 202: "202 Accepted",
274
- 204: "204 No Content",
275
- 400: "400 Bad Request",
276
- 401: "401 Unauthorized",
277
- 403: "403 Forbidden",
278
- 404: "404 Not Found",
279
- 405: "405 Method Not Allowed",
280
- 409: "409 Conflict",
281
- 413: "413 Payload Too Large",
282
- 415: "415 Unsupported Media Type",
283
- 429: "429 Too Many Requests",
284
- 500: "500 Internal Server Error",
285
- 503: "503 Service Unavailable"
286
- };
287
- function statusLine(status) {
288
- return STATUS_TEXT[status] ?? `${status}`;
289
- }
290
- function streamBody(res, abort, body, status, headers) {
291
- if (abort.aborted) return;
292
- const totalSize = body.byteLength;
293
- res.cork(() => {
294
- res.writeStatus(statusLine(status));
295
- for (const [key, value] of headers) res.writeHeader(key, value);
296
- const startOffset = res.getWriteOffset();
297
- const [, done] = res.tryEnd(body, totalSize);
298
- if (done) return;
299
- res.onWritable((offset) => {
300
- if (abort.aborted) return true;
301
- const [retryOk] = res.tryEnd(body.subarray(offset - startOffset), totalSize);
302
- return retryOk;
303
- });
304
- });
305
- }
306
- function sendJson(res, data, status = 200, abort) {
307
- const payload = encodeJson(data);
308
- if (abort && payload !== void 0 && Buffer.byteLength(payload) >= RESPONSE_STREAM_THRESHOLD_BYTES) {
309
- streamBody(res, abort, Buffer.from(payload, "utf8"), status, [["Content-Type", "application/json"]]);
310
- return;
311
- }
312
- res.cork(() => {
313
- res.writeStatus(statusLine(status)).writeHeader("Content-Type", "application/json").end(payload);
314
- });
315
- }
316
- function sendError(res, status, code, message, details) {
317
- const body = { error: details ? { code, message, details } : { code, message } };
318
- const payload = encodeJson(body);
319
- res.cork(() => {
320
- res.writeStatus(statusLine(status)).writeHeader("Content-Type", "application/json").end(payload);
321
- });
322
- }
323
- async function sendStream(res, abort, source, headers) {
324
- const reader = source.getReader();
325
- let wake = null;
326
- abort.onAbort(() => wake?.());
327
- const waitUntilWritable = () => new Promise((resolve) => {
328
- wake = () => {
329
- wake = null;
330
- resolve();
331
- };
332
- res.onWritable(() => {
333
- wake?.();
334
- return true;
335
- });
336
- });
337
- let started = false;
338
- const begin = () => {
339
- if (started) return;
340
- started = true;
341
- res.writeStatus(statusLine(200));
342
- for (const [key, value] of headers) res.writeHeader(key, value);
343
- };
344
- try {
345
- for (; ; ) {
346
- const step = await reader.read();
347
- if (abort.aborted) {
348
- await reader.cancel().catch(() => void 0);
349
- return;
350
- }
351
- if (step.done) {
352
- res.cork(() => {
353
- begin();
354
- res.end();
355
- });
356
- return;
357
- }
358
- let writable = true;
359
- res.cork(() => {
360
- begin();
361
- writable = res.write(step.value);
362
- });
363
- if (!writable && !abort.aborted) await waitUntilWritable();
364
- }
365
- } catch (err) {
366
- await reader.cancel().catch(() => void 0);
367
- if (abort.aborted) return;
368
- if (!started) throw err;
369
- res.cork(() => {
370
- res.close();
371
- });
372
- }
373
- }
374
- function sendRelayed(res, abort, status, headers, body) {
375
- if (abort.aborted) return;
376
- if (body.byteLength >= RESPONSE_STREAM_THRESHOLD_BYTES) {
377
- streamBody(res, abort, body, status, headers);
378
- return;
379
- }
380
- res.cork(() => {
381
- res.writeStatus(statusLine(status));
382
- for (const [key, value] of headers) res.writeHeader(key, value);
383
- res.end(body);
384
- });
385
- }
386
-
387
- // src/server/handler-utils.ts
388
- function parseJson(ctx) {
389
- const raw = ctx.rawBody;
390
- if (!raw || raw.length === 0) {
391
- sendError(ctx.res, 400, ServerErrorCodes.EMPTY_BODY, "Request body is empty");
392
- return void 0;
393
- }
394
- try {
395
- return JSON.parse(raw.toString("utf8"));
396
- } catch {
397
- sendError(ctx.res, 400, ServerErrorCodes.INVALID_JSON, "Request body is not valid JSON");
398
- return void 0;
399
- }
400
- }
401
- function parseJsonOptional(ctx) {
402
- const raw = ctx.rawBody;
403
- if (!raw || raw.length === 0) return {};
404
- try {
405
- return JSON.parse(raw.toString("utf8"));
406
- } catch {
407
- sendError(ctx.res, 400, ServerErrorCodes.INVALID_JSON, "Request body is not valid JSON");
408
- return void 0;
409
- }
410
- }
411
- function respondError(ctx, err) {
412
- if (ctx.abort.aborted) return;
413
- const { status, body } = toHttpError(err);
414
- sendError(ctx.res, status, body.code, body.message, body.details);
415
- }
416
- function respondJson(ctx, data, status = 200) {
417
- if (ctx.abort.aborted) return;
418
- sendJson(ctx.res, data, status, ctx.abort);
419
- }
420
- function badRequest(res, message, details) {
421
- sendError(res, 400, ServerErrorCodes.INVALID_REQUEST, message, details);
422
- }
423
- function rejectInvalid(ctx, failure) {
424
- if (ctx.abort.aborted) return;
425
- badRequest(ctx.res, failure.message, failure.details);
426
- }
427
- function serializeBatchResult(result) {
428
- return {
429
- succeeded: result.succeeded,
430
- failed: result.failed.map((f) => ({
431
- docId: f.docId,
432
- error: f.error instanceof NarsilError ? serializeNarsilError(f.error) : { code: "INTERNAL_ERROR", message: String(f.error) }
433
- }))
434
- };
435
- }
436
-
437
- // src/server/regex-policy.ts
438
- function isRecord(value) {
439
- return value !== null && typeof value === "object" && !Array.isArray(value);
440
- }
441
- function regexFieldIn(expression, depth) {
442
- if (!isRecord(expression) || depth > MAX_FILTER_DEPTH) return null;
443
- if (isRecord(expression.fields)) {
444
- for (const [fieldPath, filter] of Object.entries(expression.fields)) {
445
- if (isRecord(filter) && Object.hasOwn(filter, "regex")) return fieldPath;
446
- }
447
- }
448
- for (const nested of [expression.and, expression.or]) {
449
- if (!Array.isArray(nested)) continue;
450
- for (const child of nested) {
451
- const found = regexFieldIn(child, depth + 1);
452
- if (found !== null) return found;
453
- }
454
- }
455
- return regexFieldIn(expression.not, depth + 1);
456
- }
457
- function refusedRegex(filters, allowRegex) {
458
- if (allowRegex) return null;
459
- const fieldPath = regexFieldIn(filters, 0);
460
- if (fieldPath === null) return null;
461
- return new NarsilError(
462
- ErrorCodes.SEARCH_INVALID_FILTER,
463
- `This server refuses every "regex" test, because its operator set the allowRegex server option to false. Test field "${fieldPath}" with "contains" or "wildcard"`,
464
- { fieldPath, operator: "regex", option: "allowRegex" }
465
- );
466
- }
467
- function refuseRegex(ctx, filters, allowRegex) {
468
- const refused = refusedRegex(filters, allowRegex);
469
- if (refused === null) return false;
470
- respondError(ctx, refused);
471
- return true;
472
- }
473
-
474
- // src/server/validation.ts
475
- function isPlainObject(value) {
476
- return typeof value === "object" && value !== null && !Array.isArray(value);
477
- }
478
- function overWindow(field, value, maxWindow) {
479
- if (typeof value === "number" && value > maxWindow) {
480
- return {
481
- message: `Field "${field}" exceeds the maximum result window of ${maxWindow}`,
482
- details: { value, limit: maxWindow }
483
- };
484
- }
485
- return null;
486
- }
487
- function overRerankWindow(rerank, maxRerankWindow) {
488
- if (!isPlainObject(rerank)) return null;
489
- const window = rerank.window;
490
- if (typeof window === "number" && window > maxRerankWindow) {
491
- return {
492
- message: `Field "rerank.window" exceeds this server's maximum rerank window of ${maxRerankWindow}`,
493
- details: { value: window, limit: maxRerankWindow }
494
- };
495
- }
496
- return null;
497
- }
498
- function withServerRerankWindow(params, limits) {
499
- const rerank = params.rerank;
500
- if (rerank === void 0 || !isPlainObject(rerank) || rerank.window !== void 0) return params;
501
- const depth = params.vector === void 0 ? void 0 : params.hybrid?.depth;
502
- const fuses = params.term !== void 0 || params.mode === "hybrid";
503
- const window = fuses && typeof depth === "number" && Number.isInteger(depth) ? Math.min(limits.maxRerankWindow, depth) : limits.maxRerankWindow;
504
- if (window >= DEFAULT_RERANK_WINDOW) return params;
505
- return { ...params, rerank: { ...rerank, window } };
506
- }
507
- function validateQuery(params, limits) {
508
- const maxWindow = limits.maxResultWindow;
509
- if (params.group && typeof params.group === "object" && "reduce" in params.group) {
510
- return {
511
- message: 'Custom group reducers are not available over HTTP; use "group.fields" and "group.maxPerGroup" only'
512
- };
513
- }
514
- const rowBound = overWindow("limit", params.limit, maxWindow) ?? overWindow("offset", params.offset, maxWindow);
515
- if (rowBound) return rowBound;
516
- const reranked = overRerankWindow(params.rerank, limits.maxRerankWindow);
517
- if (reranked) return reranked;
518
- if (params.group && typeof params.group === "object") {
519
- const grouped = overWindow("group.maxPerGroup", params.group.maxPerGroup, maxWindow) ?? overWindow("group.limit", params.group.limit, maxWindow);
520
- if (grouped) return grouped;
521
- }
522
- if (params.facets && typeof params.facets === "object") {
523
- for (const [field, facet] of Object.entries(params.facets)) {
524
- if (facet && typeof facet === "object") {
525
- const faceted = overWindow(`facets.${field}.limit`, facet.limit, maxWindow);
526
- if (faceted) return faceted;
527
- }
528
- }
529
- }
530
- return null;
531
- }
532
- function validateSuggest(params) {
533
- if (typeof params.prefix !== "string") {
534
- return { message: 'Field "prefix" is required and must be a string' };
535
- }
536
- return null;
537
- }
538
- function validateDocumentBody(body) {
539
- if (!isPlainObject(body.document)) {
540
- return { message: 'Field "document" is required and must be an object' };
541
- }
542
- return null;
543
- }
544
- function validateMultiGet(body, maxFetch) {
545
- if (!Array.isArray(body.docIds)) {
546
- return { message: 'Field "docIds" is required and must be an array of strings' };
547
- }
548
- if (body.docIds.length > maxFetch) {
549
- return {
550
- message: `Field "docIds" exceeds the maximum of ${maxFetch} ids per request`,
551
- details: { count: body.docIds.length, limit: maxFetch }
552
- };
553
- }
554
- return null;
555
- }
556
- function validateList(params, maxFetch) {
557
- if (params.cursor !== void 0 && typeof params.cursor !== "string") {
558
- return { message: 'Field "cursor" must be a string' };
559
- }
560
- if (params.limit !== void 0 && typeof params.limit !== "number") {
561
- return { message: 'Field "limit" must be a number' };
562
- }
563
- if (typeof params.limit === "number" && params.limit > maxFetch) {
564
- return {
565
- message: `Field "limit" exceeds the maximum of ${maxFetch} documents per request`,
566
- details: { value: params.limit, limit: maxFetch }
567
- };
568
- }
569
- return validateListSort(params.sort);
570
- }
571
- function validateListSort(sort) {
572
- if (sort === void 0) return null;
573
- if (typeof sort !== "object" || sort === null) {
574
- return { message: 'Field "sort" must be an object keyed by field name, or a list of fields' };
575
- }
576
- const entries = Array.isArray(sort) ? sort.map(
577
- (entry) => typeof entry === "object" && entry !== null ? [entry.field, entry.direction] : [entry, void 0]
578
- ) : Object.entries(sort);
579
- if (entries.length > MAX_SORT_FIELDS) {
580
- return {
581
- message: `Field "sort" exceeds the maximum of ${MAX_SORT_FIELDS} fields`,
582
- details: { count: entries.length, limit: MAX_SORT_FIELDS }
583
- };
584
- }
585
- for (const [field, direction] of entries) {
586
- if (typeof field !== "string" || field.length === 0) {
587
- return { message: 'Every entry of "sort" must name a field', details: { value: field } };
588
- }
589
- if (direction !== "asc" && direction !== "desc") {
590
- return { message: `Field "sort.${field}" must be "asc" or "desc"`, details: { value: direction } };
591
- }
592
- }
593
- return null;
594
- }
595
- function validateBatch(body) {
596
- const action = body.action ?? "insert";
597
- if (action === "insert") {
598
- if (!Array.isArray(body.documents)) return { message: 'Batch insert requires a "documents" array' };
599
- return null;
600
- }
601
- if (action === "update") {
602
- if (!Array.isArray(body.updates)) return { message: 'Batch update requires an "updates" array' };
603
- return null;
604
- }
605
- if (action === "delete") {
606
- if (!Array.isArray(body.docIds)) return { message: 'Batch delete requires a "docIds" array' };
607
- return null;
608
- }
609
- return { message: 'Field "action" must be one of "insert", "update", or "delete"' };
610
- }
611
- function validateCreateIndex(body) {
612
- if (typeof body.name !== "string" || body.name.length === 0) {
613
- return { message: 'Field "name" is required and must be a non-empty string' };
614
- }
615
- if (!isPlainObject(body.config)) {
616
- return { message: 'Field "config" is required and must be an object' };
617
- }
618
- return null;
619
- }
620
- function validateRebalance(body) {
621
- const target = body.targetPartitionCount;
622
- if (typeof target !== "number" || !Number.isInteger(target) || target <= 0) {
623
- return { message: 'Field "targetPartitionCount" is required and must be a positive integer' };
624
- }
625
- return null;
626
- }
627
- var TASK_TYPES = [
628
- "optimizeVectors",
629
- "rebalance",
630
- "restore",
631
- "import",
632
- "importExport",
633
- "rebuildAnalysis"
634
- ];
635
- var TASK_STATUSES = ["running", "succeeded", "failed", "cancelled"];
636
- function parseCountParam(raw, field, minimum) {
637
- if (raw === null) return minimum;
638
- const value = Number(raw);
639
- if (!Number.isInteger(value) || value < minimum) {
640
- return { message: `Query parameter "${field}" must be an integer of ${minimum} or more`, details: { value: raw } };
641
- }
642
- return value;
643
- }
644
- function parseEnumParam(raw, field, allowed) {
645
- if (raw === null) return void 0;
646
- const requested = raw.split(",").map((entry) => entry.trim());
647
- const unknown = requested.filter((entry) => !allowed.includes(entry));
648
- if (requested.length === 0 || unknown.length > 0) {
649
- return {
650
- message: `Query parameter "${field}" accepts only ${allowed.join(", ")}`,
651
- details: { unknown }
652
- };
653
- }
654
- return requested;
655
- }
656
- function isFailure(value) {
657
- return isPlainObject(value) && typeof value.message === "string";
658
- }
659
- function parseTaskListQuery(params, maxPageSize) {
660
- const type = parseEnumParam(params.get("type"), "type", TASK_TYPES);
661
- if (isFailure(type)) return { failure: type };
662
- const status = parseEnumParam(params.get("status"), "status", TASK_STATUSES);
663
- if (isFailure(status)) return { failure: status };
664
- const from = parseCountParam(params.get("from"), "from", 0);
665
- if (isFailure(from)) return { failure: from };
666
- const limit = parseCountParam(params.get("limit"), "limit", 1);
667
- if (isFailure(limit)) return { failure: limit };
668
- if (params.get("limit") !== null && limit > maxPageSize) {
669
- return {
670
- failure: {
671
- message: `Query parameter "limit" exceeds the maximum page size of ${maxPageSize}`,
672
- details: { value: limit, limit: maxPageSize }
673
- }
674
- };
675
- }
676
- const indexName = params.get("indexName");
677
- return {
678
- query: {
679
- ...indexName === null ? {} : { indexName },
680
- ...type === void 0 ? {} : { type },
681
- ...status === void 0 ? {} : { status },
682
- from,
683
- ...params.get("limit") === null ? {} : { limit }
684
- }
685
- };
686
- }
687
-
688
- // src/server/handlers/document-reads.ts
689
- function createDocumentReadHandlers(deps) {
690
- const { engine, limits, allowRegex } = deps;
691
- async function get(ctx) {
692
- try {
693
- const document = await engine.get(ctx.params[0], ctx.params[1]);
694
- if (document === void 0) {
695
- respondError(ctx, indexDocNotFound(ctx.params[1]));
696
- return;
697
- }
698
- respondJson(ctx, { document });
699
- } catch (err) {
700
- respondError(ctx, err);
701
- }
702
- }
703
- async function exists(ctx) {
704
- try {
705
- respondJson(ctx, { exists: await engine.has(ctx.params[0], ctx.params[1]) });
706
- } catch (err) {
707
- respondError(ctx, err);
708
- }
709
- }
710
- async function count(ctx) {
711
- try {
712
- respondJson(ctx, { count: await engine.countDocuments(ctx.params[0]) });
713
- } catch (err) {
714
- respondError(ctx, err);
715
- }
716
- }
717
- async function multiGet(ctx) {
718
- const body = parseJson(ctx);
719
- if (!body) return;
720
- const failure = validateMultiGet(body, limits.maxFetchDocuments);
721
- if (failure) {
722
- rejectInvalid(ctx, failure);
723
- return;
724
- }
725
- try {
726
- const found = await engine.getMultiple(ctx.params[0], body.docIds);
727
- const documents = {};
728
- for (const [id, doc] of found) documents[id] = doc;
729
- respondJson(ctx, { documents });
730
- } catch (err) {
731
- respondError(ctx, err);
732
- }
733
- }
734
- async function list(ctx) {
735
- const params = parseJson(ctx);
736
- if (!params) return;
737
- const failure = validateList(params, limits.maxFetchDocuments);
738
- if (failure) {
739
- rejectInvalid(ctx, failure);
740
- return;
741
- }
742
- if (refuseRegex(ctx, params.filters, allowRegex)) return;
743
- try {
744
- respondJson(ctx, await engine.listDocuments(ctx.params[0], params));
745
- } catch (err) {
746
- respondError(ctx, err);
747
- }
748
- }
749
- return { get, exists, count, multiGet, list };
750
- }
751
- function indexDocNotFound(docId) {
752
- return new NarsilError(ErrorCodes.DOC_NOT_FOUND, `Document "${docId}" not found`, { docId });
753
- }
754
-
755
- // src/vector/native/search-path.ts
756
- function vectorSearchPath() {
757
- return nativeSearchCoreIsEnabled() && loadNativeCore() !== null ? "native" : "wasm";
758
- }
759
-
760
- // src/server/handlers/version.ts
761
- function versionReport(build) {
762
- return { name: "narsil", ...build, vectorSearch: vectorSearchPath() };
763
- }
764
- function createVersionHandler(deps) {
765
- function report(ctx) {
766
- respondJson(ctx, versionReport(deps.build));
767
- }
768
- return { report };
769
- }
770
- var NotAdmittedError = class extends Error {
771
- };
772
- async function removeDirectory(directory) {
773
- if (directory !== null) await rm(directory, { recursive: true, force: true });
774
- }
775
- function spoolBody(res, maxBytes, abort, admitted) {
776
- return new Promise((resolve, reject) => {
777
- const state = {
778
- directory: null,
779
- handle: null,
780
- chain: Promise.resolve(),
781
- queued: 0,
782
- total: 0,
783
- paused: true,
784
- done: false
785
- };
786
- const fail = (error, answer) => {
787
- if (state.done) return;
788
- state.done = true;
789
- if (answer && !abort.aborted) {
790
- sendError(res, 500, ServerErrorCodes.INTERNAL_ERROR, "The server could not store the request body");
791
- }
792
- void state.chain.catch(() => void 0).then(async () => {
793
- await state.handle?.close().catch(() => void 0);
794
- await removeDirectory(state.directory).catch(() => void 0);
795
- }).finally(() => reject(error));
796
- };
797
- const failFromChain = (error) => {
798
- if (error instanceof NotAdmittedError) fail(error, false);
799
- else fail(error instanceof Error ? error : new Error(String(error)), true);
800
- };
801
- res.pause();
802
- state.chain = (async () => {
803
- if (!await admitted) throw new NotAdmittedError("the request was not admitted");
804
- state.directory = await mkdtemp(path.join(tmpdir(), "narsil-spool-"));
805
- state.handle = await open(path.join(state.directory, "body"), "w");
806
- if (!abort.aborted && !state.done && state.queued <= SPOOL_PAUSE_ABOVE_BYTES) {
807
- state.paused = false;
808
- res.resume();
809
- }
810
- })();
811
- state.chain.catch(failFromChain);
812
- abort.onAbort(() => fail(new Error("aborted"), false));
813
- res.onData((chunk, isLast) => {
814
- if (state.done || abort.aborted) return;
815
- state.total += chunk.byteLength;
816
- if (maxBytes > 0 && state.total > maxBytes) {
817
- sendError(res, 413, ServerErrorCodes.PAYLOAD_TOO_LARGE, "Request body exceeds the configured size limit");
818
- fail(new Error("payload too large"), false);
819
- return;
820
- }
821
- const copy = new Uint8Array(chunk.slice(0));
822
- state.queued += copy.byteLength;
823
- if (!state.paused && state.queued > SPOOL_PAUSE_ABOVE_BYTES) {
824
- state.paused = true;
825
- res.pause();
826
- }
827
- state.chain = state.chain.then(async () => {
828
- if (state.handle === null) throw new Error("the spool file is not open");
829
- await state.handle.write(copy);
830
- state.queued -= copy.byteLength;
831
- if (state.paused && state.queued <= SPOOL_PAUSE_ABOVE_BYTES && !abort.aborted && !state.done) {
832
- state.paused = false;
833
- res.resume();
834
- }
835
- });
836
- state.chain.catch(failFromChain);
837
- if (!isLast) return;
838
- state.chain.then(async () => {
839
- if (state.done) return;
840
- state.done = true;
841
- await state.handle?.close();
842
- resolve({
843
- path: path.join(state.directory ?? "", "body"),
844
- bytes: state.total,
845
- remove: () => removeDirectory(state.directory)
846
- });
847
- }, failFromChain);
848
- });
849
- });
850
- }
851
-
852
- // src/server/request.ts
853
- function initAbortHandler(res) {
854
- const listeners = [];
855
- let aborted = false;
856
- res.onAborted(() => {
857
- aborted = true;
858
- for (const fn of listeners) fn();
859
- });
860
- return {
861
- get aborted() {
862
- return aborted;
863
- },
864
- onAbort(fn) {
865
- if (aborted) fn();
866
- else listeners.push(fn);
867
- }
868
- };
869
- }
870
- function declaredBodyBytes(header) {
871
- return /^\d{1,15}$/.test(header) ? Number(header) : null;
872
- }
873
- function bodyWithRoomFor(body, filled, needed, maxBytes) {
874
- if (needed <= body.length) return body;
875
- const grown = Buffer.allocUnsafeSlow(Math.min(maxBytes, Math.max(needed, body.length * 2)));
876
- grown.set(body.subarray(0, filled));
877
- return grown;
878
- }
879
- function bodyOfExactly(body, filled) {
880
- if (filled === body.length) return body;
881
- const exact = Buffer.allocUnsafeSlow(filled);
882
- exact.set(body.subarray(0, filled));
883
- return exact;
884
- }
885
- function readBody(res, maxBytes, abort, declaredBytes = null) {
886
- return new Promise((resolve, reject) => {
887
- if (abort.aborted) {
888
- reject(new Error("aborted"));
889
- return;
890
- }
891
- let done = false;
892
- let total = 0;
893
- let filled = 0;
894
- let body = null;
895
- const reserved = declaredBytes !== null && declaredBytes <= maxBytes ? declaredBytes : 0;
896
- abort.onAbort(() => {
897
- if (done) return;
898
- done = true;
899
- reject(new Error("aborted"));
900
- });
901
- res.onData((chunk, isLast) => {
902
- if (done || abort.aborted) return;
903
- total += chunk.byteLength;
904
- if (total > maxBytes) {
905
- done = true;
906
- if (!abort.aborted) {
907
- sendError(res, 413, ServerErrorCodes.PAYLOAD_TOO_LARGE, "Request body exceeds the configured size limit");
908
- }
909
- reject(new Error("payload too large"));
910
- return;
911
- }
912
- const arrived = new Uint8Array(chunk);
913
- const firstSize = isLast ? arrived.length : Math.max(reserved, arrived.length);
914
- body = bodyWithRoomFor(body ?? Buffer.allocUnsafeSlow(firstSize), filled, total, maxBytes);
915
- body.set(arrived, filled);
916
- filled = total;
917
- if (isLast) {
918
- done = true;
919
- resolve(bodyOfExactly(body, filled));
920
- }
921
- });
922
- });
923
- }
924
- function decodePathParameter(raw) {
925
- if (!raw.includes("%")) return raw;
926
- try {
927
- return decodeURIComponent(raw);
928
- } catch {
929
- return null;
930
- }
931
- }
932
- function sinkWritingAfterStatus(res, headers) {
933
- if (headers.length === 0) return res;
934
- const sink = {
935
- cork(callback) {
936
- res.cork(callback);
937
- return sink;
938
- },
939
- writeStatus(status) {
940
- res.writeStatus(status);
941
- for (const [key, value] of headers) res.writeHeader(key, value);
942
- return sink;
943
- },
944
- writeHeader(key, value) {
945
- res.writeHeader(key, value);
946
- return sink;
947
- },
948
- end(body, closeConnection) {
949
- res.end(body, closeConnection);
950
- return sink;
951
- },
952
- write(chunk) {
953
- return res.write(chunk);
954
- },
955
- pause() {
956
- res.pause();
957
- },
958
- resume() {
959
- res.resume();
960
- },
961
- close() {
962
- res.close();
963
- return sink;
964
- },
965
- endWithoutBody() {
966
- res.endWithoutBody();
967
- return sink;
968
- },
969
- tryEnd(body, totalSize) {
970
- return res.tryEnd(body, totalSize);
971
- },
972
- getWriteOffset() {
973
- return res.getWriteOffset();
974
- },
975
- onWritable(handler) {
976
- res.onWritable(handler);
977
- return sink;
978
- },
979
- onAborted(handler) {
980
- res.onAborted(handler);
981
- return sink;
982
- },
983
- onData(handler) {
984
- res.onData(handler);
985
- return sink;
986
- },
987
- getRemoteAddressAsText() {
988
- return res.getRemoteAddressAsText();
989
- }
990
- };
991
- return sink;
992
- }
993
- function isDenial(value) {
994
- return typeof value === "object" && value !== null && "status" in value;
995
- }
996
- function authorizerFor(hook) {
997
- return async (context) => {
998
- try {
999
- const result = await hook(context);
1000
- if (isDenial(result)) return { allowed: false, denial: result };
1001
- return { allowed: true };
1002
- } catch {
1003
- return { allowed: false, denial: null };
1004
- }
1005
- };
1006
- }
1007
- function sendDenial(res, authorization) {
1008
- if (authorization.allowed) return;
1009
- if (authorization.denial === null) {
1010
- sendError(res, 500, ServerErrorCodes.HOOK_ERROR, "The onRequest hook threw an error");
1011
- return;
1012
- }
1013
- sendError(res, authorization.denial.status, authorization.denial.code, authorization.denial.message);
1014
- }
1015
- function createRouteRunner(deps) {
1016
- const { authorize, gate, corsHeaders, track } = deps;
1017
- return (handler, opts) => {
1018
- const paramCount = opts.paramCount ?? 0;
1019
- const needsBody = opts.needsBody ?? false;
1020
- const useHook = authorize !== void 0 && !opts.skipHooks;
1021
- const gated = !opts.skipHooks;
1022
- return (response, req) => {
1023
- const res = corsHeaders ? sinkWritingAfterStatus(response, corsHeaders(req)) : response;
1024
- const params = [];
1025
- let malformed = null;
1026
- for (let i = 0; i < paramCount; i++) {
1027
- const decoded = decodePathParameter(req.getParameter(i) ?? "");
1028
- if (decoded === null) {
1029
- malformed = req.getParameter(i) ?? "";
1030
- break;
1031
- }
1032
- params.push(decoded);
1033
- }
1034
- const query = new URLSearchParams(req.getQuery() ?? "");
1035
- const contentType = req.getHeader("content-type");
1036
- const declaredBytes = needsBody ? declaredBodyBytes(req.getHeader("content-length")) : null;
1037
- let hookContext = null;
1038
- if (useHook) {
1039
- const headers = {};
1040
- req.forEach((key, value) => {
1041
- headers[key] = value;
1042
- });
1043
- hookContext = {
1044
- method: req.getMethod().toUpperCase(),
1045
- path: req.getUrl(),
1046
- headers,
1047
- remoteAddress: Buffer.from(res.getRemoteAddressAsText()).toString()
1048
- };
1049
- }
1050
- const abort = initAbortHandler(res);
1051
- if (malformed !== null) {
1052
- sendError(
1053
- res,
1054
- 400,
1055
- ServerErrorCodes.INVALID_REQUEST,
1056
- "A path segment holds a percent-escape the server cannot decode",
1057
- { segment: malformed }
1058
- );
1059
- return;
1060
- }
1061
- const release = track?.(res, abort);
1062
- const bodyPromise = needsBody ? readBody(res, opts.maxBytes, abort, declaredBytes) : Promise.resolve(null);
1063
- const hookPromise = hookContext !== null && authorize !== void 0 ? authorize(hookContext) : Promise.resolve({ allowed: true });
1064
- const spoolPromise = opts.spoolsBody === true ? spoolBody(
1065
- res,
1066
- opts.maxBytes,
1067
- abort,
1068
- hookPromise.then((authorization) => authorization.allowed)
1069
- ).catch(() => null) : Promise.resolve(null);
1070
- const running = Promise.all([bodyPromise, spoolPromise, hookPromise]).then(async ([rawBody, spooledBody, authorization]) => {
1071
- const discardSpool = () => {
1072
- void spooledBody?.remove().catch(() => void 0);
1073
- };
1074
- if (abort.aborted) {
1075
- discardSpool();
1076
- return;
1077
- }
1078
- if (!authorization.allowed) {
1079
- discardSpool();
1080
- sendDenial(res, authorization);
1081
- return;
1082
- }
1083
- if (opts.spoolsBody === true && spooledBody === null) return;
1084
- if (gated && !gate.tryAcquire()) {
1085
- discardSpool();
1086
- sendError(res, 429, ServerErrorCodes.TOO_MANY_REQUESTS, "The server is at capacity; retry shortly");
1087
- return;
1088
- }
1089
- try {
1090
- await handler({ res, params, query, contentType, rawBody, spooledBody, abort, hookContext });
1091
- } catch (err) {
1092
- if (!abort.aborted) {
1093
- sendError(res, 500, ServerErrorCodes.INTERNAL_ERROR, "An unexpected error occurred");
1094
- }
1095
- } finally {
1096
- if (gated) gate.release();
1097
- }
1098
- }).catch(() => {
1099
- });
1100
- if (release !== void 0) void running.then(release);
1101
- };
1102
- };
1103
- }
1104
-
1105
- // src/server/routes.ts
1106
- function serverRoutes(limits) {
1107
- const { maxBodyBytes, maxImportBytes } = limits;
1108
- const probe = { maxBytes: 0, skipHooks: true };
1109
- const bare = { maxBytes: 0 };
1110
- const named = { paramCount: 1, maxBytes: 0 };
1111
- const namedBody = { paramCount: 1, needsBody: true, maxBytes: maxBodyBytes };
1112
- const document = { paramCount: 2, maxBytes: 0 };
1113
- const documentBody = { paramCount: 2, needsBody: true, maxBytes: maxBodyBytes };
1114
- return [
1115
- { method: "get", path: "/livez", handler: "livez", options: probe },
1116
- { method: "get", path: "/readyz", handler: "readyz", options: probe },
1117
- { method: "get", path: "/health", handler: "readyz", options: probe },
1118
- { method: "get", path: "/version", handler: "version", options: probe },
1119
- { method: "get", path: "/capabilities", handler: "capabilities", options: probe },
1120
- { method: "get", path: "/cluster", handler: "clusterTopology", options: bare },
1121
- { method: "get", path: "/stats/memory", handler: "memory", options: bare },
1122
- { method: "get", path: "/tasks", handler: "listTasks", options: bare },
1123
- { method: "get", path: "/tasks/:id", handler: "getTask", options: named },
1124
- { method: "post", path: "/tasks/:id/_cancel", handler: "cancelTask", options: named },
1125
- { method: "post", path: "/indexes", handler: "createIndex", options: { needsBody: true, maxBytes: maxBodyBytes } },
1126
- { method: "get", path: "/indexes", handler: "listIndexes", options: bare },
1127
- { method: "del", path: "/indexes/:name", handler: "dropIndex", options: named },
1128
- { method: "get", path: "/indexes/:name/stats", handler: "indexStats", options: named },
1129
- { method: "get", path: "/indexes/:name/partitions", handler: "indexPartitions", options: named },
1130
- { method: "get", path: "/indexes/:name/cluster", handler: "clusterAllocation", options: named },
1131
- { method: "post", path: "/indexes/:name/_clear", handler: "clearIndex", options: named },
1132
- { method: "post", path: "/indexes/:name/_open", handler: "openIndex", options: named },
1133
- { method: "post", path: "/indexes/:name/_close", handler: "closeIndex", options: named },
1134
- { method: "get", path: "/indexes/:name/count", handler: "count", options: named },
1135
- { method: "post", path: "/indexes/:name/documents", handler: "insert", options: namedBody },
1136
- { method: "post", path: "/indexes/:name/documents/_batch", handler: "batch", options: namedBody },
1137
- { method: "post", path: "/indexes/:name/documents/_list", handler: "list", options: namedBody },
1138
- { method: "post", path: "/indexes/:name/documents/_multi-get", handler: "multiGet", options: namedBody },
1139
- {
1140
- method: "post",
1141
- path: "/indexes/:name/documents/_import",
1142
- handler: "importNdjson",
1143
- options: { paramCount: 1, needsBody: true, maxBytes: maxImportBytes }
1144
- },
1145
- { method: "post", path: "/indexes/:name/_wait-for-writes", handler: "waitForWrites", options: named },
1146
- { method: "get", path: "/indexes/:name/documents/:id", handler: "get", options: document },
1147
- { method: "get", path: "/indexes/:name/documents/:id/_exists", handler: "exists", options: document },
1148
- { method: "put", path: "/indexes/:name/documents/:id", handler: "put", options: documentBody },
1149
- { method: "patch", path: "/indexes/:name/documents/:id", handler: "patch", options: documentBody },
1150
- { method: "del", path: "/indexes/:name/documents/:id", handler: "remove", options: document },
1151
- { method: "post", path: "/indexes/:name/search", handler: "search", options: namedBody },
1152
- { method: "post", path: "/indexes/:name/search/preflight", handler: "preflight", options: namedBody },
1153
- { method: "post", path: "/indexes/:name/suggest", handler: "suggest", options: namedBody },
1154
- { method: "post", path: "/indexes/:name/_checkpoint", handler: "checkpoint", options: named },
1155
- { method: "post", path: "/indexes/:name/_rebuild-analysis", handler: "rebuildAnalysis", options: named },
1156
- { method: "get", path: "/indexes/:name/snapshot", handler: "snapshot", options: named },
1157
- { method: "get", path: "/indexes/:name/vector-maintenance", handler: "vectorMaintenance", options: named },
1158
- { method: "post", path: "/indexes/:name/vectors/_compact", handler: "compact", options: namedBody },
1159
- { method: "post", path: "/indexes/:name/vectors/_optimize", handler: "optimize", options: namedBody },
1160
- { method: "post", path: "/indexes/:name/_rebalance", handler: "rebalance", options: namedBody },
1161
- { method: "post", path: "/indexes/:name/partition-config", handler: "partitionConfig", options: namedBody },
1162
- { method: "get", path: "/indexes/:name/synonyms", handler: "readSynonyms", options: named },
1163
- { method: "post", path: "/indexes/:name/synonyms", handler: "replaceSynonyms", options: namedBody },
1164
- {
1165
- method: "post",
1166
- path: "/indexes/:name/restore",
1167
- handler: "restore",
1168
- options: { paramCount: 1, spoolsBody: true, maxBytes: limits.maxRestoreBytes }
1169
- },
1170
- { method: "get", path: "/indexes/:name/export", handler: "exportDocuments", options: named },
1171
- {
1172
- method: "post",
1173
- path: "/indexes/:name/import",
1174
- handler: "importExport",
1175
- options: { paramCount: 1, spoolsBody: true, maxBytes: limits.maxRestoreBytes }
1176
- }
1177
- ];
1178
- }
1179
- function registerServerRoutes(app, run, handlers, limits, cors) {
1180
- if (cors) {
1181
- app.options("/*", (res, req) => {
1182
- const origin = req.getHeader("origin");
1183
- res.cork(() => {
1184
- res.writeStatus("204 No Content");
1185
- writeCorsOrigin(res, cors, origin);
1186
- res.writeHeader("Access-Control-Allow-Methods", cors.methods).writeHeader("Access-Control-Allow-Headers", cors.headers).writeHeader("Access-Control-Max-Age", "86400").endWithoutBody();
1187
- });
1188
- });
1189
- }
1190
- for (const route of serverRoutes(limits)) {
1191
- app[route.method](route.path, run(handlers[route.handler], route.options));
1192
- }
1193
- const corsHeaders = cors ? corsHeaderReader(cors) : null;
1194
- app.any("/*", (res, req) => {
1195
- const sink = corsHeaders === null ? res : sinkWritingAfterStatus(res, corsHeaders(req));
1196
- sendError(sink, 404, ServerErrorCodes.NOT_FOUND, "Route not found");
1197
- });
1198
- }
1199
-
1200
- // src/server/runtime.ts
1201
- var cached = null;
1202
- async function loadUWebSockets() {
1203
- if (cached) return cached;
1204
- try {
1205
- const mod = await import('uWebSockets.js');
1206
- const resolved = typeof mod.App === "function" ? mod : mod.default;
1207
- if (!resolved || typeof resolved.App !== "function") {
1208
- throw new Error("uWebSockets.js did not expose an App factory");
1209
- }
1210
- cached = resolved;
1211
- return resolved;
1212
- } catch (err) {
1213
- throw new NarsilError(
1214
- ErrorCodes.CONFIG_INVALID,
1215
- "The `uWebSockets.js` package is required to run the Narsil HTTP server. Install it with `pnpm add github:uNetworking/uWebSockets.js#v20.58.0` (or the npm or yarn equivalent).",
1216
- { cause: err instanceof Error ? err.message : String(err) }
1217
- );
1218
- }
1219
- }
1220
-
1221
- // src/server/request-threads/acceptor.ts
1222
- function acceptorOf(app) {
1223
- const candidate = app;
1224
- if (typeof candidate.addChildAppDescriptor !== "function") return null;
1225
- if (typeof candidate.removeChildAppDescriptor !== "function") return null;
1226
- return candidate;
1227
- }
1228
- function childAppOf(app) {
1229
- const candidate = app;
1230
- if (typeof candidate.getDescriptor !== "function" || typeof candidate.close !== "function") return null;
1231
- return candidate;
1232
- }
1233
-
1234
- // src/server/request-threads/departure.ts
1235
- var DEPARTURE_WORD = 0;
1236
- var AWAITING_DEPARTURE = 0;
1237
- var DEPARTURE_CONFIRMED = 1;
1238
- function createDepartureWord() {
1239
- return new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
1240
- }
1241
- function confirmDeparture(word) {
1242
- Atomics.store(word, DEPARTURE_WORD, DEPARTURE_CONFIRMED);
1243
- Atomics.notify(word, DEPARTURE_WORD);
1244
- }
1245
- function departureConfirmed(word) {
1246
- return Atomics.load(word, DEPARTURE_WORD) === DEPARTURE_CONFIRMED;
1247
- }
1248
- function awaitDepartureConfirmation(word) {
1249
- while (!departureConfirmed(word)) Atomics.wait(word, DEPARTURE_WORD, AWAITING_DEPARTURE);
1250
- }
1251
- async function departureConfirmation(word) {
1252
- const waiting = Atomics.waitAsync(word, DEPARTURE_WORD, AWAITING_DEPARTURE);
1253
- if (waiting.async) await waiting.value;
1254
- }
1255
-
1256
- export { ASYNC_IMPORT_CAPABILITY, DEFAULT_IMPORT_BATCH_SIZE, DEFAULT_MAX_BODY_BYTES, DEFAULT_MAX_CONCURRENT_REQUESTS, DEFAULT_MAX_CONCURRENT_TASKS, DEFAULT_MAX_FETCH_DOCUMENTS, DEFAULT_MAX_IMPORT_BYTES, DEFAULT_MAX_IMPORT_ERRORS, DEFAULT_MAX_LINE_BYTES, DEFAULT_MAX_RERANK_WINDOW, DEFAULT_MAX_RESTORE_BYTES, DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_RETAINED_TASKS, DEFAULT_MAX_TASK_PAGE_SIZE, DEFAULT_TASK_PAGE_SIZE, DOCUMENT_EXPORT_CAPABILITY, DOCUMENT_EXPORT_CONTENT_TYPE, IMPORT_FLUSHES_IN_FLIGHT, INDEX_LIFECYCLE_CAPABILITY, INDEX_TOUCH_INTERVALS_PER_IDLE_TIMEOUT, MAIN_THREAD_GATE_SLOT, MAX_INDEX_TOUCH_INTERVAL_MS, MIN_COUNTED_SERVER_LIMIT, MIN_UNBOUNDED_SERVER_LIMIT, REBUILD_ANALYSIS_CAPABILITY, RELAY_STREAM_CHUNKS_IN_FLIGHT, REQUEST_THREAD_DEPARTURE_DRAIN_MS, RUNNING_TASK_TTL_MS, SERVER_CAPABILITIES, SNAPSHOT_ARCHIVE_CONTENT_TYPE, SYNONYMS_CAPABILITY, TASK_CANCEL_CAPABILITY, TASK_FILTER_CAPABILITY, TASK_PROGRESS_WRITE_INTERVAL_MS, TERMINAL_TASK_TTL_MS, acceptorOf, authorizerFor, awaitDepartureConfirmation, badRequest, childAppOf, clearGateSlot, confirmDeparture, corsHeaderReader, createDepartureWord, createDocumentReadHandlers, createRouteRunner, createSharedGateBuffer, createSharedRequestGate, createVersionHandler, departureConfirmation, departureConfirmed, encodeJson, gateSlotOfWorker, httpStatusForNarsilError, loadUWebSockets, parseJson, parseJsonOptional, parseTaskListQuery, refuseRegex, registerServerRoutes, rejectInvalid, resolveCors, respondError, respondJson, sendError, sendRelayed, sendStream, serializeBatchResult, serializeNarsilError, serverRoutes, statusLine, toHttpError, validateBatch, validateCreateIndex, validateDocumentBody, validateQuery, validateRebalance, validateSuggest, versionReport, withServerRerankWindow };