@gaganref/confect-server 10.3.1-fork.3 → 10.3.1-fork.30

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 (273) hide show
  1. package/dist/ActionCall.d.ts +30 -0
  2. package/dist/ActionCall.d.ts.map +1 -0
  3. package/dist/ActionCall.js +41 -0
  4. package/dist/ActionCall.js.map +1 -0
  5. package/dist/ActionCtx.d.ts +1 -1
  6. package/dist/ActionCtx.d.ts.map +1 -1
  7. package/dist/ActionCtx.js.map +1 -1
  8. package/dist/ActionRunner.js +2 -2
  9. package/dist/AiGatewayDecisionClient.d.ts +2 -2
  10. package/dist/AiGatewayDecisionClient.d.ts.map +1 -1
  11. package/dist/AiGatewayDecisionClient.js +1 -1
  12. package/dist/AiGatewayDecisionClient.js.map +1 -1
  13. package/dist/AiGatewayLanguageClient.d.ts +2 -2
  14. package/dist/AiGatewayLanguageClient.d.ts.map +1 -1
  15. package/dist/AiGatewayLanguageClient.js +1 -1
  16. package/dist/AiGatewayLanguageClient.js.map +1 -1
  17. package/dist/Auth.d.ts +1 -1
  18. package/dist/Auth.d.ts.map +1 -1
  19. package/dist/Auth.js +1 -1
  20. package/dist/Auth.js.map +1 -1
  21. package/dist/Callback.js +3 -3
  22. package/dist/ComponentCtx.d.ts +1 -1
  23. package/dist/ComponentCtx.d.ts.map +1 -1
  24. package/dist/ConvexConfigProvider.js +2 -2
  25. package/dist/ConvexFunctionDefinitions.d.ts +4 -4
  26. package/dist/ConvexFunctionDefinitions.d.ts.map +1 -1
  27. package/dist/ConvexFunctionDefinitions.js +2 -2
  28. package/dist/ConvexFunctionDefinitions.js.map +1 -1
  29. package/dist/ConvexLogger.js +1 -1
  30. package/dist/CronJobs.d.ts +1 -1
  31. package/dist/CronJobs.d.ts.map +1 -1
  32. package/dist/CronJobs.js +6 -6
  33. package/dist/CronJobs.js.map +1 -1
  34. package/dist/DataModel.d.ts +3 -3
  35. package/dist/DataModel.d.ts.map +1 -1
  36. package/dist/DataModel.js.map +1 -1
  37. package/dist/DatabaseReader.d.ts +4 -4
  38. package/dist/DatabaseReader.d.ts.map +1 -1
  39. package/dist/DatabaseReader.js.map +1 -1
  40. package/dist/DatabaseSchema.d.ts +1 -1
  41. package/dist/DatabaseSchema.d.ts.map +1 -1
  42. package/dist/DatabaseSchema.js +2 -2
  43. package/dist/DatabaseSchema.js.map +1 -1
  44. package/dist/DatabaseWriter.d.ts +41 -7
  45. package/dist/DatabaseWriter.d.ts.map +1 -1
  46. package/dist/DatabaseWriter.js +55 -8
  47. package/dist/DatabaseWriter.js.map +1 -1
  48. package/dist/Document.d.ts +4 -4
  49. package/dist/Document.d.ts.map +1 -1
  50. package/dist/Document.js.map +1 -1
  51. package/dist/ExecutionMetadata.js +1 -1
  52. package/dist/FunctionImpl.d.ts +2 -2
  53. package/dist/FunctionImpl.d.ts.map +1 -1
  54. package/dist/FunctionImpl.js +2 -2
  55. package/dist/FunctionImpl.js.map +1 -1
  56. package/dist/FunctionRegistryItem.d.ts +1 -1
  57. package/dist/FunctionRegistryItem.d.ts.map +1 -1
  58. package/dist/FunctionRegistryItem.js +1 -1
  59. package/dist/FunctionRegistryItem.js.map +1 -1
  60. package/dist/GroupImpl.d.ts +24 -5
  61. package/dist/GroupImpl.d.ts.map +1 -1
  62. package/dist/GroupImpl.js +21 -22
  63. package/dist/GroupImpl.js.map +1 -1
  64. package/dist/GroupRegistry.d.ts +2 -2
  65. package/dist/GroupRegistry.d.ts.map +1 -1
  66. package/dist/GroupRegistry.js.map +1 -1
  67. package/dist/Handler.d.ts +30 -26
  68. package/dist/Handler.d.ts.map +1 -1
  69. package/dist/Handler.js.map +1 -1
  70. package/dist/HttpRouter.d.ts +13 -13
  71. package/dist/HttpRouter.d.ts.map +1 -1
  72. package/dist/HttpRouter.js +2 -2
  73. package/dist/HttpRouter.js.map +1 -1
  74. package/dist/MiddlewareImpl.d.ts +14 -14
  75. package/dist/MiddlewareImpl.d.ts.map +1 -1
  76. package/dist/MiddlewareImpl.js +1 -1
  77. package/dist/MiddlewareImpl.js.map +1 -1
  78. package/dist/MutationCtx.d.ts +1 -1
  79. package/dist/MutationCtx.d.ts.map +1 -1
  80. package/dist/MutationCtx.js.map +1 -1
  81. package/dist/MutationRunner.d.ts +1 -1
  82. package/dist/MutationRunner.d.ts.map +1 -1
  83. package/dist/MutationRunner.js +2 -2
  84. package/dist/MutationRunner.js.map +1 -1
  85. package/dist/MutationTransactionContext.d.ts +2 -2
  86. package/dist/MutationTransactionContext.d.ts.map +1 -1
  87. package/dist/MutationTransactionContext.js +2 -2
  88. package/dist/MutationTransactionContext.js.map +1 -1
  89. package/dist/OfficialComponent.d.ts +50 -0
  90. package/dist/OfficialComponent.d.ts.map +1 -0
  91. package/dist/OfficialComponent.js +70 -0
  92. package/dist/OfficialComponent.js.map +1 -0
  93. package/dist/OrderedQuery.d.ts +4 -4
  94. package/dist/OrderedQuery.d.ts.map +1 -1
  95. package/dist/OrderedQuery.js.map +1 -1
  96. package/dist/QueryCtx.d.ts +1 -1
  97. package/dist/QueryCtx.d.ts.map +1 -1
  98. package/dist/QueryCtx.js.map +1 -1
  99. package/dist/QueryInitializer.d.ts +10 -10
  100. package/dist/QueryInitializer.d.ts.map +1 -1
  101. package/dist/QueryInitializer.js +2 -2
  102. package/dist/QueryInitializer.js.map +1 -1
  103. package/dist/QueryRunner.d.ts +2 -2
  104. package/dist/QueryRunner.d.ts.map +1 -1
  105. package/dist/QueryRunner.js +2 -2
  106. package/dist/QueryRunner.js.map +1 -1
  107. package/dist/QueryStream.d.ts +86 -13
  108. package/dist/QueryStream.d.ts.map +1 -1
  109. package/dist/QueryStream.js +81 -8
  110. package/dist/QueryStream.js.map +1 -1
  111. package/dist/QueryStreamCursor.d.ts +2 -2
  112. package/dist/QueryStreamCursor.d.ts.map +1 -1
  113. package/dist/QueryStreamCursor.js +1 -1
  114. package/dist/QueryStreamCursor.js.map +1 -1
  115. package/dist/QueryStreamIndexPrefix.d.ts +2 -2
  116. package/dist/QueryStreamIndexPrefix.d.ts.map +1 -1
  117. package/dist/QueryStreamIndexPrefix.js +1 -1
  118. package/dist/QueryStreamIndexPrefix.js.map +1 -1
  119. package/dist/QueryStreamIndexRange.d.ts +4 -4
  120. package/dist/QueryStreamIndexRange.d.ts.map +1 -1
  121. package/dist/QueryStreamIndexRange.js +2 -2
  122. package/dist/QueryStreamIndexRange.js.map +1 -1
  123. package/dist/QueryStreamKey.d.ts +2 -2
  124. package/dist/QueryStreamKey.d.ts.map +1 -1
  125. package/dist/QueryStreamKey.js +1 -1
  126. package/dist/QueryStreamKey.js.map +1 -1
  127. package/dist/QueryStreamKeyBounds.d.ts +3 -3
  128. package/dist/QueryStreamKeyBounds.d.ts.map +1 -1
  129. package/dist/QueryStreamKeyBounds.js +2 -2
  130. package/dist/QueryStreamKeyBounds.js.map +1 -1
  131. package/dist/QueryStreamKeyLayout.d.ts +1 -1
  132. package/dist/QueryStreamKeyLayout.d.ts.map +1 -1
  133. package/dist/QueryStreamKeyLayout.js +2 -2
  134. package/dist/QueryStreamKeyLayout.js.map +1 -1
  135. package/dist/QueryStreamKeyValues.d.ts +1 -1
  136. package/dist/QueryStreamKeyValues.d.ts.map +1 -1
  137. package/dist/QueryStreamKeyValues.js +1 -1
  138. package/dist/QueryStreamKeyValues.js.map +1 -1
  139. package/dist/QueryStreamPagination.d.ts +1 -1
  140. package/dist/QueryStreamPagination.d.ts.map +1 -1
  141. package/dist/QueryStreamPagination.js +1 -1
  142. package/dist/QueryStreamPagination.js.map +1 -1
  143. package/dist/QueryStreamReadBudget.d.ts +3 -2
  144. package/dist/QueryStreamReadBudget.d.ts.map +1 -1
  145. package/dist/QueryStreamReadBudget.js +6 -3
  146. package/dist/QueryStreamReadBudget.js.map +1 -1
  147. package/dist/QueryTransactionContext.js +2 -2
  148. package/dist/RegisteredConvexFunction.d.ts +20 -20
  149. package/dist/RegisteredConvexFunction.d.ts.map +1 -1
  150. package/dist/RegisteredConvexFunction.js +19 -19
  151. package/dist/RegisteredConvexFunction.js.map +1 -1
  152. package/dist/RegisteredFunction.d.ts +26 -26
  153. package/dist/RegisteredFunction.d.ts.map +1 -1
  154. package/dist/RegisteredFunction.js +55 -13
  155. package/dist/RegisteredFunction.js.map +1 -1
  156. package/dist/RegisteredFunctions.d.ts +3 -3
  157. package/dist/RegisteredFunctions.d.ts.map +1 -1
  158. package/dist/RegisteredFunctions.js.map +1 -1
  159. package/dist/RegisteredNodeFunction.d.ts +6 -6
  160. package/dist/RegisteredNodeFunction.d.ts.map +1 -1
  161. package/dist/RegisteredNodeFunction.js +1 -1
  162. package/dist/RegisteredNodeFunction.js.map +1 -1
  163. package/dist/Registry.d.ts +1 -1
  164. package/dist/Registry.d.ts.map +1 -1
  165. package/dist/Registry.js.map +1 -1
  166. package/dist/RegistryItems.d.ts +7 -0
  167. package/dist/RegistryItems.d.ts.map +1 -1
  168. package/dist/RegistryItems.js +8 -3
  169. package/dist/RegistryItems.js.map +1 -1
  170. package/dist/RequestMetadata.js +1 -1
  171. package/dist/ResolvedMiddleware.d.ts +2 -2
  172. package/dist/ResolvedMiddleware.d.ts.map +1 -1
  173. package/dist/ResolvedMiddleware.js.map +1 -1
  174. package/dist/Scheduler.js +2 -2
  175. package/dist/Storage.d.ts +6 -6
  176. package/dist/Storage.d.ts.map +1 -1
  177. package/dist/Storage.js +1 -1
  178. package/dist/Storage.js.map +1 -1
  179. package/dist/StorageActionWriter.d.ts +1 -1
  180. package/dist/StorageActionWriter.d.ts.map +1 -1
  181. package/dist/StorageActionWriter.js +1 -1
  182. package/dist/StorageActionWriter.js.map +1 -1
  183. package/dist/StorageReader.d.ts +1 -1
  184. package/dist/StorageReader.d.ts.map +1 -1
  185. package/dist/StorageReader.js +1 -1
  186. package/dist/StorageReader.js.map +1 -1
  187. package/dist/StorageWriter.d.ts +1 -1
  188. package/dist/StorageWriter.d.ts.map +1 -1
  189. package/dist/StorageWriter.js +1 -1
  190. package/dist/StorageWriter.js.map +1 -1
  191. package/dist/TableInfo.d.ts +2 -2
  192. package/dist/TableInfo.d.ts.map +1 -1
  193. package/dist/TableInfo.js.map +1 -1
  194. package/dist/TransactionMetadata.js +1 -1
  195. package/dist/VectorSearch.d.ts +1 -1
  196. package/dist/VectorSearch.d.ts.map +1 -1
  197. package/dist/VectorSearch.js +1 -1
  198. package/dist/VectorSearch.js.map +1 -1
  199. package/dist/index.d.ts +62 -60
  200. package/dist/index.d.ts.map +1 -1
  201. package/dist/index.js +11 -9
  202. package/dist/internal/AiGatewayDecisionClient.d.ts +1 -1
  203. package/dist/internal/AiGatewayDecisionClient.d.ts.map +1 -1
  204. package/dist/internal/AiGatewayDecisionClient.js +1 -1
  205. package/dist/internal/AiGatewayDecisionClient.js.map +1 -1
  206. package/dist/internal/AiGatewayLanguageClient.d.ts +1 -1
  207. package/dist/internal/AiGatewayLanguageClient.d.ts.map +1 -1
  208. package/dist/internal/AiGatewayLanguageClient.js +1 -1
  209. package/dist/internal/AiGatewayLanguageClient.js.map +1 -1
  210. package/dist/internal/AiGatewayServiceToken.js +1 -1
  211. package/dist/internal/DocumentPatch.d.ts +16 -0
  212. package/dist/internal/DocumentPatch.d.ts.map +1 -0
  213. package/dist/internal/DocumentPatch.js +36 -0
  214. package/dist/internal/DocumentPatch.js.map +1 -0
  215. package/dist/node.d.ts +1 -1
  216. package/dist/node.d.ts.map +1 -1
  217. package/package.json +2 -2
  218. package/src/ActionCall.ts +82 -0
  219. package/src/ActionCtx.ts +1 -1
  220. package/src/AiGatewayDecisionClient.ts +3 -3
  221. package/src/AiGatewayLanguageClient.ts +3 -3
  222. package/src/Auth.ts +1 -1
  223. package/src/ComponentCtx.ts +1 -1
  224. package/src/ConvexFunctionDefinitions.ts +8 -8
  225. package/src/CronJobs.ts +1 -1
  226. package/src/DataModel.ts +3 -3
  227. package/src/DatabaseReader.ts +4 -4
  228. package/src/DatabaseSchema.ts +1 -1
  229. package/src/DatabaseWriter.ts +189 -31
  230. package/src/Document.ts +4 -4
  231. package/src/FunctionImpl.ts +5 -5
  232. package/src/FunctionRegistryItem.ts +1 -1
  233. package/src/GroupImpl.ts +66 -13
  234. package/src/GroupRegistry.ts +4 -4
  235. package/src/Handler.ts +43 -28
  236. package/src/HttpRouter.ts +17 -17
  237. package/src/MiddlewareImpl.ts +17 -17
  238. package/src/MutationCtx.ts +1 -1
  239. package/src/MutationRunner.ts +1 -1
  240. package/src/MutationTransactionContext.ts +2 -2
  241. package/src/OfficialComponent.ts +151 -0
  242. package/src/OrderedQuery.ts +4 -4
  243. package/src/QueryCtx.ts +1 -1
  244. package/src/QueryInitializer.ts +9 -9
  245. package/src/QueryRunner.ts +2 -2
  246. package/src/QueryStream.ts +212 -20
  247. package/src/QueryStreamCursor.ts +3 -3
  248. package/src/QueryStreamIndexPrefix.ts +2 -2
  249. package/src/QueryStreamIndexRange.ts +4 -4
  250. package/src/QueryStreamKey.ts +2 -2
  251. package/src/QueryStreamKeyBounds.ts +3 -3
  252. package/src/QueryStreamKeyLayout.ts +1 -1
  253. package/src/QueryStreamKeyValues.ts +1 -1
  254. package/src/QueryStreamPagination.ts +2 -2
  255. package/src/QueryStreamReadBudget.ts +19 -6
  256. package/src/RegisteredConvexFunction.ts +21 -21
  257. package/src/RegisteredFunction.ts +72 -19
  258. package/src/RegisteredFunctions.ts +4 -4
  259. package/src/RegisteredNodeFunction.ts +8 -8
  260. package/src/Registry.ts +1 -1
  261. package/src/RegistryItems.ts +33 -2
  262. package/src/ResolvedMiddleware.ts +2 -2
  263. package/src/Storage.ts +3 -3
  264. package/src/StorageActionWriter.ts +1 -1
  265. package/src/StorageReader.ts +1 -1
  266. package/src/StorageWriter.ts +1 -1
  267. package/src/TableInfo.ts +2 -2
  268. package/src/VectorSearch.ts +1 -1
  269. package/src/index.ts +62 -60
  270. package/src/internal/AiGatewayDecisionClient.ts +2 -2
  271. package/src/internal/AiGatewayLanguageClient.ts +2 -2
  272. package/src/internal/DocumentPatch.ts +87 -0
  273. package/src/node.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"DatabaseReader.js","names":["Table.systemTablesForScope","DatabaseSchema.tables","QueryInitializer.make"],"sources":["../src/DatabaseReader.ts"],"sourcesContent":["import type { GenericDatabaseReader } from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport * as Layer from \"effect/Layer\";\nimport type { BaseDatabaseReader } from \"@confect/core/Types\";\nimport * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as DataModel from \"./DataModel\";\nimport * as QueryInitializer from \"./QueryInitializer\";\nimport * as Table from \"./Table\";\n\ntype IncludedTables<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> =\n | DatabaseSchema.Tables<DatabaseSchema_>\n | Table.SystemTables<DatabaseSchema.Scope<DatabaseSchema_>>;\n\ntype IncludedDataModel<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> =\n DataModel.FromTables<IncludedTables<DatabaseSchema_>>;\n\nexport interface DatabaseReaderService<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n> {\n readonly table: <\n const TableName extends Table.Name<IncludedTables<DatabaseSchema_>>,\n >(\n tableName: TableName,\n ) => QueryInitializer.QueryInitializer<\n IncludedDataModel<DatabaseSchema_>,\n TableName,\n TableName extends keyof Docs\n ? Docs[TableName]\n : DataModel.DocumentWithName<\n IncludedDataModel<DatabaseSchema_>,\n TableName\n >,\n DatabaseSchema_[\"target\"][\"kind\"]\n >;\n}\n\nexport const make = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexDatabaseReader: GenericDatabaseReader<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n): DatabaseReaderService<DatabaseSchema_> => {\n const systemTables = Table.systemTablesForScope(databaseSchema.target.scope);\n return {\n table: <\n const TableName extends Table.Name<IncludedTables<DatabaseSchema_>>,\n >(\n tableName: TableName,\n ) => {\n const isSystem = Object.hasOwn(systemTables, tableName);\n\n const baseDatabaseReader: BaseDatabaseReader<any> = isSystem\n ? {\n get: convexDatabaseReader.system.get.bind(\n convexDatabaseReader.system,\n ),\n query: convexDatabaseReader.system.query.bind(\n convexDatabaseReader.system,\n ),\n }\n : {\n get: convexDatabaseReader.get.bind(convexDatabaseReader),\n query: convexDatabaseReader.query.bind(convexDatabaseReader),\n };\n\n const table = (\n isSystem\n ? (systemTables as Record<string, Table.AnyWithProps>)[tableName]\n : DatabaseSchema.tables(databaseSchema)[tableName]\n ) as Table.WithName<IncludedTables<DatabaseSchema_>, TableName>;\n\n return QueryInitializer.make<IncludedTables<DatabaseSchema_>, TableName>(\n baseDatabaseReader,\n table,\n );\n },\n } as DatabaseReaderService<DatabaseSchema_>;\n};\n\n/**\n * The tag's _Identifier_ (the Effect requirements-channel type) is\n * `Docs`-independent so a helper's `R` channel is the same whether or not a\n * codegen document registry is supplied—this keeps it identical to what\n * `Handler`/runtime provisioning provide. The tag's _Service_ (what `yield*`\n * produces) carries `Docs`, so queries resolve to the named doc interfaces.\n */\nexport type DatabaseReaderTag<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n> = Context.Service<\n DatabaseReaderService<DatabaseSchema_>,\n DatabaseReaderService<DatabaseSchema_, Docs>\n>;\n\nexport const DatabaseReader = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n>(): DatabaseReaderTag<DatabaseSchema_, Docs> =>\n Context.Service<\n DatabaseReaderService<DatabaseSchema_>,\n DatabaseReaderService<DatabaseSchema_, Docs>\n >(\"@confect/server/DatabaseReader\");\n\nexport type DatabaseReader<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n> = DatabaseReaderService<DatabaseSchema_>;\n\nexport const layer = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexDatabaseReader: GenericDatabaseReader<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n) =>\n Layer.succeed(\n DatabaseReader<DatabaseSchema_>(),\n make(databaseSchema, convexDatabaseReader),\n );\n"],"mappings":";;;;;;;;;;;;AAqCA,MAAa,QACX,gBACA,yBAG2C;CAC3C,MAAM,eAAeA,qBAA2B,eAAe,OAAO,KAAK;CAC3E,OAAO,EACL,QAGE,cACG;EACH,MAAM,WAAW,OAAO,OAAO,cAAc,SAAS;EAEtD,MAAM,qBAA8C,WAChD;GACE,KAAK,qBAAqB,OAAO,IAAI,KACnC,qBAAqB,MACvB;GACA,OAAO,qBAAqB,OAAO,MAAM,KACvC,qBAAqB,MACvB;EACF,IACA;GACE,KAAK,qBAAqB,IAAI,KAAK,oBAAoB;GACvD,OAAO,qBAAqB,MAAM,KAAK,oBAAoB;EAC7D;EAEJ,MAAM,QACJ,WACK,aAAoD,aACrDC,OAAsB,cAAc,CAAC,CAAC;EAG5C,OAAOC,OACL,oBACA,KACF;CACF,EACF;AACF;AAiBA,MAAa,uBAIX,QAAQ,QAGN,gCAAgC;AAMpC,MAAa,SACX,gBACA,yBAIA,MAAM,QACJ,eAAgC,GAChC,KAAK,gBAAgB,oBAAoB,CAC3C"}
1
+ {"version":3,"file":"DatabaseReader.js","names":["Table.systemTablesForScope","DatabaseSchema.tables","QueryInitializer.make"],"sources":["../src/DatabaseReader.ts"],"sourcesContent":["import type { GenericDatabaseReader } from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport * as Layer from \"effect/Layer\";\nimport type { BaseDatabaseReader } from \"@confect/core/Types\";\nimport * as DatabaseSchema from \"./DatabaseSchema.js\";\nimport type * as DataModel from \"./DataModel.js\";\nimport * as QueryInitializer from \"./QueryInitializer.js\";\nimport * as Table from \"./Table.js\";\n\ntype IncludedTables<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> =\n | DatabaseSchema.Tables<DatabaseSchema_>\n | Table.SystemTables<DatabaseSchema.Scope<DatabaseSchema_>>;\n\ntype IncludedDataModel<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> =\n DataModel.FromTables<IncludedTables<DatabaseSchema_>>;\n\nexport interface DatabaseReaderService<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n> {\n readonly table: <\n const TableName extends Table.Name<IncludedTables<DatabaseSchema_>>,\n >(\n tableName: TableName,\n ) => QueryInitializer.QueryInitializer<\n IncludedDataModel<DatabaseSchema_>,\n TableName,\n TableName extends keyof Docs\n ? Docs[TableName]\n : DataModel.DocumentWithName<\n IncludedDataModel<DatabaseSchema_>,\n TableName\n >,\n DatabaseSchema_[\"target\"][\"kind\"]\n >;\n}\n\nexport const make = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexDatabaseReader: GenericDatabaseReader<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n): DatabaseReaderService<DatabaseSchema_> => {\n const systemTables = Table.systemTablesForScope(databaseSchema.target.scope);\n return {\n table: <\n const TableName extends Table.Name<IncludedTables<DatabaseSchema_>>,\n >(\n tableName: TableName,\n ) => {\n const isSystem = Object.hasOwn(systemTables, tableName);\n\n const baseDatabaseReader: BaseDatabaseReader<any> = isSystem\n ? {\n get: convexDatabaseReader.system.get.bind(\n convexDatabaseReader.system,\n ),\n query: convexDatabaseReader.system.query.bind(\n convexDatabaseReader.system,\n ),\n }\n : {\n get: convexDatabaseReader.get.bind(convexDatabaseReader),\n query: convexDatabaseReader.query.bind(convexDatabaseReader),\n };\n\n const table = (\n isSystem\n ? (systemTables as Record<string, Table.AnyWithProps>)[tableName]\n : DatabaseSchema.tables(databaseSchema)[tableName]\n ) as Table.WithName<IncludedTables<DatabaseSchema_>, TableName>;\n\n return QueryInitializer.make<IncludedTables<DatabaseSchema_>, TableName>(\n baseDatabaseReader,\n table,\n );\n },\n } as DatabaseReaderService<DatabaseSchema_>;\n};\n\n/**\n * The tag's _Identifier_ (the Effect requirements-channel type) is\n * `Docs`-independent so a helper's `R` channel is the same whether or not a\n * codegen document registry is supplied—this keeps it identical to what\n * `Handler`/runtime provisioning provide. The tag's _Service_ (what `yield*`\n * produces) carries `Docs`, so queries resolve to the named doc interfaces.\n */\nexport type DatabaseReaderTag<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n> = Context.Service<\n DatabaseReaderService<DatabaseSchema_>,\n DatabaseReaderService<DatabaseSchema_, Docs>\n>;\n\nexport const DatabaseReader = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n>(): DatabaseReaderTag<DatabaseSchema_, Docs> =>\n Context.Service<\n DatabaseReaderService<DatabaseSchema_>,\n DatabaseReaderService<DatabaseSchema_, Docs>\n >(\"@confect/server/DatabaseReader\");\n\nexport type DatabaseReader<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n> = DatabaseReaderService<DatabaseSchema_>;\n\nexport const layer = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexDatabaseReader: GenericDatabaseReader<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n) =>\n Layer.succeed(\n DatabaseReader<DatabaseSchema_>(),\n make(databaseSchema, convexDatabaseReader),\n );\n"],"mappings":";;;;;;;;;;;;AAqCA,MAAa,QACX,gBACA,yBAG2C;CAC3C,MAAM,eAAeA,qBAA2B,eAAe,OAAO,KAAK;CAC3E,OAAO,EACL,QAGE,cACG;EACH,MAAM,WAAW,OAAO,OAAO,cAAc,SAAS;EAEtD,MAAM,qBAA8C,WAChD;GACE,KAAK,qBAAqB,OAAO,IAAI,KACnC,qBAAqB,MACvB;GACA,OAAO,qBAAqB,OAAO,MAAM,KACvC,qBAAqB,MACvB;EACF,IACA;GACE,KAAK,qBAAqB,IAAI,KAAK,oBAAoB;GACvD,OAAO,qBAAqB,MAAM,KAAK,oBAAoB;EAC7D;EAEJ,MAAM,QACJ,WACK,aAAoD,aACrDC,OAAsB,cAAc,CAAC,CAAC;EAG5C,OAAOC,OACL,oBACA,KACF;CACF,EACF;AACF;AAiBA,MAAa,uBAIX,QAAQ,QAGN,gCAAgC;AAMpC,MAAa,SACX,gBACA,yBAIA,MAAM,QACJ,eAAgC,GAChC,KAAK,gBAAgB,oBAAoB,CAC3C"}
@@ -1,5 +1,5 @@
1
1
  import * as IdScope from "@confect/core/IdScope";
2
- import type * as Table from "./Table";
2
+ import type * as Table from "./Table.js";
3
3
  declare const EmptyDatabaseScopeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
4
4
  readonly _tag: "EmptyDatabaseScopeError";
5
5
  } & Readonly<A>;
@@ -1 +1 @@
1
- {"version":3,"file":"DatabaseSchema.d.ts","sourceRoot":"","sources":["../src/DatabaseSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AAKjD,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,CAAC;;;;AAEtC,qBAAa,uBAAwB,SAAQ,6BAE3C;IACA,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC;CACzC,CAAC;IACA,IAAa,OAAO,IAAI,MAAM,CAE7B;CACF;;;;AAED,qBAAa,yBAA0B,SAAQ,+BAE7C;IACA,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC;IACrC,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC;CACzC,CAAC;IACA,IAAa,OAAO,IAAI,MAAM,CAE7B;CACF;AAED,eAAO,MAAM,MAAM,oCAAoC,CAAC;AACxD,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAEnC,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC;CAC7B;AAED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,QAC1C,MAAM,KACX,MAAM,CAAC,MAAM,CAAiB,CAAC;AAElC,MAAM,MAAM,UAAU,CAAC,eAAe,SAAS,YAAY,IAAI,KAAK,CAAC,IAAI,CACvE,MAAM,CAAC,eAAe,CAAC,CACxB,GACC,MAAM,CAAC;AAET,MAAM,MAAM,aAAa,CACvB,eAAe,SAAS,YAAY,EACpC,SAAS,SAAS,UAAU,CAAC,eAAe,CAAC,IAC3C,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE;IAAE,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC;AA0BxE;;;;GAIG;AACH,eAAO,MAAM,IAAI,GACf,KAAK,CAAC,YAAY,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,EACvE,KAAK,CAAC,OAAO,SAAS,MAAM,GAAG,SAAS,eAE3B,YAAY,WAChB,OAAO,KACf,cAAc,CAAC,YAAY,EAAE,OAAO,CAOtC,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import * as Data from "effect/Data";
2
3
  import * as Predicate from "effect/Predicate";
3
- import * as Result from "effect/Result";
4
4
  import * as Record from "effect/Record";
5
- import * as Data from "effect/Data";
5
+ import * as Result from "effect/Result";
6
6
  import * as IdScope from "@confect/core/IdScope";
7
7
  //#region src/DatabaseSchema.ts
8
8
  var DatabaseSchema_exports = /* @__PURE__ */ __exportAll({
@@ -1 +1 @@
1
- {"version":3,"file":"DatabaseSchema.js","names":[],"sources":["../src/DatabaseSchema.ts"],"sourcesContent":["import * as IdScope from \"@confect/core/IdScope\";\nimport * as Data from \"effect/Data\";\nimport * as Result from \"effect/Result\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport type * as Table from \"./Table\";\n\nexport class EmptyDatabaseScopeError extends Data.TaggedError(\n \"EmptyDatabaseScopeError\",\n)<{\n readonly databaseScope: IdScope.IdScope;\n}> {\n override get message(): string {\n return \"A component database schema requires a nonempty ID scope.\";\n }\n}\n\nexport class TableBindingMismatchError extends Data.TaggedError(\n \"TableBindingMismatchError\",\n)<{\n readonly bindingName: string;\n readonly tableName: string;\n readonly tableScope: IdScope.IdScope;\n readonly databaseScope: IdScope.IdScope;\n}> {\n override get message(): string {\n return `Table '${this.bindingName}' must be bound to its database schema's name and ID scope.`;\n }\n}\n\nexport const TypeId = \"~@confect/server/DatabaseSchema\";\nexport type TypeId = typeof TypeId;\n\nexport interface AppTarget {\n readonly kind: \"app\";\n readonly scope: IdScope.App;\n}\n\nexport interface ComponentTarget<\n Scope_ extends IdScope.IdScope = IdScope.IdScope,\n> {\n readonly kind: \"component\";\n readonly scope: Scope_;\n}\n\nexport type Target = AppTarget | ComponentTarget;\n\nexport interface Any {\n readonly [TypeId]: unknown;\n}\n\nexport const isDatabaseSchema = (u: unknown): u is Any =>\n Predicate.hasProperty(u, TypeId);\n\n/**\n * A schema definition holding a record of bound `Table`s keyed by table name.\n * Codegen emits a single static `DatabaseSchema.make({ ... })` call; laziness\n * lives entirely on each `Table` (its `Fields` and `Doc` are lazy memoised\n * getters), so this layer is a plain record indirection with no module-loading\n * or async machinery.\n */\nexport interface DatabaseSchema<\n Tables_ extends Readonly<Record<string, Table.AnyWithProps>> = {},\n Target_ extends Target = AppTarget,\n> {\n readonly [TypeId]: Readonly<Tables_>;\n readonly target: Target_;\n}\n\nexport interface AnyWithProps extends DatabaseSchema<\n Readonly<Record<string, Table.AnyWithProps>>,\n Target\n> {}\n\nexport type Scope<Schema extends AnyWithProps> = Schema[\"target\"][\"scope\"];\n\nexport type Tables<DatabaseSchema_ extends AnyWithProps> =\n DatabaseSchema_[TypeId][keyof DatabaseSchema_[TypeId]];\n\n/**\n * The bound table record, without evaluating any table schemas.\n */\nexport const tables = <Schema extends AnyWithProps>(\n self: Schema,\n): Schema[TypeId] => self[TypeId];\n\nexport type TableNames<DatabaseSchema_ extends AnyWithProps> = Table.Name<\n Tables<DatabaseSchema_>\n> &\n string;\n\nexport type TableWithName<\n DatabaseSchema_ extends AnyWithProps,\n TableName extends TableNames<DatabaseSchema_>,\n> = Extract<Tables<DatabaseSchema_>, { readonly tableName: TableName }>;\n\nconst validateBindings = (\n tableRecord: Readonly<Record<string, Table.AnyWithProps>>,\n target: Target,\n): Result.Result<void, EmptyDatabaseScopeError | TableBindingMismatchError> => {\n if (target.kind === \"component\" && target.scope === \"\") {\n return Result.fail(\n new EmptyDatabaseScopeError({ databaseScope: target.scope }),\n );\n }\n for (const [name, table] of Record.toEntries(tableRecord)) {\n if (name !== table.tableName || table.scope !== target.scope) {\n return Result.fail(\n new TableBindingMismatchError({\n bindingName: name,\n tableName: table.tableName,\n tableScope: table.scope,\n databaseScope: target.scope,\n }),\n );\n }\n }\n return Result.succeed(undefined);\n};\n\n/**\n * Construct a database schema from its bound table record. The record's keys\n * must match their tables' names. Table schemas remain lazy; construction only\n * stores the record. The empty case is `make({})`.\n */\nexport const make = <\n const TablesRecord extends Readonly<Record<string, Table.AnyWithProps>>,\n const Target_ extends Target = AppTarget,\n>(\n tableRecord: TablesRecord,\n target?: Target_,\n): DatabaseSchema<TablesRecord, Target_> => {\n const resolvedTarget = target ?? { kind: \"app\", scope: IdScope.app };\n Result.getOrThrow(validateBindings(tableRecord, resolvedTarget));\n return {\n [TypeId]: tableRecord,\n target: resolvedTarget,\n } as DatabaseSchema<TablesRecord, Target_>;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAOA,IAAa,0BAAb,cAA6C,KAAK,YAChD,yBACF,CAAC,CAEE;CACD,IAAa,UAAkB;EAC7B,OAAO;CACT;AACF;AAEA,IAAa,4BAAb,cAA+C,KAAK,YAClD,2BACF,CAAC,CAKE;CACD,IAAa,UAAkB;EAC7B,OAAO,UAAU,KAAK,YAAY;CACpC;AACF;AAEA,MAAa,SAAS;AAqBtB,MAAa,oBAAoB,MAC/B,UAAU,YAAY,GAAG,MAAM;;;;AA8BjC,MAAa,UACX,SACmB,KAAK;AAY1B,MAAM,oBACJ,aACA,WAC6E;CAC7E,IAAI,OAAO,SAAS,eAAe,OAAO,UAAU,IAClD,OAAO,OAAO,KACZ,IAAI,wBAAwB,EAAE,eAAe,OAAO,MAAM,CAAC,CAC7D;CAEF,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,UAAU,WAAW,GACtD,IAAI,SAAS,MAAM,aAAa,MAAM,UAAU,OAAO,OACrD,OAAO,OAAO,KACZ,IAAI,0BAA0B;EAC5B,aAAa;EACb,WAAW,MAAM;EACjB,YAAY,MAAM;EAClB,eAAe,OAAO;CACxB,CAAC,CACH;CAGJ,OAAO,OAAO,QAAQ,KAAA,CAAS;AACjC;;;;;;AAOA,MAAa,QAIX,aACA,WAC0C;CAC1C,MAAM,iBAAiB,UAAU;EAAE,MAAM;EAAO,OAAO,QAAQ;CAAI;CACnE,OAAO,WAAW,iBAAiB,aAAa,cAAc,CAAC;CAC/D,OAAO;GACJ,SAAS;EACV,QAAQ;CACV;AACF"}
1
+ {"version":3,"file":"DatabaseSchema.js","names":[],"sources":["../src/DatabaseSchema.ts"],"sourcesContent":["import * as IdScope from \"@confect/core/IdScope\";\nimport * as Data from \"effect/Data\";\nimport * as Result from \"effect/Result\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport type * as Table from \"./Table.js\";\n\nexport class EmptyDatabaseScopeError extends Data.TaggedError(\n \"EmptyDatabaseScopeError\",\n)<{\n readonly databaseScope: IdScope.IdScope;\n}> {\n override get message(): string {\n return \"A component database schema requires a nonempty ID scope.\";\n }\n}\n\nexport class TableBindingMismatchError extends Data.TaggedError(\n \"TableBindingMismatchError\",\n)<{\n readonly bindingName: string;\n readonly tableName: string;\n readonly tableScope: IdScope.IdScope;\n readonly databaseScope: IdScope.IdScope;\n}> {\n override get message(): string {\n return `Table '${this.bindingName}' must be bound to its database schema's name and ID scope.`;\n }\n}\n\nexport const TypeId = \"~@confect/server/DatabaseSchema\";\nexport type TypeId = typeof TypeId;\n\nexport interface AppTarget {\n readonly kind: \"app\";\n readonly scope: IdScope.App;\n}\n\nexport interface ComponentTarget<\n Scope_ extends IdScope.IdScope = IdScope.IdScope,\n> {\n readonly kind: \"component\";\n readonly scope: Scope_;\n}\n\nexport type Target = AppTarget | ComponentTarget;\n\nexport interface Any {\n readonly [TypeId]: unknown;\n}\n\nexport const isDatabaseSchema = (u: unknown): u is Any =>\n Predicate.hasProperty(u, TypeId);\n\n/**\n * A schema definition holding a record of bound `Table`s keyed by table name.\n * Codegen emits a single static `DatabaseSchema.make({ ... })` call; laziness\n * lives entirely on each `Table` (its `Fields` and `Doc` are lazy memoised\n * getters), so this layer is a plain record indirection with no module-loading\n * or async machinery.\n */\nexport interface DatabaseSchema<\n Tables_ extends Readonly<Record<string, Table.AnyWithProps>> = {},\n Target_ extends Target = AppTarget,\n> {\n readonly [TypeId]: Readonly<Tables_>;\n readonly target: Target_;\n}\n\nexport interface AnyWithProps extends DatabaseSchema<\n Readonly<Record<string, Table.AnyWithProps>>,\n Target\n> {}\n\nexport type Scope<Schema extends AnyWithProps> = Schema[\"target\"][\"scope\"];\n\nexport type Tables<DatabaseSchema_ extends AnyWithProps> =\n DatabaseSchema_[TypeId][keyof DatabaseSchema_[TypeId]];\n\n/**\n * The bound table record, without evaluating any table schemas.\n */\nexport const tables = <Schema extends AnyWithProps>(\n self: Schema,\n): Schema[TypeId] => self[TypeId];\n\nexport type TableNames<DatabaseSchema_ extends AnyWithProps> = Table.Name<\n Tables<DatabaseSchema_>\n> &\n string;\n\nexport type TableWithName<\n DatabaseSchema_ extends AnyWithProps,\n TableName extends TableNames<DatabaseSchema_>,\n> = Extract<Tables<DatabaseSchema_>, { readonly tableName: TableName }>;\n\nconst validateBindings = (\n tableRecord: Readonly<Record<string, Table.AnyWithProps>>,\n target: Target,\n): Result.Result<void, EmptyDatabaseScopeError | TableBindingMismatchError> => {\n if (target.kind === \"component\" && target.scope === \"\") {\n return Result.fail(\n new EmptyDatabaseScopeError({ databaseScope: target.scope }),\n );\n }\n for (const [name, table] of Record.toEntries(tableRecord)) {\n if (name !== table.tableName || table.scope !== target.scope) {\n return Result.fail(\n new TableBindingMismatchError({\n bindingName: name,\n tableName: table.tableName,\n tableScope: table.scope,\n databaseScope: target.scope,\n }),\n );\n }\n }\n return Result.succeed(undefined);\n};\n\n/**\n * Construct a database schema from its bound table record. The record's keys\n * must match their tables' names. Table schemas remain lazy; construction only\n * stores the record. The empty case is `make({})`.\n */\nexport const make = <\n const TablesRecord extends Readonly<Record<string, Table.AnyWithProps>>,\n const Target_ extends Target = AppTarget,\n>(\n tableRecord: TablesRecord,\n target?: Target_,\n): DatabaseSchema<TablesRecord, Target_> => {\n const resolvedTarget = target ?? { kind: \"app\", scope: IdScope.app };\n Result.getOrThrow(validateBindings(tableRecord, resolvedTarget));\n return {\n [TypeId]: tableRecord,\n target: resolvedTarget,\n } as DatabaseSchema<TablesRecord, Target_>;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAOA,IAAa,0BAAb,cAA6C,KAAK,YAChD,yBACF,CAAC,CAEE;CACD,IAAa,UAAkB;EAC7B,OAAO;CACT;AACF;AAEA,IAAa,4BAAb,cAA+C,KAAK,YAClD,2BACF,CAAC,CAKE;CACD,IAAa,UAAkB;EAC7B,OAAO,UAAU,KAAK,YAAY;CACpC;AACF;AAEA,MAAa,SAAS;AAqBtB,MAAa,oBAAoB,MAC/B,UAAU,YAAY,GAAG,MAAM;;;;AA8BjC,MAAa,UACX,SACmB,KAAK;AAY1B,MAAM,oBACJ,aACA,WAC6E;CAC7E,IAAI,OAAO,SAAS,eAAe,OAAO,UAAU,IAClD,OAAO,OAAO,KACZ,IAAI,wBAAwB,EAAE,eAAe,OAAO,MAAM,CAAC,CAC7D;CAEF,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,UAAU,WAAW,GACtD,IAAI,SAAS,MAAM,aAAa,MAAM,UAAU,OAAO,OACrD,OAAO,OAAO,KACZ,IAAI,0BAA0B;EAC5B,aAAa;EACb,WAAW,MAAM;EACjB,YAAY,MAAM;EAClB,eAAe,OAAO;CACxB,CAAC,CACH;CAGJ,OAAO,OAAO,QAAQ,KAAA,CAAS;AACjC;;;;;;AAOA,MAAa,QAIX,aACA,WAC0C;CAC1C,MAAM,iBAAiB,UAAU;EAAE,MAAM;EAAO,OAAO,QAAQ;CAAI;CACnE,OAAO,WAAW,iBAAiB,aAAa,cAAc,CAAC;CAC/D,OAAO;GACJ,SAAS;EACV,QAAQ;CACV;AACF"}
@@ -2,11 +2,11 @@ import type { GenericDatabaseWriter } from "convex/server";
2
2
  import * as Context from "effect/Context";
3
3
  import * as Effect from "effect/Effect";
4
4
  import * as Layer from "effect/Layer";
5
- import * as DatabaseSchema from "./DatabaseSchema";
6
- import type * as DataModel from "./DataModel";
7
- import type { DocumentByName as DocumentByName_ } from "./DataModel";
8
- import * as Document from "./Document";
9
- import * as QueryInitializer from "./QueryInitializer";
5
+ import * as DatabaseSchema from "./DatabaseSchema.js";
6
+ import type * as DataModel from "./DataModel.js";
7
+ import type { DocumentByName as DocumentByName_ } from "./DataModel.js";
8
+ import * as Document from "./Document.js";
9
+ import * as QueryInitializer from "./QueryInitializer.js";
10
10
  /**
11
11
  * The argument accepted by `patch`: like `Partial<Doc>` without system fields,
12
12
  * but the fields that are already optional also accept `undefined`, since
@@ -37,8 +37,42 @@ export interface DatabaseWriterService<DatabaseSchema_ extends DatabaseSchema.An
37
37
  * interfaces.
38
38
  */
39
39
  export type DatabaseWriterTag<DatabaseSchema_ extends DatabaseSchema.AnyWithProps, Docs = {}> = Context.Service<DatabaseWriterService<DatabaseSchema_>, DatabaseWriterService<DatabaseSchema_, Docs>>;
40
- export declare const make: <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(databaseSchema: DatabaseSchema_, convexDatabaseWriter: GenericDatabaseWriter<DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>>) => DatabaseWriterService<DatabaseSchema_>;
40
+ /**
41
+ * Decoded documents surrounding one successful write.
42
+ */
43
+ export type Change<S extends DatabaseSchema.AnyWithProps> = {
44
+ [Name in DataModel.TableNames<DataModel.FromSchema<S>>]: {
45
+ readonly tableName: Name;
46
+ } & ({
47
+ readonly operation: "insert";
48
+ readonly oldDoc: null;
49
+ readonly newDoc: DocumentByName_<DataModel.FromSchema<S>, Name>;
50
+ } | {
51
+ readonly operation: "update";
52
+ readonly oldDoc: DocumentByName_<DataModel.FromSchema<S>, Name>;
53
+ readonly newDoc: DocumentByName_<DataModel.FromSchema<S>, Name>;
54
+ } | {
55
+ readonly operation: "delete";
56
+ readonly oldDoc: DocumentByName_<DataModel.FromSchema<S>, Name>;
57
+ readonly newDoc: null;
58
+ });
59
+ }[DataModel.TableNames<DataModel.FromSchema<S>>];
60
+ /**
61
+ * Runs after the write, in its transaction. A defect aborts the mutation.
62
+ *
63
+ * Only writes through this writer are observed. Raw `ctx.db`, `MutationCtx`
64
+ * writes and a second `DatabaseWriter.make` bypass the hook, so a host that
65
+ * relies on it keeps raw writers out of its functions. Component writers and
66
+ * nested `runMutation` calls each need their own hook installation.
67
+ *
68
+ * Concurrent writes to one document (for example under `Effect.all`) can
69
+ * interleave the read-write-read steps. Await them sequentially when the hook
70
+ * needs exact per-write snapshots. The writer takes no lock, because a hook
71
+ * that writes through the same writer would deadlock under one.
72
+ */
73
+ export type Hook<S extends DatabaseSchema.AnyWithProps> = (change: Change<S>) => Effect.Effect<void>;
74
+ export declare const make: <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(databaseSchema: DatabaseSchema_, convexDatabaseWriter: GenericDatabaseWriter<DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>>, hook?: Hook<DatabaseSchema_>) => DatabaseWriterService<DatabaseSchema_>;
41
75
  export declare const DatabaseWriter: <DatabaseSchema_ extends DatabaseSchema.AnyWithProps, Docs = {}>() => DatabaseWriterTag<DatabaseSchema_, Docs>;
42
76
  export type DatabaseWriter<DatabaseSchema_ extends DatabaseSchema.AnyWithProps> = DatabaseWriterService<DatabaseSchema_>;
43
- export declare const layer: <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(databaseSchema: DatabaseSchema_, convexDatabaseWriter: GenericDatabaseWriter<DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>>) => Layer.Layer<DatabaseWriterService<DatabaseSchema_, {}>, never, never>;
77
+ export declare const layer: <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(databaseSchema: DatabaseSchema_, convexDatabaseWriter: GenericDatabaseWriter<DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>>, hook?: Hook<DatabaseSchema_>) => Layer.Layer<DatabaseWriterService<DatabaseSchema_, {}>, never, never>;
44
78
  //# sourceMappingURL=DatabaseWriter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DatabaseWriter.d.ts","sourceRoot":"","sources":["../src/DatabaseWriter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,qBAAqB,EAEtB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AAGvD;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,GAAG,IAAI;KAE1B,CAAC,IAAI,MAAM,GAAG,IAAI,CAAC,SAAS,KAAK,GAAG,eAAe,GAAG,KAAK,GAAG,CAAC,CAChE,CAAC,EAAE,SAAS,SAAS,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAA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AAY,kBACtD,eAAe,wBACT,qBAAqB,CACzC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAC1D,SACM,IAAI,CAAC,eAAe,CAAC,KAC3B,qBAAqB,CAAC,eAAe,CAsNvC,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,eAAe,SAAS,cAAc,CAAC,YAAY,EACnD,IAAI,GAAG,EAAE,OACN,iBAAiB,CAAC,eAAe,EAAE,IAAI,CAIP,CAAC;AAEtC,MAAM,MAAM,cAAc,CACxB,eAAe,SAAS,cAAc,CAAC,YAAY,IACjD,qBAAqB,CAAC,eAAe,CAAC,CAAC;AAE3C,eAAO,MAAM,KAAK,GAAI,eAAe,SAAS,cAAc,CAAC,YAAY,kBACvD,eAAe,wBACT,qBAAqB,CACzC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAC1D,SACM,IAAI,CAAC,eAAe,CAAC,0EAK3B,CAAC"}
@@ -1,46 +1,93 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { tables } from "./DatabaseSchema.js";
3
- import { encode } from "./Document.js";
4
- import { getById } from "./QueryInitializer.js";
3
+ import { DocumentEncodeError, decode, encode } from "./Document.js";
4
+ import { GetByIdFailure, getById } from "./QueryInitializer.js";
5
+ import { encoder } from "./internal/DocumentPatch.js";
5
6
  import * as Context from "effect/Context";
6
- import * as Layer from "effect/Layer";
7
7
  import * as Effect from "effect/Effect";
8
- import { pipe } from "effect/Function";
8
+ import * as Layer from "effect/Layer";
9
+ import * as Predicate from "effect/Predicate";
9
10
  import * as Record from "effect/Record";
11
+ import { pipe } from "effect/Function";
12
+ import * as Result from "effect/Result";
10
13
  //#region src/DatabaseWriter.ts
11
14
  var DatabaseWriter_exports = /* @__PURE__ */ __exportAll({
12
15
  DatabaseWriter: () => DatabaseWriter,
13
16
  layer: () => layer,
14
17
  make: () => make
15
18
  });
16
- const make = (databaseSchema, convexDatabaseWriter) => {
19
+ const make = (databaseSchema, convexDatabaseWriter, hook) => {
17
20
  const table = (tableName) => {
18
21
  const tableDef = tables(databaseSchema)[tableName];
19
22
  const insert = Effect.fn("DatabaseWriter.insert")(function* (document) {
20
23
  const encodedDocument = yield* encode(document, tableDef);
21
24
  return yield* Effect.promise(() => convexDatabaseWriter.insert(tableName, encodedDocument));
22
25
  });
23
- const patch = Effect.fn("DatabaseWriter.patch")(function* (id, patchedValues) {
26
+ const replacePatched = (id, patchedValues) => Effect.gen(function* () {
24
27
  const originalDecodedDoc = yield* getById(convexDatabaseWriter, tableDef)(id);
25
28
  const updatedEncodedDoc = yield* pipe(patchedValues, Record.reduce(originalDecodedDoc, (acc, value, key) => value === void 0 ? Record.remove(acc, key) : Record.set(acc, key, value)), encode(tableDef));
26
29
  yield* Effect.promise(() => convexDatabaseWriter.replace(id, updatedEncodedDoc));
27
30
  });
31
+ const patch = Effect.fn("DatabaseWriter.patch")(function* (id, patchedValues) {
32
+ const encodePatch = encoder(tableDef);
33
+ if (encodePatch === void 0) return yield* replacePatched(id, patchedValues);
34
+ const storedDoc = yield* pipe(Effect.promise(() => convexDatabaseWriter.get(id)), Effect.andThen((value) => Effect.fromResult(Result.fromNullishOr(value, () => new GetByIdFailure({
35
+ tableName,
36
+ id
37
+ })))));
38
+ const encodedPatch = yield* pipe(encodePatch(patchedValues), Effect.mapError(({ message }) => message), Effect.tap((delta) => pipe({
39
+ ...storedDoc,
40
+ ...delta
41
+ }, Record.filter(Predicate.isNotUndefined), decode(tableDef), Effect.mapError(({ parseError }) => parseError))), Effect.catch((parseError) => pipe(decode(storedDoc, tableDef), Effect.andThen(Effect.fail(new DocumentEncodeError({
42
+ tableName,
43
+ id,
44
+ parseError
45
+ }))))));
46
+ yield* Effect.promise(() => convexDatabaseWriter.patch(id, encodedPatch));
47
+ });
28
48
  const replace = Effect.fn("DatabaseWriter.replace")(function* (id, value) {
29
49
  const updatedEncodedDoc = yield* encode(value, tableDef);
30
50
  yield* Effect.promise(() => convexDatabaseWriter.replace(id, updatedEncodedDoc));
31
51
  });
32
52
  const delete_ = (id) => Effect.promise(() => convexDatabaseWriter.delete(id));
33
- return {
53
+ const accessor = {
34
54
  insert,
35
55
  patch,
36
56
  replace,
37
57
  delete: delete_
38
58
  };
59
+ if (hook === void 0) return accessor;
60
+ const read = (id) => getById(convexDatabaseWriter, tableDef)(id);
61
+ const notify = (operation, oldDoc, newDoc) => hook({
62
+ tableName,
63
+ operation,
64
+ oldDoc,
65
+ newDoc
66
+ });
67
+ const update = (before, write) => (id, ...args) => Effect.gen(function* () {
68
+ const oldDoc = yield* before(id);
69
+ yield* write(id, ...args);
70
+ yield* notify("update", oldDoc, yield* read(id).pipe(Effect.orDie));
71
+ });
72
+ return {
73
+ insert: (document) => Effect.gen(function* () {
74
+ const id = yield* insert(document);
75
+ yield* notify("insert", null, yield* read(id).pipe(Effect.orDie));
76
+ return id;
77
+ }),
78
+ patch: update(read, patch),
79
+ replace: update((id) => read(id).pipe(Effect.orDie), replace),
80
+ delete: (id) => Effect.gen(function* () {
81
+ const oldDoc = yield* read(id).pipe(Effect.orDie);
82
+ yield* delete_(id);
83
+ yield* notify("delete", oldDoc, null);
84
+ })
85
+ };
39
86
  };
40
87
  return { table };
41
88
  };
42
89
  const DatabaseWriter = () => Context.Service("@confect/server/DatabaseWriter");
43
- const layer = (databaseSchema, convexDatabaseWriter) => Layer.succeed(DatabaseWriter(), make(databaseSchema, convexDatabaseWriter));
90
+ const layer = (databaseSchema, convexDatabaseWriter, hook) => Layer.succeed(DatabaseWriter(), make(databaseSchema, convexDatabaseWriter, hook));
44
91
  //#endregion
45
92
  export { DatabaseWriter, DatabaseWriter_exports, layer, make };
46
93
 
@@ -1 +1 @@
1
- {"version":3,"file":"DatabaseWriter.js","names":["DatabaseSchema.tables","Document.encode","QueryInitializer.getById"],"sources":["../src/DatabaseWriter.ts"],"sourcesContent":["import type {\n BetterOmit,\n DocumentByName,\n Expand,\n GenericDatabaseWriter,\n WithoutSystemFields,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { pipe } from \"effect/Function\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Record from \"effect/Record\";\nimport * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as DataModel from \"./DataModel\";\nimport type { DocumentByName as DocumentByName_ } from \"./DataModel\";\nimport * as Document from \"./Document\";\nimport * as QueryInitializer from \"./QueryInitializer\";\nimport type * as Table from \"./Table\";\n\n/**\n * The argument accepted by `patch`: like `Partial<Doc>` without system fields,\n * but the fields that are already optional also accept `undefined`, since\n * setting a field to `undefined` unsets it.\n */\nexport type PatchValue<Doc> = {\n [\n K in keyof Doc as K extends \"_id\" | \"_creationTime\" ? never : K\n ]?: undefined extends Doc[K] ? Doc[K] | undefined : Doc[K];\n};\n\nexport interface DatabaseWriterTableAccessor<\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n Doc = DocumentByName_<DataModel_, TableName>,\n> {\n readonly insert: (\n document: Document.WithoutSystemFields<Doc>,\n ) => Effect.Effect<\n DataModel.Id<DataModel_, TableName>,\n Document.DocumentEncodeError\n >;\n readonly patch: (\n id: DataModel.Id<DataModel_, TableName>,\n patchedValues: PatchValue<Doc>,\n ) => Effect.Effect<\n void,\n | QueryInitializer.GetByIdFailure\n | Document.DocumentDecodeError\n | Document.DocumentEncodeError\n >;\n readonly replace: (\n id: DataModel.Id<DataModel_, TableName>,\n value: Document.WithoutSystemFields<Doc>,\n ) => Effect.Effect<void, Document.DocumentEncodeError>;\n readonly delete: (\n id: DataModel.Id<DataModel_, TableName>,\n ) => Effect.Effect<void>;\n}\n\n/**\n * The service shape backing the `DatabaseWriter` tag. Named (rather than an\n * inferred anonymous object) so declaration emit prints\n * `DatabaseWriterService<…>` by reference instead of expanding the data model.\n * `Docs` is the optional named document registry (see\n * `DatabaseReaderService`).\n */\nexport interface DatabaseWriterService<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n> {\n readonly table: <\n const TableName extends DataModel.TableNames<\n DataModel.FromSchema<DatabaseSchema_>\n >,\n >(\n tableName: TableName,\n ) => DatabaseWriterTableAccessor<\n DataModel.FromSchema<DatabaseSchema_>,\n TableName,\n TableName extends keyof Docs\n ? Docs[TableName]\n : DocumentByName_<DataModel.FromSchema<DatabaseSchema_>, TableName>\n >;\n}\n\n/**\n * The tag's _Identifier_ is `Docs`-independent (see `DatabaseReaderTag`); only\n * the _Service_ carries `Docs` so writer inputs print the named doc\n * interfaces.\n */\nexport type DatabaseWriterTag<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n> = Context.Service<\n DatabaseWriterService<DatabaseSchema_>,\n DatabaseWriterService<DatabaseSchema_, Docs>\n>;\n\nexport const make = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexDatabaseWriter: GenericDatabaseWriter<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n): DatabaseWriterService<DatabaseSchema_> => {\n type DataModel_ = DataModel.FromSchema<DatabaseSchema_>;\n\n const table = <const TableName extends DataModel.TableNames<DataModel_>>(\n tableName: TableName,\n ) => {\n const tableDef = DatabaseSchema.tables(databaseSchema)[tableName];\n\n const insert = Effect.fn(\"DatabaseWriter.insert\")(function* (\n document: Document.WithoutSystemFields<\n DocumentByName_<DataModel_, TableName>\n >,\n ) {\n const encodedDocument = yield* Document.encode(document, tableDef);\n\n const id = yield* Effect.promise(() =>\n convexDatabaseWriter.insert(\n tableName,\n encodedDocument as WithoutSystemFields<\n DocumentByName<DataModel.ToConvex<DataModel_>, TableName>\n >,\n ),\n );\n\n // The database supplies the ID in this table's execution scope. Its\n // scope brand is erased at the Convex syscall boundary.\n return id as unknown as DataModel.Id<DataModel_, TableName>;\n });\n\n const patch = Effect.fn(\"DatabaseWriter.patch\")(function* (\n id: DataModel.Id<DataModel_, TableName>,\n patchedValues: PatchValue<\n Document.WithoutSystemFields<DocumentByName_<DataModel_, TableName>>\n >,\n ) {\n const originalDecodedDoc = yield* QueryInitializer.getById<\n Table.AnyWithProps,\n TableName\n >(\n convexDatabaseWriter as any,\n tableDef,\n )(id as unknown as GenericId<TableName>);\n\n const updatedEncodedDoc = yield* pipe(\n patchedValues,\n Record.reduce(originalDecodedDoc, (acc, value, key) =>\n value === undefined\n ? Record.remove(acc, key)\n : Record.set(acc, key, value),\n ),\n Document.encode(tableDef),\n );\n\n yield* Effect.promise(() =>\n convexDatabaseWriter.replace(\n id as unknown as GenericId<TableName>,\n updatedEncodedDoc as Expand<\n BetterOmit<\n DocumentByName<DataModel.ToConvex<DataModel_>, TableName>,\n \"_creationTime\" | \"_id\"\n >\n >,\n ),\n );\n });\n\n const replace = Effect.fn(\"DatabaseWriter.replace\")(function* (\n id: DataModel.Id<DataModel_, TableName>,\n value: Document.WithoutSystemFields<\n DocumentByName_<DataModel_, TableName>\n >,\n ) {\n const updatedEncodedDoc = yield* Document.encode(value, tableDef);\n\n yield* Effect.promise(() =>\n convexDatabaseWriter.replace(\n id as unknown as GenericId<TableName>,\n updatedEncodedDoc as Expand<\n BetterOmit<\n DocumentByName<DataModel.ToConvex<DataModel_>, TableName>,\n \"_creationTime\" | \"_id\"\n >\n >,\n ),\n );\n });\n\n const delete_ = (id: DataModel.Id<DataModel_, TableName>) =>\n Effect.promise(() =>\n convexDatabaseWriter.delete(id as unknown as GenericId<TableName>),\n );\n\n return {\n insert,\n patch,\n replace,\n delete: delete_,\n };\n };\n\n return {\n table,\n } as DatabaseWriterService<DatabaseSchema_>;\n};\n\nexport const DatabaseWriter = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n>(): DatabaseWriterTag<DatabaseSchema_, Docs> =>\n Context.Service<\n DatabaseWriterService<DatabaseSchema_>,\n DatabaseWriterService<DatabaseSchema_, Docs>\n >(\"@confect/server/DatabaseWriter\");\n\nexport type DatabaseWriter<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n> = DatabaseWriterService<DatabaseSchema_>;\n\nexport const layer = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexDatabaseWriter: GenericDatabaseWriter<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n) =>\n Layer.succeed(\n DatabaseWriter<DatabaseSchema_>(),\n make(databaseSchema, convexDatabaseWriter),\n );\n"],"mappings":";;;;;;;;;;;;;;;AAmGA,MAAa,QACX,gBACA,yBAG2C;CAG3C,MAAM,SACJ,cACG;EACH,MAAM,WAAWA,OAAsB,cAAc,CAAC,CAAC;EAEvD,MAAM,SAAS,OAAO,GAAG,uBAAuB,CAAC,CAAC,WAChD,UAGA;GACA,MAAM,kBAAkB,OAAOC,OAAgB,UAAU,QAAQ;GAajE,OAAO,OAXW,OAAO,cACvB,qBAAqB,OACnB,WACA,eAGF,CACF;EAKF,CAAC;EAED,MAAM,QAAQ,OAAO,GAAG,sBAAsB,CAAC,CAAC,WAC9C,IACA,eAGA;GACA,MAAM,qBAAqB,OAAOC,QAIhC,sBACA,QACF,CAAC,CAAC,EAAqC;GAEvC,MAAM,oBAAoB,OAAO,KAC/B,eACA,OAAO,OAAO,qBAAqB,KAAK,OAAO,QAC7C,UAAU,KAAA,IACN,OAAO,OAAO,KAAK,GAAG,IACtB,OAAO,IAAI,KAAK,KAAK,KAAK,CAChC,GACAD,OAAgB,QAAQ,CAC1B;GAEA,OAAO,OAAO,cACZ,qBAAqB,QACnB,IACA,iBAMF,CACF;EACF,CAAC;EAED,MAAM,UAAU,OAAO,GAAG,wBAAwB,CAAC,CAAC,WAClD,IACA,OAGA;GACA,MAAM,oBAAoB,OAAOA,OAAgB,OAAO,QAAQ;GAEhE,OAAO,OAAO,cACZ,qBAAqB,QACnB,IACA,iBAMF,CACF;EACF,CAAC;EAED,MAAM,WAAW,OACf,OAAO,cACL,qBAAqB,OAAO,EAAqC,CACnE;EAEF,OAAO;GACL;GACA;GACA;GACA,QAAQ;EACV;CACF;CAEA,OAAO,EACL,MACF;AACF;AAEA,MAAa,uBAIX,QAAQ,QAGN,gCAAgC;AAMpC,MAAa,SACX,gBACA,yBAIA,MAAM,QACJ,eAAgC,GAChC,KAAK,gBAAgB,oBAAoB,CAC3C"}
1
+ {"version":3,"file":"DatabaseWriter.js","names":["DatabaseSchema.tables","Document.encode","QueryInitializer.getById","DocumentPatch.encoder","QueryInitializer.GetByIdFailure","Document.decode","Document.DocumentEncodeError"],"sources":["../src/DatabaseWriter.ts"],"sourcesContent":["import type {\n BetterOmit,\n DocumentByName,\n Expand,\n GenericDatabaseWriter,\n WithoutSystemFields,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { pipe } from \"effect/Function\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Record from \"effect/Record\";\nimport * as Result from \"effect/Result\";\nimport * as DatabaseSchema from \"./DatabaseSchema.js\";\nimport type * as DataModel from \"./DataModel.js\";\nimport type { DocumentByName as DocumentByName_ } from \"./DataModel.js\";\nimport * as Document from \"./Document.js\";\nimport * as DocumentPatch from \"./internal/DocumentPatch.js\";\nimport * as QueryInitializer from \"./QueryInitializer.js\";\nimport type * as Table from \"./Table.js\";\n\n/**\n * The argument accepted by `patch`: like `Partial<Doc>` without system fields,\n * but the fields that are already optional also accept `undefined`, since\n * setting a field to `undefined` unsets it.\n */\nexport type PatchValue<Doc> = {\n [\n K in keyof Doc as K extends \"_id\" | \"_creationTime\" ? never : K\n ]?: undefined extends Doc[K] ? Doc[K] | undefined : Doc[K];\n};\n\nexport interface DatabaseWriterTableAccessor<\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n Doc = DocumentByName_<DataModel_, TableName>,\n> {\n readonly insert: (\n document: Document.WithoutSystemFields<Doc>,\n ) => Effect.Effect<\n DataModel.Id<DataModel_, TableName>,\n Document.DocumentEncodeError\n >;\n readonly patch: (\n id: DataModel.Id<DataModel_, TableName>,\n patchedValues: PatchValue<Doc>,\n ) => Effect.Effect<\n void,\n | QueryInitializer.GetByIdFailure\n | Document.DocumentDecodeError\n | Document.DocumentEncodeError\n >;\n readonly replace: (\n id: DataModel.Id<DataModel_, TableName>,\n value: Document.WithoutSystemFields<Doc>,\n ) => Effect.Effect<void, Document.DocumentEncodeError>;\n readonly delete: (\n id: DataModel.Id<DataModel_, TableName>,\n ) => Effect.Effect<void>;\n}\n\n/**\n * The service shape backing the `DatabaseWriter` tag. Named (rather than an\n * inferred anonymous object) so declaration emit prints\n * `DatabaseWriterService<…>` by reference instead of expanding the data model.\n * `Docs` is the optional named document registry (see\n * `DatabaseReaderService`).\n */\nexport interface DatabaseWriterService<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n> {\n readonly table: <\n const TableName extends DataModel.TableNames<\n DataModel.FromSchema<DatabaseSchema_>\n >,\n >(\n tableName: TableName,\n ) => DatabaseWriterTableAccessor<\n DataModel.FromSchema<DatabaseSchema_>,\n TableName,\n TableName extends keyof Docs\n ? Docs[TableName]\n : DocumentByName_<DataModel.FromSchema<DatabaseSchema_>, TableName>\n >;\n}\n\n/**\n * The tag's _Identifier_ is `Docs`-independent (see `DatabaseReaderTag`); only\n * the _Service_ carries `Docs` so writer inputs print the named doc\n * interfaces.\n */\nexport type DatabaseWriterTag<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n> = Context.Service<\n DatabaseWriterService<DatabaseSchema_>,\n DatabaseWriterService<DatabaseSchema_, Docs>\n>;\n\n/**\n * Decoded documents surrounding one successful write.\n */\nexport type Change<S extends DatabaseSchema.AnyWithProps> = {\n [Name in DataModel.TableNames<DataModel.FromSchema<S>>]: {\n readonly tableName: Name;\n } & (\n | {\n readonly operation: \"insert\";\n readonly oldDoc: null;\n readonly newDoc: DocumentByName_<DataModel.FromSchema<S>, Name>;\n }\n | {\n readonly operation: \"update\";\n readonly oldDoc: DocumentByName_<DataModel.FromSchema<S>, Name>;\n readonly newDoc: DocumentByName_<DataModel.FromSchema<S>, Name>;\n }\n | {\n readonly operation: \"delete\";\n readonly oldDoc: DocumentByName_<DataModel.FromSchema<S>, Name>;\n readonly newDoc: null;\n }\n );\n}[DataModel.TableNames<DataModel.FromSchema<S>>];\n\n/**\n * Runs after the write, in its transaction. A defect aborts the mutation.\n *\n * Only writes through this writer are observed. Raw `ctx.db`, `MutationCtx`\n * writes and a second `DatabaseWriter.make` bypass the hook, so a host that\n * relies on it keeps raw writers out of its functions. Component writers and\n * nested `runMutation` calls each need their own hook installation.\n *\n * Concurrent writes to one document (for example under `Effect.all`) can\n * interleave the read-write-read steps. Await them sequentially when the hook\n * needs exact per-write snapshots. The writer takes no lock, because a hook\n * that writes through the same writer would deadlock under one.\n */\nexport type Hook<S extends DatabaseSchema.AnyWithProps> = (\n change: Change<S>,\n) => Effect.Effect<void>;\n\nexport const make = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexDatabaseWriter: GenericDatabaseWriter<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n hook?: Hook<DatabaseSchema_>,\n): DatabaseWriterService<DatabaseSchema_> => {\n type DataModel_ = DataModel.FromSchema<DatabaseSchema_>;\n\n const table = <const TableName extends DataModel.TableNames<DataModel_>>(\n tableName: TableName,\n ) => {\n const tableDef = DatabaseSchema.tables(databaseSchema)[tableName];\n\n const insert = Effect.fn(\"DatabaseWriter.insert\")(function* (\n document: Document.WithoutSystemFields<\n DocumentByName_<DataModel_, TableName>\n >,\n ) {\n const encodedDocument = yield* Document.encode(document, tableDef);\n\n const id = yield* Effect.promise(() =>\n convexDatabaseWriter.insert(\n tableName,\n encodedDocument as WithoutSystemFields<\n DocumentByName<DataModel.ToConvex<DataModel_>, TableName>\n >,\n ),\n );\n\n // The database supplies the ID in this table's execution scope. Its\n // scope brand is erased at the Convex syscall boundary.\n return id as unknown as DataModel.Id<DataModel_, TableName>;\n });\n\n // A codec whose encoding spans fields cannot encode a patch on its own, so\n // the patch is merged into the decoded document and the result replaces it.\n const replacePatched = (\n id: DataModel.Id<DataModel_, TableName>,\n patchedValues: PatchValue<\n Document.WithoutSystemFields<DocumentByName_<DataModel_, TableName>>\n >,\n ) =>\n Effect.gen(function* () {\n const originalDecodedDoc = yield* QueryInitializer.getById<\n Table.AnyWithProps,\n TableName\n >(\n convexDatabaseWriter as any,\n tableDef,\n )(id as unknown as GenericId<TableName>);\n\n const updatedEncodedDoc = yield* pipe(\n patchedValues,\n Record.reduce(originalDecodedDoc, (acc, value, key) =>\n value === undefined\n ? Record.remove(acc, key)\n : Record.set(acc, key, value),\n ),\n Document.encode(tableDef),\n );\n\n yield* Effect.promise(() =>\n convexDatabaseWriter.replace(\n id as unknown as GenericId<TableName>,\n updatedEncodedDoc as Expand<\n BetterOmit<\n DocumentByName<DataModel.ToConvex<DataModel_>, TableName>,\n \"_creationTime\" | \"_id\"\n >\n >,\n ),\n );\n });\n\n const patch = Effect.fn(\"DatabaseWriter.patch\")(function* (\n id: DataModel.Id<DataModel_, TableName>,\n patchedValues: PatchValue<\n Document.WithoutSystemFields<DocumentByName_<DataModel_, TableName>>\n >,\n ) {\n const encodePatch = DocumentPatch.encoder(tableDef);\n if (encodePatch === undefined) {\n return yield* replacePatched(id, patchedValues);\n }\n\n const storedDoc = yield* pipe(\n Effect.promise(() =>\n convexDatabaseWriter.get(id as unknown as GenericId<TableName>),\n ),\n Effect.andThen((value) =>\n Effect.fromResult(\n Result.fromNullishOr(\n value,\n () =>\n new QueryInitializer.GetByIdFailure({\n tableName,\n id,\n }),\n ),\n ),\n ),\n );\n // The patch must encode and the patched document must decode. When\n // either fails, the stored document decides whose fault that is.\n const encodedPatch = yield* pipe(\n encodePatch(patchedValues),\n Effect.mapError(({ message }) => message),\n Effect.tap((delta) =>\n pipe(\n { ...storedDoc, ...delta },\n Record.filter(Predicate.isNotUndefined),\n Document.decode(tableDef),\n Effect.mapError(({ parseError }) => parseError),\n ),\n ),\n Effect.catch((parseError) =>\n pipe(\n Document.decode(storedDoc, tableDef),\n Effect.andThen(\n Effect.fail(\n new Document.DocumentEncodeError({\n tableName,\n id,\n parseError,\n }),\n ),\n ),\n ),\n ),\n );\n\n yield* Effect.promise(() =>\n convexDatabaseWriter.patch(\n id as unknown as GenericId<TableName>,\n encodedPatch as Partial<\n DocumentByName<DataModel.ToConvex<DataModel_>, TableName>\n >,\n ),\n );\n });\n\n const replace = Effect.fn(\"DatabaseWriter.replace\")(function* (\n id: DataModel.Id<DataModel_, TableName>,\n value: Document.WithoutSystemFields<\n DocumentByName_<DataModel_, TableName>\n >,\n ) {\n const updatedEncodedDoc = yield* Document.encode(value, tableDef);\n\n yield* Effect.promise(() =>\n convexDatabaseWriter.replace(\n id as unknown as GenericId<TableName>,\n updatedEncodedDoc as Expand<\n BetterOmit<\n DocumentByName<DataModel.ToConvex<DataModel_>, TableName>,\n \"_creationTime\" | \"_id\"\n >\n >,\n ),\n );\n });\n\n const delete_ = (id: DataModel.Id<DataModel_, TableName>) =>\n Effect.promise(() =>\n convexDatabaseWriter.delete(id as unknown as GenericId<TableName>),\n );\n\n const accessor = { insert, patch, replace, delete: delete_ };\n if (hook === undefined) return accessor;\n\n const read = (id: DataModel.Id<DataModel_, TableName>) =>\n QueryInitializer.getById<Table.AnyWithProps, TableName>(\n convexDatabaseWriter as any,\n tableDef,\n )(id as unknown as GenericId<TableName>);\n const notify = (\n operation: \"insert\" | \"update\" | \"delete\",\n oldDoc: unknown,\n newDoc: unknown,\n ) =>\n hook({ tableName, operation, oldDoc, newDoc } as Change<DatabaseSchema_>);\n const update =\n <A extends ReadonlyArray<unknown>, E, BeforeError>(\n before: (\n id: DataModel.Id<DataModel_, TableName>,\n ) => Effect.Effect<unknown, BeforeError>,\n write: (\n id: DataModel.Id<DataModel_, TableName>,\n ...args: A\n ) => Effect.Effect<void, E>,\n ) =>\n (id: DataModel.Id<DataModel_, TableName>, ...args: A) =>\n Effect.gen(function* () {\n const oldDoc = yield* before(id);\n yield* write(id, ...args);\n yield* notify(\"update\", oldDoc, yield* read(id).pipe(Effect.orDie));\n });\n\n return {\n insert: (document: Parameters<typeof insert>[0]) =>\n Effect.gen(function* () {\n const id = yield* insert(document);\n yield* notify(\"insert\", null, yield* read(id).pipe(Effect.orDie));\n return id;\n }),\n patch: update(read, patch),\n replace: update((id) => read(id).pipe(Effect.orDie), replace),\n delete: (id: DataModel.Id<DataModel_, TableName>) =>\n Effect.gen(function* () {\n const oldDoc = yield* read(id).pipe(Effect.orDie);\n yield* delete_(id);\n yield* notify(\"delete\", oldDoc, null);\n }),\n };\n };\n\n return {\n table,\n } as DatabaseWriterService<DatabaseSchema_>;\n};\n\nexport const DatabaseWriter = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Docs = {},\n>(): DatabaseWriterTag<DatabaseSchema_, Docs> =>\n Context.Service<\n DatabaseWriterService<DatabaseSchema_>,\n DatabaseWriterService<DatabaseSchema_, Docs>\n >(\"@confect/server/DatabaseWriter\");\n\nexport type DatabaseWriter<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n> = DatabaseWriterService<DatabaseSchema_>;\n\nexport const layer = <DatabaseSchema_ extends DatabaseSchema.AnyWithProps>(\n databaseSchema: DatabaseSchema_,\n convexDatabaseWriter: GenericDatabaseWriter<\n DataModel.ToConvex<DataModel.FromSchema<DatabaseSchema_>>\n >,\n hook?: Hook<DatabaseSchema_>,\n) =>\n Layer.succeed(\n DatabaseWriter<DatabaseSchema_>(),\n make(databaseSchema, convexDatabaseWriter, hook),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgJA,MAAa,QACX,gBACA,sBAGA,SAC2C;CAG3C,MAAM,SACJ,cACG;EACH,MAAM,WAAWA,OAAsB,cAAc,CAAC,CAAC;E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O,QAAQ,EAAE;IACjB,OAAO,OAAO,UAAU,QAAQ,IAAI;GACtC,CAAC;EACL;CACF;CAEA,OAAO,EACL,MACF;AACF;AAEA,MAAa,uBAIX,QAAQ,QAGN,gCAAgC;AAMpC,MAAa,SACX,gBACA,sBAGA,SAEA,MAAM,QACJ,eAAgC,GAChC,KAAK,gBAAgB,sBAAsB,IAAI,CACjD"}
@@ -2,10 +2,10 @@ import type { ReadonlyValue } from "@confect/core/SchemaToValidator";
2
2
  import * as Effect from "effect/Effect";
3
3
  import * as Schema from "effect/Schema";
4
4
  import type { ReadonlyRecord } from "effect/Record";
5
- import type * as DatabaseSchema from "./DatabaseSchema";
6
- import type * as DataModel from "./DataModel";
7
- import type * as TableInfo from "./TableInfo";
8
- import type * as Table from "./Table";
5
+ import type * as DatabaseSchema from "./DatabaseSchema.js";
6
+ import type * as DataModel from "./DataModel.js";
7
+ import type * as TableInfo from "./TableInfo.js";
8
+ import type * as Table from "./Table.js";
9
9
  export type Document<Schema_ extends DatabaseSchema.AnyWithProps, TableName extends DatabaseSchema.TableNames<Schema_>> = DataModel.DocumentByName<DataModel.FromSchema<Schema_>, TableName>;
10
10
  export type WithoutSystemFields<Doc> = Doc extends unknown ? Omit<Doc, "_creationTime" | "_id"> : never;
11
11
  export type Any = any;
@@ -1 +1 @@
1
- {"version":3,"file":"Document.d.ts","sourceRoot":"","sources":["../src/Document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAErE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CAAC;AAC9C,O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CAAC,SACvC,MAAM,KACV,MAAM,CAAC,MAAM,CAChB,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAC1C,mBAAmB,CACpB,CAuBF,CAAC;;;;;;AAEF,qBAAa,mBAAoB,SAAQ,wBAOxC;IACC,IAAa,OAAO,IAAI,MAAM,CAM7B;CACF;;;;;;AAED,qBAAa,mBAAoB,SAAQ,wBAOxC;IACC,IAAa,OAAO,IAAI,MAAM,CAM7B;CACF;AAED,eAAO,MAAM,oBAAoB,gCAI9B;IACD,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,WAAkE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Document.js","names":[],"sources":["../src/Document.ts"],"sourcesContent":["import type { ReadonlyValue } from \"@confect/core/SchemaToValidator\";\nimport { pipe } from \"effect/Function\";\nimport * as Effect from \"effect/Effect\";\nimport * as Function from \"effect/Function\";\nimport * as Schema from \"effect/Schema\";\nimport type { ReadonlyRecord } from \"effect/Record\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as DataModel from \"./DataModel\";\nimport type * as TableInfo from \"./TableInfo\";\nimport type * as Table from \"./Table\";\n\nexport type Document<\n Schema_ extends DatabaseSchema.AnyWithProps,\n TableName extends DatabaseSchema.TableNames<Schema_>,\n> = DataModel.DocumentByName<DataModel.FromSchema<Schema_>, TableName>;\n\nexport type WithoutSystemFields<Doc> = Doc extends unknown\n ? Omit<Doc, \"_creationTime\" | \"_id\">\n : never;\n\nexport type Any = any;\nexport type AnyEncoded = ReadonlyRecord<string, ReadonlyValue>;\n\nexport const decode = Function.dual<\n <Table_ extends Table.AnyWithProps>(\n table: Table_,\n ) => (\n self: TableInfo.TableInfo<Table_>[\"convexDocument\"],\n ) => Effect.Effect<\n TableInfo.TableInfo<Table_>[\"document\"],\n DocumentDecodeError\n >,\n <Table_ extends Table.AnyWithProps>(\n self: TableInfo.TableInfo<Table_>[\"convexDocument\"],\n table: Table_,\n ) => Effect.Effect<\n TableInfo.TableInfo<Table_>[\"document\"],\n DocumentDecodeError\n >\n>(\n 2,\n <Table_ extends Table.AnyWithProps>(\n self: TableInfo.TableInfo<Table_>[\"convexDocument\"],\n table: Table_,\n ): Effect.Effect<\n TableInfo.TableInfo<Table_>[\"document\"],\n DocumentDecodeError\n > =>\n pipe(\n self,\n Schema.decodeUnknownEffect(table.Doc),\n Effect.catchIf(Schema.isSchemaError, (schemaError) =>\n Effect.fail(\n new DocumentDecodeError({\n tableName: table.tableName,\n id: self._id,\n parseError: schemaError.message,\n }),\n ),\n ),\n ),\n);\n\nexport const encode = Function.dual<\n <Table_ extends Table.AnyWithProps>(\n table: Table_,\n ) => (\n self: Schema.Schema.Type<Table.Fields<Table_>>,\n ) => Effect.Effect<\n Schema.Codec.Encoded<Table.Fields<Table_>>,\n DocumentEncodeError\n >,\n <Table_ extends Table.AnyWithProps>(\n self: Schema.Schema.Type<Table.Fields<Table_>>,\n table: Table_,\n ) => Effect.Effect<\n Schema.Codec.Encoded<Table.Fields<Table_>>,\n DocumentEncodeError\n >\n>(\n 2,\n <Table_ extends Table.AnyWithProps>(\n self: Schema.Schema.Type<Table.Fields<Table_>>,\n table: Table_,\n ): Effect.Effect<\n Schema.Codec.Encoded<Table.Fields<Table_>>,\n DocumentEncodeError\n > =>\n pipe(\n self,\n Schema.encodeEffect(table.Fields),\n Effect.catchIf(Schema.isSchemaError, (schemaError) =>\n Effect.fail(\n new DocumentEncodeError({\n tableName: table.tableName,\n id: self._id,\n parseError: schemaError.message,\n }),\n ),\n ),\n ),\n);\n\nexport class DocumentDecodeError extends Schema.TaggedError<DocumentDecodeError>()(\n \"DocumentDecodeError\",\n {\n tableName: Schema.String,\n id: Schema.String,\n parseError: Schema.String,\n },\n) {\n override get message(): string {\n return documentErrorMessage({\n id: this.id,\n tableName: this.tableName,\n message: `could not be decoded:\\n\\n${this.parseError}`,\n });\n }\n}\n\nexport class DocumentEncodeError extends Schema.TaggedError<DocumentEncodeError>()(\n \"DocumentEncodeError\",\n {\n tableName: Schema.String,\n id: Schema.String,\n parseError: Schema.String,\n },\n) {\n override get message(): string {\n return documentErrorMessage({\n id: this.id,\n tableName: this.tableName,\n message: `could not be encoded:\\n\\n${this.parseError}`,\n });\n }\n}\n\nexport const documentErrorMessage = ({\n id,\n tableName,\n message,\n}: {\n id: string;\n tableName: string;\n message: string;\n}) => `Document with ID '${id}' in table '${tableName}' ${message}`;\n"],"mappings":";;;;;;;;;;;;;AAuBA,MAAa,SAAS,SAAS,KAiB7B,IAEE,MACA,UAKA,KACE,MACA,OAAO,oBAAoB,MAAM,GAAG,GACpC,OAAO,QAAQ,OAAO,gBAAgB,gBACpC,OAAO,KACL,IAAI,oBAAoB;CACtB,WAAW,MAAM;CACjB,IAAI,KAAK;CACT,YAAY,YAAY;AAC1B,CAAC,CACH,CACF,CACF,CACJ;AAEA,MAAa,SAAS,SAAS,KAiB7B,IAEE,MACA,UAKA,KACE,MACA,OAAO,aAAa,MAAM,MAAM,GAChC,OAAO,QAAQ,OAAO,gBAAgB,gBACpC,OAAO,KACL,IAAI,oBAAoB;CACtB,WAAW,MAAM;CACjB,IAAI,KAAK;CACT,YAAY,YAAY;AAC1B,CAAC,CACH,CACF,CACF,CACJ;AAEA,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAChF,uBACA;CACE,WAAW,OAAO;CAClB,IAAI,OAAO;CACX,YAAY,OAAO;AACrB,CACF,CAAC,CAAC;CACA,IAAa,UAAkB;EAC7B,OAAO,qBAAqB;GAC1B,IAAI,KAAK;GACT,WAAW,KAAK;GAChB,SAAS,4BAA4B,KAAK;EAC5C,CAAC;CACH;AACF;AAEA,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAChF,uBACA;CACE,WAAW,OAAO;CAClB,IAAI,OAAO;CACX,YAAY,OAAO;AACrB,CACF,CAAC,CAAC;CACA,IAAa,UAAkB;EAC7B,OAAO,qBAAqB;GAC1B,IAAI,KAAK;GACT,WAAW,KAAK;GAChB,SAAS,4BAA4B,KAAK;EAC5C,CAAC;CACH;AACF;AAEA,MAAa,wBAAwB,EACnC,IACA,WACA,cAKI,qBAAqB,GAAG,cAAc,UAAU,IAAI"}
1
+ {"version":3,"file":"Document.js","names":[],"sources":["../src/Document.ts"],"sourcesContent":["import type { ReadonlyValue } from \"@confect/core/SchemaToValidator\";\nimport { pipe } from \"effect/Function\";\nimport * as Effect from \"effect/Effect\";\nimport * as Function from \"effect/Function\";\nimport * as Schema from \"effect/Schema\";\nimport type { ReadonlyRecord } from \"effect/Record\";\nimport type * as DatabaseSchema from \"./DatabaseSchema.js\";\nimport type * as DataModel from \"./DataModel.js\";\nimport type * as TableInfo from \"./TableInfo.js\";\nimport type * as Table from \"./Table.js\";\n\nexport type Document<\n Schema_ extends DatabaseSchema.AnyWithProps,\n TableName extends DatabaseSchema.TableNames<Schema_>,\n> = DataModel.DocumentByName<DataModel.FromSchema<Schema_>, TableName>;\n\nexport type WithoutSystemFields<Doc> = Doc extends unknown\n ? Omit<Doc, \"_creationTime\" | \"_id\">\n : never;\n\nexport type Any = any;\nexport type AnyEncoded = ReadonlyRecord<string, ReadonlyValue>;\n\nexport const decode = Function.dual<\n <Table_ extends Table.AnyWithProps>(\n table: Table_,\n ) => (\n self: TableInfo.TableInfo<Table_>[\"convexDocument\"],\n ) => Effect.Effect<\n TableInfo.TableInfo<Table_>[\"document\"],\n DocumentDecodeError\n >,\n <Table_ extends Table.AnyWithProps>(\n self: TableInfo.TableInfo<Table_>[\"convexDocument\"],\n table: Table_,\n ) => Effect.Effect<\n TableInfo.TableInfo<Table_>[\"document\"],\n DocumentDecodeError\n >\n>(\n 2,\n <Table_ extends Table.AnyWithProps>(\n self: TableInfo.TableInfo<Table_>[\"convexDocument\"],\n table: Table_,\n ): Effect.Effect<\n TableInfo.TableInfo<Table_>[\"document\"],\n DocumentDecodeError\n > =>\n pipe(\n self,\n Schema.decodeUnknownEffect(table.Doc),\n Effect.catchIf(Schema.isSchemaError, (schemaError) =>\n Effect.fail(\n new DocumentDecodeError({\n tableName: table.tableName,\n id: self._id,\n parseError: schemaError.message,\n }),\n ),\n ),\n ),\n);\n\nexport const encode = Function.dual<\n <Table_ extends Table.AnyWithProps>(\n table: Table_,\n ) => (\n self: Schema.Schema.Type<Table.Fields<Table_>>,\n ) => Effect.Effect<\n Schema.Codec.Encoded<Table.Fields<Table_>>,\n DocumentEncodeError\n >,\n <Table_ extends Table.AnyWithProps>(\n self: Schema.Schema.Type<Table.Fields<Table_>>,\n table: Table_,\n ) => Effect.Effect<\n Schema.Codec.Encoded<Table.Fields<Table_>>,\n DocumentEncodeError\n >\n>(\n 2,\n <Table_ extends Table.AnyWithProps>(\n self: Schema.Schema.Type<Table.Fields<Table_>>,\n table: Table_,\n ): Effect.Effect<\n Schema.Codec.Encoded<Table.Fields<Table_>>,\n DocumentEncodeError\n > =>\n pipe(\n self,\n Schema.encodeEffect(table.Fields),\n Effect.catchIf(Schema.isSchemaError, (schemaError) =>\n Effect.fail(\n new DocumentEncodeError({\n tableName: table.tableName,\n id: self._id,\n parseError: schemaError.message,\n }),\n ),\n ),\n ),\n);\n\nexport class DocumentDecodeError extends Schema.TaggedError<DocumentDecodeError>()(\n \"DocumentDecodeError\",\n {\n tableName: Schema.String,\n id: Schema.String,\n parseError: Schema.String,\n },\n) {\n override get message(): string {\n return documentErrorMessage({\n id: this.id,\n tableName: this.tableName,\n message: `could not be decoded:\\n\\n${this.parseError}`,\n });\n }\n}\n\nexport class DocumentEncodeError extends Schema.TaggedError<DocumentEncodeError>()(\n \"DocumentEncodeError\",\n {\n tableName: Schema.String,\n id: Schema.String,\n parseError: Schema.String,\n },\n) {\n override get message(): string {\n return documentErrorMessage({\n id: this.id,\n tableName: this.tableName,\n message: `could not be encoded:\\n\\n${this.parseError}`,\n });\n }\n}\n\nexport const documentErrorMessage = ({\n id,\n tableName,\n message,\n}: {\n id: string;\n tableName: string;\n message: string;\n}) => `Document with ID '${id}' in table '${tableName}' ${message}`;\n"],"mappings":";;;;;;;;;;;;;AAuBA,MAAa,SAAS,SAAS,KAiB7B,IAEE,MACA,UAKA,KACE,MACA,OAAO,oBAAoB,MAAM,GAAG,GACpC,OAAO,QAAQ,OAAO,gBAAgB,gBACpC,OAAO,KACL,IAAI,oBAAoB;CACtB,WAAW,MAAM;CACjB,IAAI,KAAK;CACT,YAAY,YAAY;AAC1B,CAAC,CACH,CACF,CACF,CACJ;AAEA,MAAa,SAAS,SAAS,KAiB7B,IAEE,MACA,UAKA,KACE,MACA,OAAO,aAAa,MAAM,MAAM,GAChC,OAAO,QAAQ,OAAO,gBAAgB,gBACpC,OAAO,KACL,IAAI,oBAAoB;CACtB,WAAW,MAAM;CACjB,IAAI,KAAK;CACT,YAAY,YAAY;AAC1B,CAAC,CACH,CACF,CACF,CACJ;AAEA,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAChF,uBACA;CACE,WAAW,OAAO;CAClB,IAAI,OAAO;CACX,YAAY,OAAO;AACrB,CACF,CAAC,CAAC;CACA,IAAa,UAAkB;EAC7B,OAAO,qBAAqB;GAC1B,IAAI,KAAK;GACT,WAAW,KAAK;GAChB,SAAS,4BAA4B,KAAK;EAC5C,CAAC;CACH;AACF;AAEA,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAChF,uBACA;CACE,WAAW,OAAO;CAClB,IAAI,OAAO;CACX,YAAY,OAAO;AACrB,CACF,CAAC,CAAC;CACA,IAAa,UAAkB;EAC7B,OAAO,qBAAqB;GAC1B,IAAI,KAAK;GACT,WAAW,KAAK;GAChB,SAAS,4BAA4B,KAAK;EAC5C,CAAC;CACH;AACF;AAEA,MAAa,wBAAwB,EACnC,IACA,WACA,cAKI,qBAAqB,GAAG,cAAc,UAAU,IAAI"}
@@ -1,7 +1,7 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import * as Context from "effect/Context";
3
- import * as Layer from "effect/Layer";
4
3
  import * as Effect from "effect/Effect";
4
+ import * as Layer from "effect/Layer";
5
5
  //#region src/ExecutionMetadata.ts
6
6
  var ExecutionMetadata_exports = /* @__PURE__ */ __exportAll({
7
7
  ExecutionMetadata: () => ExecutionMetadata,
@@ -3,8 +3,8 @@ import type * as GroupSpec from "@confect/core/GroupSpec";
3
3
  import type * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
4
4
  import * as Context from "effect/Context";
5
5
  import * as Layer from "effect/Layer";
6
- import type * as DatabaseSchema from "./DatabaseSchema";
7
- import type * as Handler from "./Handler";
6
+ import type * as DatabaseSchema from "./DatabaseSchema.js";
7
+ import type * as Handler from "./Handler.js";
8
8
  export interface FunctionImpl<Name_ extends string> {
9
9
  readonly name: Name_;
10
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionImpl.d.ts","sourceRoot":"","sources":["../src/FunctionImpl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,YAAY,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,KAAK,SAAS,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,KAAK,cAAc,MAAM,8BAA8B,CAAC;AAEpE,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAE1C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,KAAK,OAAO,MAAM,WAAW,CAAC;AAI1C,MAAM,WAAW,YAAY,CAAC,KAAK,SAAS,MAAM;IAChD,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;CACtB;AAED,eAAO,MAAM,YAAY,GAAI,KAAK,SAAS,MAAM,YAAY;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,8DACE,CAAC;AAE/E;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,IAAI,GACf,eAAe,SAAS,cAAc,CAAC,YAA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AK,CAAC"}
@@ -1,10 +1,10 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { Registry } from "./Registry.js";
3
- import { make as make$1 } from "./FunctionRegistryItem.js";
4
3
  import { setNestedProperty } from "./internal/utils.js";
4
+ import { make as make$1 } from "./FunctionRegistryItem.js";
5
5
  import * as Context from "effect/Context";
6
- import * as Layer from "effect/Layer";
7
6
  import * as Effect from "effect/Effect";
7
+ import * as Layer from "effect/Layer";
8
8
  import * as Ref from "effect/Ref";
9
9
  //#region src/FunctionImpl.ts
10
10
  var FunctionImpl_exports = /* @__PURE__ */ __exportAll({
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionImpl.js","names":["Registry.Registry","FunctionRegistryItem.make"],"sources":["../src/FunctionImpl.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport type * as GroupSpec from \"@confect/core/GroupSpec\";\nimport type * as MiddlewareSpec from \"@confect/core/MiddlewareSpec\";\nimport * as Registry from \"./Registry\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Ref from \"effect/Ref\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as Handler from \"./Handler\";\nimport { setNestedProperty } from \"./internal/utils\";\nimport * as FunctionRegistryItem from \"./FunctionRegistryItem\";\n\nexport interface FunctionImpl<Name_ extends string> {\n readonly name: Name_;\n}\n\nexport const FunctionImpl = <Name_ extends string>({ name }: { name: Name_ }) =>\n Context.Service<FunctionImpl<Name_>>(`@confect/server/FunctionImpl/${name}`);\n\n/**\n * Register a single function's implementation into the group's `Registry`.\n *\n * The function is registered under a flat, single-segment key (its own `name`),\n * not a project-wide dot-path. Each group's impl layer is built in\n * isolation—`RegisteredFunctions.buildForGroup` (and the CLI's `validateImpl`)\n * provide a fresh `Registry` per group—so function names only need to be unique\n * within their own group.\n *\n * `databaseSchema` is retained purely as a type-level carrier: the handler's\n * ctx-service requirements (`DatabaseReader`, `QueryCtx<DataModel>`, …) are\n * derived from it via `Handler.WithName`. It is not read at runtime—the\n * generated per-group registry forwards the schema value to the function\n * builders—so impls depend on `_generated/schema` (table schemas) rather than\n * `_generated/api` (which transitively imports every function spec).\n */\nexport const make = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Group extends GroupSpec.AnyWithProps,\n const Name_ extends FunctionSpec.Name<GroupSpec.Functions<Group>>,\n>(\n _databaseSchema: DatabaseSchema_,\n group: Group,\n name: Name_,\n handler: Handler.WithName<\n DatabaseSchema_,\n GroupSpec.Functions<Group>,\n Name_,\n MiddlewareSpec.Provides<\n | GroupSpec.MiddlewareSpecs<Group>\n | FunctionSpec.MiddlewareSpecs<\n FunctionSpec.WithName<GroupSpec.Functions<Group>, Name_>\n >\n >\n >,\n): Layer.Layer<FunctionImpl<Name_>> => {\n const functionSpec = group.functions[name]!;\n\n return Layer.effect(\n FunctionImpl<Name_>({ name }),\n Effect.gen(function* () {\n const registry = yield* Registry.Registry;\n\n yield* Ref.update(registry, (registryItems) =>\n setNestedProperty(\n registryItems,\n [name],\n FunctionRegistryItem.make({\n functionSpec,\n groupMiddlewareAttachments: group.middlewareAttachments,\n handler,\n }),\n ),\n );\n\n return { name };\n }),\n );\n};\n\n/**\n * Get the function implementation service type for a specific function name.\n */\nexport type ForFunction<Name_ extends string> = FunctionImpl<Name_>;\n\n/**\n * Get all function implementation services required for a group spec.\n */\nexport type FromGroupSpec<Group extends GroupSpec.AnyWithProps> =\n FunctionSpec.Name<\n GroupSpec.Functions<Group>\n > extends infer FunctionNames extends string\n ? FunctionNames extends string\n ? FunctionImpl<FunctionNames>\n : never\n : never;\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAa,gBAAsC,EAAE,WACnD,QAAQ,QAA6B,gCAAgC,MAAM;;;;;;;;;;;;;;;;;AAkB7E,MAAa,QAKX,iBACA,OACA,MACA,YAWqC;CACrC,MAAM,eAAe,MAAM,UAAU;CAErC,OAAO,MAAM,OACX,aAAoB,EAAE,KAAK,CAAC,GAC5B,OAAO,IAAI,aAAa;EACtB,MAAM,WAAW,OAAOA;EAExB,OAAO,IAAI,OAAO,WAAW,kBAC3B,kBACE,eACA,CAAC,IAAI,GACLC,OAA0B;GACxB;GACA,4BAA4B,MAAM;GAClC;EACF,CAAC,CACH,CACF;EAEA,OAAO,EAAE,KAAK;CAChB,CAAC,CACH;AACF"}
1
+ {"version":3,"file":"FunctionImpl.js","names":["Registry.Registry","FunctionRegistryItem.make"],"sources":["../src/FunctionImpl.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport type * as GroupSpec from \"@confect/core/GroupSpec\";\nimport type * as MiddlewareSpec from \"@confect/core/MiddlewareSpec\";\nimport * as Registry from \"./Registry.js\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Ref from \"effect/Ref\";\nimport type * as DatabaseSchema from \"./DatabaseSchema.js\";\nimport type * as Handler from \"./Handler.js\";\nimport { setNestedProperty } from \"./internal/utils.js\";\nimport * as FunctionRegistryItem from \"./FunctionRegistryItem.js\";\n\nexport interface FunctionImpl<Name_ extends string> {\n readonly name: Name_;\n}\n\nexport const FunctionImpl = <Name_ extends string>({ name }: { name: Name_ }) =>\n Context.Service<FunctionImpl<Name_>>(`@confect/server/FunctionImpl/${name}`);\n\n/**\n * Register a single function's implementation into the group's `Registry`.\n *\n * The function is registered under a flat, single-segment key (its own `name`),\n * not a project-wide dot-path. Each group's impl layer is built in\n * isolation—`RegisteredFunctions.buildForGroup` (and the CLI's `validateImpl`)\n * provide a fresh `Registry` per group—so function names only need to be unique\n * within their own group.\n *\n * `databaseSchema` is retained purely as a type-level carrier: the handler's\n * ctx-service requirements (`DatabaseReader`, `QueryCtx<DataModel>`, …) are\n * derived from it via `Handler.WithName`. It is not read at runtime—the\n * generated per-group registry forwards the schema value to the function\n * builders—so impls depend on `_generated/schema` (table schemas) rather than\n * `_generated/api` (which transitively imports every function spec).\n */\nexport const make = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n Group extends GroupSpec.AnyWithProps,\n const Name_ extends FunctionSpec.Name<GroupSpec.Functions<Group>>,\n>(\n _databaseSchema: DatabaseSchema_,\n group: Group,\n name: Name_,\n handler: Handler.WithName<\n DatabaseSchema_,\n GroupSpec.Functions<Group>,\n Name_,\n MiddlewareSpec.Provides<\n | GroupSpec.MiddlewareSpecs<Group>\n | FunctionSpec.MiddlewareSpecs<\n FunctionSpec.WithName<GroupSpec.Functions<Group>, Name_>\n >\n >\n >,\n): Layer.Layer<FunctionImpl<Name_>> => {\n const functionSpec = group.functions[name]!;\n\n return Layer.effect(\n FunctionImpl<Name_>({ name }),\n Effect.gen(function* () {\n const registry = yield* Registry.Registry;\n\n yield* Ref.update(registry, (registryItems) =>\n setNestedProperty(\n registryItems,\n [name],\n FunctionRegistryItem.make({\n functionSpec,\n groupMiddlewareAttachments: group.middlewareAttachments,\n handler,\n }),\n ),\n );\n\n return { name };\n }),\n );\n};\n\n/**\n * Get the function implementation service type for a specific function name.\n */\nexport type ForFunction<Name_ extends string> = FunctionImpl<Name_>;\n\n/**\n * Get all function implementation services required for a group spec.\n */\nexport type FromGroupSpec<Group extends GroupSpec.AnyWithProps> =\n FunctionSpec.Name<\n GroupSpec.Functions<Group>\n > extends infer FunctionNames extends string\n ? FunctionNames extends string\n ? FunctionImpl<FunctionNames>\n : never\n : never;\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAa,gBAAsC,EAAE,WACnD,QAAQ,QAA6B,gCAAgC,MAAM;;;;;;;;;;;;;;;;;AAkB7E,MAAa,QAKX,iBACA,OACA,MACA,YAWqC;CACrC,MAAM,eAAe,MAAM,UAAU;CAErC,OAAO,MAAM,OACX,aAAoB,EAAE,KAAK,CAAC,GAC5B,OAAO,IAAI,aAAa;EACtB,MAAM,WAAW,OAAOA;EAExB,OAAO,IAAI,OAAO,WAAW,kBAC3B,kBACE,eACA,CAAC,IAAI,GACLC,OAA0B;GACxB;GACA,4BAA4B,MAAM;GAClC;EACF,CAAC,CACH,CACF;EAEA,OAAO,EAAE,KAAK;CAChB,CAAC,CACH;AACF"}
@@ -2,7 +2,7 @@ import type * as MiddlewareAttachment from "@confect/core/MiddlewareAttachment";
2
2
  import type * as FunctionSpec from "@confect/core/FunctionSpec";
3
3
  import type { FunctionType, FunctionVisibility } from "convex/server";
4
4
  import type * as Schema from "effect/Schema";
5
- import type * as Handler from "./Handler";
5
+ import type * as Handler from "./Handler.js";
6
6
  export declare const TypeId = "~@confect/server/FunctionRegistryItem";
7
7
  export type TypeId = typeof TypeId;
8
8
  export declare const isFunctionRegistryItem: (value: unknown) => value is AnyWithProps;
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionRegistryItem.d.ts","sourceRoot":"","sources":["../src/FunctionRegistryItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,oBAAoB,MAAM,oCAAoC,CAAC;AAChF,OAAO,KAAK,KAAK,YAAY,MAAM,4BAA4B,CAAC;AAEhE,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGtE,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,KAAK,OAAO,MAAM,WAAW,CAAC;AAE1C,eAAO,MAAM,MAAM,0CAA0C,CAAC;AAC9D,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAEnC,eAAO,MAAM,sBAAsB,UAAW,OAAO,KAAG,KAAK,IAAI,YAC3B,CAAC;AAMvC;;;GAGG;AACH,MAAM,MAAM,YAAY,GACpB,2BAA2B,GAC3B,0BAA0B,CAAC;AAE/B,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CA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,CAAC,oBAAoB,CAAC,CAAC;IACrF,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC;CACtB,KAAG,YA8BD,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
- import * as Match from "effect/Match";
3
2
  import * as Predicate from "effect/Predicate";
3
+ import * as Match from "effect/Match";
4
4
  import * as Lazy from "@confect/core/Lazy";
5
5
  //#region src/FunctionRegistryItem.ts
6
6
  var FunctionRegistryItem_exports = /* @__PURE__ */ __exportAll({
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionRegistryItem.js","names":[],"sources":["../src/FunctionRegistryItem.ts"],"sourcesContent":["import type * as MiddlewareAttachment from \"@confect/core/MiddlewareAttachment\";\nimport type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport * as Lazy from \"@confect/core/Lazy\";\nimport type { FunctionType, FunctionVisibility } from \"convex/server\";\nimport * as Match from \"effect/Match\";\nimport * as Predicate from \"effect/Predicate\";\nimport type * as Schema from \"effect/Schema\";\nimport type * as Handler from \"./Handler\";\n\nexport const TypeId = \"~@confect/server/FunctionRegistryItem\";\nexport type TypeId = typeof TypeId;\n\nexport const isFunctionRegistryItem = (value: unknown): value is AnyWithProps =>\n Predicate.hasProperty(value, TypeId);\n\nconst FunctionRegistryItemProto = {\n [TypeId]: TypeId,\n};\n\n/**\n * A function registered by `FunctionImpl.make`, one of two shapes keyed by the\n * spec's provenance.\n */\nexport type AnyWithProps =\n | ConfectFunctionRegistryItem\n | ConvexFunctionRegistryItem;\n\nexport interface ConfectFunctionRegistryItem {\n readonly [TypeId]: TypeId;\n readonly _tag: \"Confect\";\n readonly name: string;\n readonly functionVisibility: FunctionVisibility;\n readonly functionType: FunctionType;\n readonly args: Schema.Codec<any, any>;\n readonly returns: Schema.Codec<any, any>;\n readonly error?: Schema.Codec<any, any>;\n readonly middlewareAttachments: ReadonlyArray<MiddlewareAttachment.MiddlewareAttachment>;\n readonly handler: Handler.AnyConfectProvenance;\n}\n\nexport interface ConvexFunctionRegistryItem {\n readonly [TypeId]: TypeId;\n readonly _tag: \"Convex\";\n readonly handler: Handler.AnyConvexProvenance;\n}\n\nexport const make = ({\n functionSpec,\n groupMiddlewareAttachments,\n handler,\n}: {\n functionSpec: FunctionSpec.AnyWithProps;\n groupMiddlewareAttachments: ReadonlyArray<MiddlewareAttachment.MiddlewareAttachment>;\n handler: Handler.Any;\n}): AnyWithProps =>\n Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\"Convex\", (): AnyWithProps =>\n Object.assign(Object.create(FunctionRegistryItemProto), {\n _tag: \"Convex\" as const,\n handler: handler as Handler.AnyConvexProvenance,\n }),\n ),\n Match.tag(\"Confect\", (provenance): AnyWithProps => {\n const item = Object.assign(Object.create(FunctionRegistryItemProto), {\n _tag: \"Confect\" as const,\n name: functionSpec.name,\n functionVisibility: functionSpec.functionVisibility,\n functionType: functionSpec.runtimeAndFunctionType.functionType,\n middlewareAttachments: [\n ...groupMiddlewareAttachments,\n ...functionSpec.middlewareAttachments,\n ],\n handler: handler as Handler.AnyConfectProvenance,\n });\n\n Lazy.defineProperty(item, \"args\", () => provenance.args);\n Lazy.defineProperty(item, \"returns\", () => provenance.returns);\n if (\"error\" in provenance) {\n Lazy.defineProperty(item, \"error\", () => provenance.error);\n }\n\n return item as AnyWithProps;\n }),\n Match.exhaustive,\n );\n"],"mappings":";;;;;;;;;;AASA,MAAa,SAAS;AAGtB,MAAa,0BAA0B,UACrC,UAAU,YAAY,OAAO,MAAM;AAErC,MAAM,4BAA4B,GAC/B,SAAS,OACZ;AA6BA,MAAa,QAAQ,EACnB,cACA,4BACA,cAMA,MAAM,MAAM,aAAa,kBAAkB,CAAC,CAAC,KAC3C,MAAM,IAAI,gBACR,OAAO,OAAO,OAAO,OAAO,yBAAyB,GAAG;CACtD,MAAM;CACG;AACX,CAAC,CACH,GACA,MAAM,IAAI,YAAY,eAA6B;CACjD,MAAM,OAAO,OAAO,OAAO,OAAO,OAAO,yBAAyB,GAAG;EACnE,MAAM;EACN,MAAM,aAAa;EACnB,oBAAoB,aAAa;EACjC,cAAc,aAAa,uBAAuB;EAClD,uBAAuB,CACrB,GAAG,4BACH,GAAG,aAAa,qBAClB;EACS;CACX,CAAC;CAED,KAAK,eAAe,MAAM,cAAc,WAAW,IAAI;CACvD,KAAK,eAAe,MAAM,iBAAiB,WAAW,OAAO;CAC7D,IAAI,WAAW,YACb,KAAK,eAAe,MAAM,eAAe,WAAW,KAAK;CAG3D,OAAO;AACT,CAAC,GACD,MAAM,UACR"}
1
+ {"version":3,"file":"FunctionRegistryItem.js","names":[],"sources":["../src/FunctionRegistryItem.ts"],"sourcesContent":["import type * as MiddlewareAttachment from \"@confect/core/MiddlewareAttachment\";\nimport type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport * as Lazy from \"@confect/core/Lazy\";\nimport type { FunctionType, FunctionVisibility } from \"convex/server\";\nimport * as Match from \"effect/Match\";\nimport * as Predicate from \"effect/Predicate\";\nimport type * as Schema from \"effect/Schema\";\nimport type * as Handler from \"./Handler.js\";\n\nexport const TypeId = \"~@confect/server/FunctionRegistryItem\";\nexport type TypeId = typeof TypeId;\n\nexport const isFunctionRegistryItem = (value: unknown): value is AnyWithProps =>\n Predicate.hasProperty(value, TypeId);\n\nconst FunctionRegistryItemProto = {\n [TypeId]: TypeId,\n};\n\n/**\n * A function registered by `FunctionImpl.make`, one of two shapes keyed by the\n * spec's provenance.\n */\nexport type AnyWithProps =\n | ConfectFunctionRegistryItem\n | ConvexFunctionRegistryItem;\n\nexport interface ConfectFunctionRegistryItem {\n readonly [TypeId]: TypeId;\n readonly _tag: \"Confect\";\n readonly name: string;\n readonly functionVisibility: FunctionVisibility;\n readonly functionType: FunctionType;\n readonly args: Schema.Codec<any, any>;\n readonly returns: Schema.Codec<any, any>;\n readonly error?: Schema.Codec<any, any>;\n readonly middlewareAttachments: ReadonlyArray<MiddlewareAttachment.MiddlewareAttachment>;\n readonly handler: Handler.AnyConfectProvenance;\n}\n\nexport interface ConvexFunctionRegistryItem {\n readonly [TypeId]: TypeId;\n readonly _tag: \"Convex\";\n readonly handler: Handler.AnyConvexProvenance;\n}\n\nexport const make = ({\n functionSpec,\n groupMiddlewareAttachments,\n handler,\n}: {\n functionSpec: FunctionSpec.AnyWithProps;\n groupMiddlewareAttachments: ReadonlyArray<MiddlewareAttachment.MiddlewareAttachment>;\n handler: Handler.Any;\n}): AnyWithProps =>\n Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\"Convex\", (): AnyWithProps =>\n Object.assign(Object.create(FunctionRegistryItemProto), {\n _tag: \"Convex\" as const,\n handler: handler as Handler.AnyConvexProvenance,\n }),\n ),\n Match.tag(\"Confect\", (provenance): AnyWithProps => {\n const item = Object.assign(Object.create(FunctionRegistryItemProto), {\n _tag: \"Confect\" as const,\n name: functionSpec.name,\n functionVisibility: functionSpec.functionVisibility,\n functionType: functionSpec.runtimeAndFunctionType.functionType,\n middlewareAttachments: [\n ...groupMiddlewareAttachments,\n ...functionSpec.middlewareAttachments,\n ],\n handler: handler as Handler.AnyConfectProvenance,\n });\n\n Lazy.defineProperty(item, \"args\", () => provenance.args);\n Lazy.defineProperty(item, \"returns\", () => provenance.returns);\n if (\"error\" in provenance) {\n Lazy.defineProperty(item, \"error\", () => provenance.error);\n }\n\n return item as AnyWithProps;\n }),\n Match.exhaustive,\n );\n"],"mappings":";;;;;;;;;;AASA,MAAa,SAAS;AAGtB,MAAa,0BAA0B,UACrC,UAAU,YAAY,OAAO,MAAM;AAErC,MAAM,4BAA4B,GAC/B,SAAS,OACZ;AA6BA,MAAa,QAAQ,EACnB,cACA,4BACA,cAMA,MAAM,MAAM,aAAa,kBAAkB,CAAC,CAAC,KAC3C,MAAM,IAAI,gBACR,OAAO,OAAO,OAAO,OAAO,yBAAyB,GAAG;CACtD,MAAM;CACG;AACX,CAAC,CACH,GACA,MAAM,IAAI,YAAY,eAA6B;CACjD,MAAM,OAAO,OAAO,OAAO,OAAO,OAAO,yBAAyB,GAAG;EACnE,MAAM;EACN,MAAM,aAAa;EACnB,oBAAoB,aAAa;EACjC,cAAc,aAAa,uBAAuB;EAClD,uBAAuB,CACrB,GAAG,4BACH,GAAG,aAAa,qBAClB;EACS;CACX,CAAC;CAED,KAAK,eAAe,MAAM,cAAc,WAAW,IAAI;CACvD,KAAK,eAAe,MAAM,iBAAiB,WAAW,OAAO;CAC7D,IAAI,WAAW,YACb,KAAK,eAAe,MAAM,eAAe,WAAW,KAAK;CAG3D,OAAO;AACT,CAAC,GACD,MAAM,UACR"}
@@ -1,10 +1,11 @@
1
1
  import type * as GroupSpec from "@confect/core/GroupSpec";
2
2
  import type * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
3
+ import * as RegistryItems from "./RegistryItems.js";
3
4
  import * as Context from "effect/Context";
4
5
  import * as Layer from "effect/Layer";
5
- import type * as DatabaseSchema from "./DatabaseSchema";
6
- import type * as FunctionImpl from "./FunctionImpl";
7
- import type * as MiddlewareImpl from "./MiddlewareImpl";
6
+ import type * as DatabaseSchema from "./DatabaseSchema.js";
7
+ import type * as FunctionImpl from "./FunctionImpl.js";
8
+ import type * as MiddlewareImpl from "./MiddlewareImpl.js";
8
9
  export declare const TypeId = "~@confect/server/GroupImpl";
9
10
  export type TypeId = typeof TypeId;
10
11
  export type FinalizationStatus = "Unfinalized" | "Finalized";
@@ -59,6 +60,15 @@ export declare const GroupImpl: <FinalizationStatus_ extends FinalizationStatus>
59
60
  * runtime.
60
61
  */
61
62
  export declare const make: <DatabaseSchema_ extends DatabaseSchema.AnyWithProps, Group extends GroupSpec.AnyWithProps>(_databaseSchema: DatabaseSchema_, _group: Group & MiddlewareSpec.ValidateImplRequires<GroupSpec.Functions<Group>, GroupSpec.MiddlewareSpecs<Group>>) => Layer.Layer<GroupImpl<"Unfinalized">, never, FunctionImpl.FromGroupSpec<Group> | MiddlewareImpl.FromGroupSpec<Group>>;
63
+ declare const MissingRequiredMiddlewareError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
64
+ readonly _tag: "MissingRequiredMiddlewareError";
65
+ } & Readonly<A>;
66
+ export declare class MissingRequiredMiddlewareError extends MissingRequiredMiddlewareError_base<{
67
+ readonly missing: ReadonlyArray<RegistryItems.MissingMiddleware>;
68
+ }> {
69
+ get message(): string;
70
+ }
71
+ type Finalizable = Layer.Layer<AnyUnfinalized> | Layer.Layer<AnyFinalized>;
62
72
  /**
63
73
  * Mark a `GroupImpl` layer as fully implemented. The parameter type defaults
64
74
  * `RIn = never`, so passing a layer that still requires any `FunctionImpl`
@@ -70,8 +80,17 @@ export declare const make: <DatabaseSchema_ extends DatabaseSchema.AnyWithProps,
70
80
  * registered into this group's scope are snapshotted onto the produced service
71
81
  * value's `registeredFunctionNames` field, so consumers can verify impl
72
82
  * completeness against a `GroupSpec`'s expected functions without having to
73
- * inspect the `Registry` themselves.
83
+ * inspect the `Registry` themselves. Pass `{ required }` to check every
84
+ * registered function's middleware at layer build, including internal
85
+ * functions. This form also accepts a finalized layer so generated registration
86
+ * can enforce the backend declaration without changing authored impls. Pass
87
+ * `groupPath` to qualify uncovered function names in the diagnostic.
74
88
  */
75
- export declare const finalize: (group: Layer.Layer<GroupImpl<"Unfinalized">>) => Layer.Layer<GroupImpl<"Finalized">>;
89
+ export declare function finalize(options: {
90
+ readonly groupPath?: string;
91
+ readonly required: ReadonlyArray<Pick<MiddlewareSpec.AnyMiddlewareSpec, "key">>;
92
+ }): (group: Finalizable) => Layer.Layer<GroupImpl<"Finalized">>;
93
+ export declare function finalize(group: Layer.Layer<GroupImpl<"Unfinalized">>): Layer.Layer<GroupImpl<"Finalized">>;
76
94
  export type FromGroupSpec<Group extends GroupSpec.AnyWithProps> = FunctionImpl.FromGroupSpec<Group> | MiddlewareImpl.FromGroupSpec<Group>;
95
+ export {};
77
96
  //# sourceMappingURL=GroupImpl.d.ts.map
@@ -1 +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