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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/dist/ActionCall.d.ts +30 -0
  2. package/dist/ActionCall.d.ts.map +1 -0
  3. package/dist/ActionCall.js +41 -0
  4. package/dist/ActionCall.js.map +1 -0
  5. package/dist/ActionCtx.d.ts +1 -1
  6. package/dist/ActionCtx.d.ts.map +1 -1
  7. package/dist/ActionCtx.js.map +1 -1
  8. package/dist/ActionRunner.js +2 -2
  9. package/dist/AiGatewayDecisionClient.d.ts +2 -2
  10. package/dist/AiGatewayDecisionClient.d.ts.map +1 -1
  11. package/dist/AiGatewayDecisionClient.js +1 -1
  12. package/dist/AiGatewayDecisionClient.js.map +1 -1
  13. package/dist/AiGatewayLanguageClient.d.ts +2 -2
  14. package/dist/AiGatewayLanguageClient.d.ts.map +1 -1
  15. package/dist/AiGatewayLanguageClient.js +1 -1
  16. package/dist/AiGatewayLanguageClient.js.map +1 -1
  17. package/dist/Auth.d.ts +1 -1
  18. package/dist/Auth.d.ts.map +1 -1
  19. package/dist/Auth.js +1 -1
  20. package/dist/Auth.js.map +1 -1
  21. package/dist/Callback.js +3 -3
  22. package/dist/ComponentCtx.d.ts +1 -1
  23. package/dist/ComponentCtx.d.ts.map +1 -1
  24. package/dist/ConvexConfigProvider.js +2 -2
  25. package/dist/ConvexFunctionDefinitions.d.ts +4 -4
  26. package/dist/ConvexFunctionDefinitions.d.ts.map +1 -1
  27. package/dist/ConvexFunctionDefinitions.js +2 -2
  28. package/dist/ConvexFunctionDefinitions.js.map +1 -1
  29. package/dist/ConvexLogger.js +1 -1
  30. package/dist/CronJobs.d.ts +1 -1
  31. package/dist/CronJobs.d.ts.map +1 -1
  32. package/dist/CronJobs.js +6 -6
  33. package/dist/CronJobs.js.map +1 -1
  34. package/dist/DataModel.d.ts +3 -3
  35. package/dist/DataModel.d.ts.map +1 -1
  36. package/dist/DataModel.js.map +1 -1
  37. package/dist/DatabaseReader.d.ts +4 -4
  38. package/dist/DatabaseReader.d.ts.map +1 -1
  39. package/dist/DatabaseReader.js.map +1 -1
  40. package/dist/DatabaseSchema.d.ts +1 -1
  41. package/dist/DatabaseSchema.d.ts.map +1 -1
  42. package/dist/DatabaseSchema.js +2 -2
  43. package/dist/DatabaseSchema.js.map +1 -1
  44. package/dist/DatabaseWriter.d.ts +41 -7
  45. package/dist/DatabaseWriter.d.ts.map +1 -1
  46. package/dist/DatabaseWriter.js +55 -8
  47. package/dist/DatabaseWriter.js.map +1 -1
  48. package/dist/Document.d.ts +4 -4
  49. package/dist/Document.d.ts.map +1 -1
  50. package/dist/Document.js.map +1 -1
  51. package/dist/ExecutionMetadata.js +1 -1
  52. package/dist/FunctionImpl.d.ts +2 -2
  53. package/dist/FunctionImpl.d.ts.map +1 -1
  54. package/dist/FunctionImpl.js +2 -2
  55. package/dist/FunctionImpl.js.map +1 -1
  56. package/dist/FunctionRegistryItem.d.ts +1 -1
  57. package/dist/FunctionRegistryItem.d.ts.map +1 -1
  58. package/dist/FunctionRegistryItem.js +1 -1
  59. package/dist/FunctionRegistryItem.js.map +1 -1
  60. package/dist/GroupImpl.d.ts +24 -5
  61. package/dist/GroupImpl.d.ts.map +1 -1
  62. package/dist/GroupImpl.js +21 -22
  63. package/dist/GroupImpl.js.map +1 -1
  64. package/dist/GroupRegistry.d.ts +2 -2
  65. package/dist/GroupRegistry.d.ts.map +1 -1
  66. package/dist/GroupRegistry.js.map +1 -1
  67. package/dist/Handler.d.ts +30 -26
  68. package/dist/Handler.d.ts.map +1 -1
  69. package/dist/Handler.js.map +1 -1
  70. package/dist/HttpRouter.d.ts +13 -13
  71. package/dist/HttpRouter.d.ts.map +1 -1
  72. package/dist/HttpRouter.js +2 -2
  73. package/dist/HttpRouter.js.map +1 -1
  74. package/dist/MiddlewareImpl.d.ts +14 -14
  75. package/dist/MiddlewareImpl.d.ts.map +1 -1
  76. package/dist/MiddlewareImpl.js +1 -1
  77. package/dist/MiddlewareImpl.js.map +1 -1
  78. package/dist/MutationCtx.d.ts +1 -1
  79. package/dist/MutationCtx.d.ts.map +1 -1
  80. package/dist/MutationCtx.js.map +1 -1
  81. package/dist/MutationRunner.d.ts +1 -1
  82. package/dist/MutationRunner.d.ts.map +1 -1
  83. package/dist/MutationRunner.js +2 -2
  84. package/dist/MutationRunner.js.map +1 -1
  85. package/dist/MutationTransactionContext.d.ts +2 -2
  86. package/dist/MutationTransactionContext.d.ts.map +1 -1
  87. package/dist/MutationTransactionContext.js +2 -2
  88. package/dist/MutationTransactionContext.js.map +1 -1
  89. package/dist/OfficialComponent.d.ts +50 -0
  90. package/dist/OfficialComponent.d.ts.map +1 -0
  91. package/dist/OfficialComponent.js +70 -0
  92. package/dist/OfficialComponent.js.map +1 -0
  93. package/dist/OrderedQuery.d.ts +4 -4
  94. package/dist/OrderedQuery.d.ts.map +1 -1
  95. package/dist/OrderedQuery.js.map +1 -1
  96. package/dist/QueryCtx.d.ts +1 -1
  97. package/dist/QueryCtx.d.ts.map +1 -1
  98. package/dist/QueryCtx.js.map +1 -1
  99. package/dist/QueryInitializer.d.ts +10 -10
  100. package/dist/QueryInitializer.d.ts.map +1 -1
  101. package/dist/QueryInitializer.js +2 -2
  102. package/dist/QueryInitializer.js.map +1 -1
  103. package/dist/QueryRunner.d.ts +2 -2
  104. package/dist/QueryRunner.d.ts.map +1 -1
  105. package/dist/QueryRunner.js +2 -2
  106. package/dist/QueryRunner.js.map +1 -1
  107. package/dist/QueryStream.d.ts +86 -13
  108. package/dist/QueryStream.d.ts.map +1 -1
  109. package/dist/QueryStream.js +81 -8
  110. package/dist/QueryStream.js.map +1 -1
  111. package/dist/QueryStreamCursor.d.ts +2 -2
  112. package/dist/QueryStreamCursor.d.ts.map +1 -1
  113. package/dist/QueryStreamCursor.js +1 -1
  114. package/dist/QueryStreamCursor.js.map +1 -1
  115. package/dist/QueryStreamIndexPrefix.d.ts +2 -2
  116. package/dist/QueryStreamIndexPrefix.d.ts.map +1 -1
  117. package/dist/QueryStreamIndexPrefix.js +1 -1
  118. package/dist/QueryStreamIndexPrefix.js.map +1 -1
  119. package/dist/QueryStreamIndexRange.d.ts +4 -4
  120. package/dist/QueryStreamIndexRange.d.ts.map +1 -1
  121. package/dist/QueryStreamIndexRange.js +2 -2
  122. package/dist/QueryStreamIndexRange.js.map +1 -1
  123. package/dist/QueryStreamKey.d.ts +2 -2
  124. package/dist/QueryStreamKey.d.ts.map +1 -1
  125. package/dist/QueryStreamKey.js +1 -1
  126. package/dist/QueryStreamKey.js.map +1 -1
  127. package/dist/QueryStreamKeyBounds.d.ts +3 -3
  128. package/dist/QueryStreamKeyBounds.d.ts.map +1 -1
  129. package/dist/QueryStreamKeyBounds.js +2 -2
  130. package/dist/QueryStreamKeyBounds.js.map +1 -1
  131. package/dist/QueryStreamKeyLayout.d.ts +1 -1
  132. package/dist/QueryStreamKeyLayout.d.ts.map +1 -1
  133. package/dist/QueryStreamKeyLayout.js +2 -2
  134. package/dist/QueryStreamKeyLayout.js.map +1 -1
  135. package/dist/QueryStreamKeyValues.d.ts +1 -1
  136. package/dist/QueryStreamKeyValues.d.ts.map +1 -1
  137. package/dist/QueryStreamKeyValues.js +1 -1
  138. package/dist/QueryStreamKeyValues.js.map +1 -1
  139. package/dist/QueryStreamPagination.d.ts +1 -1
  140. package/dist/QueryStreamPagination.d.ts.map +1 -1
  141. package/dist/QueryStreamPagination.js +1 -1
  142. package/dist/QueryStreamPagination.js.map +1 -1
  143. package/dist/QueryStreamReadBudget.d.ts +3 -2
  144. package/dist/QueryStreamReadBudget.d.ts.map +1 -1
  145. package/dist/QueryStreamReadBudget.js +6 -3
  146. package/dist/QueryStreamReadBudget.js.map +1 -1
  147. package/dist/QueryTransactionContext.js +2 -2
  148. package/dist/RegisteredConvexFunction.d.ts +20 -20
  149. package/dist/RegisteredConvexFunction.d.ts.map +1 -1
  150. package/dist/RegisteredConvexFunction.js +19 -19
  151. package/dist/RegisteredConvexFunction.js.map +1 -1
  152. package/dist/RegisteredFunction.d.ts +26 -26
  153. package/dist/RegisteredFunction.d.ts.map +1 -1
  154. package/dist/RegisteredFunction.js +55 -13
  155. package/dist/RegisteredFunction.js.map +1 -1
  156. package/dist/RegisteredFunctions.d.ts +3 -3
  157. package/dist/RegisteredFunctions.d.ts.map +1 -1
  158. package/dist/RegisteredFunctions.js.map +1 -1
  159. package/dist/RegisteredNodeFunction.d.ts +6 -6
  160. package/dist/RegisteredNodeFunction.d.ts.map +1 -1
  161. package/dist/RegisteredNodeFunction.js +1 -1
  162. package/dist/RegisteredNodeFunction.js.map +1 -1
  163. package/dist/Registry.d.ts +1 -1
  164. package/dist/Registry.d.ts.map +1 -1
  165. package/dist/Registry.js.map +1 -1
  166. package/dist/RegistryItems.d.ts +7 -0
  167. package/dist/RegistryItems.d.ts.map +1 -1
  168. package/dist/RegistryItems.js +8 -3
  169. package/dist/RegistryItems.js.map +1 -1
  170. package/dist/RequestMetadata.js +1 -1
  171. package/dist/ResolvedMiddleware.d.ts +2 -2
  172. package/dist/ResolvedMiddleware.d.ts.map +1 -1
  173. package/dist/ResolvedMiddleware.js.map +1 -1
  174. package/dist/Scheduler.js +2 -2
  175. package/dist/Storage.d.ts +6 -6
  176. package/dist/Storage.d.ts.map +1 -1
  177. package/dist/Storage.js +1 -1
  178. package/dist/Storage.js.map +1 -1
  179. package/dist/StorageActionWriter.d.ts +1 -1
  180. package/dist/StorageActionWriter.d.ts.map +1 -1
  181. package/dist/StorageActionWriter.js +1 -1
  182. package/dist/StorageActionWriter.js.map +1 -1
  183. package/dist/StorageReader.d.ts +1 -1
  184. package/dist/StorageReader.d.ts.map +1 -1
  185. package/dist/StorageReader.js +1 -1
  186. package/dist/StorageReader.js.map +1 -1
  187. package/dist/StorageWriter.d.ts +1 -1
  188. package/dist/StorageWriter.d.ts.map +1 -1
  189. package/dist/StorageWriter.js +1 -1
  190. package/dist/StorageWriter.js.map +1 -1
  191. package/dist/TableInfo.d.ts +2 -2
  192. package/dist/TableInfo.d.ts.map +1 -1
  193. package/dist/TableInfo.js.map +1 -1
  194. package/dist/TransactionMetadata.js +1 -1
  195. package/dist/VectorSearch.d.ts +1 -1
  196. package/dist/VectorSearch.d.ts.map +1 -1
  197. package/dist/VectorSearch.js +1 -1
  198. package/dist/VectorSearch.js.map +1 -1
  199. package/dist/index.d.ts +62 -60
  200. package/dist/index.d.ts.map +1 -1
  201. package/dist/index.js +11 -9
  202. package/dist/internal/AiGatewayDecisionClient.d.ts +1 -1
  203. package/dist/internal/AiGatewayDecisionClient.d.ts.map +1 -1
  204. package/dist/internal/AiGatewayDecisionClient.js +1 -1
  205. package/dist/internal/AiGatewayDecisionClient.js.map +1 -1
  206. package/dist/internal/AiGatewayLanguageClient.d.ts +1 -1
  207. package/dist/internal/AiGatewayLanguageClient.d.ts.map +1 -1
  208. package/dist/internal/AiGatewayLanguageClient.js +1 -1
  209. package/dist/internal/AiGatewayLanguageClient.js.map +1 -1
  210. package/dist/internal/AiGatewayServiceToken.js +1 -1
  211. package/dist/internal/DocumentPatch.d.ts +16 -0
  212. package/dist/internal/DocumentPatch.d.ts.map +1 -0
  213. package/dist/internal/DocumentPatch.js +36 -0
  214. package/dist/internal/DocumentPatch.js.map +1 -0
  215. package/dist/node.d.ts +1 -1
  216. package/dist/node.d.ts.map +1 -1
  217. package/package.json +2 -2
  218. package/src/ActionCall.ts +82 -0
  219. package/src/ActionCtx.ts +1 -1
  220. package/src/AiGatewayDecisionClient.ts +3 -3
  221. package/src/AiGatewayLanguageClient.ts +3 -3
  222. package/src/Auth.ts +1 -1
  223. package/src/ComponentCtx.ts +1 -1
  224. package/src/ConvexFunctionDefinitions.ts +8 -8
  225. package/src/CronJobs.ts +1 -1
  226. package/src/DataModel.ts +3 -3
  227. package/src/DatabaseReader.ts +4 -4
  228. package/src/DatabaseSchema.ts +1 -1
  229. package/src/DatabaseWriter.ts +189 -31
  230. package/src/Document.ts +4 -4
  231. package/src/FunctionImpl.ts +5 -5
  232. package/src/FunctionRegistryItem.ts +1 -1
  233. package/src/GroupImpl.ts +66 -13
  234. package/src/GroupRegistry.ts +4 -4
  235. package/src/Handler.ts +43 -28
  236. package/src/HttpRouter.ts +17 -17
  237. package/src/MiddlewareImpl.ts +17 -17
  238. package/src/MutationCtx.ts +1 -1
  239. package/src/MutationRunner.ts +1 -1
  240. package/src/MutationTransactionContext.ts +2 -2
  241. package/src/OfficialComponent.ts +151 -0
  242. package/src/OrderedQuery.ts +4 -4
  243. package/src/QueryCtx.ts +1 -1
  244. package/src/QueryInitializer.ts +9 -9
  245. package/src/QueryRunner.ts +2 -2
  246. package/src/QueryStream.ts +212 -20
  247. package/src/QueryStreamCursor.ts +3 -3
  248. package/src/QueryStreamIndexPrefix.ts +2 -2
  249. package/src/QueryStreamIndexRange.ts +4 -4
  250. package/src/QueryStreamKey.ts +2 -2
  251. package/src/QueryStreamKeyBounds.ts +3 -3
  252. package/src/QueryStreamKeyLayout.ts +1 -1
  253. package/src/QueryStreamKeyValues.ts +1 -1
  254. package/src/QueryStreamPagination.ts +2 -2
  255. package/src/QueryStreamReadBudget.ts +19 -6
  256. package/src/RegisteredConvexFunction.ts +21 -21
  257. package/src/RegisteredFunction.ts +72 -19
  258. package/src/RegisteredFunctions.ts +4 -4
  259. package/src/RegisteredNodeFunction.ts +8 -8
  260. package/src/Registry.ts +1 -1
  261. package/src/RegistryItems.ts +33 -2
  262. package/src/ResolvedMiddleware.ts +2 -2
  263. package/src/Storage.ts +3 -3
  264. package/src/StorageActionWriter.ts +1 -1
  265. package/src/StorageReader.ts +1 -1
  266. package/src/StorageWriter.ts +1 -1
  267. package/src/TableInfo.ts +2 -2
  268. package/src/VectorSearch.ts +1 -1
  269. package/src/index.ts +62 -60
  270. package/src/internal/AiGatewayDecisionClient.ts +2 -2
  271. package/src/internal/AiGatewayLanguageClient.ts +2 -2
  272. package/src/internal/DocumentPatch.ts +87 -0
  273. package/src/node.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStreamCursor.js","names":["QueryStreamKeyValues.QueryStreamKeyValues","QueryStreamKeyLayout.positions","QueryStreamKey.isComplete","QueryStreamKeyLayout.Equivalence","QueryStreamKey.complete"],"sources":["../src/QueryStreamCursor.ts"],"sourcesContent":["import * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as QueryStreamKey from \"./QueryStreamKey\";\nimport * as SchemaIssue from \"effect/SchemaIssue\";\nimport * as Match from \"effect/Match\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaGetter from \"effect/SchemaGetter\";\nimport * as QueryStreamKeyLayout from \"./QueryStreamKeyLayout\";\nimport * as QueryStreamKeyValues from \"./QueryStreamKeyValues\";\n\n// Serialized labels are a cursor boundary representation. They include every\n// runtime position but do not preserve implicitness.\nconst RuntimeLabels = Schema.Array(Schema.String);\nconst RuntimeLabelsEquivalence = Schema.toEquivalence(RuntimeLabels);\nconst positionRuntimeLabel = Match.type<QueryStreamKeyLayout.Position>().pipe(\n Match.tagsExhaustive({\n Visible: ({ label }) => label,\n ImplicitId: () => \"_id\",\n }),\n);\n\n/**\n * @experimental\n */\nexport const QueryStreamCursor = Schema.Struct({\n runtimeLabels: RuntimeLabels,\n keyValues: QueryStreamKeyValues.QueryStreamKeyValues,\n}).check(\n Schema.makeFilter(\n (cursor) => cursor.keyValues.length === cursor.runtimeLabels.length,\n { message: \"key values and runtime labels must have the same length\" },\n ),\n);\n\n/**\n * @experimental\n */\nexport interface QueryStreamCursor extends Schema.Schema.Type<\n typeof QueryStreamCursor\n> {}\n\n/**\n * @experimental\n */\nexport const END_CURSOR = \"[]\";\n\n/**\n * Bind cursor string encoding and decoding to a layout.\n *\n * @experimental\n */\nexport const fromKeyLayout = (\n keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n) => {\n const runtimeLabels = Array.map(\n QueryStreamKeyLayout.positions(keyLayout),\n positionRuntimeLabel,\n );\n return Schema.fromJsonString(QueryStreamCursor)\n .check(\n Schema.makeFilter(\n (cursor) =>\n RuntimeLabelsEquivalence(cursor.runtimeLabels, runtimeLabels),\n { message: \"Cursor runtime labels do not match the stream\" },\n ),\n )\n .pipe(\n Schema.decodeTo(\n Schema.declare(QueryStreamKey.isComplete).check(\n Schema.makeFilter(\n (key) => QueryStreamKeyLayout.Equivalence(key.layout, keyLayout),\n { message: \"Cursor key does not belong to the stream layout\" },\n ),\n ),\n {\n decode: SchemaGetter.transformEffect((cursor, options) =>\n Effect.fromResult(\n QueryStreamKey.complete(keyLayout, cursor.keyValues),\n ).pipe(\n Effect.mapError(\n (error) =>\n new SchemaIssue.InvalidValue(\n { message: error.message },\n cursor.keyValues,\n options,\n ),\n ),\n ),\n ),\n encode: SchemaGetter.transformEffect((key) =>\n QueryStreamCursor.makeEffect({\n runtimeLabels,\n keyValues: key.values,\n }),\n ),\n },\n ),\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAYA,MAAM,gBAAgB,OAAO,MAAM,OAAO,MAAM;AAChD,MAAM,2BAA2B,OAAO,cAAc,aAAa;AACnE,MAAM,uBAAuB,MAAM,KAAoC,CAAC,CAAC,KACvE,MAAM,eAAe;CACnB,UAAU,EAAE,YAAY;CACxB,kBAAkB;AACpB,CAAC,CACH;;;;AAKA,MAAa,oBAAoB,OAAO,OAAO;CAC7C,eAAe;CACf,WAAWA;AACb,CAAC,CAAC,CAAC,MACD,OAAO,YACJ,WAAW,OAAO,UAAU,WAAW,OAAO,cAAc,QAC7D,EAAE,SAAS,0DAA0D,CACvE,CACF;;;;AAYA,MAAa,aAAa;;;;;;AAO1B,MAAa,iBACX,cACG;CACH,MAAM,gBAAgB,MAAM,IAC1BC,UAA+B,SAAS,GACxC,oBACF;CACA,OAAO,OAAO,eAAe,iBAAiB,CAAC,CAC5C,MACC,OAAO,YACJ,WACC,yBAAyB,OAAO,eAAe,aAAa,GAC9D,EAAE,SAAS,gDAAgD,CAC7D,CACF,CAAC,CACA,KACC,OAAO,SACL,OAAO,QAAQC,UAAyB,CAAC,CAAC,MACxC,OAAO,YACJ,QAAQC,YAAiC,IAAI,QAAQ,SAAS,GAC/D,EAAE,SAAS,kDAAkD,CAC/D,CACF,GACA;EACE,QAAQ,aAAa,iBAAiB,QAAQ,YAC5C,OAAO,WACLC,SAAwB,WAAW,OAAO,SAAS,CACrD,CAAC,CAAC,KACA,OAAO,UACJ,UACC,IAAI,YAAY,aACd,EAAE,SAAS,MAAM,QAAQ,GACzB,OAAO,WACP,OACF,CACJ,CACF,CACF;EACA,QAAQ,aAAa,iBAAiB,QACpC,kBAAkB,WAAW;GAC3B;GACA,WAAW,IAAI;EACjB,CAAC,CACH;CACF,CACF,CACF;AACJ"}
1
+ {"version":3,"file":"QueryStreamCursor.js","names":["QueryStreamKeyValues.QueryStreamKeyValues","QueryStreamKeyLayout.positions","QueryStreamKey.isComplete","QueryStreamKeyLayout.Equivalence","QueryStreamKey.complete"],"sources":["../src/QueryStreamCursor.ts"],"sourcesContent":["import * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as QueryStreamKey from \"./QueryStreamKey.js\";\nimport * as SchemaIssue from \"effect/SchemaIssue\";\nimport * as Match from \"effect/Match\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaGetter from \"effect/SchemaGetter\";\nimport * as QueryStreamKeyLayout from \"./QueryStreamKeyLayout.js\";\nimport * as QueryStreamKeyValues from \"./QueryStreamKeyValues.js\";\n\n// Serialized labels are a cursor boundary representation. They include every\n// runtime position but do not preserve implicitness.\nconst RuntimeLabels = Schema.Array(Schema.String);\nconst RuntimeLabelsEquivalence = Schema.toEquivalence(RuntimeLabels);\nconst positionRuntimeLabel = Match.type<QueryStreamKeyLayout.Position>().pipe(\n Match.tagsExhaustive({\n Visible: ({ label }) => label,\n ImplicitId: () => \"_id\",\n }),\n);\n\n/**\n * @experimental\n */\nexport const QueryStreamCursor = Schema.Struct({\n runtimeLabels: RuntimeLabels,\n keyValues: QueryStreamKeyValues.QueryStreamKeyValues,\n}).check(\n Schema.makeFilter(\n (cursor) => cursor.keyValues.length === cursor.runtimeLabels.length,\n { message: \"key values and runtime labels must have the same length\" },\n ),\n);\n\n/**\n * @experimental\n */\nexport interface QueryStreamCursor extends Schema.Schema.Type<\n typeof QueryStreamCursor\n> {}\n\n/**\n * @experimental\n */\nexport const END_CURSOR = \"[]\";\n\n/**\n * Bind cursor string encoding and decoding to a layout.\n *\n * @experimental\n */\nexport const fromKeyLayout = (\n keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n) => {\n const runtimeLabels = Array.map(\n QueryStreamKeyLayout.positions(keyLayout),\n positionRuntimeLabel,\n );\n return Schema.fromJsonString(QueryStreamCursor)\n .check(\n Schema.makeFilter(\n (cursor) =>\n RuntimeLabelsEquivalence(cursor.runtimeLabels, runtimeLabels),\n { message: \"Cursor runtime labels do not match the stream\" },\n ),\n )\n .pipe(\n Schema.decodeTo(\n Schema.declare(QueryStreamKey.isComplete).check(\n Schema.makeFilter(\n (key) => QueryStreamKeyLayout.Equivalence(key.layout, keyLayout),\n { message: \"Cursor key does not belong to the stream layout\" },\n ),\n ),\n {\n decode: SchemaGetter.transformEffect((cursor, options) =>\n Effect.fromResult(\n QueryStreamKey.complete(keyLayout, cursor.keyValues),\n ).pipe(\n Effect.mapError(\n (error) =>\n new SchemaIssue.InvalidValue(\n { message: error.message },\n cursor.keyValues,\n options,\n ),\n ),\n ),\n ),\n encode: SchemaGetter.transformEffect((key) =>\n QueryStreamCursor.makeEffect({\n runtimeLabels,\n keyValues: key.values,\n }),\n ),\n },\n ),\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAYA,MAAM,gBAAgB,OAAO,MAAM,OAAO,MAAM;AAChD,MAAM,2BAA2B,OAAO,cAAc,aAAa;AACnE,MAAM,uBAAuB,MAAM,KAAoC,CAAC,CAAC,KACvE,MAAM,eAAe;CACnB,UAAU,EAAE,YAAY;CACxB,kBAAkB;AACpB,CAAC,CACH;;;;AAKA,MAAa,oBAAoB,OAAO,OAAO;CAC7C,eAAe;CACf,WAAWA;AACb,CAAC,CAAC,CAAC,MACD,OAAO,YACJ,WAAW,OAAO,UAAU,WAAW,OAAO,cAAc,QAC7D,EAAE,SAAS,0DAA0D,CACvE,CACF;;;;AAYA,MAAa,aAAa;;;;;;AAO1B,MAAa,iBACX,cACG;CACH,MAAM,gBAAgB,MAAM,IAC1BC,UAA+B,SAAS,GACxC,oBACF;CACA,OAAO,OAAO,eAAe,iBAAiB,CAAC,CAC5C,MACC,OAAO,YACJ,WACC,yBAAyB,OAAO,eAAe,aAAa,GAC9D,EAAE,SAAS,gDAAgD,CAC7D,CACF,CAAC,CACA,KACC,OAAO,SACL,OAAO,QAAQC,UAAyB,CAAC,CAAC,MACxC,OAAO,YACJ,QAAQC,YAAiC,IAAI,QAAQ,SAAS,GAC/D,EAAE,SAAS,kDAAkD,CAC/D,CACF,GACA;EACE,QAAQ,aAAa,iBAAiB,QAAQ,YAC5C,OAAO,WACLC,SAAwB,WAAW,OAAO,SAAS,CACrD,CAAC,CAAC,KACA,OAAO,UACJ,UACC,IAAI,YAAY,aACd,EAAE,SAAS,MAAM,QAAQ,GACzB,OAAO,WACP,OACF,CACJ,CACF,CACF;EACA,QAAQ,aAAa,iBAAiB,QACpC,kBAAkB,WAAW;GAC3B;GACA,WAAW,IAAI;EACjB,CAAC,CACH;CACF,CACF,CACF;AACJ"}
@@ -1,6 +1,6 @@
1
1
  import * as Result from "effect/Result";
2
- import type * as QueryStreamKey from "./QueryStreamKey";
3
- import type * as QueryStreamKeyValues from "./QueryStreamKeyValues";
2
+ import type * as QueryStreamKey from "./QueryStreamKey.js";
3
+ import type * as QueryStreamKeyValues from "./QueryStreamKeyValues.js";
4
4
  declare const TypeId = "~@confect/server/QueryStreamIndexPrefix";
5
5
  /**
6
6
  * @experimental
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStreamIndexPrefix.d.ts","sourceRoot":"","sources":["../src/QueryStreamIndexPrefix.ts"],"names":[],"mappings":"A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,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,cAAc,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,KAAK,oBAAoB,MAAM,2BAA2B,CAAC;AAEvE,QAAA,MAAM,MAAM,4CAA4C,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,aAAa,CACtC,SAAS,CAAC,MAAM,EAAE,oBAAoB,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CACrE,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;CACjC;;;;AAED;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,mCAEjD;IACA,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;IACA,IAAa,OAAO,IAAI,MAAM,CAE7B;CACF;AAED;;GAEG;AACH,eAAO,MAAM,IAAI,eACH,aAAa,CAAC,MAAM,CAAC,aACtB,oBAAoB,CAAC,oBAAoB,KACnD,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE,6BAA6B,CAQ/D,CAAC;AAER;;GAEG;AACH,eAAO,MAAM,OAAO,SAAU,sBAAsB,KAAG,YACzC,CAAC;AAEf;;GAEG;AACH,eAAO,MAAM,SAAS,SACd,sBAAsB,KAC3B,oBAAoB,CAAC,oBACwB,CAAC;AAEjD;;;;GAIG;AACH,eAAO,MAAM,aAAa,eACZ,aAAa,CAAC,MAAM,CAAC,qBACd,oBAAoB,CAAC,oBAAoB,QACtD,cAAc,CAAC,cAAc,KAClC,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE,6BAA6B,CACH,CAAC"}
@@ -1,6 +1,6 @@
1
+ import * as Data from "effect/Data";
1
2
  import * as Array from "effect/Array";
2
3
  import * as Result from "effect/Result";
3
- import * as Data from "effect/Data";
4
4
  //#region src/QueryStreamIndexPrefix.ts
5
5
  const TypeId = "~@confect/server/QueryStreamIndexPrefix";
6
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStreamIndexPrefix.js","names":[],"sources":["../src/QueryStreamIndexPrefix.ts"],"sourcesContent":["import * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as Result from \"effect/Result\";\nimport type * as QueryStreamKey from \"./QueryStreamKey\";\nimport type * as QueryStreamKeyValues from \"./QueryStreamKeyValues\";\n\nconst TypeId = \"~@confect/server/QueryStreamIndexPrefix\";\n\n/**\n * @experimental\n */\nexport type IndexEntries = ReadonlyArray<\n readonly [string, QueryStreamKeyValues.QueryStreamKeyValues[number]]\n>;\n\n/**\n * Index coordinates retain the field path belonging to each value.\n *\n * @experimental\n */\nexport interface QueryStreamIndexPrefix {\n readonly [TypeId]: IndexEntries;\n}\n\n/**\n * @experimental\n */\nexport class IndexPrefixWidthMismatchError extends Data.TaggedError(\n \"IndexPrefixWidthMismatchError\",\n)<{\n readonly width: number;\n readonly actual: number;\n}> {\n override get message(): string {\n return `Invalid index prefix key width (${this.actual}); expected at most ${this.width}`;\n }\n}\n\n/**\n * @experimental\n */\nexport const make = (\n fieldPaths: ReadonlyArray<string>,\n keyValues: QueryStreamKeyValues.QueryStreamKeyValues,\n): Result.Result<QueryStreamIndexPrefix, IndexPrefixWidthMismatchError> =>\n keyValues.length <= fieldPaths.length\n ? Result.succeed({ [TypeId]: Array.zip(fieldPaths, keyValues) })\n : Result.fail(\n new IndexPrefixWidthMismatchError({\n width: fieldPaths.length,\n actual: keyValues.length,\n }),\n );\n\n/**\n * @experimental\n */\nexport const entries = (self: QueryStreamIndexPrefix): IndexEntries =>\n self[TypeId];\n\n/**\n * @experimental\n */\nexport const keyValues = (\n self: QueryStreamIndexPrefix,\n): QueryStreamKeyValues.QueryStreamKeyValues =>\n Array.map(entries(self), ([, value]) => value);\n\n/**\n * Restore equality values when crossing into index coordinates.\n *\n * @experimental\n */\nexport const fromStreamKey = (\n fieldPaths: ReadonlyArray<string>,\n equalityKeyValues: QueryStreamKeyValues.QueryStreamKeyValues,\n self: QueryStreamKey.QueryStreamKey,\n): Result.Result<QueryStreamIndexPrefix, IndexPrefixWidthMismatchError> =>\n make(fieldPaths, Array.appendAll(equalityKeyValues, self.values));\n"],"mappings":";;;;AAMA,MAAM,SAAS;;;;AAqBf,IAAa,gCAAb,cAAmD,KAAK,YACtD,+BACF,CAAC,CAGE;CACD,IAAa,UAAkB;EAC7B,OAAO,mCAAmC,KAAK,OAAO,sBAAsB,KAAK;CACnF;AACF;;;;AAKA,MAAa,QACX,YACA,cAEA,UAAU,UAAU,WAAW,SAC3B,OAAO,QAAQ,GAAG,SAAS,MAAM,IAAI,YAAY,SAAS,EAAE,CAAC,IAC7D,OAAO,KACL,IAAI,8BAA8B;CAChC,OAAO,WAAW;CAClB,QAAQ,UAAU;AACpB,CAAC,CACH;;;;AAKN,MAAa,WAAW,SACtB,KAAK;;;;AAKP,MAAa,aACX,SAEA,MAAM,IAAI,QAAQ,IAAI,IAAI,GAAG,WAAW,KAAK;;;;;;AAO/C,MAAa,iBACX,YACA,mBACA,SAEA,KAAK,YAAY,MAAM,UAAU,mBAAmB,KAAK,MAAM,CAAC"}
1
+ {"version":3,"file":"QueryStreamIndexPrefix.js","names":[],"sources":["../src/QueryStreamIndexPrefix.ts"],"sourcesContent":["import * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as Result from \"effect/Result\";\nimport type * as QueryStreamKey from \"./QueryStreamKey.js\";\nimport type * as QueryStreamKeyValues from \"./QueryStreamKeyValues.js\";\n\nconst TypeId = \"~@confect/server/QueryStreamIndexPrefix\";\n\n/**\n * @experimental\n */\nexport type IndexEntries = ReadonlyArray<\n readonly [string, QueryStreamKeyValues.QueryStreamKeyValues[number]]\n>;\n\n/**\n * Index coordinates retain the field path belonging to each value.\n *\n * @experimental\n */\nexport interface QueryStreamIndexPrefix {\n readonly [TypeId]: IndexEntries;\n}\n\n/**\n * @experimental\n */\nexport class IndexPrefixWidthMismatchError extends Data.TaggedError(\n \"IndexPrefixWidthMismatchError\",\n)<{\n readonly width: number;\n readonly actual: number;\n}> {\n override get message(): string {\n return `Invalid index prefix key width (${this.actual}); expected at most ${this.width}`;\n }\n}\n\n/**\n * @experimental\n */\nexport const make = (\n fieldPaths: ReadonlyArray<string>,\n keyValues: QueryStreamKeyValues.QueryStreamKeyValues,\n): Result.Result<QueryStreamIndexPrefix, IndexPrefixWidthMismatchError> =>\n keyValues.length <= fieldPaths.length\n ? Result.succeed({ [TypeId]: Array.zip(fieldPaths, keyValues) })\n : Result.fail(\n new IndexPrefixWidthMismatchError({\n width: fieldPaths.length,\n actual: keyValues.length,\n }),\n );\n\n/**\n * @experimental\n */\nexport const entries = (self: QueryStreamIndexPrefix): IndexEntries =>\n self[TypeId];\n\n/**\n * @experimental\n */\nexport const keyValues = (\n self: QueryStreamIndexPrefix,\n): QueryStreamKeyValues.QueryStreamKeyValues =>\n Array.map(entries(self), ([, value]) => value);\n\n/**\n * Restore equality values when crossing into index coordinates.\n *\n * @experimental\n */\nexport const fromStreamKey = (\n fieldPaths: ReadonlyArray<string>,\n equalityKeyValues: QueryStreamKeyValues.QueryStreamKeyValues,\n self: QueryStreamKey.QueryStreamKey,\n): Result.Result<QueryStreamIndexPrefix, IndexPrefixWidthMismatchError> =>\n make(fieldPaths, Array.appendAll(equalityKeyValues, self.values));\n"],"mappings":";;;;AAMA,MAAM,SAAS;;;;AAqBf,IAAa,gCAAb,cAAmD,KAAK,YACtD,+BACF,CAAC,CAGE;CACD,IAAa,UAAkB;EAC7B,OAAO,mCAAmC,KAAK,OAAO,sBAAsB,KAAK;CACnF;AACF;;;;AAKA,MAAa,QACX,YACA,cAEA,UAAU,UAAU,WAAW,SAC3B,OAAO,QAAQ,GAAG,SAAS,MAAM,IAAI,YAAY,SAAS,EAAE,CAAC,IAC7D,OAAO,KACL,IAAI,8BAA8B;CAChC,OAAO,WAAW;CAClB,QAAQ,UAAU;AACpB,CAAC,CACH;;;;AAKN,MAAa,WAAW,SACtB,KAAK;;;;AAKP,MAAa,aACX,SAEA,MAAM,IAAI,QAAQ,IAAI,IAAI,GAAG,WAAW,KAAK;;;;;;AAO/C,MAAa,iBACX,YACA,mBACA,SAEA,KAAK,YAAY,MAAM,UAAU,mBAAmB,KAAK,MAAM,CAAC"}
@@ -3,10 +3,10 @@ import * as Data from "effect/Data";
3
3
  import * as Option from "effect/Option";
4
4
  import * as Result from "effect/Result";
5
5
  import type * as Types from "effect/Types";
6
- import * as QueryStreamIndexPrefix from "./QueryStreamIndexPrefix";
7
- import * as QueryStreamKeyBounds from "./QueryStreamKeyBounds";
8
- import * as QueryStreamKeyValues from "./QueryStreamKeyValues";
9
- import type * as QueryStreamOrderDirection from "./QueryStreamOrderDirection";
6
+ import * as QueryStreamIndexPrefix from "./QueryStreamIndexPrefix.js";
7
+ import * as QueryStreamKeyBounds from "./QueryStreamKeyBounds.js";
8
+ import * as QueryStreamKeyValues from "./QueryStreamKeyValues.js";
9
+ import type * as QueryStreamOrderDirection from "./QueryStreamOrderDirection.js";
10
10
  type Head<FieldPaths extends ReadonlyArray<string>> = FieldPaths extends readonly [infer H extends string, ...ReadonlyArray<string>] ? H : never;
11
11
  type Tail<FieldPaths extends ReadonlyArray<string>> = FieldPaths extends readonly [
12
12
  string,
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStreamIndexRange.d.ts","sourceRoot":"","sources":["../src/QueryStreamIndexRange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACtB,UAAU,IAAI,gBAAgB,EAC9B,iBAAiB,IAAI,uBAAuB,EAC7C,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAGpC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,OA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KACvD,qBAAqB,CAAC,UAAU,CAAC,CAAC;IACvC,QAAQ,CAAC,GAAG,EAAE,CACZ,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,EAC3B,KAAK,EAAE,sBAAsB,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,KACvD,qBAAqB,CAAC,UAAU,CAAC,CAAC;CACxC;AAiED;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAClB,SAAS,SAAS,eAAe,EACjC,UAAU,SAAS,aAAa,CAAC,MAAM,CAAC,OACrC,OAAO,CAAC,SAAS,EAAE,UAAU,CAC4B,CAAC;AAE/D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,SAAU,qBAAqB,KAAG,MACnC,CAAC;AA4BjC;;;;GAIG;AACH,eAAO,MAAM,KAAK,SACV,qBAAqB,KACxB,uBAAuB,CAAC,eAAe,EAAE,MAAM,EAAE,CAAC,KACpD,gBA+BF,CAAC;AA+EF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,eACT,aAAa,CAAC,MAAM,CAAC,kBACjB,yBAAyB,CAAC,yBAAyB,eACtD,oBAAoB,CAAC,WAAW,KAC5C,MAAM,CAAC,MAAM,CACd,aAAa,CAAC,qBAAqB,CAAC,EACpC,sBAAsB,CAAC,6BAA6B,CAqFlD,CAAC;AAEL;;;;GAIG;AACH,eAAO,MAAM,QAAQ,SACb,qBAAqB,KAC1B,oBAAoB,CAAC,WAoBvB,CAAC"}
@@ -2,12 +2,12 @@ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { ValueOrder } from "./QueryStreamKeyValues.js";
3
3
  import { entries, make as make$1 } from "./QueryStreamIndexPrefix.js";
4
4
  import { isEmpty } from "./QueryStreamKeyBounds.js";
5
+ import * as Data from "effect/Data";
6
+ import * as Array from "effect/Array";
5
7
  import { identity, pipe } from "effect/Function";
6
8
  import * as Match from "effect/Match";
7
9
  import * as Option from "effect/Option";
8
- import * as Array from "effect/Array";
9
10
  import * as Result from "effect/Result";
10
- import * as Data from "effect/Data";
11
11
  //#region src/QueryStreamIndexRange.ts
12
12
  var QueryStreamIndexRange_exports = /* @__PURE__ */ __exportAll({
13
13
  apply: () => apply,
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStreamIndexRange.js","names":["QueryStreamIndexPrefix.entries","QueryStreamIndexPrefix.make","QueryStreamKeyBounds.isEmpty","QueryStreamKeyValues.ValueOrder"],"sources":["../src/QueryStreamIndexRange.ts"],"sourcesContent":["import type {\n GenericDocument,\n FieldTypeFromFieldPath,\n IndexRange as ConvexIndexRange,\n IndexRangeBuilder as ConvexIndexRangeBuilder,\n} from \"convex/server\";\nimport * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport { identity, pipe } from \"effect/Function\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Result from \"effect/Result\";\nimport type * as Types from \"effect/Types\";\nimport * as QueryStreamIndexPrefix from \"./QueryStreamIndexPrefix\";\nimport * as QueryStreamKeyBounds from \"./QueryStreamKeyBounds\";\nimport * as QueryStreamKeyValues from \"./QueryStreamKeyValues\";\nimport type * as QueryStreamOrderDirection from \"./QueryStreamOrderDirection\";\n\ntype Head<FieldPaths extends ReadonlyArray<string>> =\n FieldPaths extends readonly [infer H extends string, ...ReadonlyArray<string>]\n ? H\n : never;\n\ntype Tail<FieldPaths extends ReadonlyArray<string>> =\n FieldPaths extends readonly [\n string,\n ...infer Rest extends ReadonlyArray<string>,\n ]\n ? Rest\n : ReadonlyArray<string>;\n\n// The range builder mirrors Convex's `IndexRangeBuilder`, but *consumes* the\n// index-field tuple at the type level as `eq` pins field paths. The remaining\n// tuple supplies the initial visible ordering labels of the resulting stream.\n\nconst TypeId = \"~@confect/server/QueryStreamIndexRange\";\n\ninterface Equality {\n readonly fieldPath: string;\n readonly value: QueryStreamKeyValues.KeyValue;\n}\n\ninterface Endpoint {\n readonly value: QueryStreamKeyValues.KeyValue;\n readonly inclusive: boolean;\n}\n\ntype Interval = Data.TaggedEnum<{\n Lower: { readonly lower: Endpoint };\n Upper: { readonly upper: Endpoint };\n Between: { readonly lower: Endpoint; readonly upper: Endpoint };\n}>;\nconst Interval = Data.taggedEnum<Interval>();\n\ninterface Constraints {\n readonly equalities: ReadonlyArray<Equality>;\n readonly bounded: Option.Option<{\n readonly fieldPath: string;\n readonly interval: Interval;\n }>;\n}\n\n/**\n * The equality prefix followed by at most one bounded field.\n *\n * @experimental\n */\nexport interface QueryStreamIndexRange<\n out RemainingFieldPaths extends ReadonlyArray<string> = ReadonlyArray<string>,\n> {\n readonly [TypeId]: Constraints & {\n readonly _Remaining: Types.Covariant<RemainingFieldPaths>;\n };\n}\n\n/**\n * @experimental\n */\nexport type Remaining<IndexRange> =\n IndexRange extends QueryStreamIndexRange<infer RemainingFieldPaths>\n ? RemainingFieldPaths\n : never;\n\n/**\n * A typed index-range builder. `eq` must target the next unpinned index field,\n * and consumes it; `gt`/`gte`/`lt`/`lte` bound the next field without consuming\n * it (bounded field paths still vary within the range).\n *\n * @experimental\n */\nexport interface Builder<\n ConvexDoc extends GenericDocument,\n FieldPaths extends ReadonlyArray<string>,\n> extends QueryStreamIndexRange<FieldPaths> {\n readonly eq: (\n fieldPath: Head<FieldPaths>,\n value: FieldTypeFromFieldPath<ConvexDoc, Head<FieldPaths>>,\n ) => Builder<ConvexDoc, Tail<FieldPaths>>;\n readonly gt: (\n fieldPath: Head<FieldPaths>,\n value: FieldTypeFromFieldPath<ConvexDoc, Head<FieldPaths>>,\n ) => LowerBoundedBuilder<ConvexDoc, FieldPaths>;\n readonly gte: (\n fieldPath: Head<FieldPaths>,\n value: FieldTypeFromFieldPath<ConvexDoc, Head<FieldPaths>>,\n ) => LowerBoundedBuilder<ConvexDoc, FieldPaths>;\n readonly lt: (\n fieldPath: Head<FieldPaths>,\n value: FieldTypeFromFieldPath<ConvexDoc, Head<FieldPaths>>,\n ) => QueryStreamIndexRange<FieldPaths>;\n readonly lte: (\n fieldPath: Head<FieldPaths>,\n value: FieldTypeFromFieldPath<ConvexDoc, Head<FieldPaths>>,\n ) => QueryStreamIndexRange<FieldPaths>;\n}\n\n/**\n * After `gt`/`gte`, only an upper bound on the same field may follow.\n *\n * @experimental\n */\nexport interface LowerBoundedBuilder<\n ConvexDoc extends GenericDocument,\n FieldPaths extends ReadonlyArray<string>,\n> extends QueryStreamIndexRange<FieldPaths> {\n readonly lt: (\n fieldPath: Head<FieldPaths>,\n value: FieldTypeFromFieldPath<ConvexDoc, Head<FieldPaths>>,\n ) => QueryStreamIndexRange<FieldPaths>;\n readonly lte: (\n fieldPath: Head<FieldPaths>,\n value: FieldTypeFromFieldPath<ConvexDoc, Head<FieldPaths>>,\n ) => QueryStreamIndexRange<FieldPaths>;\n}\n\nconst make = (constraints: Constraints): QueryStreamIndexRange => ({\n [TypeId]: {\n ...constraints,\n _Remaining: identity as Types.Covariant<ReadonlyArray<string>>,\n },\n});\n\nconst makeBuilder = (\n equalities: ReadonlyArray<Equality>,\n): Builder<GenericDocument, ReadonlyArray<string>> => {\n const upper =\n (inclusive: boolean) =>\n (fieldPath: string, value: QueryStreamKeyValues.KeyValue) =>\n make({\n equalities,\n bounded: Option.some({\n fieldPath,\n interval: Interval.Upper({ upper: { value, inclusive } }),\n }),\n });\n const lower =\n (inclusive: boolean) =>\n (\n fieldPath: string,\n value: QueryStreamKeyValues.KeyValue,\n ): LowerBoundedBuilder<GenericDocument, ReadonlyArray<string>> => {\n const endpoint = { value, inclusive };\n const finish =\n (upperInclusive: boolean) =>\n (_fieldPath: string, upperValue: QueryStreamKeyValues.KeyValue) =>\n make({\n equalities,\n bounded: Option.some({\n fieldPath,\n interval: Interval.Between({\n lower: endpoint,\n upper: { value: upperValue, inclusive: upperInclusive },\n }),\n }),\n });\n return {\n ...make({\n equalities,\n bounded: Option.some({\n fieldPath,\n interval: Interval.Lower({ lower: endpoint }),\n }),\n }),\n lt: finish(false),\n lte: finish(true),\n };\n };\n return {\n ...make({ equalities, bounded: Option.none() }),\n eq: (fieldPath, value) =>\n makeBuilder(Array.append(equalities, { fieldPath, value })),\n gt: lower(false),\n gte: lower(true),\n lt: upper(false),\n lte: upper(true),\n };\n};\n\n/**\n * The initial builder handed to a range callback.\n *\n * @experimental\n */\nexport const builder = <\n ConvexDoc extends GenericDocument,\n FieldPaths extends ReadonlyArray<string>,\n>(): Builder<ConvexDoc, FieldPaths> =>\n makeBuilder([]) as unknown as Builder<ConvexDoc, FieldPaths>;\n\n/**\n * Number of index fields pinned by equality constraints.\n *\n * @experimental\n */\nexport const equalityPrefixLength = (self: QueryStreamIndexRange): number =>\n self[TypeId].equalities.length;\n\ninterface ConvexUpperBoundBuilder extends ConvexIndexRange {\n readonly lt: (\n fieldPath: string,\n value: QueryStreamKeyValues.KeyValue,\n ) => ConvexIndexRange;\n readonly lte: (\n fieldPath: string,\n value: QueryStreamKeyValues.KeyValue,\n ) => ConvexIndexRange;\n}\n\ninterface ConvexRangeBuilder extends ConvexUpperBoundBuilder {\n readonly eq: (\n fieldPath: string,\n value: QueryStreamKeyValues.KeyValue,\n ) => ConvexRangeBuilder;\n readonly gt: (\n fieldPath: string,\n value: QueryStreamKeyValues.KeyValue,\n ) => ConvexUpperBoundBuilder;\n readonly gte: (\n fieldPath: string,\n value: QueryStreamKeyValues.KeyValue,\n ) => ConvexUpperBoundBuilder;\n}\n\n/**\n * Apply one range to Convex's index-range builder.\n *\n * @experimental\n */\nexport const apply = (\n self: QueryStreamIndexRange,\n q: ConvexIndexRangeBuilder<GenericDocument, string[]>,\n): ConvexIndexRange => {\n const { equalities, bounded } = self[TypeId];\n // Convex tracks equality progress through a static field tuple. These paths\n // are runtime data; the range model owns their ordering. Its runtime builder\n // supports further equality calls, even when the SDK type has lost the tuple.\n const prefix = Array.reduce(\n equalities,\n q as ConvexRangeBuilder,\n (target, { fieldPath, value }) => target.eq(fieldPath, value),\n );\n return Option.match(bounded, {\n onNone: () => prefix,\n onSome: ({ fieldPath, interval }) => {\n const lower = (\n target: ConvexRangeBuilder,\n endpoint: Endpoint,\n ): ConvexUpperBoundBuilder =>\n target[endpoint.inclusive ? \"gte\" : \"gt\"](fieldPath, endpoint.value);\n const upper = (\n target: ConvexUpperBoundBuilder,\n endpoint: Endpoint,\n ): ConvexIndexRange =>\n target[endpoint.inclusive ? \"lte\" : \"lt\"](fieldPath, endpoint.value);\n return Interval.$match(interval, {\n Lower: ({ lower: endpoint }) => lower(prefix, endpoint),\n Upper: ({ upper: endpoint }) => upper(prefix, endpoint),\n Between: (endpoints) =>\n upper(lower(prefix, endpoints.lower), endpoints.upper),\n });\n },\n });\n};\n\n// Convex index ranges have the shape `eq(f1) … eq(fn), gt/gte(fm)?,\n// lt/lte(fm)?`—every field path pinned except the last, which may carry two\n// inequalities. An arbitrary range between two index keys therefore\n// decomposes into a *sequence* of Convex-expressible ranges (the port of\n// `convex-helpers`' `splitRange`): e.g. `(1, 2, 3) < key <= (1, 3, 2)` over\n// field paths `(f1, f2, f3)` becomes\n//\n// 1. eq(f1, 1), eq(f2, 2), gt(f3, 3)\n// 2. eq(f1, 1), gt(f2, 2), lt(f2, 3)\n// 3. eq(f1, 1), eq(f2, 3), lte(f3, 2)\n\ntype BoundTag = \"gt\" | \"gte\" | \"lt\" | \"lte\";\n\nclass TaggedBound extends Data.Class<{\n readonly indexEntries: QueryStreamIndexPrefix.IndexEntries;\n readonly tag: BoundTag;\n}> {}\n\n/**\n * Dropping a bound's last entry bounds the remaining prefix exclusively.\n */\nconst excludePrefix = (tag: BoundTag): BoundTag =>\n Match.value(tag).pipe(\n Match.whenOr(\"gt\", \"gte\", () => \"gt\" as const),\n Match.whenOr(\"lt\", \"lte\", () => \"lt\" as const),\n Match.exhaustive,\n );\n\n/**\n * Peel a bound down to the single entry that feeds the middle range.\n */\nconst peelBound = (\n indexEntries: QueryStreamIndexPrefix.IndexEntries,\n tag: BoundTag,\n): {\n readonly peeled: ReadonlyArray<TaggedBound>;\n readonly final: TaggedBound;\n} =>\n indexEntries.length <= 1\n ? { peeled: [], final: new TaggedBound({ indexEntries, tag }) }\n : pipe(\n peelBound(Array.dropRight(indexEntries, 1), excludePrefix(tag)),\n ({ final, peeled }) => ({\n peeled: Array.prepend(peeled, new TaggedBound({ indexEntries, tag })),\n final,\n }),\n );\n\n/**\n * Pin every entry but the last, which gets the bound tag.\n */\nconst rangeFor = (\n prefix: ReadonlyArray<Equality>,\n indexEntries: QueryStreamIndexPrefix.IndexEntries,\n tag: BoundTag,\n): QueryStreamIndexRange =>\n Option.match(Array.last(indexEntries), {\n onNone: () => make({ equalities: prefix, bounded: Option.none() }),\n onSome: ([fieldPath, value]) =>\n make({\n equalities: Array.appendAll(\n prefix,\n Array.map(Array.dropRight(indexEntries, 1), ([path, pinned]) => ({\n fieldPath: path,\n value: pinned,\n })),\n ),\n bounded: Option.some({\n fieldPath,\n interval:\n tag === \"gt\" || tag === \"gte\"\n ? Interval.Lower({ lower: { value, inclusive: tag === \"gte\" } })\n : Interval.Upper({ upper: { value, inclusive: tag === \"lte\" } }),\n }),\n }),\n });\n\n/**\n * Decompose the range between `indexBounds.lower` and `indexBounds.upper` (over\n * the complete index `fieldPaths`, `_id` tiebreaker included) into a sequence\n * of Convex-expressible ranges, ordered for the given direction.\n *\n * @experimental\n */\nexport const fromBounds = (\n fieldPaths: ReadonlyArray<string>,\n orderDirection: QueryStreamOrderDirection.QueryStreamOrderDirection,\n indexBounds: QueryStreamKeyBounds.IndexBounds,\n): Result.Result<\n ReadonlyArray<QueryStreamIndexRange>,\n QueryStreamIndexPrefix.IndexPrefixWidthMismatchError\n> =>\n Result.gen(function* () {\n const lowerIndexEntries = QueryStreamIndexPrefix.entries(\n yield* QueryStreamIndexPrefix.make(\n fieldPaths,\n indexBounds.lower.keyValues,\n ),\n );\n const upperIndexEntries = QueryStreamIndexPrefix.entries(\n yield* QueryStreamIndexPrefix.make(\n fieldPaths,\n indexBounds.upper.keyValues,\n ),\n );\n // Equal cuts are an empty range too: e.g. lower exclusive at `k` and\n // upper inclusive at `k`—the half-open (k, k]—both cut at\n // successor(k).\n if (QueryStreamKeyBounds.isEmpty(indexBounds)) {\n return [];\n }\n\n const commonLength = pipe(\n Array.zip(indexBounds.lower.keyValues, indexBounds.upper.keyValues),\n Array.takeWhile(\n ([lowerValue, upperValue]) =>\n QueryStreamKeyValues.ValueOrder(lowerValue, upperValue) === 0,\n ),\n Array.length,\n );\n const equalities = pipe(\n Array.take(lowerIndexEntries, commonLength),\n Array.map(([fieldPath, value]) => ({ fieldPath, value })),\n );\n\n const lower = peelBound(\n Array.drop(lowerIndexEntries, commonLength),\n indexBounds.lower.inclusive ? \"gte\" : \"gt\",\n );\n const upper = peelBound(\n Array.drop(upperIndexEntries, commonLength),\n indexBounds.upper.inclusive ? \"lte\" : \"lt\",\n );\n\n const startIndexRanges = Array.map(lower.peeled, ({ indexEntries, tag }) =>\n rangeFor(equalities, indexEntries, tag),\n );\n const endIndexRanges = Array.reverse(\n Array.map(upper.peeled, ({ indexEntries, tag }) =>\n rangeFor(equalities, indexEntries, tag),\n ),\n );\n\n const { indexEntries: lowerFinalIndexEntries, tag: lowerFinalTag } =\n lower.final;\n const { indexEntries: upperFinalIndexEntries, tag: upperFinalTag } =\n upper.final;\n const middleIndexRange =\n Array.isReadonlyArrayNonEmpty(lowerFinalIndexEntries) &&\n Array.isReadonlyArrayNonEmpty(upperFinalIndexEntries)\n ? make({\n equalities,\n bounded: Option.some({\n fieldPath: Array.headNonEmpty(lowerFinalIndexEntries)[0],\n interval: Interval.Between({\n lower: {\n value: Array.headNonEmpty(lowerFinalIndexEntries)[1],\n inclusive: lowerFinalTag === \"gte\",\n },\n upper: {\n value: Array.headNonEmpty(upperFinalIndexEntries)[1],\n inclusive: upperFinalTag === \"lte\",\n },\n }),\n }),\n })\n : Array.isReadonlyArrayNonEmpty(lowerFinalIndexEntries)\n ? rangeFor(equalities, lowerFinalIndexEntries, lowerFinalTag)\n : rangeFor(equalities, upperFinalIndexEntries, upperFinalTag);\n\n const indexRanges = Array.appendAll(\n Array.appendAll(startIndexRanges, Array.of(middleIndexRange)),\n endIndexRanges,\n );\n return orderDirection === \"desc\" ? Array.reverse(indexRanges) : indexRanges;\n });\n\n/**\n * Derive full-index bounds directly from the structural range.\n *\n * @experimental\n */\nexport const toBounds = (\n self: QueryStreamIndexRange,\n): QueryStreamKeyBounds.IndexBounds => {\n const { equalities, bounded } = self[TypeId];\n const keyValues = Array.map(equalities, (equality) => equality.value);\n const unbounded = { keyValues, inclusive: true };\n const endpoint = ({ value, inclusive }: Endpoint) => ({\n keyValues: Array.append(keyValues, value),\n inclusive,\n });\n return Option.match(bounded, {\n onNone: () => ({ lower: unbounded, upper: unbounded }),\n onSome: ({ interval }) =>\n Interval.$match(interval, {\n Lower: ({ lower }) => ({ lower: endpoint(lower), upper: unbounded }),\n Upper: ({ upper }) => ({ lower: unbounded, upper: endpoint(upper) }),\n Between: ({ lower, upper }) => ({\n lower: endpoint(lower),\n upper: endpoint(upper),\n }),\n }),\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmCA,MAAM,SAAS;AAiBf,MAAM,WAAW,KAAK,WAAqB;AAmF3C,MAAM,QAAQ,iBAAqD,GAChE,SAAS;CACR,GAAG;CACH,YAAY;AACd,EACF;AAEA,MAAM,eACJ,eACoD;CACpD,MAAM,SACH,eACA,WAAmB,UAClB,KAAK;EACH;EACA,SAAS,OAAO,KAAK;GACnB;GACA,UAAU,SAAS,MAAM,EAAE,OAAO;IAAE;IAAO;GAAU,EAAE,CAAC;EAC1D,CAAC;CACH,CAAC;CACL,MAAM,SACH,eAEC,WACA,UACgE;EAChE,MAAM,WAAW;GAAE;GAAO;EAAU;EACpC,MAAM,UACH,oBACA,YAAoB,eACnB,KAAK;GACH;GACA,SAAS,OAAO,KAAK;IACnB;IACA,UAAU,SAAS,QAAQ;KACzB,OAAO;KACP,OAAO;MAAE,OAAO;MAAY,WAAW;KAAe;IACxD,CAAC;GACH,CAAC;EACH,CAAC;EACL,OAAO;GACL,GAAG,KAAK;IACN;IACA,S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AAM,UAAU,kBAAkB,MAAM,GAAG,gBAAgB,CAAC,GAC5D,cACF;CACA,OAAO,mBAAmB,SAAS,MAAM,QAAQ,WAAW,IAAI;AAClE,CAAC;;;;;;AAOH,MAAa,YACX,SACqC;CACrC,MAAM,EAAE,YAAY,YAAY,KAAK;CACrC,MAAM,YAAY,MAAM,IAAI,aAAa,aAAa,SAAS,KAAK;CACpE,MAAM,YAAY;EAAE;EAAW,WAAW;CAAK;CAC/C,MAAM,YAAY,EAAE,OAAO,iBAA2B;EACpD,WAAW,MAAM,OAAO,WAAW,KAAK;EACxC;CACF;CACA,OAAO,OAAO,MAAM,SAAS;EAC3B,eAAe;GAAE,OAAO;GAAW,OAAO;EAAU;EACpD,SAAS,EAAE,eACT,SAAS,OAAO,UAAU;GACxB,QAAQ,EAAE,aAAa;IAAE,OAAO,SAAS,KAAK;IAAG,OAAO;GAAU;GAClE,QAAQ,EAAE,aAAa;IAAE,OAAO;IAAW,OAAO,SAAS,KAAK;GAAE;GAClE,UAAU,EAAE,OAAO,aAAa;IAC9B,OAAO,SAAS,KAAK;IACrB,OAAO,SAAS,KAAK;GACvB;EACF,CAAC;CACL,CAAC;AACH"}
1
+ {"version":3,"file":"QueryStreamIndexRange.js","names":["QueryStreamIndexPrefix.entries","QueryStreamIndexPrefix.make","QueryStreamKeyBounds.isEmpty","QueryStreamKeyValues.ValueOrder"],"sources":["../src/QueryStreamIndexRange.ts"],"sourcesContent":["import type {\n GenericDocument,\n FieldTypeFromFieldPath,\n IndexRange as ConvexIndexRange,\n IndexRangeBuilder as ConvexIndexRangeBuilder,\n} from \"convex/server\";\nimport * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport { identity, pipe } from \"effect/Function\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Result from \"effect/Result\";\nimport type * as Types from \"effect/Types\";\nimport * as QueryStreamIndexPrefix from \"./QueryStreamIndexPrefix.js\";\nimport * as QueryStreamKeyBounds from \"./QueryStreamKeyBounds.js\";\nimport * as QueryStreamKeyValues from \"./QueryStreamKeyValues.js\";\nimport type * as QueryStreamOrderDirection from \"./QueryStreamOrderDirection.js\";\n\ntype Head<FieldPaths extends ReadonlyArray<string>> =\n FieldPaths extends readonly [infer H extends string, ...ReadonlyArray<string>]\n ? H\n : never;\n\ntype Tail<FieldPaths extends ReadonlyArray<string>> =\n FieldPaths extends readonly [\n string,\n ...infer Rest extends ReadonlyArray<string>,\n ]\n ? Rest\n : ReadonlyArray<string>;\n\n// The range builder mirrors Convex's `IndexRangeBuilder`, but *consumes* the\n// index-field tuple at the type level as `eq` pins field paths. The remaining\n// tuple supplies the initial visible ordering labels of the resulting stream.\n\nconst TypeId = \"~@confect/server/QueryStreamIndexRange\";\n\ninterface Equality {\n readonly fieldPath: string;\n readonly value: QueryStreamKeyValues.KeyValue;\n}\n\ninterface Endpoint {\n readonly value: QueryStreamKeyValues.KeyValue;\n readonly inclusive: boolean;\n}\n\ntype Interval = Data.TaggedEnum<{\n Lower: { readonly lower: Endpoint };\n Upper: { readonly upper: Endpoint };\n Between: { readonly lower: Endpoint; readonly upper: Endpoint };\n}>;\nconst Interval = Data.taggedEnum<Interval>();\n\ninterface Constraints {\n readonly equalities: ReadonlyArray<Equality>;\n readonly bounded: Option.Option<{\n readonly fieldPath: string;\n readonly interval: Interval;\n }>;\n}\n\n/**\n * The equality prefix followed by at most one bounded field.\n *\n * @experimental\n */\nexport interface QueryStreamIndexRange<\n out RemainingFieldPaths extends ReadonlyArray<string> = ReadonlyArray<string>,\n> {\n readonly [TypeId]: Constraints & {\n readonly _Remaining: Types.Covariant<RemainingFieldPaths>;\n };\n}\n\n/**\n * @experimental\n */\nexport type Remaining<IndexRange> =\n IndexRange extends QueryStreamIndexRange<infer RemainingFieldPaths>\n ? RemainingFieldPaths\n : never;\n\n/**\n * A typed index-range builder. `eq` must target the next unpinned index field,\n * and consumes it; `gt`/`gte`/`lt`/`lte` bound the next field without consuming\n * it (bounded field paths still vary within the range).\n *\n * @experimental\n */\nexport interface Builder<\n ConvexDoc extends GenericDocument,\n FieldPaths extends ReadonlyArray<string>,\n> extends QueryStreamIndexRange<FieldPaths> {\n readonly eq: (\n fieldPath: Head<FieldPaths>,\n value: FieldTypeFromFieldPath<ConvexDoc, Head<FieldPaths>>,\n ) => Builder<ConvexDoc, Tail<FieldPaths>>;\n readonly gt: (\n fieldPath: Head<FieldPaths>,\n value: FieldTypeFromFieldPath<ConvexDoc, Head<FieldPaths>>,\n ) => LowerBoundedBuilder<ConvexDoc, FieldPaths>;\n readonly gte: (\n fieldPath: Head<FieldPaths>,\n value: FieldTypeFromFieldPath<ConvexDoc, Head<FieldPaths>>,\n ) => LowerBoundedBuilder<ConvexDoc, FieldPaths>;\n readonly lt: (\n fieldPath: Head<FieldPaths>,\n value: FieldTypeFromFieldPath<ConvexDoc, Head<FieldPaths>>,\n ) => QueryStreamIndexRange<FieldPaths>;\n readonly lte: (\n fieldPath: Head<FieldPaths>,\n value: FieldTypeFromFieldPath<ConvexDoc, Head<FieldPaths>>,\n ) => QueryStreamIndexRange<FieldPaths>;\n}\n\n/**\n * After `gt`/`gte`, only an upper bound on the same field may follow.\n *\n * @experimental\n */\nexport interface LowerBoundedBuilder<\n ConvexDoc extends GenericDocument,\n FieldPaths extends ReadonlyArray<string>,\n> extends QueryStreamIndexRange<FieldPaths> {\n readonly lt: (\n fieldPath: Head<FieldPaths>,\n value: FieldTypeFromFieldPath<ConvexDoc, Head<FieldPaths>>,\n ) => QueryStreamIndexRange<FieldPaths>;\n readonly lte: (\n fieldPath: Head<FieldPaths>,\n value: FieldTypeFromFieldPath<ConvexDoc, Head<FieldPaths>>,\n ) => QueryStreamIndexRange<FieldPaths>;\n}\n\nconst make = (constraints: Constraints): QueryStreamIndexRange => ({\n [TypeId]: {\n ...constraints,\n _Remaining: identity as Types.Covariant<ReadonlyArray<string>>,\n },\n});\n\nconst makeBuilder = (\n equalities: ReadonlyArray<Equality>,\n): Builder<GenericDocument, ReadonlyArray<string>> => {\n const upper =\n (inclusive: boolean) =>\n (fieldPath: string, value: QueryStreamKeyValues.KeyValue) =>\n make({\n equalities,\n bounded: Option.some({\n fieldPath,\n interval: Interval.Upper({ upper: { value, inclusive } }),\n }),\n });\n const lower =\n (inclusive: boolean) =>\n (\n fieldPath: string,\n value: QueryStreamKeyValues.KeyValue,\n ): LowerBoundedBuilder<GenericDocument, ReadonlyArray<string>> => {\n const endpoint = { value, inclusive };\n const finish =\n (upperInclusive: boolean) =>\n (_fieldPath: string, upperValue: QueryStreamKeyValues.KeyValue) =>\n make({\n equalities,\n bounded: Option.some({\n fieldPath,\n interval: Interval.Between({\n lower: endpoint,\n upper: { value: upperValue, inclusive: upperInclusive },\n }),\n }),\n });\n return {\n ...make({\n equalities,\n bounded: Option.some({\n fieldPath,\n interval: Interval.Lower({ lower: endpoint }),\n }),\n }),\n lt: finish(false),\n lte: finish(true),\n };\n };\n return {\n ...make({ equalities, bounded: Option.none() }),\n eq: (fieldPath, value) =>\n makeBuilder(Array.append(equalities, { fieldPath, value })),\n gt: lower(false),\n gte: lower(true),\n lt: upper(false),\n lte: upper(true),\n };\n};\n\n/**\n * The initial builder handed to a range callback.\n *\n * @experimental\n */\nexport const builder = <\n ConvexDoc extends GenericDocument,\n FieldPaths extends ReadonlyArray<string>,\n>(): Builder<ConvexDoc, FieldPaths> =>\n makeBuilder([]) as unknown as Builder<ConvexDoc, FieldPaths>;\n\n/**\n * Number of index fields pinned by equality constraints.\n *\n * @experimental\n */\nexport const equalityPrefixLength = (self: QueryStreamIndexRange): number =>\n self[TypeId].equalities.length;\n\ninterface ConvexUpperBoundBuilder extends ConvexIndexRange {\n readonly lt: (\n fieldPath: string,\n value: QueryStreamKeyValues.KeyValue,\n ) => ConvexIndexRange;\n readonly lte: (\n fieldPath: string,\n value: QueryStreamKeyValues.KeyValue,\n ) => ConvexIndexRange;\n}\n\ninterface ConvexRangeBuilder extends ConvexUpperBoundBuilder {\n readonly eq: (\n fieldPath: string,\n value: QueryStreamKeyValues.KeyValue,\n ) => ConvexRangeBuilder;\n readonly gt: (\n fieldPath: string,\n value: QueryStreamKeyValues.KeyValue,\n ) => ConvexUpperBoundBuilder;\n readonly gte: (\n fieldPath: string,\n value: QueryStreamKeyValues.KeyValue,\n ) => ConvexUpperBoundBuilder;\n}\n\n/**\n * Apply one range to Convex's index-range builder.\n *\n * @experimental\n */\nexport const apply = (\n self: QueryStreamIndexRange,\n q: ConvexIndexRangeBuilder<GenericDocument, string[]>,\n): ConvexIndexRange => {\n const { equalities, bounded } = self[TypeId];\n // Convex tracks equality progress through a static field tuple. These paths\n // are runtime data; the range model owns their ordering. Its runtime builder\n // supports further equality calls, even when the SDK type has lost the tuple.\n const prefix = Array.reduce(\n equalities,\n q as ConvexRangeBuilder,\n (target, { fieldPath, value }) => target.eq(fieldPath, value),\n );\n return Option.match(bounded, {\n onNone: () => prefix,\n onSome: ({ fieldPath, interval }) => {\n const lower = (\n target: ConvexRangeBuilder,\n endpoint: Endpoint,\n ): ConvexUpperBoundBuilder =>\n target[endpoint.inclusive ? \"gte\" : \"gt\"](fieldPath, endpoint.value);\n const upper = (\n target: ConvexUpperBoundBuilder,\n endpoint: Endpoint,\n ): ConvexIndexRange =>\n target[endpoint.inclusive ? \"lte\" : \"lt\"](fieldPath, endpoint.value);\n return Interval.$match(interval, {\n Lower: ({ lower: endpoint }) => lower(prefix, endpoint),\n Upper: ({ upper: endpoint }) => upper(prefix, endpoint),\n Between: (endpoints) =>\n upper(lower(prefix, endpoints.lower), endpoints.upper),\n });\n },\n });\n};\n\n// Convex index ranges have the shape `eq(f1) … eq(fn), gt/gte(fm)?,\n// lt/lte(fm)?`—every field path pinned except the last, which may carry two\n// inequalities. An arbitrary range between two index keys therefore\n// decomposes into a *sequence* of Convex-expressible ranges (the port of\n// `convex-helpers`' `splitRange`): e.g. `(1, 2, 3) < key <= (1, 3, 2)` over\n// field paths `(f1, f2, f3)` becomes\n//\n// 1. eq(f1, 1), eq(f2, 2), gt(f3, 3)\n// 2. eq(f1, 1), gt(f2, 2), lt(f2, 3)\n// 3. eq(f1, 1), eq(f2, 3), lte(f3, 2)\n\ntype BoundTag = \"gt\" | \"gte\" | \"lt\" | \"lte\";\n\nclass TaggedBound extends Data.Class<{\n readonly indexEntries: QueryStreamIndexPrefix.IndexEntries;\n readonly tag: BoundTag;\n}> {}\n\n/**\n * Dropping a bound's last entry bounds the remaining prefix exclusively.\n */\nconst excludePrefix = (tag: BoundTag): BoundTag =>\n Match.value(tag).pipe(\n Match.whenOr(\"gt\", \"gte\", () => \"gt\" as const),\n Match.whenOr(\"lt\", \"lte\", () => \"lt\" as const),\n Match.exhaustive,\n );\n\n/**\n * Peel a bound down to the single entry that feeds the middle range.\n */\nconst peelBound = (\n indexEntries: QueryStreamIndexPrefix.IndexEntries,\n tag: BoundTag,\n): {\n readonly peeled: ReadonlyArray<TaggedBound>;\n readonly final: TaggedBound;\n} =>\n indexEntries.length <= 1\n ? { peeled: [], final: new TaggedBound({ indexEntries, tag }) }\n : pipe(\n peelBound(Array.dropRight(indexEntries, 1), excludePrefix(tag)),\n ({ final, peeled }) => ({\n peeled: Array.prepend(peeled, new TaggedBound({ indexEntries, tag })),\n final,\n }),\n );\n\n/**\n * Pin every entry but the last, which gets the bound tag.\n */\nconst rangeFor = (\n prefix: ReadonlyArray<Equality>,\n indexEntries: QueryStreamIndexPrefix.IndexEntries,\n tag: BoundTag,\n): QueryStreamIndexRange =>\n Option.match(Array.last(indexEntries), {\n onNone: () => make({ equalities: prefix, bounded: Option.none() }),\n onSome: ([fieldPath, value]) =>\n make({\n equalities: Array.appendAll(\n prefix,\n Array.map(Array.dropRight(indexEntries, 1), ([path, pinned]) => ({\n fieldPath: path,\n value: pinned,\n })),\n ),\n bounded: Option.some({\n fieldPath,\n interval:\n tag === \"gt\" || tag === \"gte\"\n ? Interval.Lower({ lower: { value, inclusive: tag === \"gte\" } })\n : Interval.Upper({ upper: { value, inclusive: tag === \"lte\" } }),\n }),\n }),\n });\n\n/**\n * Decompose the range between `indexBounds.lower` and `indexBounds.upper` (over\n * the complete index `fieldPaths`, `_id` tiebreaker included) into a sequence\n * of Convex-expressible ranges, ordered for the given direction.\n *\n * @experimental\n */\nexport const fromBounds = (\n fieldPaths: ReadonlyArray<string>,\n orderDirection: QueryStreamOrderDirection.QueryStreamOrderDirection,\n indexBounds: QueryStreamKeyBounds.IndexBounds,\n): Result.Result<\n ReadonlyArray<QueryStreamIndexRange>,\n QueryStreamIndexPrefix.IndexPrefixWidthMismatchError\n> =>\n Result.gen(function* () {\n const lowerIndexEntries = QueryStreamIndexPrefix.entries(\n yield* QueryStreamIndexPrefix.make(\n fieldPaths,\n indexBounds.lower.keyValues,\n ),\n );\n const upperIndexEntries = QueryStreamIndexPrefix.entries(\n yield* QueryStreamIndexPrefix.make(\n fieldPaths,\n indexBounds.upper.keyValues,\n ),\n );\n // Equal cuts are an empty range too: e.g. lower exclusive at `k` and\n // upper inclusive at `k`—the half-open (k, k]—both cut at\n // successor(k).\n if (QueryStreamKeyBounds.isEmpty(indexBounds)) {\n return [];\n }\n\n const commonLength = pipe(\n Array.zip(indexBounds.lower.keyValues, indexBounds.upper.keyValues),\n Array.takeWhile(\n ([lowerValue, upperValue]) =>\n QueryStreamKeyValues.ValueOrder(lowerValue, upperValue) === 0,\n ),\n Array.length,\n );\n const equalities = pipe(\n Array.take(lowerIndexEntries, commonLength),\n Array.map(([fieldPath, value]) => ({ fieldPath, value })),\n );\n\n const lower = peelBound(\n Array.drop(lowerIndexEntries, commonLength),\n indexBounds.lower.inclusive ? \"gte\" : \"gt\",\n );\n const upper = peelBound(\n Array.drop(upperIndexEntries, commonLength),\n indexBounds.upper.inclusive ? \"lte\" : \"lt\",\n );\n\n const startIndexRanges = Array.map(lower.peeled, ({ indexEntries, tag }) =>\n rangeFor(equalities, indexEntries, tag),\n );\n const endIndexRanges = Array.reverse(\n Array.map(upper.peeled, ({ indexEntries, tag }) =>\n rangeFor(equalities, indexEntries, tag),\n ),\n );\n\n const { indexEntries: lowerFinalIndexEntries, tag: lowerFinalTag } =\n lower.final;\n const { indexEntries: upperFinalIndexEntries, tag: upperFinalTag } =\n upper.final;\n const middleIndexRange =\n Array.isReadonlyArrayNonEmpty(lowerFinalIndexEntries) &&\n Array.isReadonlyArrayNonEmpty(upperFinalIndexEntries)\n ? make({\n equalities,\n bounded: Option.some({\n fieldPath: Array.headNonEmpty(lowerFinalIndexEntries)[0],\n interval: Interval.Between({\n lower: {\n value: Array.headNonEmpty(lowerFinalIndexEntries)[1],\n inclusive: lowerFinalTag === \"gte\",\n },\n upper: {\n value: Array.headNonEmpty(upperFinalIndexEntries)[1],\n inclusive: upperFinalTag === \"lte\",\n },\n }),\n }),\n })\n : Array.isReadonlyArrayNonEmpty(lowerFinalIndexEntries)\n ? rangeFor(equalities, lowerFinalIndexEntries, lowerFinalTag)\n : rangeFor(equalities, upperFinalIndexEntries, upperFinalTag);\n\n const indexRanges = Array.appendAll(\n Array.appendAll(startIndexRanges, Array.of(middleIndexRange)),\n endIndexRanges,\n );\n return orderDirection === \"desc\" ? Array.reverse(indexRanges) : indexRanges;\n });\n\n/**\n * Derive full-index bounds directly from the structural range.\n *\n * @experimental\n */\nexport const toBounds = (\n self: QueryStreamIndexRange,\n): QueryStreamKeyBounds.IndexBounds => {\n const { equalities, bounded } = self[TypeId];\n const keyValues = Array.map(equalities, (equality) => equality.value);\n const unbounded = { keyValues, inclusive: true };\n const endpoint = ({ value, inclusive }: Endpoint) => ({\n keyValues: Array.append(keyValues, value),\n inclusive,\n });\n return Option.match(bounded, {\n onNone: () => ({ lower: unbounded, upper: unbounded }),\n onSome: ({ interval }) =>\n Interval.$match(interval, {\n Lower: ({ lower }) => ({ lower: endpoint(lower), upper: unbounded }),\n Upper: ({ upper }) => ({ lower: unbounded, upper: endpoint(upper) }),\n Between: ({ lower, upper }) => ({\n lower: endpoint(lower),\n upper: endpoint(upper),\n }),\n }),\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AA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EAAE,OAAO,aAAa;IAC9B,OAAO,SAAS,KAAK;IACrB,OAAO,SAAS,KAAK;GACvB;EACF,CAAC;CACL,CAAC;AACH"}
@@ -1,7 +1,7 @@
1
1
  import * as Data from "effect/Data";
2
2
  import * as Result from "effect/Result";
3
- import * as QueryStreamKeyLayout from "./QueryStreamKeyLayout";
4
- import type * as QueryStreamKeyValues from "./QueryStreamKeyValues";
3
+ import * as QueryStreamKeyLayout from "./QueryStreamKeyLayout.js";
4
+ import type * as QueryStreamKeyValues from "./QueryStreamKeyValues.js";
5
5
  declare const TypeId = "~@confect/server/QueryStreamKey";
6
6
  interface Payload {
7
7
  readonly [TypeId]: typeof TypeId;
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStreamKey.d.ts","sourceRoot":"","sources":["../src/QueryStreamKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAEpE,QAAA,MAAM,MAAM,oCAAoC,CAAC;AAEjD,UAAU,OAAO;IACf,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,MAAM,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC,oBAAoB,CAAC;IAC3D,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC,oBAAoB,CAAC;CAC5D;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC;IAC3C,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC,CAAC;AAGH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;AACzE;;GAEG;AACH,MAAM,MA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tC,CAAC;AAEL;;GAEG;AACH,eAAO,MAAM,MAAM,SACX,cAAc,KACnB,oBAAoB,CAAC,oBAAmC,CAAC;AAC5D;;GAEG;AACH,eAAO,MAAM,MAAM,SACX,cAAc,KACnB,oBAAoB,CAAC,oBAAmC,CAAC;AAE5D;;GAEG;AACH,eAAO,MAAM,UAAU,UAAW,OAAO,KAAG,KAAK,IAAI,QAC0B,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { runtimeWidth } from "./QueryStreamKeyLayout.js";
2
+ import * as Data from "effect/Data";
2
3
  import * as Predicate from "effect/Predicate";
3
4
  import * as Result from "effect/Result";
4
- import * as Data from "effect/Data";
5
5
  //#region src/QueryStreamKey.ts
6
6
  const TypeId = "~@confect/server/QueryStreamKey";
7
7
  const QueryStreamKey = Data.taggedEnum();
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStreamKey.js","names":["QueryStreamKeyLayout.runtimeWidth"],"sources":["../src/QueryStreamKey.ts"],"sourcesContent":["import * as Data from \"effect/Data\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Result from \"effect/Result\";\nimport * as QueryStreamKeyLayout from \"./QueryStreamKeyLayout\";\nimport type * as QueryStreamKeyValues from \"./QueryStreamKeyValues\";\n\nconst TypeId = \"~@confect/server/QueryStreamKey\";\n\ninterface Payload {\n readonly [TypeId]: typeof TypeId;\n readonly layout: QueryStreamKeyLayout.QueryStreamKeyLayout;\n readonly values: QueryStreamKeyValues.QueryStreamKeyValues;\n}\n\n/**\n * @experimental\n */\nexport type QueryStreamKey = Data.TaggedEnum<{\n Complete: Payload;\n Prefix: Payload;\n}>;\nconst QueryStreamKey = Data.taggedEnum<QueryStreamKey>();\n\n/**\n * @experimental\n */\nexport type Complete = Data.TaggedEnum.Value<QueryStreamKey, \"Complete\">;\n/**\n * @experimental\n */\nexport type Prefix = Data.TaggedEnum.Value<QueryStreamKey, \"Prefix\">;\n\n/**\n * @experimental\n */\nexport class KeyWidthMismatchError extends Data.TaggedError(\n \"KeyWidthMismatchError\",\n)<{\n readonly kind: \"complete\" | \"prefix\";\n readonly width: number;\n readonly actual: number;\n}> {\n override get message(): string {\n return `Invalid ${this.kind} key width (${this.actual}); expected ${this.kind === \"complete\" ? \"exactly\" : \"at most\"} ${this.width}`;\n }\n}\n\n/**\n * @experimental\n */\nexport const complete = (\n layout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n values: QueryStreamKeyValues.QueryStreamKeyValues,\n): Result.Result<Complete, KeyWidthMismatchError> => {\n const width = QueryStreamKeyLayout.runtimeWidth(layout);\n return values.length === width\n ? Result.succeed(\n QueryStreamKey.Complete({ [TypeId]: TypeId, layout, values }),\n )\n : Result.fail(\n new KeyWidthMismatchError({\n kind: \"complete\",\n width,\n actual: values.length,\n }),\n );\n};\n\n/**\n * @experimental\n */\nexport const prefix = (\n layout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n values: QueryStreamKeyValues.QueryStreamKeyValues,\n): Result.Result<Prefix, KeyWidthMismatchError> => {\n const width = QueryStreamKeyLayout.runtimeWidth(layout);\n return values.length <= width\n ? Result.succeed(\n QueryStreamKey.Prefix({ [TypeId]: TypeId, layout, values }),\n )\n : Result.fail(\n new KeyWidthMismatchError({\n kind: \"prefix\",\n width,\n actual: values.length,\n }),\n );\n};\n\n// A complete key already satisfies the prefix width guarantee.\n/**\n * @experimental\n */\nexport const toPrefix = (self: Complete): Prefix =>\n QueryStreamKey.Prefix({\n [TypeId]: TypeId,\n layout: self.layout,\n values: self.values,\n });\n\n/**\n * @experimental\n */\nexport const values = (\n self: QueryStreamKey,\n): QueryStreamKeyValues.QueryStreamKeyValues => self.values;\n/**\n * @experimental\n */\nexport const layout = (\n self: QueryStreamKey,\n): QueryStreamKeyLayout.QueryStreamKeyLayout => self.layout;\n\n/**\n * @experimental\n */\nexport const isComplete = (value: unknown): value is Complete =>\n Predicate.hasProperty(value, TypeId) && QueryStreamKey.$is(\"Complete\")(value);\n"],"mappings":";;;;;AAMA,MAAM,SAAS;AAef,MAAM,iBAAiB,KAAK,WAA2B;;;;AAcvD,IAAa,wBAAb,cAA2C,KAAK,YAC9C,uBACF,CAAC,CAIE;CACD,IAAa,UAAkB;EAC7B,OAAO,WAAW,KAAK,KAAK,cAAc,KAAK,OAAO,cAAc,KAAK,SAAS,aAAa,YAAY,UAAU,GAAG,KAAK;CAC/H;AACF;;;;AAKA,MAAa,YACX,QACA,WACmD;CACnD,MAAM,QAAQA,aAAkC,MAAM;CACtD,OAAO,OAAO,WAAW,QACrB,OAAO,QACL,eAAe,SAAS;GAAG,SAAS;EAAQ;EAAQ;CAAO,CAAC,CAC9D,IACA,OAAO,KACL,IAAI,sBAAsB;EACxB,MAAM;EACN;EACA,QAAQ,OAAO;CACjB,CAAC,CACH;AACN;;;;AAKA,MAAa,UACX,QACA,WACiD;CACjD,MAAM,QAAQA,aAAkC,MAAM;CACtD,OAAO,OAAO,UAAU,QACpB,OAAO,QACL,eAAe,OAAO;GAAG,SAAS;EAAQ;EAAQ;CAAO,CAAC,CAC5D,IACA,OAAO,KACL,IAAI,sBAAsB;EACxB,MAAM;EACN;EACA,QAAQ,OAAO;CACjB,CAAC,CACH;AACN;;;;AAMA,MAAa,YAAY,SACvB,eAAe,OAAO;EACnB,SAAS;CACV,QAAQ,KAAK;CACb,QAAQ,KAAK;AACf,CAAC;;;;AAKH,MAAa,UACX,SAC8C,KAAK;;;;AAIrD,MAAa,UACX,SAC8C,KAAK;;;;AAKrD,MAAa,cAAc,UACzB,UAAU,YAAY,OAAO,MAAM,KAAK,eAAe,IAAI,UAAU,CAAC,CAAC,KAAK"}
1
+ {"version":3,"file":"QueryStreamKey.js","names":["QueryStreamKeyLayout.runtimeWidth"],"sources":["../src/QueryStreamKey.ts"],"sourcesContent":["import * as Data from \"effect/Data\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Result from \"effect/Result\";\nimport * as QueryStreamKeyLayout from \"./QueryStreamKeyLayout.js\";\nimport type * as QueryStreamKeyValues from \"./QueryStreamKeyValues.js\";\n\nconst TypeId = \"~@confect/server/QueryStreamKey\";\n\ninterface Payload {\n readonly [TypeId]: typeof TypeId;\n readonly layout: QueryStreamKeyLayout.QueryStreamKeyLayout;\n readonly values: QueryStreamKeyValues.QueryStreamKeyValues;\n}\n\n/**\n * @experimental\n */\nexport type QueryStreamKey = Data.TaggedEnum<{\n Complete: Payload;\n Prefix: Payload;\n}>;\nconst QueryStreamKey = Data.taggedEnum<QueryStreamKey>();\n\n/**\n * @experimental\n */\nexport type Complete = Data.TaggedEnum.Value<QueryStreamKey, \"Complete\">;\n/**\n * @experimental\n */\nexport type Prefix = Data.TaggedEnum.Value<QueryStreamKey, \"Prefix\">;\n\n/**\n * @experimental\n */\nexport class KeyWidthMismatchError extends Data.TaggedError(\n \"KeyWidthMismatchError\",\n)<{\n readonly kind: \"complete\" | \"prefix\";\n readonly width: number;\n readonly actual: number;\n}> {\n override get message(): string {\n return `Invalid ${this.kind} key width (${this.actual}); expected ${this.kind === \"complete\" ? \"exactly\" : \"at most\"} ${this.width}`;\n }\n}\n\n/**\n * @experimental\n */\nexport const complete = (\n layout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n values: QueryStreamKeyValues.QueryStreamKeyValues,\n): Result.Result<Complete, KeyWidthMismatchError> => {\n const width = QueryStreamKeyLayout.runtimeWidth(layout);\n return values.length === width\n ? Result.succeed(\n QueryStreamKey.Complete({ [TypeId]: TypeId, layout, values }),\n )\n : Result.fail(\n new KeyWidthMismatchError({\n kind: \"complete\",\n width,\n actual: values.length,\n }),\n );\n};\n\n/**\n * @experimental\n */\nexport const prefix = (\n layout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n values: QueryStreamKeyValues.QueryStreamKeyValues,\n): Result.Result<Prefix, KeyWidthMismatchError> => {\n const width = QueryStreamKeyLayout.runtimeWidth(layout);\n return values.length <= width\n ? Result.succeed(\n QueryStreamKey.Prefix({ [TypeId]: TypeId, layout, values }),\n )\n : Result.fail(\n new KeyWidthMismatchError({\n kind: \"prefix\",\n width,\n actual: values.length,\n }),\n );\n};\n\n// A complete key already satisfies the prefix width guarantee.\n/**\n * @experimental\n */\nexport const toPrefix = (self: Complete): Prefix =>\n QueryStreamKey.Prefix({\n [TypeId]: TypeId,\n layout: self.layout,\n values: self.values,\n });\n\n/**\n * @experimental\n */\nexport const values = (\n self: QueryStreamKey,\n): QueryStreamKeyValues.QueryStreamKeyValues => self.values;\n/**\n * @experimental\n */\nexport const layout = (\n self: QueryStreamKey,\n): QueryStreamKeyLayout.QueryStreamKeyLayout => self.layout;\n\n/**\n * @experimental\n */\nexport const isComplete = (value: unknown): value is Complete =>\n Predicate.hasProperty(value, TypeId) && QueryStreamKey.$is(\"Complete\")(value);\n"],"mappings":";;;;;AAMA,MAAM,SAAS;AAef,MAAM,iBAAiB,KAAK,WAA2B;;;;AAcvD,IAAa,wBAAb,cAA2C,KAAK,YAC9C,uBACF,CAAC,CAIE;CACD,IAAa,UAAkB;EAC7B,OAAO,WAAW,KAAK,KAAK,cAAc,KAAK,OAAO,cAAc,KAAK,SAAS,aAAa,YAAY,UAAU,GAAG,KAAK;CAC/H;AACF;;;;AAKA,MAAa,YACX,QACA,WACmD;CACnD,MAAM,QAAQA,aAAkC,MAAM;CACtD,OAAO,OAAO,WAAW,QACrB,OAAO,QACL,eAAe,SAAS;GAAG,SAAS;EAAQ;EAAQ;CAAO,CAAC,CAC9D,IACA,OAAO,KACL,IAAI,sBAAsB;EACxB,MAAM;EACN;EACA,QAAQ,OAAO;CACjB,CAAC,CACH;AACN;;;;AAKA,MAAa,UACX,QACA,WACiD;CACjD,MAAM,QAAQA,aAAkC,MAAM;CACtD,OAAO,OAAO,UAAU,QACpB,OAAO,QACL,eAAe,OAAO;GAAG,SAAS;EAAQ;EAAQ;CAAO,CAAC,CAC5D,IACA,OAAO,KACL,IAAI,sBAAsB;EACxB,MAAM;EACN;EACA,QAAQ,OAAO;CACjB,CAAC,CACH;AACN;;;;AAMA,MAAa,YAAY,SACvB,eAAe,OAAO;EACnB,SAAS;CACV,QAAQ,KAAK;CACb,QAAQ,KAAK;AACf,CAAC;;;;AAKH,MAAa,UACX,SAC8C,KAAK;;;;AAIrD,MAAa,UACX,SAC8C,KAAK;;;;AAKrD,MAAa,cAAc,UACzB,UAAU,YAAY,OAAO,MAAM,KAAK,eAAe,IAAI,UAAU,CAAC,CAAC,KAAK"}
@@ -1,8 +1,8 @@
1
1
  import * as Option from "effect/Option";
2
2
  import * as Result from "effect/Result";
3
- import * as QueryStreamKey from "./QueryStreamKey";
4
- import * as QueryStreamKeyLayout from "./QueryStreamKeyLayout";
5
- import * as QueryStreamKeyValues from "./QueryStreamKeyValues";
3
+ import * as QueryStreamKey from "./QueryStreamKey.js";
4
+ import * as QueryStreamKeyLayout from "./QueryStreamKeyLayout.js";
5
+ import * as QueryStreamKeyValues from "./QueryStreamKeyValues.js";
6
6
  /**
7
7
  * One side of a range: a (possibly prefix) key and whether it's included.
8
8
  *
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStreamKeyBounds.d.ts","sourceRoot":"","sources":["../src/QueryStreamKeyBounds.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAS/D;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,SAAS,EAAE,oBAAoB,CAAC,oBAAoB,CAAC;IAC9D,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ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CAWlE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,iBAAkB,YAAY,KAAG,SAGpD,CAAC"}
@@ -2,11 +2,11 @@ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { validateEquivalence } from "./QueryStreamKeyLayout.js";
3
3
  import { prefix, values } from "./QueryStreamKey.js";
4
4
  import { Order as Order$1 } from "./QueryStreamKeyValues.js";
5
- import * as Option from "effect/Option";
5
+ import * as Data from "effect/Data";
6
6
  import * as Array from "effect/Array";
7
+ import * as Option from "effect/Option";
7
8
  import * as Order from "effect/Order";
8
9
  import * as Result from "effect/Result";
9
- import * as Data from "effect/Data";
10
10
  //#region src/QueryStreamKeyBounds.ts
11
11
  var QueryStreamKeyBounds_exports = /* @__PURE__ */ __exportAll({
12
12
  admittedByLower: () => admittedByLower,
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStreamKeyBounds.js","names":["QueryStreamKey.values","QueryStreamKeyValues.Order","QueryStreamKeyLayout.validateEquivalence","QueryStreamKey.prefix"],"sources":["../src/QueryStreamKeyBounds.ts"],"sourcesContent":["import * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as Option from \"effect/Option\";\nimport * as Order from \"effect/Order\";\nimport * as Result from \"effect/Result\";\nimport * as QueryStreamKey from \"./QueryStreamKey\";\nimport * as QueryStreamKeyLayout from \"./QueryStreamKeyLayout\";\nimport * as QueryStreamKeyValues from \"./QueryStreamKeyValues\";\n\n// A bound's key may be a *prefix* of the full key: bounding by `[\"a\"]` means\n// bounding by the whole family of keys that start with `\"a\"`. To compare\n// bounds and keys uniformly, each is modelled as a \"cut\"—a position\n// *between* keys: the `predecessor` cut of a prefix sits just before every\n// key extending it, the `successor` cut just after, and an `exact` cut is a\n// full key itself. (This is `convex-helpers`' `compareKeys` model.)\n\n/**\n * One side of a range: a (possibly prefix) key and whether it's included.\n *\n * @experimental\n */\nexport interface KeyBound {\n readonly keyValues: QueryStreamKeyValues.QueryStreamKeyValues;\n readonly inclusive: boolean;\n}\n\n/**\n * Bounds over a stream's key, in _ascending key space_ (`narrow` converts from\n * stream space, where `desc` reverses which end is which).\n *\n * @experimental\n */\nexport interface KeyBounds {\n readonly lower: Option.Option<KeyBound>;\n readonly upper: Option.Option<KeyBound>;\n}\n\n/**\n * Bounds in _full index-key space_: `eq`-pinned values appear as a shared\n * prefix of both keys (`fromBounds` re-derives them as `eq` constraints). An\n * empty key bounds nothing.\n *\n * @experimental\n */\nexport interface IndexBounds {\n readonly lower: KeyBound;\n readonly upper: KeyBound;\n}\n\ntype KeyCut = Data.TaggedEnum<{\n Predecessor: {\n readonly keyValues: QueryStreamKeyValues.QueryStreamKeyValues;\n };\n Exact: { readonly key: QueryStreamKey.Complete };\n Successor: { readonly keyValues: QueryStreamKeyValues.QueryStreamKeyValues };\n}>;\nconst KeyCut = Data.taggedEnum<KeyCut>();\n\nconst cutRank = KeyCut.$match({\n Predecessor: () => 0,\n Exact: () => 1,\n Successor: () => 2,\n});\n\nconst cutKeyValues = KeyCut.$match({\n Predecessor: ({ keyValues }) => keyValues,\n Exact: ({ key }) => QueryStreamKey.values(key),\n Successor: ({ keyValues }) => keyValues,\n});\n\nconst KeyCutOrder: Order.Order<KeyCut> = Order.make((self, that) => {\n const selfKeyValues = cutKeyValues(self);\n const thatKeyValues = cutKeyValues(that);\n const minLength = Math.min(selfKeyValues.length, thatKeyValues.length);\n const prefixOrdering = QueryStreamKeyValues.Order(\"asc\")(\n Array.take(selfKeyValues, minLength),\n Array.take(thatKeyValues, minLength),\n );\n if (prefixOrdering !== 0) {\n return prefixOrdering;\n }\n if (selfKeyValues.length === thatKeyValues.length) {\n return Order.Number(cutRank(self), cutRank(that));\n }\n // One key is a proper prefix of the other. The shorter cut sits just\n // before (`predecessor`) or just after (`successor`) *every* key\n // extending its prefix—the longer one included. (`exact` cuts are\n // always full keys, so an `exact` cut is never the shorter one here.)\n const selfIsShorter = selfKeyValues.length < thatKeyValues.length;\n const shorter = selfIsShorter ? self : that;\n const shorterOrdering = KeyCut.$match(shorter, {\n Predecessor: () => -1 as const,\n Exact: () => 1 as const,\n Successor: () => 1 as const,\n });\n return selfIsShorter ? shorterOrdering : (-shorterOrdering as -1 | 1);\n});\n\nconst lowerCut = (bound: KeyBound): KeyCut =>\n bound.inclusive\n ? KeyCut.Predecessor({ keyValues: bound.keyValues })\n : KeyCut.Successor({ keyValues: bound.keyValues });\n\nconst upperCut = (bound: KeyBound): KeyCut =>\n bound.inclusive\n ? KeyCut.Successor({ keyValues: bound.keyValues })\n : KeyCut.Predecessor({ keyValues: bound.keyValues });\n\n/**\n * The stricter (later) of two lower bounds.\n *\n * @experimental\n */\nexport const tightestLower = (self: KeyBound, that: KeyBound): KeyBound =>\n Order.isGreaterThan(KeyCutOrder)(lowerCut(that), lowerCut(self))\n ? that\n : self;\n\n/**\n * The stricter (earlier) of two upper bounds.\n *\n * @experimental\n */\nexport const tightestUpper = (self: KeyBound, that: KeyBound): KeyBound =>\n Order.isLessThan(KeyCutOrder)(upperCut(that), upperCut(self)) ? that : self;\n\nconst combineKeyBound = (\n self: Option.Option<ParsedBound>,\n that: Option.Option<ParsedBound>,\n combine: (self: ParsedBound, that: ParsedBound) => ParsedBound,\n): Option.Option<ParsedBound> =>\n Option.match(self, {\n onNone: () => that,\n onSome: (first) =>\n Option.some(\n Option.match(that, {\n onNone: () => first,\n onSome: (second) => combine(first, second),\n }),\n ),\n });\n\n/**\n * @experimental\n */\nexport const intersect = (\n self: ParsedBounds,\n that: ParsedBounds,\n): Result.Result<ParsedBounds, QueryStreamKeyLayout.KeyLayoutMismatchError> =>\n Result.map(forLayout(self.keyLayout, that), () =>\n make(self.keyLayout, {\n lower: combineKeyBound(self.lower, that.lower, tighterLower),\n upper: combineKeyBound(self.upper, that.upper, tighterUpper),\n }),\n );\n\n/**\n * @experimental\n */\nexport const isEmpty = (indexBounds: IndexBounds): boolean =>\n KeyCutOrder(lowerCut(indexBounds.lower), upperCut(indexBounds.upper)) >= 0;\n\n/**\n * @experimental\n */\nexport const intersectIndexBounds = (\n self: IndexBounds,\n that: IndexBounds,\n): IndexBounds => ({\n lower: tightestLower(self.lower, that.lower),\n upper: tightestUpper(self.upper, that.upper),\n});\n\n/**\n * Whether a compatible key sits after the lower bound (always, when unbounded).\n *\n * @experimental\n */\nexport const admittedByLower =\n (parsedBounds: ParsedBounds) =>\n (\n key: QueryStreamKey.Complete,\n ): Result.Result<boolean, QueryStreamKeyLayout.KeyLayoutMismatchError> =>\n Result.gen(function* () {\n yield* QueryStreamKeyLayout.validateEquivalence(\n parsedBounds.keyLayout,\n key.layout,\n );\n return Option.match(parsedBounds.lower, {\n onNone: () => true,\n onSome: (bound) =>\n KeyCutOrder(KeyCut.Exact({ key }), lowerCut(rawBound(bound))) > 0,\n });\n });\n\n/**\n * Whether a compatible key sits before the upper bound (always, when\n * unbounded).\n *\n * @experimental\n */\nexport const admittedByUpper =\n (parsedBounds: ParsedBounds) =>\n (\n key: QueryStreamKey.Complete,\n ): Result.Result<boolean, QueryStreamKeyLayout.KeyLayoutMismatchError> =>\n Result.gen(function* () {\n yield* QueryStreamKeyLayout.validateEquivalence(\n parsedBounds.keyLayout,\n key.layout,\n );\n return Option.match(parsedBounds.upper, {\n onNone: () => true,\n onSome: (bound) =>\n KeyCutOrder(KeyCut.Exact({ key }), upperCut(rawBound(bound))) < 0,\n });\n });\n\n/**\n * At least one endpoint in stream order. Omit the other to leave that side\n * unbounded.\n *\n * @experimental\n */\nexport type NarrowBounds =\n | {\n readonly start: KeyBound;\n readonly end?: KeyBound | undefined;\n }\n | {\n readonly start?: KeyBound | undefined;\n readonly end: KeyBound;\n };\n\n/**\n * @experimental\n */\nexport interface ParsedBound {\n readonly key: QueryStreamKey.Prefix;\n readonly inclusive: boolean;\n}\n\n// Endpoints validated against a stream layout. Operations that preserve the\n// key space retain these values; coordinate changes construct new endpoints.\nconst TypeId = \"~@confect/server/QueryStreamKeyBounds\";\n\n/**\n * @experimental\n */\nexport interface ParsedBounds {\n readonly [TypeId]: typeof TypeId;\n readonly keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout;\n readonly lower: Option.Option<ParsedBound>;\n readonly upper: Option.Option<ParsedBound>;\n}\n\nconst make = (\n keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n endpoints: Pick<ParsedBounds, \"lower\" | \"upper\">,\n): ParsedBounds => ({\n [TypeId]: TypeId,\n keyLayout,\n lower: endpoints.lower,\n upper: endpoints.upper,\n});\n\n/**\n * @experimental\n */\nexport const unbounded = (\n keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n): ParsedBounds =>\n make(keyLayout, { lower: Option.none(), upper: Option.none() });\n\n/**\n * @experimental\n */\nexport const forLayout = (\n keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n parsedBounds: ParsedBounds,\n): Result.Result<ParsedBounds, QueryStreamKeyLayout.KeyLayoutMismatchError> =>\n Result.gen(function* () {\n yield* QueryStreamKeyLayout.validateEquivalence(\n keyLayout,\n parsedBounds.keyLayout,\n );\n return parsedBounds;\n });\n\n// Combining existing parsed endpoints still needs a shared layout, including\n// when one or both endpoints are absent.\n/**\n * @experimental\n */\nexport const fromParsed = (\n keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n endpoints: Pick<ParsedBounds, \"lower\" | \"upper\">,\n): Result.Result<ParsedBounds, QueryStreamKeyLayout.KeyLayoutMismatchError> => {\n const validateEndpoint = (endpoint: Option.Option<ParsedBound>) =>\n Option.match(endpoint, {\n onNone: () => Result.succeed(undefined),\n onSome: ({ key }) =>\n QueryStreamKeyLayout.validateEquivalence(keyLayout, key.layout),\n });\n return Result.gen(function* () {\n yield* validateEndpoint(endpoints.lower);\n yield* validateEndpoint(endpoints.upper);\n return make(keyLayout, endpoints);\n });\n};\n\nconst rawBound = (bound: ParsedBound): KeyBound => ({\n keyValues: QueryStreamKey.values(bound.key),\n inclusive: bound.inclusive,\n});\n\n// Select existing endpoints so intersection retains their parsed keys.\nconst tighterLower = (self: ParsedBound, that: ParsedBound): ParsedBound =>\n KeyCutOrder(lowerCut(rawBound(that)), lowerCut(rawBound(self))) > 0\n ? that\n : self;\n\nconst tighterUpper = (self: ParsedBound, that: ParsedBound): ParsedBound =>\n KeyCutOrder(upperCut(rawBound(that)), upperCut(rawBound(self))) < 0\n ? that\n : self;\n\n/**\n * @experimental\n */\nexport const tightestParsedLower = (\n self: ParsedBound,\n that: ParsedBound,\n): Result.Result<ParsedBound, QueryStreamKeyLayout.KeyLayoutMismatchError> =>\n Result.gen(function* () {\n yield* QueryStreamKeyLayout.validateEquivalence(\n self.key.layout,\n that.key.layout,\n );\n return tighterLower(self, that);\n });\n\n/**\n * @experimental\n */\nexport const tightestParsedUpper = (\n self: ParsedBound,\n that: ParsedBound,\n): Result.Result<ParsedBound, QueryStreamKeyLayout.KeyLayoutMismatchError> =>\n Result.gen(function* () {\n yield* QueryStreamKeyLayout.validateEquivalence(\n self.key.layout,\n that.key.layout,\n );\n return tighterUpper(self, that);\n });\n\n/**\n * @experimental\n */\nexport const parseBound = (\n keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n { keyValues, inclusive }: KeyBound,\n): Result.Result<ParsedBound, QueryStreamKey.KeyWidthMismatchError> =>\n Result.map(QueryStreamKey.prefix(keyLayout, keyValues), (key) => ({\n key,\n inclusive,\n }));\n\n/**\n * @experimental\n */\nexport const parse = (\n keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n keyBounds: KeyBounds,\n): Result.Result<ParsedBounds, QueryStreamKey.KeyWidthMismatchError> => {\n const endpoint = (bound: Option.Option<KeyBound>) =>\n Option.match(bound, {\n onNone: () => Result.succeed(Option.none<ParsedBound>()),\n onSome: (value) => Result.map(parseBound(keyLayout, value), Option.some),\n });\n return Result.gen(function* () {\n const lower = yield* endpoint(keyBounds.lower);\n const upper = yield* endpoint(keyBounds.upper);\n return make(keyLayout, { lower, upper });\n });\n};\n\n/**\n * @experimental\n */\nexport const toBounds = (parsedBounds: Parsed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AC;;;;AAKH,MAAa,uBACX,MACA,SAEA,OAAO,IAAI,aAAa;CACtB,OAAOA,oBACL,KAAK,IAAI,QACT,KAAK,IAAI,MACX;CACA,OAAO,aAAa,MAAM,IAAI;AAChC,CAAC;;;;AAKH,MAAa,cACX,WACA,EAAE,WAAW,gBAEb,OAAO,IAAIC,OAAsB,WAAW,SAAS,IAAI,SAAS;CAChE;CACA;AACF,EAAE;;;;AAKJ,MAAa,SACX,WACA,cACsE;CACtE,MAAM,YAAY,UAChB,OAAO,MAAM,OAAO;EAClB,cAAc,OAAO,QAAQ,OAAO,KAAkB,CAAC;EACvD,SAAS,UAAU,OAAO,IAAI,WAAW,WAAW,KAAK,GAAG,OAAO,IAAI;CACzE,CAAC;CACH,OAAO,OAAO,IAAI,aAAa;EAC7B,MAAM,QAAQ,OAAO,SAAS,UAAU,KAAK;EAC7C,MAAM,QAAQ,OAAO,SAAS,UAAU,KAAK;EAC7C,OAAO,KAAK,WAAW;GAAE;GAAO;EAAM,CAAC;CACzC,CAAC;AACH;;;;AAKA,MAAa,YAAY,kBAA2C;CAClE,OAAO,OAAO,IAAI,aAAa,OAAO,QAAQ;CAC9C,OAAO,OAAO,IAAI,aAAa,OAAO,QAAQ;AAChD"}
1
+ {"version":3,"file":"QueryStreamKeyBounds.js","names":["QueryStreamKey.values","QueryStreamKeyValues.Order","QueryStreamKeyLayout.validateEquivalence","QueryStreamKey.prefix"],"sources":["../src/QueryStreamKeyBounds.ts"],"sourcesContent":["import * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as Option from \"effect/Option\";\nimport * as Order from \"effect/Order\";\nimport * as Result from \"effect/Result\";\nimport * as QueryStreamKey from \"./QueryStreamKey.js\";\nimport * as QueryStreamKeyLayout from \"./QueryStreamKeyLayout.js\";\nimport * as QueryStreamKeyValues from \"./QueryStreamKeyValues.js\";\n\n// A bound's key may be a *prefix* of the full key: bounding by `[\"a\"]` means\n// bounding by the whole family of keys that start with `\"a\"`. To compare\n// bounds and keys uniformly, each is modelled as a \"cut\"—a position\n// *between* keys: the `predecessor` cut of a prefix sits just before every\n// key extending it, the `successor` cut just after, and an `exact` cut is a\n// full key itself. (This is `convex-helpers`' `compareKeys` model.)\n\n/**\n * One side of a range: a (possibly prefix) key and whether it's included.\n *\n * @experimental\n */\nexport interface KeyBound {\n readonly keyValues: QueryStreamKeyValues.QueryStreamKeyValues;\n readonly inclusive: boolean;\n}\n\n/**\n * Bounds over a stream's key, in _ascending key space_ (`narrow` converts from\n * stream space, where `desc` reverses which end is which).\n *\n * @experimental\n */\nexport interface KeyBounds {\n readonly lower: Option.Option<KeyBound>;\n readonly upper: Option.Option<KeyBound>;\n}\n\n/**\n * Bounds in _full index-key space_: `eq`-pinned values appear as a shared\n * prefix of both keys (`fromBounds` re-derives them as `eq` constraints). An\n * empty key bounds nothing.\n *\n * @experimental\n */\nexport interface IndexBounds {\n readonly lower: KeyBound;\n readonly upper: KeyBound;\n}\n\ntype KeyCut = Data.TaggedEnum<{\n Predecessor: {\n readonly keyValues: QueryStreamKeyValues.QueryStreamKeyValues;\n };\n Exact: { readonly key: QueryStreamKey.Complete };\n Successor: { readonly keyValues: QueryStreamKeyValues.QueryStreamKeyValues };\n}>;\nconst KeyCut = Data.taggedEnum<KeyCut>();\n\nconst cutRank = KeyCut.$match({\n Predecessor: () => 0,\n Exact: () => 1,\n Successor: () => 2,\n});\n\nconst cutKeyValues = KeyCut.$match({\n Predecessor: ({ keyValues }) => keyValues,\n Exact: ({ key }) => QueryStreamKey.values(key),\n Successor: ({ keyValues }) => keyValues,\n});\n\nconst KeyCutOrder: Order.Order<KeyCut> = Order.make((self, that) => {\n const selfKeyValues = cutKeyValues(self);\n const thatKeyValues = cutKeyValues(that);\n const minLength = Math.min(selfKeyValues.length, thatKeyValues.length);\n const prefixOrdering = QueryStreamKeyValues.Order(\"asc\")(\n Array.take(selfKeyValues, minLength),\n Array.take(thatKeyValues, minLength),\n );\n if (prefixOrdering !== 0) {\n return prefixOrdering;\n }\n if (selfKeyValues.length === thatKeyValues.length) {\n return Order.Number(cutRank(self), cutRank(that));\n }\n // One key is a proper prefix of the other. The shorter cut sits just\n // before (`predecessor`) or just after (`successor`) *every* key\n // extending its prefix—the longer one included. (`exact` cuts are\n // always full keys, so an `exact` cut is never the shorter one here.)\n const selfIsShorter = selfKeyValues.length < thatKeyValues.length;\n const shorter = selfIsShorter ? self : that;\n const shorterOrdering = KeyCut.$match(shorter, {\n Predecessor: () => -1 as const,\n Exact: () => 1 as const,\n Successor: () => 1 as const,\n });\n return selfIsShorter ? shorterOrdering : (-shorterOrdering as -1 | 1);\n});\n\nconst lowerCut = (bound: KeyBound): KeyCut =>\n bound.inclusive\n ? KeyCut.Predecessor({ keyValues: bound.keyValues })\n : KeyCut.Successor({ keyValues: bound.keyValues });\n\nconst upperCut = (bound: KeyBound): KeyCut =>\n bound.inclusive\n ? KeyCut.Successor({ keyValues: bound.keyValues })\n : KeyCut.Predecessor({ keyValues: bound.keyValues });\n\n/**\n * The stricter (later) of two lower bounds.\n *\n * @experimental\n */\nexport const tightestLower = (self: KeyBound, that: KeyBound): KeyBound =>\n Order.isGreaterThan(KeyCutOrder)(lowerCut(that), lowerCut(self))\n ? that\n : self;\n\n/**\n * The stricter (earlier) of two upper bounds.\n *\n * @experimental\n */\nexport const tightestUpper = (self: KeyBound, that: KeyBound): KeyBound =>\n Order.isLessThan(KeyCutOrder)(upperCut(that), upperCut(self)) ? that : self;\n\nconst combineKeyBound = (\n self: Option.Option<ParsedBound>,\n that: Option.Option<ParsedBound>,\n combine: (self: ParsedBound, that: ParsedBound) => ParsedBound,\n): Option.Option<ParsedBound> =>\n Option.match(self, {\n onNone: () => that,\n onSome: (first) =>\n Option.some(\n Option.match(that, {\n onNone: () => first,\n onSome: (second) => combine(first, second),\n }),\n ),\n });\n\n/**\n * @experimental\n */\nexport const intersect = (\n self: ParsedBounds,\n that: ParsedBounds,\n): Result.Result<ParsedBounds, QueryStreamKeyLayout.KeyLayoutMismatchError> =>\n Result.map(forLayout(self.keyLayout, that), () =>\n make(self.keyLayout, {\n lower: combineKeyBound(self.lower, that.lower, tighterLower),\n upper: combineKeyBound(self.upper, that.upper, tighterUpper),\n }),\n );\n\n/**\n * @experimental\n */\nexport const isEmpty = (indexBounds: IndexBounds): boolean =>\n KeyCutOrder(lowerCut(indexBounds.lower), upperCut(indexBounds.upper)) >= 0;\n\n/**\n * @experimental\n */\nexport const intersectIndexBounds = (\n self: IndexBounds,\n that: IndexBounds,\n): IndexBounds => ({\n lower: tightestLower(self.lower, that.lower),\n upper: tightestUpper(self.upper, that.upper),\n});\n\n/**\n * Whether a compatible key sits after the lower bound (always, when unbounded).\n *\n * @experimental\n */\nexport const admittedByLower =\n (parsedBounds: ParsedBounds) =>\n (\n key: QueryStreamKey.Complete,\n ): Result.Result<boolean, QueryStreamKeyLayout.KeyLayoutMismatchError> =>\n Result.gen(function* () {\n yield* QueryStreamKeyLayout.validateEquivalence(\n parsedBounds.keyLayout,\n key.layout,\n );\n return Option.match(parsedBounds.lower, {\n onNone: () => true,\n onSome: (bound) =>\n KeyCutOrder(KeyCut.Exact({ key }), lowerCut(rawBound(bound))) > 0,\n });\n });\n\n/**\n * Whether a compatible key sits before the upper bound (always, when\n * unbounded).\n *\n * @experimental\n */\nexport const admittedByUpper =\n (parsedBounds: ParsedBounds) =>\n (\n key: QueryStreamKey.Complete,\n ): Result.Result<boolean, QueryStreamKeyLayout.KeyLayoutMismatchError> =>\n Result.gen(function* () {\n yield* QueryStreamKeyLayout.validateEquivalence(\n parsedBounds.keyLayout,\n key.layout,\n );\n return Option.match(parsedBounds.upper, {\n onNone: () => true,\n onSome: (bound) =>\n KeyCutOrder(KeyCut.Exact({ key }), upperCut(rawBound(bound))) < 0,\n });\n });\n\n/**\n * At least one endpoint in stream order. Omit the other to leave that side\n * unbounded.\n *\n * @experimental\n */\nexport type NarrowBounds =\n | {\n readonly start: KeyBound;\n readonly end?: KeyBound | undefined;\n }\n | {\n readonly start?: KeyBound | undefined;\n readonly end: KeyBound;\n };\n\n/**\n * @experimental\n */\nexport interface ParsedBound {\n readonly key: QueryStreamKey.Prefix;\n readonly inclusive: boolean;\n}\n\n// Endpoints validated against a stream layout. Operations that preserve the\n// key space retain these values; coordinate changes construct new endpoints.\nconst TypeId = \"~@confect/server/QueryStreamKeyBounds\";\n\n/**\n * @experimental\n */\nexport interface ParsedBounds {\n readonly [TypeId]: typeof TypeId;\n readonly keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout;\n readonly lower: Option.Option<ParsedBound>;\n readonly upper: Option.Option<ParsedBound>;\n}\n\nconst make = (\n keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n endpoints: Pick<ParsedBounds, \"lower\" | \"upper\">,\n): ParsedBounds => ({\n [TypeId]: TypeId,\n keyLayout,\n lower: endpoints.lower,\n upper: endpoints.upper,\n});\n\n/**\n * @experimental\n */\nexport const unbounded = (\n keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n): ParsedBounds =>\n make(keyLayout, { lower: Option.none(), upper: Option.none() });\n\n/**\n * @experimental\n */\nexport const forLayout = (\n keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n parsedBounds: ParsedBounds,\n): Result.Result<ParsedBounds, QueryStreamKeyLayout.KeyLayoutMismatchError> =>\n Result.gen(function* () {\n yield* QueryStreamKeyLayout.validateEquivalence(\n keyLayout,\n parsedBounds.keyLayout,\n );\n return parsedBounds;\n });\n\n// Combining existing parsed endpoints still needs a shared layout, including\n// when one or both endpoints are absent.\n/**\n * @experimental\n */\nexport const fromParsed = (\n keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n endpoints: Pick<ParsedBounds, \"lower\" | \"upper\">,\n): Result.Result<ParsedBounds, QueryStreamKeyLayout.KeyLayoutMismatchError> => {\n const validateEndpoint = (endpoint: Option.Option<ParsedBound>) =>\n Option.match(endpoint, {\n onNone: () => Result.succeed(undefined),\n onSome: ({ key }) =>\n QueryStreamKeyLayout.validateEquivalence(keyLayout, key.layout),\n });\n return Result.gen(function* () {\n yield* validateEndpoint(endpoints.lower);\n yield* validateEndpoint(endpoints.upper);\n return make(keyLayout, endpoints);\n });\n};\n\nconst rawBound = (bound: ParsedBound): KeyBound => ({\n keyValues: QueryStreamKey.values(bound.key),\n inclusive: bound.inclusive,\n});\n\n// Select existing endpoints so intersection retains their parsed keys.\nconst tighterLower = (self: ParsedBound, that: ParsedBound): ParsedBound =>\n KeyCutOrder(lowerCut(rawBound(that)), lowerCut(rawBound(self))) > 0\n ? that\n : self;\n\nconst tighterUpper = (self: ParsedBound, that: ParsedBound): ParsedBound =>\n KeyCutOrder(upperCut(rawBound(that)), upperCut(rawBound(self))) < 0\n ? that\n : self;\n\n/**\n * @experimental\n */\nexport const tightestParsedLower = (\n self: ParsedBound,\n that: ParsedBound,\n): Result.Result<ParsedBound, QueryStreamKeyLayout.KeyLayoutMismatchError> =>\n Result.gen(function* () {\n yield* QueryStreamKeyLayout.validateEquivalence(\n self.key.layout,\n that.key.layout,\n );\n return tighterLower(self, that);\n });\n\n/**\n * @experimental\n */\nexport const tightestParsedUpper = (\n self: ParsedBound,\n that: ParsedBound,\n): Result.Result<ParsedBound, QueryStreamKeyLayout.KeyLayoutMismatchError> =>\n Result.gen(function* () {\n yield* QueryStreamKeyLayout.validateEquivalence(\n self.key.layout,\n that.key.layout,\n );\n return tighterUpper(self, that);\n });\n\n/**\n * @experimental\n */\nexport const parseBound = (\n keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n { keyValues, inclusive }: KeyBound,\n): Result.Result<ParsedBound, QueryStreamKey.KeyWidthMismatchError> =>\n Result.map(QueryStreamKey.prefix(keyLayout, keyValues), (key) => ({\n key,\n inclusive,\n }));\n\n/**\n * @experimental\n */\nexport const parse = (\n keyLayout: QueryStreamKeyLayout.QueryStreamKeyLayout,\n keyBounds: KeyBounds,\n): Result.Result<ParsedBounds, QueryStreamKey.KeyWidthMismatchError> => {\n const endpoint = (bound: Option.Option<KeyBound>) =>\n Option.match(bound, {\n onNone: () => Result.succeed(Option.none<ParsedBound>()),\n onSome: (value) => Result.map(parseBound(keyLayout, value), Option.some),\n });\n return Result.gen(function* () {\n const lower = yield* endpoint(keyBounds.lower);\n const upper = yield* endpoint(keyBounds.upper);\n return make(keyLayout, { lower, upper });\n });\n};\n\n/**\n * @experimental\n */\nexport const toBounds = (parsedBounds: ParsedBounds): KeyBounds => ({\n lower: Option.map(parsedBounds.lower, rawBound),\n upper: Option.map(parsedBounds.upper, rawBound),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,MAAM,SAAS,KAAK,WAAmB;AAEvC,MAAM,UAAU,OAAO,OAAO;CAC5B,mBAAmB;CACnB,aAAa;CACb,iBAAiB;AACnB,CAAC;AAED,MAAM,eAAe,OAAO,OAAO;CACjC,cAAc,EAAE,gBAAgB;CAChC,QAAQ,EAAE,UAAUA,OAAsB,GAAG;CAC7C,YAAY,EAAE,gBAAgB;AAChC,CAAC;AAED,MAAM,cAAmC,MAAM,MAAM,MAAM,SAAS;CAClE,MAAM,gBAAgB,aAAa,IAAI;CACvC,MAAM,gBAAgB,aAAa,IAAI;CACvC,MAAM,YAAY,KAAK,IAAI,cAAc,QAAQ,cAAc,MAAM;CACrE,MAAM,iBAAiBC,QAA2B,KAAK,CAAC,CACtD,MAAM,KAAK,eAAe,SAAS,GACnC,MAAM,KAAK,eAAe,SAAS,CACrC;CACA,IAAI,mBAAmB,GACrB,OAAO;CAET,IAAI,cAAc,WAAW,cAAc,QACzC,OAAO,MAAM,OAAO,QAAQ,IAAI,GAAG,QAAQ,IAAI,CAAC;CAMlD,MAAM,gBAAgB,cAAc,SAAS,cAAc;CAC3D,MAAM,UAAU,gBAAgB,OAAO;CACvC,MAAM,kBAAkB,OAAO,OAAO,SAAS;EAC7C,mBAAmB;EACnB,aAAa;EACb,iBAAiB;CACnB,CAAC;CACD,OAAO,gBAAgB,kBAAmB,CAAC;AAC7C,CAAC;AAED,MAA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BAAgB,MAAmB,SACvC,YAAY,SAAS,SAAS,IAAI,CAAC,GAAG,SAAS,SAAS,IAAI,CAAC,CAAC,IAAI,IAC9D,OACA;;;;AAKN,MAAa,uBACX,MACA,SAEA,OAAO,IAAI,aAAa;CACtB,OAAOE,oBACL,KAAK,IAAI,QACT,KAAK,IAAI,MACX;CACA,OAAO,aAAa,MAAM,IAAI;AAChC,CAAC;;;;AAKH,MAAa,uBACX,MACA,SAEA,OAAO,IAAI,aAAa;CACtB,OAAOA,oBACL,KAAK,IAAI,QACT,KAAK,IAAI,MACX;CACA,OAAO,aAAa,MAAM,IAAI;AAChC,CAAC;;;;AAKH,MAAa,cACX,WACA,EAAE,WAAW,gBAEb,OAAO,IAAIC,OAAsB,WAAW,SAAS,IAAI,SAAS;CAChE;CACA;AACF,EAAE;;;;AAKJ,MAAa,SACX,WACA,cACsE;CACtE,MAAM,YAAY,UAChB,OAAO,MAAM,OAAO;EAClB,cAAc,OAAO,QAAQ,OAAO,KAAkB,CAAC;EACvD,SAAS,UAAU,OAAO,IAAI,WAAW,WAAW,KAAK,GAAG,OAAO,IAAI;CACzE,CAAC;CACH,OAAO,OAAO,IAAI,aAAa;EAC7B,MAAM,QAAQ,OAAO,SAAS,UAAU,KAAK;EAC7C,MAAM,QAAQ,OAAO,SAAS,UAAU,KAAK;EAC7C,OAAO,KAAK,WAAW;GAAE;GAAO;EAAM,CAAC;CACzC,CAAC;AACH;;;;AAKA,MAAa,YAAY,kBAA2C;CAClE,OAAO,OAAO,IAAI,aAAa,OAAO,QAAQ;CAC9C,OAAO,OAAO,IAAI,aAAa,OAAO,QAAQ;AAChD"}
@@ -2,7 +2,7 @@ import * as Data from "effect/Data";
2
2
  import * as Equivalence_ from "effect/Equivalence";
3
3
  import * as Result from "effect/Result";
4
4
  import type * as Types from "effect/Types";
5
- import * as QueryStreamKeyLabels from "./QueryStreamKeyLabels";
5
+ import * as QueryStreamKeyLabels from "./QueryStreamKeyLabels.js";
6
6
  /**
7
7
  * One runtime position of a stream key. Explicit IDs and their aliases are
8
8
  * visible; implicit ID tiebreakers have no label. Empty keys have no
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStreamKeyLayout.d.ts","sourceRoot":"","sources":["../src/QueryStreamKeyLayout.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AAGnD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC;IACrC,OAAO,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACpC,UAAU,EAAE,EAAE,CAAC;CAChB,CAAC,CAAC;AAGH,QAAA,MAAM,MAAM,yCAAyC,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,oBAAoB,CACnC,GAAG,CAAC,SAAS,SAAS,oBAAoB,CAAC,oBAAoB,GAC7D,oBAAoB,CAAC,oBAAoB;IAE3C,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE;QACjB,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC7C,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;KAC7C,CAAC;CACH;AAUD;;;;GAIG;AACH,eAAO,MAAM,SAAS,SACd,oBAAoB,KACzB,aAAa,CAAC,QAAQ,CAA2B,CAAC;AAErD;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,CAC7B,UAAU,SAAS,aAAa,CAAC,MAAM,CAAC,EACxC,KAAK,SAAS,MAAM,IAClB,KAAK,SAAS,OAAO,GAAG,UAAU,CAAC,UAAU,EAAE,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
@@ -1,10 +1,10 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { hasPrefix, make as make$1 } from "./QueryStreamKeyLabels.js";
3
+ import * as Data from "effect/Data";
4
+ import * as Array from "effect/Array";
3
5
  import { identity } from "effect/Function";
4
6
  import * as Option from "effect/Option";
5
- import * as Array from "effect/Array";
6
7
  import * as Result from "effect/Result";
7
- import * as Data from "effect/Data";
8
8
  import * as Equivalence_ from "effect/Equivalence";
9
9
  //#region src/QueryStreamKeyLayout.ts
10
10
  var QueryStreamKeyLayout_exports = /* @__PURE__ */ __exportAll({
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStreamKeyLayout.js","names":["QueryStreamKeyLabels.make","QueryStreamKeyLabels.hasPrefix"],"sources":["../src/QueryStreamKeyLayout.ts"],"sourcesContent":["import * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as Equivalence_ from \"effect/Equivalence\";\nimport { identity } from \"effect/Function\";\nimport * as Option from \"effect/Option\";\nimport * as Result from \"effect/Result\";\nimport type * as Types from \"effect/Types\";\n\nimport * as QueryStreamKeyLabels from \"./QueryStreamKeyLabels\";\n\n/**\n * One runtime position of a stream key. Explicit IDs and their aliases are\n * visible; implicit ID tiebreakers have no label. Empty keys have no\n * positions.\n *\n * @experimental\n */\nexport type Position = Data.TaggedEnum<{\n Visible: { readonly label: string };\n ImplicitId: {};\n}>;\n\nconst Position = Data.taggedEnum<Position>();\nconst TypeId = \"@confect/server/QueryStreamKeyLayout\";\n\n/**\n * Describes the positions in a stream's keys: their sequence, their labels, and\n * where implicit document-ID tiebreakers occur. Every element has its own key\n * values; the stream has one shared layout.\n *\n * For example, labels `[\"text\", \"_creationTime\"]` describe the labeled\n * positions in a key such as `[\"apple\", 1, \"n1\"]`. Its layout also records the\n * final implicit ID position. Joined layouts retain each component's ID, so\n * their labels alone do not describe every key position.\n *\n * Layouts are compatible when they have the same total width, labels in the\n * same positions, and implicit-ID positions. Direction is separate. Layouts\n * contain no key values, value-type schemas, table identity, or equality-pinned\n * values. Labels start as index field paths but may be renamed. An explicit ID,\n * such as in `by_id`, has a label.\n *\n * Reuse a stream's `keyLayout` with `empty` or `flatMap`'s `innerKeyLayout`.\n * Creating a stream to obtain its layout does not read documents. The\n * `KeyLabels` parameter tracks only labels; implicit-ID positions are checked\n * at runtime. Normally this type is inferred from the source stream.\n *\n * @experimental\n */\nexport interface QueryStreamKeyLayout<\n out KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels =\n QueryStreamKeyLabels.QueryStreamKeyLabels,\n> {\n readonly [TypeId]: {\n readonly _Labels: Types.Covariant<KeyLabels>;\n readonly positions: ReadonlyArray<Position>;\n };\n}\n\n// Private construction keeps the visible label witness with the operations\n// that derive it from index fields, concatenation, or renaming.\nconst make = <KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels>(\n positions: ReadonlyArray<Position>,\n): QueryStreamKeyLayout<KeyLabels> => ({\n [TypeId]: { _Labels: identity, positions },\n});\n\n/**\n * The runtime positions, including implicit ID tiebreakers.\n *\n * @experimental\n */\nexport const positions = (\n self: QueryStreamKeyLayout,\n): ReadonlyArray<Position> => self[TypeId].positions;\n\n/**\n * The source field paths remaining after an equality prefix.\n *\n * @experimental\n */\nexport type RemainingFieldPaths<\n FieldPaths extends ReadonlyArray<string>,\n Count extends number,\n> = Count extends unknown ? DropPrefix<FieldPaths, Count> : never;\n\ntype DropPrefix<\n FieldPaths extends ReadonlyArray<string>,\n Count extends number,\n Prefix extends ReadonlyArray<unknown> = [],\n> = number extends Count\n ? ReadonlyArray<string>\n : Prefix[\"length\"] extends Count\n ? Types.Mutable<FieldPaths>\n : FieldPaths extends readonly [\n string,\n ...infer TailFieldPaths extends ReadonlyArray<string>,\n ]\n ? DropPrefix<TailFieldPaths, Count, readonly [...Prefix, unknown]>\n : FieldPaths extends readonly []\n ? []\n : ReadonlyArray<string>;\n\n/**\n * The equality prefix cannot select a whole number of source field paths.\n *\n * @experimental\n */\nexport class InvalidEqualityPrefixError extends Data.TaggedError(\n \"InvalidEqualityPrefixError\",\n)<{\n readonly fieldPaths: ReadonlyArray<string>;\n readonly eqCount: number;\n}> {\n override get message(): string {\n return `QueryStreamKeyLayout.fromIndex: invalid equality prefix length (${this.eqCount}) for ${this.fieldPaths.length} field paths`;\n }\n}\n\n/**\n * The requested labels do not form a prefix of the layout's visible labels.\n *\n * @experimental\n */\nexport class InvalidLabelPrefixError extends Data.TaggedError(\n \"InvalidLabelPrefixError\",\n)<{\n readonly keyLabels: QueryStreamKeyLabels.QueryStreamKeyLabels;\n readonly prefixKeyLabels: QueryStreamKeyLabels.QueryStreamKeyLabels;\n}> {\n override get message(): string {\n return `Labels ([${Array.join(this.prefixKeyLabels, \", \")}]) must be a prefix of the ordering labels ([${Array.join(this.keyLabels, \", \")}])`;\n }\n}\n\n/**\n * The replacement labels cannot fill exactly the layout's visible positions.\n *\n * @experimental\n */\nexport class LabelCountMismatchError extends Data.TaggedError(\n \"LabelCountMismatchError\",\n)<{\n readonly keyLabels: QueryStreamKeyLabels.QueryStreamKeyLabels;\n readonly replacementKeyLabels: QueryStreamKeyLabels.QueryStreamKeyLabels;\n}> {\n override get message(): string {\n return `Replacement labels ([${Array.join(this.replacementKeyLabels, \", \")}]) must have as many labels as the ordering labels ([${Array.join(this.keyLabels, \", \")}])`;\n }\n}\n\n/**\n * Construct a scan layout from the original index field paths, before equality\n * pinning. Only an ID absent from the end of that original key is implicit.\n * Pinning every field of `by_id` produces a zero-width layout; pinning every\n * visible field of another index leaves its implicit ID. Invalid equality\n * prefix lengths return `InvalidEqualityPrefixError`.\n *\n * @experimental\n */\nexport function fromIndex<const FieldPaths extends ReadonlyArray<string>>(\n fieldPaths: FieldPaths,\n): Result.Result<\n QueryStreamKeyLayout<QueryStreamKeyLabels.QueryStreamKeyLabels<FieldPaths>>,\n InvalidEqualityPrefixError\n>;\n/**\n * @experimental\n */\nexport function fromIndex<\n const FieldPaths extends ReadonlyArray<string>,\n const Count extends number,\n>(\n fieldPaths: FieldPaths,\n eqCount: Count,\n): Result.Result<\n QueryStreamKeyLayout<\n QueryStreamKeyLabels.QueryStreamKeyLabels<\n RemainingFieldPaths<FieldPaths, Count>\n >\n >,\n InvalidEqualityPrefixError\n>;\nexport function fromIndex(\n fieldPaths: ReadonlyArray<string>,\n eqCount = 0,\n): Result.Result<QueryStreamKeyLayout, InvalidEqualityPrefixError> {\n if (\n !Number.isInteger(eqCount) ||\n eqCount < 0 ||\n eqCount > fieldPaths.length\n ) {\n return Result.fail(new InvalidEqualityPrefixError({ fieldPaths, eqCount }));\n }\n const visible = Array.map(Array.drop(fieldPaths, eqCount), (label) =>\n Position.Visible({ label }),\n );\n const keyPositions = Option.exists(\n Array.last(fieldPaths),\n (fieldPath) => fieldPath === \"_id\",\n )\n ? visible\n : Array.append(visible, Position.ImplicitId());\n return Result.succeed(make(keyPositions));\n}\n\n/**\n * Concatenate layouts without losing component tiebreakers.\n *\n * @experimental\n */\nexport const concat = <\n LeftKeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels,\n RightKeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels,\n>(\n self: QueryStreamKeyLayout<LeftKeyLabels>,\n that: QueryStreamKeyLayout<RightKeyLabels>,\n): QueryStreamKeyLayout<\n QueryStreamKeyLabels.Concat<LeftKeyLabels, RightKeyLabels>\n> => make(Array.appendAll(positions(self), positions(that)));\n\n/**\n * Format visible labels and implicit IDs for diagnostics.\n *\n * @experimental\n */\nexport const format = (self: QueryStreamKeyLayout): string => {\n const tokens = Array.map(\n positions(self),\n Position.$match({\n Visible: ({ label }) => JSON.stringify(label),\n ImplicitId: () => \"<implicit _id>\",\n }),\n );\n return `[${Array.join(tokens, \", \")}]`;\n};\n\n/**\n * The labels available to `distinct` and `renameKey`.\n *\n * @experimental\n */\nexport function visibleLabels<\n KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels,\n>(self: QueryStreamKeyLayout<KeyLabels>): KeyLabels;\nexport function visibleLabels(\n self: QueryStreamKeyLayout,\n): QueryStreamKeyLabels.QueryStreamKeyLabels {\n return QueryStreamKeyLabels.make(\n Array.filterMap(\n positions(self),\n Position.$match({\n Visible: ({ label }) => Result.succeed(label),\n ImplicitId: () => Result.failVoid,\n }),\n ),\n );\n}\n\n/**\n * Number of positions in an element's runtime key.\n *\n * @experimental\n */\nexport const runtimeWidth = (self: QueryStreamKeyLayout): number =>\n positions(self).length;\n\n// Runtime offsets of visible labels, used to resolve label prefixes.\nconst visiblePositions = (self: QueryStreamKeyLayout): ReadonlyArray<number> =>\n Array.filterMap(positions(self), (position, index) =>\n Position.$is(\"Visible\")(position) ? Result.succeed(index) : Result.failVoid,\n );\n\nconst PositionsEquivalence = Equivalence_.Array<Position>((self, that) =>\n Position.$match(self, {\n Visible: ({ label }) =>\n Position.$is(\"Visible\")(that) && label === that.label,\n ImplicitId: () => Position.$is(\"ImplicitId\")(that),\n }),\n);\n\n/**\n * @experimental\n */\nexport const Equivalence: Equivalence_.Equivalence<QueryStreamKeyLayout> =\n Equivalence_.mapInput(PositionsEquivalence, positions);\n\n/**\n * @experimental\n */\nexport class KeyLayoutMismatchError extends Data.TaggedError(\n \"KeyLayoutMismatchError\",\n)<{\n readonly expectedKeyLayout: QueryStreamKeyLayout;\n readonly actualKeyLayout: QueryStreamKeyLayout;\n}> {\n override get message(): string {\n return `Key layout (${format(this.actualKeyLayout)}) does not match the expected layout (${format(this.expectedKeyLayout)})`;\n }\n}\n\n/**\n * @experimental\n */\nexport const validateEquivalence = (\n expectedKeyLayout: QueryStreamKeyLayout,\n actualKeyLayout: QueryStreamKeyLayout,\n): Result.Result<void, KeyLayoutMismatchError> =>\n Equivalence(expectedKeyLayout, actualKeyLayout)\n ? Result.succeed(undefined)\n : Result.fail(\n new KeyLayoutMismatchError({ expectedKeyLayout, actualKeyLayout }),\n );\n\n/**\n * Parse a visible label prefix and resolve its runtime width. Implicit IDs\n * before the last selected label are included; implicit IDs after it are not.\n *\n * @experimental\n */\nexport const resolvePrefix = (\n self: QueryStreamKeyLayout,\n prefixKeyLabels: QueryStreamKeyLabels.QueryStreamKeyLabels,\n): Result.Result<number, InvalidLabelPrefixError> => {\n const keyLabels = visibleLabels(self);\n if (!QueryStreamKeyLabels.hasPrefix(keyLabels, prefixKeyLabels)) {\n return Result.fail(\n new InvalidLabelPrefixError({ keyLabels, prefixKeyLabels }),\n );\n }\n return Result.succeed(\n Option.match(\n Array.get(visiblePositions(self), prefixKeyLabels.length - 1),\n {\n onNone: () => 0,\n onSome: (position) => position + 1,\n },\n ),\n );\n};\n\n/**\n * Relabel visible positions, preserving every implicit ID.\n *\n * @experimental\n */\nexport const rename = <\n ReplacementKeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels,\n>(\n self: QueryStreamKeyLayout,\n replacementKeyLabels: ReplacementKeyLabels,\n): Result.Result<\n QueryStreamKeyLayout<ReplacementKeyLabels>,\n LabelCountMismatchError\n> => {\n const [consumed, renamed] = Array.mapAccum(\n positions(self),\n 0,\n (index, position): readonly [number, Option.Option<Position>] =>\n Position.$match(position, {\n ImplicitId: () => [index, Option.some(position)] as const,\n Visible: () =>\n [\n index + 1,\n Option.map(Array.get(replacementKeyLabels, index), (label) =>\n Position.Visible({ label }),\n ),\n ] as const,\n }),\n );\n const parsed =\n consumed === replacementKeyLabels.length\n ? Option.all(renamed)\n : Option.none();\n return Result.fromOption(\n Option.map(parsed, make<ReplacementKeyLabels>),\n () =>\n new LabelCountMismatchError({\n keyLabels: visibleLabels(self),\n replacementKeyLabels,\n }),\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,WAAW,KAAK,WAAqB;AAC3C,MAAM,SAAS;AAqCf,MAAM,QACJ,eACqC,GACpC,SAAS;CAAE,SAAS;CAAU;AAAU,EAC3C;;;;;;AAOA,MAAa,aACX,SAC4B,KAAK,OAAO,CAAC;;;;;;AAkC3C,IAAa,6BAAb,cAAgD,KAAK,YACnD,4BACF,CAAC,CAG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AAS,CAAC,GAC5D;EACE,cAAc;EACd,SAAS,aAAa,WAAW;CACnC,CACF,CACF;AACF;;;;;;AAOA,MAAa,UAGX,MACA,yBAIG;CACH,MAAM,CAAC,UAAU,WAAW,MAAM,SAChC,UAAU,IAAI,GACd,IACC,OAAO,aACN,SAAS,OAAO,UAAU;EACxB,kBAAkB,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC;EAC/C,eACE,CACE,QAAQ,GACR,OAAO,IAAI,MAAM,IAAI,sBAAsB,KAAK,IAAI,UAClD,SAAS,QAAQ,EAAE,MAAM,CAAC,CAC5B,CACF;CACJ,CAAC,CACL;CACA,MAAM,SACJ,aAAa,qBAAqB,SAC9B,OAAO,IAAI,OAAO,IAClB,OAAO,KAAK;CAClB,OAAO,OAAO,WACZ,OAAO,IAAI,QAAQ,IAA0B,SAE3C,IAAI,wBAAwB;EAC1B,WAAW,cAAc,IAAI;EAC7B;CACF,CAAC,CACL;AACF"}
1
+ {"version":3,"file":"QueryStreamKeyLayout.js","names":["QueryStreamKeyLabels.make","QueryStreamKeyLabels.hasPrefix"],"sources":["../src/QueryStreamKeyLayout.ts"],"sourcesContent":["import * as Array from \"effect/Array\";\nimport * as Data from \"effect/Data\";\nimport * as Equivalence_ from \"effect/Equivalence\";\nimport { identity } from \"effect/Function\";\nimport * as Option from \"effect/Option\";\nimport * as Result from \"effect/Result\";\nimport type * as Types from \"effect/Types\";\n\nimport * as QueryStreamKeyLabels from \"./QueryStreamKeyLabels.js\";\n\n/**\n * One runtime position of a stream key. Explicit IDs and their aliases are\n * visible; implicit ID tiebreakers have no label. Empty keys have no\n * positions.\n *\n * @experimental\n */\nexport type Position = Data.TaggedEnum<{\n Visible: { readonly label: string };\n ImplicitId: {};\n}>;\n\nconst Position = Data.taggedEnum<Position>();\nconst TypeId = \"@confect/server/QueryStreamKeyLayout\";\n\n/**\n * Describes the positions in a stream's keys: their sequence, their labels, and\n * where implicit document-ID tiebreakers occur. Every element has its own key\n * values; the stream has one shared layout.\n *\n * For example, labels `[\"text\", \"_creationTime\"]` describe the labeled\n * positions in a key such as `[\"apple\", 1, \"n1\"]`. Its layout also records the\n * final implicit ID position. Joined layouts retain each component's ID, so\n * their labels alone do not describe every key position.\n *\n * Layouts are compatible when they have the same total width, labels in the\n * same positions, and implicit-ID positions. Direction is separate. Layouts\n * contain no key values, value-type schemas, table identity, or equality-pinned\n * values. Labels start as index field paths but may be renamed. An explicit ID,\n * such as in `by_id`, has a label.\n *\n * Reuse a stream's `keyLayout` with `empty` or `flatMap`'s `innerKeyLayout`.\n * Creating a stream to obtain its layout does not read documents. The\n * `KeyLabels` parameter tracks only labels; implicit-ID positions are checked\n * at runtime. Normally this type is inferred from the source stream.\n *\n * @experimental\n */\nexport interface QueryStreamKeyLayout<\n out KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels =\n QueryStreamKeyLabels.QueryStreamKeyLabels,\n> {\n readonly [TypeId]: {\n readonly _Labels: Types.Covariant<KeyLabels>;\n readonly positions: ReadonlyArray<Position>;\n };\n}\n\n// Private construction keeps the visible label witness with the operations\n// that derive it from index fields, concatenation, or renaming.\nconst make = <KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels>(\n positions: ReadonlyArray<Position>,\n): QueryStreamKeyLayout<KeyLabels> => ({\n [TypeId]: { _Labels: identity, positions },\n});\n\n/**\n * The runtime positions, including implicit ID tiebreakers.\n *\n * @experimental\n */\nexport const positions = (\n self: QueryStreamKeyLayout,\n): ReadonlyArray<Position> => self[TypeId].positions;\n\n/**\n * The source field paths remaining after an equality prefix.\n *\n * @experimental\n */\nexport type RemainingFieldPaths<\n FieldPaths extends ReadonlyArray<string>,\n Count extends number,\n> = Count extends unknown ? DropPrefix<FieldPaths, Count> : never;\n\ntype DropPrefix<\n FieldPaths extends ReadonlyArray<string>,\n Count extends number,\n Prefix extends ReadonlyArray<unknown> = [],\n> = number extends Count\n ? ReadonlyArray<string>\n : Prefix[\"length\"] extends Count\n ? Types.Mutable<FieldPaths>\n : FieldPaths extends readonly [\n string,\n ...infer TailFieldPaths extends ReadonlyArray<string>,\n ]\n ? DropPrefix<TailFieldPaths, Count, readonly [...Prefix, unknown]>\n : FieldPaths extends readonly []\n ? []\n : ReadonlyArray<string>;\n\n/**\n * The equality prefix cannot select a whole number of source field paths.\n *\n * @experimental\n */\nexport class InvalidEqualityPrefixError extends Data.TaggedError(\n \"InvalidEqualityPrefixError\",\n)<{\n readonly fieldPaths: ReadonlyArray<string>;\n readonly eqCount: number;\n}> {\n override get message(): string {\n return `QueryStreamKeyLayout.fromIndex: invalid equality prefix length (${this.eqCount}) for ${this.fieldPaths.length} field paths`;\n }\n}\n\n/**\n * The requested labels do not form a prefix of the layout's visible labels.\n *\n * @experimental\n */\nexport class InvalidLabelPrefixError extends Data.TaggedError(\n \"InvalidLabelPrefixError\",\n)<{\n readonly keyLabels: QueryStreamKeyLabels.QueryStreamKeyLabels;\n readonly prefixKeyLabels: QueryStreamKeyLabels.QueryStreamKeyLabels;\n}> {\n override get message(): string {\n return `Labels ([${Array.join(this.prefixKeyLabels, \", \")}]) must be a prefix of the ordering labels ([${Array.join(this.keyLabels, \", \")}])`;\n }\n}\n\n/**\n * The replacement labels cannot fill exactly the layout's visible positions.\n *\n * @experimental\n */\nexport class LabelCountMismatchError extends Data.TaggedError(\n \"LabelCountMismatchError\",\n)<{\n readonly keyLabels: QueryStreamKeyLabels.QueryStreamKeyLabels;\n readonly replacementKeyLabels: QueryStreamKeyLabels.QueryStreamKeyLabels;\n}> {\n override get message(): string {\n return `Replacement labels ([${Array.join(this.replacementKeyLabels, \", \")}]) must have as many labels as the ordering labels ([${Array.join(this.keyLabels, \", \")}])`;\n }\n}\n\n/**\n * Construct a scan layout from the original index field paths, before equality\n * pinning. Only an ID absent from the end of that original key is implicit.\n * Pinning every field of `by_id` produces a zero-width layout; pinning every\n * visible field of another index leaves its implicit ID. Invalid equality\n * prefix lengths return `InvalidEqualityPrefixError`.\n *\n * @experimental\n */\nexport function fromIndex<const FieldPaths extends ReadonlyArray<string>>(\n fieldPaths: FieldPaths,\n): Result.Result<\n QueryStreamKeyLayout<QueryStreamKeyLabels.QueryStreamKeyLabels<FieldPaths>>,\n InvalidEqualityPrefixError\n>;\n/**\n * @experimental\n */\nexport function fromIndex<\n const FieldPaths extends ReadonlyArray<string>,\n const Count extends number,\n>(\n fieldPaths: FieldPaths,\n eqCount: Count,\n): Result.Result<\n QueryStreamKeyLayout<\n QueryStreamKeyLabels.QueryStreamKeyLabels<\n RemainingFieldPaths<FieldPaths, Count>\n >\n >,\n InvalidEqualityPrefixError\n>;\nexport function fromIndex(\n fieldPaths: ReadonlyArray<string>,\n eqCount = 0,\n): Result.Result<QueryStreamKeyLayout, InvalidEqualityPrefixError> {\n if (\n !Number.isInteger(eqCount) ||\n eqCount < 0 ||\n eqCount > fieldPaths.length\n ) {\n return Result.fail(new InvalidEqualityPrefixError({ fieldPaths, eqCount }));\n }\n const visible = Array.map(Array.drop(fieldPaths, eqCount), (label) =>\n Position.Visible({ label }),\n );\n const keyPositions = Option.exists(\n Array.last(fieldPaths),\n (fieldPath) => fieldPath === \"_id\",\n )\n ? visible\n : Array.append(visible, Position.ImplicitId());\n return Result.succeed(make(keyPositions));\n}\n\n/**\n * Concatenate layouts without losing component tiebreakers.\n *\n * @experimental\n */\nexport const concat = <\n LeftKeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels,\n RightKeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels,\n>(\n self: QueryStreamKeyLayout<LeftKeyLabels>,\n that: QueryStreamKeyLayout<RightKeyLabels>,\n): QueryStreamKeyLayout<\n QueryStreamKeyLabels.Concat<LeftKeyLabels, RightKeyLabels>\n> => make(Array.appendAll(positions(self), positions(that)));\n\n/**\n * Format visible labels and implicit IDs for diagnostics.\n *\n * @experimental\n */\nexport const format = (self: QueryStreamKeyLayout): string => {\n const tokens = Array.map(\n positions(self),\n Position.$match({\n Visible: ({ label }) => JSON.stringify(label),\n ImplicitId: () => \"<implicit _id>\",\n }),\n );\n return `[${Array.join(tokens, \", \")}]`;\n};\n\n/**\n * The labels available to `distinct` and `renameKey`.\n *\n * @experimental\n */\nexport function visibleLabels<\n KeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels,\n>(self: QueryStreamKeyLayout<KeyLabels>): KeyLabels;\nexport function visibleLabels(\n self: QueryStreamKeyLayout,\n): QueryStreamKeyLabels.QueryStreamKeyLabels {\n return QueryStreamKeyLabels.make(\n Array.filterMap(\n positions(self),\n Position.$match({\n Visible: ({ label }) => Result.succeed(label),\n ImplicitId: () => Result.failVoid,\n }),\n ),\n );\n}\n\n/**\n * Number of positions in an element's runtime key.\n *\n * @experimental\n */\nexport const runtimeWidth = (self: QueryStreamKeyLayout): number =>\n positions(self).length;\n\n// Runtime offsets of visible labels, used to resolve label prefixes.\nconst visiblePositions = (self: QueryStreamKeyLayout): ReadonlyArray<number> =>\n Array.filterMap(positions(self), (position, index) =>\n Position.$is(\"Visible\")(position) ? Result.succeed(index) : Result.failVoid,\n );\n\nconst PositionsEquivalence = Equivalence_.Array<Position>((self, that) =>\n Position.$match(self, {\n Visible: ({ label }) =>\n Position.$is(\"Visible\")(that) && label === that.label,\n ImplicitId: () => Position.$is(\"ImplicitId\")(that),\n }),\n);\n\n/**\n * @experimental\n */\nexport const Equivalence: Equivalence_.Equivalence<QueryStreamKeyLayout> =\n Equivalence_.mapInput(PositionsEquivalence, positions);\n\n/**\n * @experimental\n */\nexport class KeyLayoutMismatchError extends Data.TaggedError(\n \"KeyLayoutMismatchError\",\n)<{\n readonly expectedKeyLayout: QueryStreamKeyLayout;\n readonly actualKeyLayout: QueryStreamKeyLayout;\n}> {\n override get message(): string {\n return `Key layout (${format(this.actualKeyLayout)}) does not match the expected layout (${format(this.expectedKeyLayout)})`;\n }\n}\n\n/**\n * @experimental\n */\nexport const validateEquivalence = (\n expectedKeyLayout: QueryStreamKeyLayout,\n actualKeyLayout: QueryStreamKeyLayout,\n): Result.Result<void, KeyLayoutMismatchError> =>\n Equivalence(expectedKeyLayout, actualKeyLayout)\n ? Result.succeed(undefined)\n : Result.fail(\n new KeyLayoutMismatchError({ expectedKeyLayout, actualKeyLayout }),\n );\n\n/**\n * Parse a visible label prefix and resolve its runtime width. Implicit IDs\n * before the last selected label are included; implicit IDs after it are not.\n *\n * @experimental\n */\nexport const resolvePrefix = (\n self: QueryStreamKeyLayout,\n prefixKeyLabels: QueryStreamKeyLabels.QueryStreamKeyLabels,\n): Result.Result<number, InvalidLabelPrefixError> => {\n const keyLabels = visibleLabels(self);\n if (!QueryStreamKeyLabels.hasPrefix(keyLabels, prefixKeyLabels)) {\n return Result.fail(\n new InvalidLabelPrefixError({ keyLabels, prefixKeyLabels }),\n );\n }\n return Result.succeed(\n Option.match(\n Array.get(visiblePositions(self), prefixKeyLabels.length - 1),\n {\n onNone: () => 0,\n onSome: (position) => position + 1,\n },\n ),\n );\n};\n\n/**\n * Relabel visible positions, preserving every implicit ID.\n *\n * @experimental\n */\nexport const rename = <\n ReplacementKeyLabels extends QueryStreamKeyLabels.QueryStreamKeyLabels,\n>(\n self: QueryStreamKeyLayout,\n replacementKeyLabels: ReplacementKeyLabels,\n): Result.Result<\n QueryStreamKeyLayout<ReplacementKeyLabels>,\n LabelCountMismatchError\n> => {\n const [consumed, renamed] = Array.mapAccum(\n positions(self),\n 0,\n (index, position): readonly [number, Option.Option<Position>] =>\n Position.$match(position, {\n ImplicitId: () => [index, Option.some(position)] as const,\n Visible: () =>\n [\n index + 1,\n Option.map(Array.get(replacementKeyLabels, index), (label) =>\n Position.Visible({ label }),\n ),\n ] as const,\n }),\n );\n const parsed =\n consumed === replacementKeyLabels.length\n ? Option.all(renamed)\n : Option.none();\n return Result.fromOption(\n Option.map(parsed, make<ReplacementKeyLabels>),\n () =>\n new LabelCountMismatchError({\n keyLabels: visibleLabels(self),\n replacementKeyLabels,\n }),\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,WAAW,KAA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AM,YAAY,cAAc,IAAI;CACpC,IAAI,CAACC,UAA+B,WAAW,eAAe,GAC5D,OAAO,OAAO,KACZ,IAAI,wBAAwB;EAAE;EAAW;CAAgB,CAAC,CAC5D;CAEF,OAAO,OAAO,QACZ,OAAO,MACL,MAAM,IAAI,iBAAiB,IAAI,GAAG,gBAAgB,SAAS,CAAC,GAC5D;EACE,cAAc;EACd,SAAS,aAAa,WAAW;CACnC,CACF,CACF;AACF;;;;;;AAOA,MAAa,UAGX,MACA,yBAIG;CACH,MAAM,CAAC,UAAU,WAAW,MAAM,SAChC,UAAU,IAAI,GACd,IACC,OAAO,aACN,SAAS,OAAO,UAAU;EACxB,kBAAkB,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC;EAC/C,eACE,CACE,QAAQ,GACR,OAAO,IAAI,MAAM,IAAI,sBAAsB,KAAK,IAAI,UAClD,SAAS,QAAQ,EAAE,MAAM,CAAC,CAC5B,CACF;CACJ,CAAC,CACL;CACA,MAAM,SACJ,aAAa,qBAAqB,SAC9B,OAAO,IAAI,OAAO,IAClB,OAAO,KAAK;CAClB,OAAO,OAAO,WACZ,OAAO,IAAI,QAAQ,IAA0B,SAE3C,IAAI,wBAAwB;EAC1B,WAAW,cAAc,IAAI;EAC7B;CACF,CAAC,CACL;AACF"}
@@ -2,7 +2,7 @@ import { type Value } from "convex/values";
2
2
  import * as Order_ from "effect/Order";
3
3
  import type * as Record from "effect/Record";
4
4
  import * as Schema from "effect/Schema";
5
- import type * as QueryStreamOrderDirection from "./QueryStreamOrderDirection";
5
+ import type * as QueryStreamOrderDirection from "./QueryStreamOrderDirection.js";
6
6
  declare const KeyValue: Schema.decodeTo<Schema.declare<Value | undefined, Value | undefined>, Schema.Codec<Schema.Json, Schema.Json, never, never>, never, never>;
7
7
  /**
8
8
  * @experimental
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStreamKeyValues.d.ts","sourceRoot":"","sources":["../src/QueryStreamKeyValues.ts"],"names":[],"mappings":"AAAA,OAA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;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,oBAAoB,0JAAyB,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,OAAO,oBAAoB,CAAC,IAAI,CAAC;AAEpE;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAE7C,CAAC;AAKF;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,mBACA,yBAAyB,CAAC,yBAAyB,KAClE,MAAM,CAAC,KAAK,CAAC,oBAAoB,CACyB,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,OAAO,YACT,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,YACrC,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,KAC7C,oBAUwB,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import * as Effect from "effect/Effect";
3
+ import * as Array from "effect/Array";
3
4
  import * as Schema from "effect/Schema";
4
5
  import { compareValues, convexToJson, jsonToConvex } from "convex/values";
5
- import * as Array from "effect/Array";
6
6
  import * as Order_ from "effect/Order";
7
7
  import * as Result from "effect/Result";
8
8
  import * as SchemaIssue from "effect/SchemaIssue";