@ahoo-wang/wow-client 10.0.0-alpha.3 → 10.0.0-alpha.5

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 (420) hide show
  1. package/README.md +85 -230
  2. package/README.zh-CN.md +74 -209
  3. package/dist/commands.cjs +2 -0
  4. package/dist/commands.cjs.map +1 -0
  5. package/dist/{v10/commands.d.cts → commands.d.cts} +21 -3
  6. package/dist/{v10/commands.d.ts → commands.d.ts} +21 -3
  7. package/dist/commands.es.js +96 -0
  8. package/dist/commands.es.js.map +1 -0
  9. package/dist/dsl/aggregation/types.cjs.map +1 -1
  10. package/dist/dsl/aggregation/types.d.cts +1 -1
  11. package/dist/dsl/aggregation/types.d.ts +1 -1
  12. package/dist/dsl/aggregation/types.es.js.map +1 -1
  13. package/dist/dsl/cursorQuery.cjs.map +1 -1
  14. package/dist/dsl/cursorQuery.d.cts +7 -8
  15. package/dist/dsl/cursorQuery.d.ts +7 -8
  16. package/dist/dsl/cursorQuery.es.js.map +1 -1
  17. package/dist/dsl/descriptor.cjs.map +1 -1
  18. package/dist/dsl/descriptor.d.cts +1 -1
  19. package/dist/dsl/descriptor.d.ts +1 -1
  20. package/dist/dsl/descriptor.es.js.map +1 -1
  21. package/dist/dsl/documents.d.cts +1 -1
  22. package/dist/dsl/documents.d.ts +1 -1
  23. package/dist/dsl/filter/types.d.cts +2 -1
  24. package/dist/dsl/filter/types.d.ts +2 -1
  25. package/dist/dsl/projection.cjs.map +1 -1
  26. package/dist/dsl/projection.d.cts +22 -0
  27. package/dist/dsl/projection.d.ts +22 -0
  28. package/dist/dsl/projection.es.js.map +1 -1
  29. package/dist/dsl/queryErrorCodes.cjs +2 -0
  30. package/dist/dsl/queryErrorCodes.cjs.map +1 -0
  31. package/dist/{error → dsl}/queryErrorCodes.d.cts +25 -24
  32. package/dist/{error → dsl}/queryErrorCodes.d.ts +25 -24
  33. package/dist/{error → dsl}/queryErrorCodes.es.js +2 -1
  34. package/dist/{error/queryErrorCodes.cjs.map → dsl/queryErrorCodes.es.js.map} +1 -1
  35. package/dist/dsl.cjs +1 -1
  36. package/dist/dsl.d.cts +1 -2
  37. package/dist/dsl.d.ts +1 -2
  38. package/dist/dsl.es.js +2 -3
  39. package/dist/exactJson.cjs +3 -0
  40. package/dist/exactJson.cjs.map +1 -0
  41. package/dist/exactJson.d.cts +54 -0
  42. package/dist/exactJson.d.ts +54 -0
  43. package/dist/exactJson.es.js +213 -0
  44. package/dist/exactJson.es.js.map +1 -0
  45. package/dist/http.cjs +2 -0
  46. package/dist/http.cjs.map +1 -0
  47. package/dist/{v10/http.d.cts → http.d.cts} +16 -7
  48. package/dist/{v10/http.d.ts → http.d.ts} +16 -7
  49. package/dist/http.es.js +77 -0
  50. package/dist/http.es.js.map +1 -0
  51. package/dist/index.cjs +1 -1
  52. package/dist/index.d.cts +19 -17
  53. package/dist/index.d.ts +19 -17
  54. package/dist/index.es.js +10 -36
  55. package/dist/manifest.cjs.map +1 -0
  56. package/dist/{v10/manifest.es.js → manifest.es.js} +1 -1
  57. package/dist/manifest.es.js.map +1 -0
  58. package/dist/problem.cjs +2 -0
  59. package/dist/problem.cjs.map +1 -0
  60. package/dist/{v10/problem.d.cts → problem.d.cts} +51 -4
  61. package/dist/{v10/problem.d.ts → problem.d.ts} +51 -4
  62. package/dist/{v10/problem.es.js → problem.es.js} +30 -11
  63. package/dist/problem.es.js.map +1 -0
  64. package/dist/queries.cjs +2 -0
  65. package/dist/queries.cjs.map +1 -0
  66. package/dist/{v10/queries.d.cts → queries.d.cts} +63 -17
  67. package/dist/{v10/queries.d.ts → queries.d.ts} +63 -17
  68. package/dist/queries.es.js +112 -0
  69. package/dist/queries.es.js.map +1 -0
  70. package/dist/state.cjs +2 -0
  71. package/dist/state.cjs.map +1 -0
  72. package/dist/{v10/state.d.cts → state.d.cts} +26 -4
  73. package/dist/{v10/state.d.ts → state.d.ts} +26 -4
  74. package/dist/state.es.js +70 -0
  75. package/dist/state.es.js.map +1 -0
  76. package/dist/streams.cjs +2 -0
  77. package/dist/streams.cjs.map +1 -0
  78. package/dist/streams.d.cts +74 -0
  79. package/dist/streams.d.ts +74 -0
  80. package/dist/streams.es.js +103 -0
  81. package/dist/streams.es.js.map +1 -0
  82. package/dist/wait.cjs.map +1 -0
  83. package/dist/{v10/wait.es.js → wait.es.js} +1 -1
  84. package/dist/wait.es.js.map +1 -0
  85. package/dist/wire.cjs.map +1 -0
  86. package/dist/{v10/wire.d.cts → wire.d.cts} +32 -7
  87. package/dist/{v10/wire.d.ts → wire.d.ts} +32 -7
  88. package/dist/{v10/wire.es.js → wire.es.js} +1 -1
  89. package/dist/wire.es.js.map +1 -0
  90. package/package.json +4 -26
  91. package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorate.cjs +0 -1
  92. package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorate.es.js +0 -9
  93. package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorateMetadata.cjs +0 -1
  94. package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorateMetadata.es.js +0 -6
  95. package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorateParam.cjs +0 -1
  96. package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorateParam.es.js +0 -8
  97. package/dist/client/bindMethods.cjs +0 -2
  98. package/dist/client/bindMethods.cjs.map +0 -1
  99. package/dist/client/bindMethods.d.cts +0 -13
  100. package/dist/client/bindMethods.d.ts +0 -13
  101. package/dist/client/bindMethods.es.js +0 -19
  102. package/dist/client/bindMethods.es.js.map +0 -1
  103. package/dist/client/command/commandClient.cjs +0 -2
  104. package/dist/client/command/commandClient.cjs.map +0 -1
  105. package/dist/client/command/commandClient.d.cts +0 -67
  106. package/dist/client/command/commandClient.d.ts +0 -67
  107. package/dist/client/command/commandClient.es.js +0 -38
  108. package/dist/client/command/commandClient.es.js.map +0 -1
  109. package/dist/client/command/commandHeaders.cjs +0 -2
  110. package/dist/client/command/commandHeaders.cjs.map +0 -1
  111. package/dist/client/command/commandHeaders.d.cts +0 -75
  112. package/dist/client/command/commandHeaders.d.ts +0 -75
  113. package/dist/client/command/commandHeaders.es.js +0 -31
  114. package/dist/client/command/commandHeaders.es.js.map +0 -1
  115. package/dist/client/command/commandRequest.cjs +0 -2
  116. package/dist/client/command/commandRequest.cjs.map +0 -1
  117. package/dist/client/command/commandRequest.d.cts +0 -180
  118. package/dist/client/command/commandRequest.d.ts +0 -180
  119. package/dist/client/command/commandRequest.es.js +0 -31
  120. package/dist/client/command/commandRequest.es.js.map +0 -1
  121. package/dist/client/command/commandResult.d.cts +0 -15
  122. package/dist/client/command/commandResult.d.ts +0 -15
  123. package/dist/client/command/index.d.cts +0 -5
  124. package/dist/client/command/index.d.ts +0 -5
  125. package/dist/client/command/types.d.cts +0 -71
  126. package/dist/client/command/types.d.ts +0 -71
  127. package/dist/client/metadata/index.d.cts +0 -2
  128. package/dist/client/metadata/index.d.ts +0 -2
  129. package/dist/client/metadata/wowMetadata.d.cts +0 -48
  130. package/dist/client/metadata/wowMetadata.d.ts +0 -48
  131. package/dist/client/metadata/wowMetadataClient.cjs +0 -2
  132. package/dist/client/metadata/wowMetadataClient.cjs.map +0 -1
  133. package/dist/client/metadata/wowMetadataClient.d.cts +0 -23
  134. package/dist/client/metadata/wowMetadataClient.d.ts +0 -23
  135. package/dist/client/metadata/wowMetadataClient.es.js +0 -25
  136. package/dist/client/metadata/wowMetadataClient.es.js.map +0 -1
  137. package/dist/client/query/dataset/datasetDescriptorEndpoint.cjs +0 -2
  138. package/dist/client/query/dataset/datasetDescriptorEndpoint.cjs.map +0 -1
  139. package/dist/client/query/dataset/datasetDescriptorEndpoint.d.cts +0 -8
  140. package/dist/client/query/dataset/datasetDescriptorEndpoint.d.ts +0 -8
  141. package/dist/client/query/dataset/datasetDescriptorEndpoint.es.js +0 -34
  142. package/dist/client/query/dataset/datasetDescriptorEndpoint.es.js.map +0 -1
  143. package/dist/client/query/dataset/datasetDirectoryClient.cjs +0 -2
  144. package/dist/client/query/dataset/datasetDirectoryClient.cjs.map +0 -1
  145. package/dist/client/query/dataset/datasetDirectoryClient.d.cts +0 -29
  146. package/dist/client/query/dataset/datasetDirectoryClient.d.ts +0 -29
  147. package/dist/client/query/dataset/datasetDirectoryClient.es.js +0 -25
  148. package/dist/client/query/dataset/datasetDirectoryClient.es.js.map +0 -1
  149. package/dist/client/query/dataset/datasetQueryApi.d.cts +0 -40
  150. package/dist/client/query/dataset/datasetQueryApi.d.ts +0 -40
  151. package/dist/client/query/dataset/datasetQueryClient.cjs +0 -2
  152. package/dist/client/query/dataset/datasetQueryClient.cjs.map +0 -1
  153. package/dist/client/query/dataset/datasetQueryClient.d.cts +0 -57
  154. package/dist/client/query/dataset/datasetQueryClient.d.ts +0 -57
  155. package/dist/client/query/dataset/datasetQueryClient.es.js +0 -154
  156. package/dist/client/query/dataset/datasetQueryClient.es.js.map +0 -1
  157. package/dist/client/query/dataset/endpointPaths.cjs +0 -2
  158. package/dist/client/query/dataset/endpointPaths.cjs.map +0 -1
  159. package/dist/client/query/dataset/endpointPaths.d.cts +0 -9
  160. package/dist/client/query/dataset/endpointPaths.d.ts +0 -9
  161. package/dist/client/query/dataset/endpointPaths.es.js +0 -14
  162. package/dist/client/query/dataset/endpointPaths.es.js.map +0 -1
  163. package/dist/client/query/dataset/index.d.cts +0 -3
  164. package/dist/client/query/dataset/index.d.ts +0 -3
  165. package/dist/client/query/descriptor/descriptorEndpoints.cjs +0 -2
  166. package/dist/client/query/descriptor/descriptorEndpoints.cjs.map +0 -1
  167. package/dist/client/query/descriptor/descriptorEndpoints.d.cts +0 -29
  168. package/dist/client/query/descriptor/descriptorEndpoints.d.ts +0 -29
  169. package/dist/client/query/descriptor/descriptorEndpoints.es.js +0 -69
  170. package/dist/client/query/descriptor/descriptorEndpoints.es.js.map +0 -1
  171. package/dist/client/query/descriptor/endpointPaths.cjs +0 -2
  172. package/dist/client/query/descriptor/endpointPaths.cjs.map +0 -1
  173. package/dist/client/query/descriptor/endpointPaths.d.cts +0 -4
  174. package/dist/client/query/descriptor/endpointPaths.d.ts +0 -4
  175. package/dist/client/query/descriptor/endpointPaths.es.js +0 -9
  176. package/dist/client/query/descriptor/endpointPaths.es.js.map +0 -1
  177. package/dist/client/query/descriptor/index.d.cts +0 -2
  178. package/dist/client/query/descriptor/index.d.ts +0 -2
  179. package/dist/client/query/descriptor/queryDescriptorApi.d.cts +0 -58
  180. package/dist/client/query/descriptor/queryDescriptorApi.d.ts +0 -58
  181. package/dist/client/query/descriptor/queryDescriptorClient.cjs +0 -2
  182. package/dist/client/query/descriptor/queryDescriptorClient.cjs.map +0 -1
  183. package/dist/client/query/descriptor/queryDescriptorClient.d.cts +0 -61
  184. package/dist/client/query/descriptor/queryDescriptorClient.d.ts +0 -61
  185. package/dist/client/query/descriptor/queryDescriptorClient.es.js +0 -20
  186. package/dist/client/query/descriptor/queryDescriptorClient.es.js.map +0 -1
  187. package/dist/client/query/event/endpointPaths.cjs +0 -2
  188. package/dist/client/query/event/endpointPaths.cjs.map +0 -1
  189. package/dist/client/query/event/endpointPaths.d.cts +0 -8
  190. package/dist/client/query/event/endpointPaths.d.ts +0 -8
  191. package/dist/client/query/event/endpointPaths.es.js +0 -13
  192. package/dist/client/query/event/endpointPaths.es.js.map +0 -1
  193. package/dist/client/query/event/eventStreamQueryApi.d.cts +0 -29
  194. package/dist/client/query/event/eventStreamQueryApi.d.ts +0 -29
  195. package/dist/client/query/event/eventStreamQueryClient.cjs +0 -2
  196. package/dist/client/query/event/eventStreamQueryClient.cjs.map +0 -1
  197. package/dist/client/query/event/eventStreamQueryClient.d.cts +0 -193
  198. package/dist/client/query/event/eventStreamQueryClient.d.ts +0 -193
  199. package/dist/client/query/event/eventStreamQueryClient.es.js +0 -160
  200. package/dist/client/query/event/eventStreamQueryClient.es.js.map +0 -1
  201. package/dist/client/query/event/index.d.cts +0 -2
  202. package/dist/client/query/event/index.d.ts +0 -2
  203. package/dist/client/query/factory.cjs +0 -2
  204. package/dist/client/query/factory.cjs.map +0 -1
  205. package/dist/client/query/factory.d.cts +0 -165
  206. package/dist/client/query/factory.d.ts +0 -165
  207. package/dist/client/query/factory.es.js +0 -45
  208. package/dist/client/query/factory.es.js.map +0 -1
  209. package/dist/client/query/index.d.cts +0 -7
  210. package/dist/client/query/index.d.ts +0 -7
  211. package/dist/client/query/queryApi.d.cts +0 -68
  212. package/dist/client/query/queryApi.d.ts +0 -68
  213. package/dist/client/query/requests.d.cts +0 -24
  214. package/dist/client/query/requests.d.ts +0 -24
  215. package/dist/client/query/snapshot/endpointPaths.cjs +0 -2
  216. package/dist/client/query/snapshot/endpointPaths.cjs.map +0 -1
  217. package/dist/client/query/snapshot/endpointPaths.d.cts +0 -12
  218. package/dist/client/query/snapshot/endpointPaths.d.ts +0 -12
  219. package/dist/client/query/snapshot/endpointPaths.es.js +0 -17
  220. package/dist/client/query/snapshot/endpointPaths.es.js.map +0 -1
  221. package/dist/client/query/snapshot/index.d.cts +0 -2
  222. package/dist/client/query/snapshot/index.d.ts +0 -2
  223. package/dist/client/query/snapshot/snapshotQueryApi.d.cts +0 -101
  224. package/dist/client/query/snapshot/snapshotQueryApi.d.ts +0 -101
  225. package/dist/client/query/snapshot/snapshotQueryClient.cjs +0 -2
  226. package/dist/client/query/snapshot/snapshotQueryClient.cjs.map +0 -1
  227. package/dist/client/query/snapshot/snapshotQueryClient.d.cts +0 -372
  228. package/dist/client/query/snapshot/snapshotQueryClient.d.ts +0 -372
  229. package/dist/client/query/snapshot/snapshotQueryClient.es.js +0 -239
  230. package/dist/client/query/snapshot/snapshotQueryClient.es.js.map +0 -1
  231. package/dist/client/query/state/endpointPaths.cjs +0 -2
  232. package/dist/client/query/state/endpointPaths.cjs.map +0 -1
  233. package/dist/client/query/state/endpointPaths.d.cts +0 -10
  234. package/dist/client/query/state/endpointPaths.d.ts +0 -10
  235. package/dist/client/query/state/endpointPaths.es.js +0 -14
  236. package/dist/client/query/state/endpointPaths.es.js.map +0 -1
  237. package/dist/client/query/state/index.d.cts +0 -4
  238. package/dist/client/query/state/index.d.ts +0 -4
  239. package/dist/client/query/state/loadOwnerStateAggregateApi.d.cts +0 -36
  240. package/dist/client/query/state/loadOwnerStateAggregateApi.d.ts +0 -36
  241. package/dist/client/query/state/loadOwnerStateAggregateClient.cjs +0 -2
  242. package/dist/client/query/state/loadOwnerStateAggregateClient.cjs.map +0 -1
  243. package/dist/client/query/state/loadOwnerStateAggregateClient.d.cts +0 -58
  244. package/dist/client/query/state/loadOwnerStateAggregateClient.d.ts +0 -58
  245. package/dist/client/query/state/loadOwnerStateAggregateClient.es.js +0 -56
  246. package/dist/client/query/state/loadOwnerStateAggregateClient.es.js.map +0 -1
  247. package/dist/client/query/state/loadStateAggregateApi.d.cts +0 -37
  248. package/dist/client/query/state/loadStateAggregateApi.d.ts +0 -37
  249. package/dist/client/query/state/loadStateAggregateClient.cjs +0 -2
  250. package/dist/client/query/state/loadStateAggregateClient.cjs.map +0 -1
  251. package/dist/client/query/state/loadStateAggregateClient.d.cts +0 -62
  252. package/dist/client/query/state/loadStateAggregateClient.d.ts +0 -62
  253. package/dist/client/query/state/loadStateAggregateClient.es.js +0 -65
  254. package/dist/client/query/state/loadStateAggregateClient.es.js.map +0 -1
  255. package/dist/client/routing.cjs +0 -2
  256. package/dist/client/routing.cjs.map +0 -1
  257. package/dist/client/routing.d.cts +0 -47
  258. package/dist/client/routing.d.ts +0 -47
  259. package/dist/client/routing.es.js +0 -8
  260. package/dist/client/routing.es.js.map +0 -1
  261. package/dist/error/errorInfo.cjs +0 -2
  262. package/dist/error/errorInfo.cjs.map +0 -1
  263. package/dist/error/errorInfo.d.cts +0 -139
  264. package/dist/error/errorInfo.d.ts +0 -139
  265. package/dist/error/errorInfo.es.js +0 -32
  266. package/dist/error/errorInfo.es.js.map +0 -1
  267. package/dist/error/headers.cjs +0 -2
  268. package/dist/error/headers.cjs.map +0 -1
  269. package/dist/error/headers.d.cts +0 -39
  270. package/dist/error/headers.d.ts +0 -39
  271. package/dist/error/headers.es.js +0 -10
  272. package/dist/error/headers.es.js.map +0 -1
  273. package/dist/error/index.d.cts +0 -21
  274. package/dist/error/index.d.ts +0 -21
  275. package/dist/error/queryErrorCodes.cjs +0 -2
  276. package/dist/error/queryErrorCodes.es.js.map +0 -1
  277. package/dist/error/wowError.cjs +0 -2
  278. package/dist/error/wowError.cjs.map +0 -1
  279. package/dist/error/wowError.d.cts +0 -99
  280. package/dist/error/wowError.d.ts +0 -99
  281. package/dist/error/wowError.es.js +0 -53
  282. package/dist/error/wowError.es.js.map +0 -1
  283. package/dist/legacy/condition.cjs +0 -2
  284. package/dist/legacy/condition.cjs.map +0 -1
  285. package/dist/legacy/condition.d.cts +0 -517
  286. package/dist/legacy/condition.d.ts +0 -517
  287. package/dist/legacy/condition.es.js +0 -338
  288. package/dist/legacy/condition.es.js.map +0 -1
  289. package/dist/legacy/index.d.cts +0 -16
  290. package/dist/legacy/index.d.ts +0 -16
  291. package/dist/legacy/locale/en_US.cjs +0 -2
  292. package/dist/legacy/locale/en_US.cjs.map +0 -1
  293. package/dist/legacy/locale/en_US.d.cts +0 -7
  294. package/dist/legacy/locale/en_US.d.ts +0 -7
  295. package/dist/legacy/locale/en_US.es.js +0 -50
  296. package/dist/legacy/locale/en_US.es.js.map +0 -1
  297. package/dist/legacy/locale/operatorLocale.d.cts +0 -10
  298. package/dist/legacy/locale/operatorLocale.d.ts +0 -10
  299. package/dist/legacy/locale/zh_CN.cjs +0 -2
  300. package/dist/legacy/locale/zh_CN.cjs.map +0 -1
  301. package/dist/legacy/locale/zh_CN.d.cts +0 -7
  302. package/dist/legacy/locale/zh_CN.d.ts +0 -7
  303. package/dist/legacy/locale/zh_CN.es.js +0 -50
  304. package/dist/legacy/locale/zh_CN.es.js.map +0 -1
  305. package/dist/legacy/operator.cjs +0 -2
  306. package/dist/legacy/operator.cjs.map +0 -1
  307. package/dist/legacy/operator.d.cts +0 -218
  308. package/dist/legacy/operator.d.ts +0 -218
  309. package/dist/legacy/operator.es.js +0 -25
  310. package/dist/legacy/operator.es.js.map +0 -1
  311. package/dist/legacy/queryable.cjs +0 -2
  312. package/dist/legacy/queryable.cjs.map +0 -1
  313. package/dist/legacy/queryable.d.cts +0 -61
  314. package/dist/legacy/queryable.d.ts +0 -61
  315. package/dist/legacy/queryable.es.js +0 -34
  316. package/dist/legacy/queryable.es.js.map +0 -1
  317. package/dist/legacy.cjs +0 -1
  318. package/dist/legacy.es.js +0 -6
  319. package/dist/model/abac.cjs +0 -2
  320. package/dist/model/abac.cjs.map +0 -1
  321. package/dist/model/abac.d.cts +0 -33
  322. package/dist/model/abac.d.ts +0 -33
  323. package/dist/model/abac.es.js +0 -6
  324. package/dist/model/abac.es.js.map +0 -1
  325. package/dist/model/bi.cjs +0 -2
  326. package/dist/model/bi.cjs.map +0 -1
  327. package/dist/model/bi.d.cts +0 -12
  328. package/dist/model/bi.d.ts +0 -12
  329. package/dist/model/bi.es.js +0 -8
  330. package/dist/model/bi.es.js.map +0 -1
  331. package/dist/model/command.cjs +0 -2
  332. package/dist/model/command.cjs.map +0 -1
  333. package/dist/model/command.d.cts +0 -137
  334. package/dist/model/command.d.ts +0 -137
  335. package/dist/model/command.es.js +0 -8
  336. package/dist/model/command.es.js.map +0 -1
  337. package/dist/model/common.d.cts +0 -19
  338. package/dist/model/common.d.ts +0 -19
  339. package/dist/model/domainEventStream.cjs +0 -2
  340. package/dist/model/domainEventStream.cjs.map +0 -1
  341. package/dist/model/domainEventStream.d.cts +0 -109
  342. package/dist/model/domainEventStream.d.ts +0 -109
  343. package/dist/model/domainEventStream.es.js +0 -23
  344. package/dist/model/domainEventStream.es.js.map +0 -1
  345. package/dist/model/function.cjs +0 -2
  346. package/dist/model/function.cjs.map +0 -1
  347. package/dist/model/function.d.cts +0 -41
  348. package/dist/model/function.d.ts +0 -41
  349. package/dist/model/function.es.js +0 -8
  350. package/dist/model/function.es.js.map +0 -1
  351. package/dist/model/index.d.cts +0 -24
  352. package/dist/model/index.d.ts +0 -24
  353. package/dist/model/messaging.d.cts +0 -5
  354. package/dist/model/messaging.d.ts +0 -5
  355. package/dist/model/modeling.d.cts +0 -145
  356. package/dist/model/modeling.d.ts +0 -145
  357. package/dist/model/naming.d.cts +0 -27
  358. package/dist/model/naming.d.ts +0 -27
  359. package/dist/model/snapshot.cjs +0 -2
  360. package/dist/model/snapshot.cjs.map +0 -1
  361. package/dist/model/snapshot.d.cts +0 -53
  362. package/dist/model/snapshot.d.ts +0 -53
  363. package/dist/model/snapshot.es.js +0 -20
  364. package/dist/model/snapshot.es.js.map +0 -1
  365. package/dist/transport/endpoints.cjs +0 -2
  366. package/dist/transport/endpoints.cjs.map +0 -1
  367. package/dist/transport/endpoints.d.cts +0 -79
  368. package/dist/transport/endpoints.d.ts +0 -79
  369. package/dist/transport/endpoints.es.js +0 -14
  370. package/dist/transport/endpoints.es.js.map +0 -1
  371. package/dist/transport/eventStreams.cjs +0 -2
  372. package/dist/transport/eventStreams.cjs.map +0 -1
  373. package/dist/transport/eventStreams.d.cts +0 -25
  374. package/dist/transport/eventStreams.d.ts +0 -25
  375. package/dist/transport/eventStreams.es.js +0 -21
  376. package/dist/transport/eventStreams.es.js.map +0 -1
  377. package/dist/transport/index.d.cts +0 -1
  378. package/dist/transport/index.d.ts +0 -1
  379. package/dist/v10/commands.cjs +0 -2
  380. package/dist/v10/commands.cjs.map +0 -1
  381. package/dist/v10/commands.es.js +0 -68
  382. package/dist/v10/commands.es.js.map +0 -1
  383. package/dist/v10/http.cjs +0 -2
  384. package/dist/v10/http.cjs.map +0 -1
  385. package/dist/v10/http.es.js +0 -73
  386. package/dist/v10/http.es.js.map +0 -1
  387. package/dist/v10/index.d.cts +0 -19
  388. package/dist/v10/index.d.ts +0 -19
  389. package/dist/v10/manifest.cjs.map +0 -1
  390. package/dist/v10/manifest.es.js.map +0 -1
  391. package/dist/v10/problem.cjs +0 -2
  392. package/dist/v10/problem.cjs.map +0 -1
  393. package/dist/v10/problem.es.js.map +0 -1
  394. package/dist/v10/queries.cjs +0 -2
  395. package/dist/v10/queries.cjs.map +0 -1
  396. package/dist/v10/queries.es.js +0 -88
  397. package/dist/v10/queries.es.js.map +0 -1
  398. package/dist/v10/state.cjs +0 -2
  399. package/dist/v10/state.cjs.map +0 -1
  400. package/dist/v10/state.es.js +0 -51
  401. package/dist/v10/state.es.js.map +0 -1
  402. package/dist/v10/streams.cjs +0 -2
  403. package/dist/v10/streams.cjs.map +0 -1
  404. package/dist/v10/streams.d.cts +0 -14
  405. package/dist/v10/streams.d.ts +0 -14
  406. package/dist/v10/streams.es.js +0 -22
  407. package/dist/v10/streams.es.js.map +0 -1
  408. package/dist/v10/wait.cjs.map +0 -1
  409. package/dist/v10/wait.es.js.map +0 -1
  410. package/dist/v10/wire.cjs.map +0 -1
  411. package/dist/v10/wire.es.js.map +0 -1
  412. package/dist/v10.cjs +0 -1
  413. package/dist/v10.es.js +0 -9
  414. /package/dist/{v10/manifest.cjs → manifest.cjs} +0 -0
  415. /package/dist/{v10/manifest.d.cts → manifest.d.cts} +0 -0
  416. /package/dist/{v10/manifest.d.ts → manifest.d.ts} +0 -0
  417. /package/dist/{v10/wait.cjs → wait.cjs} +0 -0
  418. /package/dist/{v10/wait.d.cts → wait.d.cts} +0 -0
  419. /package/dist/{v10/wait.d.ts → wait.d.ts} +0 -0
  420. /package/dist/{v10/wire.cjs → wire.cjs} +0 -0
@@ -1,18 +1,26 @@
1
- import { AggregationQuery } from '../dsl/aggregation/index.js';
2
- import { CursorPage, CursorQuery } from '../dsl/cursorQuery.js';
3
- import { QueryModelDescriptor } from '../dsl/descriptor.js';
4
- import { FilterCapable } from '../dsl/filter/index.js';
5
- import { FilterListQuery, FilterPagedQuery, FilterSingleQuery } from '../dsl/queryable.js';
1
+ import { AggregationQuery } from './dsl/aggregation/index.js';
2
+ import { CursorPage, CursorQuery } from './dsl/cursorQuery.js';
3
+ import { Projected } from './dsl/projection.js';
4
+ import { TextNumbers } from './exactJson.js';
5
+ import { QueryModelDescriptor } from './dsl/descriptor.js';
6
+ import { FilterCapable } from './dsl/filter/index.js';
7
+ import { FilterListQuery, FilterPagedQuery, FilterSingleQuery } from './dsl/queryable.js';
6
8
  import { RequestOptions, WowClientOptions } from './http.js';
7
9
  import { AggregateType, DatasetEntry, EventStreamField, EventStreamRecord, EventView, SnapshotRecord, SnapshotSystemField } from './wire.js';
10
+ import { StreamedRow, StreamResumeOptions } from './streams.js';
11
+ /** How a list is streamed: the request's options, and how it resumes. */
12
+ export interface ListStreamOptions extends RequestOptions {
13
+ /** How the stream resumes (decision D253); `false` never resumes it. */
14
+ readonly resume?: StreamResumeOptions | false;
15
+ }
8
16
  /** How a paged query counts its total (`TotalMode`, decision D150). */
9
17
  export type TotalMode = 'EXACT' | 'BOUNDED' | 'NONE';
10
- /** A paged query of a V10 query route: a page, and how its total is counted. */
18
+ /** A paged query of a query route: a page, and how its total is counted. */
11
19
  export interface PagedQuery<FIELDS extends string = string> extends FilterPagedQuery<FIELDS> {
12
20
  /** `BOUNDED` (the server's default) counts up to the budget's limit. */
13
21
  total?: TotalMode;
14
22
  }
15
- /** A count of a V10 query route (decision D150). */
23
+ /** A count of a query route (decision D150). */
16
24
  export interface CountQuery<FIELDS extends string = string> extends FilterCapable<FIELDS> {
17
25
  /** The most matches to count; the budget's default when absent. */
18
26
  limit?: number;
@@ -44,9 +52,11 @@ export type DescriptorResult = {
44
52
  readonly version: string;
45
53
  };
46
54
  /**
47
- * Queries one query model of a Wow V10 service: `POST {path}` with a body
55
+ * Queries one query model of a Wow service: `POST {path}` with a body
48
56
  * whose `kind` names the operation, `GET {path}` for the capability
49
- * descriptor (decisions D127, D145).
57
+ * descriptor (decisions D127, D145). A query written with literal `include`
58
+ * paths answers records narrowed to them ({@link Projected}, review R4-Q,
59
+ * Q-14).
50
60
  *
51
61
  * @typeParam R - The record's type.
52
62
  * @typeParam FIELDS - The field paths a filter, sort or projection takes.
@@ -54,23 +64,47 @@ export type DescriptorResult = {
54
64
  export declare class QueryModelClient<R, FIELDS extends string = string> {
55
65
  readonly path: string;
56
66
  readonly client: WowClientOptions;
67
+ readonly numbers?: TextNumbers | undefined;
57
68
  /**
58
69
  * @param path - The query route, `/{context}/{aggregate}/{model}/query`
59
70
  * @param client - How the service is reached
71
+ * @param numbers - The numbers of each record read as their exact text
72
+ * (review R4-Q, Q-9)
60
73
  */
61
- constructor(path: string, client?: WowClientOptions);
74
+ constructor(path: string, client?: WowClientOptions, numbers?: TextNumbers | undefined);
75
+ /** The marks of a list of records. */
76
+ private get listNumbers();
77
+ /** The marks of a page of records. */
78
+ private get pageNumbers();
62
79
  /** The records that match, at most `limit` (the server's default when absent). */
80
+ list<const INCLUDE extends FIELDS>(query: Including<FilterListQuery<FIELDS>, INCLUDE>, options?: RequestOptions): Promise<Projected<R, INCLUDE>[]>;
63
81
  list(query: FilterListQuery<FIELDS>, options?: RequestOptions): Promise<R[]>;
64
82
  /**
65
83
  * The records that match, as server-sent events read one at a time; a
66
- * failure after the first record errors the stream with its problem.
84
+ * failure after the first record errors the stream with its problem. The
85
+ * stream resumes where it stopped (decision D253) when the server ends it
86
+ * to be resumed, when it is cut off and when it fails with a retryable
87
+ * problem: see {@link StreamResumeOptions}. A `limit` counts every record
88
+ * read, resumed or not.
89
+ */
90
+ listStream<const INCLUDE extends FIELDS>(query: Including<FilterListQuery<FIELDS>, INCLUDE>, options?: ListStreamOptions): Promise<ReadableStream<Projected<R, INCLUDE>>>;
91
+ listStream(query: FilterListQuery<FIELDS>, options?: ListStreamOptions): Promise<ReadableStream<R>>;
92
+ /**
93
+ * The records that match as {@link listStream} reads them, each with its
94
+ * position: keep the last one read to resume the stream later
95
+ * ({@link StreamResumeOptions.lastEventId}), on another page or after a
96
+ * restart.
67
97
  */
68
- listStream(query: FilterListQuery<FIELDS>, options?: RequestOptions): Promise<ReadableStream<R>>;
98
+ listStreamRows<const INCLUDE extends FIELDS>(query: Including<FilterListQuery<FIELDS>, INCLUDE>, options?: ListStreamOptions): Promise<ReadableStream<StreamedRow<Projected<R, INCLUDE>>>>;
99
+ listStreamRows(query: FilterListQuery<FIELDS>, options?: ListStreamOptions): Promise<ReadableStream<StreamedRow<R>>>;
69
100
  /** One page of the records that match, and their total. */
101
+ paged<const INCLUDE extends FIELDS>(query: Including<PagedQuery<FIELDS>, INCLUDE>, options?: RequestOptions): Promise<PagedResult<Projected<R, INCLUDE>>>;
70
102
  paged(query: PagedQuery<FIELDS>, options?: RequestOptions): Promise<PagedResult<R>>;
71
103
  /** One page of a forward-only cursor over the records that match. */
104
+ cursor<const INCLUDE extends FIELDS>(query: Including<CursorQuery<FIELDS>, INCLUDE>, options?: RequestOptions): Promise<CursorPage<Projected<R, INCLUDE>>>;
72
105
  cursor(query: CursorQuery<FIELDS>, options?: RequestOptions): Promise<CursorPage<R>>;
73
- /** The first record that matches; rejects with 404 when none does. */
106
+ /** The first record that matches; rejects with 404 `wow.query.not-found` when none does. */
107
+ single<const INCLUDE extends FIELDS>(query: Including<FilterSingleQuery<FIELDS>, INCLUDE>, options?: RequestOptions): Promise<Projected<R, INCLUDE>>;
74
108
  single(query: FilterSingleQuery<FIELDS>, options?: RequestOptions): Promise<R>;
75
109
  /** How many records match, bounded by the count's limit. */
76
110
  count(query: CountQuery<FIELDS>, options?: RequestOptions): Promise<CountResult>;
@@ -83,6 +117,15 @@ export declare class QueryModelClient<R, FIELDS extends string = string> {
83
117
  describe(version?: string, options?: RequestOptions): Promise<DescriptorResult>;
84
118
  private post;
85
119
  }
120
+ /**
121
+ * A query whose projection includes the literal paths `INCLUDE`: a query
122
+ * client narrows its records to them ({@link Projected}).
123
+ */
124
+ export type Including<Q, INCLUDE extends string> = Q & {
125
+ readonly projection: {
126
+ readonly include: readonly INCLUDE[];
127
+ };
128
+ };
86
129
  /** The query route of a model of an aggregate type. */
87
130
  export declare function queryPath(type: AggregateType, model: string): string;
88
131
  /**
@@ -101,9 +144,12 @@ export declare class SnapshotQueryClient<S = unknown, STATE_FIELDS extends strin
101
144
  constructor(type: AggregateType, client?: WowClientOptions);
102
145
  }
103
146
  /**
104
- * Queries an aggregate type's event streams (decision D131), one aggregate
105
- * at a time: a filter names its `aggregateId`, and may bound `version` or
106
- * `commitTime`.
147
+ * Queries an aggregate type's event streams (decision D235) on the same
148
+ * engine as its snapshots: one record per commit, `count` counts commits, a
149
+ * condition on an event is an `elementMatch` on `events`, and per-event
150
+ * analytics expand `events` in an aggregation (`elements`). A filter need
151
+ * not name the aggregate, but one that does not reads the log the service
152
+ * appends to: the budget bounds it.
107
153
  *
108
154
  * @typeParam E - The events' type.
109
155
  */
@@ -116,7 +162,7 @@ export declare class EventQueryClient<E extends EventView = EventView> extends Q
116
162
  constructor(type: AggregateType, client?: WowClientOptions);
117
163
  }
118
164
  /**
119
- * The datasets of a Wow V10 service (decisions D75, D145): registered at run
165
+ * The datasets of a Wow service (decisions D75, D145): registered at run
120
166
  * time, so not in the Manifest. Lists those the caller sees and queries
121
167
  * each as a snapshot model is queried.
122
168
  */
@@ -0,0 +1,112 @@
1
+ import { eventNumbers as e } from "./exactJson.es.js";
2
+ import { WowHeaders as t, entityTag as n, json as r, send as i } from "./http.es.js";
3
+ import { resumableQueryRows as a } from "./streams.es.js";
4
+ //#region src/queries.ts
5
+ var o = class {
6
+ constructor(e, t = {}, n) {
7
+ this.path = e, this.client = t, this.numbers = n;
8
+ }
9
+ get listNumbers() {
10
+ return this.numbers === void 0 ? void 0 : { "*": this.numbers };
11
+ }
12
+ get pageNumbers() {
13
+ return this.numbers === void 0 ? void 0 : { list: { "*": this.numbers } };
14
+ }
15
+ async list(e, t) {
16
+ return r(await this.post("list", e, t), this.listNumbers);
17
+ }
18
+ async listStream(e, t) {
19
+ return (await this.listStreamRows(e, t)).pipeThrough(new TransformStream({ transform(e, t) {
20
+ t.enqueue(e.record);
21
+ } }));
22
+ }
23
+ async listStreamRows(e, t = {}) {
24
+ let n = t.resume === !1 ? { maxRetries: 0 } : t.resume, r = e.limit ?? 0, i = (n, i) => this.post("list", r > 0 ? {
25
+ ...e,
26
+ limit: r - i
27
+ } : e, t, "text/event-stream", n), o = await i(n?.lastEventId, 0);
28
+ return a(o, (e, t) => r > 0 && t >= r ? Promise.resolve(void 0) : i(e, t), {
29
+ ...n,
30
+ ...t.signal === void 0 ? {} : { signal: t.signal },
31
+ ...this.numbers === void 0 ? {} : { numbers: this.numbers }
32
+ });
33
+ }
34
+ async paged(e, t) {
35
+ return r(await this.post("paged", e, t), this.pageNumbers);
36
+ }
37
+ async cursor(e, t) {
38
+ return r(await this.post("cursor", e, t), this.pageNumbers);
39
+ }
40
+ async single(e, t) {
41
+ return r(await this.post("single", e, t), this.numbers);
42
+ }
43
+ async count(e, t) {
44
+ return r(await this.post("count", e, t));
45
+ }
46
+ async aggregate(e, t) {
47
+ return r(await this.post("aggregate", e, t));
48
+ }
49
+ async describe(e, a) {
50
+ let o = await i(this.client, {
51
+ method: "GET",
52
+ path: this.path,
53
+ headers: { [t.IF_NONE_MATCH]: e === void 0 ? void 0 : `"${e}"` },
54
+ options: a,
55
+ notModified: !0
56
+ }), s = n(o);
57
+ return o.status === 304 ? {
58
+ notModified: !0,
59
+ version: s ?? e ?? ""
60
+ } : {
61
+ notModified: !1,
62
+ ...s === void 0 ? {} : { version: s },
63
+ descriptor: await r(o)
64
+ };
65
+ }
66
+ post(e, n, r, a, o) {
67
+ return i(this.client, {
68
+ method: "POST",
69
+ path: this.path,
70
+ headers: {
71
+ Accept: a,
72
+ [t.LAST_EVENT_ID]: o
73
+ },
74
+ body: {
75
+ ...n,
76
+ kind: e
77
+ },
78
+ options: r
79
+ });
80
+ }
81
+ };
82
+ function s(e, t) {
83
+ return `/${e.context}/${e.name}/${t}/query`;
84
+ }
85
+ var c = class extends o {
86
+ constructor(e, t) {
87
+ super(s(e, "snapshot"), t, e.textNumbers?.state === void 0 ? void 0 : { state: e.textNumbers.state }), this.type = e;
88
+ }
89
+ }, l = class extends o {
90
+ constructor(t, n) {
91
+ let r = e(t);
92
+ super(s(t, "events"), n, r === void 0 ? void 0 : { events: { "*": r } }), this.type = t;
93
+ }
94
+ }, u = class {
95
+ constructor(e = {}) {
96
+ this.client = e;
97
+ }
98
+ async list(e) {
99
+ return r(await i(this.client, {
100
+ method: "GET",
101
+ path: "/wow/dataset",
102
+ options: e
103
+ }));
104
+ }
105
+ dataset(e, t) {
106
+ return new o(`/wow/dataset/${encodeURIComponent(e)}/${encodeURIComponent(t)}/query`, this.client);
107
+ }
108
+ };
109
+ //#endregion
110
+ export { u as DatasetClient, l as EventQueryClient, o as QueryModelClient, c as SnapshotQueryClient, s as queryPath };
111
+
112
+ //# sourceMappingURL=queries.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.es.js","names":["QueryModelClient","path","client","numbers","json","query","options","row","resume","limit","open","received","lastEventId","first","resumableQueryRows","response","send","WowHeaders","version","tag","entityTag","accept","queryPath","type","model","SnapshotQueryClient","EventQueryClient","events","eventNumbers","DatasetClient","context","dataset"],"sources":["../src/queries.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AggregationQuery } from './dsl/aggregation/index.js';\nimport type { CursorPage, CursorQuery } from './dsl/cursorQuery.js';\nimport type { Projected } from './dsl/projection.js';\nimport { eventNumbers, type TextNumbers } from './exactJson.js';\nimport type { QueryModelDescriptor } from './dsl/descriptor.js';\nimport type { FilterCapable } from './dsl/filter/index.js';\nimport type {\n FilterListQuery,\n FilterPagedQuery,\n FilterSingleQuery,\n} from './dsl/queryable.js';\nimport {\n entityTag,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowHeaders,\n} from './http.js';\nimport type {\n AggregateType,\n DatasetEntry,\n EventStreamField,\n EventStreamRecord,\n EventView,\n SnapshotRecord,\n SnapshotSystemField,\n} from './wire.js';\nimport {\n resumableQueryRows,\n type StreamedRow,\n type StreamResumeOptions,\n} from './streams.js';\n\n/** How a list is streamed: the request's options, and how it resumes. */\nexport interface ListStreamOptions extends RequestOptions {\n /** How the stream resumes (decision D253); `false` never resumes it. */\n readonly resume?: StreamResumeOptions | false;\n}\n\n/** How a paged query counts its total (`TotalMode`, decision D150). */\nexport type TotalMode = 'EXACT' | 'BOUNDED' | 'NONE';\n\n/** A paged query of a query route: a page, and how its total is counted. */\nexport interface PagedQuery<\n FIELDS extends string = string,\n> extends FilterPagedQuery<FIELDS> {\n /** `BOUNDED` (the server's default) counts up to the budget's limit. */\n total?: TotalMode;\n}\n\n/** A count of a query route (decision D150). */\nexport interface CountQuery<\n FIELDS extends string = string,\n> extends FilterCapable<FIELDS> {\n /** The most matches to count; the budget's default when absent. */\n limit?: number;\n}\n\n/** What a count answers: exact below its limit, else the limit itself. */\nexport interface CountResult {\n readonly count: number;\n readonly exact: boolean;\n}\n\n/**\n * A page of a paged query: `total` is exact when `exact`, a lower bound\n * otherwise, and null for `TotalMode.NONE`.\n */\nexport interface PagedResult<T> {\n readonly total: number | null;\n readonly exact: boolean;\n readonly list: readonly T[];\n}\n\n/**\n * A query model's capability descriptor and its version, the `ETag` of\n * `GET …/query`; `notModified` when the version given is still current.\n */\nexport type DescriptorResult =\n | {\n readonly notModified: false;\n readonly version?: string;\n readonly descriptor: QueryModelDescriptor;\n }\n | { readonly notModified: true; readonly version: string };\n\n/**\n * Queries one query model of a Wow service: `POST {path}` with a body\n * whose `kind` names the operation, `GET {path}` for the capability\n * descriptor (decisions D127, D145). A query written with literal `include`\n * paths answers records narrowed to them ({@link Projected}, review R4-Q,\n * Q-14).\n *\n * @typeParam R - The record's type.\n * @typeParam FIELDS - The field paths a filter, sort or projection takes.\n */\nexport class QueryModelClient<R, FIELDS extends string = string> {\n /**\n * @param path - The query route, `/{context}/{aggregate}/{model}/query`\n * @param client - How the service is reached\n * @param numbers - The numbers of each record read as their exact text\n * (review R4-Q, Q-9)\n */\n constructor(\n readonly path: string,\n readonly client: WowClientOptions = {},\n readonly numbers?: TextNumbers,\n ) {}\n\n /** The marks of a list of records. */\n private get listNumbers(): TextNumbers | undefined {\n return this.numbers === undefined ? undefined : { '*': this.numbers };\n }\n\n /** The marks of a page of records. */\n private get pageNumbers(): TextNumbers | undefined {\n return this.numbers === undefined\n ? undefined\n : { list: { '*': this.numbers } };\n }\n\n /** The records that match, at most `limit` (the server's default when absent). */\n list<const INCLUDE extends FIELDS>(\n query: Including<FilterListQuery<FIELDS>, INCLUDE>,\n options?: RequestOptions,\n ): Promise<Projected<R, INCLUDE>[]>;\n list(query: FilterListQuery<FIELDS>, options?: RequestOptions): Promise<R[]>;\n async list(\n query: FilterListQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<unknown> {\n return json<R[]>(await this.post('list', query, options), this.listNumbers);\n }\n\n /**\n * The records that match, as server-sent events read one at a time; a\n * failure after the first record errors the stream with its problem. The\n * stream resumes where it stopped (decision D253) when the server ends it\n * to be resumed, when it is cut off and when it fails with a retryable\n * problem: see {@link StreamResumeOptions}. A `limit` counts every record\n * read, resumed or not.\n */\n listStream<const INCLUDE extends FIELDS>(\n query: Including<FilterListQuery<FIELDS>, INCLUDE>,\n options?: ListStreamOptions,\n ): Promise<ReadableStream<Projected<R, INCLUDE>>>;\n listStream(\n query: FilterListQuery<FIELDS>,\n options?: ListStreamOptions,\n ): Promise<ReadableStream<R>>;\n async listStream(\n query: FilterListQuery<FIELDS>,\n options?: ListStreamOptions,\n ): Promise<unknown> {\n return (await this.listStreamRows(query, options)).pipeThrough(\n new TransformStream<StreamedRow<R>, R>({\n transform(row, controller) {\n controller.enqueue(row.record);\n },\n }),\n );\n }\n\n /**\n * The records that match as {@link listStream} reads them, each with its\n * position: keep the last one read to resume the stream later\n * ({@link StreamResumeOptions.lastEventId}), on another page or after a\n * restart.\n */\n listStreamRows<const INCLUDE extends FIELDS>(\n query: Including<FilterListQuery<FIELDS>, INCLUDE>,\n options?: ListStreamOptions,\n ): Promise<ReadableStream<StreamedRow<Projected<R, INCLUDE>>>>;\n listStreamRows(\n query: FilterListQuery<FIELDS>,\n options?: ListStreamOptions,\n ): Promise<ReadableStream<StreamedRow<R>>>;\n async listStreamRows(\n query: FilterListQuery<FIELDS>,\n options: ListStreamOptions = {},\n ): Promise<ReadableStream<StreamedRow<R>>> {\n const resume =\n options.resume === false ? { maxRetries: 0 } : options.resume;\n const limit = query.limit ?? 0;\n const open = (lastEventId: string | undefined, received: number) => {\n return this.post(\n 'list',\n limit > 0 ? { ...query, limit: limit - received } : query,\n options,\n 'text/event-stream',\n lastEventId,\n );\n };\n const first = await open(resume?.lastEventId, 0);\n return resumableQueryRows<R>(\n first,\n (lastEventId, received) =>\n limit > 0 && received >= limit\n ? Promise.resolve(undefined)\n : open(lastEventId, received),\n {\n ...resume,\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n ...(this.numbers === undefined ? {} : { numbers: this.numbers }),\n },\n );\n }\n\n /** One page of the records that match, and their total. */\n paged<const INCLUDE extends FIELDS>(\n query: Including<PagedQuery<FIELDS>, INCLUDE>,\n options?: RequestOptions,\n ): Promise<PagedResult<Projected<R, INCLUDE>>>;\n paged(\n query: PagedQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<PagedResult<R>>;\n async paged(\n query: PagedQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<unknown> {\n return json<PagedResult<R>>(\n await this.post('paged', query, options),\n this.pageNumbers,\n );\n }\n\n /** One page of a forward-only cursor over the records that match. */\n cursor<const INCLUDE extends FIELDS>(\n query: Including<CursorQuery<FIELDS>, INCLUDE>,\n options?: RequestOptions,\n ): Promise<CursorPage<Projected<R, INCLUDE>>>;\n cursor(\n query: CursorQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<CursorPage<R>>;\n async cursor(\n query: CursorQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<unknown> {\n return json<CursorPage<R>>(\n await this.post('cursor', query, options),\n this.pageNumbers,\n );\n }\n\n /** The first record that matches; rejects with 404 `wow.query.not-found` when none does. */\n single<const INCLUDE extends FIELDS>(\n query: Including<FilterSingleQuery<FIELDS>, INCLUDE>,\n options?: RequestOptions,\n ): Promise<Projected<R, INCLUDE>>;\n single(\n query: FilterSingleQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<R>;\n async single(\n query: FilterSingleQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<unknown> {\n return json<R>(await this.post('single', query, options), this.numbers);\n }\n\n /** How many records match, bounded by the count's limit. */\n async count(\n query: CountQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<CountResult> {\n return json<CountResult>(await this.post('count', query, options));\n }\n\n /** The groups and metrics of an aggregation, one row per group. */\n async aggregate<ROW = Record<string, unknown>>(\n query: AggregationQuery<FIELDS, string>,\n options?: RequestOptions,\n ): Promise<ROW[]> {\n return json<ROW[]>(await this.post('aggregate', query, options));\n }\n\n /**\n * The model's capability descriptor; with the `version` already held, a\n * 304 answers `notModified`.\n */\n async describe(\n version?: string,\n options?: RequestOptions,\n ): Promise<DescriptorResult> {\n const response = await send(this.client, {\n method: 'GET',\n path: this.path,\n headers: {\n [WowHeaders.IF_NONE_MATCH]:\n version === undefined ? undefined : `\"${version}\"`,\n },\n options,\n notModified: true,\n });\n const tag = entityTag(response);\n if (response.status === 304) {\n return { notModified: true, version: tag ?? version ?? '' };\n }\n return {\n notModified: false,\n ...(tag === undefined ? {} : { version: tag }),\n descriptor: await json<QueryModelDescriptor>(response),\n };\n }\n\n private post(\n kind: string,\n query: object,\n options?: RequestOptions,\n accept?: string,\n lastEventId?: string,\n ): Promise<Response> {\n return send(this.client, {\n method: 'POST',\n path: this.path,\n headers: { Accept: accept, [WowHeaders.LAST_EVENT_ID]: lastEventId },\n body: { ...query, kind },\n options,\n });\n }\n}\n\n/**\n * A query whose projection includes the literal paths `INCLUDE`: a query\n * client narrows its records to them ({@link Projected}).\n */\nexport type Including<Q, INCLUDE extends string> = Q & {\n readonly projection: { readonly include: readonly INCLUDE[] };\n};\n\n/** The query route of a model of an aggregate type. */\nexport function queryPath(type: AggregateType, model: string): string {\n return `/${type.context}/${type.name}/${model}/query`;\n}\n\n/**\n * Queries an aggregate type's snapshots (decision D128), the default read\n * model; only where the aggregate keeps them.\n *\n * @typeParam S - The state's type.\n * @typeParam STATE_FIELDS - The `state.*` paths of the state.\n */\nexport class SnapshotQueryClient<\n S = unknown,\n STATE_FIELDS extends string = `state.${string}`,\n> extends QueryModelClient<\n SnapshotRecord<S>,\n SnapshotSystemField | STATE_FIELDS\n> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n client?: WowClientOptions,\n ) {\n super(\n queryPath(type, 'snapshot'),\n client,\n type.textNumbers?.state === undefined\n ? undefined\n : { state: type.textNumbers.state },\n );\n }\n}\n\n/**\n * Queries an aggregate type's event streams (decision D235) on the same\n * engine as its snapshots: one record per commit, `count` counts commits, a\n * condition on an event is an `elementMatch` on `events`, and per-event\n * analytics expand `events` in an aggregation (`elements`). A filter need\n * not name the aggregate, but one that does not reads the log the service\n * appends to: the budget bounds it.\n *\n * @typeParam E - The events' type.\n */\nexport class EventQueryClient<\n E extends EventView = EventView,\n> extends QueryModelClient<EventStreamRecord<E>, EventStreamField> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n client?: WowClientOptions,\n ) {\n const events = eventNumbers(type);\n super(\n queryPath(type, 'events'),\n client,\n events === undefined ? undefined : { events: { '*': events } },\n );\n }\n}\n\n/**\n * The datasets of a Wow service (decisions D75, D145): registered at run\n * time, so not in the Manifest. Lists those the caller sees and queries\n * each as a snapshot model is queried.\n */\nexport class DatasetClient {\n /** @param client - How the service is reached */\n constructor(readonly client: WowClientOptions = {}) {}\n\n /** The datasets the caller sees, by name. */\n async list(options?: RequestOptions): Promise<DatasetEntry[]> {\n return json<DatasetEntry[]>(\n await send(this.client, { method: 'GET', path: '/wow/dataset', options }),\n );\n }\n\n /**\n * The query client of the dataset `context.dataset`.\n *\n * @typeParam R - The row's type.\n * @typeParam FIELDS - The dataset's field paths.\n */\n dataset<R = Record<string, unknown>, FIELDS extends string = string>(\n context: string,\n dataset: string,\n ): QueryModelClient<R, FIELDS> {\n return new QueryModelClient<R, FIELDS>(\n `/wow/dataset/${encodeURIComponent(context)}/${encodeURIComponent(dataset)}/query`,\n this.client,\n );\n }\n}\n"],"mappings":";;;;AA8GA,IAAaA,IAAb,MAAiE;CAO/D,YACE,GACA,IAAoC,CAAC,GACrC,GACA;EADS,AAFA,KAAA,OAAAC,GACA,KAAA,SAAAC,GACA,KAAA,UAAAC;CACR;CAGH,IAAY,cAAuC;EACjD,OAAO,KAAK,YAAY,KAAA,IAAY,KAAA,IAAY,EAAE,KAAK,KAAK,QAAQ;CACtE;CAGA,IAAY,cAAuC;EACjD,OAAO,KAAK,YAAY,KAAA,IACpB,KAAA,IACA,EAAE,MAAM,EAAE,KAAK,KAAK,QAAQ,EAAE;CACpC;CAQA,MAAM,KACJ,GACA,GACkB;EAClB,OAAOC,EAAU,MAAM,KAAK,KAAK,QAAQC,GAAOC,CAAO,GAAG,KAAK,WAAW;CAC5E;CAkBA,MAAM,WACJ,GACA,GACkB;EAClB,QAAQ,MAAM,KAAK,eAAeD,GAAOC,CAAO,EAAA,CAAG,YACjD,IAAI,gBAAmC,EACrC,UAAU,GAAK,GAAY;GACzB,EAAW,QAAQC,EAAI,MAAM;EAC/B,EACF,CAAC,CACH;CACF;CAgBA,MAAM,eACJ,GACA,IAA6B,CAAC,GACW;EACzC,IAAMC,IACJF,EAAQ,WAAW,KAAQ,EAAE,YAAY,EAAE,IAAIA,EAAQ,QACnDG,I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ACE,GACA,GAC6B;EAC7B,OAAO,IAAIhB,EACT,gBAAgB,mBAAmB8B,CAAO,EAAE,GAAG,mBAAmBC,CAAO,EAAE,SAC3E,KAAK,MACP;CACF;AACF"}
package/dist/state.cjs ADDED
@@ -0,0 +1,2 @@
1
+ const e=require("./exactJson.cjs"),t=require("./http.cjs");var n=class{constructor(e,t={}){this.type=e,this.client=t}async read(e,n={}){let r=n.at instanceof Date?n.at.toISOString():n.at,i=await t.send(this.client,{method:`GET`,path:this.statePath(e),query:{version:n.version,at:r,minVersion:n.minVersion},headers:{[t.WowHeaders.IF_NONE_MATCH]:n.ifNoneMatch===void 0?void 0:`"${n.ifNoneMatch}"`},options:n,notModified:!0});if(i.status===304){let e=t.entityTag(i)??n.ifNoneMatch??``;return{notModified:!0,version:Number.parseInt(e,10),etag:e}}return{notModified:!1,view:await t.json(i,this.stateNumbers),etag:t.entityTag(i)}}async get(e,t={}){let n=await this.read(e,t);if(n.notModified)throw Error(`A read without If-None-Match was answered 304.`);return n.view}async trace(e,n={}){return t.json(await t.send(this.client,{method:`GET`,path:`${this.statePath(e)}/trace`,query:{from:n.from,to:n.to,limit:n.limit},options:n}),this.traceNumbers)}get stateNumbers(){let e=this.type.textNumbers?.state;return e===void 0?void 0:{state:e}}get traceNumbers(){let t=this.type.textNumbers?.state,n=e.eventNumbers(this.type);if(t!==void 0||n!==void 0)return{commits:{"*":{...t===void 0?{}:{state:t},...n===void 0?{}:{events:{"*":n}}}}}}statePath(e){return`/${this.type.context}/${this.type.name}/${encodeURIComponent(e)}/state`}};exports.StateClient=n;
2
+ //# sourceMappingURL=state.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.cjs","names":["send","WowHeaders","entityTag","json","eventNumbers","require_exactJson","require_http","StateClient","type","client","at","options","response","id","etag","result","state","events"],"sources":["../src/state.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n entityTag,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowHeaders,\n} from './http.js';\nimport { eventNumbers, type TextNumbers } from './exactJson.js';\nimport type {\n AggregateType,\n EventView,\n StateTrace,\n StateView,\n} from './wire.js';\n\n/** Which state a read asks for: the latest, at a version or as of a time. */\nexport interface StateReadOptions extends RequestOptions {\n /** The committed state at this version. */\n readonly version?: number;\n /** The committed state as of this instant (ISO-8601, or a `Date`). */\n readonly at?: string | Date;\n /**\n * The latest state at this version or later (review R4-Q, Q-13: read your\n * writes), such as the `version` of a command's result: a lagging snapshot is\n * caught up with the log. Not with `version` or `at`. One not reached within\n * the server's wait rejects with 409 `wow.query.min-version-not-reached`,\n * whose `version` is the current one.\n */\n readonly minVersion?: number;\n /**\n * The entity tag of the state already held, as a read answered it\n * (`etag`): a 304 then answers `notModified`. The tag is the version and a\n * digest of the body (`3-<digest>`), so it changes whenever what is read\n * does, not only with the version.\n */\n readonly ifNoneMatch?: string;\n}\n\n/**\n * A state read: the view and its entity tag, or `notModified` when the state\n * held is current, with its tag and the version the tag names.\n */\nexport type StateReadResult<S> =\n | {\n readonly notModified: false;\n readonly view: StateView<S>;\n readonly etag?: string;\n }\n | {\n readonly notModified: true;\n readonly version: number;\n readonly etag: string;\n };\n\n/** Which commits a trace reads (decision D40). */\nexport interface StateTraceOptions extends RequestOptions {\n /** The first version; 1 when absent. */\n readonly from?: number;\n /** The last version; the latest when absent. */\n readonly to?: number;\n /** The most commits, at most 1000; 100 when absent. */\n readonly limit?: number;\n}\n\n/**\n * Reads an aggregate type's states (decisions D40, D112):\n * `GET /{context}/{aggregate}/{id}/state` with `?version=`, `?at=` or `?minVersion=`, and\n * its trace, `…/state/trace`. A state that does not exist rejects with 404\n * `wow.aggregate.not-found`.\n *\n * @typeParam S - The state's type.\n * @typeParam E - The events' type of a trace.\n */\nexport class StateClient<S = unknown, E extends EventView = EventView> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n readonly client: WowClientOptions = {},\n ) {}\n\n /** The state the options ask for. */\n async read(\n id: string,\n options: StateReadOptions = {},\n ): Promise<StateReadResult<S>> {\n const at =\n options.at instanceof Date ? options.at.toISOString() : options.at;\n const response = await send(this.client, {\n method: 'GET',\n path: this.statePath(id),\n query: { version: options.version, at, minVersion: options.minVersion },\n headers: {\n [WowHeaders.IF_NONE_MATCH]:\n options.ifNoneMatch === undefined\n ? undefined\n : `\"${options.ifNoneMatch}\"`,\n },\n options,\n notModified: true,\n });\n if (response.status === 304) {\n const etag = entityTag(response) ?? options.ifNoneMatch ?? '';\n return {\n notModified: true,\n version: Number.parseInt(etag, 10),\n etag,\n };\n }\n return {\n notModified: false,\n view: await json<StateView<S>>(response, this.stateNumbers),\n etag: entityTag(response),\n };\n }\n\n /** The latest state, or the one the options ask for, without a cache. */\n async get(\n id: string,\n options: Omit<StateReadOptions, 'ifNoneMatch'> = {},\n ): Promise<StateView<S>> {\n const result = await this.read(id, options);\n if (result.notModified) {\n throw new Error('A read without If-None-Match was answered 304.');\n }\n return result.view;\n }\n\n /** The commits from `from` to `to`, each with its events and the state after it. */\n async trace(\n id: string,\n options: StateTraceOptions = {},\n ): Promise<StateTrace<S, E>> {\n return json<StateTrace<S, E>>(\n await send(this.client, {\n method: 'GET',\n path: `${this.statePath(id)}/trace`,\n query: { from: options.from, to: options.to, limit: options.limit },\n options,\n }),\n this.traceNumbers,\n );\n }\n\n /** The exact numbers of a state view: its state's. */\n private get stateNumbers(): TextNumbers | undefined {\n const state = this.type.textNumbers?.state;\n return state === undefined ? undefined : { state };\n }\n\n /** The exact numbers of a trace: each commit's state and events. */\n private get traceNumbers(): TextNumbers | undefined {\n const state = this.type.textNumbers?.state;\n const events = eventNumbers(this.type);\n if (state === undefined && events === undefined) return undefined;\n return {\n commits: {\n '*': {\n ...(state === undefined ? {} : { state }),\n ...(events === undefined ? {} : { events: { '*': events } }),\n },\n },\n };\n }\n\n private statePath(id: string): string {\n return `/${this.type.context}/${this.type.name}/${encodeURIComponent(id)}/state`;\n }\n}\n"],"mappings":"2DAuFA,IAAaO,EAAb,KAAuE,CAKrE,YACE,EACA,EAAoC,CAAC,EACrC,CAFS,KAAA,KAAAC,EACA,KAAA,OAAAC,CACR,CAGH,MAAM,KACJ,EACA,EAA4B,CAAC,EACA,CAC7B,IAAMC,EACJC,EAAQ,cAAc,KAAOA,EAAQ,GAAG,YAAY,EAAIA,EAAQ,GAC5DC,EAAW,MAAMZ,EAAAA,KAAK,KAAK,OAAQ,CACvC,OAAQ,MACR,KAAM,KAAK,UAAUa,CAAE,EACvB,MAAO,CAAE,QAASF,EAAQ,QAAS,KAAI,WAAYA,EAAQ,UAAW,EACtE,QAAS,EACNV,EAAAA,WAAW,eACVU,EAAQ,cAAgB,IAAA,GACpB,IAAA,GACA,IAAIA,EAAQ,YAAY,EAChC,EACA,UACA,YAAa,EACf,CAAC,EACD,GAAIC,EAAS,SAAW,IAAK,CAC3B,IAAME,EAAOZ,EAAAA,UAAUU,CAAQ,GAAKD,EAAQ,aAAe,GAC3D,MAAO,CACL,YAAa,GACb,QAAS,OAAO,SAASG,EAAM,EAAE,EACjC,MACF,CACF,CACA,MAAO,CACL,YAAa,GACb,KAAM,MAAMX,EAAAA,KAAmBS,EAAU,KAAK,YAAY,EAC1D,KAAMV,EAAAA,UAAUU,CAAQ,CAC1B,CACF,CAGA,MAAM,IACJ,EACA,EAAiD,CAAC,EAC3B,CACvB,IAAMG,EAAS,MAAM,KAAK,KAAKF,EAAIF,CAAO,EAC1C,GAAII,EAAO,YACT,MAAU,MAAM,gDAAgD,EAElE,OAAOA,EAAO,IAChB,CAGA,MAAM,MACJ,EACA,EAA6B,CAAC,EACH,CAC3B,OAAOZ,EAAAA,KACL,MAAMH,EAAAA,KAAK,KAAK,OAAQ,CACtB,OAAQ,MACR,KAAM,GAAG,KAAK,UAAUa,CAAE,EAAE,QAC5B,MAAO,CAAE,KAAMF,EAAQ,KAAM,GAAIA,EAAQ,GAAI,MAAOA,EAAQ,KAAM,EAClE,SACF,CAAC,EACD,KAAK,YACP,CACF,CAGA,IAAY,cAAwC,CAClD,IAAMK,EAAQ,KAAK,KAAK,aAAa,MACrC,OAAOA,IAAU,IAAA,GAAY,IAAA,GAAY,CAAE,OAAM,CACnD,CAGA,IAAY,cAAwC,CAClD,IAAMA,EAAQ,KAAK,KAAK,aAAa,MAC/BC,EAASb,EAAAA,aAAa,KAAK,IAAI,EACrC,GAAIY,IAAU,IAAA,IAAaC,IAAW,IAAA,GACtC,MAAO,CACL,QAAS,CACP,IAAK,CACH,GAAID,IAAU,IAAA,GAAY,CAAC,EAAI,CAAE,OAAM,EACvC,GAAIC,IAAW,IAAA,GAAY,CAAC,EAAI,CAAE,OAAQ,CAAE,IAAKA,CAAO,CAAE,CAC5D,CACF,CACF,CACF,CAEA,UAAkB,EAAoB,CACpC,MAAO,IAAI,KAAK,KAAK,QAAQ,GAAG,KAAK,KAAK,KAAK,GAAG,mBAAmBJ,CAAE,EAAE,OAC3E,CACF"}
@@ -6,16 +6,34 @@ export interface StateReadOptions extends RequestOptions {
6
6
  readonly version?: number;
7
7
  /** The committed state as of this instant (ISO-8601, or a `Date`). */
8
8
  readonly at?: string | Date;
9
- /** The version already held: a 304 then answers `notModified`. */
10
- readonly ifNoneMatch?: number;
9
+ /**
10
+ * The latest state at this version or later (review R4-Q, Q-13: read your
11
+ * writes), such as the `version` of a command's result: a lagging snapshot is
12
+ * caught up with the log. Not with `version` or `at`. One not reached within
13
+ * the server's wait rejects with 409 `wow.query.min-version-not-reached`,
14
+ * whose `version` is the current one.
15
+ */
16
+ readonly minVersion?: number;
17
+ /**
18
+ * The entity tag of the state already held, as a read answered it
19
+ * (`etag`): a 304 then answers `notModified`. The tag is the version and a
20
+ * digest of the body (`3-<digest>`), so it changes whenever what is read
21
+ * does, not only with the version.
22
+ */
23
+ readonly ifNoneMatch?: string;
11
24
  }
12
- /** A state read: the view, or `notModified` when the version held is current. */
25
+ /**
26
+ * A state read: the view and its entity tag, or `notModified` when the state
27
+ * held is current, with its tag and the version the tag names.
28
+ */
13
29
  export type StateReadResult<S> = {
14
30
  readonly notModified: false;
15
31
  readonly view: StateView<S>;
32
+ readonly etag?: string;
16
33
  } | {
17
34
  readonly notModified: true;
18
35
  readonly version: number;
36
+ readonly etag: string;
19
37
  };
20
38
  /** Which commits a trace reads (decision D40). */
21
39
  export interface StateTraceOptions extends RequestOptions {
@@ -28,7 +46,7 @@ export interface StateTraceOptions extends RequestOptions {
28
46
  }
29
47
  /**
30
48
  * Reads an aggregate type's states (decisions D40, D112):
31
- * `GET /{context}/{aggregate}/{id}/state` with `?version=` or `?at=`, and
49
+ * `GET /{context}/{aggregate}/{id}/state` with `?version=`, `?at=` or `?minVersion=`, and
32
50
  * its trace, `…/state/trace`. A state that does not exist rejects with 404
33
51
  * `wow.aggregate.not-found`.
34
52
  *
@@ -49,5 +67,9 @@ export declare class StateClient<S = unknown, E extends EventView = EventView> {
49
67
  get(id: string, options?: Omit<StateReadOptions, 'ifNoneMatch'>): Promise<StateView<S>>;
50
68
  /** The commits from `from` to `to`, each with its events and the state after it. */
51
69
  trace(id: string, options?: StateTraceOptions): Promise<StateTrace<S, E>>;
70
+ /** The exact numbers of a state view: its state's. */
71
+ private get stateNumbers();
72
+ /** The exact numbers of a trace: each commit's state and events. */
73
+ private get traceNumbers();
52
74
  private statePath;
53
75
  }
@@ -6,16 +6,34 @@ export interface StateReadOptions extends RequestOptions {
6
6
  readonly version?: number;
7
7
  /** The committed state as of this instant (ISO-8601, or a `Date`). */
8
8
  readonly at?: string | Date;
9
- /** The version already held: a 304 then answers `notModified`. */
10
- readonly ifNoneMatch?: number;
9
+ /**
10
+ * The latest state at this version or later (review R4-Q, Q-13: read your
11
+ * writes), such as the `version` of a command's result: a lagging snapshot is
12
+ * caught up with the log. Not with `version` or `at`. One not reached within
13
+ * the server's wait rejects with 409 `wow.query.min-version-not-reached`,
14
+ * whose `version` is the current one.
15
+ */
16
+ readonly minVersion?: number;
17
+ /**
18
+ * The entity tag of the state already held, as a read answered it
19
+ * (`etag`): a 304 then answers `notModified`. The tag is the version and a
20
+ * digest of the body (`3-<digest>`), so it changes whenever what is read
21
+ * does, not only with the version.
22
+ */
23
+ readonly ifNoneMatch?: string;
11
24
  }
12
- /** A state read: the view, or `notModified` when the version held is current. */
25
+ /**
26
+ * A state read: the view and its entity tag, or `notModified` when the state
27
+ * held is current, with its tag and the version the tag names.
28
+ */
13
29
  export type StateReadResult<S> = {
14
30
  readonly notModified: false;
15
31
  readonly view: StateView<S>;
32
+ readonly etag?: string;
16
33
  } | {
17
34
  readonly notModified: true;
18
35
  readonly version: number;
36
+ readonly etag: string;
19
37
  };
20
38
  /** Which commits a trace reads (decision D40). */
21
39
  export interface StateTraceOptions extends RequestOptions {
@@ -28,7 +46,7 @@ export interface StateTraceOptions extends RequestOptions {
28
46
  }
29
47
  /**
30
48
  * Reads an aggregate type's states (decisions D40, D112):
31
- * `GET /{context}/{aggregate}/{id}/state` with `?version=` or `?at=`, and
49
+ * `GET /{context}/{aggregate}/{id}/state` with `?version=`, `?at=` or `?minVersion=`, and
32
50
  * its trace, `…/state/trace`. A state that does not exist rejects with 404
33
51
  * `wow.aggregate.not-found`.
34
52
  *
@@ -49,5 +67,9 @@ export declare class StateClient<S = unknown, E extends EventView = EventView> {
49
67
  get(id: string, options?: Omit<StateReadOptions, 'ifNoneMatch'>): Promise<StateView<S>>;
50
68
  /** The commits from `from` to `to`, each with its events and the state after it. */
51
69
  trace(id: string, options?: StateTraceOptions): Promise<StateTrace<S, E>>;
70
+ /** The exact numbers of a state view: its state's. */
71
+ private get stateNumbers();
72
+ /** The exact numbers of a trace: each commit's state and events. */
73
+ private get traceNumbers();
52
74
  private statePath;
53
75
  }
@@ -0,0 +1,70 @@
1
+ import { eventNumbers as e } from "./exactJson.es.js";
2
+ import { WowHeaders as t, entityTag as n, json as r, send as i } from "./http.es.js";
3
+ //#region src/state.ts
4
+ var a = class {
5
+ constructor(e, t = {}) {
6
+ this.type = e, this.client = t;
7
+ }
8
+ async read(e, a = {}) {
9
+ let o = a.at instanceof Date ? a.at.toISOString() : a.at, s = await i(this.client, {
10
+ method: "GET",
11
+ path: this.statePath(e),
12
+ query: {
13
+ version: a.version,
14
+ at: o,
15
+ minVersion: a.minVersion
16
+ },
17
+ headers: { [t.IF_NONE_MATCH]: a.ifNoneMatch === void 0 ? void 0 : `"${a.ifNoneMatch}"` },
18
+ options: a,
19
+ notModified: !0
20
+ });
21
+ if (s.status === 304) {
22
+ let e = n(s) ?? a.ifNoneMatch ?? "";
23
+ return {
24
+ notModified: !0,
25
+ version: Number.parseInt(e, 10),
26
+ etag: e
27
+ };
28
+ }
29
+ return {
30
+ notModified: !1,
31
+ view: await r(s, this.stateNumbers),
32
+ etag: n(s)
33
+ };
34
+ }
35
+ async get(e, t = {}) {
36
+ let n = await this.read(e, t);
37
+ if (n.notModified) throw Error("A read without If-None-Match was answered 304.");
38
+ return n.view;
39
+ }
40
+ async trace(e, t = {}) {
41
+ return r(await i(this.client, {
42
+ method: "GET",
43
+ path: `${this.statePath(e)}/trace`,
44
+ query: {
45
+ from: t.from,
46
+ to: t.to,
47
+ limit: t.limit
48
+ },
49
+ options: t
50
+ }), this.traceNumbers);
51
+ }
52
+ get stateNumbers() {
53
+ let e = this.type.textNumbers?.state;
54
+ return e === void 0 ? void 0 : { state: e };
55
+ }
56
+ get traceNumbers() {
57
+ let t = this.type.textNumbers?.state, n = e(this.type);
58
+ if (t !== void 0 || n !== void 0) return { commits: { "*": {
59
+ ...t === void 0 ? {} : { state: t },
60
+ ...n === void 0 ? {} : { events: { "*": n } }
61
+ } } };
62
+ }
63
+ statePath(e) {
64
+ return `/${this.type.context}/${this.type.name}/${encodeURIComponent(e)}/state`;
65
+ }
66
+ };
67
+ //#endregion
68
+ export { a as StateClient };
69
+
70
+ //# sourceMappingURL=state.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.es.js","names":["StateClient","type","client","at","options","response","send","id","WowHeaders","etag","entityTag","json","result","state","events","eventNumbers"],"sources":["../src/state.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n entityTag,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowHeaders,\n} from './http.js';\nimport { eventNumbers, type TextNumbers } from './exactJson.js';\nimport type {\n AggregateType,\n EventView,\n StateTrace,\n StateView,\n} from './wire.js';\n\n/** Which state a read asks for: the latest, at a version or as of a time. */\nexport interface StateReadOptions extends RequestOptions {\n /** The committed state at this version. */\n readonly version?: number;\n /** The committed state as of this instant (ISO-8601, or a `Date`). */\n readonly at?: string | Date;\n /**\n * The latest state at this version or later (review R4-Q, Q-13: read your\n * writes), such as the `version` of a command's result: a lagging snapshot is\n * caught up with the log. Not with `version` or `at`. One not reached within\n * the server's wait rejects with 409 `wow.query.min-version-not-reached`,\n * whose `version` is the current one.\n */\n readonly minVersion?: number;\n /**\n * The entity tag of the state already held, as a read answered it\n * (`etag`): a 304 then answers `notModified`. The tag is the version and a\n * digest of the body (`3-<digest>`), so it changes whenever what is read\n * does, not only with the version.\n */\n readonly ifNoneMatch?: string;\n}\n\n/**\n * A state read: the view and its entity tag, or `notModified` when the state\n * held is current, with its tag and the version the tag names.\n */\nexport type StateReadResult<S> =\n | {\n readonly notModified: false;\n readonly view: StateView<S>;\n readonly etag?: string;\n }\n | {\n readonly notModified: true;\n readonly version: number;\n readonly etag: string;\n };\n\n/** Which commits a trace reads (decision D40). */\nexport interface StateTraceOptions extends RequestOptions {\n /** The first version; 1 when absent. */\n readonly from?: number;\n /** The last version; the latest when absent. */\n readonly to?: number;\n /** The most commits, at most 1000; 100 when absent. */\n readonly limit?: number;\n}\n\n/**\n * Reads an aggregate type's states (decisions D40, D112):\n * `GET /{context}/{aggregate}/{id}/state` with `?version=`, `?at=` or `?minVersion=`, and\n * its trace, `…/state/trace`. A state that does not exist rejects with 404\n * `wow.aggregate.not-found`.\n *\n * @typeParam S - The state's type.\n * @typeParam E - The events' type of a trace.\n */\nexport class StateClient<S = unknown, E extends EventView = EventView> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n readonly client: WowClientOptions = {},\n ) {}\n\n /** The state the options ask for. */\n async read(\n id: string,\n options: StateReadOptions = {},\n ): Promise<StateReadResult<S>> {\n const at =\n options.at instanceof Date ? options.at.toISOString() : options.at;\n const response = await send(this.client, {\n method: 'GET',\n path: this.statePath(id),\n query: { version: options.version, at, minVersion: options.minVersion },\n headers: {\n [WowHeaders.IF_NONE_MATCH]:\n options.ifNoneMatch === undefined\n ? undefined\n : `\"${options.ifNoneMatch}\"`,\n },\n options,\n notModified: true,\n });\n if (response.status === 304) {\n const etag = entityTag(response) ?? options.ifNoneMatch ?? '';\n return {\n notModified: true,\n version: Number.parseInt(etag, 10),\n etag,\n };\n }\n return {\n notModified: false,\n view: await json<StateView<S>>(response, this.stateNumbers),\n etag: entityTag(response),\n };\n }\n\n /** The latest state, or the one the options ask for, without a cache. */\n async get(\n id: string,\n options: Omit<StateReadOptions, 'ifNoneMatch'> = {},\n ): Promise<StateView<S>> {\n const result = await this.read(id, options);\n if (result.notModified) {\n throw new Error('A read without If-None-Match was answered 304.');\n }\n return result.view;\n }\n\n /** The commits from `from` to `to`, each with its events and the state after it. */\n async trace(\n id: string,\n options: StateTraceOptions = {},\n ): Promise<StateTrace<S, E>> {\n return json<StateTrace<S, E>>(\n await send(this.client, {\n method: 'GET',\n path: `${this.statePath(id)}/trace`,\n query: { from: options.from, to: options.to, limit: options.limit },\n options,\n }),\n this.traceNumbers,\n );\n }\n\n /** The exact numbers of a state view: its state's. */\n private get stateNumbers(): TextNumbers | undefined {\n const state = this.type.textNumbers?.state;\n return state === undefined ? undefined : { state };\n }\n\n /** The exact numbers of a trace: each commit's state and events. */\n private get traceNumbers(): TextNumbers | undefined {\n const state = this.type.textNumbers?.state;\n const events = eventNumbers(this.type);\n if (state === undefined && events === undefined) return undefined;\n return {\n commits: {\n '*': {\n ...(state === undefined ? {} : { state }),\n ...(events === undefined ? {} : { events: { '*': events } }),\n },\n },\n };\n }\n\n private statePath(id: string): string {\n return `/${this.type.context}/${this.type.name}/${encodeURIComponent(id)}/state`;\n }\n}\n"],"mappings":";;;AAuFA,IAAaA,IAAb,MAAuE;CAKrE,YACE,GACA,IAAoC,CAAC,GACrC;EADS,AADA,KAAA,OAAAC,GACA,KAAA,SAAAC;CACR;CAGH,MAAM,KACJ,GACA,IAA4B,CAAC,GACA;EAC7B,IAAMC,IACJC,EAAQ,cAAc,OAAOA,EAAQ,GAAG,YAAY,IAAIA,EAAQ,IAC5DC,IAAW,MAAMC,EAAK,KAAK,QAAQ;GACvC,QAAQ;GACR,MAAM,KAAK,UAAUC,CAAE;GACvB,OAAO;IAAE,SAASH,EAAQ;IAAS;IAAI,YAAYA,EAAQ;GAAW;GACtE,SAAS,GACNI,EAAW,gBACVJ,EAAQ,gBAAgB,KAAA,IACpB,KAAA,IACA,IAAIA,EAAQ,YAAY,GAChC;GACA;GACA,aAAa;EACf,CAAC;EACD,IAAIC,EAAS,WAAW,KAAK;GAC3B,IAAMI,IAAOC,EAAUL,CAAQ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.cjs"),t=require("./problem.cjs");let n=require("@ahoo-wang/fetcher-eventstream");var r=`row`,i=`error`,a=`end`,o=`message`;function s(e){return(0,n.toJsonServerSentEventStream)((0,n.toServerSentEventStream)(e)).pipeThrough(new TransformStream({transform(e,t){t.enqueue(e.data)}}))}var c=`hold-expired`,l=`complete`;function u(e,t){return new Promise((n,r)=>{let i=()=>{clearTimeout(a),r(t?.reason)},a=setTimeout(()=>{t?.removeEventListener(`abort`,i),n()},e);t?.addEventListener(`abort`,i)})}function d(e){return new t.WowProblemError(t.isProblem(e)?e:{type:`about:blank`,title:`Query failed`,status:500})}function f(s,f,p={}){let{maxRetries:m=5,initialDelayMs:h=200,maxDelayMs:g=1e4,signal:_}=p,v=p.numbers,y=t=>(e.marksNothing(v)?(0,n.toJsonServerSentEventStream)((0,n.toServerSentEventStream)(t)):(0,n.toServerSentEventStream)(t).pipeThrough(new TransformStream({transform(t,n){let i=t.event===r||t.event===o;n.enqueue({...t,data:e.parseJson(t.data,i?v:void 0)})}}))).getReader(),b=y(s),x=p.lastEventId,S=0,C=0,w=!1;async function T(e,n){for(;;){if(_?.aborted)throw _.reason;if(C++>=m)throw e;let r=n??Math.min(g,h*2**(C-1));r>0&&await u(r,_);try{let e=await f(x,S);return e&&(b=y(e)),e!==void 0}catch(r){if(_?.aborted||r instanceof t.WowProblemError&&!r.retry.retryable)throw r;n=r.retry?.afterMs,e=r}}}return new ReadableStream({async pull(e){for(;;){let n,s;try{let t=await b.read();if(t.done)n=TypeError(`The query stream was cut off.`);else{let{event:u,id:f,data:p}=t.value;if(u===r||u===o){f&&(x=f),S++,C=0,e.enqueue(f?{record:p,position:f}:{record:p});return}if(u===a){let t=p;if(t.reason===l){e.close();return}if(n=TypeError(`The query stream ended: ${t.reason}.`),!t.resumable)throw n;t.reason===c&&(s=0)}else if(u===i){let e=d(p);if(!e.retry.retryable)throw e;n=e,s=e.retry.afterMs}else continue}}catch(e){if(e===n||e instanceof t.WowProblemError)throw e;n=e}if(w)return;if(_?.aborted)throw _.reason;if(x===void 0&&S>0)throw n;if(!await T(n,s)){e.close();return}}},cancel(e){return w=!0,b.cancel(e)}})}exports.commandResults=s,exports.resumableQueryRows=f;
2
+ //# sourceMappingURL=streams.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streams.cjs","names":["toJsonServerSentEventStream","toServerSentEventStream","WowProblemError","isProblem","marksNothing","parseJson","require_exactJson","require_problem","_ahoo_wang_fetcher_eventstream","ROW_EVENT","ERROR_EVENT","END_EVENT","UNNAMED_EVENT","commandResults","response","controller","event","HOLD_EXPIRED","COMPLETE","sleep","abort","timer","reject","signal","resolve","ms","problemOf","data","resumableQueryRows","options","numbers","events","from","row","reader","lastEventId","received","failures","cancelled","resume","maxRetries","cause","wait","delayMs","maxDelayMs","initialDelayMs","next","reopen","error","stop","id","end","reason"],"sources":["../src/streams.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n type JsonServerSentEvent,\n type ServerSentEvent,\n toJsonServerSentEventStream,\n toServerSentEventStream,\n} from '@ahoo-wang/fetcher-eventstream';\nimport { marksNothing, parseJson, type TextNumbers } from './exactJson.js';\nimport type { CommandResult } from './wire.js';\nimport { isProblem, WowProblemError } from './problem.js';\n\n/** The event of each record of a streamed query list. */\nconst ROW_EVENT = 'row';\n\n/** The event that ends a streamed query list that failed: the problem. */\nconst ERROR_EVENT = 'error';\n\n/** The event that ends a resumable streamed query list (decision D253). */\nconst END_EVENT = 'end';\n\n/** The name an event without one is read under. */\nconst UNNAMED_EVENT = 'message';\n\n/**\n * The results of a command's event stream (`Accept: text/event-stream`), one\n * per hop, each event named by its stage. A rejection or a failure after\n * admission is the stream's last result, not an error.\n */\nexport type CommandResultStream<R = Record<string, unknown>> = ReadableStream<\n CommandResult<R>\n>;\n\n/** The data of each event of `response`'s server-sent event stream. */\nexport function commandResults<R>(response: Response): CommandResultStream<R> {\n return toJsonServerSentEventStream<CommandResult<R>>(\n toServerSentEventStream(response),\n ).pipeThrough(\n new TransformStream<\n JsonServerSentEvent<CommandResult<R>>,\n CommandResult<R>\n >({\n transform(event, controller) {\n controller.enqueue(event.data);\n },\n }),\n );\n}\n\n/**\n * Why a resumable streamed list ended (decision D253): `complete` once every\n * record was sent; the others are the server's, and resumable: the stream ran\n * for its hold time, its store had no query permit for its next chunk, or\n * the node is stopping.\n */\nexport type StreamEndReason =\n 'complete' | 'hold-expired' | 'permit-reclaimed' | 'node-stopping';\n\n/** The data of the `end` event that ends a resumable streamed list. */\nexport interface StreamEnd {\n /** Why it ended. */\n readonly reason: StreamEndReason | (string & {});\n /** Whether asking again with `Last-Event-ID` goes on where it ended. */\n readonly resumable: boolean;\n}\n\n/** One record of a streamed list, with its position. */\nexport interface StreamedRow<T> {\n /** The record. */\n readonly record: T;\n /**\n * The record's position, its event's `id`: an opaque cursor token to\n * resume after it ({@link StreamResumeOptions.lastEventId}). Absent from a\n * list whose sort cannot order a cursor, which cannot be resumed.\n */\n readonly position?: string;\n}\n\n/**\n * How a streamed list resumes (decision D253). A stream the server ends with\n * a resumable `end`, one cut off before its `end`, and one that fails with a\n * retryable problem (a 429 after its `Retry-After`) are asked for again with\n * `Last-Event-ID`, the position of the last record read, and go on strictly\n * after it.\n */\nexport interface StreamResumeOptions {\n /** Starts after this position: a {@link StreamedRow.position} read before. */\n readonly lastEventId?: string;\n /**\n * How many times in a row the stream may be resumed without a record in\n * between before it fails with what stopped it; 5 by default, 0 never\n * resumes.\n */\n readonly maxRetries?: number;\n /** The wait before the first such retry, doubled for each next; 200 ms by default. */\n readonly initialDelayMs?: number;\n /** The longest wait between retries; 10 s by default. */\n readonly maxDelayMs?: number;\n}\n\nconst HOLD_EXPIRED: StreamEndReason = 'hold-expired';\nconst COMPLETE: StreamEndReason = 'complete';\n\n/** Waits `ms`, or rejects once `signal` aborts. */\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n const abort = () => {\n clearTimeout(timer);\n reject(signal?.reason);\n };\n const timer = setTimeout(() => {\n signal?.removeEventListener('abort', abort);\n resolve();\n }, ms);\n signal?.addEventListener('abort', abort);\n });\n}\n\nfunction problemOf(data: unknown): WowProblemError {\n return new WowProblemError(\n isProblem(data)\n ? data\n : { type: 'about:blank', title: 'Query failed', status: 500 },\n );\n}\n\n/**\n * The records of a resumable streamed list (decision D253), read from\n * `response` and, each time the stream is to be resumed, from what `reopen`\n * answers for the position of the last record read (none before the first),\n * with how many records were read so far: `undefined` when no more are\n * wanted. Each record comes with its position. An `error` event that is not\n * retryable, a failure `reopen` cannot get past, and an abort of `signal`\n * error the stream.\n *\n * @param response - The first response\n * @param reopen - Asks for the stream again after a position\n * @param options - How the stream resumes, and what cancels it\n */\nexport function resumableQueryRows<T>(\n response: Response,\n reopen: (\n lastEventId: string | undefined,\n received: number,\n ) => Promise<Response | undefined>,\n options: StreamResumeOptions & {\n readonly signal?: AbortSignal;\n /** The numbers of each record read as their exact text (review R4-Q, Q-9). */\n readonly numbers?: TextNumbers;\n } = {},\n): ReadableStream<StreamedRow<T>> {\n const {\n maxRetries = 5,\n initialDelayMs = 200,\n maxDelayMs = 10_000,\n signal,\n } = options;\n const numbers = options.numbers;\n const events = (from: Response) =>\n (marksNothing(numbers)\n ? toJsonServerSentEventStream<unknown>(toServerSentEventStream(from))\n : toServerSentEventStream(from).pipeThrough(\n new TransformStream<ServerSentEvent, JsonServerSentEvent<unknown>>({\n transform(event, controller) {\n const row =\n event.event === ROW_EVENT || event.event === UNNAMED_EVENT;\n controller.enqueue({\n ...event,\n data: parseJson(event.data, row ? numbers : undefined),\n });\n },\n }),\n )\n ).getReader();\n let reader = events(response);\n let lastEventId = options.lastEventId;\n let received = 0;\n let failures = 0;\n // Set once the reader cancels: a read in flight then ends, and must not be\n // taken for a cut-off stream to ask for again.\n let cancelled = false;\n\n /** Asks for the stream again, or throws `cause` once out of retries. */\n async function resume(cause: unknown, delayMs?: number): Promise<boolean> {\n for (;;) {\n if (signal?.aborted) throw signal.reason;\n if (failures++ >= maxRetries) throw cause;\n const wait =\n delayMs ?? Math.min(maxDelayMs, initialDelayMs * 2 ** (failures - 1));\n if (wait > 0) await sleep(wait, signal);\n try {\n const next = await reopen(lastEventId, received);\n if (next) reader = events(next);\n return next !== undefined;\n } catch (error) {\n if (\n signal?.aborted ||\n (error instanceof WowProblemError && !error.retry.retryable)\n ) {\n throw error;\n }\n delayMs = (error as WowProblemError).retry?.afterMs;\n cause = error;\n }\n }\n }\n\n return new ReadableStream<StreamedRow<T>>({\n async pull(controller) {\n for (;;) {\n let stop: unknown;\n let delayMs: number | undefined;\n try {\n const next = await reader.read();\n if (next.done) {\n // Every stream ends with `end`: one without was cut off.\n stop = new TypeError('The query stream was cut off.');\n } else {\n const { event, id, data } = next.value;\n if (event === ROW_EVENT || event === UNNAMED_EVENT) {\n if (id) lastEventId = id;\n received++;\n failures = 0;\n controller.enqueue(\n id\n ? { record: data as T, position: id }\n : { record: data as T },\n );\n return;\n }\n if (event === END_EVENT) {\n const end = data as StreamEnd;\n if (end.reason === COMPLETE) {\n controller.close();\n return;\n }\n stop = new TypeError(`The query stream ended: ${end.reason}.`);\n if (!end.resumable) throw stop;\n if (end.reason === HOLD_EXPIRED) delayMs = 0;\n } else if (event === ERROR_EVENT) {\n const error = problemOf(data);\n if (!error.retry.retryable) throw error;\n stop = error;\n delayMs = error.retry.afterMs;\n } else {\n continue;\n }\n }\n } catch (error) {\n if (error === stop || error instanceof WowProblemError) throw error;\n stop = error;\n }\n if (cancelled) return;\n // Only a stream read from the start, or whose records have positions, can be asked for again.\n if (signal?.aborted) throw signal.reason;\n if (lastEventId === undefined && received > 0) throw stop;\n if (!(await resume(stop, delayMs))) {\n controller.close();\n return;\n }\n }\n },\n cancel(reason) {\n cancelled = true;\n return reader.cancel(reason);\n },\n });\n}\n"],"mappings":"8GAwBA,IAAMS,EAAY,MAGZC,EAAc,QAGdC,EAAY,MAGZC,EAAgB,UAYtB,SAAgBC,EAAkB,EAA4C,CAC5E,OAAA,EAAOb,EAAAA,4BAAAA,EAAAA,EACLC,EAAAA,wBAAAA,CAAwBa,CAAQ,CAClC,CAAC,CAAC,YACA,IAAI,gBAGF,CACA,UAAU,EAAO,EAAY,CAC3BC,EAAW,QAAQC,EAAM,IAAI,CAC/B,CACF,CAAC,CACH,CACF,CAqDA,IAAMC,EAAgC,eAChCC,EAA4B,WAGlC,SAASC,EAAM,EAAY,EAAqC,CAC9D,OAAO,IAAI,SAAS,EAAS,IAAW,CACtC,IAAMC,MAAc,CAClB,aAAaC,CAAK,EAClBC,EAAOC,GAAQ,MAAM,CACvB,EACMF,EAAQ,eAAiB,CAC7BE,GAAQ,oBAAoB,QAASH,CAAK,EAC1CI,EAAQ,CACV,EAAGC,CAAE,EACLF,GAAQ,iBAAiB,QAASH,CAAK,CACzC,CAAC,CACH,CAEA,SAASM,EAAU,EAAgC,CACjD,OAAO,IAAIxB,EAAAA,gBACTC,EAAAA,UAAUwB,CAAI,EACVA,EACA,CAAE,KAAM,cAAe,MAAO,eAAgB,OAAQ,GAAI,CAChE,CACF,CAeA,SAAgBC,EACd,EACA,EAIA,EAII,CAAC,EAC2B,CAChC,GAAM,CACJ,aAAa,EACb,iBAAiB,IACjB,aAAa,IACb,UACEC,EACEC,EAAUD,EAAQ,QAClBE,EAAU,IACb3B,EAAAA,aAAa0B,CAAO,GAAA,EACjB9B,EAAAA,4BAAAA,EAAAA,EAAqCC,EAAAA,wBAAAA,CAAwB+B,CAAI,CAAC,GAAA,EAClE/B,EAAAA,wBAAAA,CAAwB+B,CAA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