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

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,45 @@
1
+ import type * as IdScope from "@confect/core/IdScope";
2
+ import type { GenericDataModel, GenericMutationCtx } from "convex/server";
3
+ import * as Context from "effect/Context";
4
+ import type * as ComponentCtx from "./ComponentCtx";
5
+ import * as Layer from "effect/Layer";
6
+
7
+ export type MutationCtxTag<
8
+ DataModel extends GenericDataModel,
9
+ Scope extends IdScope.IdScope = IdScope.App,
10
+ > = Context.Service<
11
+ MutationCtx<DataModel, Scope>,
12
+ Scope extends IdScope.App
13
+ ? GenericMutationCtx<DataModel>
14
+ : ComponentCtx.Mutation<DataModel, Scope>
15
+ >;
16
+
17
+ export const MutationCtx = <
18
+ DataModel extends GenericDataModel,
19
+ Scope extends IdScope.IdScope = IdScope.App,
20
+ >(): MutationCtxTag<DataModel, Scope> =>
21
+ Context.Service("@confect/server/MutationCtx");
22
+
23
+ export type MutationCtx<
24
+ DataModel extends GenericDataModel,
25
+ Scope extends IdScope.IdScope = IdScope.App,
26
+ > = Scope extends IdScope.App
27
+ ? GenericMutationCtx<DataModel>
28
+ : ComponentCtx.Identifier<"mutation", DataModel, Scope>;
29
+
30
+ export const layer = <
31
+ DataModel extends GenericDataModel,
32
+ Scope extends IdScope.IdScope,
33
+ >(
34
+ ctx: GenericMutationCtx<DataModel>,
35
+ scope: Scope,
36
+ ) => {
37
+ const tag = MutationCtx<DataModel, Scope>();
38
+ const { auth: _auth, ...componentCtx } = ctx;
39
+ return Layer.succeed(
40
+ tag,
41
+ (scope === "" ? ctx : componentCtx) as unknown as Context.Service.Shape<
42
+ typeof tag
43
+ >,
44
+ );
45
+ };
@@ -0,0 +1,66 @@
1
+ import * as Ref from "@confect/core/Ref";
2
+ import type { GenericActionCtx } from "convex/server";
3
+ import * as Context from "effect/Context";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Layer from "effect/Layer";
6
+ import type * as Schema from "effect/Schema";
7
+ import * as MutationTransactionContext from "./MutationTransactionContext";
8
+
9
+ export type Options = MutationTransactionContext.MutationOptions;
10
+
11
+ const run = Effect.fn("MutationRunner.runMutation")(
12
+ <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => effect,
13
+ );
14
+
15
+ const make = (nativeRunMutation: GenericActionCtx<any>["runMutation"]) => {
16
+ function runMutation<Mutation extends Ref.AnyMutation>(
17
+ mutation: Mutation,
18
+ ...args: [...Ref.OptionalArgs<Mutation>, options?: undefined]
19
+ ): Effect.Effect<
20
+ Ref.Returns<Mutation>,
21
+ Ref.Error<Mutation> | Schema.SchemaError
22
+ >;
23
+ function runMutation<Mutation extends Ref.AnyMutation>(
24
+ mutation: Mutation,
25
+ args: Ref.Args<Mutation>,
26
+ options: Options | undefined,
27
+ ): Effect.Effect<
28
+ Ref.Returns<Mutation>,
29
+ Ref.Error<Mutation> | Schema.SchemaError,
30
+ MutationTransactionContext.MutationTransactionContext
31
+ >;
32
+ function runMutation<Mutation extends Ref.AnyMutation>(
33
+ mutation: Mutation,
34
+ args?: Ref.Args<Mutation>,
35
+ options?: Options,
36
+ ): Effect.Effect<
37
+ Ref.Returns<Mutation>,
38
+ Ref.Error<Mutation> | Schema.SchemaError,
39
+ MutationTransactionContext.MutationTransactionContext
40
+ > {
41
+ return run(
42
+ Effect.gen(function* () {
43
+ const actualArgs = (args ?? {}) as Ref.Args<Mutation>;
44
+ if (options !== undefined) {
45
+ const controls =
46
+ yield* MutationTransactionContext.MutationTransactionContext;
47
+ return yield* controls.runMutation(mutation, actualArgs, options);
48
+ }
49
+ return yield* Ref.runWithCodec(
50
+ mutation,
51
+ actualArgs,
52
+ (ref, encodedArgs) => nativeRunMutation(ref, encodedArgs),
53
+ );
54
+ }),
55
+ );
56
+ }
57
+ return { runMutation };
58
+ };
59
+
60
+ export const MutationRunner = Context.Service<ReturnType<typeof make>>(
61
+ "@confect/server/MutationRunner",
62
+ );
63
+ export type MutationRunner = typeof MutationRunner.Identifier;
64
+
65
+ export const layer = (runMutation: GenericActionCtx<any>["runMutation"]) =>
66
+ Layer.succeed(MutationRunner, make(runMutation));
@@ -0,0 +1,48 @@
1
+ import * as Ref from "@confect/core/Ref";
2
+ import type {
3
+ AdvancedRunQueryOptions,
4
+ GenericDataModel,
5
+ GenericMutationCtx,
6
+ } from "convex/server";
7
+ import * as Context from "effect/Context";
8
+ import * as Effect from "effect/Effect";
9
+ import * as Layer from "effect/Layer";
10
+ import type { Options as MutationOptions } from "./QueryTransactionContext";
11
+
12
+ export type { TransactionLimits } from "convex/server";
13
+ export type { Options as MutationOptions } from "./QueryTransactionContext";
14
+ export type QueryOptions = AdvancedRunQueryOptions;
15
+
16
+ const make = (
17
+ ctx: Pick<GenericMutationCtx<GenericDataModel>, "runQuery" | "runMutation">,
18
+ ) => ({
19
+ runQuery: Effect.fn("MutationTransactionContext.runQuery")(
20
+ <Query extends Ref.AnyQuery>(
21
+ query: Query,
22
+ args: Ref.Args<Query>,
23
+ options: QueryOptions,
24
+ ) =>
25
+ Ref.runWithCodec(query, args, (ref, encodedArgs) =>
26
+ ctx.runQuery(ref, encodedArgs, options),
27
+ ),
28
+ ),
29
+ runMutation: Effect.fn("MutationTransactionContext.runMutation")(
30
+ <Mutation extends Ref.AnyMutation>(
31
+ mutation: Mutation,
32
+ args: Ref.Args<Mutation>,
33
+ options: MutationOptions,
34
+ ) =>
35
+ Ref.runWithCodec(mutation, args, (ref, encodedArgs) =>
36
+ ctx.runMutation(ref, encodedArgs, options),
37
+ ),
38
+ ),
39
+ });
40
+
41
+ export class MutationTransactionContext extends Context.Service<
42
+ MutationTransactionContext,
43
+ ReturnType<typeof make>
44
+ >()("@confect/server/MutationTransactionContext") {}
45
+
46
+ export const layer = (
47
+ ctx: Pick<GenericMutationCtx<GenericDataModel>, "runQuery" | "runMutation">,
48
+ ) => Layer.succeed(MutationTransactionContext, make(ctx));
@@ -0,0 +1,136 @@
1
+ import type * as IdScope from "@confect/core/IdScope";
2
+ import type {
3
+ ExpressionOrValue,
4
+ FilterBuilder,
5
+ OrderedQuery as ConvexOrderedQuery,
6
+ PaginationOptions,
7
+ PaginationResult,
8
+ } from "convex/server";
9
+ import { identity, pipe } from "effect/Function";
10
+ import type { Option } from "effect";
11
+ import * as Effect from "effect/Effect";
12
+ import * as Stream from "effect/Stream";
13
+ import type * as DatabaseSchema from "./DatabaseSchema";
14
+ import * as Document from "./Document";
15
+ import type * as TableInfo from "./TableInfo";
16
+ import type * as Table from "./Table";
17
+
18
+ type NativePaginate<TableInfo_ extends TableInfo.AnyWithProps, Doc> = (
19
+ options: PaginationOptions,
20
+ filter?: (
21
+ q: FilterBuilder<TableInfo.ConvexTableInfo<TableInfo_>>,
22
+ ) => ExpressionOrValue<boolean>,
23
+ ) => Effect.Effect<PaginationResult<Doc>, Document.DocumentDecodeError>;
24
+
25
+ export type OrderedQuery<
26
+ TableInfo_ extends TableInfo.AnyWithProps,
27
+ Doc = TableInfo_["document"],
28
+ TargetKind extends DatabaseSchema.Target["kind"] = "app",
29
+ > = {
30
+ readonly first: () => Effect.Effect<
31
+ Option.Option<Doc>,
32
+ Document.DocumentDecodeError
33
+ >;
34
+ readonly take: (
35
+ n: number,
36
+ ) => Effect.Effect<ReadonlyArray<Doc>, Document.DocumentDecodeError>;
37
+ readonly collect: () => Effect.Effect<
38
+ ReadonlyArray<Doc>,
39
+ Document.DocumentDecodeError
40
+ >;
41
+ readonly stream: () => Stream.Stream<Doc, Document.DocumentDecodeError>;
42
+ /**
43
+ * Native pagination is application-only. Use `QueryStream.paginate` for
44
+ * component index queries.
45
+ */
46
+ readonly paginate: {
47
+ readonly app: NativePaginate<TableInfo_, Doc>;
48
+ readonly component: {
49
+ readonly "Native pagination is unavailable in components. Use QueryStream.paginate for index queries.": never;
50
+ };
51
+ }[TargetKind];
52
+ };
53
+
54
+ export function make<Table_ extends Table.AnyWithProps>(
55
+ query: ConvexOrderedQuery<
56
+ TableInfo.ConvexTableInfo<TableInfo.TableInfo<Table_>>
57
+ >,
58
+ table: Table_ & { readonly scope: IdScope.App },
59
+ ): OrderedQuery<TableInfo.TableInfo<Table_>>;
60
+ export function make<Table_ extends Table.AnyWithProps>(
61
+ query: ConvexOrderedQuery<
62
+ TableInfo.ConvexTableInfo<TableInfo.TableInfo<Table_>>
63
+ >,
64
+ table: Table_,
65
+ ): OrderedQuery<
66
+ TableInfo.TableInfo<Table_>,
67
+ TableInfo.TableInfo<Table_>["document"],
68
+ Table.Scope<Table_> extends IdScope.App ? "app" : "component"
69
+ >;
70
+ export function make<Table_ extends Table.AnyWithProps>(
71
+ query: ConvexOrderedQuery<
72
+ TableInfo.ConvexTableInfo<TableInfo.TableInfo<Table_>>
73
+ >,
74
+ table: Table_,
75
+ ): OrderedQuery<
76
+ TableInfo.TableInfo<Table_>,
77
+ TableInfo.TableInfo<Table_>["document"],
78
+ DatabaseSchema.Target["kind"]
79
+ > {
80
+ type TableInfo_ = TableInfo.TableInfo<Table_>;
81
+ type OrderedQueryFunction<
82
+ FunctionName extends keyof OrderedQuery<TableInfo_>,
83
+ > = OrderedQuery<TableInfo_>[FunctionName];
84
+
85
+ const streamEncoded = Stream.fromAsyncIterable(query, identity).pipe(
86
+ Stream.orDie,
87
+ );
88
+
89
+ const stream: OrderedQueryFunction<"stream"> = () =>
90
+ pipe(streamEncoded, Stream.mapEffect(Document.decode(table)));
91
+
92
+ const first: OrderedQueryFunction<"first"> = () =>
93
+ pipe(stream(), Stream.take(1), Stream.runHead);
94
+
95
+ const take: OrderedQueryFunction<"take"> = (n: number) =>
96
+ pipe(stream(), Stream.take(n), Stream.runCollect);
97
+
98
+ const collect: OrderedQueryFunction<"collect"> = () =>
99
+ pipe(stream(), Stream.runCollect);
100
+
101
+ const paginate: NativePaginate<TableInfo_, TableInfo_["document"]> =
102
+ Effect.fn("OrderedQuery.paginate")(function* (options, filter) {
103
+ const filteredQuery = filter !== undefined ? query.filter(filter) : query;
104
+
105
+ const paginationResult = yield* Effect.promise(() =>
106
+ filteredQuery.paginate(options),
107
+ );
108
+
109
+ const parsedPage = yield* Effect.forEach(
110
+ paginationResult.page,
111
+ Document.decode(table),
112
+ );
113
+
114
+ return {
115
+ page: parsedPage,
116
+ isDone: paginationResult.isDone,
117
+ continueCursor: paginationResult.continueCursor,
118
+ /* v8 ignore start */
119
+ ...(paginationResult.splitCursor
120
+ ? { splitCursor: paginationResult.splitCursor }
121
+ : {}),
122
+ ...(paginationResult.pageStatus
123
+ ? { pageStatus: paginationResult.pageStatus }
124
+ : {}),
125
+ /* v8 ignore stop */
126
+ };
127
+ });
128
+
129
+ return {
130
+ first,
131
+ take,
132
+ collect,
133
+ paginate,
134
+ stream,
135
+ };
136
+ }
@@ -0,0 +1,45 @@
1
+ import type * as IdScope from "@confect/core/IdScope";
2
+ import type { GenericDataModel, GenericQueryCtx } from "convex/server";
3
+ import * as Context from "effect/Context";
4
+ import type * as ComponentCtx from "./ComponentCtx";
5
+ import * as Layer from "effect/Layer";
6
+
7
+ export type QueryCtxTag<
8
+ DataModel extends GenericDataModel,
9
+ Scope extends IdScope.IdScope = IdScope.App,
10
+ > = Context.Service<
11
+ QueryCtx<DataModel, Scope>,
12
+ Scope extends IdScope.App
13
+ ? GenericQueryCtx<DataModel>
14
+ : ComponentCtx.Query<DataModel, Scope>
15
+ >;
16
+
17
+ export const QueryCtx = <
18
+ DataModel extends GenericDataModel,
19
+ Scope extends IdScope.IdScope = IdScope.App,
20
+ >(): QueryCtxTag<DataModel, Scope> =>
21
+ Context.Service("@confect/server/QueryCtx");
22
+
23
+ export type QueryCtx<
24
+ DataModel extends GenericDataModel,
25
+ Scope extends IdScope.IdScope = IdScope.App,
26
+ > = Scope extends IdScope.App
27
+ ? GenericQueryCtx<DataModel>
28
+ : ComponentCtx.Identifier<"query", DataModel, Scope>;
29
+
30
+ export const layer = <
31
+ DataModel extends GenericDataModel,
32
+ Scope extends IdScope.IdScope,
33
+ >(
34
+ ctx: GenericQueryCtx<DataModel>,
35
+ scope: Scope,
36
+ ) => {
37
+ const tag = QueryCtx<DataModel, Scope>();
38
+ const { auth: _auth, ...componentCtx } = ctx;
39
+ return Layer.succeed(
40
+ tag,
41
+ (scope === "" ? ctx : componentCtx) as unknown as Context.Service.Shape<
42
+ typeof tag
43
+ >,
44
+ );
45
+ };