@gaganref/confect-server 0.0.0-stage → 10.3.1-fork.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/CHANGELOG.md +2119 -0
  2. package/LICENSE +7 -0
  3. package/README.md +16 -2
  4. package/dist/ActionCtx.d.ts +10 -0
  5. package/dist/ActionCtx.d.ts.map +1 -0
  6. package/dist/ActionCtx.js +18 -0
  7. package/dist/ActionCtx.js.map +1 -0
  8. package/dist/ActionRunner.d.ts +16 -0
  9. package/dist/ActionRunner.d.ts.map +1 -0
  10. package/dist/ActionRunner.js +18 -0
  11. package/dist/ActionRunner.js.map +1 -0
  12. package/dist/AiGatewayDecisionClient.d.ts +20 -0
  13. package/dist/AiGatewayDecisionClient.d.ts.map +1 -0
  14. package/dist/AiGatewayDecisionClient.js +31 -0
  15. package/dist/AiGatewayDecisionClient.js.map +1 -0
  16. package/dist/AiGatewayDecisionModel.d.ts +24 -0
  17. package/dist/AiGatewayDecisionModel.d.ts.map +1 -0
  18. package/dist/AiGatewayDecisionModel.js +27 -0
  19. package/dist/AiGatewayDecisionModel.js.map +1 -0
  20. package/dist/AiGatewayLanguageClient.d.ts +21 -0
  21. package/dist/AiGatewayLanguageClient.d.ts.map +1 -0
  22. package/dist/AiGatewayLanguageClient.js +32 -0
  23. package/dist/AiGatewayLanguageClient.js.map +1 -0
  24. package/dist/AiGatewayLanguageModel.d.ts +95 -0
  25. package/dist/AiGatewayLanguageModel.d.ts.map +1 -0
  26. package/dist/AiGatewayLanguageModel.js +42 -0
  27. package/dist/AiGatewayLanguageModel.js.map +1 -0
  28. package/dist/Auth.d.ts +20 -0
  29. package/dist/Auth.d.ts.map +1 -0
  30. package/dist/Auth.js +31 -0
  31. package/dist/Auth.js.map +1 -0
  32. package/dist/BlobNotFoundError.d.ts +9 -0
  33. package/dist/BlobNotFoundError.d.ts.map +1 -0
  34. package/dist/BlobNotFoundError.js +13 -0
  35. package/dist/BlobNotFoundError.js.map +1 -0
  36. package/dist/Callback.d.ts +31 -0
  37. package/dist/Callback.d.ts.map +1 -0
  38. package/dist/Callback.js +182 -0
  39. package/dist/Callback.js.map +1 -0
  40. package/dist/ComponentCtx.d.ts +71 -0
  41. package/dist/ComponentCtx.d.ts.map +1 -0
  42. package/dist/ComponentCtx.js +0 -0
  43. package/dist/ConvexConfigProvider.d.ts +21 -0
  44. package/dist/ConvexConfigProvider.d.ts.map +1 -0
  45. package/dist/ConvexConfigProvider.js +36 -0
  46. package/dist/ConvexConfigProvider.js.map +1 -0
  47. package/dist/ConvexFunctionDefinitions.d.ts +25 -0
  48. package/dist/ConvexFunctionDefinitions.d.ts.map +1 -0
  49. package/dist/ConvexFunctionDefinitions.js +25 -0
  50. package/dist/ConvexFunctionDefinitions.js.map +1 -0
  51. package/dist/ConvexLogger.d.ts +17 -0
  52. package/dist/ConvexLogger.d.ts.map +1 -0
  53. package/dist/ConvexLogger.js +33 -0
  54. package/dist/ConvexLogger.js.map +1 -0
  55. package/dist/CronJob.d.ts +14 -0
  56. package/dist/CronJob.d.ts.map +1 -0
  57. package/dist/CronJob.js +22 -0
  58. package/dist/CronJob.js.map +1 -0
  59. package/dist/CronJobs.d.ts +22 -0
  60. package/dist/CronJobs.d.ts.map +1 -0
  61. package/dist/CronJobs.js +83 -0
  62. package/dist/CronJobs.js.map +1 -0
  63. package/dist/DataModel.d.ts +28 -0
  64. package/dist/DataModel.d.ts.map +1 -0
  65. package/dist/DataModel.js +7 -0
  66. package/dist/DataModel.js.map +1 -0
  67. package/dist/DatabaseReader.d.ts +26 -0
  68. package/dist/DatabaseReader.d.ts.map +1 -0
  69. package/dist/DatabaseReader.js +33 -0
  70. package/dist/DatabaseReader.js.map +1 -0
  71. package/dist/DatabaseSchema.d.ts +67 -0
  72. package/dist/DatabaseSchema.d.ts.map +1 -0
  73. package/dist/DatabaseSchema.js +61 -0
  74. package/dist/DatabaseSchema.js.map +1 -0
  75. package/dist/DatabaseWriter.d.ts +44 -0
  76. package/dist/DatabaseWriter.d.ts.map +1 -0
  77. package/dist/DatabaseWriter.js +47 -0
  78. package/dist/DatabaseWriter.js.map +1 -0
  79. package/dist/Document.d.ts +37 -0
  80. package/dist/Document.d.ts.map +1 -0
  81. package/dist/Document.js +54 -0
  82. package/dist/Document.js.map +1 -0
  83. package/dist/ExecutionMetadata.d.ts +13 -0
  84. package/dist/ExecutionMetadata.d.ts.map +1 -0
  85. package/dist/ExecutionMetadata.js +19 -0
  86. package/dist/ExecutionMetadata.js.map +1 -0
  87. package/dist/FunctionImpl.d.ts +39 -0
  88. package/dist/FunctionImpl.d.ts.map +1 -0
  89. package/dist/FunctionImpl.js +46 -0
  90. package/dist/FunctionImpl.js.map +1 -0
  91. package/dist/FunctionRegistryItem.d.ts +36 -0
  92. package/dist/FunctionRegistryItem.d.ts.map +1 -0
  93. package/dist/FunctionRegistryItem.js +34 -0
  94. package/dist/FunctionRegistryItem.js.map +1 -0
  95. package/dist/GroupImpl.d.ts +77 -0
  96. package/dist/GroupImpl.d.ts.map +1 -0
  97. package/dist/GroupImpl.js +81 -0
  98. package/dist/GroupImpl.js.map +1 -0
  99. package/dist/GroupRegistry.d.ts +8 -0
  100. package/dist/GroupRegistry.d.ts.map +1 -0
  101. package/dist/GroupRegistry.js +26 -0
  102. package/dist/GroupRegistry.js.map +1 -0
  103. package/dist/Handler.d.ts +47 -0
  104. package/dist/Handler.d.ts.map +1 -0
  105. package/dist/Handler.js +7 -0
  106. package/dist/Handler.js.map +1 -0
  107. package/dist/HttpRouter.d.ts +80 -0
  108. package/dist/HttpRouter.d.ts.map +1 -0
  109. package/dist/HttpRouter.js +195 -0
  110. package/dist/HttpRouter.js.map +1 -0
  111. package/dist/MiddlewareImpl.d.ts +79 -0
  112. package/dist/MiddlewareImpl.d.ts.map +1 -0
  113. package/dist/MiddlewareImpl.js +58 -0
  114. package/dist/MiddlewareImpl.js.map +1 -0
  115. package/dist/MiddlewareRegistryItem.d.ts +12 -0
  116. package/dist/MiddlewareRegistryItem.d.ts.map +1 -0
  117. package/dist/MiddlewareRegistryItem.js +15 -0
  118. package/dist/MiddlewareRegistryItem.js.map +1 -0
  119. package/dist/MutationCtx.d.ts +10 -0
  120. package/dist/MutationCtx.d.ts.map +1 -0
  121. package/dist/MutationCtx.js +18 -0
  122. package/dist/MutationCtx.js.map +1 -0
  123. package/dist/MutationRunner.d.ts +27 -0
  124. package/dist/MutationRunner.d.ts.map +1 -0
  125. package/dist/MutationRunner.js +28 -0
  126. package/dist/MutationRunner.js.map +1 -0
  127. package/dist/MutationTransactionContext.d.ts +17 -0
  128. package/dist/MutationTransactionContext.d.ts.map +1 -0
  129. package/dist/MutationTransactionContext.js +20 -0
  130. package/dist/MutationTransactionContext.js.map +1 -0
  131. package/dist/OrderedQuery.d.ts +32 -0
  132. package/dist/OrderedQuery.d.ts.map +1 -0
  133. package/dist/OrderedQuery.js +36 -0
  134. package/dist/OrderedQuery.js.map +1 -0
  135. package/dist/QueryCtx.d.ts +10 -0
  136. package/dist/QueryCtx.d.ts.map +1 -0
  137. package/dist/QueryCtx.js +18 -0
  138. package/dist/QueryCtx.js.map +1 -0
  139. package/dist/QueryInitializer.d.ts +75 -0
  140. package/dist/QueryInitializer.d.ts.map +1 -0
  141. package/dist/QueryInitializer.js +105 -0
  142. package/dist/QueryInitializer.js.map +1 -0
  143. package/dist/QueryRunner.d.ts +46 -0
  144. package/dist/QueryRunner.d.ts.map +1 -0
  145. package/dist/QueryRunner.js +30 -0
  146. package/dist/QueryRunner.js.map +1 -0
  147. package/dist/QueryStream.d.ts +678 -0
  148. package/dist/QueryStream.d.ts.map +1 -0
  149. package/dist/QueryStream.js +943 -0
  150. package/dist/QueryStream.js.map +1 -0
  151. package/dist/QueryStreamCursor.d.ts +39 -0
  152. package/dist/QueryStreamCursor.d.ts.map +1 -0
  153. package/dist/QueryStreamCursor.js +52 -0
  154. package/dist/QueryStreamCursor.js.map +1 -0
  155. package/dist/QueryStreamIndexPrefix.d.ts +48 -0
  156. package/dist/QueryStreamIndexPrefix.d.ts.map +1 -0
  157. package/dist/QueryStreamIndexPrefix.js +38 -0
  158. package/dist/QueryStreamIndexPrefix.js.map +1 -0
  159. package/dist/QueryStreamIndexRange.d.ts +193 -0
  160. package/dist/QueryStreamIndexRange.d.ts.map +1 -0
  161. package/dist/QueryStreamIndexRange.js +241 -0
  162. package/dist/QueryStreamIndexRange.js.map +1 -0
  163. package/dist/QueryStreamKey.d.ts +64 -0
  164. package/dist/QueryStreamKey.d.ts.map +1 -0
  165. package/dist/QueryStreamKey.js +69 -0
  166. package/dist/QueryStreamKey.js.map +1 -0
  167. package/dist/QueryStreamKeyBounds.d.ts +136 -0
  168. package/dist/QueryStreamKeyBounds.d.ts.map +1 -0
  169. package/dist/QueryStreamKeyBounds.js +208 -0
  170. package/dist/QueryStreamKeyBounds.js.map +1 -0
  171. package/dist/QueryStreamKeyLabels.d.ts +27 -0
  172. package/dist/QueryStreamKeyLabels.d.ts.map +1 -0
  173. package/dist/QueryStreamKeyLabels.js +22 -0
  174. package/dist/QueryStreamKeyLabels.js.map +1 -0
  175. package/dist/QueryStreamKeyLayout.d.ts +179 -0
  176. package/dist/QueryStreamKeyLayout.d.ts.map +1 -0
  177. package/dist/QueryStreamKeyLayout.js +167 -0
  178. package/dist/QueryStreamKeyLayout.js.map +1 -0
  179. package/dist/QueryStreamKeyValues.d.ts +40 -0
  180. package/dist/QueryStreamKeyValues.d.ts.map +1 -0
  181. package/dist/QueryStreamKeyValues.js +57 -0
  182. package/dist/QueryStreamKeyValues.js.map +1 -0
  183. package/dist/QueryStreamOrderDirection.d.ts +24 -0
  184. package/dist/QueryStreamOrderDirection.d.ts.map +1 -0
  185. package/dist/QueryStreamOrderDirection.js +11 -0
  186. package/dist/QueryStreamOrderDirection.js.map +1 -0
  187. package/dist/QueryStreamPagination.d.ts +264 -0
  188. package/dist/QueryStreamPagination.d.ts.map +1 -0
  189. package/dist/QueryStreamPagination.js +172 -0
  190. package/dist/QueryStreamPagination.js.map +1 -0
  191. package/dist/QueryStreamReadBudget.d.ts +63 -0
  192. package/dist/QueryStreamReadBudget.d.ts.map +1 -0
  193. package/dist/QueryStreamReadBudget.js +81 -0
  194. package/dist/QueryStreamReadBudget.js.map +1 -0
  195. package/dist/QueryTransactionContext.d.ts +16 -0
  196. package/dist/QueryTransactionContext.d.ts.map +1 -0
  197. package/dist/QueryTransactionContext.js +17 -0
  198. package/dist/QueryTransactionContext.js.map +1 -0
  199. package/dist/RegisteredConvexFunction.d.ts +359 -0
  200. package/dist/RegisteredConvexFunction.d.ts.map +1 -0
  201. package/dist/RegisteredConvexFunction.js +154 -0
  202. package/dist/RegisteredConvexFunction.js.map +1 -0
  203. package/dist/RegisteredFunction.d.ts +143 -0
  204. package/dist/RegisteredFunction.d.ts.map +1 -0
  205. package/dist/RegisteredFunction.js +125 -0
  206. package/dist/RegisteredFunction.js.map +1 -0
  207. package/dist/RegisteredFunctions.d.ts +57 -0
  208. package/dist/RegisteredFunctions.d.ts.map +1 -0
  209. package/dist/RegisteredFunctions.js +32 -0
  210. package/dist/RegisteredFunctions.js.map +1 -0
  211. package/dist/RegisteredNodeFunction.d.ts +11 -0
  212. package/dist/RegisteredNodeFunction.d.ts.map +1 -0
  213. package/dist/RegisteredNodeFunction.js +45 -0
  214. package/dist/RegisteredNodeFunction.js.map +1 -0
  215. package/dist/Registry.d.ts +12 -0
  216. package/dist/Registry.d.ts.map +1 -0
  217. package/dist/Registry.js +17 -0
  218. package/dist/Registry.js.map +1 -0
  219. package/dist/RegistryItems.d.ts +21 -0
  220. package/dist/RegistryItems.d.ts.map +1 -0
  221. package/dist/RegistryItems.js +27 -0
  222. package/dist/RegistryItems.js.map +1 -0
  223. package/dist/RequestMetadata.d.ts +12 -0
  224. package/dist/RequestMetadata.d.ts.map +1 -0
  225. package/dist/RequestMetadata.js +16 -0
  226. package/dist/RequestMetadata.js.map +1 -0
  227. package/dist/ResolvedMiddleware.d.ts +24 -0
  228. package/dist/ResolvedMiddleware.d.ts.map +1 -0
  229. package/dist/ResolvedMiddleware.js +34 -0
  230. package/dist/ResolvedMiddleware.js.map +1 -0
  231. package/dist/Scheduler.d.ts +31 -0
  232. package/dist/Scheduler.d.ts.map +1 -0
  233. package/dist/Scheduler.js +35 -0
  234. package/dist/Scheduler.js.map +1 -0
  235. package/dist/Storage.d.ts +22 -0
  236. package/dist/Storage.d.ts.map +1 -0
  237. package/dist/Storage.js +27 -0
  238. package/dist/Storage.js.map +1 -0
  239. package/dist/StorageActionWriter.d.ts +35 -0
  240. package/dist/StorageActionWriter.d.ts.map +1 -0
  241. package/dist/StorageActionWriter.js +24 -0
  242. package/dist/StorageActionWriter.js.map +1 -0
  243. package/dist/StorageReader.d.ts +26 -0
  244. package/dist/StorageReader.d.ts.map +1 -0
  245. package/dist/StorageReader.js +22 -0
  246. package/dist/StorageReader.js.map +1 -0
  247. package/dist/StorageWriter.d.ts +29 -0
  248. package/dist/StorageWriter.d.ts.map +1 -0
  249. package/dist/StorageWriter.js +24 -0
  250. package/dist/StorageWriter.js.map +1 -0
  251. package/dist/Table.d.ts +274 -0
  252. package/dist/Table.d.ts.map +1 -0
  253. package/dist/Table.js +70 -0
  254. package/dist/Table.js.map +1 -0
  255. package/dist/TableInfo.d.ts +44 -0
  256. package/dist/TableInfo.d.ts.map +1 -0
  257. package/dist/TableInfo.js +7 -0
  258. package/dist/TableInfo.js.map +1 -0
  259. package/dist/TransactionMetadata.d.ts +12 -0
  260. package/dist/TransactionMetadata.d.ts.map +1 -0
  261. package/dist/TransactionMetadata.js +16 -0
  262. package/dist/TransactionMetadata.js.map +1 -0
  263. package/dist/VectorSearch.d.ts +23 -0
  264. package/dist/VectorSearch.d.ts.map +1 -0
  265. package/dist/VectorSearch.js +17 -0
  266. package/dist/VectorSearch.js.map +1 -0
  267. package/dist/_virtual/_rolldown/runtime.js +13 -0
  268. package/dist/index.d.ts +88 -0
  269. package/dist/index.d.ts.map +1 -0
  270. package/dist/index.js +61 -0
  271. package/dist/internal/AiGatewayDecisionClient.d.ts +7 -0
  272. package/dist/internal/AiGatewayDecisionClient.d.ts.map +1 -0
  273. package/dist/internal/AiGatewayDecisionClient.js +19 -0
  274. package/dist/internal/AiGatewayDecisionClient.js.map +1 -0
  275. package/dist/internal/AiGatewayLanguageClient.d.ts +7 -0
  276. package/dist/internal/AiGatewayLanguageClient.d.ts.map +1 -0
  277. package/dist/internal/AiGatewayLanguageClient.js +19 -0
  278. package/dist/internal/AiGatewayLanguageClient.js.map +1 -0
  279. package/dist/internal/AiGatewayServiceToken.d.ts +46 -0
  280. package/dist/internal/AiGatewayServiceToken.d.ts.map +1 -0
  281. package/dist/internal/AiGatewayServiceToken.js +62 -0
  282. package/dist/internal/AiGatewayServiceToken.js.map +1 -0
  283. package/dist/internal/constants.d.ts +2 -0
  284. package/dist/internal/constants.d.ts.map +1 -0
  285. package/dist/internal/constants.js +6 -0
  286. package/dist/internal/constants.js.map +1 -0
  287. package/dist/internal/utils.d.ts +13 -0
  288. package/dist/internal/utils.d.ts.map +1 -0
  289. package/dist/internal/utils.js +50 -0
  290. package/dist/internal/utils.js.map +1 -0
  291. package/dist/node.d.ts +2 -0
  292. package/dist/node.d.ts.map +1 -0
  293. package/dist/node.js +1 -0
  294. package/package.json +68 -3
  295. package/src/ActionCtx.ts +45 -0
  296. package/src/ActionRunner.ts +36 -0
  297. package/src/AiGatewayDecisionClient.ts +40 -0
  298. package/src/AiGatewayDecisionModel.ts +46 -0
  299. package/src/AiGatewayLanguageClient.ts +41 -0
  300. package/src/AiGatewayLanguageModel.ts +61 -0
  301. package/src/Auth.ts +51 -0
  302. package/src/BlobNotFoundError.ts +12 -0
  303. package/src/Callback.ts +313 -0
  304. package/src/ComponentCtx.ts +192 -0
  305. package/src/ConvexConfigProvider.ts +39 -0
  306. package/src/ConvexFunctionDefinitions.ts +91 -0
  307. package/src/ConvexLogger.ts +43 -0
  308. package/src/CronJob.ts +42 -0
  309. package/src/CronJobs.ts +165 -0
  310. package/src/DataModel.ts +81 -0
  311. package/src/DatabaseReader.ts +118 -0
  312. package/src/DatabaseSchema.ts +139 -0
  313. package/src/DatabaseWriter.ts +232 -0
  314. package/src/Document.ts +146 -0
  315. package/src/ExecutionMetadata.ts +26 -0
  316. package/src/FunctionImpl.ts +96 -0
  317. package/src/FunctionRegistryItem.ts +85 -0
  318. package/src/GroupImpl.ts +167 -0
  319. package/src/GroupRegistry.ts +41 -0
  320. package/src/Handler.ts +191 -0
  321. package/src/HttpRouter.ts +388 -0
  322. package/src/MiddlewareImpl.ts +247 -0
  323. package/src/MiddlewareRegistryItem.ts +21 -0
  324. package/src/MutationCtx.ts +45 -0
  325. package/src/MutationRunner.ts +66 -0
  326. package/src/MutationTransactionContext.ts +48 -0
  327. package/src/OrderedQuery.ts +136 -0
  328. package/src/QueryCtx.ts +45 -0
  329. package/src/QueryInitializer.ts +537 -0
  330. package/src/QueryRunner.ts +91 -0
  331. package/src/QueryStream.ts +2476 -0
  332. package/src/QueryStreamCursor.ts +99 -0
  333. package/src/QueryStreamIndexPrefix.ts +79 -0
  334. package/src/QueryStreamIndexRange.ts +489 -0
  335. package/src/QueryStreamKey.ts +118 -0
  336. package/src/QueryStreamKeyBounds.ts +395 -0
  337. package/src/QueryStreamKeyLabels.ts +56 -0
  338. package/src/QueryStreamKeyLayout.ts +382 -0
  339. package/src/QueryStreamKeyValues.ts +112 -0
  340. package/src/QueryStreamOrderDirection.ts +29 -0
  341. package/src/QueryStreamPagination.ts +357 -0
  342. package/src/QueryStreamReadBudget.ts +167 -0
  343. package/src/QueryTransactionContext.ts +37 -0
  344. package/src/RegisteredConvexFunction.ts +415 -0
  345. package/src/RegisteredFunction.ts +391 -0
  346. package/src/RegisteredFunctions.ts +88 -0
  347. package/src/RegisteredNodeFunction.ts +120 -0
  348. package/src/Registry.ts +17 -0
  349. package/src/RegistryItems.ts +40 -0
  350. package/src/RequestMetadata.ts +20 -0
  351. package/src/ResolvedMiddleware.ts +70 -0
  352. package/src/Scheduler.ts +85 -0
  353. package/src/Storage.ts +37 -0
  354. package/src/StorageActionWriter.ts +59 -0
  355. package/src/StorageReader.ts +59 -0
  356. package/src/StorageWriter.ts +58 -0
  357. package/src/Table.ts +156 -0
  358. package/src/TableInfo.ts +106 -0
  359. package/src/TransactionMetadata.ts +20 -0
  360. package/src/VectorSearch.ts +75 -0
  361. package/src/index.ts +87 -0
  362. package/src/internal/AiGatewayDecisionClient.ts +16 -0
  363. package/src/internal/AiGatewayLanguageClient.ts +16 -0
  364. package/src/internal/AiGatewayServiceToken.ts +129 -0
  365. package/src/internal/constants.ts +1 -0
  366. package/src/internal/utils.ts +89 -0
  367. package/src/node.ts +1 -0
@@ -0,0 +1,678 @@
1
+ /**
2
+ * Compose, merge, join, and paginate index queries as Effect streams.
3
+ *
4
+ * A query stream is an Effect `Stream` of decoded documents with stored keys, a
5
+ * shared key layout, and a direction. Create one with
6
+ * `reader.table(...).stream(index, range?, order?)` for a standard index. The
7
+ * order defaults to `"asc"`; search indexes use `reader.table(...).search(...)`
8
+ * instead. Unlike `reader.table(...).index(...).stream()`, this returns a
9
+ * composable query stream rather than a plain `Stream` over one query.
10
+ *
11
+ * Creating or composing a stream does not read documents. Reads begin when you
12
+ * run a consuming effect, such as `Stream.runCollect` or `paginate`, and each
13
+ * run executes the queries again. Keep callbacks deterministic and read-only:
14
+ * pagination, seeks, and reversal can reevaluate them.
15
+ *
16
+ * Key values are stored separately from emitted values. Pinning an index field
17
+ * with `eq` removes it from the key; range bounds keep it. Keys retain creation
18
+ * time and document-ID tiebreakers where applicable. `QueryStream` combinators
19
+ * preserve the ordering information needed to merge and paginate; plain
20
+ * `Stream` transforms return ordinary streams without that information. A key
21
+ * layout describes the key positions, their visible labels, and implicit ID
22
+ * positions. Reuse a stream's `keyLayout` with `empty` or `flatMap`.
23
+ *
24
+ * Return the whole `paginate` result from a paginated query handler. In React,
25
+ * use `useStreamPaginatedQuery`, not `usePaginatedQuery`: stream pages aren't
26
+ * tracked by Convex's query journal, so the stream hook pins and splits page
27
+ * ranges to keep loaded pages gap-free. Foldkit's `PaginatedQuery` also
28
+ * supports stream pagination.
29
+ *
30
+ * Stream querying is experimental. Its API may still change.
31
+ */
32
+ import type { PaginationOptions as ConvexPaginationOptions, PaginationResult as ConvexPaginationResult } from "convex/server";
33
+ import { type Pipeable } from "effect/Pipeable";
34
+ import * as Array from "effect/Array";
35
+ import type * as Channel from "effect/Channel";
36
+ import * as Data from "effect/Data";
37
+ import * as Effect from "effect/Effect";
38
+ import * as Option from "effect/Option";
39
+ import * as Schema from "effect/Schema";
40
+ import * as Stream from "effect/Stream";
41
+ import type * as Types from "effect/Types";
42
+ import * as Document from "./Document";
43
+ import type * as Table from "./Table";
44
+ import * as QueryStreamKeyLabels from "./QueryStreamKeyLabels";
45
+ import * as QueryStreamKeyLayout from "./QueryStreamKeyLayout";
46
+ import * as QueryStreamOrderDirection from "./QueryStreamOrderDirection";
47
+ import * as QueryStreamKeyValues from "./QueryStreamKeyValues";
48
+ import * as QueryStreamKeyBounds from "./QueryStreamKeyBounds";
49
+ import * as QueryStreamIndexRange from "./QueryStreamIndexRange";
50
+ import * as QueryStreamReadBudget from "./QueryStreamReadBudget";
51
+ declare const ReadBudgetExceededError_base: Schema.Class<ReadBudgetExceededError, Schema.TaggedStruct<"ReadBudgetExceededError", {
52
+ readonly rowsRead: Schema.Natural;
53
+ readonly bytesRead: Schema.Natural;
54
+ }>, import("effect/Cause").YieldableError>;
55
+ /**
56
+ * A page exhausted its read budget without a safe logical continuation.
57
+ *
58
+ * @experimental
59
+ */
60
+ export declare class ReadBudgetExceededError extends ReadBudgetExceededError_base {
61
+ get message(): string;
62
+ }
63
+ declare const IncompatibleStreamsError_base: new <A extends Record<string, any> = {}>(args: Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
64
+ readonly _tag: "IncompatibleStreamsError";
65
+ } & Readonly<A>;
66
+ /**
67
+ * Thrown by `merge` when inputs have different directions, visible ordering
68
+ * labels, or implicit-ID positions. The payload identifies the expected and
69
+ * actual direction and layout; map and relabel compatible inputs before
70
+ * merging.
71
+ *
72
+ * @experimental
73
+ */
74
+ export declare class IncompatibleStreamsError extends IncompatibleStreamsError_base<{
75
+ readonly expectedOrderDirection: QueryStreamOrderDirection.QueryStreamOrderDirection;
76
+ readonly actualOrderDirection: QueryStreamOrderDirection.QueryStreamOrderDirection;
77
+ readonly expectedKeyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout;
78
+ readonly actualKeyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout;
79
+ }> {
80
+ get message(): string;
81
+ }
82
+ declare const InnerStreamOrderMismatchError_base: new <A extends Record<string, any> = {}>(args: Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
83
+ readonly _tag: "InnerStreamOrderMismatchError";
84
+ } & Readonly<A>;
85
+ /**
86
+ * A `flatMap` inner stream runs in a different direction from its outer stream.
87
+ * The join dies with this error when it runs; `expectedOrderDirection` is the
88
+ * outer direction and `actualOrderDirection` is the inner direction.
89
+ *
90
+ * @experimental
91
+ */
92
+ export declare class InnerStreamOrderMismatchError extends InnerStreamOrderMismatchError_base<{
93
+ readonly expectedOrderDirection: QueryStreamOrderDirection.QueryStreamOrderDirection;
94
+ readonly actualOrderDirection: QueryStreamOrderDirection.QueryStreamOrderDirection;
95
+ }> {
96
+ get message(): string;
97
+ }
98
+ declare const InnerStreamLayoutMismatchError_base: new <A extends Record<string, any> = {}>(args: Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
99
+ readonly _tag: "InnerStreamLayoutMismatchError";
100
+ } & Readonly<A>;
101
+ /**
102
+ * A `flatMap` inner stream does not match the supplied `innerKeyLayout`,
103
+ * including visible labels and implicit-ID positions. The join dies with this
104
+ * error when it runs; the payload contains the expected and actual layouts.
105
+ *
106
+ * @experimental
107
+ */
108
+ export declare class InnerStreamLayoutMismatchError extends InnerStreamLayoutMismatchError_base<{
109
+ readonly expectedKeyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout;
110
+ readonly actualKeyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout;
111
+ }> {
112
+ get message(): string;
113
+ }
114
+ declare const MissingReversalRecipeError_base: new <A extends Record<string, any> = {}>(args: Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
115
+ readonly _tag: "MissingReversalRecipeError";
116
+ } & Readonly<A>;
117
+ /**
118
+ * Thrown by `reverse` when a manually constructed stream has no `reverseWith`
119
+ * recipe. Streams created through the table reader and `QueryStream`
120
+ * combinators support reversal.
121
+ *
122
+ * @experimental
123
+ */
124
+ export declare class MissingReversalRecipeError extends MissingReversalRecipeError_base {
125
+ get message(): string;
126
+ }
127
+ /**
128
+ * `paginate` dies with this error for `numItems: 0` and `cursor: null`, because
129
+ * an empty initial page cannot establish a continuation boundary. Request a
130
+ * positive number of items for the first page.
131
+ *
132
+ * @experimental
133
+ */
134
+ export { EmptyInitialPageError, InvalidPageSizeError, } from "./QueryStreamPagination";
135
+ /**
136
+ * Invalid numeric read limits.
137
+ *
138
+ * @experimental
139
+ */
140
+ export { InvalidReadLimitError } from "./QueryStreamReadBudget";
141
+ /**
142
+ * Runtime identifier used to distinguish query streams from plain streams.
143
+ *
144
+ * @experimental
145
+ */
146
+ export declare const TypeId = "~@confect/server/QueryStream";
147
+ /**
148
+ * Type of the query stream's runtime identifier.
149
+ *
150
+ * @experimental
151
+ */
152
+ export type TypeId = typeof TypeId;
153
+ /**
154
+ * A decoded value and its stored key. `doc: None` marks an element that was
155
+ * read but filtered out: it emits no value, but still advances cursors. Mapping
156
+ * a value does not recompute its key.
157
+ *
158
+ * @experimental
159
+ */
160
+ export declare class Element<Doc> extends Data.Class<{
161
+ readonly doc: Option.Option<Doc>;
162
+ readonly keyValues: QueryStreamKeyValues.QueryStreamKeyValues;
163
+ }> {
164
+ }
165
+ /**
166
+ * An Effect `Stream` whose stored keys determine its order and pagination
167
+ * boundaries independently of its emitted values.
168
+ *
169
+ * TypeScript normally infers all five parameters from the table's `stream`
170
+ * method and subsequent composition:
171
+ *
172
+ * - `Doc` is the emitted value: a decoded document or a mapped or joined result.
173
+ * - `KeyLabels` is the branded readonly tuple of visible ordering names,
174
+ * initially the index fields not pinned by `eq`. `flatMap` appends labels and
175
+ * `renameKey` replaces them. Implicit ID tiebreakers are omitted from labels
176
+ * but retained in `keyLayout`.
177
+ * - `OrderDirection` is `"asc"` or `"desc"`; the type defaults to their union.
178
+ * - `E` contains typed failures while reading or transforming values. `never`
179
+ * means no typed failures, not no defects.
180
+ * - `R` contains Effect services required to run the stream. The stream retains
181
+ * the database access supplied at creation, so it doesn't require providing
182
+ * `DatabaseReader` again; effectful callbacks can add requirements.
183
+ *
184
+ * Known label or direction mismatches prevent merging at compile time. Runtime
185
+ * checks also compare implicit-ID positions. Reuse a compatible stream's
186
+ * `keyLayout` for `empty` or `flatMap`'s `innerKeyLayout`.
187
+ *
188
+ * Consume with Effect's `Stream.runCollect` or `Stream.runHead`, or use
189
+ * `unique` or `paginate`. A plain `Stream` transform such as `Stream.take`
190
+ * returns an ordinary stream that can be consumed but no longer merged or
191
+ * paginated with this module.
192
+ *
193
+ * @experimental
194
+ */
195
+ export declare class QueryStream<out Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels = QueryStreamKeyLabels.QueryStreamKeyLabels, out OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection = QueryStreamOrderDirection.QueryStreamOrderDirection, out E = never, out R = never> implements Stream.Stream<Doc, E, R> {
196
+ readonly orderDirection: OrderDirection;
197
+ /**
198
+ * Shared description of the key positions, including visible labels and
199
+ * implicit IDs. Reuse with `empty` or `flatMap`'s `innerKeyLayout`. Reading
200
+ * this property does not read documents. Direction is in `orderDirection`.
201
+ */
202
+ readonly keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout<KeyLabels>;
203
+ /**
204
+ * Values paired with stored keys, including filtered markers that advance
205
+ * cursors without emitting a value.
206
+ */
207
+ readonly annotated: Stream.Stream<Element<Doc>, E, R | QueryStreamReadBudget.QueryStreamReadBudget>;
208
+ /**
209
+ * Query recipe retained by direct index streams and rebuilt on each run.
210
+ * Includes the effective index bounds. Composed streams instead delegate
211
+ * range changes to their inputs through `narrowWith`.
212
+ */
213
+ readonly reflection?: Reflection | undefined;
214
+ /**
215
+ * Rebuilds the stream with validated key bounds, pushing them into index
216
+ * ranges where that preserves the composition's results. Without this
217
+ * recipe, `narrow` filters the annotated stream in memory. The constructor
218
+ * guards recipe calls against bounds from incompatible layouts.
219
+ */
220
+ readonly narrowWith?: ((parsedBounds: QueryStreamKeyBounds.ParsedBounds) => QueryStream<Doc, KeyLabels, OrderDirection, E, R>) | undefined;
221
+ /**
222
+ * Rebuilds the stream in the opposite direction using index scans and
223
+ * seeks. Distinct streams keep their original representatives. Without this
224
+ * recipe, `reverse` throws `MissingReversalRecipeError`.
225
+ */
226
+ readonly reverseWith?: (() => QueryStream<Doc, KeyLabels, QueryStreamOrderDirection.Flip<OrderDirection>, E, R>) | undefined;
227
+ readonly [TypeId]: TypeId;
228
+ readonly "~labels": Types.Invariant<KeyLabels>;
229
+ readonly "~direction": Types.Covariant<OrderDirection>;
230
+ readonly [Stream.TypeId]: Stream.VarianceStruct<Doc, E, R>;
231
+ readonly pipe: Pipeable["pipe"];
232
+ readonly channel: Channel.Channel<Array.NonEmptyReadonlyArray<Doc>, E, void, unknown, unknown, unknown, R>;
233
+ constructor(orderDirection: OrderDirection,
234
+ /**
235
+ * Shared description of the key positions, including visible labels and
236
+ * implicit IDs. Reuse with `empty` or `flatMap`'s `innerKeyLayout`. Reading
237
+ * this property does not read documents. Direction is in `orderDirection`.
238
+ */
239
+ keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout<KeyLabels>,
240
+ /**
241
+ * Values paired with stored keys, including filtered markers that advance
242
+ * cursors without emitting a value.
243
+ */
244
+ annotated: Stream.Stream<Element<Doc>, E, R | QueryStreamReadBudget.QueryStreamReadBudget>,
245
+ /**
246
+ * Query recipe retained by direct index streams and rebuilt on each run.
247
+ * Includes the effective index bounds. Composed streams instead delegate
248
+ * range changes to their inputs through `narrowWith`.
249
+ */
250
+ reflection?: Reflection | undefined,
251
+ /**
252
+ * Rebuilds the stream with validated key bounds, pushing them into index
253
+ * ranges where that preserves the composition's results. Without this
254
+ * recipe, `narrow` filters the annotated stream in memory. The constructor
255
+ * guards recipe calls against bounds from incompatible layouts.
256
+ */
257
+ narrowWith?: ((parsedBounds: QueryStreamKeyBounds.ParsedBounds) => QueryStream<Doc, KeyLabels, OrderDirection, E, R>) | undefined,
258
+ /**
259
+ * Rebuilds the stream in the opposite direction using index scans and
260
+ * seeks. Distinct streams keep their original representatives. Without this
261
+ * recipe, `reverse` throws `MissingReversalRecipeError`.
262
+ */
263
+ reverseWith?: (() => QueryStream<Doc, KeyLabels, QueryStreamOrderDirection.Flip<OrderDirection>, E, R>) | undefined);
264
+ toStream(): Stream.Stream<Doc, E, R>;
265
+ }
266
+ /**
267
+ * A query stream with any value, ordering, error, and requirement types.
268
+ *
269
+ * @experimental
270
+ */
271
+ export type Any = QueryStream<any, any, any, any, any>;
272
+ /**
273
+ * Check whether a value retains query-stream ordering and pagination support.
274
+ * Plain `Stream` transforms return ordinary streams, for which this is false.
275
+ *
276
+ * @experimental
277
+ */
278
+ export declare const isQueryStream: (u: unknown) => u is Any;
279
+ /**
280
+ * Create a stream with no documents but a known key layout and direction. Use
281
+ * it when a dynamic list of streams is empty, since `merge` requires at least
282
+ * one input. The direction defaults to `"asc"`.
283
+ *
284
+ * Supply the document type in the first call, then reuse a compatible stream's
285
+ * layout: `QueryStream.empty<NotesDoc>()(source.keyLayout, "desc")`. Creating
286
+ * the source solely to obtain its layout does not read documents.
287
+ *
288
+ * @experimental
289
+ */
290
+ export declare const empty: <Doc>() => {
291
+ <const KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels>(keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout<KeyLabels>): QueryStream<Doc, KeyLabels, "asc", never, never>;
292
+ <const KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout<KeyLabels>, orderDirection: OrderDirection): QueryStream<Doc, KeyLabels, OrderDirection, never, never>;
293
+ };
294
+ /**
295
+ * Database access needed to rebuild a direct index query on each run. Normally
296
+ * supplied by `reader.table(...).stream(...)` rather than implemented
297
+ * manually.
298
+ *
299
+ * @experimental
300
+ */
301
+ export interface ReflectionReader {
302
+ query(tableName: string): {
303
+ withIndex(indexName: string, indexRange?: (q: any) => any): {
304
+ order(orderDirection: QueryStreamOrderDirection.QueryStreamOrderDirection): AsyncIterable<unknown>;
305
+ };
306
+ };
307
+ }
308
+ /**
309
+ * A reusable index-query description: database access, table schema, index,
310
+ * range, and direction. Direct index streams retain this description instead of
311
+ * a one-shot Convex query so each run can execute the query again. Narrowing
312
+ * and pagination use it to rebuild queries with tighter index bounds.
313
+ *
314
+ * @experimental
315
+ */
316
+ export interface Reflection<OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection = QueryStreamOrderDirection.QueryStreamOrderDirection> {
317
+ readonly reader: ReflectionReader;
318
+ readonly table: Table.AnyWithProps;
319
+ readonly indexName: string;
320
+ /**
321
+ * Index fields in declared order, including `_creationTime` where applicable.
322
+ * The `by_id` index uses only `["_id"]`.
323
+ */
324
+ readonly indexFieldPaths: ReadonlyArray<string>;
325
+ /**
326
+ * Index constraints. Equality constraints pin leading fields, removing them
327
+ * from the stream's key; range bounds do not.
328
+ */
329
+ readonly indexRange: QueryStreamIndexRange.QueryStreamIndexRange;
330
+ readonly orderDirection: OrderDirection;
331
+ /**
332
+ * Effective bounds in full index-key values, including pinned fields and ID
333
+ * tiebreakers. If absent, bounds come from `indexRange`; supplied bounds
334
+ * intersect those constraints rather than replacing them.
335
+ */
336
+ readonly indexBounds?: QueryStreamKeyBounds.IndexBounds;
337
+ }
338
+ /**
339
+ * Create a reusable query stream from an index-query description. Prefer
340
+ * `reader.table(...).stream(...)` for inferred document and ordering types.
341
+ *
342
+ * Construction does not read documents. Each consuming run rebuilds the index
343
+ * queries within the supplied range and decodes their documents, failing with
344
+ * `DocumentDecodeError` if decoding fails. Key values come from encoded index
345
+ * values before decoding, with equality-pinned fields removed.
346
+ *
347
+ * @experimental
348
+ */
349
+ export declare const fromReflection: <Doc, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection = QueryStreamOrderDirection.QueryStreamOrderDirection>(reflection: Reflection<OrderDirection>) => QueryStream<Doc, QueryStreamKeyLabels.QueryStreamKeyLabels, OrderDirection, Document.DocumentDecodeError, never>;
350
+ /**
351
+ * Combine streams sharing a key layout into one stream in key order. Use this
352
+ * to query several index ranges at once, such as notes by multiple roles.
353
+ *
354
+ * The merge emits the smallest next key when ascending and the largest when
355
+ * descending. Unlike `Stream.merge`, it does not interleave by arrival time.
356
+ * Overlapping inputs are not deduplicated: a document matched twice appears
357
+ * twice. Supply at least one input; use `empty` for an empty dynamic list.
358
+ *
359
+ * Inputs need compatible document types and identical key layouts and
360
+ * directions. TypeScript rejects known mismatches; runtime mismatches throw
361
+ * `IncompatibleStreamsError` when combined. Map to a common value shape and use
362
+ * `renameKey` when compatible indexes have different field names.
363
+ *
364
+ * @experimental
365
+ */
366
+ export declare const merge: <Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(streams: readonly [QueryStream<Doc, KeyLabels, OrderDirection, E, R>, ...ReadonlyArray<QueryStream<Doc, KeyLabels, NoInfer<OrderDirection>, E, R>>]) => QueryStream<Doc, KeyLabels, OrderDirection, E, R>;
367
+ /**
368
+ * Control concurrent callback evaluation in `filterEffect` and `mapEffect`.
369
+ *
370
+ * @experimental
371
+ */
372
+ export interface EffectOptions {
373
+ /**
374
+ * Maximum number of document effects running at once, or `"unbounded"`.
375
+ * Defaults to one at a time. Results retain stream order regardless of
376
+ * completion order; callbacks must remain deterministic and read-only.
377
+ */
378
+ readonly concurrency?: number | "unbounded" | undefined;
379
+ }
380
+ /**
381
+ * Keep values that satisfy a pure predicate without changing their stored keys.
382
+ * Like `Stream.filter`, this removes emitted values, but it retains the
383
+ * ordering information needed to merge and paginate the result.
384
+ *
385
+ * Rejected documents still count as reads and advance cursors. Filtering before
386
+ * `distinct` selects each group's first matching document; filtering after it
387
+ * tests only the chosen representative. Use `filterEffect` for predicates that
388
+ * read another table, use a service, or fail with a typed error.
389
+ *
390
+ * @experimental
391
+ */
392
+ export declare const filter: (<Doc>(predicate: (doc: Doc) => boolean) => <KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>) => QueryStream<Doc, KeyLabels, OrderDirection, E, R>) & (<Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>, predicate: (doc: Doc) => boolean) => QueryStream<Doc, KeyLabels, OrderDirection, E, R>);
393
+ /**
394
+ * Keep values that satisfy an effectful predicate, preserving stored keys and
395
+ * cursor progress just like `filter`. The predicate can read other tables or
396
+ * use services; its errors and requirements become part of the stream's types.
397
+ *
398
+ * Effects run one document at a time by default. Pass `{ concurrency }` to run
399
+ * several at once while retaining stream order. Keep the predicate
400
+ * deterministic and read-only, since seeks and pagination can run it again.
401
+ * Separate lookups inside the predicate are not counted by pagination's read
402
+ * budgets.
403
+ *
404
+ * @experimental
405
+ */
406
+ export declare const filterEffect: (<Doc, E2, R2>(predicate: (doc: Doc) => Effect.Effect<boolean, E2, R2>, options?: EffectOptions) => <KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>) => QueryStream<Doc, KeyLabels, OrderDirection, E | E2, R | R2>) & (<Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R, E2, R2, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>, predicate: (doc: Doc) => Effect.Effect<boolean, E2, R2>, options?: EffectOptions) => QueryStream<Doc, KeyLabels, OrderDirection, E | E2, R | R2>);
407
+ /**
408
+ * Transform emitted values with a pure function while keeping their stored key
409
+ * values. The result retains merge and pagination support, unlike the plain
410
+ * stream returned by `Stream.map`.
411
+ *
412
+ * The mapper may replace any fields, including indexed fields, or return a
413
+ * different shape entirely. It does not recompute keys or sort by the new
414
+ * values: mapping note text to its length still orders by the original text,
415
+ * creation time, and ID, not by length. Preserve the input value rather than
416
+ * mutating it. Use `mapEffect` when the mapper needs an effect.
417
+ *
418
+ * @experimental
419
+ */
420
+ export declare const map: (<Doc, Doc2>(f: (doc: Doc) => Doc2) => <KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>) => QueryStream<Doc2, KeyLabels, OrderDirection, E, R>) & (<Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R, Doc2, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>, f: (doc: Doc) => Doc2) => QueryStream<Doc2, KeyLabels, OrderDirection, E, R>);
421
+ /**
422
+ * Transform emitted values with an effect, preserving the original stored keys
423
+ * just like `map`. The mapper may read another table or use services; its
424
+ * errors and requirements become part of the stream's types.
425
+ *
426
+ * Effects run one document at a time by default. Pass `{ concurrency }` for
427
+ * concurrent reads without changing output order. Keep the mapper deterministic
428
+ * and read-only: seeks, reversal, and pagination can reevaluate it. Separate
429
+ * lookups inside the mapper are not counted by pagination's read budgets.
430
+ *
431
+ * @experimental
432
+ */
433
+ export declare const mapEffect: (<Doc, Doc2, E2, R2>(f: (doc: Doc) => Effect.Effect<Doc2, E2, R2>, options?: EffectOptions) => <KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>) => QueryStream<Doc2, KeyLabels, OrderDirection, E | E2, R | R2>) & (<Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R, Doc2, E2, R2, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>, f: (doc: Doc) => Effect.Effect<Doc2, E2, R2>, options?: EffectOptions) => QueryStream<Doc2, KeyLabels, OrderDirection, E | E2, R | R2>);
434
+ /**
435
+ * Run an inner query stream for each outer document and concatenate the
436
+ * results. Like sequential `Stream.flatMap`, each inner stream finishes before
437
+ * the next begins. The joined key is the outer key followed by the inner key,
438
+ * retaining both document IDs so equal timestamps remain distinguishable.
439
+ *
440
+ * Supply `options.innerKeyLayout` from a compatible stream's `keyLayout`. For
441
+ * example, comments indexed by `noteId` and pinned to a note have the same
442
+ * layout as comments ordered by creation time: one visible creation-time
443
+ * position followed by an implicit ID. Creating the template reads no
444
+ * documents. For nested joins or renamed streams, apply the same composition or
445
+ * renaming to the template before reusing its layout.
446
+ *
447
+ * The layout is required when constructing the joined stream, before any outer
448
+ * document is available to pass to `f`, including when the outer stream is
449
+ * empty. It determines the joined key positions and the width of empty-inner
450
+ * markers. It contains no query results or direction.
451
+ *
452
+ * Every inner stream must match that layout and the outer direction. TypeScript
453
+ * rejects known mismatches; others die with `InnerStreamOrderMismatchError` or
454
+ * `InnerStreamLayoutMismatchError` when the join runs.
455
+ *
456
+ * An empty inner stream emits no value by default, but leaves a filtered marker
457
+ * that advances cursors past its outer document. Pass `options.onEmpty` to emit
458
+ * `onEmpty(outer)` instead. The element type widens to include the placeholder,
459
+ * so map inner values to a common shape when needed. Its key is the outer key
460
+ * followed by null inner components, and pagination steps past it like any
461
+ * element. Outer documents filtered out before the join remain absent.
462
+ *
463
+ * Keep `f` and `onEmpty` deterministic and read-only. Pagination, narrowing,
464
+ * and reversal can reevaluate them; both outer and inner index reads count
465
+ * toward pagination's budgets.
466
+ *
467
+ * @experimental
468
+ */
469
+ export declare const flatMap: (<Doc, Doc2, InnerKeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E2, R2, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection, Doc3 = never>(f: (doc: Doc) => QueryStream<Doc2, InnerKeyLabels, OrderDirection, E2, R2>, options: {
470
+ readonly innerKeyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout<NoInfer<InnerKeyLabels>>;
471
+ readonly onEmpty?: ((doc: Doc) => Doc3) | undefined;
472
+ }) => <KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>) => QueryStream<Doc2 | Doc3, QueryStreamKeyLabels.Concat<KeyLabels, InnerKeyLabels>, OrderDirection, E | E2, R | R2>) & (<Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R, Doc2, InnerKeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E2, R2, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection, Doc3 = never>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>, f: (doc: Doc) => QueryStream<Doc2, InnerKeyLabels, NoInfer<OrderDirection>, E2, R2>, options: {
473
+ readonly innerKeyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout<NoInfer<InnerKeyLabels>>;
474
+ readonly onEmpty?: ((doc: Doc) => Doc3) | undefined;
475
+ }) => QueryStream<Doc2 | Doc3, QueryStreamKeyLabels.Concat<KeyLabels, InnerKeyLabels>, OrderDirection, E | E2, R | R2>);
476
+ /**
477
+ * Keep the first document for each distinct value of a key prefix. Similar to
478
+ * `Stream.changes` on that prefix, this groups consecutive equal keys, but
479
+ * seeks past the rest of each group instead of scanning it.
480
+ *
481
+ * Pass a prefix of the visible ordering labels, such as `["text"]` for notes
482
+ * ordered by text and creation time. Prefix validity is checked by TypeScript
483
+ * and at runtime. On a `flatMap` result, a prefix reaching into the inner key
484
+ * also groups by the outer document, including its ID.
485
+ *
486
+ * Operation order controls representative selection. Filter before `distinct`
487
+ * to choose the first matching document, or after it to test only the selected
488
+ * representative. `reverse(distinct(q))` keeps those representatives and flips
489
+ * their output order; `distinct(reverse(q))` selects from the other direction.
490
+ *
491
+ * Narrowing after `distinct` filters the original representatives without
492
+ * selecting replacements. Narrowing before it constrains the input and can
493
+ * change the representatives. Preserving representatives may require extra
494
+ * reads outside output bounds and repeated callback evaluation.
495
+ *
496
+ * @experimental
497
+ */
498
+ export declare const distinct: (<const PrefixNames extends ReadonlyArray<string>>(prefixNames: PrefixNames) => <Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels<readonly [...PrefixNames, ...ReadonlyArray<string>]>, E, R, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>) => QueryStream<Doc, KeyLabels, OrderDirection, E, R>) & (<const PrefixNames extends ReadonlyArray<string>, Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels<readonly [...PrefixNames, ...ReadonlyArray<string>]>, E, R, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>, prefixNames: PrefixNames) => QueryStream<Doc, KeyLabels, OrderDirection, E, R>);
499
+ /**
500
+ * Relabel visible key positions without changing values or their order. This
501
+ * does not sort or transform emitted documents.
502
+ *
503
+ * Use it to merge indexes or tables ordered by comparable values under
504
+ * different field names. For example, relabel comments ordered by `["body",
505
+ * "_creationTime"]` as `["text", "_creationTime"]` to merge with notes ordered
506
+ * by text. Map both streams to a common value shape first.
507
+ *
508
+ * Supply exactly as many replacement labels as the original visible labels. The
509
+ * values at corresponding positions must be comparable; relabeling does not
510
+ * establish that semantic compatibility for you. Implicit ID tiebreakers keep
511
+ * their positions. For joined streams, replacement labels cover the combined
512
+ * key, outer labels first.
513
+ *
514
+ * @experimental
515
+ */
516
+ export declare const renameKey: (<const ReplacementNames extends ReadonlyArray<string>>(replacementNames: ReplacementNames) => <Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels & {
517
+ readonly length: ReplacementNames["length"];
518
+ }, E, R, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>) => QueryStream<Doc, QueryStreamKeyLabels.QueryStreamKeyLabels<ReplacementNames>, OrderDirection, E, R>) & (<const ReplacementNames extends ReadonlyArray<string>, Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels & {
519
+ readonly length: ReplacementNames["length"];
520
+ }, E, R, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>, replacementNames: ReplacementNames) => QueryStream<Doc, QueryStreamKeyLabels.QueryStreamKeyLabels<ReplacementNames>, OrderDirection, E, R>);
521
+ /**
522
+ * Run a composed query stream in the opposite direction without changing its
523
+ * key layout. Use this for bidirectional pagination: a reversed feed can load
524
+ * its earlier pages.
525
+ *
526
+ * Reversal uses index scans and seeks rather than collecting and reversing
527
+ * values. Merges, filters, maps, flat-maps (including their inner streams),
528
+ * distinct streams, renamed streams, and empty streams all support it.
529
+ *
530
+ * `reverse(distinct(q))` retains each group's original first representative and
531
+ * reverses their output order. `distinct(reverse(q))` instead chooses the first
532
+ * document from the other direction. Preserving representatives can require
533
+ * extra reads to discover groups and seek their original first documents.
534
+ *
535
+ * A manually constructed stream without `reverseWith` throws
536
+ * `MissingReversalRecipeError`.
537
+ *
538
+ * @experimental
539
+ */
540
+ export declare const reverse: <Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>) => QueryStream<Doc, KeyLabels, QueryStreamOrderDirection.Flip<OrderDirection>, E, R>;
541
+ /**
542
+ * Restrict a stream to keys between `start` and `end`. Provide at least one
543
+ * endpoint, each with `keyValues` and a required `inclusive` flag; omit the
544
+ * other endpoint to leave that side unbounded.
545
+ *
546
+ * Endpoints follow stream order: `start` is the lower key when ascending and
547
+ * the upper key when descending. Repeated narrowing intersects existing bounds
548
+ * and can only restrict the range further.
549
+ *
550
+ * A key may be a prefix of the full key. An inclusive prefix includes every key
551
+ * extending it; an exclusive prefix excludes the whole group. For example,
552
+ * creation-time bounds can use `[startTime]` and `[endTime]` without trailing
553
+ * IDs. Equal endpoints produce an empty range unless both are inclusive, in
554
+ * which case they select that key or prefix group.
555
+ *
556
+ * Bounds are pushed into index ranges where that preserves the composition's
557
+ * results. On a distinct stream, full-key bounds filter original
558
+ * representatives without choosing replacements; prefix bounds include or
559
+ * exclude whole groups. This can require reads outside the output bounds. Apply
560
+ * bounds before `distinct` instead to constrain which documents can represent a
561
+ * group. Manually constructed streams without `narrowWith` are filtered in
562
+ * memory.
563
+ *
564
+ * For pagination, pass the previous `continueCursor` unchanged to `paginate`;
565
+ * do not decode a cursor into explicit bounds.
566
+ *
567
+ * @experimental
568
+ */
569
+ export declare const narrow: ((narrowBounds: QueryStreamKeyBounds.NarrowBounds) => <Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>) => QueryStream<Doc, KeyLabels, OrderDirection, E, R>) & (<Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R, OrderDirection extends QueryStreamOrderDirection.QueryStreamOrderDirection>(self: QueryStream<Doc, KeyLabels, OrderDirection, E, R>, narrowBounds: QueryStreamKeyBounds.NarrowBounds) => QueryStream<Doc, KeyLabels, OrderDirection, E, R>);
570
+ declare const NotUniqueError_base: Schema.Class<NotUniqueError, Schema.TaggedStruct<"NotUniqueError", {}>, import("effect/Cause").YieldableError>;
571
+ /**
572
+ * `unique` found at least two emitted values. Narrow the query if at most one
573
+ * value was expected, or use another consumer to handle multiple results.
574
+ *
575
+ * @experimental
576
+ */
577
+ export declare class NotUniqueError extends NotUniqueError_base {
578
+ get message(): string;
579
+ }
580
+ /**
581
+ * Consume a stream expected to emit at most one value. The effect returns
582
+ * `None` for no values and `Some(value)` for one, or fails with
583
+ * `NotUniqueError` for two or more. Like `Stream.runHead` with a uniqueness
584
+ * check, it inspects at most two emitted values; finding them may read
585
+ * additional filtered documents.
586
+ *
587
+ * @experimental
588
+ */
589
+ export declare const unique: <Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R>(self: QueryStream<Doc, KeyLabels, QueryStreamOrderDirection.QueryStreamOrderDirection, E, R>) => Effect.Effect<Option.Option<Doc>, E | NotUniqueError, R>;
590
+ /**
591
+ * Convex pagination options interpreted over a query stream's stored keys. Pass
592
+ * a paginated query handler's `paginationOpts` directly to `paginate`.
593
+ *
594
+ * - `cursor`: required exclusive start boundary; `null` starts at the beginning.
595
+ * - `numItems`: requested emitted values, excluding filtered documents. With an
596
+ * `endCursor`, it is not an item limit, but still informs split
597
+ * recommendations.
598
+ * - `endCursor`: optional inclusive boundary returned by a previous page. Pins
599
+ * the page to a key range regardless of how many values it holds.
600
+ * - `maximumRowsRead`: optional budget for physical document reads from
601
+ * underlying query-stream indexes, including filtered documents.
602
+ * - `maximumBytesRead`: optional budget charging estimated document size on every
603
+ * read, not Convex's exact billed bytes. The final document can take the
604
+ * total over the limit because its size is known only after reading it.
605
+ *
606
+ * With `numItems: 0`, an existing cursor is returned unchanged with an empty
607
+ * page and `isDone: false`; a null cursor dies with `EmptyInitialPageError`.
608
+ *
609
+ * @experimental
610
+ */
611
+ export type PaginateOptions = ConvexPaginationOptions;
612
+ /**
613
+ * One page in Convex's pagination result shape. Return the whole result to
614
+ * reactive clients so they can pin and split pages; use `page` alone for a
615
+ * one-shot read inside a handler.
616
+ *
617
+ * - `page`: emitted values, possibly empty despite progress past filtered keys.
618
+ * - `continueCursor`: the next page's exclusive start. Pass it back unchanged as
619
+ * `cursor` while `isDone` is false.
620
+ * - `splitCursor`: an optional interior boundary. Pin the left page with this as
621
+ * `endCursor`; start the right page here, retaining the original end.
622
+ * - `pageStatus`: `"SplitRequired"` when a read budget stops at a safe boundary,
623
+ * or `"SplitRecommended"` when a pinned page grows too large or a page scans
624
+ * many keys. Both include a `splitCursor`; otherwise status may be absent.
625
+ * - `isDone`: true confirms the stream's end. Reaching a pinned boundary does not
626
+ * prove completion. A split recommendation can report false even at the end,
627
+ * so handle splitting before requesting another page.
628
+ *
629
+ * @experimental
630
+ */
631
+ export type PaginationResult<Doc> = ConvexPaginationResult<Doc>;
632
+ /**
633
+ * Return an effect producing one page of a composed query stream. Start with
634
+ * `cursor: null`, then pass each returned `continueCursor` back unchanged until
635
+ * `isDone`. Cursors record key boundaries, not offsets or the last visible
636
+ * document: filtered elements can advance the cursor without entering `page`.
637
+ *
638
+ * `cursor` is exclusive and `endCursor` is inclusive, in stream order. Without
639
+ * an end boundary, `numItems` limits emitted values. With `endCursor`, the page
640
+ * covers the pinned range regardless of its item count, keeping adjacent
641
+ * reactive pages gap-free as data changes. See `PaginateOptions` for read
642
+ * limits and the special case of a zero-sized request.
643
+ *
644
+ * Bounds are pushed into underlying index queries where possible, but composed
645
+ * streams may read more documents than they return, including documents read on
646
+ * earlier pages. Budgets count filtered documents, distinct-group discovery,
647
+ * repeated seeks, merge prefetch, and both outer and inner query-stream reads
648
+ * in joins. Arbitrary I/O inside callbacks, such as a separate lookup in
649
+ * `mapEffect`, is not tracked.
650
+ *
651
+ * A budget-limited page returns `SplitRequired` at a safe logical boundary. If
652
+ * the budget prevents safe progress or an interior split of a pinned page, the
653
+ * effect fails with `ReadBudgetExceededError` rather than returning a
654
+ * non-advancing cursor. Increase the budget or reduce the reads needed for
655
+ * progress. See `PaginationResult` for split and completion handling.
656
+ *
657
+ * Malformed or incompatible cursors die with a `ConvexError` whose data is `{
658
+ * paginationError: "InvalidCursor" }`; Confect's pagination clients restart
659
+ * from the first page. Restart pagination whenever filters, ordering, or other
660
+ * query semantics change, even if an old cursor is still accepted.
661
+ *
662
+ * Cursors expose boundary field names and key values, including document IDs.
663
+ * They are neither opaque nor signed: clients can read or craft them. Do not
664
+ * publicly paginate over sensitive indexed fields unless pinned with `eq`.
665
+ * Never construct cursors from documents or decode them into `narrow` bounds.
666
+ *
667
+ * Return the whole result to reactive clients. React's
668
+ * `useStreamPaginatedQuery` handles pinning, splitting, and invalid-cursor
669
+ * resets; `usePaginatedQuery` does not support stream pages. Foldkit's
670
+ * `PaginatedQuery` also supports them.
671
+ *
672
+ * @experimental
673
+ */
674
+ export declare const paginate: {
675
+ (options: PaginateOptions): <Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R>(self: QueryStream<Doc, KeyLabels, QueryStreamOrderDirection.QueryStreamOrderDirection, E, R>) => Effect.Effect<PaginationResult<Doc>, E | ReadBudgetExceededError, R>;
676
+ <Doc, KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels, E, R>(self: QueryStream<Doc, KeyLabels, QueryStreamOrderDirection.QueryStreamOrderDirection, E, R>, options: PaginateOptions): Effect.Effect<PaginationResult<Doc>, E | ReadBudgetExceededError, R>;
677
+ };
678
+ //# sourceMappingURL=QueryStream.d.ts.map