@gaganref/confect-server 10.3.1-fork.1 → 10.3.1-fork.11

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 (210) hide show
  1. package/dist/ActionCtx.d.ts +1 -1
  2. package/dist/ActionCtx.d.ts.map +1 -1
  3. package/dist/ActionCtx.js.map +1 -1
  4. package/dist/AiGatewayDecisionClient.d.ts +2 -2
  5. package/dist/AiGatewayDecisionClient.d.ts.map +1 -1
  6. package/dist/AiGatewayDecisionClient.js.map +1 -1
  7. package/dist/AiGatewayLanguageClient.d.ts +2 -2
  8. package/dist/AiGatewayLanguageClient.d.ts.map +1 -1
  9. package/dist/AiGatewayLanguageClient.js.map +1 -1
  10. package/dist/Auth.d.ts +1 -1
  11. package/dist/Auth.d.ts.map +1 -1
  12. package/dist/Auth.js.map +1 -1
  13. package/dist/ComponentCtx.d.ts +1 -1
  14. package/dist/ComponentCtx.d.ts.map +1 -1
  15. package/dist/ConvexFunctionDefinitions.d.ts +4 -4
  16. package/dist/ConvexFunctionDefinitions.d.ts.map +1 -1
  17. package/dist/ConvexFunctionDefinitions.js.map +1 -1
  18. package/dist/CronJobs.d.ts +1 -1
  19. package/dist/CronJobs.d.ts.map +1 -1
  20. package/dist/CronJobs.js.map +1 -1
  21. package/dist/DataModel.d.ts +3 -3
  22. package/dist/DataModel.d.ts.map +1 -1
  23. package/dist/DataModel.js.map +1 -1
  24. package/dist/DatabaseReader.d.ts +4 -4
  25. package/dist/DatabaseReader.d.ts.map +1 -1
  26. package/dist/DatabaseReader.js.map +1 -1
  27. package/dist/DatabaseSchema.d.ts +1 -1
  28. package/dist/DatabaseSchema.d.ts.map +1 -1
  29. package/dist/DatabaseSchema.js.map +1 -1
  30. package/dist/DatabaseWriter.d.ts +5 -5
  31. package/dist/DatabaseWriter.d.ts.map +1 -1
  32. package/dist/DatabaseWriter.js.map +1 -1
  33. package/dist/Document.d.ts +4 -4
  34. package/dist/Document.d.ts.map +1 -1
  35. package/dist/Document.js.map +1 -1
  36. package/dist/FunctionImpl.d.ts +2 -2
  37. package/dist/FunctionImpl.d.ts.map +1 -1
  38. package/dist/FunctionImpl.js.map +1 -1
  39. package/dist/FunctionRegistryItem.d.ts +1 -1
  40. package/dist/FunctionRegistryItem.d.ts.map +1 -1
  41. package/dist/FunctionRegistryItem.js.map +1 -1
  42. package/dist/GroupImpl.d.ts +3 -3
  43. package/dist/GroupImpl.d.ts.map +1 -1
  44. package/dist/GroupImpl.js.map +1 -1
  45. package/dist/GroupRegistry.d.ts +2 -2
  46. package/dist/GroupRegistry.d.ts.map +1 -1
  47. package/dist/GroupRegistry.js.map +1 -1
  48. package/dist/Handler.d.ts +23 -23
  49. package/dist/Handler.d.ts.map +1 -1
  50. package/dist/Handler.js.map +1 -1
  51. package/dist/HttpRouter.d.ts +13 -13
  52. package/dist/HttpRouter.d.ts.map +1 -1
  53. package/dist/HttpRouter.js.map +1 -1
  54. package/dist/MiddlewareImpl.d.ts +14 -14
  55. package/dist/MiddlewareImpl.d.ts.map +1 -1
  56. package/dist/MiddlewareImpl.js.map +1 -1
  57. package/dist/MutationCtx.d.ts +1 -1
  58. package/dist/MutationCtx.d.ts.map +1 -1
  59. package/dist/MutationCtx.js.map +1 -1
  60. package/dist/MutationRunner.d.ts +1 -1
  61. package/dist/MutationRunner.d.ts.map +1 -1
  62. package/dist/MutationRunner.js.map +1 -1
  63. package/dist/MutationTransactionContext.d.ts +2 -2
  64. package/dist/MutationTransactionContext.d.ts.map +1 -1
  65. package/dist/MutationTransactionContext.js.map +1 -1
  66. package/dist/OfficialComponent.d.ts +50 -0
  67. package/dist/OfficialComponent.d.ts.map +1 -0
  68. package/dist/OfficialComponent.js +70 -0
  69. package/dist/OfficialComponent.js.map +1 -0
  70. package/dist/OrderedQuery.d.ts +4 -4
  71. package/dist/OrderedQuery.d.ts.map +1 -1
  72. package/dist/OrderedQuery.js.map +1 -1
  73. package/dist/QueryCtx.d.ts +1 -1
  74. package/dist/QueryCtx.d.ts.map +1 -1
  75. package/dist/QueryCtx.js.map +1 -1
  76. package/dist/QueryInitializer.d.ts +10 -10
  77. package/dist/QueryInitializer.d.ts.map +1 -1
  78. package/dist/QueryInitializer.js.map +1 -1
  79. package/dist/QueryRunner.d.ts +2 -2
  80. package/dist/QueryRunner.d.ts.map +1 -1
  81. package/dist/QueryRunner.js.map +1 -1
  82. package/dist/QueryStream.d.ts +11 -11
  83. package/dist/QueryStream.d.ts.map +1 -1
  84. package/dist/QueryStream.js.map +1 -1
  85. package/dist/QueryStreamCursor.d.ts +2 -2
  86. package/dist/QueryStreamCursor.d.ts.map +1 -1
  87. package/dist/QueryStreamCursor.js.map +1 -1
  88. package/dist/QueryStreamIndexPrefix.d.ts +2 -2
  89. package/dist/QueryStreamIndexPrefix.d.ts.map +1 -1
  90. package/dist/QueryStreamIndexPrefix.js.map +1 -1
  91. package/dist/QueryStreamIndexRange.d.ts +4 -4
  92. package/dist/QueryStreamIndexRange.d.ts.map +1 -1
  93. package/dist/QueryStreamIndexRange.js.map +1 -1
  94. package/dist/QueryStreamKey.d.ts +2 -2
  95. package/dist/QueryStreamKey.d.ts.map +1 -1
  96. package/dist/QueryStreamKey.js.map +1 -1
  97. package/dist/QueryStreamKeyBounds.d.ts +3 -3
  98. package/dist/QueryStreamKeyBounds.d.ts.map +1 -1
  99. package/dist/QueryStreamKeyBounds.js.map +1 -1
  100. package/dist/QueryStreamKeyLayout.d.ts +1 -1
  101. package/dist/QueryStreamKeyLayout.d.ts.map +1 -1
  102. package/dist/QueryStreamKeyLayout.js.map +1 -1
  103. package/dist/QueryStreamKeyValues.d.ts +1 -1
  104. package/dist/QueryStreamKeyValues.d.ts.map +1 -1
  105. package/dist/QueryStreamKeyValues.js.map +1 -1
  106. package/dist/QueryStreamPagination.d.ts +1 -1
  107. package/dist/QueryStreamPagination.d.ts.map +1 -1
  108. package/dist/QueryStreamPagination.js.map +1 -1
  109. package/dist/RegisteredConvexFunction.d.ts +20 -20
  110. package/dist/RegisteredConvexFunction.d.ts.map +1 -1
  111. package/dist/RegisteredConvexFunction.js.map +1 -1
  112. package/dist/RegisteredFunction.d.ts +26 -26
  113. package/dist/RegisteredFunction.d.ts.map +1 -1
  114. package/dist/RegisteredFunction.js.map +1 -1
  115. package/dist/RegisteredFunctions.d.ts +3 -3
  116. package/dist/RegisteredFunctions.d.ts.map +1 -1
  117. package/dist/RegisteredFunctions.js.map +1 -1
  118. package/dist/RegisteredNodeFunction.d.ts +6 -6
  119. package/dist/RegisteredNodeFunction.d.ts.map +1 -1
  120. package/dist/RegisteredNodeFunction.js.map +1 -1
  121. package/dist/Registry.d.ts +1 -1
  122. package/dist/Registry.d.ts.map +1 -1
  123. package/dist/Registry.js.map +1 -1
  124. package/dist/RegistryItems.js.map +1 -1
  125. package/dist/ResolvedMiddleware.d.ts +2 -2
  126. package/dist/ResolvedMiddleware.d.ts.map +1 -1
  127. package/dist/ResolvedMiddleware.js.map +1 -1
  128. package/dist/Storage.d.ts +6 -6
  129. package/dist/Storage.d.ts.map +1 -1
  130. package/dist/Storage.js.map +1 -1
  131. package/dist/StorageActionWriter.d.ts +1 -1
  132. package/dist/StorageActionWriter.d.ts.map +1 -1
  133. package/dist/StorageActionWriter.js.map +1 -1
  134. package/dist/StorageReader.d.ts +1 -1
  135. package/dist/StorageReader.d.ts.map +1 -1
  136. package/dist/StorageReader.js.map +1 -1
  137. package/dist/StorageWriter.d.ts +1 -1
  138. package/dist/StorageWriter.d.ts.map +1 -1
  139. package/dist/StorageWriter.js.map +1 -1
  140. package/dist/TableInfo.d.ts +2 -2
  141. package/dist/TableInfo.d.ts.map +1 -1
  142. package/dist/TableInfo.js.map +1 -1
  143. package/dist/VectorSearch.d.ts +1 -1
  144. package/dist/VectorSearch.d.ts.map +1 -1
  145. package/dist/VectorSearch.js.map +1 -1
  146. package/dist/index.d.ts +61 -60
  147. package/dist/index.d.ts.map +1 -1
  148. package/dist/index.js +2 -1
  149. package/dist/internal/AiGatewayDecisionClient.d.ts +1 -1
  150. package/dist/internal/AiGatewayDecisionClient.d.ts.map +1 -1
  151. package/dist/internal/AiGatewayDecisionClient.js.map +1 -1
  152. package/dist/internal/AiGatewayLanguageClient.d.ts +1 -1
  153. package/dist/internal/AiGatewayLanguageClient.d.ts.map +1 -1
  154. package/dist/internal/AiGatewayLanguageClient.js.map +1 -1
  155. package/dist/node.d.ts +1 -1
  156. package/dist/node.d.ts.map +1 -1
  157. package/package.json +2 -2
  158. package/src/ActionCtx.ts +1 -1
  159. package/src/AiGatewayDecisionClient.ts +3 -3
  160. package/src/AiGatewayLanguageClient.ts +3 -3
  161. package/src/Auth.ts +1 -1
  162. package/src/ComponentCtx.ts +1 -1
  163. package/src/ConvexFunctionDefinitions.ts +8 -8
  164. package/src/CronJobs.ts +1 -1
  165. package/src/DataModel.ts +3 -3
  166. package/src/DatabaseReader.ts +4 -4
  167. package/src/DatabaseSchema.ts +1 -1
  168. package/src/DatabaseWriter.ts +6 -6
  169. package/src/Document.ts +4 -4
  170. package/src/FunctionImpl.ts +5 -5
  171. package/src/FunctionRegistryItem.ts +1 -1
  172. package/src/GroupImpl.ts +5 -5
  173. package/src/GroupRegistry.ts +4 -4
  174. package/src/Handler.ts +23 -23
  175. package/src/HttpRouter.ts +17 -17
  176. package/src/MiddlewareImpl.ts +17 -17
  177. package/src/MutationCtx.ts +1 -1
  178. package/src/MutationRunner.ts +1 -1
  179. package/src/MutationTransactionContext.ts +2 -2
  180. package/src/OfficialComponent.ts +151 -0
  181. package/src/OrderedQuery.ts +4 -4
  182. package/src/QueryCtx.ts +1 -1
  183. package/src/QueryInitializer.ts +9 -9
  184. package/src/QueryRunner.ts +2 -2
  185. package/src/QueryStream.ts +15 -15
  186. package/src/QueryStreamCursor.ts +3 -3
  187. package/src/QueryStreamIndexPrefix.ts +2 -2
  188. package/src/QueryStreamIndexRange.ts +4 -4
  189. package/src/QueryStreamKey.ts +2 -2
  190. package/src/QueryStreamKeyBounds.ts +3 -3
  191. package/src/QueryStreamKeyLayout.ts +1 -1
  192. package/src/QueryStreamKeyValues.ts +1 -1
  193. package/src/QueryStreamPagination.ts +2 -2
  194. package/src/RegisteredConvexFunction.ts +21 -21
  195. package/src/RegisteredFunction.ts +18 -18
  196. package/src/RegisteredFunctions.ts +4 -4
  197. package/src/RegisteredNodeFunction.ts +8 -8
  198. package/src/Registry.ts +1 -1
  199. package/src/RegistryItems.ts +2 -2
  200. package/src/ResolvedMiddleware.ts +2 -2
  201. package/src/Storage.ts +3 -3
  202. package/src/StorageActionWriter.ts +1 -1
  203. package/src/StorageReader.ts +1 -1
  204. package/src/StorageWriter.ts +1 -1
  205. package/src/TableInfo.ts +2 -2
  206. package/src/VectorSearch.ts +1 -1
  207. package/src/index.ts +61 -60
  208. package/src/internal/AiGatewayDecisionClient.ts +2 -2
  209. package/src/internal/AiGatewayLanguageClient.ts +2 -2
  210. package/src/node.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"MiddlewareImpl.js","names":["Registry.Registry","MiddlewareRegistryItem.registryKey","MiddlewareRegistryItem.TypeId"],"sources":["../src/MiddlewareImpl.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport type * as GroupSpec from \"@confect/core/GroupSpec\";\nimport * as MiddlewareSpec from \"@confect/core/MiddlewareSpec\";\nimport * as Registry from \"./Registry\";\nimport type { FunctionType } from \"convex/server\";\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 Auth from \"./Auth\";\nimport type * as DatabaseReader from \"./DatabaseReader\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport type * as Handler from \"./Handler\";\nimport type { ExecutionMetadata } from \"./ExecutionMetadata\";\nimport type { RequestMetadata } from \"./RequestMetadata\";\nimport type { TransactionMetadata } from \"./TransactionMetadata\";\nimport type * as MutationRunner from \"./MutationRunner\";\nimport type * as QueryRunner from \"./QueryRunner\";\nimport type { QueryTransactionContext } from \"./QueryTransactionContext\";\nimport type * as Scheduler from \"./Scheduler\";\nimport type { Storage } from \"./Storage\";\nimport type * as StorageReader from \"./StorageReader\";\nimport type * as StorageWriter from \"./StorageWriter\";\nimport * as MiddlewareRegistryItem from \"./MiddlewareRegistryItem\";\nimport { setNestedProperty } from \"./internal/utils\";\n\n/**\n * Marker service produced by providing a middleware's implementation to a\n * group's impl layer. `GroupImpl.make` requires one per middleware attached to\n * the group's spec (via {@link FromGroupSpec}), so `GroupImpl.finalize`'s `RIn =\n * never` bound rejects a group that attaches a middleware but never provides\n * its implementation—the exact mechanism used for `FunctionImpl`s.\n */\nexport interface MiddlewareImpl<MiddlewareKey extends string> {\n readonly middlewareKey: MiddlewareKey;\n}\n\nexport const MiddlewareImpl = <MiddlewareKey extends string>({\n middlewareKey,\n}: {\n middlewareKey: MiddlewareKey;\n}) =>\n Context.Service<MiddlewareImpl<MiddlewareKey>>(\n `@confect/server/MiddlewareImpl/${middlewareKey}`,\n );\n\nexport type FromGroupSpec<Group extends GroupSpec.AnyWithProps> =\n | GroupSpec.MiddlewareSpecs<Group>\n | FunctionSpec.MiddlewareSpecs<\n GroupSpec.Functions<Group>\n > extends infer MiddlewareSpec_\n ? MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec\n ? MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>\n : never\n : never;\n\nexport type FunctionTypeServices<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionType_ extends FunctionType,\n> = FunctionType_ extends \"query\"\n ? Handler.QueryServices<DatabaseSchema_>\n : FunctionType_ extends \"mutation\"\n ? Handler.MutationServices<DatabaseSchema_>\n : FunctionType_ extends \"action\"\n ? Handler.ActionServices<DatabaseSchema_>\n : never;\n\n/**\n * The services a single middleware implementation may use: the set-theoretic\n * intersection of the ctx-service unions of the middleware's declared\n * `functionTypes`, so one implementation is valid in every runtime it can be\n * invoked in. Enumerated by hand rather than derived with\n * `Exclude`/`Extract`—several ctx services are structurally typed (e.g. the raw\n * `GenericQueryCtx`/`GenericMutationCtx` tags), so conditional-type set\n * arithmetic over them is not reliable.\n */\nexport type CommonServices<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionTypes extends FunctionType,\n> = [FunctionTypes] extends [\"query\"]\n ? Handler.QueryServices<DatabaseSchema_>\n : [FunctionTypes] extends [\"mutation\"]\n ? Handler.MutationServices<DatabaseSchema_>\n : [FunctionTypes] extends [\"action\"]\n ? Handler.ActionServices<DatabaseSchema_>\n : [FunctionTypes] extends [\"query\" | \"mutation\"]\n ? QueryMutationCommonServices<DatabaseSchema_>\n : [FunctionTypes] extends [\"mutation\" | \"action\"]\n ? MutationActionCommonServices\n : AllFunctionTypesCommonServices;\n\ntype QueryMutationCommonServices<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n> =\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | Auth.Auth\n | ExecutionMetadata\n | TransactionMetadata\n | QueryTransactionContext\n | Storage\n | StorageReader.StorageReader\n | QueryRunner.QueryRunner;\n\ntype MutationActionCommonServices =\n | Auth.Auth\n | ExecutionMetadata\n | RequestMetadata\n | Scheduler.Scheduler\n | Storage\n | StorageReader.StorageReader\n | StorageWriter.StorageWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner;\n\ntype AllFunctionTypesCommonServices =\n | Auth.Auth\n | ExecutionMetadata\n | Storage\n | StorageReader.StorageReader\n | QueryRunner.QueryRunner;\n\nconst layerFromImpls = <\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,\n>(\n middlewareSpec: MiddlewareSpec_,\n impls: MiddlewareRegistryItem.MiddlewareRegistryItem[\"impls\"],\n): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>\n Layer.effect(\n MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>({\n middlewareKey: middlewareSpec.key,\n }),\n Effect.gen(function* () {\n const registry = yield* Registry.Registry;\n\n yield* Ref.update(registry, (registryItems) =>\n setNestedProperty(\n registryItems,\n [MiddlewareRegistryItem.registryKey(middlewareSpec.key)],\n {\n [MiddlewareRegistryItem.TypeId]: MiddlewareRegistryItem.TypeId,\n middlewareSpec,\n impls,\n } satisfies MiddlewareRegistryItem.MiddlewareRegistryItem,\n ),\n );\n\n return { middlewareKey: middlewareSpec.key };\n }),\n );\n\n/**\n * Provide a middleware's implementation with a single strategy shared by every\n * function type the middleware declares. The implementation's environment is\n * bounded by {@link CommonServices}—the intersection of the declared\n * functionTypes' ctx services—plus the middleware's declared `requires`, which\n * middleware running earlier in the chain provide. Reach for\n * {@link makeByFunctionType} when one strategy can't fit all declared\n * functionTypes (the usual case for database-touching middleware attached to\n * actions).\n *\n * Like `FunctionImpl.make`, `databaseSchema` is a type-level carrier only.\n */\nexport const make = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,\n>(\n _databaseSchema: DatabaseSchema_,\n middlewareSpec: MiddlewareSpec_,\n impl: MiddlewareSpec.MiddlewareImpl<\n MiddlewareSpec.Provides<MiddlewareSpec_>,\n MiddlewareSpec.Error<MiddlewareSpec_>,\n | CommonServices<\n DatabaseSchema_,\n MiddlewareSpec.FunctionTypes<MiddlewareSpec_>\n >\n | MiddlewareSpec.Requires<MiddlewareSpec_>,\n MiddlewareSpec.Options<MiddlewareSpec_>\n >,\n): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>\n layerFromImpls(\n middlewareSpec,\n Object.fromEntries(\n MiddlewareSpec.allFunctionTypes\n .filter((functionType) => middlewareSpec.functionTypes[functionType])\n .map((functionType) => [\n functionType,\n impl as MiddlewareSpec.AnyMiddlewareImpl,\n ]),\n ),\n );\n\n/**\n * Provide a middleware's implementation with one strategy per declared function\n * type. Each entry may use that function type's full ctx-service union—the\n * recommended shape for database-touching middleware that also covers actions:\n * use `DatabaseReader`/`DatabaseWriter` in queries and mutations, and\n * `runQuery` of an internal query in actions.\n */\nexport const makeByFunctionType = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,\n>(\n _databaseSchema: DatabaseSchema_,\n middlewareSpec: MiddlewareSpec_,\n impls: {\n readonly [\n FunctionType_ in MiddlewareSpec.FunctionTypes<MiddlewareSpec_>\n ]: MiddlewareSpec.MiddlewareImpl<\n MiddlewareSpec.Provides<MiddlewareSpec_>,\n MiddlewareSpec.Error<MiddlewareSpec_>,\n | FunctionTypeServices<DatabaseSchema_, FunctionType_>\n | MiddlewareSpec.Requires<MiddlewareSpec_>,\n MiddlewareSpec.Options<MiddlewareSpec_>\n >;\n },\n): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>\n layerFromImpls(\n middlewareSpec,\n impls as MiddlewareRegistryItem.MiddlewareRegistryItem[\"impls\"],\n );\n\n/**\n * Sugar over {@link make} for the flagship \"run something, provide a service\"\n * shape: run `effect` before the rest of the chain and provide its result under\n * `tag` (the runtime tag for the middleware's type-level `provides` service,\n * passed explicitly since the spec class only knows it at the type level).\n */\nexport const provides = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,\n Shape,\n>(\n databaseSchema: DatabaseSchema_,\n middlewareSpec: MiddlewareSpec_,\n tag: Context.Key<MiddlewareSpec.Provides<MiddlewareSpec_>, Shape>,\n effect: Effect.Effect<\n Shape,\n MiddlewareSpec.Error<MiddlewareSpec_>,\n | CommonServices<\n DatabaseSchema_,\n MiddlewareSpec.FunctionTypes<MiddlewareSpec_>\n >\n | MiddlewareSpec.Requires<MiddlewareSpec_>\n >,\n): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>\n make(databaseSchema, middlewareSpec, ((handlerEffect: Effect.Effect<any>) =>\n Effect.provideServiceEffect(handlerEffect, tag, effect)) as any);\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,MAAa,kBAAgD,EAC3D,oBAIA,QAAQ,QACN,kCAAkC,eACpC;AA6EF,MAAM,kBAGJ,gBACA,UAEA,MAAM,OACJ,eAAoD,EAClD,eAAe,eAAe,IAChC,CAAC,GACD,OAAO,IAAI,aAAa;CACtB,MAAM,WAAW,OAAOA;CAExB,OAAO,IAAI,OAAO,WAAW,kBAC3B,kBACE,eACA,CAACC,YAAmC,eAAe,GAAG,CAAC,GACvD;GACGC,SAAgCA;EACjC;EACA;CACF,CACF,CACF;CAEA,OAAO,EAAE,eAAe,eAAe,IAAI;AAC7C,CAAC,CACH;;;;;;;;;;;;;AAcF,MAAa,QAIX,iBACA,gBACA,SAWA,eACE,gBACA,OAAO,YACL,eAAe,iBACZ,QAAQ,iBAAiB,eAAe,cAAc,aAAa,CAAC,CACpE,KAAK,iBAAiB,CACrB,cACA,IACF,CAAC,CACL,CACF;;;;;;;;AASF,MAAa,sBAIX,iBACA,gBACA,UAYA,eACE,gBACA,KACF;;;;;;;AAQF,MAAa,YAKX,gBACA,gBACA,KACA,WAUA,KAAK,gBAAgB,kBAAkB,kBACrC,OAAO,qBAAqB,eAAe,KAAK,MAAM,EAAS"}
1
+ {"version":3,"file":"MiddlewareImpl.js","names":["Registry.Registry","MiddlewareRegistryItem.registryKey","MiddlewareRegistryItem.TypeId"],"sources":["../src/MiddlewareImpl.ts"],"sourcesContent":["import type * as FunctionSpec from \"@confect/core/FunctionSpec\";\nimport type * as GroupSpec from \"@confect/core/GroupSpec\";\nimport * as MiddlewareSpec from \"@confect/core/MiddlewareSpec\";\nimport * as Registry from \"./Registry.js\";\nimport type { FunctionType } from \"convex/server\";\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 Auth from \"./Auth.js\";\nimport type * as DatabaseReader from \"./DatabaseReader.js\";\nimport type * as DatabaseSchema from \"./DatabaseSchema.js\";\nimport type * as Handler from \"./Handler.js\";\nimport type { ExecutionMetadata } from \"./ExecutionMetadata.js\";\nimport type { RequestMetadata } from \"./RequestMetadata.js\";\nimport type { TransactionMetadata } from \"./TransactionMetadata.js\";\nimport type * as MutationRunner from \"./MutationRunner.js\";\nimport type * as QueryRunner from \"./QueryRunner.js\";\nimport type { QueryTransactionContext } from \"./QueryTransactionContext.js\";\nimport type * as Scheduler from \"./Scheduler.js\";\nimport type { Storage } from \"./Storage.js\";\nimport type * as StorageReader from \"./StorageReader.js\";\nimport type * as StorageWriter from \"./StorageWriter.js\";\nimport * as MiddlewareRegistryItem from \"./MiddlewareRegistryItem.js\";\nimport { setNestedProperty } from \"./internal/utils.js\";\n\n/**\n * Marker service produced by providing a middleware's implementation to a\n * group's impl layer. `GroupImpl.make` requires one per middleware attached to\n * the group's spec (via {@link FromGroupSpec}), so `GroupImpl.finalize`'s `RIn =\n * never` bound rejects a group that attaches a middleware but never provides\n * its implementation—the exact mechanism used for `FunctionImpl`s.\n */\nexport interface MiddlewareImpl<MiddlewareKey extends string> {\n readonly middlewareKey: MiddlewareKey;\n}\n\nexport const MiddlewareImpl = <MiddlewareKey extends string>({\n middlewareKey,\n}: {\n middlewareKey: MiddlewareKey;\n}) =>\n Context.Service<MiddlewareImpl<MiddlewareKey>>(\n `@confect/server/MiddlewareImpl/${middlewareKey}`,\n );\n\nexport type FromGroupSpec<Group extends GroupSpec.AnyWithProps> =\n | GroupSpec.MiddlewareSpecs<Group>\n | FunctionSpec.MiddlewareSpecs<\n GroupSpec.Functions<Group>\n > extends infer MiddlewareSpec_\n ? MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec\n ? MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>\n : never\n : never;\n\nexport type FunctionTypeServices<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionType_ extends FunctionType,\n> = FunctionType_ extends \"query\"\n ? Handler.QueryServices<DatabaseSchema_>\n : FunctionType_ extends \"mutation\"\n ? Handler.MutationServices<DatabaseSchema_>\n : FunctionType_ extends \"action\"\n ? Handler.ActionServices<DatabaseSchema_>\n : never;\n\n/**\n * The services a single middleware implementation may use: the set-theoretic\n * intersection of the ctx-service unions of the middleware's declared\n * `functionTypes`, so one implementation is valid in every runtime it can be\n * invoked in. Enumerated by hand rather than derived with\n * `Exclude`/`Extract`—several ctx services are structurally typed (e.g. the raw\n * `GenericQueryCtx`/`GenericMutationCtx` tags), so conditional-type set\n * arithmetic over them is not reliable.\n */\nexport type CommonServices<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n FunctionTypes extends FunctionType,\n> = [FunctionTypes] extends [\"query\"]\n ? Handler.QueryServices<DatabaseSchema_>\n : [FunctionTypes] extends [\"mutation\"]\n ? Handler.MutationServices<DatabaseSchema_>\n : [FunctionTypes] extends [\"action\"]\n ? Handler.ActionServices<DatabaseSchema_>\n : [FunctionTypes] extends [\"query\" | \"mutation\"]\n ? QueryMutationCommonServices<DatabaseSchema_>\n : [FunctionTypes] extends [\"mutation\" | \"action\"]\n ? MutationActionCommonServices\n : AllFunctionTypesCommonServices;\n\ntype QueryMutationCommonServices<\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n> =\n | DatabaseReader.DatabaseReader<DatabaseSchema_>\n | Auth.Auth\n | ExecutionMetadata\n | TransactionMetadata\n | QueryTransactionContext\n | Storage\n | StorageReader.StorageReader\n | QueryRunner.QueryRunner;\n\ntype MutationActionCommonServices =\n | Auth.Auth\n | ExecutionMetadata\n | RequestMetadata\n | Scheduler.Scheduler\n | Storage\n | StorageReader.StorageReader\n | StorageWriter.StorageWriter\n | QueryRunner.QueryRunner\n | MutationRunner.MutationRunner;\n\ntype AllFunctionTypesCommonServices =\n | Auth.Auth\n | ExecutionMetadata\n | Storage\n | StorageReader.StorageReader\n | QueryRunner.QueryRunner;\n\nconst layerFromImpls = <\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,\n>(\n middlewareSpec: MiddlewareSpec_,\n impls: MiddlewareRegistryItem.MiddlewareRegistryItem[\"impls\"],\n): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>\n Layer.effect(\n MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>({\n middlewareKey: middlewareSpec.key,\n }),\n Effect.gen(function* () {\n const registry = yield* Registry.Registry;\n\n yield* Ref.update(registry, (registryItems) =>\n setNestedProperty(\n registryItems,\n [MiddlewareRegistryItem.registryKey(middlewareSpec.key)],\n {\n [MiddlewareRegistryItem.TypeId]: MiddlewareRegistryItem.TypeId,\n middlewareSpec,\n impls,\n } satisfies MiddlewareRegistryItem.MiddlewareRegistryItem,\n ),\n );\n\n return { middlewareKey: middlewareSpec.key };\n }),\n );\n\n/**\n * Provide a middleware's implementation with a single strategy shared by every\n * function type the middleware declares. The implementation's environment is\n * bounded by {@link CommonServices}—the intersection of the declared\n * functionTypes' ctx services—plus the middleware's declared `requires`, which\n * middleware running earlier in the chain provide. Reach for\n * {@link makeByFunctionType} when one strategy can't fit all declared\n * functionTypes (the usual case for database-touching middleware attached to\n * actions).\n *\n * Like `FunctionImpl.make`, `databaseSchema` is a type-level carrier only.\n */\nexport const make = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,\n>(\n _databaseSchema: DatabaseSchema_,\n middlewareSpec: MiddlewareSpec_,\n impl: MiddlewareSpec.MiddlewareImpl<\n MiddlewareSpec.Provides<MiddlewareSpec_>,\n MiddlewareSpec.Error<MiddlewareSpec_>,\n | CommonServices<\n DatabaseSchema_,\n MiddlewareSpec.FunctionTypes<MiddlewareSpec_>\n >\n | MiddlewareSpec.Requires<MiddlewareSpec_>,\n MiddlewareSpec.Options<MiddlewareSpec_>\n >,\n): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>\n layerFromImpls(\n middlewareSpec,\n Object.fromEntries(\n MiddlewareSpec.allFunctionTypes\n .filter((functionType) => middlewareSpec.functionTypes[functionType])\n .map((functionType) => [\n functionType,\n impl as MiddlewareSpec.AnyMiddlewareImpl,\n ]),\n ),\n );\n\n/**\n * Provide a middleware's implementation with one strategy per declared function\n * type. Each entry may use that function type's full ctx-service union—the\n * recommended shape for database-touching middleware that also covers actions:\n * use `DatabaseReader`/`DatabaseWriter` in queries and mutations, and\n * `runQuery` of an internal query in actions.\n */\nexport const makeByFunctionType = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,\n>(\n _databaseSchema: DatabaseSchema_,\n middlewareSpec: MiddlewareSpec_,\n impls: {\n readonly [\n FunctionType_ in MiddlewareSpec.FunctionTypes<MiddlewareSpec_>\n ]: MiddlewareSpec.MiddlewareImpl<\n MiddlewareSpec.Provides<MiddlewareSpec_>,\n MiddlewareSpec.Error<MiddlewareSpec_>,\n | FunctionTypeServices<DatabaseSchema_, FunctionType_>\n | MiddlewareSpec.Requires<MiddlewareSpec_>,\n MiddlewareSpec.Options<MiddlewareSpec_>\n >;\n },\n): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>\n layerFromImpls(\n middlewareSpec,\n impls as MiddlewareRegistryItem.MiddlewareRegistryItem[\"impls\"],\n );\n\n/**\n * Sugar over {@link make} for the flagship \"run something, provide a service\"\n * shape: run `effect` before the rest of the chain and provide its result under\n * `tag` (the runtime tag for the middleware's type-level `provides` service,\n * passed explicitly since the spec class only knows it at the type level).\n */\nexport const provides = <\n DatabaseSchema_ extends DatabaseSchema.AnyWithProps,\n MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec,\n Shape,\n>(\n databaseSchema: DatabaseSchema_,\n middlewareSpec: MiddlewareSpec_,\n tag: Context.Key<MiddlewareSpec.Provides<MiddlewareSpec_>, Shape>,\n effect: Effect.Effect<\n Shape,\n MiddlewareSpec.Error<MiddlewareSpec_>,\n | CommonServices<\n DatabaseSchema_,\n MiddlewareSpec.FunctionTypes<MiddlewareSpec_>\n >\n | MiddlewareSpec.Requires<MiddlewareSpec_>\n >,\n): Layer.Layer<MiddlewareImpl<MiddlewareSpec.Key<MiddlewareSpec_>>> =>\n make(databaseSchema, middlewareSpec, ((handlerEffect: Effect.Effect<any>) =>\n Effect.provideServiceEffect(handlerEffect, tag, effect)) as any);\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,MAAa,kBAAgD,EAC3D,oBAIA,QAAQ,QACN,kCAAkC,eACpC;AA6EF,MAAM,kBAGJ,gBACA,UAEA,MAAM,OACJ,eAAoD,EAClD,eAAe,eAAe,IAChC,CAAC,GACD,OAAO,IAAI,aAAa;CACtB,MAAM,WAAW,OAAOA;CAExB,OAAO,IAAI,OAAO,WAAW,kBAC3B,kBACE,eACA,CAACC,YAAmC,eAAe,GAAG,CAAC,GACvD;GACGC,SAAgCA;EACjC;EACA;CACF,CACF,CACF;CAEA,OAAO,EAAE,eAAe,eAAe,IAAI;AAC7C,CAAC,CACH;;;;;;;;;;;;;AAcF,MAAa,QAIX,iBACA,gBACA,SAWA,eACE,gBACA,OAAO,YACL,eAAe,iBACZ,QAAQ,iBAAiB,eAAe,cAAc,aAAa,CAAC,CACpE,KAAK,iBAAiB,CACrB,cACA,IACF,CAAC,CACL,CACF;;;;;;;;AASF,MAAa,sBAIX,iBACA,gBACA,UAYA,eACE,gBACA,KACF;;;;;;;AAQF,MAAa,YAKX,gBACA,gBACA,KACA,WAUA,KAAK,gBAAgB,kBAAkB,kBACrC,OAAO,qBAAqB,eAAe,KAAK,MAAM,EAAS"}
@@ -1,7 +1,7 @@
1
1
  import type * as IdScope from "@confect/core/IdScope";
2
2
  import type { GenericDataModel, GenericMutationCtx } from "convex/server";
3
3
  import * as Context from "effect/Context";
4
- import type * as ComponentCtx from "./ComponentCtx";
4
+ import type * as ComponentCtx from "./ComponentCtx.js";
5
5
  import * as Layer from "effect/Layer";
6
6
  export type MutationCtxTag<DataModel extends GenericDataModel, Scope extends IdScope.IdScope = IdScope.App> = Context.Service<MutationCtx<DataModel, Scope>, Scope extends IdScope.App ? GenericMutationCtx<DataModel> : ComponentCtx.Mutation<DataModel, Scope>>;
7
7
  export declare const MutationCtx: <DataModel extends GenericDataModel, Scope extends IdScope.IdScope = IdScope.App>() => MutationCtxTag<DataModel, Scope>;
@@ -1 +1 @@
1
- {"version":3,"file":"MutationCtx.d.ts","sourceRoot":"","sources":["../src/MutationCtx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,KAAK,YAAY,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,MAAM,MAAM,cAAc,CACxB,SAAS,SAAS,gBAAgB,EAClC,KAAK,SAAS,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,IACzC,OAAO,CAAC,OAAO,CACjB,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,EAC7B,KAAK,SAAS,OAAO,CAAC,GAAG,GACrB,kBAAkB,CAAC,SAAS,CAAC,GAC7B,YAAY,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,CAC5C,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,SAAS,SAAS,gBAAgB,EAClC,KAAK,SAAS,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,OACxC,cAAc,CAAC,SAAS,EAAE,KAAK,CACY,CAAC;AAEjD,MAAM,MAAM,WAAW,CACrB,SAAS,SAAS,gBAAgB,EAClC,KAAK,SAAS,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,IACzC,KAAK,SAAS,OAAO,CA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kBAAkB,CAAC,SAAS,CAAC,GAC7B,YAAY,CAAC,UAAU,CAAC,UAAU,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;AAE1D,eAAO,MAAM,KAAK,GAChB,SAAS,SAAS,gBAAgB,EAClC,KAAK,SAAS,OAAO,CAAC,OAAO,OAExB,kBAAkB,CAAC,SAAS,CAAC,SAC3B,KAAK,6DAUb,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"MutationCtx.js","names":[],"sources":["../src/MutationCtx.ts"],"sourcesContent":["import type * as IdScope from \"@confect/core/IdScope\";\nimport type { GenericDataModel, GenericMutationCtx } from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport type * as ComponentCtx from \"./ComponentCtx\";\nimport * as Layer from \"effect/Layer\";\n\nexport type MutationCtxTag<\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n> = Context.Service<\n MutationCtx<DataModel, Scope>,\n Scope extends IdScope.App\n ? GenericMutationCtx<DataModel>\n : ComponentCtx.Mutation<DataModel, Scope>\n>;\n\nexport const MutationCtx = <\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n>(): MutationCtxTag<DataModel, Scope> =>\n Context.Service(\"@confect/server/MutationCtx\");\n\nexport type MutationCtx<\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n> = Scope extends IdScope.App\n ? GenericMutationCtx<DataModel>\n : ComponentCtx.Identifier<\"mutation\", DataModel, Scope>;\n\nexport const layer = <\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope,\n>(\n ctx: GenericMutationCtx<DataModel>,\n scope: Scope,\n) => {\n const tag = MutationCtx<DataModel, Scope>();\n const { auth: _auth, ...componentCtx } = ctx;\n return Layer.succeed(\n tag,\n (scope === \"\" ? ctx : componentCtx) as unknown as Context.Service.Shape<\n typeof tag\n >,\n );\n};\n"],"mappings":";;;;;;;;AAgBA,MAAa,oBAIX,QAAQ,QAAQ,6BAA6B;AAS/C,MAAa,SAIX,KACA,UACG;CACH,MAAM,MAAM,YAA8B;CAC1C,MAAM,EAAE,MAAM,OAAO,GAAG,iBAAiB;CACzC,OAAO,MAAM,QACX,KACC,UAAU,KAAK,MAAM,YAGxB;AACF"}
1
+ {"version":3,"file":"MutationCtx.js","names":[],"sources":["../src/MutationCtx.ts"],"sourcesContent":["import type * as IdScope from \"@confect/core/IdScope\";\nimport type { GenericDataModel, GenericMutationCtx } from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport type * as ComponentCtx from \"./ComponentCtx.js\";\nimport * as Layer from \"effect/Layer\";\n\nexport type MutationCtxTag<\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n> = Context.Service<\n MutationCtx<DataModel, Scope>,\n Scope extends IdScope.App\n ? GenericMutationCtx<DataModel>\n : ComponentCtx.Mutation<DataModel, Scope>\n>;\n\nexport const MutationCtx = <\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n>(): MutationCtxTag<DataModel, Scope> =>\n Context.Service(\"@confect/server/MutationCtx\");\n\nexport type MutationCtx<\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n> = Scope extends IdScope.App\n ? GenericMutationCtx<DataModel>\n : ComponentCtx.Identifier<\"mutation\", DataModel, Scope>;\n\nexport const layer = <\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope,\n>(\n ctx: GenericMutationCtx<DataModel>,\n scope: Scope,\n) => {\n const tag = MutationCtx<DataModel, Scope>();\n const { auth: _auth, ...componentCtx } = ctx;\n return Layer.succeed(\n tag,\n (scope === \"\" ? ctx : componentCtx) as unknown as Context.Service.Shape<\n typeof tag\n >,\n );\n};\n"],"mappings":";;;;;;;;AAgBA,MAAa,oBAIX,QAAQ,QAAQ,6BAA6B;AAS/C,MAAa,SAIX,KACA,UACG;CACH,MAAM,MAAM,YAA8B;CAC1C,MAAM,EAAE,MAAM,OAAO,GAAG,iBAAiB;CACzC,OAAO,MAAM,QACX,KACC,UAAU,KAAK,MAAM,YAGxB;AACF"}
@@ -4,7 +4,7 @@ import * as Context from "effect/Context";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as Layer from "effect/Layer";
6
6
  import type * as Schema from "effect/Schema";
7
- import * as MutationTransactionContext from "./MutationTransactionContext";
7
+ import * as MutationTransactionContext from "./MutationTransactionContext.js";
8
8
  export type Options = MutationTransactionContext.MutationOptions;
9
9
  export declare const MutationRunner: Context.Service<{
10
10
  runMutation: {
@@ -1 +1 @@
1
- {"version":3,"file":"MutationRunner.d.ts","sourceRoot":"","sources":["../src/MutationRunner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,0BAA0B,MAAM,8BAA8B,CAAC;AAE3E,MAAM,MAAM,OAAO,GAAG,0BAA0B,CAAC,eAAe,CAAC;AAmDjE,eAAO,MAAM,cAAc;;SA5CJ,QAAQ,SAAS,GAAG,CAAC,WAAW,YACzC,QAAQ,WACT,CAAC,GAAG,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,EAAE,SAAS,CAAC,GAC5D,MAAM,CAAC,MAAM,CACd,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,EACrB,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,WAAW,CACzC;SACoB,QAAQ,SAAS,GAAG,CAAC,WAAW,YACzC,QAAQ,QACZ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,WACf,OAAO,GAAG,SAAS,GAC3B,MAAM,CAAC,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CAAC,IAAI,CAAC,QAAQ,CAAC,WACf,OAAO,GAAG,SAAS,GAC3B,MAAM,CAAC,MAAM,CACd,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,EACrB,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,WAAW,EACxC,0BAA0B,CAAC,0BAA0B,CACtD;;gBAmC+C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"MutationRunner.js","names":["MutationTransactionContext.MutationTransactionContext"],"sources":["../src/MutationRunner.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport type { GenericActionCtx } from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport type * as Schema from \"effect/Schema\";\nimport * as MutationTransactionContext from \"./MutationTransactionContext\";\n\nexport type Options = MutationTransactionContext.MutationOptions;\n\nconst run = Effect.fn(\"MutationRunner.runMutation\")(\n <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => effect,\n);\n\nconst make = (nativeRunMutation: GenericActionCtx<any>[\"runMutation\"]) => {\n function runMutation<Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n ...args: [...Ref.OptionalArgs<Mutation>, options?: undefined]\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | Schema.SchemaError\n >;\n function runMutation<Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n args: Ref.Args<Mutation>,\n options: Options | undefined,\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | Schema.SchemaError,\n MutationTransactionContext.MutationTransactionContext\n >;\n function runMutation<Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n args?: Ref.Args<Mutation>,\n options?: Options,\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | Schema.SchemaError,\n MutationTransactionContext.MutationTransactionContext\n > {\n return run(\n Effect.gen(function* () {\n const actualArgs = (args ?? {}) as Ref.Args<Mutation>;\n if (options !== undefined) {\n const controls =\n yield* MutationTransactionContext.MutationTransactionContext;\n return yield* controls.runMutation(mutation, actualArgs, options);\n }\n return yield* Ref.runWithCodec(\n mutation,\n actualArgs,\n (ref, encodedArgs) => nativeRunMutation(ref, encodedArgs),\n );\n }),\n );\n }\n return { runMutation };\n};\n\nexport const MutationRunner = Context.Service<ReturnType<typeof make>>(\n \"@confect/server/MutationRunner\",\n);\nexport type MutationRunner = typeof MutationRunner.Identifier;\n\nexport const layer = (runMutation: GenericActionCtx<any>[\"runMutation\"]) =>\n Layer.succeed(MutationRunner, make(runMutation));\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,MAAM,OAAO,GAAG,4BAA4B,CAAC,EACvC,WAA2D,MACvE;AAEA,MAAM,QAAQ,sBAA4D;CAiBxE,SAAS,YACP,UACA,MACA,SAKA;EACA,OAAO,IACL,OAAO,IAAI,aAAa;GACtB,MAAM,aAAc,QAAQ,CAAC;GAC7B,IAAI,YAAY,KAAA,GAGd,OAAO,QAAO,OADLA,2BAAAA,CACc,YAAY,UAAU,YAAY,OAAO;GAElE,OAAO,OAAO,IAAI,aAChB,UACA,aACC,KAAK,gBAAgB,kBAAkB,KAAK,WAAW,CAC1D;EACF,CAAC,CACH;CACF;CACA,OAAO,EAAE,YAAY;AACvB;AAEA,MAAa,iBAAiB,QAAQ,QACpC,gCACF;AAGA,MAAa,SAAS,gBACpB,MAAM,QAAQ,gBAAgB,KAAK,WAAW,CAAC"}
1
+ {"version":3,"file":"MutationRunner.js","names":["MutationTransactionContext.MutationTransactionContext"],"sources":["../src/MutationRunner.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport type { GenericActionCtx } from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport type * as Schema from \"effect/Schema\";\nimport * as MutationTransactionContext from \"./MutationTransactionContext.js\";\n\nexport type Options = MutationTransactionContext.MutationOptions;\n\nconst run = Effect.fn(\"MutationRunner.runMutation\")(\n <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => effect,\n);\n\nconst make = (nativeRunMutation: GenericActionCtx<any>[\"runMutation\"]) => {\n function runMutation<Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n ...args: [...Ref.OptionalArgs<Mutation>, options?: undefined]\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | Schema.SchemaError\n >;\n function runMutation<Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n args: Ref.Args<Mutation>,\n options: Options | undefined,\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | Schema.SchemaError,\n MutationTransactionContext.MutationTransactionContext\n >;\n function runMutation<Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n args?: Ref.Args<Mutation>,\n options?: Options,\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | Schema.SchemaError,\n MutationTransactionContext.MutationTransactionContext\n > {\n return run(\n Effect.gen(function* () {\n const actualArgs = (args ?? {}) as Ref.Args<Mutation>;\n if (options !== undefined) {\n const controls =\n yield* MutationTransactionContext.MutationTransactionContext;\n return yield* controls.runMutation(mutation, actualArgs, options);\n }\n return yield* Ref.runWithCodec(\n mutation,\n actualArgs,\n (ref, encodedArgs) => nativeRunMutation(ref, encodedArgs),\n );\n }),\n );\n }\n return { runMutation };\n};\n\nexport const MutationRunner = Context.Service<ReturnType<typeof make>>(\n \"@confect/server/MutationRunner\",\n);\nexport type MutationRunner = typeof MutationRunner.Identifier;\n\nexport const layer = (runMutation: GenericActionCtx<any>[\"runMutation\"]) =>\n Layer.succeed(MutationRunner, make(runMutation));\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,MAAM,OAAO,GAAG,4BAA4B,CAAC,EACvC,WAA2D,MACvE;AAEA,MAAM,QAAQ,sBAA4D;CAiBxE,SAAS,YACP,UACA,MACA,SAKA;EACA,OAAO,IACL,OAAO,IAAI,aAAa;GACtB,MAAM,aAAc,QAAQ,CAAC;GAC7B,IAAI,YAAY,KAAA,GAGd,OAAO,QAAO,OADLA,2BAAAA,CACc,YAAY,UAAU,YAAY,OAAO;GAElE,OAAO,OAAO,IAAI,aAChB,UACA,aACC,KAAK,gBAAgB,kBAAkB,KAAK,WAAW,CAC1D;EACF,CAAC,CACH;CACF;CACA,OAAO,EAAE,YAAY;AACvB;AAEA,MAAa,iBAAiB,QAAQ,QACpC,gCACF;AAGA,MAAa,SAAS,gBACpB,MAAM,QAAQ,gBAAgB,KAAK,WAAW,CAAC"}
@@ -3,9 +3,9 @@ import type { AdvancedRunQueryOptions, GenericDataModel, GenericMutationCtx } fr
3
3
  import * as Context from "effect/Context";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as Layer from "effect/Layer";
6
- import type { Options as MutationOptions } from "./QueryTransactionContext";
6
+ import type { Options as MutationOptions } from "./QueryTransactionContext.js";
7
7
  export type { TransactionLimits } from "convex/server";
8
- export type { Options as MutationOptions } from "./QueryTransactionContext";
8
+ export type { Options as MutationOptions } from "./QueryTransactionContext.js";
9
9
  export type QueryOptions = AdvancedRunQueryOptions;
10
10
  declare const MutationTransactionContext_base: Context.ServiceClass<MutationTransactionContext, "@confect/server/MutationTransactionContext", {
11
11
  runQuery: <Query extends Ref.AnyQuery>(query: Query, args: Ref.Args<Query>, options: AdvancedRunQueryOptions) => Effect.Effect<Ref.Returns<Query>, import("effect/Schema").SchemaError | Ref.Error<Query>, never>;
@@ -1 +1 @@
1
- {"version":3,"file":"MutationTransactionContext.d.ts","sourceRoot":"","sources":["../src/MutationTransactionContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,EACV,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAA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;CAAG;AAEpD,eAAO,MAAM,KAAK,QACX,IAAI,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,EAAE,UAAU,GAAG,aAAa,CAAC,0DACpB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"MutationTransactionContext.js","names":[],"sources":["../src/MutationTransactionContext.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport type {\n AdvancedRunQueryOptions,\n GenericDataModel,\n GenericMutationCtx,\n} from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport type { Options as MutationOptions } from \"./QueryTransactionContext\";\n\nexport type { TransactionLimits } from \"convex/server\";\nexport type { Options as MutationOptions } from \"./QueryTransactionContext\";\nexport type QueryOptions = AdvancedRunQueryOptions;\n\nconst make = (\n ctx: Pick<GenericMutationCtx<GenericDataModel>, \"runQuery\" | \"runMutation\">,\n) => ({\n runQuery: Effect.fn(\"MutationTransactionContext.runQuery\")(\n <Query extends Ref.AnyQuery>(\n query: Query,\n args: Ref.Args<Query>,\n options: QueryOptions,\n ) =>\n Ref.runWithCodec(query, args, (ref, encodedArgs) =>\n ctx.runQuery(ref, encodedArgs, options),\n ),\n ),\n runMutation: Effect.fn(\"MutationTransactionContext.runMutation\")(\n <Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n args: Ref.Args<Mutation>,\n options: MutationOptions,\n ) =>\n Ref.runWithCodec(mutation, args, (ref, encodedArgs) =>\n ctx.runMutation(ref, encodedArgs, options),\n ),\n ),\n});\n\nexport class MutationTransactionContext extends Context.Service<\n MutationTransactionContext,\n ReturnType<typeof make>\n>()(\"@confect/server/MutationTransactionContext\") {}\n\nexport const layer = (\n ctx: Pick<GenericMutationCtx<GenericDataModel>, \"runQuery\" | \"runMutation\">,\n) => Layer.succeed(MutationTransactionContext, make(ctx));\n"],"mappings":";;;;;;;;;;AAeA,MAAM,QACJ,SACI;CACJ,UAAU,OAAO,GAAG,qCAAqC,CAAC,EAEtD,OACA,MACA,YAEA,IAAI,aAAa,OAAO,OAAO,KAAK,gBAClC,IAAI,SAAS,KAAK,aAAa,OAAO,CACxC,CACJ;CACA,aAAa,OAAO,GAAG,wCAAwC,CAAC,EAE5D,UACA,MACA,YAEA,IAAI,aAAa,UAAU,OAAO,KAAK,gBACrC,IAAI,YAAY,KAAK,aAAa,OAAO,CAC3C,CACJ;AACF;AAEA,IAAa,6BAAb,cAAgD,QAAQ,QAGtD,CAAC,CAAC,4CAA4C,CAAC,CAAC,CAAC;AAEnD,MAAa,SACX,QACG,MAAM,QAAQ,4BAA4B,KAAK,GAAG,CAAC"}
1
+ {"version":3,"file":"MutationTransactionContext.js","names":[],"sources":["../src/MutationTransactionContext.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport type {\n AdvancedRunQueryOptions,\n GenericDataModel,\n GenericMutationCtx,\n} from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport type { Options as MutationOptions } from \"./QueryTransactionContext.js\";\n\nexport type { TransactionLimits } from \"convex/server\";\nexport type { Options as MutationOptions } from \"./QueryTransactionContext.js\";\nexport type QueryOptions = AdvancedRunQueryOptions;\n\nconst make = (\n ctx: Pick<GenericMutationCtx<GenericDataModel>, \"runQuery\" | \"runMutation\">,\n) => ({\n runQuery: Effect.fn(\"MutationTransactionContext.runQuery\")(\n <Query extends Ref.AnyQuery>(\n query: Query,\n args: Ref.Args<Query>,\n options: QueryOptions,\n ) =>\n Ref.runWithCodec(query, args, (ref, encodedArgs) =>\n ctx.runQuery(ref, encodedArgs, options),\n ),\n ),\n runMutation: Effect.fn(\"MutationTransactionContext.runMutation\")(\n <Mutation extends Ref.AnyMutation>(\n mutation: Mutation,\n args: Ref.Args<Mutation>,\n options: MutationOptions,\n ) =>\n Ref.runWithCodec(mutation, args, (ref, encodedArgs) =>\n ctx.runMutation(ref, encodedArgs, options),\n ),\n ),\n});\n\nexport class MutationTransactionContext extends Context.Service<\n MutationTransactionContext,\n ReturnType<typeof make>\n>()(\"@confect/server/MutationTransactionContext\") {}\n\nexport const layer = (\n ctx: Pick<GenericMutationCtx<GenericDataModel>, \"runQuery\" | \"runMutation\">,\n) => Layer.succeed(MutationTransactionContext, make(ctx));\n"],"mappings":";;;;;;;;;;AAeA,MAAM,QACJ,SACI;CACJ,UAAU,OAAO,GAAG,qCAAqC,CAAC,EAEtD,OACA,MACA,YAEA,IAAI,aAAa,OAAO,OAAO,KAAK,gBAClC,IAAI,SAAS,KAAK,aAAa,OAAO,CACxC,CACJ;CACA,aAAa,OAAO,GAAG,wCAAwC,CAAC,EAE5D,UACA,MACA,YAEA,IAAI,aAAa,UAAU,OAAO,KAAK,gBACrC,IAAI,YAAY,KAAK,aAAa,OAAO,CAC3C,CACJ;AACF;AAEA,IAAa,6BAAb,cAAgD,QAAQ,QAGtD,CAAC,CAAC,4CAA4C,CAAC,CAAC,CAAC;AAEnD,MAAa,SACX,QACG,MAAM,QAAQ,4BAA4B,KAAK,GAAG,CAAC"}
@@ -0,0 +1,50 @@
1
+ import * as Ref from "@confect/core/Ref";
2
+ import type { DefaultFunctionArgs, GenericActionCtx, GenericDataModel, GenericMutationCtx, GenericQueryCtx } from "convex/server";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Schema from "effect/Schema";
5
+ import type * as ActionRunner from "./ActionRunner.js";
6
+ import type * as MutationRunner from "./MutationRunner.js";
7
+ import type * as QueryRunner from "./QueryRunner.js";
8
+ declare const ComponentCallFailed_base: Schema.Class<ComponentCallFailed, Schema.TaggedStruct<"ComponentCallFailed", {
9
+ readonly component: Schema.String;
10
+ readonly method: Schema.String;
11
+ readonly cause: Schema.Defect;
12
+ }>, import("effect/Cause").YieldableError>;
13
+ /**
14
+ * An official component's method rejected. `cause` is the rejection as thrown.
15
+ */
16
+ export declare class ComponentCallFailed extends ComponentCallFailed_base {
17
+ }
18
+ declare const unsupported: unique symbol;
19
+ type Unsupported = typeof unsupported;
20
+ type Needs<Param> = [GenericActionCtx<GenericDataModel>] extends [Param] ? [GenericMutationCtx<GenericDataModel>] extends [Param] ? [GenericQueryCtx<GenericDataModel>] extends [Param] ? QueryRunner.QueryRunner : MutationRunner.MutationRunner : [GenericQueryCtx<GenericDataModel>] extends [Param] ? Unsupported : ActionRunner.ActionRunner : Unsupported;
21
+ type Method<Official> = {
22
+ [K in keyof Official & string]: Official[K] extends (ctx: infer Ctx, ...args: never[]) => Promise<unknown> ? Needs<Ctx> extends Unsupported ? never : K : never;
23
+ }[keyof Official & string];
24
+ type Call<F> = F extends (ctx: infer Ctx, ...args: infer Args) => Promise<infer A> ? (...args: Args) => Effect.Effect<A, never, Needs<Ctx>> : never;
25
+ type Lifted<Official> = <M extends Method<Official>>(method: M, ...args: Parameters<Call<Official[M]>>) => ReturnType<Call<Official[M]>>;
26
+ /**
27
+ * Lift official promise methods, deriving each capability from its ctx
28
+ * parameter. A rejection is caller misuse, a limit or a platform fault rather
29
+ * than a domain fact, so it dies.
30
+ */
31
+ export declare const make: <Official extends object>(component: string, official: Official) => Lifted<Official>;
32
+ /**
33
+ * A function reference with its encoded arguments, ready for an official method
34
+ * that takes both.
35
+ */
36
+ export interface Fn<R extends Ref.Any> {
37
+ readonly reference: Ref.FunctionReference<R>;
38
+ readonly args: DefaultFunctionArgs;
39
+ }
40
+ /**
41
+ * Encode a ref's arguments through its codecs to the wire record an official
42
+ * method expects.
43
+ */
44
+ export declare const encodeCall: <R extends Ref.Any>(ref: R, args: NoInfer<Ref.Args<R>>) => Effect.Effect<Fn<R>>;
45
+ /**
46
+ * Encode a callback's real field without fabricating the rest of its arguments.
47
+ */
48
+ export declare const encodeField: <R extends Ref.AnyConfect, K extends keyof Ref.Args<R> & keyof Ref.ArgsFields<R>>(ref: R, key: K, value: NoInfer<Ref.Args<R>[K]>) => Effect.Effect<unknown>;
49
+ export {};
50
+ //# sourceMappingURL=OfficialComponent.d.ts.map
@@ -0,0 +1 @@
1
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nB,CAAC;AAEJ;;GAEG;AACH,eAAO,MAAM,WAAW,GACtB,CAAC,SAAS,GAAG,CAAC,UAAU,EACxB,CAAC,SAAS,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,OAEhD,CAAC,OACD,CAAC,SACC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAC7B,MAAM,CAAC,MAAM,CAAC,OAAO,CAMvB,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { ActionCtx } from "./ActionCtx.js";
3
+ import { MutationCtx } from "./MutationCtx.js";
4
+ import { QueryCtx } from "./QueryCtx.js";
5
+ import * as Ref from "@confect/core/Ref";
6
+ import * as Effect from "effect/Effect";
7
+ import * as Schema from "effect/Schema";
8
+ import * as Option from "effect/Option";
9
+ //#region src/OfficialComponent.ts
10
+ var OfficialComponent_exports = /* @__PURE__ */ __exportAll({
11
+ ComponentCallFailed: () => ComponentCallFailed,
12
+ encodeCall: () => encodeCall,
13
+ encodeField: () => encodeField,
14
+ make: () => make
15
+ });
16
+ /**
17
+ * An official component's method rejected. `cause` is the rejection as thrown.
18
+ */
19
+ var ComponentCallFailed = class extends Schema.TaggedError()("ComponentCallFailed", {
20
+ component: Schema.String,
21
+ method: Schema.String,
22
+ cause: Schema.Defect()
23
+ }) {};
24
+ /**
25
+ * Lift official promise methods, deriving each capability from its ctx
26
+ * parameter. A rejection is caller misuse, a limit or a platform fault rather
27
+ * than a domain fact, so it dies.
28
+ */
29
+ const make = (component, official) => {
30
+ const context = Effect.gen(function* () {
31
+ const action = yield* Effect.serviceOption(ActionCtx());
32
+ if (Option.isSome(action)) return action.value;
33
+ const mutation = yield* Effect.serviceOption(MutationCtx());
34
+ if (Option.isSome(mutation)) return mutation.value;
35
+ const query = yield* Effect.serviceOption(QueryCtx());
36
+ if (Option.isSome(query)) return query.value;
37
+ return yield* Effect.die(/* @__PURE__ */ new Error(`${component} called outside a Confect handler`));
38
+ });
39
+ return Effect.fn(`${component}.call`)(function* (method, ...args) {
40
+ const ctx = yield* context;
41
+ const invoke = official[method];
42
+ return yield* Effect.tryPromise({
43
+ try: () => invoke.call(official, ctx, ...args),
44
+ catch: (cause) => ComponentCallFailed.make({
45
+ component,
46
+ method,
47
+ cause
48
+ })
49
+ }).pipe(Effect.orDie);
50
+ });
51
+ };
52
+ /**
53
+ * Encode a ref's arguments through its codecs to the wire record an official
54
+ * method expects.
55
+ */
56
+ const encodeCall = (ref, args) => Ref.encodeArgs(ref, args).pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown))), Effect.map((encoded) => ({
57
+ reference: Ref.getFunctionReference(ref),
58
+ args: encoded
59
+ })), Effect.orDie);
60
+ /**
61
+ * Encode a callback's real field without fabricating the rest of its arguments.
62
+ */
63
+ const encodeField = (ref, key, value) => {
64
+ const fields = ref.args.fields;
65
+ return Schema.encodeUnknownEffect(fields[key])(value).pipe(Effect.orDie);
66
+ };
67
+ //#endregion
68
+ export { ComponentCallFailed, OfficialComponent_exports, encodeCall, encodeField, make };
69
+
70
+ //# sourceMappingURL=OfficialComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OfficialComponent.js","names":["ActionCtx.ActionCtx","MutationCtx.MutationCtx","QueryCtx.QueryCtx"],"sources":["../src/OfficialComponent.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport type {\n DefaultFunctionArgs,\n GenericActionCtx,\n GenericDataModel,\n GenericMutationCtx,\n GenericQueryCtx,\n} from \"convex/server\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport * as ActionCtx from \"./ActionCtx.js\";\nimport type * as ActionRunner from \"./ActionRunner.js\";\nimport * as MutationCtx from \"./MutationCtx.js\";\nimport type * as MutationRunner from \"./MutationRunner.js\";\nimport * as QueryCtx from \"./QueryCtx.js\";\nimport type * as QueryRunner from \"./QueryRunner.js\";\n\n/**\n * An official component's method rejected. `cause` is the rejection as thrown.\n */\nexport class ComponentCallFailed extends Schema.TaggedError<ComponentCallFailed>()(\n \"ComponentCallFailed\",\n { component: Schema.String, method: Schema.String, cause: Schema.Defect() },\n) {}\n\ndeclare const unsupported: unique symbol;\ntype Unsupported = typeof unsupported;\ntype Needs<Param> = [GenericActionCtx<GenericDataModel>] extends [Param]\n ? [GenericMutationCtx<GenericDataModel>] extends [Param]\n ? [GenericQueryCtx<GenericDataModel>] extends [Param]\n ? QueryRunner.QueryRunner\n : MutationRunner.MutationRunner\n : [GenericQueryCtx<GenericDataModel>] extends [Param]\n ? Unsupported\n : ActionRunner.ActionRunner\n : Unsupported;\n\ntype Method<Official> = {\n [K in keyof Official & string]: Official[K] extends (\n ctx: infer Ctx,\n ...args: never[]\n ) => Promise<unknown>\n ? Needs<Ctx> extends Unsupported\n ? never\n : K\n : never;\n}[keyof Official & string];\n\ntype Call<F> = F extends (\n ctx: infer Ctx,\n ...args: infer Args\n) => Promise<infer A>\n ? (...args: Args) => Effect.Effect<A, never, Needs<Ctx>>\n : never;\n\ntype Lifted<Official> = <M extends Method<Official>>(\n method: M,\n ...args: Parameters<Call<Official[M]>>\n) => ReturnType<Call<Official[M]>>;\n\n/**\n * Lift official promise methods, deriving each capability from its ctx\n * parameter. A rejection is caller misuse, a limit or a platform fault rather\n * than a domain fact, so it dies.\n */\nexport const make = <Official extends object>(\n component: string,\n official: Official,\n): Lifted<Official> => {\n const context = Effect.gen(function* () {\n const action = yield* Effect.serviceOption(\n ActionCtx.ActionCtx<GenericDataModel>(),\n );\n if (Option.isSome(action)) return action.value;\n const mutation = yield* Effect.serviceOption(\n MutationCtx.MutationCtx<GenericDataModel>(),\n );\n if (Option.isSome(mutation)) return mutation.value;\n const query = yield* Effect.serviceOption(\n QueryCtx.QueryCtx<GenericDataModel>(),\n );\n if (Option.isSome(query)) return query.value;\n return yield* Effect.die(\n new Error(`${component} called outside a Confect handler`),\n );\n });\n const call = Effect.fn(`${component}.call`)(function* (\n method: Method<Official>,\n ...args: unknown[]\n ) {\n const ctx = yield* context;\n // Method selects promise methods whose first argument accepts a native handler context.\n const invoke = official[method] as (\n native: typeof ctx,\n ...args: unknown[]\n ) => Promise<unknown>;\n return yield* Effect.tryPromise({\n try: () => invoke.call(official, ctx, ...args),\n catch: (cause) => ComponentCallFailed.make({ component, method, cause }),\n }).pipe(Effect.orDie);\n });\n // Confect installs the native ctx with the runner capability inferred by Needs.\n return call as unknown as Lifted<Official>;\n};\n\n/**\n * A function reference with its encoded arguments, ready for an official method\n * that takes both.\n */\nexport interface Fn<R extends Ref.Any> {\n readonly reference: Ref.FunctionReference<R>;\n readonly args: DefaultFunctionArgs;\n}\n\n/**\n * Encode a ref's arguments through its codecs to the wire record an official\n * method expects.\n */\nexport const encodeCall = <R extends Ref.Any>(\n ref: R,\n args: NoInfer<Ref.Args<R>>,\n): Effect.Effect<Fn<R>> =>\n Ref.encodeArgs(ref, args).pipe(\n Effect.flatMap(\n Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown)),\n ),\n Effect.map((encoded) => ({\n reference: Ref.getFunctionReference(ref),\n args: encoded,\n })),\n Effect.orDie,\n );\n\n/**\n * Encode a callback's real field without fabricating the rest of its arguments.\n */\nexport const encodeField = <\n R extends Ref.AnyConfect,\n K extends keyof Ref.Args<R> & keyof Ref.ArgsFields<R>,\n>(\n ref: R,\n key: K,\n value: NoInfer<Ref.Args<R>[K]>,\n): Effect.Effect<unknown> => {\n const fields = ref.args.fields as Record<\n keyof Ref.ArgsFields<R>,\n Schema.Codec<unknown, unknown>\n >;\n return Schema.encodeUnknownEffect(fields[key])(value).pipe(Effect.orDie);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqBA,IAAa,sBAAb,cAAyC,OAAO,YAAiC,CAAC,CAChF,uBACA;CAAE,WAAW,OAA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KAAK,CAAC,CAAC,KAAK,OAAO,KAAK;AACzE"}
@@ -3,10 +3,10 @@ import type { ExpressionOrValue, FilterBuilder, OrderedQuery as ConvexOrderedQue
3
3
  import type { Option } from "effect";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as Stream from "effect/Stream";
6
- import type * as DatabaseSchema from "./DatabaseSchema";
7
- import * as Document from "./Document";
8
- import type * as TableInfo from "./TableInfo";
9
- import type * as Table from "./Table";
6
+ import type * as DatabaseSchema from "./DatabaseSchema.js";
7
+ import * as Document from "./Document.js";
8
+ import type * as TableInfo from "./TableInfo.js";
9
+ import type * as Table from "./Table.js";
10
10
  type NativePaginate<TableInfo_ extends TableInfo.AnyWithProps, Doc> = (options: PaginationOptions, filter?: (q: FilterBuilder<TableInfo.ConvexTableInfo<TableInfo_>>) => ExpressionOrValue<boolean>) => Effect.Effect<PaginationResult<Doc>, Document.DocumentDecodeError>;
11
11
  export type OrderedQuery<TableInfo_ extends TableInfo.AnyWithProps, Doc = TableInfo_["document"], TargetKind extends DatabaseSchema.Target["kind"] = "app"> = {
12
12
  readonly first: () => Effect.Effect<Option.Option<Doc>, Document.DocumentDecodeError>;
@@ -1 +1 @@
1
- {"version":3,"file":"OrderedQuery.d.ts","sourceRoot":"","sources":["../src/OrderedQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EACV,iBAAiB,EACjB,aAAa,EACb,YAAY,IAAI,kBAAkB,EAClC,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,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ACH,QAAQ,CAAC,QAAQ,EAAE;QACjB,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAC9C,QAAQ,CAAC,SAAS,EAAE;YAClB,QAAQ,CAAC,6FAA6F,EAAE,KAAK,CAAC;SAC/G,CAAC;KACH,CAAC,UAAU,CAAC,CAAC;CACf,CAAC;AAEF,wBAAgB,IAAI,CAAC,MAAM,SAAS,KAAK,CAAC,YAAY,EACpD,KAAK,EAAE,kBAAkB,CACvB,SAAS,CAAC,eAAe,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CACvD,EACD,KAAK,EAAE,MAAM,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAA;CAAE,GAC9C,YAAY,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7C,wBAAgB,IAAI,CAAC,MAAM,SAAS,KAAK,CAAC,YAAY,EACpD,KAAK,EAAE,kBAAkB,CACvB,SAAS,CAAC,eAAe,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CACvD,EACD,KAAK,EAAE,MAAM,GACZ,YAAY,CACb,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,EAC3B,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,EACvC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,OAAO,CAAC,GAAG,GAAG,KAAK,GAAG,WAAW,CAC9D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"OrderedQuery.js","names":["Document.decode"],"sources":["../src/OrderedQuery.ts"],"sourcesContent":["import type * as IdScope from \"@confect/core/IdScope\";\nimport type {\n ExpressionOrValue,\n FilterBuilder,\n OrderedQuery as ConvexOrderedQuery,\n PaginationOptions,\n PaginationResult,\n} from \"convex/server\";\nimport { identity, pipe } from \"effect/Function\";\nimport type { Option } from \"effect\";\nimport * as Effect from \"effect/Effect\";\nimport * as Stream from \"effect/Stream\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport * as Document from \"./Document\";\nimport type * as TableInfo from \"./TableInfo\";\nimport type * as Table from \"./Table\";\n\ntype NativePaginate<TableInfo_ extends TableInfo.AnyWithProps, Doc> = (\n options: PaginationOptions,\n filter?: (\n q: FilterBuilder<TableInfo.ConvexTableInfo<TableInfo_>>,\n ) => ExpressionOrValue<boolean>,\n) => Effect.Effect<PaginationResult<Doc>, Document.DocumentDecodeError>;\n\nexport type OrderedQuery<\n TableInfo_ extends TableInfo.AnyWithProps,\n Doc = TableInfo_[\"document\"],\n TargetKind extends DatabaseSchema.Target[\"kind\"] = \"app\",\n> = {\n readonly first: () => Effect.Effect<\n Option.Option<Doc>,\n Document.DocumentDecodeError\n >;\n readonly take: (\n n: number,\n ) => Effect.Effect<ReadonlyArray<Doc>, Document.DocumentDecodeError>;\n readonly collect: () => Effect.Effect<\n ReadonlyArray<Doc>,\n Document.DocumentDecodeError\n >;\n readonly stream: () => Stream.Stream<Doc, Document.DocumentDecodeError>;\n /**\n * Native pagination is application-only. Use `QueryStream.paginate` for\n * component index queries.\n */\n readonly paginate: {\n readonly app: NativePaginate<TableInfo_, Doc>;\n readonly component: {\n readonly \"Native pagination is unavailable in components. Use QueryStream.paginate for index queries.\": never;\n };\n }[TargetKind];\n};\n\nexport function make<Table_ extends Table.AnyWithProps>(\n query: ConvexOrderedQuery<\n TableInfo.ConvexTableInfo<TableInfo.TableInfo<Table_>>\n >,\n table: Table_ & { readonly scope: IdScope.App },\n): OrderedQuery<TableInfo.TableInfo<Table_>>;\nexport function make<Table_ extends Table.AnyWithProps>(\n query: ConvexOrderedQuery<\n TableInfo.ConvexTableInfo<TableInfo.TableInfo<Table_>>\n >,\n table: Table_,\n): OrderedQuery<\n TableInfo.TableInfo<Table_>,\n TableInfo.TableInfo<Table_>[\"document\"],\n Table.Scope<Table_> extends IdScope.App ? \"app\" : \"component\"\n>;\nexport function make<Table_ extends Table.AnyWithProps>(\n query: ConvexOrderedQuery<\n TableInfo.ConvexTableInfo<TableInfo.TableInfo<Table_>>\n >,\n table: Table_,\n): OrderedQuery<\n TableInfo.TableInfo<Table_>,\n TableInfo.TableInfo<Table_>[\"document\"],\n DatabaseSchema.Target[\"kind\"]\n> {\n type TableInfo_ = TableInfo.TableInfo<Table_>;\n type OrderedQueryFunction<\n FunctionName extends keyof OrderedQuery<TableInfo_>,\n > = OrderedQuery<TableInfo_>[FunctionName];\n\n const streamEncoded = Stream.fromAsyncIterable(query, identity).pipe(\n Stream.orDie,\n );\n\n const stream: OrderedQueryFunction<\"stream\"> = () =>\n pipe(streamEncoded, Stream.mapEffect(Document.decode(table)));\n\n const first: OrderedQueryFunction<\"first\"> = () =>\n pipe(stream(), Stream.take(1), Stream.runHead);\n\n const take: OrderedQueryFunction<\"take\"> = (n: number) =>\n pipe(stream(), Stream.take(n), Stream.runCollect);\n\n const collect: OrderedQueryFunction<\"collect\"> = () =>\n pipe(stream(), Stream.runCollect);\n\n const paginate: NativePaginate<TableInfo_, TableInfo_[\"document\"]> =\n Effect.fn(\"OrderedQuery.paginate\")(function* (options, filter) {\n const filteredQuery = filter !== undefined ? query.filter(filter) : query;\n\n const paginationResult = yield* Effect.promise(() =>\n filteredQuery.paginate(options),\n );\n\n const parsedPage = yield* Effect.forEach(\n paginationResult.page,\n Document.decode(table),\n );\n\n return {\n page: parsedPage,\n isDone: paginationResult.isDone,\n continueCursor: paginationResult.continueCursor,\n /* v8 ignore start */\n ...(paginationResult.splitCursor\n ? { splitCursor: paginationResult.splitCursor }\n : {}),\n ...(paginationResult.pageStatus\n ? { pageStatus: paginationResult.pageStatus }\n : {}),\n /* v8 ignore stop */\n };\n });\n\n return {\n first,\n take,\n collect,\n paginate,\n stream,\n };\n}\n"],"mappings":";;;;;;;AAqEA,SAAgB,KACd,OAGA,OAKA;CAMA,MAAM,gBAAgB,OAAO,kBAAkB,OAAO,QAAQ,CAAC,CAAC,KAC9D,OAAO,KACT;CAEA,MAAM,eACJ,KAAK,eAAe,OAAO,UAAUA,OAAgB,KAAK,CAAC,CAAC;CAE9D,MAAM,cACJ,KAAK,OAAO,GAAG,OAAO,KAAK,CAAC,GAAG,OAAO,OAAO;CAE/C,MAAM,QAAsC,MAC1C,KAAK,OAAO,GAAG,OAAO,KAAK,CAAC,GAAG,OAAO,UAAU;CAElD,MAAM,gBACJ,KAAK,OAAO,GAAG,OAAO,UAAU;CA8BlC,OAAO;EACL;EACA;EACA;EACA,UA/BA,OAAO,GAAG,uBAAuB,CAAC,CAAC,WAAW,SAAS,QAAQ;GAC7D,MAAM,gBAAgB,WAAW,KAAA,IAAY,MAAM,OAAO,MAAM,IAAI;GAEpE,MAAM,mBAAmB,OAAO,OAAO,cACrC,cAAc,SAAS,OAAO,CAChC;GAOA,OAAO;IACL,MAAM,OANkB,OAAO,QAC/B,iBAAiB,MACjBA,OAAgB,KAAK,CACvB;IAIE,QAAQ,iBAAiB;IACzB,gBAAgB,iBAAiB;;IAEjC,GAAI,iBAAiB,cACjB,EAAE,aAAa,iBAAiB,YAAY,IAC5C,CAAC;IACL,GAAI,iBAAiB,aACjB,EAAE,YAAY,iBAAiB,WAAW,IAC1C,CAAC;GAEP;EACF,CAMO;EACP;CACF;AACF"}
1
+ {"version":3,"file":"OrderedQuery.js","names":["Document.decode"],"sources":["../src/OrderedQuery.ts"],"sourcesContent":["import type * as IdScope from \"@confect/core/IdScope\";\nimport type {\n ExpressionOrValue,\n FilterBuilder,\n OrderedQuery as ConvexOrderedQuery,\n PaginationOptions,\n PaginationResult,\n} from \"convex/server\";\nimport { identity, pipe } from \"effect/Function\";\nimport type { Option } from \"effect\";\nimport * as Effect from \"effect/Effect\";\nimport * as Stream from \"effect/Stream\";\nimport type * as DatabaseSchema from \"./DatabaseSchema.js\";\nimport * as Document from \"./Document.js\";\nimport type * as TableInfo from \"./TableInfo.js\";\nimport type * as Table from \"./Table.js\";\n\ntype NativePaginate<TableInfo_ extends TableInfo.AnyWithProps, Doc> = (\n options: PaginationOptions,\n filter?: (\n q: FilterBuilder<TableInfo.ConvexTableInfo<TableInfo_>>,\n ) => ExpressionOrValue<boolean>,\n) => Effect.Effect<PaginationResult<Doc>, Document.DocumentDecodeError>;\n\nexport type OrderedQuery<\n TableInfo_ extends TableInfo.AnyWithProps,\n Doc = TableInfo_[\"document\"],\n TargetKind extends DatabaseSchema.Target[\"kind\"] = \"app\",\n> = {\n readonly first: () => Effect.Effect<\n Option.Option<Doc>,\n Document.DocumentDecodeError\n >;\n readonly take: (\n n: number,\n ) => Effect.Effect<ReadonlyArray<Doc>, Document.DocumentDecodeError>;\n readonly collect: () => Effect.Effect<\n ReadonlyArray<Doc>,\n Document.DocumentDecodeError\n >;\n readonly stream: () => Stream.Stream<Doc, Document.DocumentDecodeError>;\n /**\n * Native pagination is application-only. Use `QueryStream.paginate` for\n * component index queries.\n */\n readonly paginate: {\n readonly app: NativePaginate<TableInfo_, Doc>;\n readonly component: {\n readonly \"Native pagination is unavailable in components. Use QueryStream.paginate for index queries.\": never;\n };\n }[TargetKind];\n};\n\nexport function make<Table_ extends Table.AnyWithProps>(\n query: ConvexOrderedQuery<\n TableInfo.ConvexTableInfo<TableInfo.TableInfo<Table_>>\n >,\n table: Table_ & { readonly scope: IdScope.App },\n): OrderedQuery<TableInfo.TableInfo<Table_>>;\nexport function make<Table_ extends Table.AnyWithProps>(\n query: ConvexOrderedQuery<\n TableInfo.ConvexTableInfo<TableInfo.TableInfo<Table_>>\n >,\n table: Table_,\n): OrderedQuery<\n TableInfo.TableInfo<Table_>,\n TableInfo.TableInfo<Table_>[\"document\"],\n Table.Scope<Table_> extends IdScope.App ? \"app\" : \"component\"\n>;\nexport function make<Table_ extends Table.AnyWithProps>(\n query: ConvexOrderedQuery<\n TableInfo.ConvexTableInfo<TableInfo.TableInfo<Table_>>\n >,\n table: Table_,\n): OrderedQuery<\n TableInfo.TableInfo<Table_>,\n TableInfo.TableInfo<Table_>[\"document\"],\n DatabaseSchema.Target[\"kind\"]\n> {\n type TableInfo_ = TableInfo.TableInfo<Table_>;\n type OrderedQueryFunction<\n FunctionName extends keyof OrderedQuery<TableInfo_>,\n > = OrderedQuery<TableInfo_>[FunctionName];\n\n const streamEncoded = Stream.fromAsyncIterable(query, identity).pipe(\n Stream.orDie,\n );\n\n const stream: OrderedQueryFunction<\"stream\"> = () =>\n pipe(streamEncoded, Stream.mapEffect(Document.decode(table)));\n\n const first: OrderedQueryFunction<\"first\"> = () =>\n pipe(stream(), Stream.take(1), Stream.runHead);\n\n const take: OrderedQueryFunction<\"take\"> = (n: number) =>\n pipe(stream(), Stream.take(n), Stream.runCollect);\n\n const collect: OrderedQueryFunction<\"collect\"> = () =>\n pipe(stream(), Stream.runCollect);\n\n const paginate: NativePaginate<TableInfo_, TableInfo_[\"document\"]> =\n Effect.fn(\"OrderedQuery.paginate\")(function* (options, filter) {\n const filteredQuery = filter !== undefined ? query.filter(filter) : query;\n\n const paginationResult = yield* Effect.promise(() =>\n filteredQuery.paginate(options),\n );\n\n const parsedPage = yield* Effect.forEach(\n paginationResult.page,\n Document.decode(table),\n );\n\n return {\n page: parsedPage,\n isDone: paginationResult.isDone,\n continueCursor: paginationResult.continueCursor,\n /* v8 ignore start */\n ...(paginationResult.splitCursor\n ? { splitCursor: paginationResult.splitCursor }\n : {}),\n ...(paginationResult.pageStatus\n ? { pageStatus: paginationResult.pageStatus }\n : {}),\n /* v8 ignore stop */\n };\n });\n\n return {\n first,\n take,\n collect,\n paginate,\n stream,\n };\n}\n"],"mappings":";;;;;;;AAqEA,SAAgB,KACd,OAGA,OAKA;CAMA,MAAM,gBAAgB,OAAO,kBAAkB,OAAO,QAAQ,CAAC,CAAC,KAC9D,OAAO,KACT;CAEA,MAAM,eACJ,KAAK,eAAe,OAAO,UAAUA,OAAgB,KAAK,CAAC,CAAC;CAE9D,MAAM,cACJ,KAAK,OAAO,GAAG,OAAO,KAAK,CAAC,GAAG,OAAO,OAAO;CAE/C,MAAM,QAAsC,MAC1C,KAAK,OAAO,GAAG,OAAO,KAAK,CAAC,GAAG,OAAO,UAAU;CAElD,MAAM,gBACJ,KAAK,OAAO,GAAG,OAAO,UAAU;CA8BlC,OAAO;EACL;EACA;EACA;EACA,UA/BA,OAAO,GAAG,uBAAuB,CAAC,CAAC,WAAW,SAAS,QAAQ;GAC7D,MAAM,gBAAgB,WAAW,KAAA,IAAY,MAAM,OAAO,MAAM,IAAI;GAEpE,MAAM,mBAAmB,OAAO,OAAO,cACrC,cAAc,SAAS,OAAO,CAChC;GAOA,OAAO;IACL,MAAM,OANkB,OAAO,QAC/B,iBAAiB,MACjBA,OAAgB,KAAK,CACvB;IAIE,QAAQ,iBAAiB;IACzB,gBAAgB,iBAAiB;;IAEjC,GAAI,iBAAiB,cACjB,EAAE,aAAa,iBAAiB,YAAY,IAC5C,CAAC;IACL,GAAI,iBAAiB,aACjB,EAAE,YAAY,iBAAiB,WAAW,IAC1C,CAAC;GAEP;EACF,CAMO;EACP;CACF;AACF"}
@@ -1,7 +1,7 @@
1
1
  import type * as IdScope from "@confect/core/IdScope";
2
2
  import type { GenericDataModel, GenericQueryCtx } from "convex/server";
3
3
  import * as Context from "effect/Context";
4
- import type * as ComponentCtx from "./ComponentCtx";
4
+ import type * as ComponentCtx from "./ComponentCtx.js";
5
5
  import * as Layer from "effect/Layer";
6
6
  export type QueryCtxTag<DataModel extends GenericDataModel, Scope extends IdScope.IdScope = IdScope.App> = Context.Service<QueryCtx<DataModel, Scope>, Scope extends IdScope.App ? GenericQueryCtx<DataModel> : ComponentCtx.Query<DataModel, Scope>>;
7
7
  export declare const QueryCtx: <DataModel extends GenericDataModel, Scope extends IdScope.IdScope = IdScope.App>() => QueryCtxTag<DataModel, Scope>;
@@ -1 +1 @@
1
- {"version":3,"file":"QueryCtx.d.ts","sourceRoot":"","sources":["../src/QueryCtx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK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,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,KAAK,YAAY,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,MAAM,MAAM,WAAW,CACrB,SAAS,SAAS,gBAAgB,EAClC,KAAK,SAAS,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,IACzC,OAAO,CAAC,OAAO,CACjB,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,EAC1B,KAAK,SAAS,OAAO,CAAC,GAAG,GACrB,eAAe,CAAC,SAAS,CAAC,GAC1B,YAAY,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CACzC,CAAC;AAEF,eAAO,MAAM,QAAQ,GACnB,SAAS,SAAS,gBAAgB,EAClC,KAAK,SAAS,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,OACxC,WAAW,CAAC,SAAS,EAAE,KAAK,CACY,CAAC;AAE9C,MAAM,MAAM,QAAQ,CAClB,SAAS,SAAS,gBAAgB,EAClC,KAAK,SAAS,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,IACzC,KAAK,SAAS,OAAO,CAAC,GAAG,GACzB,eAAe,CAAC,SAAS,CAAC,GAC1B,YAAY,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;AAEvD,eAAO,MAAM,KAAK,GAChB,SAAS,SAAS,gBAAgB,EAClC,KAAK,SAAS,OAAO,CAAC,OAAO,OAExB,eAAe,CAAC,SAAS,CAAC,SACxB,KAAK,0DAUb,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"QueryCtx.js","names":[],"sources":["../src/QueryCtx.ts"],"sourcesContent":["import type * as IdScope from \"@confect/core/IdScope\";\nimport type { GenericDataModel, GenericQueryCtx } from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport type * as ComponentCtx from \"./ComponentCtx\";\nimport * as Layer from \"effect/Layer\";\n\nexport type QueryCtxTag<\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n> = Context.Service<\n QueryCtx<DataModel, Scope>,\n Scope extends IdScope.App\n ? GenericQueryCtx<DataModel>\n : ComponentCtx.Query<DataModel, Scope>\n>;\n\nexport const QueryCtx = <\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n>(): QueryCtxTag<DataModel, Scope> =>\n Context.Service(\"@confect/server/QueryCtx\");\n\nexport type QueryCtx<\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n> = Scope extends IdScope.App\n ? GenericQueryCtx<DataModel>\n : ComponentCtx.Identifier<\"query\", DataModel, Scope>;\n\nexport const layer = <\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope,\n>(\n ctx: GenericQueryCtx<DataModel>,\n scope: Scope,\n) => {\n const tag = QueryCtx<DataModel, Scope>();\n const { auth: _auth, ...componentCtx } = ctx;\n return Layer.succeed(\n tag,\n (scope === \"\" ? ctx : componentCtx) as unknown as Context.Service.Shape<\n typeof tag\n >,\n );\n};\n"],"mappings":";;;;;;;;AAgBA,MAAa,iBAIX,QAAQ,QAAQ,0BAA0B;AAS5C,MAAa,SAIX,KACA,UACG;CACH,MAAM,MAAM,SAA2B;CACvC,MAAM,EAAE,MAAM,OAAO,GAAG,iBAAiB;CACzC,OAAO,MAAM,QACX,KACC,UAAU,KAAK,MAAM,YAGxB;AACF"}
1
+ {"version":3,"file":"QueryCtx.js","names":[],"sources":["../src/QueryCtx.ts"],"sourcesContent":["import type * as IdScope from \"@confect/core/IdScope\";\nimport type { GenericDataModel, GenericQueryCtx } from \"convex/server\";\nimport * as Context from \"effect/Context\";\nimport type * as ComponentCtx from \"./ComponentCtx.js\";\nimport * as Layer from \"effect/Layer\";\n\nexport type QueryCtxTag<\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n> = Context.Service<\n QueryCtx<DataModel, Scope>,\n Scope extends IdScope.App\n ? GenericQueryCtx<DataModel>\n : ComponentCtx.Query<DataModel, Scope>\n>;\n\nexport const QueryCtx = <\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n>(): QueryCtxTag<DataModel, Scope> =>\n Context.Service(\"@confect/server/QueryCtx\");\n\nexport type QueryCtx<\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope = IdScope.App,\n> = Scope extends IdScope.App\n ? GenericQueryCtx<DataModel>\n : ComponentCtx.Identifier<\"query\", DataModel, Scope>;\n\nexport const layer = <\n DataModel extends GenericDataModel,\n Scope extends IdScope.IdScope,\n>(\n ctx: GenericQueryCtx<DataModel>,\n scope: Scope,\n) => {\n const tag = QueryCtx<DataModel, Scope>();\n const { auth: _auth, ...componentCtx } = ctx;\n return Layer.succeed(\n tag,\n (scope === \"\" ? ctx : componentCtx) as unknown as Context.Service.Shape<\n typeof tag\n >,\n );\n};\n"],"mappings":";;;;;;;;AAgBA,MAAa,iBAIX,QAAQ,QAAQ,0BAA0B;AAS5C,MAAa,SAIX,KACA,UACG;CACH,MAAM,MAAM,SAA2B;CACvC,MAAM,EAAE,MAAM,OAAO,GAAG,iBAAiB;CACzC,OAAO,MAAM,QACX,KACC,UAAU,KAAK,MAAM,YAGxB;AACF"}
@@ -4,15 +4,15 @@ import type { GenericId } from "convex/values";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as Schema from "effect/Schema";
6
6
  import type { BaseDatabaseReader, IndexFieldTypesForEq } from "@confect/core/Types";
7
- import type * as DataModel from "./DataModel";
8
- import type * as DatabaseSchema from "./DatabaseSchema";
9
- import * as Document from "./Document";
10
- import * as OrderedQuery from "./OrderedQuery";
11
- import * as QueryStream from "./QueryStream";
12
- import type * as QueryStreamKeyLabels from "./QueryStreamKeyLabels";
13
- import * as QueryStreamIndexRange from "./QueryStreamIndexRange";
14
- import type { QueryStreamOrderDirection as OrderDirection } from "./QueryStreamOrderDirection";
15
- import type * as Table from "./Table";
7
+ import type * as DataModel from "./DataModel.js";
8
+ import type * as DatabaseSchema from "./DatabaseSchema.js";
9
+ import * as Document from "./Document.js";
10
+ import * as OrderedQuery from "./OrderedQuery.js";
11
+ import * as QueryStream from "./QueryStream.js";
12
+ import type * as QueryStreamKeyLabels from "./QueryStreamKeyLabels.js";
13
+ import * as QueryStreamIndexRange from "./QueryStreamIndexRange.js";
14
+ import type { QueryStreamOrderDirection as OrderDirection } from "./QueryStreamOrderDirection.js";
15
+ import type * as Table from "./Table.js";
16
16
  type ConvexTableInfoFor<DataModel_ extends DataModel.AnyWithProps, TableName extends DataModel.TableNames<DataModel_>> = DataModel.TableInfoWithName<DataModel_, TableName>;
17
17
  type TableInfoFor<DataModel_ extends DataModel.AnyWithProps, TableName extends DataModel.TableNames<DataModel_>> = DataModel.TableInfoWithName_<DataModel_, TableName>;
18
18
  export interface QueryInitializer<DataModel_ extends DataModel.AnyWithProps, TableName extends DataModel.TableNames<DataModel_>, Doc = DataModel.DocumentWithName<DataModel_, TableName>, TargetKind extends DatabaseSchema.Target["kind"] = "app"> {
@@ -55,7 +55,7 @@ export declare function make<Tables extends Table.AnyWithProps, TableName extend
55
55
  readonly scope: IdScope.App;
56
56
  }): QueryInitializer<DataModel.FromTables<Tables>, TableName>;
57
57
  export declare function make<Tables extends Table.AnyWithProps, TableName extends Table.Name<Tables>>(convexDatabaseReader: BaseDatabaseReader<DataModel.ToConvex<DataModel.FromTables<Tables>>>, table: Table.WithName<Tables, TableName>): QueryInitializer<DataModel.FromTables<Tables>, TableName, DataModel.DocumentWithName<DataModel.FromTables<Tables>, TableName>, Table.Scope<Table.WithName<Tables, TableName>> extends IdScope.App ? "app" : "component">;
58
- export declare const getById: <Tables extends Table.AnyWithProps, TableName extends Table.Name<Tables>>(convexDatabaseReader: BaseDatabaseReader<DataModel.ToConvex<DataModel.FromTables<Tables>>>, table: Table.WithName<Tables, TableName>) => (id: GenericId<TableName>) => Effect.Effect<import("./TableInfo").TableInfo<Table.WithName<Tables, TableName>>["document"], Document.DocumentDecodeError | GetByIdFailure, never>;
58
+ export declare const getById: <Tables extends Table.AnyWithProps, TableName extends Table.Name<Tables>>(convexDatabaseReader: BaseDatabaseReader<DataModel.ToConvex<DataModel.FromTables<Tables>>>, table: Table.WithName<Tables, TableName>) => (id: GenericId<TableName>) => Effect.Effect<import("./TableInfo.js").TableInfo<Table.WithName<Tables, TableName>>["document"], Document.DocumentDecodeError | GetByIdFailure, never>;
59
59
  declare const GetByIdFailure_base: Schema.Class<GetByIdFailure, Schema.TaggedStruct<"GetByIdFailure", {
60
60
  readonly id: Schema.String;
61
61
  readonly tableName: Schema.String;
@@ -1 +1 @@
1
- {"version":3,"file":"QueryInitializer.d.ts","sourceRoot":"","sources":["../src/QueryInitializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAGV,cAAc,EAEd,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,gBAAgB,EAGhB,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAKxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AACpE,OAAO,KAAK,qBAAq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CAAC,CAAC,CACjD,SACM,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,UAErC,SAAS,CAAC,SAAS,CAAC,2JAYtB,CAAC;;;;;AAEN,qBAAa,cAAe,SAAQ,mBAMnC;IACC,IAAa,OAAO,IAAI,MAAM,CAM7B;CACF;;;;;;AAED,qBAAa,iBAAkB,SAAQ,sBAOtC;IACC,IAAa,OAAO,IAAI,MAAM,CAK7B;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"QueryInitializer.js","names":["Document.decode","OrderedQuery.make","QueryStreamIndexRange.builder","QueryStream.fromReflection","Document.documentErrorMessage"],"sources":["../src/QueryInitializer.ts"],"sourcesContent":["import type * as IdScope from \"@confect/core/IdScope\";\nimport type {\n OrderedQuery as ConvexOrderedQuery,\n QueryInitializer as ConvexQueryInitializer,\n DocumentByInfo,\n GenericTableIndexes,\n Indexes,\n IndexRange,\n IndexRangeBuilder,\n NamedIndex,\n NamedSearchIndex,\n NamedTableInfo,\n Query,\n SearchFilter,\n SearchFilterBuilder,\n SearchIndexes,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport type { ReadonlyRecord } from \"effect/Record\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport type {\n BaseDatabaseReader,\n IndexFieldTypesForEq,\n} from \"@confect/core/Types\";\nimport type * as DataModel from \"./DataModel\";\nimport type * as DatabaseSchema from \"./DatabaseSchema\";\nimport * as Document from \"./Document\";\nimport * as OrderedQuery from \"./OrderedQuery\";\nimport * as QueryStream from \"./QueryStream\";\nimport type * as QueryStreamKeyLabels from \"./QueryStreamKeyLabels\";\nimport * as QueryStreamIndexRange from \"./QueryStreamIndexRange\";\nimport type { QueryStreamOrderDirection as OrderDirection } from \"./QueryStreamOrderDirection\";\nimport type * as Table from \"./Table\";\n\ntype ConvexTableInfoFor<\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n> = DataModel.TableInfoWithName<DataModel_, TableName>;\n\ntype TableInfoFor<\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n> = DataModel.TableInfoWithName_<DataModel_, TableName>;\n\nexport interface QueryInitializer<\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n Doc = DataModel.DocumentWithName<DataModel_, TableName>,\n TargetKind extends DatabaseSchema.Target[\"kind\"] = \"app\",\n> {\n readonly get: {\n (\n id: DataModel.Id<DataModel_, TableName>,\n ): Effect.Effect<Doc, Document.DocumentDecodeError | GetByIdFailure>;\n <\n IndexName extends keyof Indexes<\n ConvexTableInfoFor<DataModel_, TableName>\n >,\n >(\n indexName: IndexName,\n ...indexFieldValues: IndexFieldTypesForEq<\n DataModel.ToConvex<DataModel_>,\n TableName,\n Indexes<ConvexTableInfoFor<DataModel_, TableName>>[IndexName]\n >\n ): Effect.Effect<Doc, Document.DocumentDecodeError | GetByIndexFailure>;\n };\n readonly index: {\n <\n IndexName extends keyof Indexes<\n ConvexTableInfoFor<DataModel_, TableName>\n >,\n >(\n indexName: IndexName,\n indexRange?: (\n q: IndexRangeBuilder<\n TableInfoFor<DataModel_, TableName>[\"convexDocument\"],\n NamedIndex<ConvexTableInfoFor<DataModel_, TableName>, IndexName>\n >,\n ) => IndexRange,\n order?: OrderDirection,\n ): OrderedQuery.OrderedQuery<\n TableInfoFor<DataModel_, TableName>,\n Doc,\n TargetKind\n >;\n <\n IndexName extends keyof Indexes<\n ConvexTableInfoFor<DataModel_, TableName>\n >,\n >(\n indexName: IndexName,\n order?: OrderDirection,\n ): OrderedQuery.OrderedQuery<\n TableInfoFor<DataModel_, TableName>,\n Doc,\n TargetKind\n >;\n };\n readonly search: <\n IndexName extends keyof SearchIndexes<\n ConvexTableInfoFor<DataModel_, TableName>\n >,\n >(\n indexName: IndexName,\n searchFilter: (\n q: SearchFilterBuilder<\n DocumentByInfo<ConvexTableInfoFor<DataModel_, TableName>>,\n NamedSearchIndex<ConvexTableInfoFor<DataModel_, TableName>, IndexName>\n >,\n ) => SearchFilter,\n ) => OrderedQuery.OrderedQuery<\n TableInfoFor<DataModel_, TableName>,\n Doc,\n TargetKind\n >;\n /**\n * EXPERIMENTAL—stream-first querying (see `notes/stream-based-querying.md`).\n *\n * Like `index`, but returns a {@link QueryStream.QueryStream}: a genuine\n * Effect `Stream` of documents in index order that stays mergeable and\n * paginable.\n *\n * In SQL terms: an index range scan—`SELECT * FROM table WHERE <range> ORDER\n * BY <index fields> [DESC]`; `eq` calls are the equality predicates, the\n * bound calls are the range predicates. The value is a reusable description\n * of a query: each run re-runs the index query. * The typed range builder\n * consumes `eq`-pinned fields from the index's field tuple at the type level,\n * so the stream's visible label type is exactly the fields that still vary\n * (the `ORDER BY` columns left after the equality predicates). The order\n * direction is part of the type too: omitted, it is `\"asc\"`; a literal is\n * tracked as that literal, and a value known only at runtime as the union.\n * The order parameter is either absent or a direction—never `undefined`—so\n * the type can't claim a literal the runtime default would contradict.\n */\n readonly stream: {\n <\n IndexName extends keyof Indexes<\n ConvexTableInfoFor<DataModel_, TableName>\n > &\n string,\n Range extends QueryStreamIndexRange.QueryStreamIndexRange,\n >(\n indexName: IndexName,\n indexRange: (\n q: QueryStreamIndexRange.Builder<\n TableInfoFor<DataModel_, TableName>[\"convexDocument\"],\n NamedIndex<ConvexTableInfoFor<DataModel_, TableName>, IndexName>\n >,\n ) => Range,\n ): QueryStream.QueryStream<\n Doc,\n QueryStreamKeyLabels.QueryStreamKeyLabels<\n QueryStreamIndexRange.Remaining<Range>\n >,\n \"asc\",\n Document.DocumentDecodeError,\n never\n >;\n <\n IndexName extends keyof Indexes<\n ConvexTableInfoFor<DataModel_, TableName>\n > &\n string,\n Range extends QueryStreamIndexRange.QueryStreamIndexRange,\n Direction extends OrderDirection,\n >(\n indexName: IndexName,\n indexRange: (\n q: QueryStreamIndexRange.Builder<\n TableInfoFor<DataModel_, TableName>[\"convexDocument\"],\n NamedIndex<ConvexTableInfoFor<DataModel_, TableName>, IndexName>\n >,\n ) => Range,\n order: Direction,\n ): QueryStream.QueryStream<\n Doc,\n QueryStreamKeyLabels.QueryStreamKeyLabels<\n QueryStreamIndexRange.Remaining<Range>\n >,\n Direction,\n Document.DocumentDecodeError,\n never\n >;\n <\n IndexName extends keyof Indexes<\n ConvexTableInfoFor<DataModel_, TableName>\n > &\n string,\n >(\n indexName: IndexName,\n ): QueryStream.QueryStream<\n Doc,\n QueryStreamKeyLabels.QueryStreamKeyLabels<\n NamedIndex<ConvexTableInfoFor<DataModel_, TableName>, IndexName>\n >,\n \"asc\",\n Document.DocumentDecodeError,\n never\n >;\n <\n IndexName extends keyof Indexes<\n ConvexTableInfoFor<DataModel_, TableName>\n > &\n string,\n Direction extends OrderDirection,\n >(\n indexName: IndexName,\n order: Direction,\n ): QueryStream.QueryStream<\n Doc,\n QueryStreamKeyLabels.QueryStreamKeyLabels<\n NamedIndex<ConvexTableInfoFor<DataModel_, TableName>, IndexName>\n >,\n Direction,\n Document.DocumentDecodeError,\n never\n >;\n };\n}\n\nexport function make<\n Tables extends Table.AnyWithProps,\n TableName extends Table.Name<Tables>,\n>(\n convexDatabaseReader: BaseDatabaseReader<\n DataModel.ToConvex<DataModel.FromTables<Tables>>\n >,\n table: Table.WithName<Tables, TableName> & { readonly scope: IdScope.App },\n): QueryInitializer<DataModel.FromTables<Tables>, TableName>;\nexport function make<\n Tables extends Table.AnyWithProps,\n TableName extends Table.Name<Tables>,\n>(\n convexDatabaseReader: BaseDatabaseReader<\n DataModel.ToConvex<DataModel.FromTables<Tables>>\n >,\n table: Table.WithName<Tables, TableName>,\n): QueryInitializer<\n DataModel.FromTables<Tables>,\n TableName,\n DataModel.DocumentWithName<DataModel.FromTables<Tables>, TableName>,\n Table.Scope<Table.WithName<Tables, TableName>> extends IdScope.App\n ? \"app\"\n : \"component\"\n>;\nexport function make<\n Tables extends Table.AnyWithProps,\n TableName extends Table.Name<Tables>,\n>(\n convexDatabaseReader: BaseDatabaseReader<\n DataModel.ToConvex<DataModel.FromTables<Tables>>\n >,\n table: Table.WithName<Tables, TableName>,\n): QueryInitializer<\n DataModel.FromTables<Tables>,\n TableName,\n DataModel.DocumentWithName<DataModel.FromTables<Tables>, TableName>,\n DatabaseSchema.Target[\"kind\"]\n> {\n const tableName = table.tableName;\n type DataModel_ = DataModel.FromTables<Tables>;\n type ConvexDataModel_ = DataModel.ToConvex<DataModel_>;\n type ThisQueryInitializer = QueryInitializer<\n DataModel_,\n TableName,\n DataModel.DocumentWithName<DataModel_, TableName>,\n DatabaseSchema.Target[\"kind\"]\n >;\n type QueryInitializerFunction<\n FunctionName extends keyof ThisQueryInitializer,\n > = ThisQueryInitializer[FunctionName];\n\n const getByIndex = <\n IndexName extends keyof Indexes<\n DataModel.TableInfoWithName<DataModel_, TableName>\n >,\n >(\n indexName: IndexName,\n indexFieldValues: IndexFieldTypesForEq<\n DataModel.ToConvex<DataModel_>,\n TableName,\n Indexes<DataModel.TableInfoWithName<DataModel_, TableName>>[IndexName]\n >,\n ): Effect.Effect<\n DataModel.DocumentWithName<DataModel_, TableName>,\n Document.DocumentDecodeError | GetByIndexFailure\n > => {\n const indexFieldPaths: GenericTableIndexes[keyof GenericTableIndexes] = (\n table.indexes as GenericTableIndexes\n )[indexName as keyof GenericTableIndexes]!;\n\n return pipe(\n Effect.promise(() =>\n convexDatabaseReader\n .query(tableName)\n .withIndex(indexName, (q) =>\n Array.reduce(\n indexFieldValues,\n q,\n (q_, v, i) => q_.eq(indexFieldPaths[i] as any, v as any) as any,\n ),\n )\n .unique(),\n ),\n Effect.andThen((value) =>\n Effect.fromResult(\n Result.fromNullishOr(\n value,\n () =>\n new GetByIndexFailure({\n tableName,\n indexName: indexName as string,\n indexFieldValues,\n }),\n ),\n ),\n ),\n Effect.andThen(Document.decode(table)),\n );\n };\n\n const get: QueryInitializerFunction<\"get\"> = ((\n ...args: Parameters<QueryInitializerFunction<\"get\">>\n ) => {\n if (args.length === 1) {\n const id = args[0] as GenericId<TableName>;\n\n return getById<Tables, TableName>(convexDatabaseReader, table)(id);\n } else {\n const [indexName, ...indexFieldValues] = args;\n\n return getByIndex(\n indexName as keyof Indexes<\n DataModel.TableInfoWithName<DataModel_, TableName>\n >,\n indexFieldValues,\n );\n }\n }) as QueryInitializerFunction<\"get\">;\n\n const index: QueryInitializerFunction<\"index\"> = <\n IndexName extends keyof Indexes<\n DataModel.TableInfoWithName<DataModel_, TableName>\n >,\n >(\n indexName: IndexName,\n indexRangeOrOrder?:\n | ((\n q: IndexRangeBuilder<\n DataModel.TableInfoWithName_<\n DataModel_,\n TableName\n >[\"convexDocument\"],\n NamedIndex<\n DataModel.TableInfoWithName<DataModel_, TableName>,\n IndexName\n >\n >,\n ) => IndexRange)\n | OrderDirection,\n order?: OrderDirection,\n ) => {\n const {\n applyWithIndex,\n applyOrder,\n }: {\n applyWithIndex: (\n queryInitializer: ConvexQueryInitializer<\n NamedTableInfo<ConvexDataModel_, TableName>\n >,\n ) => Query<NamedTableInfo<ConvexDataModel_, TableName>>;\n applyOrder: (\n query: Query<NamedTableInfo<ConvexDataModel_, TableName>>,\n ) => ConvexOrderedQuery<NamedTableInfo<ConvexDataModel_, TableName>>;\n } =\n indexRangeOrOrder === undefined\n ? {\n applyWithIndex: (q) => q.withIndex(indexName),\n applyOrder: (q) => q.order(\"asc\"),\n }\n : typeof indexRangeOrOrder === \"function\"\n ? order === undefined\n ? {\n applyWithIndex: (q) =>\n q.withIndex(indexName, indexRangeOrOrder),\n applyOrder: (q) => q.order(\"asc\"),\n }\n : {\n applyWithIndex: (q) =>\n q.withIndex(indexName, indexRangeOrOrder),\n applyOrder: (q) => q.order(order),\n }\n : {\n applyWithIndex: (q) => q.withIndex(indexName),\n applyOrder: (q) => q.order(indexRangeOrOrder),\n };\n\n const orderedQuery = pipe(\n convexDatabaseReader.query(tableName),\n applyWithIndex,\n applyOrder,\n );\n\n return OrderedQuery.make(orderedQuery, table);\n };\n\n const stream: QueryInitializerFunction<\"stream\"> = ((\n indexName: string,\n indexRangeOrOrder?:\n | ((\n q: QueryStreamIndexRange.Builder<any, any>,\n ) => QueryStreamIndexRange.QueryStreamIndexRange)\n | OrderDirection,\n maybeOrder?: OrderDirection,\n ) => {\n const orderDirection = Predicate.isString(indexRangeOrOrder)\n ? indexRangeOrOrder\n : (maybeOrder ?? \"asc\");\n\n // Without a range callback, the leaf scans the entire index.\n const indexRange = Predicate.isFunction(indexRangeOrOrder)\n ? indexRangeOrOrder(QueryStreamIndexRange.builder())\n : QueryStreamIndexRange.builder();\n\n // The type-level field tuple appends the `_creationTime` tiebreaker, but\n // the runtime `table.indexes` record stores only the declared fields—append it here.\n const indexFieldPaths: ReadonlyArray<string> =\n indexName === \"by_id\"\n ? [\"_id\"]\n : indexName === \"by_creation_time\"\n ? [\"_creationTime\"]\n : pipe(\n Option.fromUndefinedOr(\n (\n table.indexes as ReadonlyRecord<string, ReadonlyArray<string>>\n )[indexName],\n ),\n // An unknown index name is a defect, not an empty field list:\n // silently empty fields would make key extraction and range\n // splitting target the wrong fields.\n Option.getOrThrowWith(\n () =>\n new Error(\n `QueryInitializer.stream: table \"${tableName}\" has no index named \"${indexName}\"`,\n ),\n ),\n Array.append(\"_creationTime\"),\n );\n\n return QueryStream.fromReflection({\n reader: convexDatabaseReader as QueryStream.ReflectionReader,\n table,\n indexName,\n indexFieldPaths,\n indexRange,\n orderDirection,\n });\n }) as QueryInitializerFunction<\"stream\">;\n\n const search: QueryInitializerFunction<\"search\"> = (\n indexName,\n searchFilter,\n ) =>\n OrderedQuery.make(\n convexDatabaseReader\n .query(tableName)\n .withSearchIndex(indexName, searchFilter),\n table,\n );\n\n return {\n get,\n index,\n search,\n stream,\n };\n}\n\nexport const getById =\n <Tables extends Table.AnyWithProps, TableName extends Table.Name<Tables>>(\n convexDatabaseReader: BaseDatabaseReader<\n DataModel.ToConvex<DataModel.FromTables<Tables>>\n >,\n table: Table.WithName<Tables, TableName>,\n ) =>\n (id: GenericId<TableName>) =>\n pipe(\n Effect.promise(() => convexDatabaseReader.get(id)),\n Effect.andThen((value) =>\n Effect.fromResult(\n Result.fromNullishOr(\n value,\n () => new GetByIdFailure({ tableName: table.tableName, id }),\n ),\n ),\n ),\n Effect.andThen(Document.decode(table)),\n );\n\nexport class GetByIdFailure extends Schema.TaggedError<GetByIdFailure>()(\n \"GetByIdFailure\",\n {\n id: Schema.String,\n tableName: Schema.String,\n },\n) {\n override get message(): string {\n return Document.documentErrorMessage({\n id: this.id,\n tableName: this.tableName,\n message: \"not found\",\n });\n }\n}\n\nexport class GetByIndexFailure extends Schema.TaggedError<GetByIndexFailure>()(\n \"GetByIndexFailure\",\n {\n tableName: Schema.String,\n indexName: Schema.String,\n indexFieldValues: Schema.Array(Schema.Unknown),\n },\n) {\n override get message(): string {\n return `No documents found in table '${this.tableName}' with index '${this.indexName}' and field values '${JSON.stringify(\n this.indexFieldValues,\n (_key, value) => (typeof value === \"bigint\" ? value.toString() : value),\n )}'`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA4PA,SAAgB,KAId,sBAGA,OAMA;CACA,MAAM,YAAY,MAAM;CAaxB,MAAM,cAKJ,WACA,qBAQG;EACH,MAAM,kBACJ,MAAM,QACN;EAEF,OAAO,KACL,OAAO,cACL,qBACG,MAAM,SAAS,CAAC,CAChB,UAAU,YAAY,MACrB,MAAM,OACJ,kBACA,IACC,IAAI,GAAG,MAAM,GAAG,GAAG,gBAAgB,IAAW,CAAQ,CACzD,CACF,CAAC,CACA,OAAO,CACZ,GACA,OAAO,SAAS,UACd,OAAO,WACL,OAAO,cACL,aAEE,IAAI,kBAAkB;GACpB;GACW;GACX;EACF,CAAC,CACL,CACF,CACF,GACA,OAAO,QAAQA,OAAgB,KAAK,CAAC,CACvC;CACF;CAEA,MAAM,QACJ,GAAG,SACA;E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ACH;CAEA,MAAM,UACJ,WACA,iBAEAF,OACE,qBACG,MAAM,SAAS,CAAC,CAChB,gBAAgB,WAAW,YAAY,GAC1C,KACF;CAEF,OAAO;EACL;EACA;EACA;EACA;CACF;AACF;AAEA,MAAa,WAET,sBAGA,WAED,OACC,KACE,OAAO,cAAc,qBAAqB,IAAI,EAAE,CAAC,GACjD,OAAO,SAAS,UACd,OAAO,WACL,OAAO,cACL,aACM,IAAI,eAAe;CAAE,WAAW,MAAM;CAAW;AAAG,CAAC,CAC7D,CACF,CACF,GACA,OAAO,QAAQD,OAAgB,KAAK,CAAC,CACvC;AAEJ,IAAa,iBAAb,cAAoC,OAAO,YAA4B,CAAC,CACtE,kBACA;CACE,IAAI,OAAO;CACX,WAAW,OAAO;AACpB,CACF,CAAC,CAAC;CACA,IAAa,UAAkB;EAC7B,OAAOI,qBAA8B;GACnC,IAAI,KAAK;GACT,WAAW,KAAK;GAChB,SAAS;EACX,CAAC;CACH;AACF;AAEA,IAAa,oBAAb,cAAuC,OAAO,YAA+B,CAAC,CAC5E,qBACA;CACE,WAAW,OAAO;CAClB,WAAW,OAAO;CAClB,kBAAkB,OAAO,MAAM,OAAO,OAAO;AAC/C,CACF,CAAC,CAAC;CACA,IAAa,UAAkB;EAC7B,OAAO,gCAAgC,KAAK,UAAU,gBAAgB,KAAK,UAAU,sBAAsB,KAAK,UAC9G,KAAK,mBACJ,MAAM,UAAW,OAAO,UAAU,WAAW,MAAM,SAAS,IAAI,KACnE,EAAE;CACJ;AACF"}
1
+ {"version":3,"file":"QueryInitializer.js","names":["Document.decode","OrderedQuery.make","QueryStreamIndexRange.builder","QueryStream.fromReflection","Document.documentErrorMessage"],"sources":["../src/QueryInitializer.ts"],"sourcesContent":["import type * as IdScope from \"@confect/core/IdScope\";\nimport type {\n OrderedQuery as ConvexOrderedQuery,\n QueryInitializer as ConvexQueryInitializer,\n DocumentByInfo,\n GenericTableIndexes,\n Indexes,\n IndexRange,\n IndexRangeBuilder,\n NamedIndex,\n NamedSearchIndex,\n NamedTableInfo,\n Query,\n SearchFilter,\n SearchFilterBuilder,\n SearchIndexes,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Predicate from \"effect/Predicate\";\nimport type { ReadonlyRecord } from \"effect/Record\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport type {\n BaseDatabaseReader,\n IndexFieldTypesForEq,\n} from \"@confect/core/Types\";\nimport type * as DataModel from \"./DataModel.js\";\nimport type * as DatabaseSchema from \"./DatabaseSchema.js\";\nimport * as Document from \"./Document.js\";\nimport * as OrderedQuery from \"./OrderedQuery.js\";\nimport * as QueryStream from \"./QueryStream.js\";\nimport type * as QueryStreamKeyLabels from \"./QueryStreamKeyLabels.js\";\nimport * as QueryStreamIndexRange from \"./QueryStreamIndexRange.js\";\nimport type { QueryStreamOrderDirection as OrderDirection } from \"./QueryStreamOrderDirection.js\";\nimport type * as Table from \"./Table.js\";\n\ntype ConvexTableInfoFor<\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n> = DataModel.TableInfoWithName<DataModel_, TableName>;\n\ntype TableInfoFor<\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n> = DataModel.TableInfoWithName_<DataModel_, TableName>;\n\nexport interface QueryInitializer<\n DataModel_ extends DataModel.AnyWithProps,\n TableName extends DataModel.TableNames<DataModel_>,\n Doc = DataModel.DocumentWithName<DataModel_, TableName>,\n TargetKind extends DatabaseSchema.Target[\"kind\"] = \"app\",\n> {\n readonly get: {\n (\n id: DataModel.Id<DataModel_, TableName>,\n ): Effect.Effect<Doc, Document.DocumentDecodeError | GetByIdFailure>;\n <\n IndexName extends keyof Indexes<\n ConvexTableInfoFor<DataModel_, TableName>\n >,\n >(\n indexName: IndexName,\n ...indexFieldValues: IndexFieldTypesForEq<\n DataModel.ToConvex<DataModel_>,\n TableName,\n Indexes<ConvexTableInfoFor<DataModel_, TableName>>[IndexName]\n >\n ): Effect.Effect<Doc, Document.DocumentDecodeError | GetByIndexFailure>;\n };\n readonly index: {\n <\n IndexName extends keyof Indexes<\n ConvexTableInfoFor<DataModel_, TableName>\n >,\n >(\n indexName: IndexName,\n indexRange?: (\n q: IndexRangeBuilder<\n TableInfoFor<DataModel_, TableName>[\"convexDocument\"],\n NamedIndex<ConvexTableInfoFor<DataModel_, TableName>, IndexName>\n >,\n ) => IndexRange,\n order?: OrderDirection,\n ): OrderedQuery.OrderedQuery<\n TableInfoFor<DataModel_, TableName>,\n Doc,\n TargetKind\n >;\n <\n IndexName extends keyof Indexes<\n ConvexTableInfoFor<DataModel_, TableName>\n >,\n >(\n indexName: IndexName,\n order?: OrderDirection,\n ): OrderedQuery.OrderedQuery<\n TableInfoFor<DataModel_, TableName>,\n Doc,\n TargetKind\n >;\n };\n readonly search: <\n IndexName extends keyof SearchIndexes<\n ConvexTableInfoFor<DataModel_, TableName>\n >,\n >(\n indexName: IndexName,\n searchFilter: (\n q: SearchFilterBuilder<\n DocumentByInfo<ConvexTableInfoFor<DataModel_, TableName>>,\n NamedSearchIndex<ConvexTableInfoFor<DataModel_, TableName>, IndexName>\n >,\n ) => SearchFilter,\n ) => OrderedQuery.OrderedQuery<\n TableInfoFor<DataModel_, TableName>,\n Doc,\n TargetKind\n >;\n /**\n * EXPERIMENTAL—stream-first querying (see `notes/stream-based-querying.md`).\n *\n * Like `index`, but returns a {@link QueryStream.QueryStream}: a genuine\n * Effect `Stream` of documents in index order that stays mergeable and\n * paginable.\n *\n * In SQL terms: an index range scan—`SELECT * FROM table WHERE <range> ORDER\n * BY <index fields> [DESC]`; `eq` calls are the equality predicates, the\n * bound calls are the range predicates. The value is a reusable description\n * of a query: each run re-runs the index query. * The typed range builder\n * consumes `eq`-pinned fields from the index's field tuple at the type level,\n * so the stream's visible label type is exactly the fields that still vary\n * (the `ORDER BY` columns left after the equality predicates). The order\n * direction is part of the type too: omitted, it is `\"asc\"`; a literal is\n * tracked as that literal, and a value known only at runtime as the union.\n * The order parameter is either absent or a direction—never `undefined`—so\n * the type can't claim a literal the runtime default would contradict.\n */\n readonly stream: {\n <\n IndexName extends keyof Indexes<\n ConvexTableInfoFor<DataModel_, TableName>\n > &\n string,\n Range extends QueryStreamIndexRange.QueryStreamIndexRange,\n >(\n indexName: IndexName,\n indexRange: (\n q: QueryStreamIndexRange.Builder<\n TableInfoFor<DataModel_, TableName>[\"convexDocument\"],\n NamedIndex<ConvexTableInfoFor<DataModel_, TableName>, IndexName>\n >,\n ) => Range,\n ): QueryStream.QueryStream<\n Doc,\n QueryStreamKeyLabels.QueryStreamKeyLabels<\n QueryStreamIndexRange.Remaining<Range>\n >,\n \"asc\",\n Document.DocumentDecodeError,\n never\n >;\n <\n IndexName extends keyof Indexes<\n ConvexTableInfoFor<DataModel_, TableName>\n > &\n string,\n Range extends QueryStreamIndexRange.QueryStreamIndexRange,\n Direction extends OrderDirection,\n >(\n indexName: IndexName,\n indexRange: (\n q: QueryStreamIndexRange.Builder<\n TableInfoFor<DataModel_, TableName>[\"convexDocument\"],\n NamedIndex<ConvexTableInfoFor<DataModel_, TableName>, IndexName>\n >,\n ) => Range,\n order: Direction,\n ): QueryStream.QueryStream<\n Doc,\n QueryStreamKeyLabels.QueryStreamKeyLabels<\n QueryStreamIndexRange.Remaining<Range>\n >,\n Direction,\n Document.DocumentDecodeError,\n never\n >;\n <\n IndexName extends keyof Indexes<\n ConvexTableInfoFor<DataModel_, TableName>\n > &\n string,\n >(\n indexName: IndexName,\n ): QueryStream.QueryStream<\n Doc,\n QueryStreamKeyLabels.QueryStreamKeyLabels<\n NamedIndex<ConvexTableInfoFor<DataModel_, TableName>, IndexName>\n >,\n \"asc\",\n Document.DocumentDecodeError,\n never\n >;\n <\n IndexName extends keyof Indexes<\n ConvexTableInfoFor<DataModel_, TableName>\n > &\n string,\n Direction extends OrderDirection,\n >(\n indexName: IndexName,\n order: Direction,\n ): QueryStream.QueryStream<\n Doc,\n QueryStreamKeyLabels.QueryStreamKeyLabels<\n NamedIndex<ConvexTableInfoFor<DataModel_, TableName>, IndexName>\n >,\n Direction,\n Document.DocumentDecodeError,\n never\n >;\n };\n}\n\nexport function make<\n Tables extends Table.AnyWithProps,\n TableName extends Table.Name<Tables>,\n>(\n convexDatabaseReader: BaseDatabaseReader<\n DataModel.ToConvex<DataModel.FromTables<Tables>>\n >,\n table: Table.WithName<Tables, TableName> & { readonly scope: IdScope.App },\n): QueryInitializer<DataModel.FromTables<Tables>, TableName>;\nexport function make<\n Tables extends Table.AnyWithProps,\n TableName extends Table.Name<Tables>,\n>(\n convexDatabaseReader: BaseDatabaseReader<\n DataModel.ToConvex<DataModel.FromTables<Tables>>\n >,\n table: Table.WithName<Tables, TableName>,\n): QueryInitializer<\n DataModel.FromTables<Tables>,\n TableName,\n DataModel.DocumentWithName<DataModel.FromTables<Tables>, TableName>,\n Table.Scope<Table.WithName<Tables, TableName>> extends IdScope.App\n ? \"app\"\n : \"component\"\n>;\nexport function make<\n Tables extends Table.AnyWithProps,\n TableName extends Table.Name<Tables>,\n>(\n convexDatabaseReader: BaseDatabaseReader<\n DataModel.ToConvex<DataModel.FromTables<Tables>>\n >,\n table: Table.WithName<Tables, TableName>,\n): QueryInitializer<\n DataModel.FromTables<Tables>,\n TableName,\n DataModel.DocumentWithName<DataModel.FromTables<Tables>, TableName>,\n DatabaseSchema.Target[\"kind\"]\n> {\n const tableName = table.tableName;\n type DataModel_ = DataModel.FromTables<Tables>;\n type ConvexDataModel_ = DataModel.ToConvex<DataModel_>;\n type ThisQueryInitializer = QueryInitializer<\n DataModel_,\n TableName,\n DataModel.DocumentWithName<DataModel_, TableName>,\n DatabaseSchema.Target[\"kind\"]\n >;\n type QueryInitializerFunction<\n FunctionName extends keyof ThisQueryInitializer,\n > = ThisQueryInitializer[FunctionName];\n\n const getByIndex = <\n IndexName extends keyof Indexes<\n DataModel.TableInfoWithName<DataModel_, TableName>\n >,\n >(\n indexName: IndexName,\n indexFieldValues: IndexFieldTypesForEq<\n DataModel.ToConvex<DataModel_>,\n TableName,\n Indexes<DataModel.TableInfoWithName<DataModel_, TableName>>[IndexName]\n >,\n ): Effect.Effect<\n DataModel.DocumentWithName<DataModel_, TableName>,\n Document.DocumentDecodeError | GetByIndexFailure\n > => {\n const indexFieldPaths: GenericTableIndexes[keyof GenericTableIndexes] = (\n table.indexes as GenericTableIndexes\n )[indexName as keyof GenericTableIndexes]!;\n\n return pipe(\n Effect.promise(() =>\n convexDatabaseReader\n .query(tableName)\n .withIndex(indexName, (q) =>\n Array.reduce(\n indexFieldValues,\n q,\n (q_, v, i) => q_.eq(indexFieldPaths[i] as any, v as any) as any,\n ),\n )\n .unique(),\n ),\n Effect.andThen((value) =>\n Effect.fromResult(\n Result.fromNullishOr(\n value,\n () =>\n new GetByIndexFailure({\n tableName,\n indexName: indexName as string,\n indexFieldValues,\n }),\n ),\n ),\n ),\n Effect.andThen(Document.decode(table)),\n );\n };\n\n const get: QueryInitializerFunction<\"get\"> = ((\n ...args: Parameters<QueryInitializerFunction<\"get\">>\n ) => {\n if (args.length === 1) {\n const id = args[0] as GenericId<TableName>;\n\n return getById<Tables, TableName>(convexDatabaseReader, table)(id);\n } else {\n const [indexName, ...indexFieldValues] = args;\n\n return getByIndex(\n indexName as keyof Indexes<\n DataModel.TableInfoWithName<DataModel_, TableName>\n >,\n indexFieldValues,\n );\n }\n }) as QueryInitializerFunction<\"get\">;\n\n const index: QueryInitializerFunction<\"index\"> = <\n IndexName extends keyof Indexes<\n DataModel.TableInfoWithName<DataModel_, TableName>\n >,\n >(\n indexName: IndexName,\n indexRangeOrOrder?:\n | ((\n q: IndexRangeBuilder<\n DataModel.TableInfoWithName_<\n DataModel_,\n TableName\n >[\"convexDocument\"],\n NamedIndex<\n DataModel.TableInfoWithName<DataModel_, TableName>,\n IndexName\n >\n >,\n ) => IndexRange)\n | OrderDirection,\n order?: OrderDirection,\n ) => {\n const {\n applyWithIndex,\n applyOrder,\n }: {\n applyWithIndex: (\n queryInitializer: ConvexQueryInitializer<\n NamedTableInfo<ConvexDataModel_, TableName>\n >,\n ) => Query<NamedTableInfo<ConvexDataModel_, TableName>>;\n applyOrder: (\n query: Query<NamedTableInfo<ConvexDataModel_, TableName>>,\n ) => ConvexOrderedQuery<NamedTableInfo<ConvexDataModel_, TableName>>;\n } =\n indexRangeOrOrder === undefined\n ? {\n applyWithIndex: (q) => q.withIndex(indexName),\n applyOrder: (q) => q.order(\"asc\"),\n }\n : typeof indexRangeOrOrder === \"function\"\n ? order === undefined\n ? {\n applyWithIndex: (q) =>\n q.withIndex(indexName, indexRangeOrOrder),\n applyOrder: (q) => q.order(\"asc\"),\n }\n : {\n applyWithIndex: (q) =>\n q.withIndex(indexName, indexRangeOrOrder),\n applyOrder: (q) => q.order(order),\n }\n : {\n applyWithIndex: (q) => q.withIndex(indexName),\n applyOrder: (q) => q.order(indexRangeOrOrder),\n };\n\n const orderedQuery = pipe(\n convexDatabaseReader.query(tableName),\n applyWithIndex,\n applyOrder,\n );\n\n return OrderedQuery.make(orderedQuery, table);\n };\n\n const stream: QueryInitializerFunction<\"stream\"> = ((\n indexName: string,\n indexRangeOrOrder?:\n | ((\n q: QueryStreamIndexRange.Builder<any, any>,\n ) => QueryStreamIndexRange.QueryStreamIndexRange)\n | OrderDirection,\n maybeOrder?: OrderDirection,\n ) => {\n const orderDirection = Predicate.isString(indexRangeOrOrder)\n ? indexRangeOrOrder\n : (maybeOrder ?? \"asc\");\n\n // Without a range callback, the leaf scans the entire index.\n const indexRange = Predicate.isFunction(indexRangeOrOrder)\n ? indexRangeOrOrder(QueryStreamIndexRange.builder())\n : QueryStreamIndexRange.builder();\n\n // The type-level field tuple appends the `_creationTime` tiebreaker, but\n // the runtime `table.indexes` record stores only the declared fields—append it here.\n const indexFieldPaths: ReadonlyArray<string> =\n indexName === \"by_id\"\n ? [\"_id\"]\n : indexName === \"by_creation_time\"\n ? [\"_creationTime\"]\n : pipe(\n Option.fromUndefinedOr(\n (\n table.indexes as ReadonlyRecord<string, ReadonlyArray<string>>\n )[indexName],\n ),\n // An unknown index name is a defect, not an empty field list:\n // silently empty fields would make key extraction and range\n // splitting target the wrong fields.\n Option.getOrThrowWith(\n () =>\n new Error(\n `QueryInitializer.stream: table \"${tableName}\" has no index named \"${indexName}\"`,\n ),\n ),\n Array.append(\"_creationTime\"),\n );\n\n return QueryStream.fromReflection({\n reader: convexDatabaseReader as QueryStream.ReflectionReader,\n table,\n indexName,\n indexFieldPaths,\n indexRange,\n orderDirection,\n });\n }) as QueryInitializerFunction<\"stream\">;\n\n const search: QueryInitializerFunction<\"search\"> = (\n indexName,\n searchFilter,\n ) =>\n OrderedQuery.make(\n convexDatabaseReader\n .query(tableName)\n .withSearchIndex(indexName, searchFilter),\n table,\n );\n\n return {\n get,\n index,\n search,\n stream,\n };\n}\n\nexport const getById =\n <Tables extends Table.AnyWithProps, TableName extends Table.Name<Tables>>(\n convexDatabaseReader: BaseDatabaseReader<\n DataModel.ToConvex<DataModel.FromTables<Tables>>\n >,\n table: Table.WithName<Tables, TableName>,\n ) =>\n (id: GenericId<TableName>) =>\n pipe(\n Effect.promise(() => convexDatabaseReader.get(id)),\n Effect.andThen((value) =>\n Effect.fromResult(\n Result.fromNullishOr(\n value,\n () => new GetByIdFailure({ tableName: table.tableName, id }),\n ),\n ),\n ),\n Effect.andThen(Document.decode(table)),\n );\n\nexport class GetByIdFailure extends Schema.TaggedError<GetByIdFailure>()(\n \"GetByIdFailure\",\n {\n id: Schema.String,\n tableName: Schema.String,\n },\n) {\n override get message(): string {\n return Document.documentErrorMessage({\n id: this.id,\n tableName: this.tableName,\n message: \"not found\",\n });\n }\n}\n\nexport class GetByIndexFailure extends Schema.TaggedError<GetByIndexFailure>()(\n \"GetByIndexFailure\",\n {\n tableName: Schema.String,\n indexName: Schema.String,\n indexFieldValues: Schema.Array(Schema.Unknown),\n },\n) {\n override get message(): string {\n return `No documents found in table '${this.tableName}' with index '${this.indexName}' and field values '${JSON.stringify(\n this.indexFieldValues,\n (_key, value) => (typeof value === \"bigint\" ? value.toString() : value),\n )}'`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA4PA,SAAgB,KAId,sBAGA,OAMA;CACA,MAAM,YAAY,MAAM;CAaxB,MAAM,cAKJ,WACA,qBAQG;EACH,MAAM,kBACJ,MAAM,QACN;EAEF,OAAO,KACL,OAAO,cACL,qBACG,MAAM,SAAS,CAAC,CAChB,UAAU,YAAY,MACrB,MAAM,OACJ,kBACA,IACC,IAAI,GAAG,MAAM,GAAG,GAAG,gBAAgB,IAAW,CAAQ,CACzD,CACF,CAAC,CACA,OAAO,CACZ,GACA,OAAO,SAAS,UACd,OAAO,WACL,OAAO,cACL,aAEE,IAAI,kBAAkB;GACpB;GACW;GACX;EACF,CAAC,CACL,CACF,CACF,GACA,OAAO,QAAQA,OAAgB,KAAK,CAAC,CACvC;CACF;CAEA,MAAM,QACJ,GAAG,SACA;EACH,IAAI,KAAK,WAAW,GAAG;GACrB,MAAM,KAAK,KAAK;GAEhB,OAAO,QAA2B,sBAAsB,KAAK,CAAC,CAAC,EAAE;EACnE,OAAO;GACL,MAAM,CAAC,WAAW,GAAG,oBAAoB;GAEzC,OAAO,WACL,WAGA,gBACF;EACF;CACF;CAEA,MAAM,SAKJ,WACA,mBAcA,UACG;EACH,MAAM,EACJ,gBACA,eAWA,sBAAsB,KAAA,IAClB;GACE,iBAAiB,MAAM,EAAE,UAAU,SAAS;GAC5C,aAAa,MAAM,EAAE,MAAM,KAAK;EAClC,IACA,OAAO,sBAAsB,aAC3B,UAAU,KAAA,IACR;GACE,iBAAiB,MACf,EAAE,UAAU,WAAW,iBAAiB;GAC1C,aAAa,MAAM,EAAE,MAAM,KAAK;EAClC,IACA;GACE,iBAAiB,MACf,EAAE,UAAU,WAAW,iBAAiB;GAC1C,aAAa,MAAM,EAAE,MA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;GAChB,SAAS;EACX,CAAC;CACH;AACF;AAEA,IAAa,oBAAb,cAAuC,OAAO,YAA+B,CAAC,CAC5E,qBACA;CACE,WAAW,OAAO;CAClB,WAAW,OAAO;CAClB,kBAAkB,OAAO,MAAM,OAAO,OAAO;AAC/C,CACF,CAAC,CAAC;CACA,IAAa,UAAkB;EAC7B,OAAO,gCAAgC,KAAK,UAAU,gBAAgB,KAAK,UAAU,sBAAsB,KAAK,UAC9G,KAAK,mBACJ,MAAM,UAAW,OAAO,UAAU,WAAW,MAAM,SAAS,IAAI,KACnE,EAAE;CACJ;AACF"}
@@ -4,8 +4,8 @@ import * as Context from "effect/Context";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as Layer from "effect/Layer";
6
6
  import type * as Schema from "effect/Schema";
7
- import * as MutationTransactionContext from "./MutationTransactionContext";
8
- import * as QueryTransactionContext from "./QueryTransactionContext";
7
+ import * as MutationTransactionContext from "./MutationTransactionContext.js";
8
+ import * as QueryTransactionContext from "./QueryTransactionContext.js";
9
9
  export type Options = MutationTransactionContext.QueryOptions;
10
10
  export declare const QueryRunner: Context.Service<{
11
11
  runQuery: {