@delali/narsil 0.4.1 → 0.4.2-next.273

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/README.md +1 -1
  2. package/dist/adapters/filesystem.d.ts +1 -1
  3. package/dist/adapters/filesystem.mjs +9 -3
  4. package/dist/adapters/gcs.d.ts +1 -1
  5. package/dist/adapters/indexeddb.d.ts +6 -1
  6. package/dist/adapters/indexeddb.mjs +20 -26
  7. package/dist/adapters/memory.d.ts +1 -1
  8. package/dist/adapters/s3.d.ts +1 -1
  9. package/dist/{adapters-pljAqmrC.d.ts → adapters-8LcdNB77.d.ts} +18 -1
  10. package/dist/browser/{chunk-QAOVAYAG.mjs → chunk-56UNHLAF.mjs} +1 -1
  11. package/dist/browser/{chunk-GBJSEHVJ.mjs → chunk-EKISQBV2.mjs} +283 -244
  12. package/dist/browser/{chunk-YINZFPLT.mjs → chunk-VAPCFSMX.mjs} +1 -1
  13. package/dist/browser/{chunk-4E5APHTM.mjs → chunk-VIVG3OXM.mjs} +1 -1
  14. package/dist/browser/{durability-config-75NSFCQN.mjs → durability-config-UP3OTUMB.mjs} +34 -2
  15. package/dist/browser/{msgpack-leaf-44XNWSSY.mjs → msgpack-leaf-76Q5SZ5S.mjs} +23 -10
  16. package/dist/browser/{optional-reads-6LN3HMUH.mjs → optional-reads-NQO5DKM4.mjs} +18 -16
  17. package/dist/browser/{optional-writes-76DWMRQH.mjs → optional-writes-3HKIVZFU.mjs} +295 -106
  18. package/dist/browser/{segment-codec-leaf-A427QJUX.mjs → segment-codec-leaf-GXSRX5VT.mjs} +47 -30
  19. package/dist/browser/{storage-leaf-5UTR5K7J.mjs → storage-leaf-42IZEOJJ.mjs} +1473 -305
  20. package/dist/{capabilities-BOFFMx84.d.ts → capabilities-BoWiLNv7.d.ts} +76 -61
  21. package/dist/{chunk-Z7XSHKOF.mjs → chunk-35RWLUVY.mjs} +63 -144
  22. package/dist/{chunk-6GHX35ZM.mjs → chunk-43T3P3BE.mjs} +1 -1
  23. package/dist/{chunk-IL5DRCNU.mjs → chunk-4JLHHEBN.mjs} +1 -1
  24. package/dist/{chunk-DKIMHIBC.mjs → chunk-4YIVY3PB.mjs} +2 -2
  25. package/dist/{react-native/chunks/chunk-ZUJCUPVS.mjs → chunk-5SHWA6PE.mjs} +1 -1
  26. package/dist/{chunk-2K24MEYV.mjs → chunk-6LVQ3GLT.mjs} +3 -3
  27. package/dist/{chunk-DDUXEJXW.mjs → chunk-6SIEVWMG.mjs} +45 -22
  28. package/dist/{chunk-WM5KJSQV.mjs → chunk-ACNHJOGC.mjs} +1 -1
  29. package/dist/{chunk-755NM4PL.mjs → chunk-BWPVDIRN.mjs} +183 -21
  30. package/dist/{chunk-SMQPZHPS.mjs → chunk-C57GWAXN.mjs} +1 -1
  31. package/dist/{chunk-357KIU5E.mjs → chunk-DRZP5MSG.mjs} +5 -5
  32. package/dist/{chunk-MYN4K5IS.mjs → chunk-DZMD4OMD.mjs} +1 -1
  33. package/dist/{chunk-7P5YWDRQ.mjs → chunk-EY5U4P5V.mjs} +1 -1
  34. package/dist/{chunk-X3EQCQLP.mjs → chunk-EZJ6HBG7.mjs} +2 -2
  35. package/dist/{chunk-WC5KAWXQ.mjs → chunk-FE2XILWN.mjs} +4 -4
  36. package/dist/{chunk-CERPUGRK.mjs → chunk-G3KVEHIW.mjs} +2 -2
  37. package/dist/{chunk-B3MO37YF.mjs → chunk-GTGQLCEI.mjs} +1 -1
  38. package/dist/{chunk-MSJD74GN.mjs → chunk-H23FB267.mjs} +5 -5
  39. package/dist/{chunk-UNEEFTEU.mjs → chunk-HZ3OAUTL.mjs} +2 -1
  40. package/dist/{chunk-M3B7SGJB.mjs → chunk-KL4ORYJW.mjs} +6 -6
  41. package/dist/{chunk-WTMCGZ74.mjs → chunk-KXA77DPZ.mjs} +2 -2
  42. package/dist/{chunk-6I6OO6B2.mjs → chunk-LRIJ7U3T.mjs} +4 -4
  43. package/dist/{chunk-3IE3A74H.mjs → chunk-PNFP5THV.mjs} +3 -3
  44. package/dist/{react-native/chunks/chunk-4FUCRLSA.mjs → chunk-PQWK7KXS.mjs} +1 -1
  45. package/dist/{chunk-P4F4UWLC.mjs → chunk-PSO7V7VW.mjs} +17 -3
  46. package/dist/{chunk-OGYSPNL2.mjs → chunk-QNZJYMCF.mjs} +7 -7
  47. package/dist/{chunk-DBC4EJWB.mjs → chunk-R3PFPFME.mjs} +1 -1
  48. package/dist/{chunk-MSIN4NM3.mjs → chunk-S3JHYPH7.mjs} +6 -1
  49. package/dist/{chunk-MI6UZGUR.mjs → chunk-SPA7GXST.mjs} +3 -3
  50. package/dist/{chunk-PP3W5PQQ.mjs → chunk-WYH3QHBK.mjs} +698 -451
  51. package/dist/{chunk-D456ZFPQ.mjs → chunk-X5V25BPN.mjs} +2 -2
  52. package/dist/{chunk-GXCDWLQI.mjs → chunk-Y7GXGJFZ.mjs} +23 -10
  53. package/dist/{chunk-NCIGNQJE.mjs → chunk-YGRJLI2Z.mjs} +930 -387
  54. package/dist/{react-native/chunks/chunk-MMPBO4WR.mjs → chunk-ZO7VLAIT.mjs} +2 -2
  55. package/dist/{chunk-AXDB6KUQ.mjs → chunk-ZTB7AWTW.mjs} +4 -4
  56. package/dist/chunk-ZYEEOZTT.mjs +52 -0
  57. package/dist/{client-BhNxHtcZ.d.ts → client-B0NPZSKY.d.ts} +4 -4
  58. package/dist/client.d.ts +9 -9
  59. package/dist/client.mjs +2 -2
  60. package/dist/{config-P9zW3Zz7.d.ts → config-B3-sw887.d.ts} +3 -3
  61. package/dist/{config-BJSL7piq.d.ts → config-DL_nkguq.d.ts} +4 -4
  62. package/dist/{direct-executor-GWJXDFLD.mjs → direct-executor-7G57AYXH.mjs} +4 -4
  63. package/dist/distribution/coordinator/etcd.d.ts +3 -3
  64. package/dist/distribution/coordinator/etcd.mjs +33 -3
  65. package/dist/distribution/coordinator/in-memory.d.ts +3 -3
  66. package/dist/distribution/transport/grpc.mjs +4 -4
  67. package/dist/distribution/transport/in-memory.mjs +1 -1
  68. package/dist/distribution/transport/tcp.mjs +12 -7
  69. package/dist/distribution.d.ts +8 -8
  70. package/dist/distribution.mjs +167 -91
  71. package/dist/{durability-config-VWS2K24E.mjs → durability-config-HWKWP35M.mjs} +34 -2
  72. package/dist/embeddings/openai.d.ts +7 -3
  73. package/dist/embeddings/openai.mjs +37 -31
  74. package/dist/{engine-DoFnkRoF.d.ts → engine-DGG_yX0p.d.ts} +3 -3
  75. package/dist/{index-B_vmxpgW.d.ts → index-fX_FbuRT.d.ts} +1 -1
  76. package/dist/index.browser.mjs +3 -3
  77. package/dist/index.d.ts +7 -7
  78. package/dist/index.mjs +4 -4
  79. package/dist/index.react-native.mjs +4 -4
  80. package/dist/invalidation/broadcast-channel.d.ts +1 -1
  81. package/dist/invalidation/filesystem.d.ts +1 -1
  82. package/dist/invalidation/noop.d.ts +1 -1
  83. package/dist/{long-query-thread-GNTDYDOZ.mjs → long-query-thread-KPN7NSOC.mjs} +14 -14
  84. package/dist/msgpack-leaf-LIT7TKZW.mjs +9 -0
  85. package/dist/{optional-reads-UCS23AWP.mjs → optional-reads-ESDVS225.mjs} +18 -16
  86. package/dist/{optional-writes-2AHJCGTY.mjs → optional-writes-CSULLISE.mjs} +9 -8
  87. package/dist/{paged-partition-archive-GBAHDT55.mjs → paged-partition-archive-BKQADXOT.mjs} +13 -13
  88. package/dist/partial-words.browser.mjs +3 -3
  89. package/dist/partial-words.mjs +4 -4
  90. package/dist/pattern.browser.mjs +2 -2
  91. package/dist/pattern.mjs +2 -2
  92. package/dist/persistence/durability/checkpoint-worker.d.ts +2 -2
  93. package/dist/persistence/durability/checkpoint-worker.mjs +14 -14
  94. package/dist/{query-actions-IDCUA7UV.mjs → query-actions-HTSJKZRU.mjs} +4 -4
  95. package/dist/query-suggestions/merge-worker.mjs +7 -7
  96. package/dist/query-suggestions.browser.mjs +3 -3
  97. package/dist/query-suggestions.d.ts +3 -3
  98. package/dist/query-suggestions.mjs +5 -5
  99. package/dist/react-native/chunks/{chunk-MRH36RN3.mjs → chunk-AOLLV37A.mjs} +1 -1
  100. package/dist/react-native/chunks/{chunk-UO44MA5M.mjs → chunk-DN4FT62B.mjs} +23 -10
  101. package/dist/react-native/chunks/{chunk-TG56N5JC.mjs → chunk-EF4Y5C3Y.mjs} +2 -2
  102. package/dist/react-native/chunks/{chunk-HTBY4GON.mjs → chunk-ESVBC3AT.mjs} +1 -1
  103. package/dist/{chunk-F26DOOUH.mjs → react-native/chunks/chunk-H6LK5WCF.mjs} +1 -1
  104. package/dist/react-native/chunks/{chunk-LPX26NNL.mjs → chunk-JEYZQA4Z.mjs} +699 -451
  105. package/dist/react-native/chunks/{chunk-AJAH6X7W.mjs → chunk-KJQ3BUVM.mjs} +4 -4
  106. package/dist/{chunk-UHLFCGZ3.mjs → react-native/chunks/chunk-QYVRD6C5.mjs} +2 -2
  107. package/dist/react-native/chunks/{chunk-SCGBU47K.mjs → chunk-X3VY2YT4.mjs} +2 -2
  108. package/dist/{chunk-R2PJKSNL.mjs → react-native/chunks/chunk-ZF3VSGEI.mjs} +1 -1
  109. package/dist/react-native/chunks/{durability-config-FCSD4MXY.mjs → durability-config-HJETGZVB.mjs} +34 -2
  110. package/dist/react-native/chunks/msgpack-leaf-FOUPTT7J.mjs +7 -0
  111. package/dist/react-native/chunks/{optional-reads-4XCJ34QG.mjs → optional-reads-TN3PT6M4.mjs} +18 -16
  112. package/dist/react-native/chunks/{optional-writes-XYZVTBFB.mjs → optional-writes-MGFFGKYQ.mjs} +8 -7
  113. package/dist/react-native/chunks/{restore-queue-NOKQZJ2Z.mjs → restore-queue-MVJTP3E4.mjs} +7 -7
  114. package/dist/react-native/chunks/{segment-codec-leaf-3ZXBJVKH.mjs → segment-codec-leaf-PSWHL55A.mjs} +5 -5
  115. package/dist/react-native/chunks/{segment-merge-leaf-3Z7MMPWE.mjs → segment-merge-leaf-WOJWSDLW.mjs} +6 -6
  116. package/dist/react-native/chunks/{storage-leaf-KJOX3MMW.mjs → storage-leaf-ZUN6Y44X.mjs} +1481 -314
  117. package/dist/react-native/chunks/{store-leaf-QGLVSO5X.mjs → store-leaf-K5XG46FV.mjs} +6 -6
  118. package/dist/react-native/chunks/{suggestions-leaf-6GI5ZSW6.mjs → suggestions-leaf-KDPM3P27.mjs} +6 -6
  119. package/dist/react-native/chunks/{worker-copies-ALOD7TSP.mjs → worker-copies-FVFMBBH6.mjs} +5 -5
  120. package/dist/react-native/partial-words.mjs +4 -4
  121. package/dist/react-native/pattern.mjs +2 -2
  122. package/dist/react-native/query-suggestions.mjs +4 -4
  123. package/dist/react-native/sync.mjs +4 -4
  124. package/dist/react-native/synonyms.mjs +4 -4
  125. package/dist/react.d.ts +10 -10
  126. package/dist/react.mjs +0 -2
  127. package/dist/{rerank-HB6DU6GS.mjs → rerank-3QEJNMFH.mjs} +4 -4
  128. package/dist/rerankers/http.d.ts +1 -1
  129. package/dist/rerankers/http.mjs +19 -15
  130. package/dist/{restore-queue-VUQHGCXE.mjs → restore-queue-Q76Q4S35.mjs} +7 -7
  131. package/dist/{schema-CzG9OUw5.d.ts → schema-CFnQ-WI3.d.ts} +1 -1
  132. package/dist/{segment-codec-leaf-TW2FPAAT.mjs → segment-codec-leaf-BSDDR7DQ.mjs} +5 -5
  133. package/dist/{segment-merge-leaf-BS3QV5PZ.mjs → segment-merge-leaf-6TT66HC5.mjs} +5 -5
  134. package/dist/server.d.ts +86 -12
  135. package/dist/server.mjs +2243 -1918
  136. package/dist/{storage-leaf-5IG2HPNY.mjs → storage-leaf-R5JQ2X2M.mjs} +1193 -219
  137. package/dist/{store-leaf-ZWSOK2DV.mjs → store-leaf-NCGETZYY.mjs} +6 -6
  138. package/dist/{suggestions-leaf-MUZNKQVF.mjs → suggestions-leaf-TX3GTD6S.mjs} +8 -8
  139. package/dist/sync/filesystem.d.ts +4 -4
  140. package/dist/sync/filesystem.mjs +12 -12
  141. package/dist/sync/indexeddb.browser.mjs +1 -1
  142. package/dist/sync/indexeddb.d.ts +4 -4
  143. package/dist/sync/indexeddb.mjs +2 -2
  144. package/dist/sync.browser.mjs +4 -4
  145. package/dist/sync.d.ts +5 -5
  146. package/dist/sync.mjs +4 -4
  147. package/dist/synonyms.browser.mjs +3 -3
  148. package/dist/synonyms.mjs +4 -4
  149. package/dist/{tasks-DrLiolTG.d.ts → tasks-B2MDjPL0.d.ts} +4 -4
  150. package/dist/{thread-6ZBCENAP.mjs → thread-VLVPAUWC.mjs} +13 -13
  151. package/dist/{types-pS-mAJmX.d.ts → types-DGjk684l.d.ts} +2 -2
  152. package/dist/vector/search-worker.d.ts +2 -2
  153. package/dist/{worker-copies-32HWFUH7.mjs → worker-copies-NZSBQZKG.mjs} +7 -7
  154. package/dist/workers/entry.mjs +16 -16
  155. package/package.json +12 -12
  156. package/dist/chunk-HLPRHOSO.mjs +0 -17
  157. package/dist/msgpack-leaf-H5ZYW7S7.mjs +0 -9
  158. package/dist/react-native/chunks/msgpack-leaf-JMNGSTRW.mjs +0 -7
@@ -1,7 +1,65 @@
1
- import { E as EmbeddingAdapter, R as RerankAdapter } from './adapters-pljAqmrC.js';
2
- import { C as ClusterNamespace } from './config-BJSL7piq.js';
1
+ import { E as EmbeddingAdapter, R as RerankAdapter } from './adapters-8LcdNB77.js';
2
+ import { C as ClusterNamespace } from './config-DL_nkguq.js';
3
3
  import { l as RecordedQuery } from './query-suggestions-CBYkrQ5T.js';
4
- import { E as ErrorDetail, j as TaskStore } from './tasks-DrLiolTG.js';
4
+ import { E as ErrorDetail, j as TaskStore } from './tasks-B2MDjPL0.js';
5
+
6
+ /**
7
+ * The settings of the device sync routes, `GET /indexes/{name}/sync/snapshot`
8
+ * and the feed at `GET /indexes/{name}/sync/feed`. Every field has a default.
9
+ *
10
+ * @public
11
+ */
12
+ interface ServerSyncOptions {
13
+ /**
14
+ * The server stops sending entries to a device while the entries that it
15
+ * has sent, and that the device has not acknowledged, hold more than this
16
+ * many bytes. It defaults to 8,388,608.
17
+ */
18
+ windowBytes?: number;
19
+ /** The server holds at most this many feed connections, and it answers 429 to one more. It defaults to 10,000. */
20
+ maxConnections?: number;
21
+ /**
22
+ * The server reads the history of at most this many feed connections at
23
+ * once, and it holds any other connection until one of those reads ends.
24
+ * It defaults to 32.
25
+ */
26
+ maxCatchUps?: number;
27
+ /**
28
+ * The server stops reading entries for every feed while its feed
29
+ * connections hold this many bytes that the network has not yet taken. It
30
+ * defaults to 268,435,456.
31
+ */
32
+ maxBufferedBytes?: number;
33
+ }
34
+ /**
35
+ * The settings of the change feed at `GET /indexes/{name}/changes/feed`. Every
36
+ * field has a default, and the server counts the connections and the
37
+ * catch-ups of this feed apart from those of the device sync feed.
38
+ *
39
+ * @public
40
+ */
41
+ interface ServerChangesOptions {
42
+ /**
43
+ * The server stops sending changes to a subscriber while the changes that
44
+ * it has sent, and that the subscriber has not acknowledged, hold more than
45
+ * this many bytes. It defaults to 8,388,608.
46
+ */
47
+ windowBytes?: number;
48
+ /** The server holds at most this many change feed connections, and it answers 429 to one more. It defaults to 10,000. */
49
+ maxConnections?: number;
50
+ /**
51
+ * The server reads the history of at most this many change feed
52
+ * connections at once, and it holds any other connection until one of
53
+ * those reads ends. It defaults to 32.
54
+ */
55
+ maxCatchUps?: number;
56
+ /**
57
+ * The server stops reading changes for every subscriber while its change
58
+ * feed connections hold this many bytes that the network has not yet
59
+ * taken. It defaults to 268,435,456.
60
+ */
61
+ maxBufferedBytes?: number;
62
+ }
5
63
 
6
64
  /**
7
65
  * Context handed to {@link OnRequestHook} for every inbound request, captured
@@ -64,63 +122,6 @@ interface RequestGrant {
64
122
  * @public
65
123
  */
66
124
  type OnRequestHook = (ctx: RequestContext) => undefined | RequestDenial | RequestGrant | Promise<undefined | RequestDenial | RequestGrant>;
67
- /**
68
- * The settings of the device sync routes, `GET /indexes/{name}/sync/snapshot`
69
- * and the feed at `GET /indexes/{name}/sync/feed`. Every field has a default.
70
- *
71
- * @public
72
- */
73
- interface ServerSyncOptions {
74
- /**
75
- * The server stops sending entries to a device while the entries that it
76
- * has sent, and that the device has not acknowledged, hold more than this
77
- * many bytes. It defaults to 8,388,608.
78
- */
79
- windowBytes?: number;
80
- /** The server holds at most this many feed connections, and it answers 429 to one more. It defaults to 10,000. */
81
- maxConnections?: number;
82
- /**
83
- * The server reads the history of at most this many feed connections at
84
- * once, and it holds any other connection until one of those reads ends.
85
- * It defaults to 32.
86
- */
87
- maxCatchUps?: number;
88
- /**
89
- * The server stops reading entries for every feed while its feed
90
- * connections hold this many bytes that the network has not yet taken. It
91
- * defaults to 268,435,456.
92
- */
93
- maxBufferedBytes?: number;
94
- }
95
- /**
96
- * The settings of the change feed at `GET /indexes/{name}/changes/feed`. Every
97
- * field has a default, and the server counts the connections and the
98
- * catch-ups of this feed apart from those of the device sync feed.
99
- *
100
- * @public
101
- */
102
- interface ServerChangesOptions {
103
- /**
104
- * The server stops sending changes to a subscriber while the changes that
105
- * it has sent, and that the subscriber has not acknowledged, hold more than
106
- * this many bytes. It defaults to 8,388,608.
107
- */
108
- windowBytes?: number;
109
- /** The server holds at most this many change feed connections, and it answers 429 to one more. It defaults to 10,000. */
110
- maxConnections?: number;
111
- /**
112
- * The server reads the history of at most this many change feed
113
- * connections at once, and it holds any other connection until one of
114
- * those reads ends. It defaults to 32.
115
- */
116
- maxCatchUps?: number;
117
- /**
118
- * The server stops reading changes for every subscriber while its change
119
- * feed connections hold this many bytes that the network has not yet
120
- * taken. It defaults to 268,435,456.
121
- */
122
- maxBufferedBytes?: number;
123
- }
124
125
  /**
125
126
  * Which cross-origin requests the server accepts.
126
127
  *
@@ -356,7 +357,21 @@ interface NarsilServer {
356
357
  * address is configured without an authentication hook.
357
358
  */
358
359
  listen(): Promise<void>;
359
- /** Closes the socket and ends the server. The engine keeps running. */
360
+ /**
361
+ * Stops accepting connections and resolves once the server holds none. A new
362
+ * request on a connection that is already open gets a 503 that closes the
363
+ * connection, and a running request gets up to 30 seconds to finish before
364
+ * the server drops every connection. The engine keeps running.
365
+ *
366
+ * @returns A promise that resolves once every connection has closed. After
367
+ * a timeout, later calls return the same rejection.
368
+ * @throws A `NarsilError` with `WORKER_TIMEOUT` if a request thread has not
369
+ * acknowledged closure by the 30-second deadline. The message reports the
370
+ * number of threads and the deadline. The server closes connections on the
371
+ * main thread and responsive threads before rejecting. A blocked thread
372
+ * retains the close signal and closes its connections without answering
373
+ * once it resumes.
374
+ */
360
375
  close(): Promise<void>;
361
376
  /**
362
377
  * Closes the server and then shuts the engine down, which is what a process
@@ -1,12 +1,12 @@
1
- import { responseStopOf, sendRelayed, parseJson, validateQuery, rejectInvalid, refuseRegex, withServerRerankWindow, requestSignal, respondJson, encodeQueryResult, respondError, loadUWebSockets, childAppOf, createRouteRunner, corsHeaderReader, createSharedBodyBudget, createSharedRequestGate, registerFeedRoute, SYNC_FEED_ROUTE, CHANGES_FEED_ROUTE, registerServerRoutes, closeWhenTheProcessExits, statusLine, sendError, REQUEST_THREAD_MOVE_AFTER_MS, MAX_LONG_QUERIES_IN_FLIGHT, serverRoutes, createDocumentReadHandlers, SERVER_CAPABILITIES, versionReport, departureConfirmed, departureConfirmation, stopResponse, validateSuggest, isMainFeedNote, SEARCH_CLOCK_SAMPLE_UNITS, REQUEST_THREAD_DRAIN_DEADLINE_MS, REQUEST_THREAD_DEPARTURE_DRAIN_MS, awaitDepartureConfirmation } from './chunk-NCIGNQJE.mjs';
2
- import { SYNC_CLOSE_GOING_AWAY, encodeJson } from './chunk-TACP6VK6.mjs';
3
- import { importOptionalReads, loadSortingFor, holdsQuotedText, loadQueryCode, executeQuery, lazyQueryBinding, executePreflight, resolveProjection, projectionKeepsField, loadRerankRuntime, setNestedValue } from './chunk-PP3W5PQQ.mjs';
4
- import { loadedMessagePack, loadMessagePack, extractVectorFieldsFromSchema } from './chunk-7P5YWDRQ.mjs';
1
+ import { responseStopOf, sendRelayed, readQueryBody, withServerQueryLimits, requestSignal, respondJson, encodeQueryResult, respondError, loadUWebSockets, childAppOf, createRouteRunner, corsHeaderReader, createSharedBodyBudget, createSharedRequestGate, registerFeedRoute, SYNC_FEED_ROUTE, CHANGES_FEED_ROUTE, registerServerRoutes, closeWhenTheProcessExits, acknowledgeThreadClose, statusLine, sendError, REQUEST_THREAD_MOVE_AFTER_MS, MAX_LONG_QUERIES_IN_FLIGHT, LeavingResponse, refuseAndClose, serverRoutes, createDocumentReadHandlers, SERVER_CAPABILITIES, versionReport, threadCloseRequested, departureConfirmed, serverCloseDeadline, REQUEST_THREAD_DRAIN_DEADLINE_MS, departureConfirmation, serverCloseSignalled, stopResponse, parseJsonObject, validateSuggest, rejectInvalid, isMainFeedNote, SEARCH_CLOCK_SAMPLE_UNITS, REQUEST_THREAD_DEPARTURE_DRAIN_MS, awaitDepartureConfirmation } from './chunk-YGRJLI2Z.mjs';
2
+ import { SYNC_CLOSE_GOING_AWAY } from './chunk-TACP6VK6.mjs';
3
+ import { importOptionalReads, loadSortingFor, holdsQuotedText, loadQueryCode, executeQuery, lazyQueryBinding, executePreflight, resolveProjection, projectionKeepsField, loadRerankRuntime, setNestedValue } from './chunk-WYH3QHBK.mjs';
4
+ import { loadedMessagePack, loadMessagePack, extractVectorFieldsFromSchema } from './chunk-EY5U4P5V.mjs';
5
5
  import { answerFromOneState } from './chunk-FJXJZUWF.mjs';
6
6
  import { ServerErrorCodes, ErrorCodes, NarsilError, isNarsilError } from './chunk-ZKOQR7EA.mjs';
7
7
 
8
8
  // src/server/request-threads/feed-relay.ts
9
- function threadFeedGateway(port, relay, feed) {
9
+ function threadFeedGateway(port, relay, feed, canRespond) {
10
10
  const sockets = /* @__PURE__ */ new Map();
11
11
  function post(note, transfer = []) {
12
12
  try {
@@ -16,6 +16,7 @@ function threadFeedGateway(port, relay, feed) {
16
16
  }
17
17
  const onMessage = (message) => {
18
18
  if (!isMainFeedNote(message)) return;
19
+ if (!canRespond()) return;
19
20
  const socket = sockets.get(message.feedId);
20
21
  if (socket === void 0) return;
21
22
  if (message.type === "feed-close") {
@@ -738,120 +739,6 @@ function createThreadReadEngine(options) {
738
739
  };
739
740
  }
740
741
 
741
- // src/server/request-threads/leaving-response.ts
742
- function refuseAndClose(res, status, envelope) {
743
- const payload = encodeJson(envelope);
744
- res.cork(() => {
745
- res.writeStatus(statusLine(status)).writeHeader("Content-Type", "application/json").writeHeader("Connection", "close").end(payload, true);
746
- });
747
- }
748
- var LeavingResponse = class {
749
- constructor(res, leaving) {
750
- this.res = res;
751
- this.leaving = leaving;
752
- }
753
- headStarted = false;
754
- closesConnection = false;
755
- finished = false;
756
- onFinish = null;
757
- get isFinished() {
758
- return this.finished;
759
- }
760
- whenFinished(callback) {
761
- if (this.finished) callback();
762
- else this.onFinish = callback;
763
- }
764
- refuse(status, envelope) {
765
- if (this.finished) return;
766
- if (this.headStarted) {
767
- this.close();
768
- return;
769
- }
770
- refuseAndClose(this.res, status, envelope);
771
- this.headStarted = true;
772
- this.finish();
773
- }
774
- cork(callback) {
775
- this.res.cork(callback);
776
- return this;
777
- }
778
- writeStatus(status) {
779
- this.res.writeStatus(status);
780
- this.startHead();
781
- return this;
782
- }
783
- writeHeader(key, value) {
784
- this.startHead();
785
- this.res.writeHeader(key, value);
786
- return this;
787
- }
788
- end(body, closeConnection) {
789
- this.startHead();
790
- this.res.end(body, closeConnection === true || this.closesConnection);
791
- this.finish();
792
- return this;
793
- }
794
- write(chunk) {
795
- this.startHead();
796
- return this.res.write(chunk);
797
- }
798
- pause() {
799
- this.res.pause();
800
- }
801
- resume() {
802
- this.res.resume();
803
- }
804
- close() {
805
- this.res.close();
806
- this.finish();
807
- return this;
808
- }
809
- endWithoutBody() {
810
- this.startHead();
811
- this.res.endWithoutBody();
812
- this.finish();
813
- return this;
814
- }
815
- tryEnd(body, totalSize) {
816
- this.startHead();
817
- const result = this.res.tryEnd(body, totalSize);
818
- if (result[1]) this.finish();
819
- return result;
820
- }
821
- getWriteOffset() {
822
- return this.res.getWriteOffset();
823
- }
824
- onWritable(handler) {
825
- this.res.onWritable(handler);
826
- return this;
827
- }
828
- onAborted(handler) {
829
- this.res.onAborted(handler);
830
- return this;
831
- }
832
- onData(handler) {
833
- this.res.onData(handler);
834
- return this;
835
- }
836
- getRemoteAddressAsText() {
837
- return this.res.getRemoteAddressAsText();
838
- }
839
- startHead() {
840
- if (this.headStarted) return;
841
- this.headStarted = true;
842
- if (!this.leaving()) return;
843
- this.closesConnection = true;
844
- this.res.writeHeader("Connection", "close");
845
- }
846
- finish() {
847
- if (this.finished) return;
848
- this.finished = true;
849
- const callback = this.onFinish;
850
- this.onFinish = null;
851
- callback?.();
852
- }
853
- };
854
-
855
742
  // src/server/request-threads/thread-departure.ts
856
743
  var DEPARTURE_REFUSAL = {
857
744
  error: {
@@ -970,11 +857,17 @@ function watchForDeparture(options) {
970
857
  let finishing = false;
971
858
  let draining = false;
972
859
  let closing = false;
860
+ let serverClosing = false;
973
861
  let drained = null;
974
862
  function closeOnce() {
975
863
  if (active === state) active = null;
976
864
  close();
977
865
  }
866
+ function canRespond() {
867
+ if (!threadCloseRequested(options.closeAtExit)) return true;
868
+ closeOnce();
869
+ return false;
870
+ }
978
871
  function leaving() {
979
872
  return departing || draining || departureConfirmed(departure);
980
873
  }
@@ -989,13 +882,19 @@ function watchForDeparture(options) {
989
882
  async function drainRunning() {
990
883
  draining = true;
991
884
  if (!departureConfirmed(departure)) relay.announceDeparture();
992
- const deadline = Date.now() + REQUEST_THREAD_DRAIN_DEADLINE_MS;
885
+ let deadline = serverCloseDeadline(options.serverClose) ?? Date.now() + REQUEST_THREAD_DRAIN_DEADLINE_MS;
993
886
  await settledBy(departureConfirmation(departure), deadline);
994
- await settledBy(idle(), deadline);
887
+ do {
888
+ deadline = serverCloseDeadline(options.serverClose) ?? deadline;
889
+ await settledBy(idle(), deadline);
890
+ if (Date.now() >= deadline && deadline === (serverCloseDeadline(options.serverClose) ?? deadline)) break;
891
+ await pause(Math.min(REQUEST_THREAD_DEPARTURE_DRAIN_MS, Math.max(0, deadline - Date.now())));
892
+ } while (running.size > 0);
995
893
  closing = true;
894
+ const refused = running.size > 0;
996
895
  for (const request of running) refuse(request, DRAIN_DEADLINE_REFUSAL);
997
896
  running.clear();
998
- await pause(REQUEST_THREAD_DEPARTURE_DRAIN_MS);
897
+ if (refused && !serverCloseSignalled(options.serverClose)) await pause(REQUEST_THREAD_DEPARTURE_DRAIN_MS);
999
898
  }
1000
899
  const state = {
1001
900
  begin() {
@@ -1025,6 +924,9 @@ function watchForDeparture(options) {
1025
924
  if (departing) return DEPARTURE_REFUSAL;
1026
925
  return closing ? CLOSING_REFUSAL : null;
1027
926
  }
927
+ function refusalOnConnection() {
928
+ return refusalOnArrival() ?? (serverClosing || serverCloseSignalled(options.serverClose) ? CLOSING_REFUSAL : null);
929
+ }
1028
930
  function refusingOnceDeparting(call) {
1029
931
  return (...args) => {
1030
932
  if (departing) throw departedError();
@@ -1032,8 +934,16 @@ function watchForDeparture(options) {
1032
934
  };
1033
935
  }
1034
936
  return {
937
+ canRespond,
938
+ accept(res) {
939
+ if (!canRespond()) return false;
940
+ const refusal = refusalOnConnection();
941
+ if (refusal === null) return true;
942
+ refuseAndClose(res, 503, refusal);
943
+ return false;
944
+ },
1035
945
  respondThrough(res) {
1036
- return new LeavingResponse(res, leaving);
946
+ return new LeavingResponse(res, leaving, canRespond);
1037
947
  },
1038
948
  track(res, abort) {
1039
949
  const request = { res, abort };
@@ -1088,7 +998,8 @@ function watchForDeparture(options) {
1088
998
  listIndexes: refusingOnceDeparting(() => executor.listIndexes())
1089
999
  };
1090
1000
  },
1091
- drain() {
1001
+ drain(refuseNewRequests) {
1002
+ if (refuseNewRequests) serverClosing = true;
1092
1003
  if (departing) return Promise.resolve();
1093
1004
  if (drained === null) drained = drainRunning();
1094
1005
  return drained;
@@ -1125,7 +1036,7 @@ async function answerMoved(ctx, params, limits, options) {
1125
1036
  try {
1126
1037
  const answer = await options.answerHere(
1127
1038
  ctx.params[0],
1128
- withServerRerankWindow(params, limits),
1039
+ withServerQueryLimits(params, limits),
1129
1040
  requestSignal(ctx.abort)
1130
1041
  );
1131
1042
  respondJson(ctx, "hits" in answer ? encodeQueryResult(answer) : answer);
@@ -1138,20 +1049,14 @@ async function answerMoved(ctx, params, limits, options) {
1138
1049
  function searchHandler(options) {
1139
1050
  const { fallback, limits, allowRegex, staysOnThread, answer } = options;
1140
1051
  return async (ctx) => {
1141
- const params = parseJson(ctx);
1052
+ const params = readQueryBody(ctx, limits, allowRegex);
1142
1053
  if (!params) return;
1143
- const failure = validateQuery(params, limits);
1144
- if (failure) {
1145
- rejectInvalid(ctx, failure);
1146
- return;
1147
- }
1148
- if (refuseRegex(ctx, params.filters, allowRegex)) return;
1149
1054
  if (!staysOnThread(ctx.params[0], params)) {
1150
1055
  await fallback(ctx);
1151
1056
  return;
1152
1057
  }
1153
1058
  try {
1154
- const result = await answer(ctx.params[0], withServerRerankWindow(params, limits), requestSignal(ctx.abort));
1059
+ const result = await answer(ctx.params[0], withServerQueryLimits(params, limits), requestSignal(ctx.abort));
1155
1060
  respondJson(ctx, "hits" in result ? encodeQueryResult(result) : result);
1156
1061
  } catch (err) {
1157
1062
  if (ctx.abort.aborted) return;
@@ -1163,7 +1068,7 @@ function searchHandler(options) {
1163
1068
  }
1164
1069
  function suggestHandler(local, fallback) {
1165
1070
  return async (ctx) => {
1166
- const params = parseJson(ctx);
1071
+ const params = parseJsonObject(ctx);
1167
1072
  if (!params) return;
1168
1073
  const failure = validateSuggest(params);
1169
1074
  if (failure) {
@@ -1232,6 +1137,10 @@ async function serveRequests(executor, settings) {
1232
1137
  const app = uws.App();
1233
1138
  const child = childAppOf(app);
1234
1139
  if (child === null) throw new Error("This uWebSockets.js build offers no child apps");
1140
+ const closeAtExit = new Int32Array(settings.closeAtExit);
1141
+ const close = () => {
1142
+ if (servingApp?.app === child) closeRequestThread();
1143
+ };
1235
1144
  const relay = createRelayClient(settings.port, settings.touchIntervalMs);
1236
1145
  const longQueries = routeLongQueries(
1237
1146
  settings.port,
@@ -1242,7 +1151,9 @@ async function serveRequests(executor, settings) {
1242
1151
  const departure = watchForDeparture({
1243
1152
  relay,
1244
1153
  departure: new Int32Array(settings.departure),
1245
- close: closeRequestThread
1154
+ serverClose: new BigInt64Array(settings.serverClose),
1155
+ closeAtExit,
1156
+ close
1246
1157
  });
1247
1158
  const local = createThreadReadEngine({
1248
1159
  executor: departure.guardExecutor(executor),
@@ -1253,6 +1164,7 @@ async function serveRequests(executor, settings) {
1253
1164
  moveAfterMs: () => longQueries.moveAfterMs()
1254
1165
  });
1255
1166
  const run = createRouteRunner({
1167
+ accept: departure.accept,
1256
1168
  authorize: settings.authorizes ? (context) => relay.authorize(context) : void 0,
1257
1169
  gate: createSharedRequestGate(settings.gate, settings.maxConcurrentRequests, settings.gateSlot),
1258
1170
  bodyBudget: createSharedBodyBudget(settings.bodyBudget, settings.limits.maxBodyBytesInFlight, settings.gateSlot),
@@ -1263,30 +1175,37 @@ async function serveRequests(executor, settings) {
1263
1175
  const forwarded = relayedHandlers(relay, settings.limits);
1264
1176
  const handlers = guardEveryRoute(threadHandlers(local, forwarded, longQueries, settings), forwarded, departure);
1265
1177
  const feeds = settings.feeds.map((feed) => {
1266
- const gateway = threadFeedGateway(settings.port, relay, feed);
1267
- registerFeedRoute(app, gateway, feed === "sync" ? SYNC_FEED_ROUTE : CHANGES_FEED_ROUTE);
1178
+ const gateway = threadFeedGateway(settings.port, relay, feed, departure.canRespond);
1179
+ registerFeedRoute(
1180
+ app,
1181
+ gateway,
1182
+ feed === "sync" ? SYNC_FEED_ROUTE : CHANGES_FEED_ROUTE,
1183
+ departure.accept,
1184
+ departure.canRespond
1185
+ );
1268
1186
  return gateway;
1269
1187
  });
1270
- registerServerRoutes(app, run, handlers, settings.limits, settings.cors);
1271
- servingApp = { app: child, relay, longQueries, feeds, departure };
1272
- void closeWhenTheProcessExits(new Int32Array(settings.closeAtExit), closeRequestThread);
1188
+ registerServerRoutes(app, run, handlers, settings.limits, settings.cors, departure.accept);
1189
+ servingApp = { app: child, relay, longQueries, feeds, departure, closeAtExit };
1190
+ void closeWhenTheProcessExits(closeAtExit, close);
1273
1191
  return { descriptor: child.getDescriptor() };
1274
1192
  }
1275
- async function drainRequestThread() {
1193
+ async function drainRequestThread(refuseNewRequests) {
1276
1194
  const serving = servingApp;
1277
1195
  if (serving === null) return;
1278
- await serving.departure.drain();
1279
- closeRequestThread();
1196
+ await serving.departure.drain(refuseNewRequests);
1197
+ if (servingApp === serving) closeRequestThread();
1280
1198
  }
1281
1199
  function closeRequestThread() {
1282
1200
  leaveWithoutDeparture();
1283
1201
  if (servingApp === null) return;
1284
- const { app, relay, longQueries, feeds } = servingApp;
1202
+ const { app, relay, longQueries, feeds, closeAtExit } = servingApp;
1285
1203
  servingApp = null;
1286
1204
  for (const gateway of feeds) gateway.close();
1287
1205
  app.close();
1288
1206
  longQueries.close();
1289
1207
  relay.close();
1208
+ acknowledgeThreadClose(closeAtExit);
1290
1209
  }
1291
1210
 
1292
1211
  export { closeRequestThread, createRelayClient, createThreadReadEngine, drainRequestThread, isLongQueryPortNote, searchHandler, serveRequests };
@@ -1,5 +1,5 @@
1
1
  import { isSyncEpoch } from './chunk-BUMREPLU.mjs';
2
- import { requireLoadedMessagePack } from './chunk-7P5YWDRQ.mjs';
2
+ import { requireLoadedMessagePack } from './chunk-EY5U4P5V.mjs';
3
3
  import { NarsilError, ErrorCodes } from './chunk-ZKOQR7EA.mjs';
4
4
 
5
5
  // src/sync/device/stores/records.ts
@@ -1,4 +1,4 @@
1
- import { requireLoadedMessagePack, getNestedValue, parsedTypeOf } from './chunk-7P5YWDRQ.mjs';
1
+ import { requireLoadedMessagePack, getNestedValue, parsedTypeOf } from './chunk-EY5U4P5V.mjs';
2
2
  import { NarsilError, ErrorCodes } from './chunk-ZKOQR7EA.mjs';
3
3
  import { codePointCount, exceedsCodePoints } from './chunk-TGPKS2UM.mjs';
4
4
 
@@ -1,5 +1,5 @@
1
- import { MAX_HISTORY_FILE_BYTES, openChecksummedEnvelope, KEY_FINGERPRINT_BYTES, DAY_MS, dayFileKey, SCRAMBLED_ID_BYTES, restoreStagingPrefix, resolveSetting, QUERY_HISTORY_ARCHIVE_PREFIX, restoredFileKey, attachedRuntimeOf, MAX_INDEX_UUID_LENGTH, HEADER_SIZE, isGroup, isNormalPhrase, MAX_MAX_LENGTH, MAX_MAX_WORDS, listHistoryFolder, historyFileOf, MIN_PHRASE_TABLE_CAPACITY, PERSON_TABLE_MIN_SLOTS, PAIR_PAGE_BLOCKS, PAIR_BLOCK_SLOTS, packEnvelopeWithChecksum, crc32, MAX_PEOPLE_PER_PHRASE_IN_FILE } from './chunk-CERPUGRK.mjs';
2
- import { loadSuggestionsCode, emitWriteEventAfter, dropEngineIndex } from './chunk-PP3W5PQQ.mjs';
1
+ import { MAX_HISTORY_FILE_BYTES, openChecksummedEnvelope, KEY_FINGERPRINT_BYTES, DAY_MS, dayFileKey, SCRAMBLED_ID_BYTES, restoreStagingPrefix, resolveSetting, QUERY_HISTORY_ARCHIVE_PREFIX, restoredFileKey, attachedRuntimeOf, MAX_INDEX_UUID_LENGTH, HEADER_SIZE, isGroup, isNormalPhrase, MAX_MAX_LENGTH, MAX_MAX_WORDS, listHistoryFolder, historyFileOf, MIN_PHRASE_TABLE_CAPACITY, PERSON_TABLE_MIN_SLOTS, PAIR_PAGE_BLOCKS, PAIR_BLOCK_SLOTS, packEnvelopeWithChecksum, crc32, MAX_PEOPLE_PER_PHRASE_IN_FILE } from './chunk-G3KVEHIW.mjs';
2
+ import { loadSuggestionsCode, emitWriteEventAfter, dropEngineIndex } from './chunk-WYH3QHBK.mjs';
3
3
  import { NarsilError, ErrorCodes } from './chunk-ZKOQR7EA.mjs';
4
4
 
5
5
  // src/query-suggestions/engine-hooks.ts
@@ -1,4 +1,4 @@
1
- import { getNestedValue } from './chunk-MRH36RN3.mjs';
1
+ import { getNestedValue } from './chunk-EY5U4P5V.mjs';
2
2
 
3
3
  // src/serialization/vector-field-bytes.ts
4
4
  var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
@@ -1,8 +1,8 @@
1
1
  import { restoredEmbedding, restoredPartitionConfig, readSharedConfigFields } from './chunk-M2Z5WVWW.mjs';
2
2
  import { MAX_PARTITION_COUNT, MAX_REPLICATION_FACTOR } from './chunk-JDDXV6UF.mjs';
3
- import { storedStateOf } from './chunk-CERPUGRK.mjs';
4
- import { getLanguage, generateId, decodeSynonymRules } from './chunk-PP3W5PQQ.mjs';
5
- import { decode } from './chunk-GXCDWLQI.mjs';
3
+ import { storedStateOf } from './chunk-G3KVEHIW.mjs';
4
+ import { getLanguage, generateId, decodeSynonymRules } from './chunk-WYH3QHBK.mjs';
5
+ import { decode } from './chunk-Y7GXGJFZ.mjs';
6
6
  import { isSyncEpoch } from './chunk-BUMREPLU.mjs';
7
7
  import { MAX_INDEX_NAME_LENGTH, INDEX_NAME_PATTERN } from './chunk-3ECIRFS5.mjs';
8
8
  import { NarsilError, ErrorCodes } from './chunk-ZKOQR7EA.mjs';