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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/dist/ActionCtx.d.ts +1 -1
  2. package/dist/ActionCtx.d.ts.map +1 -1
  3. package/dist/ActionCtx.js.map +1 -1
  4. package/dist/AiGatewayDecisionClient.d.ts +2 -2
  5. package/dist/AiGatewayDecisionClient.d.ts.map +1 -1
  6. package/dist/AiGatewayDecisionClient.js.map +1 -1
  7. package/dist/AiGatewayLanguageClient.d.ts +2 -2
  8. package/dist/AiGatewayLanguageClient.d.ts.map +1 -1
  9. package/dist/AiGatewayLanguageClient.js.map +1 -1
  10. package/dist/Auth.d.ts +1 -1
  11. package/dist/Auth.d.ts.map +1 -1
  12. package/dist/Auth.js.map +1 -1
  13. package/dist/ComponentCtx.d.ts +1 -1
  14. package/dist/ComponentCtx.d.ts.map +1 -1
  15. package/dist/ConvexFunctionDefinitions.d.ts +4 -4
  16. package/dist/ConvexFunctionDefinitions.d.ts.map +1 -1
  17. package/dist/ConvexFunctionDefinitions.js.map +1 -1
  18. package/dist/CronJobs.d.ts +1 -1
  19. package/dist/CronJobs.d.ts.map +1 -1
  20. package/dist/CronJobs.js.map +1 -1
  21. package/dist/DataModel.d.ts +3 -3
  22. package/dist/DataModel.d.ts.map +1 -1
  23. package/dist/DataModel.js.map +1 -1
  24. package/dist/DatabaseReader.d.ts +4 -4
  25. package/dist/DatabaseReader.d.ts.map +1 -1
  26. package/dist/DatabaseReader.js.map +1 -1
  27. package/dist/DatabaseSchema.d.ts +1 -1
  28. package/dist/DatabaseSchema.d.ts.map +1 -1
  29. package/dist/DatabaseSchema.js.map +1 -1
  30. package/dist/DatabaseWriter.d.ts +5 -5
  31. package/dist/DatabaseWriter.d.ts.map +1 -1
  32. package/dist/DatabaseWriter.js.map +1 -1
  33. package/dist/Document.d.ts +4 -4
  34. package/dist/Document.d.ts.map +1 -1
  35. package/dist/Document.js.map +1 -1
  36. package/dist/FunctionImpl.d.ts +2 -2
  37. package/dist/FunctionImpl.d.ts.map +1 -1
  38. package/dist/FunctionImpl.js.map +1 -1
  39. package/dist/FunctionRegistryItem.d.ts +1 -1
  40. package/dist/FunctionRegistryItem.d.ts.map +1 -1
  41. package/dist/FunctionRegistryItem.js.map +1 -1
  42. package/dist/GroupImpl.d.ts +3 -3
  43. package/dist/GroupImpl.d.ts.map +1 -1
  44. package/dist/GroupImpl.js.map +1 -1
  45. package/dist/GroupRegistry.d.ts +2 -2
  46. package/dist/GroupRegistry.d.ts.map +1 -1
  47. package/dist/GroupRegistry.js.map +1 -1
  48. package/dist/Handler.d.ts +23 -23
  49. package/dist/Handler.d.ts.map +1 -1
  50. package/dist/Handler.js.map +1 -1
  51. package/dist/HttpRouter.d.ts +13 -13
  52. package/dist/HttpRouter.d.ts.map +1 -1
  53. package/dist/HttpRouter.js.map +1 -1
  54. package/dist/MiddlewareImpl.d.ts +14 -14
  55. package/dist/MiddlewareImpl.d.ts.map +1 -1
  56. package/dist/MiddlewareImpl.js.map +1 -1
  57. package/dist/MutationCtx.d.ts +1 -1
  58. package/dist/MutationCtx.d.ts.map +1 -1
  59. package/dist/MutationCtx.js.map +1 -1
  60. package/dist/MutationRunner.d.ts +1 -1
  61. package/dist/MutationRunner.d.ts.map +1 -1
  62. package/dist/MutationRunner.js.map +1 -1
  63. package/dist/MutationTransactionContext.d.ts +2 -2
  64. package/dist/MutationTransactionContext.d.ts.map +1 -1
  65. package/dist/MutationTransactionContext.js.map +1 -1
  66. package/dist/OfficialComponent.d.ts +50 -0
  67. package/dist/OfficialComponent.d.ts.map +1 -0
  68. package/dist/OfficialComponent.js +70 -0
  69. package/dist/OfficialComponent.js.map +1 -0
  70. package/dist/OrderedQuery.d.ts +4 -4
  71. package/dist/OrderedQuery.d.ts.map +1 -1
  72. package/dist/OrderedQuery.js.map +1 -1
  73. package/dist/QueryCtx.d.ts +1 -1
  74. package/dist/QueryCtx.d.ts.map +1 -1
  75. package/dist/QueryCtx.js.map +1 -1
  76. package/dist/QueryInitializer.d.ts +10 -10
  77. package/dist/QueryInitializer.d.ts.map +1 -1
  78. package/dist/QueryInitializer.js.map +1 -1
  79. package/dist/QueryRunner.d.ts +2 -2
  80. package/dist/QueryRunner.d.ts.map +1 -1
  81. package/dist/QueryRunner.js.map +1 -1
  82. package/dist/QueryStream.d.ts +11 -11
  83. package/dist/QueryStream.d.ts.map +1 -1
  84. package/dist/QueryStream.js.map +1 -1
  85. package/dist/QueryStreamCursor.d.ts +2 -2
  86. package/dist/QueryStreamCursor.d.ts.map +1 -1
  87. package/dist/QueryStreamCursor.js.map +1 -1
  88. package/dist/QueryStreamIndexPrefix.d.ts +2 -2
  89. package/dist/QueryStreamIndexPrefix.d.ts.map +1 -1
  90. package/dist/QueryStreamIndexPrefix.js.map +1 -1
  91. package/dist/QueryStreamIndexRange.d.ts +4 -4
  92. package/dist/QueryStreamIndexRange.d.ts.map +1 -1
  93. package/dist/QueryStreamIndexRange.js.map +1 -1
  94. package/dist/QueryStreamKey.d.ts +2 -2
  95. package/dist/QueryStreamKey.d.ts.map +1 -1
  96. package/dist/QueryStreamKey.js.map +1 -1
  97. package/dist/QueryStreamKeyBounds.d.ts +3 -3
  98. package/dist/QueryStreamKeyBounds.d.ts.map +1 -1
  99. package/dist/QueryStreamKeyBounds.js.map +1 -1
  100. package/dist/QueryStreamKeyLayout.d.ts +1 -1
  101. package/dist/QueryStreamKeyLayout.d.ts.map +1 -1
  102. package/dist/QueryStreamKeyLayout.js.map +1 -1
  103. package/dist/QueryStreamKeyValues.d.ts +1 -1
  104. package/dist/QueryStreamKeyValues.d.ts.map +1 -1
  105. package/dist/QueryStreamKeyValues.js.map +1 -1
  106. package/dist/QueryStreamPagination.d.ts +1 -1
  107. package/dist/QueryStreamPagination.d.ts.map +1 -1
  108. package/dist/QueryStreamPagination.js.map +1 -1
  109. package/dist/RegisteredConvexFunction.d.ts +20 -20
  110. package/dist/RegisteredConvexFunction.d.ts.map +1 -1
  111. package/dist/RegisteredConvexFunction.js.map +1 -1
  112. package/dist/RegisteredFunction.d.ts +26 -26
  113. package/dist/RegisteredFunction.d.ts.map +1 -1
  114. package/dist/RegisteredFunction.js.map +1 -1
  115. package/dist/RegisteredFunctions.d.ts +3 -3
  116. package/dist/RegisteredFunctions.d.ts.map +1 -1
  117. package/dist/RegisteredFunctions.js.map +1 -1
  118. package/dist/RegisteredNodeFunction.d.ts +6 -6
  119. package/dist/RegisteredNodeFunction.d.ts.map +1 -1
  120. package/dist/RegisteredNodeFunction.js.map +1 -1
  121. package/dist/Registry.d.ts +1 -1
  122. package/dist/Registry.d.ts.map +1 -1
  123. package/dist/Registry.js.map +1 -1
  124. package/dist/RegistryItems.js.map +1 -1
  125. package/dist/ResolvedMiddleware.d.ts +2 -2
  126. package/dist/ResolvedMiddleware.d.ts.map +1 -1
  127. package/dist/ResolvedMiddleware.js.map +1 -1
  128. package/dist/Storage.d.ts +6 -6
  129. package/dist/Storage.d.ts.map +1 -1
  130. package/dist/Storage.js.map +1 -1
  131. package/dist/StorageActionWriter.d.ts +1 -1
  132. package/dist/StorageActionWriter.d.ts.map +1 -1
  133. package/dist/StorageActionWriter.js.map +1 -1
  134. package/dist/StorageReader.d.ts +1 -1
  135. package/dist/StorageReader.d.ts.map +1 -1
  136. package/dist/StorageReader.js.map +1 -1
  137. package/dist/StorageWriter.d.ts +1 -1
  138. package/dist/StorageWriter.d.ts.map +1 -1
  139. package/dist/StorageWriter.js.map +1 -1
  140. package/dist/TableInfo.d.ts +2 -2
  141. package/dist/TableInfo.d.ts.map +1 -1
  142. package/dist/TableInfo.js.map +1 -1
  143. package/dist/VectorSearch.d.ts +1 -1
  144. package/dist/VectorSearch.d.ts.map +1 -1
  145. package/dist/VectorSearch.js.map +1 -1
  146. package/dist/index.d.ts +61 -60
  147. package/dist/index.d.ts.map +1 -1
  148. package/dist/index.js +2 -1
  149. package/dist/internal/AiGatewayDecisionClient.d.ts +1 -1
  150. package/dist/internal/AiGatewayDecisionClient.d.ts.map +1 -1
  151. package/dist/internal/AiGatewayDecisionClient.js.map +1 -1
  152. package/dist/internal/AiGatewayLanguageClient.d.ts +1 -1
  153. package/dist/internal/AiGatewayLanguageClient.d.ts.map +1 -1
  154. package/dist/internal/AiGatewayLanguageClient.js.map +1 -1
  155. package/dist/node.d.ts +1 -1
  156. package/dist/node.d.ts.map +1 -1
  157. package/package.json +2 -2
  158. package/src/ActionCtx.ts +1 -1
  159. package/src/AiGatewayDecisionClient.ts +3 -3
  160. package/src/AiGatewayLanguageClient.ts +3 -3
  161. package/src/Auth.ts +1 -1
  162. package/src/ComponentCtx.ts +1 -1
  163. package/src/ConvexFunctionDefinitions.ts +8 -8
  164. package/src/CronJobs.ts +1 -1
  165. package/src/DataModel.ts +3 -3
  166. package/src/DatabaseReader.ts +4 -4
  167. package/src/DatabaseSchema.ts +1 -1
  168. package/src/DatabaseWriter.ts +6 -6
  169. package/src/Document.ts +4 -4
  170. package/src/FunctionImpl.ts +5 -5
  171. package/src/FunctionRegistryItem.ts +1 -1
  172. package/src/GroupImpl.ts +5 -5
  173. package/src/GroupRegistry.ts +4 -4
  174. package/src/Handler.ts +23 -23
  175. package/src/HttpRouter.ts +17 -17
  176. package/src/MiddlewareImpl.ts +17 -17
  177. package/src/MutationCtx.ts +1 -1
  178. package/src/MutationRunner.ts +1 -1
  179. package/src/MutationTransactionContext.ts +2 -2
  180. package/src/OfficialComponent.ts +151 -0
  181. package/src/OrderedQuery.ts +4 -4
  182. package/src/QueryCtx.ts +1 -1
  183. package/src/QueryInitializer.ts +9 -9
  184. package/src/QueryRunner.ts +2 -2
  185. package/src/QueryStream.ts +15 -15
  186. package/src/QueryStreamCursor.ts +3 -3
  187. package/src/QueryStreamIndexPrefix.ts +2 -2
  188. package/src/QueryStreamIndexRange.ts +4 -4
  189. package/src/QueryStreamKey.ts +2 -2
  190. package/src/QueryStreamKeyBounds.ts +3 -3
  191. package/src/QueryStreamKeyLayout.ts +1 -1
  192. package/src/QueryStreamKeyValues.ts +1 -1
  193. package/src/QueryStreamPagination.ts +2 -2
  194. package/src/RegisteredConvexFunction.ts +21 -21
  195. package/src/RegisteredFunction.ts +18 -18
  196. package/src/RegisteredFunctions.ts +4 -4
  197. package/src/RegisteredNodeFunction.ts +8 -8
  198. package/src/Registry.ts +1 -1
  199. package/src/RegistryItems.ts +2 -2
  200. package/src/ResolvedMiddleware.ts +2 -2
  201. package/src/Storage.ts +3 -3
  202. package/src/StorageActionWriter.ts +1 -1
  203. package/src/StorageReader.ts +1 -1
  204. package/src/StorageWriter.ts +1 -1
  205. package/src/TableInfo.ts +2 -2
  206. package/src/VectorSearch.ts +1 -1
  207. package/src/index.ts +61 -60
  208. package/src/internal/AiGatewayDecisionClient.ts +2 -2
  209. package/src/internal/AiGatewayLanguageClient.ts +2 -2
  210. package/src/node.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"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,OAAO,KAAK,sBAAsB,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,KAAK,yBAAyB,MAAM,6BAA6B,CAAC;AAE9E,KAAK,IAAI,CAAC,UAAU,SAAS,aAAa,CAAC,MAAM,CAAC,IAChD,UAAU,SAAS,SAAS,CAAC,MAAM,CAAC,SAAS,MAAM,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,GAC1E,CAAC,GACD,KAAK,CAAC;AAEZ,KAAK,IAAI,CAAC,UAAU,SAAS,aAAa,CAAC,MAAM,CAAC,IAChD,UAAU,SAAS,SAAS;IAC1B,MAAM;IACN,GAAG,MAAM,IAAI,SAAS,aAAa,CAAC,MAAM,CAAC;CAC5C,GACG,IAAI,GACJ,aAAa,CAAC,MAAM,CAAC,CAAC;AAM5B,QAAA,MAAM,MAAM,2CAA2C,CAAC;AAExD,UAAU,QAAQ;IAChB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CA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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"}
@@ -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,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AS,YAAY,wBAAwB,aAAa;CAElE,MAAM,cAAc,MAAM,UACxB,MAAM,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(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;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,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,c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;;GAEG;AACH,eAAO,MAAM,QAAQ,SAAU,QAAQ,KAAG,MAKtC,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 +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,CAAC,CAAC;CACzC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;CAC1B;AA6DD;;;;GAIG;AACH,eAAO,MAAM,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ivalence","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: 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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AAC;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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AAC;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,y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CAAC,iBAAiB,EAAE,oBAAoB,CAAC;IACjD,QAAQ,CAAC,eAAe,EAAE,oBAAoB,CAAC;CAChD,CAAC;IACA,IAAa,OAAO,IAAI,MAAM,CAE7B;CACF;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,sBACX,oBAAoB,mBACtB,oBAAoB,KACpC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,sBAAsB,CAKtC,CAAC;AAER;;;;;GAKG;AACH,eAAO,MAAM,aAAa,SAClB,oBAAoB,mBACT,oBAAoB,CAAC,oBAAoB,KACzD,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAgB/C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,MAAM,GACjB,oBAAoB,SAAS,oBAAoB,CAAC,oBAAoB,QAEhE,oBAAoB,wBACJ,oBAAoB,KACzC,MAAM,CAAC,MAAM,CACd,oBAAoB,CAAC,oBAAoB,CAAC,EAC1C,uBAAuB,CA6BxB,CAAC"}
@@ -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":";;;;;;;;;;;;;;;;;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MAAa,iBACX,MACA,oBACmD;CACnD,MAAM,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"}
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,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,CAGE;CACD,IAAa,UAAkB;EAC7B,OAAO,mEAAmE,KAAK,QAAQ,QAAQ,KAAK,WAAW,OAAO;CACxH;AACF;;;;;;AAOA,IAAa,0BAAb,cAA6C,KAAK,YAChD,yBACF,CAAC,CAGE;CACD,IAAa,UAAkB;EAC7B,OAAO,YAAY,MAAM,KAAK,KAAK,iBAAiB,IAAI,EAAE,+CAA+C,MAAM,KAAK,KAAK,WAAW,IAAI,EAAE;CAC5I;AACF;;;;;;AAOA,IAAa,0BAAb,cAA6C,KAAK,YAChD,yBACF,CAAC,CAGE;CACD,IAAa,UAAkB;EAC7B,OAAO,wBAAwB,MAAM,KAAK,KAAK,sBAAsB,IAAI,EAAE,uDAAuD,MAAM,KAAK,KAAK,WAAW,IAAI,EAAE;CACrK;AACF;AAkCA,SAAgB,UACd,YACA,UAAU,GACuD;CACjE,IACE,CAAC,OAAO,UAAU,OAAO,KACzB,UAAU,KACV,UAAU,WAAW,QAErB,OAAO,OAAO,KAAK,IAAI,2BAA2B;EAAE;EAAY;CAAQ,CAAC,CAAC;CAE5E,MAAM,UAAU,MAAM,IAAI,MAAM,KAAK,YAAY,OAAO,IAAI,UAC1D,SAAS,QAAQ,EAAE,MAAM,CAAC,CAC5B;CACA,MAAM,eAAe,OAAO,O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AwC,OAAO,KAAK,iBAAiB,EAAE;CAC5H;AACF;;;;AAKA,MAAa,uBACX,mBACA,oBAEA,YAAY,mBAAmB,eAAe,IAC1C,OAAO,QAAQ,KAAA,CAAS,IACxB,OAAO,KACL,IAAI,uBAAuB;CAAE;CAAmB;AAAgB,CAAC,CACnE;;;;;;;AAQN,MAAa,iBACX,MACA,oBACmD;CACnD,MAAM,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,OAAO,EAIL,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,OAAO,KAAK,KAAK,yBAAyB,MAAM,6BAA6B,CAAC;AAG9E,QAAA,MAAM,QAAQ,2IAmCb,CAAC;AAEF;;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
+ {"version":3,"file":"QueryStreamKeyValues.d.ts","sourceRoot":"","sources":["../src/QueryStreamKeyValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,OAAO,KAAK,KAAK,yBAAyB,MAAM,gCAAgC,CAAC;AAGjF,QAAA,MAAM,QAAQ,2IAmCb,CAAC;AAEF;;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 +1 @@
1
- {"version":3,"file":"QueryStreamKeyValues.js","names":[],"sources":["../src/QueryStreamKeyValues.ts"],"sourcesContent":["import {\n convexToJson,\n jsonToConvex,\n compareValues,\n type Value,\n} from \"convex/values\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as Order_ from \"effect/Order\";\nimport type * as Record from \"effect/Record\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaGetter from \"effect/SchemaGetter\";\nimport * as SchemaIssue from \"effect/SchemaIssue\";\nimport type * as QueryStreamOrderDirection from \"./QueryStreamOrderDirection\";\n\nconst UNDEFINED_SENTINEL = { $undefined: true } as const;\nconst KeyValue = Schema.Json.pipe(\n Schema.decodeTo(\n Schema.declare<Value | undefined>(\n (value): value is Value | undefined =>\n value === undefined ||\n Result.isSuccess(Result.try(() => convexToJson(value as Value))),\n ),\n {\n decode: SchemaGetter.transformEffect((value, options) =>\n Effect.try({\n try: () =>\n Result.match(\n Schema.decodeUnknownResult(\n Schema.Struct({ $undefined: Schema.Literal(true) }),\n { onExcessProperty: \"error\" },\n )(value),\n {\n onSuccess: () => undefined,\n onFailure: () =>\n jsonToConvex(value as Parameters<typeof jsonToConvex>[0]),\n },\n ),\n catch: () =>\n new SchemaIssue.InvalidValue(\n { message: \"Invalid Convex key value\" },\n value,\n options,\n ),\n }),\n ),\n encode: SchemaGetter.transform((value) =>\n value === undefined ? UNDEFINED_SENTINEL : convexToJson(value),\n ),\n },\n ),\n);\n\n/**\n * @experimental\n */\nexport type KeyValue = typeof KeyValue.Type;\n\n/**\n * @experimental\n */\nexport const QueryStreamKeyValues = Schema.Array(KeyValue);\n\n/**\n * @experimental\n */\nexport type QueryStreamKeyValues = typeof QueryStreamKeyValues.Type;\n\n/**\n * `Order` over Convex values, matching Convex's index ordering—a wrapper around\n * the canonical `compareValues` from `convex/values` (type rank first, then\n * within the type, including UTF-8 string order and NaN bit-level ordering).\n *\n * @experimental\n */\nexport const ValueOrder: Order_.Order<KeyValue> = Order_.make(\n (self, that) => Math.sign(compareValues(self, that)) as -1 | 0 | 1,\n);\n\nconst AscendingOrder = Order_.Array(ValueOrder);\nconst DescendingOrder = Order_.flip(AscendingOrder);\n\n/**\n * Compare key values in the requested direction. Ascending order is\n * lexicographic by `ValueOrder`, then by length, matching Convex array values;\n * descending order reverses it.\n *\n * @experimental\n */\nexport const Order = (\n orderDirection: QueryStreamOrderDirection.QueryStreamOrderDirection,\n): Order_.Order<QueryStreamKeyValues> =>\n orderDirection === \"asc\" ? AscendingOrder : DescendingOrder;\n\n/**\n * @experimental\n */\nexport const extract = (\n encoded: Record.ReadonlyRecord<string, unknown>,\n keyPaths: ReadonlyArray<ReadonlyArray<string>>,\n): QueryStreamKeyValues =>\n Array.map(keyPaths, (path) =>\n Array.reduce(\n path,\n encoded as unknown,\n (value, segment) =>\n (value as Record.ReadonlyRecord<string, unknown> | undefined)?.[\n segment\n ],\n ),\n ) as QueryStreamKeyValues;\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAM,qBAAqB,EAAE,YAAY,KAAK;AAC9C,MAAM,WAAW,OAAO,KAAK,KAC3B,OAAO,SACL,OAAO,SACJ,UACC,UAAU,KAAA,KACV,OAAO,UAAU,OAAO,UAAU,aAAa,KAAc,CAAC,CAAC,CACnE,GACA;CACE,QAAQ,aAAa,iBAAiB,OAAO,YAC3C,OAAO,IAAI;EACT,WACE,OAAO,MACL,OAAO,oBACL,OAAO,OAAO,EAAE,YAAY,OAAO,QAAQ,IAAI,EAAE,CAAC,GAClD,EAAE,kBAAkB,QAAQ,CAC9B,CAAC,CAAC,KAAK,GACP;GACE,iBAAiB,KAAA;GACjB,iBACE,aAAa,KAA2C;EAC5D,CACF;EACF,aACE,IAAI,YAAY,aACd,EAAE,SAAS,2BAA2B,GACtC,OACA,OACF;CACJ,CAAC,CACH;CACA,QAAQ,aAAa,WAAW,UAC9B,UAAU,KAAA,IAAY,qBAAqB,aAAa,KAAK,CAC/D;AACF,CACF,CACF;;;;AAUA,MAAa,uBAAuB,OAAO,MAAM,QAAQ;;;;;;;;AAczD,MAAa,aAAqC,OAAO,MACtD,MAAM,SAAS,KAAK,KAAK,cAAc,MAAM,IAAI,CAAC,CACrD;AAEA,MAAM,iBAAiB,OAAO,MAAM,UAAU;AAC9C,MAAM,kBAAkB,OAAO,KAAK,cAAc;;;;;;;;AASlD,MAAa,SACX,mBAEA,mBAAmB,QAAQ,iBAAiB;;;;AAK9C,MAAa,WACX,SACA,aAEA,MAAM,IAAI,WAAW,SACnB,MAAM,OACJ,MACA,UACC,OAAO,YACL,QACC,QAEN,CACF"}
1
+ {"version":3,"file":"QueryStreamKeyValues.js","names":[],"sources":["../src/QueryStreamKeyValues.ts"],"sourcesContent":["import {\n convexToJson,\n jsonToConvex,\n compareValues,\n type Value,\n} from \"convex/values\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as Order_ from \"effect/Order\";\nimport type * as Record from \"effect/Record\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaGetter from \"effect/SchemaGetter\";\nimport * as SchemaIssue from \"effect/SchemaIssue\";\nimport type * as QueryStreamOrderDirection from \"./QueryStreamOrderDirection.js\";\n\nconst UNDEFINED_SENTINEL = { $undefined: true } as const;\nconst KeyValue = Schema.Json.pipe(\n Schema.decodeTo(\n Schema.declare<Value | undefined>(\n (value): value is Value | undefined =>\n value === undefined ||\n Result.isSuccess(Result.try(() => convexToJson(value as Value))),\n ),\n {\n decode: SchemaGetter.transformEffect((value, options) =>\n Effect.try({\n try: () =>\n Result.match(\n Schema.decodeUnknownResult(\n Schema.Struct({ $undefined: Schema.Literal(true) }),\n { onExcessProperty: \"error\" },\n )(value),\n {\n onSuccess: () => undefined,\n onFailure: () =>\n jsonToConvex(value as Parameters<typeof jsonToConvex>[0]),\n },\n ),\n catch: () =>\n new SchemaIssue.InvalidValue(\n { message: \"Invalid Convex key value\" },\n value,\n options,\n ),\n }),\n ),\n encode: SchemaGetter.transform((value) =>\n value === undefined ? UNDEFINED_SENTINEL : convexToJson(value),\n ),\n },\n ),\n);\n\n/**\n * @experimental\n */\nexport type KeyValue = typeof KeyValue.Type;\n\n/**\n * @experimental\n */\nexport const QueryStreamKeyValues = Schema.Array(KeyValue);\n\n/**\n * @experimental\n */\nexport type QueryStreamKeyValues = typeof QueryStreamKeyValues.Type;\n\n/**\n * `Order` over Convex values, matching Convex's index ordering—a wrapper around\n * the canonical `compareValues` from `convex/values` (type rank first, then\n * within the type, including UTF-8 string order and NaN bit-level ordering).\n *\n * @experimental\n */\nexport const ValueOrder: Order_.Order<KeyValue> = Order_.make(\n (self, that) => Math.sign(compareValues(self, that)) as -1 | 0 | 1,\n);\n\nconst AscendingOrder = Order_.Array(ValueOrder);\nconst DescendingOrder = Order_.flip(AscendingOrder);\n\n/**\n * Compare key values in the requested direction. Ascending order is\n * lexicographic by `ValueOrder`, then by length, matching Convex array values;\n * descending order reverses it.\n *\n * @experimental\n */\nexport const Order = (\n orderDirection: QueryStreamOrderDirection.QueryStreamOrderDirection,\n): Order_.Order<QueryStreamKeyValues> =>\n orderDirection === \"asc\" ? AscendingOrder : DescendingOrder;\n\n/**\n * @experimental\n */\nexport const extract = (\n encoded: Record.ReadonlyRecord<string, unknown>,\n keyPaths: ReadonlyArray<ReadonlyArray<string>>,\n): QueryStreamKeyValues =>\n Array.map(keyPaths, (path) =>\n Array.reduce(\n path,\n encoded as unknown,\n (value, segment) =>\n (value as Record.ReadonlyRecord<string, unknown> | undefined)?.[\n segment\n ],\n ),\n ) as QueryStreamKeyValues;\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAM,qBAAqB,EAAE,YAAY,KAAK;AAC9C,MAAM,WAAW,OAAO,KAAK,KAC3B,OAAO,SACL,OAAO,SACJ,UACC,UAAU,KAAA,KACV,OAAO,UAAU,OAAO,UAAU,aAAa,KAAc,CAAC,CAAC,CACnE,GACA;CACE,QAAQ,aAAa,iBAAiB,OAAO,YAC3C,OAAO,IAAI;EACT,WACE,OAAO,MACL,OAAO,oBACL,OAAO,OAAO,EAAE,YAAY,OAAO,QAAQ,IAAI,EAAE,CAAC,GAClD,EAAE,kBAAkB,QAAQ,CAC9B,CAAC,CAAC,KAAK,GACP;GACE,iBAAiB,KAAA;GACjB,iBACE,aAAa,KAA2C;EAC5D,CACF;EACF,aACE,IAAI,YAAY,aACd,EAAE,SAAS,2BAA2B,GACtC,OACA,OACF;CACJ,CAAC,CACH;CACA,QAAQ,aAAa,WAAW,UAC9B,UAAU,KAAA,IAAY,qBAAqB,aAAa,KAAK,CAC/D;AACF,CACF,CACF;;;;AAUA,MAAa,uBAAuB,OAAO,MAAM,QAAQ;;;;;;;;AAczD,MAAa,aAAqC,OAAO,MACtD,MAAM,SAAS,KAAK,KAAK,cAAc,MAAM,IAAI,CAAC,CACrD;AAEA,MAAM,iBAAiB,OAAO,MAAM,UAAU;AAC9C,MAAM,kBAAkB,OAAO,KAAK,cAAc;;;;;;;;AASlD,MAAa,SACX,mBAEA,mBAAmB,QAAQ,iBAAiB;;;;AAK9C,MAAa,WACX,SACA,aAEA,MAAM,IAAI,WAAW,SACnB,MAAM,OACJ,MACA,UACC,OAAO,YACL,QACC,QAEN,CACF"}
@@ -3,7 +3,7 @@ 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 * as Schema from "effect/Schema";
6
- import type * as QueryStreamKey from "./QueryStreamKey";
6
+ import type * as QueryStreamKey from "./QueryStreamKey.js";
7
7
  declare const PageSize: Schema.brand<Schema.Natural, "~@confect/server/QueryStreamPagination/PageSize">;
8
8
  type PageSize = typeof PageSize.Type;
9
9
  declare const InvalidPageSizeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStreamPagination.d.ts","sourceRoot":"","sources":["../src/QueryStreamPagination.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAGxD,QAAA,MAAM,QAAQ,iFAEb,CAAC;AACF,KAAK,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,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AM,MAAM,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC;IACzC,IAAI,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,CAAA;KAAE,CAAC;IAC5C,QAAQ,EAAE;QACR,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;QAClC,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC,QAAQ,CAAC;KACvC,CAAC;IACF,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,gBAAgB,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CAC9B,CAAC,CAAC;;;;AAEH;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,6BAE3C;IACA,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,iBAAiB,CAAC;CACnD,CAAC;IACA,IAAa,OAAO,IAAI,MAAM,CAY7B;CACF;AAID;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAAI,GAAG,WACf,WAAW,QACd,qBAAqB,CAAC,GAAG,CAAC,mBACf,OAAO,KACvB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,uBAAuB,CA4FrD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStreamPagination.js","names":["QueryStreamKeyValues.Order"],"sources":["../src/QueryStreamPagination.ts"],"sourcesContent":["import * as Chunk from \"effect/Chunk\";\nimport * as Data from \"effect/Data\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport type * as QueryStreamKey from \"./QueryStreamKey\";\nimport * as QueryStreamKeyValues from \"./QueryStreamKeyValues\";\n\nconst PageSize = Schema.Natural.pipe(\n Schema.brand(\"~@confect/server/QueryStreamPagination/PageSize\"),\n);\ntype PageSize = typeof PageSize.Type;\n\n/**\n * @experimental\n */\nexport class InvalidPageSizeError extends Data.TaggedError(\n \"InvalidPageSizeError\",\n)<{\n readonly numItems: number;\n}> {\n override get message(): string {\n return `QueryStream.paginate: numItems must be a nonnegative integer (received ${this.numItems})`;\n }\n}\n\n/**\n * @experimental\n */\nexport class EmptyInitialPageError extends Data.TaggedError(\n \"EmptyInitialPageError\",\n) {\n override get message(): string {\n return \"QueryStream.paginate: numItems of 0 with a null cursor is not supported\";\n }\n}\n\n/**\n * @experimental\n */\nexport type Range = Data.TaggedEnum<{\n Unpinned: {};\n ThroughKey: { readonly key: QueryStreamKey.Complete };\n ThroughEnd: {};\n}>;\n/**\n * @experimental\n */\nexport const Range = Data.taggedEnum<Range>();\n\n/**\n * @experimental\n */\nexport type Start = Data.TaggedEnum<{\n Beginning: {};\n After: {\n readonly key: QueryStreamKey.Complete;\n readonly cursor: string;\n };\n}>;\n/**\n * @experimental\n */\nexport const Start = Data.taggedEnum<Start>();\n\n/**\n * @experimental\n */\nexport interface ScanRequest {\n readonly numItems: PageSize;\n readonly after: Option.Option<QueryStreamKey.Complete>;\n readonly range: Range;\n}\n\n/**\n * @experimental\n */\nexport type Request = Data.TaggedEnum<{\n Unchanged: { readonly cursor: string };\n Scan: ScanRequest;\n}>;\nconst Request = Data.taggedEnum<Request>();\n\n/**\n * @experimental\n */\nexport const parseRequest = (\n numItems: number,\n start: Start,\n range: Range,\n): Result.Result<Request, InvalidPageSizeError | EmptyInitialPageError> =>\n Result.flatMap(\n Schema.decodeResult(PageSize)(numItems).pipe(\n Result.mapError(() => new InvalidPageSizeError({ numItems })),\n ),\n (size): Result.Result<Request, EmptyInitialPageError> =>\n size === 0\n ? Start.$match(start, {\n Beginning: () => Result.fail(new EmptyInitialPageError()),\n After: ({ cursor }) =>\n Result.succeed(Request.Unchanged({ cursor })),\n })\n : Result.succeed(\n Request.Scan({\n numItems: size,\n after: Start.$match(start, {\n Beginning: () => Option.none(),\n After: ({ key }) => Option.some(key),\n }),\n range,\n }),\n ),\n );\n\n/**\n * A nonempty scan, including filtered markers.\n */\ntype Progress = Chunk.NonEmptyChunk<QueryStreamKey.Complete>;\nconst append = (\n progress: Option.Option<Progress>,\n key: QueryStreamKey.Complete,\n): Progress =>\n Option.match(progress, {\n onNone: () => Chunk.of(key),\n onSome: (keys) => Chunk.append(keys, key),\n });\nconst midpoint = (progress: Progress): QueryStreamKey.Complete =>\n Option.getOrElse(\n Chunk.get(progress, Math.floor((Chunk.size(progress) - 1) / 2)),\n () => Chunk.headNonEmpty(progress),\n );\n\ninterface Stopped<Doc> {\n readonly page: Chunk.Chunk<Doc>;\n readonly progress: Progress;\n}\n\n/**\n * @experimental\n */\nexport type QueryStreamPagination<Doc> = Data.TaggedEnum<{\n Reading: {\n readonly page: Chunk.Chunk<Doc>;\n readonly progress: Option.Option<Progress>;\n };\n ItemLimit: Stopped<Doc>;\n ReadLimit: Stopped<Doc>;\n}>;\ninterface PaginationDefinition extends Data.TaggedEnum.WithGenerics<1> {\n readonly taggedEnum: QueryStreamPagination<this[\"A\"]>;\n}\nconst QueryStreamPagination = Data.taggedEnum<PaginationDefinition>();\n\n/**\n * @experimental\n */\nexport const initial = <Doc>(): QueryStreamPagination<Doc> =>\n QueryStreamPagination.Reading({\n page: Chunk.empty<Doc>(),\n progress: Option.none(),\n });\n\n/**\n * @experimental\n */\nexport const record = <Doc>(\n request: ScanRequest,\n self: QueryStreamPagination<Doc>,\n doc: Option.Option<Doc>,\n key: QueryStreamKey.Complete,\n readLimit: boolean,\n): QueryStreamPagination<Doc> =>\n Match.value(self).pipe(\n Match.tagsExhaustive({\n Reading: (reading) => {\n const progress = append(reading.progress, key);\n const page = Option.match(doc, {\n onNone: () => reading.page,\n onSome: (value) => Chunk.append(reading.page, value),\n });\n const continueReading = () =>\n QueryStreamPagination.Reading({\n page,\n progress: Option.some(progress),\n });\n return readLimit\n ? QueryStreamPagination.ReadLimit({ page, progress })\n : Range.$match(request.range, {\n Unpinned: () =>\n Chunk.size(page) >= request.numItems\n ? QueryStreamPagination.ItemLimit({ page, progress })\n : continueReading(),\n ThroughKey: continueReading,\n ThroughEnd: continueReading,\n });\n },\n ItemLimit: () => self,\n ReadLimit: () => self,\n }),\n );\n\n/**\n * @experimental\n */\nexport type Continuation = Data.TaggedEnum<{\n End: {};\n Key: { readonly key: QueryStreamKey.Complete };\n}>;\nconst Continuation = Data.taggedEnum<Continuation>();\n\ninterface Split<Doc> {\n readonly page: ReadonlyArray<Doc>;\n readonly continuation: Continuation;\n readonly splitKey: QueryStreamKey.Complete;\n}\n\n/**\n * @experimental\n */\nexport type Outcome<Doc> = Data.TaggedEnum<{\n Done: { readonly page: ReadonlyArray<Doc> };\n Continue: {\n readonly page: ReadonlyArray<Doc>;\n readonly key: QueryStreamKey.Complete;\n };\n SplitRequired: Split<Doc>;\n SplitRecommended: Split<Doc>;\n}>;\n\n/**\n * @experimental\n */\nexport class UnsafePageBoundaryError extends Data.TaggedError(\n \"UnsafePageBoundaryError\",\n)<{\n readonly reason: \"NoProgress\" | \"NoInteriorSplit\";\n}> {\n override get message(): string {\n return Match.value(this.reason).pipe(\n Match.when(\n \"NoProgress\",\n () => \"The read budget stopped the page before any key was scanned\",\n ),\n Match.when(\n \"NoInteriorSplit\",\n () => \"The read budget stopped the page without an interior split key\",\n ),\n Match.exhaustive,\n );\n }\n}\n\nconst SOFT_MAX_SCAN_LENGTH = 16000;\n\n/**\n * Decide the page result without reading a stream or serializing a cursor.\n *\n * @experimental\n */\nexport const finish = <Doc>(\n request: ScanRequest,\n self: QueryStreamPagination<Doc>,\n upstreamStopped: boolean,\n): Result.Result<Outcome<Doc>, UnsafePageBoundaryError> => {\n const page = Chunk.toArray(self.page);\n const stopped = (\n progress: Option.Option<Progress>,\n readLimit: boolean,\n ): Result.Result<Outcome<Doc>, UnsafePageBoundaryError> =>\n Result.flatMap(\n Result.fromOption(\n progress,\n () => new UnsafePageBoundaryError({ reason: \"NoProgress\" }),\n ),\n (scanned): Result.Result<Outcome<Doc>, UnsafePageBoundaryError> => {\n const splitKey = midpoint(scanned);\n const atEnd = Range.$match(request.range, {\n Unpinned: () => false,\n ThroughEnd: () => false,\n ThroughKey: ({ key }) =>\n QueryStreamKeyValues.Order(\"asc\")(splitKey.values, key.values) ===\n 0,\n });\n if (readLimit && atEnd) {\n return Result.fail(\n new UnsafePageBoundaryError({ reason: \"NoInteriorSplit\" }),\n );\n }\n const key = Chunk.lastNonEmpty(scanned);\n if (readLimit)\n return Result.succeed({\n _tag: \"SplitRequired\",\n page,\n continuation: Continuation.Key({ key }),\n splitKey,\n });\n return Result.succeed(\n Chunk.size(scanned) >= SOFT_MAX_SCAN_LENGTH\n ? {\n _tag: \"SplitRecommended\",\n page,\n continuation: Continuation.Key({ key }),\n splitKey,\n }\n : { _tag: \"Continue\", page, key },\n );\n },\n );\n const exhausted = (progress: Option.Option<Progress>): Outcome<Doc> => {\n const finishRange = (\n continuation: Continuation,\n pinned: boolean,\n ): Outcome<Doc> => {\n const split = Option.filter(\n progress,\n (scanned) =>\n pinned &&\n (Chunk.size(scanned) >= SOFT_MAX_SCAN_LENGTH ||\n page.length > request.numItems + 1),\n );\n return Option.match(split, {\n onSome: (scanned): Outcome<Doc> => ({\n _tag: \"SplitRecommended\",\n page,\n continuation,\n splitKey: midpoint(scanned),\n }),\n onNone: () =>\n Continuation.$match(continuation, {\n End: (): Outcome<Doc> => ({ _tag: \"Done\", page }),\n Key: ({ key }): Outcome<Doc> => ({\n _tag: \"Continue\",\n page,\n key,\n }),\n }),\n });\n };\n return Range.$match(request.range, {\n Unpinned: () => finishRange(Continuation.End(), false),\n ThroughEnd: () => finishRange(Continuation.End(), true),\n ThroughKey: ({ key }) => finishRange(Continuation.Key({ key }), true),\n });\n };\n return Match.value(self).pipe(\n Match.tagsExhaustive({\n Reading: ({ progress }) =>\n upstreamStopped\n ? stopped(progress, true)\n : Result.succeed(exhausted(progress)),\n ItemLimit: ({ progress }) =>\n stopped(Option.some(progress), upstreamStopped),\n ReadLimit: ({ progress }) => stopped(Option.some(progress), true),\n }),\n );\n};\n"],"mappings":";;;;;;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AAe;EACnB,UAAU,EAAE,eACV,kBACI,QAAQ,UAAU,IAAI,IACtB,OAAO,QAAQ,UAAU,QAAQ,CAAC;EACxC,YAAY,EAAE,eACZ,QAAQ,OAAO,KAAK,QAAQ,GAAG,eAAe;EAChD,YAAY,EAAE,eAAe,QAAQ,OAAO,KAAK,QAAQ,GAAG,IAAI;CAClE,CAAC,CACH;AACF"}
1
+ {"version":3,"file":"QueryStreamPagination.js","names":["QueryStreamKeyValues.Order"],"sources":["../src/QueryStreamPagination.ts"],"sourcesContent":["import * as Chunk from \"effect/Chunk\";\nimport * as Data from \"effect/Data\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport type * as QueryStreamKey from \"./QueryStreamKey.js\";\nimport * as QueryStreamKeyValues from \"./QueryStreamKeyValues.js\";\n\nconst PageSize = Schema.Natural.pipe(\n Schema.brand(\"~@confect/server/QueryStreamPagination/PageSize\"),\n);\ntype PageSize = typeof PageSize.Type;\n\n/**\n * @experimental\n */\nexport class InvalidPageSizeError extends Data.TaggedError(\n \"InvalidPageSizeError\",\n)<{\n readonly numItems: number;\n}> {\n override get message(): string {\n return `QueryStream.paginate: numItems must be a nonnegative integer (received ${this.numItems})`;\n }\n}\n\n/**\n * @experimental\n */\nexport class EmptyInitialPageError extends Data.TaggedError(\n \"EmptyInitialPageError\",\n) {\n override get message(): string {\n return \"QueryStream.paginate: numItems of 0 with a null cursor is not supported\";\n }\n}\n\n/**\n * @experimental\n */\nexport type Range = Data.TaggedEnum<{\n Unpinned: {};\n ThroughKey: { readonly key: QueryStreamKey.Complete };\n ThroughEnd: {};\n}>;\n/**\n * @experimental\n */\nexport const Range = Data.taggedEnum<Range>();\n\n/**\n * @experimental\n */\nexport type Start = Data.TaggedEnum<{\n Beginning: {};\n After: {\n readonly key: QueryStreamKey.Complete;\n readonly cursor: string;\n };\n}>;\n/**\n * @experimental\n */\nexport const Start = Data.taggedEnum<Start>();\n\n/**\n * @experimental\n */\nexport interface ScanRequest {\n readonly numItems: PageSize;\n readonly after: Option.Option<QueryStreamKey.Complete>;\n readonly range: Range;\n}\n\n/**\n * @experimental\n */\nexport type Request = Data.TaggedEnum<{\n Unchanged: { readonly cursor: string };\n Scan: ScanRequest;\n}>;\nconst Request = Data.taggedEnum<Request>();\n\n/**\n * @experimental\n */\nexport const parseRequest = (\n numItems: number,\n start: Start,\n range: Range,\n): Result.Result<Request, InvalidPageSizeError | EmptyInitialPageError> =>\n Result.flatMap(\n Schema.decodeResult(PageSize)(numItems).pipe(\n Result.mapError(() => new InvalidPageSizeError({ numItems })),\n ),\n (size): Result.Result<Request, EmptyInitialPageError> =>\n size === 0\n ? Start.$match(start, {\n Beginning: () => Result.fail(new EmptyInitialPageError()),\n After: ({ cursor }) =>\n Result.succeed(Request.Unchanged({ cursor })),\n })\n : Result.succeed(\n Request.Scan({\n numItems: size,\n after: Start.$match(start, {\n Beginning: () => Option.none(),\n After: ({ key }) => Option.some(key),\n }),\n range,\n }),\n ),\n );\n\n/**\n * A nonempty scan, including filtered markers.\n */\ntype Progress = Chunk.NonEmptyChunk<QueryStreamKey.Complete>;\nconst append = (\n progress: Option.Option<Progress>,\n key: QueryStreamKey.Complete,\n): Progress =>\n Option.match(progress, {\n onNone: () => Chunk.of(key),\n onSome: (keys) => Chunk.append(keys, key),\n });\nconst midpoint = (progress: Progress): QueryStreamKey.Complete =>\n Option.getOrElse(\n Chunk.get(progress, Math.floor((Chunk.size(progress) - 1) / 2)),\n () => Chunk.headNonEmpty(progress),\n );\n\ninterface Stopped<Doc> {\n readonly page: Chunk.Chunk<Doc>;\n readonly progress: Progress;\n}\n\n/**\n * @experimental\n */\nexport type QueryStreamPagination<Doc> = Data.TaggedEnum<{\n Reading: {\n readonly page: Chunk.Chunk<Doc>;\n readonly progress: Option.Option<Progress>;\n };\n ItemLimit: Stopped<Doc>;\n ReadLimit: Stopped<Doc>;\n}>;\ninterface PaginationDefinition extends Data.TaggedEnum.WithGenerics<1> {\n readonly taggedEnum: QueryStreamPagination<this[\"A\"]>;\n}\nconst QueryStreamPagination = Data.taggedEnum<PaginationDefinition>();\n\n/**\n * @experimental\n */\nexport const initial = <Doc>(): QueryStreamPagination<Doc> =>\n QueryStreamPagination.Reading({\n page: Chunk.empty<Doc>(),\n progress: Option.none(),\n });\n\n/**\n * @experimental\n */\nexport const record = <Doc>(\n request: ScanRequest,\n self: QueryStreamPagination<Doc>,\n doc: Option.Option<Doc>,\n key: QueryStreamKey.Complete,\n readLimit: boolean,\n): QueryStreamPagination<Doc> =>\n Match.value(self).pipe(\n Match.tagsExhaustive({\n Reading: (reading) => {\n const progress = append(reading.progress, key);\n const page = Option.match(doc, {\n onNone: () => reading.page,\n onSome: (value) => Chunk.append(reading.page, value),\n });\n const continueReading = () =>\n QueryStreamPagination.Reading({\n page,\n progress: Option.some(progress),\n });\n return readLimit\n ? QueryStreamPagination.ReadLimit({ page, progress })\n : Range.$match(request.range, {\n Unpinned: () =>\n Chunk.size(page) >= request.numItems\n ? QueryStreamPagination.ItemLimit({ page, progress })\n : continueReading(),\n ThroughKey: continueReading,\n ThroughEnd: continueReading,\n });\n },\n ItemLimit: () => self,\n ReadLimit: () => self,\n }),\n );\n\n/**\n * @experimental\n */\nexport type Continuation = Data.TaggedEnum<{\n End: {};\n Key: { readonly key: QueryStreamKey.Complete };\n}>;\nconst Continuation = Data.taggedEnum<Continuation>();\n\ninterface Split<Doc> {\n readonly page: ReadonlyArray<Doc>;\n readonly continuation: Continuation;\n readonly splitKey: QueryStreamKey.Complete;\n}\n\n/**\n * @experimental\n */\nexport type Outcome<Doc> = Data.TaggedEnum<{\n Done: { readonly page: ReadonlyArray<Doc> };\n Continue: {\n readonly page: ReadonlyArray<Doc>;\n readonly key: QueryStreamKey.Complete;\n };\n SplitRequired: Split<Doc>;\n SplitRecommended: Split<Doc>;\n}>;\n\n/**\n * @experimental\n */\nexport class UnsafePageBoundaryError extends Data.TaggedError(\n \"UnsafePageBoundaryError\",\n)<{\n readonly reason: \"NoProgress\" | \"NoInteriorSplit\";\n}> {\n override get message(): string {\n return Match.value(this.reason).pipe(\n Match.when(\n \"NoProgress\",\n () => \"The read budget stopped the page before any key was scanned\",\n ),\n Match.when(\n \"NoInteriorSplit\",\n () => \"The read budget stopped the page without an interior split key\",\n ),\n Match.exhaustive,\n );\n }\n}\n\nconst SOFT_MAX_SCAN_LENGTH = 16000;\n\n/**\n * Decide the page result without reading a stream or serializing a cursor.\n *\n * @experimental\n */\nexport const finish = <Doc>(\n request: ScanRequest,\n self: QueryStreamPagination<Doc>,\n upstreamStopped: boolean,\n): Result.Result<Outcome<Doc>, UnsafePageBoundaryError> => {\n const page = Chunk.toArray(self.page);\n const stopped = (\n progress: Option.Option<Progress>,\n readLimit: boolean,\n ): Result.Result<Outcome<Doc>, UnsafePageBoundaryError> =>\n Result.flatMap(\n Result.fromOption(\n progress,\n () => new UnsafePageBoundaryError({ reason: \"NoProgress\" }),\n ),\n (scanned): Result.Result<Outcome<Doc>, UnsafePageBoundaryError> => {\n const splitKey = midpoint(scanned);\n const atEnd = Range.$match(request.range, {\n Unpinned: () => false,\n ThroughEnd: () => false,\n ThroughKey: ({ key }) =>\n QueryStreamKeyValues.Order(\"asc\")(splitKey.values, key.values) ===\n 0,\n });\n if (readLimit && atEnd) {\n return Result.fail(\n new UnsafePageBoundaryError({ reason: \"NoInteriorSplit\" }),\n );\n }\n const key = Chunk.lastNonEmpty(scanned);\n if (readLimit)\n return Result.succeed({\n _tag: \"SplitRequired\",\n page,\n continuation: Continuation.Key({ key }),\n splitKey,\n });\n return Result.succeed(\n Chunk.size(scanned) >= SOFT_MAX_SCAN_LENGTH\n ? {\n _tag: \"SplitRecommended\",\n page,\n continuation: Continuation.Key({ key }),\n splitKey,\n }\n : { _tag: \"Continue\", page, key },\n );\n },\n );\n const exhausted = (progress: Option.Option<Progress>): Outcome<Doc> => {\n const finishRange = (\n continuation: Continuation,\n pinned: boolean,\n ): Outcome<Doc> => {\n const split = Option.filter(\n progress,\n (scanned) =>\n pinned &&\n (Chunk.size(scanned) >= SOFT_MAX_SCAN_LENGTH ||\n page.length > request.numItems + 1),\n );\n return Option.match(split, {\n onSome: (scanned): Outcome<Doc> => ({\n _tag: \"SplitRecommended\",\n page,\n continuation,\n splitKey: midpoint(scanned),\n }),\n onNone: () =>\n Continuation.$match(continuation, {\n End: (): Outcome<Doc> => ({ _tag: \"Done\", page }),\n Key: ({ key }): Outcome<Doc> => ({\n _tag: \"Continue\",\n page,\n key,\n }),\n }),\n });\n };\n return Range.$match(request.range, {\n Unpinned: () => finishRange(Continuation.End(), false),\n ThroughEnd: () => finishRange(Continuation.End(), true),\n ThroughKey: ({ key }) => finishRange(Continuation.Key({ key }), true),\n });\n };\n return Match.value(self).pipe(\n Match.tagsExhaustive({\n Reading: ({ progress }) =>\n upstreamStopped\n ? stopped(progress, true)\n : Result.succeed(exhausted(progress)),\n ItemLimit: ({ progress }) =>\n stopped(Option.some(progress), upstreamStopped),\n ReadLimit: ({ progress }) => stopped(Option.some(progress), true),\n }),\n );\n};\n"],"mappings":";;;;;;;;AASA,MAAM,WAAW,OAAO,QAAQ,KAC9B,OAAO,MAAM,iDAAiD,CAChE;;;;AAMA,IAAa,uBAAb,cAA0C,KAAK,YAC7C,sBACF,CAAC,CAEE;CACD,IAAa,UAAkB;EAC7B,OAAO,0EAA0E,KAAK,SAAS;CACjG;AACF;;;;AAKA,IAAa,wBAAb,cAA2C,KAAK,YAC9C,uBACF,CAAC,CAAC;CACA,IAAa,UAAkB;EAC7B,OAAO;CACT;AACF;;;;AAaA,MAAa,QAAQ,KAAK,WAAkB;;;;AAe5C,MAAa,QAAQ,KAAK,WAAkB;AAkB5C,MAAM,UAAU,KAAK,WAAoB;;;;AAKzC,MAAa,gBACX,UACA,OACA,UAEA,OAAO,QACL,OAAO,aAAa,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,KACtC,OAAO,eAAe,IAAI,qBAAqB,EAA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