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

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 +0,0 @@
1
- {"version":3,"file":"eventStreams.es.js","names":["ROW_EVENT","COMMAND_STAGES","CommandStage","namesStage","data","rowsUntilErrorEvent","isData","event","controller","WowError","isErrorInfo","QueryEventStreamResultExtractor","JsonEventStreamResultExtractor","exchange","CommandResultEventStreamResultExtractor"],"sources":["../../src/transport/eventStreams.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 { ResultExtractor } from '@ahoo-wang/fetcher';\nimport {\n JsonEventStreamResultExtractor,\n type JsonServerSentEvent,\n} from '@ahoo-wang/fetcher-eventstream';\nimport { isErrorInfo, WowError } from '../error/wowError.js';\nimport { type CommandResult, CommandStage } from '../model/command.js';\n\n/**\n * The event name the server gives the rows of a query stream. Wow sends them\n * without an `event:` field, which the event-stream parser reads as\n * `message`.\n */\nconst ROW_EVENT = 'message';\n\nconst COMMAND_STAGES: ReadonlySet<string> = new Set(\n Object.values(CommandStage),\n);\n\n/** True when the data is a command result: it names the stage it reports. */\nfunction namesStage(data: unknown): boolean {\n return (\n typeof data === 'object' &&\n data !== null &&\n typeof (data as { stage?: unknown }).stage === 'string'\n );\n}\n\n/**\n * Unwraps the events `isData` accepts to their data, and errors the stream\n * with a `WowError` at the first one it does not.\n *\n * Wow's `event`, `id` and `retry` fields carry nothing an application reads:\n * a query row always arrives as `message`, a command result names its stage\n * in `stage`, and Wow does not resume a stream. So the stream a client\n * answers is the rows themselves.\n *\n * When a server-sent event stream fails midway, Wow still answers HTTP 200\n * and sends one last event whose name is the error code and whose data is\n * the `ErrorInfo`, then closes the stream (`WebFluxResponseStrategy`,\n * `errorResume`). Read as data it would pass for a row or a command result;\n * here it ends the stream the way a failed request ends a call.\n */\nfunction rowsUntilErrorEvent<T>(\n isData: (event: JsonServerSentEvent<unknown>) => boolean,\n): TransformStream<JsonServerSentEvent<unknown>, T> {\n return new TransformStream({\n transform(event, controller) {\n if (isData(event)) {\n controller.enqueue(event.data as T);\n return;\n }\n controller.error(\n new WowError(\n isErrorInfo(event.data)\n ? event.data\n : { errorCode: event.event, errorMsg: '' },\n ),\n );\n },\n });\n}\n\n/**\n * Internal: applications and generated code take the two extractors below\n * through the endpoint presets `QUERY_STREAM_ENDPOINT` and\n * `COMMAND_STREAM_ENDPOINT` (`endpoints.ts`); this file is not re-exported.\n *\n * The result extractor of the query streams (`listStream`,\n * `listStateStream`, `aggregateStream`, `loadStream`): the response as a\n * stream of rows, one per server-sent event, which errors with a\n * {@link WowError} when the server sends an error event.\n */\nexport const QueryEventStreamResultExtractor: ResultExtractor<\n ReadableStream<unknown>\n> = async exchange =>\n (await JsonEventStreamResultExtractor(exchange)).pipeThrough(\n rowsUntilErrorEvent(event => event.event === ROW_EVENT),\n );\n\n/**\n * The result extractor of `sendAndWaitStream`: the command results, one per\n * stage the command reached, which errors with a {@link WowError} when the\n * server sends an error event. A command result whose own `errorCode` is not\n * `Ok` is still a result — the command failed in its processing — and is\n * passed on as one. So is a result from a stage this version does not know:\n * a command result names its stage in `stage`, the error event's `ErrorInfo`\n * does not, so a newer server's stage is not read as an error.\n *\n * Generated command clients take it through `COMMAND_STREAM_ENDPOINT`.\n */\nexport const CommandResultEventStreamResultExtractor: ResultExtractor<\n ReadableStream<CommandResult>\n> = async exchange =>\n (await JsonEventStreamResultExtractor(exchange)).pipeThrough(\n rowsUntilErrorEvent<CommandResult>(\n event => COMMAND_STAGES.has(event.event) || namesStage(event.data),\n ),\n );\n"],"mappings":";;;;AA0BA,IAAMA,IAAY,WAEZC,IAAsC,IAAI,IAC9C,OAAO,OAAOC,CAAY,CAC5B;AAGA,SAASC,EAAW,GAAwB;CAC1C,OACE,OAAOC,KAAS,cAChBA,KACA,OAAQA,EAA6B,SAAU;AAEnD;AAiBA,SAASC,EACP,GACkD;CAClD,OAAO,IAAI,gBAAgB,EACzB,UAAU,GAAO,GAAY;EAC3B,AAAIC,EAAOC,CAAK,IACdC,EAAW,QAAQD,EAAM,IAAS,IAGpCC,EAAW,MACT,IAAIC,EACFC,EAAYH,EAAM,IAAI,IAClBA,EAAM,OACN;GAAE,WAAWA,EAAM;GAAO,UAAU;EAAG,CAC7C,CACF;CACF,EACF,CAAC;AACH;AAYA,IAAaI,IAET,OAAM,OACP,MAAMC,EAA+BC,CAAQ,EAAA,CAAG,YAC/CR,GAAoB,MAASE,EAAM,UAAUP,CAAS,CACxD,GAaWc,IAET,OAAM,OACP,MAAMF,EAA+BC,CAAQ,EAAA,CAAG,YAC/CR,GACE,MAASJ,EAAe,IAAIM,EAAM,KAAK,KAAKJ,EAAWI,EAAM,IAAI,CACnE,CACF"}
@@ -1 +0,0 @@
1
- export * from './endpoints.cjs';
@@ -1 +0,0 @@
1
- export * from './endpoints.js';
@@ -1,2 +0,0 @@
1
- const e=require("./problem.cjs"),t=require("./http.cjs"),n=require("./streams.cjs"),r=require("./wait.cjs");var i={DELETE_AGGREGATE:`wow.lifecycle.DeleteAggregate`,RESTORE_AGGREGATE:`wow.lifecycle.RestoreAggregate`,TRANSFER_OWNER:`wow.lifecycle.TransferOwner`,TRANSFER_SPACE:`wow.lifecycle.TransferSpace`,APPLY_TAGS:`wow.lifecycle.ApplyTags`};function a(e){return e.replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/[_\s]+/g,`-`).toLowerCase()}function o(e,n){let i=e.wait;return{[t.WowV10Headers.REQUEST_ID]:e.requestId,[t.WowV10Headers.WAIT]:i?.plan===void 0?void 0:r.formatWaitPlan(i.plan),[t.WowV10Headers.WAIT_TIMEOUT]:i?.timeout===void 0?void 0:r.formatWaitTimeout(i.timeout),[t.WowV10Headers.IF_MATCH]:e.expectedVersion===void 0?void 0:`"${e.expectedVersion}"`,Accept:n}}var s=class{constructor(e={}){this.client=e}async send(n,r,i={}){try{let e=await this.post(n,r,i);return await t.json(e)}catch(t){if(i.resolveRejected&&t instanceof e.WowProblemError&&t.result!==void 0)return t.result;throw t}}async stream(e,t,r={}){return n.commandResults(await this.post(e,t,r,`text/event-stream`))}async lifecycle(e,n,r,s,c={}){let l=`${e}/${encodeURIComponent(n)}`;if(r===i.DELETE_AGGREGATE){let e=await t.send(this.client,{method:`DELETE`,path:l,headers:o(c),options:c});return t.json(e)}return this.send(`${l}/${a(r)}`,s??{},c)}post(e,n,r,i){return t.send(this.client,{method:`POST`,path:e.includes(`{id}`)?t.expandPath(e,{id:r.id??``}):e,headers:o(r,i),body:n??{},options:r})}};exports.CommandGateway=s,exports.LifecycleCommands=i,exports.commandSegment=a;
2
- //# sourceMappingURL=commands.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"commands.cjs","names":["WowV10Headers","formatWaitPlan","formatWaitTimeout","json","WowProblemError","commandResults","send","expandPath","require_problem","require_http","require_streams","require_wait","LifecycleCommands","commandSegment","name","commandHeaders","wait","options","accept","CommandGateway","client","response","path","body","error","base","aggregatePath","id","command"],"sources":["../../src/v10/commands.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 expandPath,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowV10Headers,\n} from './http.js';\nimport type { CommandResult } from './wire.js';\nimport { WowProblemError } from './problem.js';\nimport { commandResults, type CommandResultStream } from './streams.js';\nimport { formatWaitPlan, formatWaitTimeout, type WaitOptions } from './wait.js';\n\n/** What a command request carries beside its body (decisions D95–D99). */\nexport interface CommandOptions extends RequestOptions {\n /**\n * The request id (`Wow-Request-Id`): a retry with the same one is\n * deduplicated, answered as the first commit's duplicate.\n */\n readonly requestId?: string;\n /** What to wait for, and for how long. */\n readonly wait?: WaitOptions;\n /** The version the aggregate must be at (`If-Match`). */\n readonly expectedVersion?: number;\n /**\n * Resolve a result that did not succeed instead of rejecting with its\n * {@link WowProblemError}; `false` by default.\n */\n readonly resolveRejected?: boolean;\n}\n\n/** The options of a command whose route may name the aggregate id or not. */\nexport interface CreateCommandOptions extends CommandOptions {\n /**\n * The id of the aggregate to create (decision D176); the service generates\n * one when absent.\n */\n readonly id?: string;\n}\n\n/** The lifecycle commands an aggregate may list (decision D113). */\nexport const LifecycleCommands = {\n DELETE_AGGREGATE: 'wow.lifecycle.DeleteAggregate',\n RESTORE_AGGREGATE: 'wow.lifecycle.RestoreAggregate',\n TRANSFER_OWNER: 'wow.lifecycle.TransferOwner',\n TRANSFER_SPACE: 'wow.lifecycle.TransferSpace',\n APPLY_TAGS: 'wow.lifecycle.ApplyTags',\n} as const;\n\n/** A {@link LifecycleCommands} value. */\nexport type LifecycleCommand =\n (typeof LifecycleCommands)[keyof typeof LifecycleCommands];\n\n/** The body of `wow.lifecycle.TransferOwner`. */\nexport interface TransferOwner {\n readonly ownerId: string;\n}\n\n/** The body of `wow.lifecycle.TransferSpace`. */\nexport interface TransferSpace {\n readonly spaceId: string;\n}\n\n/** The body of `wow.lifecycle.ApplyTags`: the tags, names to values. */\nexport interface ApplyTags {\n readonly tags: Readonly<Record<string, readonly string[]>>;\n}\n\n/**\n * The route segment of a command name, as the server derives it: kebab case,\n * dots kept (`AddCartItem` → `add-cart-item`,\n * `wow.lifecycle.RestoreAggregate` → `wow.lifecycle.restore-aggregate`).\n *\n * @param name - The command's name\n */\nexport function commandSegment(name: string): string {\n return name\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')\n .replace(/([a-z0-9])([A-Z])/g, '$1-$2')\n .replace(/[_\\s]+/g, '-')\n .toLowerCase();\n}\n\nfunction commandHeaders(\n options: CommandOptions,\n accept?: string,\n): Record<string, string | undefined> {\n const wait = options.wait;\n return {\n [WowV10Headers.REQUEST_ID]: options.requestId,\n [WowV10Headers.WAIT]:\n wait?.plan === undefined ? undefined : formatWaitPlan(wait.plan),\n [WowV10Headers.WAIT_TIMEOUT]:\n wait?.timeout === undefined ? undefined : formatWaitTimeout(wait.timeout),\n [WowV10Headers.IF_MATCH]:\n options.expectedVersion === undefined\n ? undefined\n : `\"${options.expectedVersion}\"`,\n Accept: accept,\n };\n}\n\n/**\n * Sends commands to the command routes of a Wow V10 service\n * (`POST /{context}/{aggregate}/{id}/{command}`, and without `{id}` for a\n * command that may create its aggregate). Generated aggregate clients build\n * on it; it serves any route too.\n *\n * A command that did not succeed rejects with a {@link WowProblemError}\n * holding its result, unless the options resolve it.\n */\nexport class CommandGateway {\n /** @param client - How the service is reached */\n constructor(readonly client: WowClientOptions = {}) {}\n\n /**\n * Sends a command and answers the result its wait ends with: 200, or 202\n * for a plan that ends at `accepted`.\n *\n * @param path - The route, `{id}` filled from `id`\n * @param body - The command's body; `{}` when absent\n * @param options - Headers, wait and the aggregate id\n */\n async send<R = Record<string, unknown>>(\n path: string,\n body?: object,\n options: CreateCommandOptions = {},\n ): Promise<CommandResult<R>> {\n try {\n const response = await this.post(path, body, options);\n return await json<CommandResult<R>>(response);\n } catch (error) {\n if (\n options.resolveRejected &&\n error instanceof WowProblemError &&\n error.result !== undefined\n ) {\n return error.result as CommandResult<R>;\n }\n throw error;\n }\n }\n\n /**\n * Sends a command with `Accept: text/event-stream` and answers one result\n * per hop as the wait advances. An admission refusal rejects with its\n * problem; a rejection after admission is the stream's last result.\n *\n * @param path - The route, `{id}` filled from `id`\n * @param body - The command's body; `{}` when absent\n * @param options - Headers, wait and the aggregate id\n */\n async stream<R = Record<string, unknown>>(\n path: string,\n body?: object,\n options: CreateCommandOptions = {},\n ): Promise<CommandResultStream<R>> {\n return commandResults<R>(\n await this.post(path, body, options, 'text/event-stream'),\n );\n }\n\n /**\n * Sends a lifecycle command an aggregate lists: `DELETE\n * /{context}/{aggregate}/{id}` for `DeleteAggregate`, `POST\n * …/{id}/wow.lifecycle.<kebab>` for the others.\n *\n * @param aggregatePath - `/{context}/{aggregate}`\n * @param id - The aggregate's id\n * @param command - The lifecycle command\n * @param body - Its body, for the commands that have one\n * @param options - Headers and wait\n */\n async lifecycle<R = Record<string, unknown>>(\n aggregatePath: string,\n id: string,\n command: LifecycleCommand,\n body?: TransferOwner | TransferSpace | ApplyTags,\n options: CommandOptions = {},\n ): Promise<CommandResult<R>> {\n const base = `${aggregatePath}/${encodeURIComponent(id)}`;\n if (command === LifecycleCommands.DELETE_AGGREGATE) {\n const response = await send(this.client, {\n method: 'DELETE',\n path: base,\n headers: commandHeaders(options),\n options,\n });\n return json<CommandResult<R>>(response);\n }\n return this.send<R>(\n `${base}/${commandSegment(command)}`,\n body ?? {},\n options,\n );\n }\n\n private post(\n path: string,\n body: object | undefined,\n options: CreateCommandOptions,\n accept?: string,\n ): Promise<Response> {\n return send(this.client, {\n method: 'POST',\n path: path.includes('{id}')\n ? expandPath(path, { id: options.id ?? '' })\n : path,\n headers: commandHeaders(options, accept),\n body: body ?? {},\n options,\n });\n }\n}\n"],"mappings":"4GAsDA,IAAaY,EAAoB,CAC/B,iBAAkB,gCAClB,kBAAmB,iCACnB,eAAgB,8BAChB,eAAgB,8BAChB,WAAY,yBACd,EA4BA,SAAgBC,EAAe,EAAsB,CACnD,OAAOC,EACJ,QAAQ,wBAAyB,OAAO,CAAC,CACzC,QAAQ,qBAAsB,OAAO,CAAC,CACtC,QAAQ,UAAW,GAAG,CAAC,CACvB,YAAY,CACjB,CAEA,SAASC,EACP,EACA,EACoC,CACpC,IAAMC,EAAOC,EAAQ,KACrB,MAAO,EACJjB,EAAAA,cAAc,YAAaiB,EAAQ,WACnCjB,EAAAA,cAAc,MACbgB,GAAM,OAAS,IAAA,GAAY,IAAA,GAAYf,EAAAA,eAAee,EAAK,IAAI,GAChEhB,EAAAA,cAAc,cACbgB,GAAM,UAAY,IAAA,GAAY,IAAA,GAAYd,EAAAA,kBAAkBc,EAAK,OAAO,GACzEhB,EAAAA,cAAc,UACbiB,EAAQ,kBAAoB,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,EACf,SACF,CAAC,CACH,CACF"}
@@ -1,68 +0,0 @@
1
- import { WowProblemError as e } from "./problem.es.js";
2
- import { WowV10Headers as t, expandPath as n, json as r, send as i } from "./http.es.js";
3
- import { commandResults as a } from "./streams.es.js";
4
- import { formatWaitPlan as o, formatWaitTimeout as s } from "./wait.es.js";
5
- //#region src/v10/commands.ts
6
- var c = {
7
- DELETE_AGGREGATE: "wow.lifecycle.DeleteAggregate",
8
- RESTORE_AGGREGATE: "wow.lifecycle.RestoreAggregate",
9
- TRANSFER_OWNER: "wow.lifecycle.TransferOwner",
10
- TRANSFER_SPACE: "wow.lifecycle.TransferSpace",
11
- APPLY_TAGS: "wow.lifecycle.ApplyTags"
12
- };
13
- function l(e) {
14
- return e.replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase();
15
- }
16
- function u(e, n) {
17
- let r = e.wait;
18
- return {
19
- [t.REQUEST_ID]: e.requestId,
20
- [t.WAIT]: r?.plan === void 0 ? void 0 : o(r.plan),
21
- [t.WAIT_TIMEOUT]: r?.timeout === void 0 ? void 0 : s(r.timeout),
22
- [t.IF_MATCH]: e.expectedVersion === void 0 ? void 0 : `"${e.expectedVersion}"`,
23
- Accept: n
24
- };
25
- }
26
- var d = class {
27
- constructor(e = {}) {
28
- this.client = e;
29
- }
30
- async send(t, n, i = {}) {
31
- try {
32
- let e = await this.post(t, n, i);
33
- return await r(e);
34
- } catch (t) {
35
- if (i.resolveRejected && t instanceof e && t.result !== void 0) return t.result;
36
- throw t;
37
- }
38
- }
39
- async stream(e, t, n = {}) {
40
- return a(await this.post(e, t, n, "text/event-stream"));
41
- }
42
- async lifecycle(e, t, n, a, o = {}) {
43
- let s = `${e}/${encodeURIComponent(t)}`;
44
- if (n === c.DELETE_AGGREGATE) {
45
- let e = await i(this.client, {
46
- method: "DELETE",
47
- path: s,
48
- headers: u(o),
49
- options: o
50
- });
51
- return r(e);
52
- }
53
- return this.send(`${s}/${l(n)}`, a ?? {}, o);
54
- }
55
- post(e, t, r, a) {
56
- return i(this.client, {
57
- method: "POST",
58
- path: e.includes("{id}") ? n(e, { id: r.id ?? "" }) : e,
59
- headers: u(r, a),
60
- body: t ?? {},
61
- options: r
62
- });
63
- }
64
- };
65
- //#endregion
66
- export { d as CommandGateway, c as LifecycleCommands, l as commandSegment };
67
-
68
- //# sourceMappingURL=commands.es.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"commands.es.js","names":["LifecycleCommands","commandSegment","name","commandHeaders","wait","options","WowV10Headers","formatWaitPlan","formatWaitTimeout","accept","CommandGateway","client","response","path","body","json","error","WowProblemError","commandResults","base","aggregatePath","id","command","send","expandPath"],"sources":["../../src/v10/commands.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 expandPath,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowV10Headers,\n} from './http.js';\nimport type { CommandResult } from './wire.js';\nimport { WowProblemError } from './problem.js';\nimport { commandResults, type CommandResultStream } from './streams.js';\nimport { formatWaitPlan, formatWaitTimeout, type WaitOptions } from './wait.js';\n\n/** What a command request carries beside its body (decisions D95–D99). */\nexport interface CommandOptions extends RequestOptions {\n /**\n * The request id (`Wow-Request-Id`): a retry with the same one is\n * deduplicated, answered as the first commit's duplicate.\n */\n readonly requestId?: string;\n /** What to wait for, and for how long. */\n readonly wait?: WaitOptions;\n /** The version the aggregate must be at (`If-Match`). */\n readonly expectedVersion?: number;\n /**\n * Resolve a result that did not succeed instead of rejecting with its\n * {@link WowProblemError}; `false` by default.\n */\n readonly resolveRejected?: boolean;\n}\n\n/** The options of a command whose route may name the aggregate id or not. */\nexport interface CreateCommandOptions extends CommandOptions {\n /**\n * The id of the aggregate to create (decision D176); the service generates\n * one when absent.\n */\n readonly id?: string;\n}\n\n/** The lifecycle commands an aggregate may list (decision D113). */\nexport const LifecycleCommands = {\n DELETE_AGGREGATE: 'wow.lifecycle.DeleteAggregate',\n RESTORE_AGGREGATE: 'wow.lifecycle.RestoreAggregate',\n TRANSFER_OWNER: 'wow.lifecycle.TransferOwner',\n TRANSFER_SPACE: 'wow.lifecycle.TransferSpace',\n APPLY_TAGS: 'wow.lifecycle.ApplyTags',\n} as const;\n\n/** A {@link LifecycleCommands} value. */\nexport type LifecycleCommand =\n (typeof LifecycleCommands)[keyof typeof LifecycleCommands];\n\n/** The body of `wow.lifecycle.TransferOwner`. */\nexport interface TransferOwner {\n readonly ownerId: string;\n}\n\n/** The body of `wow.lifecycle.TransferSpace`. */\nexport interface TransferSpace {\n readonly spaceId: string;\n}\n\n/** The body of `wow.lifecycle.ApplyTags`: the tags, names to values. */\nexport interface ApplyTags {\n readonly tags: Readonly<Record<string, readonly string[]>>;\n}\n\n/**\n * The route segment of a command name, as the server derives it: kebab case,\n * dots kept (`AddCartItem` → `add-cart-item`,\n * `wow.lifecycle.RestoreAggregate` → `wow.lifecycle.restore-aggregate`).\n *\n * @param name - The command's name\n */\nexport function commandSegment(name: string): string {\n return name\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')\n .replace(/([a-z0-9])([A-Z])/g, '$1-$2')\n .replace(/[_\\s]+/g, '-')\n .toLowerCase();\n}\n\nfunction commandHeaders(\n options: CommandOptions,\n accept?: string,\n): Record<string, string | undefined> {\n const wait = options.wait;\n return {\n [WowV10Headers.REQUEST_ID]: options.requestId,\n [WowV10Headers.WAIT]:\n wait?.plan === undefined ? undefined : formatWaitPlan(wait.plan),\n [WowV10Headers.WAIT_TIMEOUT]:\n wait?.timeout === undefined ? undefined : formatWaitTimeout(wait.timeout),\n [WowV10Headers.IF_MATCH]:\n options.expectedVersion === undefined\n ? undefined\n : `\"${options.expectedVersion}\"`,\n Accept: accept,\n };\n}\n\n/**\n * Sends commands to the command routes of a Wow V10 service\n * (`POST /{context}/{aggregate}/{id}/{command}`, and without `{id}` for a\n * command that may create its aggregate). Generated aggregate clients build\n * on it; it serves any route too.\n *\n * A command that did not succeed rejects with a {@link WowProblemError}\n * holding its result, unless the options resolve it.\n */\nexport class CommandGateway {\n /** @param client - How the service is reached */\n constructor(readonly client: WowClientOptions = {}) {}\n\n /**\n * Sends a command and answers the result its wait ends with: 200, or 202\n * for a plan that ends at `accepted`.\n *\n * @param path - The route, `{id}` filled from `id`\n * @param body - The command's body; `{}` when absent\n * @param options - Headers, wait and the aggregate id\n */\n async send<R = Record<string, unknown>>(\n path: string,\n body?: object,\n options: CreateCommandOptions = {},\n ): Promise<CommandResult<R>> {\n try {\n const response = await this.post(path, body, options);\n return await json<CommandResult<R>>(response);\n } catch (error) {\n if (\n options.resolveRejected &&\n error instanceof WowProblemError &&\n error.result !== undefined\n ) {\n return error.result as CommandResult<R>;\n }\n throw error;\n }\n }\n\n /**\n * Sends a command with `Accept: text/event-stream` and answers one result\n * per hop as the wait advances. An admission refusal rejects with its\n * problem; a rejection after admission is the stream's last result.\n *\n * @param path - The route, `{id}` filled from `id`\n * @param body - The command's body; `{}` when absent\n * @param options - Headers, wait and the aggregate id\n */\n async stream<R = Record<string, unknown>>(\n path: string,\n body?: object,\n options: CreateCommandOptions = {},\n ): Promise<CommandResultStream<R>> {\n return commandResults<R>(\n await this.post(path, body, options, 'text/event-stream'),\n );\n }\n\n /**\n * Sends a lifecycle command an aggregate lists: `DELETE\n * /{context}/{aggregate}/{id}` for `DeleteAggregate`, `POST\n * …/{id}/wow.lifecycle.<kebab>` for the others.\n *\n * @param aggregatePath - `/{context}/{aggregate}`\n * @param id - The aggregate's id\n * @param command - The lifecycle command\n * @param body - Its body, for the commands that have one\n * @param options - Headers and wait\n */\n async lifecycle<R = Record<string, unknown>>(\n aggregatePath: string,\n id: string,\n command: LifecycleCommand,\n body?: TransferOwner | TransferSpace | ApplyTags,\n options: CommandOptions = {},\n ): Promise<CommandResult<R>> {\n const base = `${aggregatePath}/${encodeURIComponent(id)}`;\n if (command === LifecycleCommands.DELETE_AGGREGATE) {\n const response = await send(this.client, {\n method: 'DELETE',\n path: base,\n headers: commandHeaders(options),\n options,\n });\n return json<CommandResult<R>>(response);\n }\n return this.send<R>(\n `${base}/${commandSegment(command)}`,\n body ?? {},\n options,\n );\n }\n\n private post(\n path: string,\n body: object | undefined,\n options: CreateCommandOptions,\n accept?: string,\n ): Promise<Response> {\n return send(this.client, {\n method: 'POST',\n path: path.includes('{id}')\n ? expandPath(path, { id: options.id ?? '' })\n : path,\n headers: commandHeaders(options, accept),\n body: body ?? {},\n options,\n });\n }\n}\n"],"mappings":";;;;;AAsDA,IAAaA,IAAoB;CAC/B,kBAAkB;CAClB,mBAAmB;CACnB,gBAAgB;CAChB,gBAAgB;CAChB,YAAY;AACd;AA4BA,SAAgBC,EAAe,GAAsB;CACnD,OAAOC,EACJ,QAAQ,yBAAyB,OAAO,CAAC,CACzC,QAAQ,sBAAsB,OAAO,CAAC,CACtC,QAAQ,WAAW,GAAG,CAAC,CACvB,YAAY;AACjB;AAEA,SAASC,EACP,GACA,GACoC;CACpC,IAAMC,IAAOC,EAAQ;CACrB,OAAO;GACJC,EAAc,aAAaD,EAAQ;GACnCC,EAAc,OACbF,GAAM,SAAS,KAAA,IAAY,KAAA,IAAYG,EAAeH,EAAK,IAAI;GAChEE,EAAc,eACbF,GAAM,YAAY,KAAA,IAAY,KAAA,IAAYI,EAAkBJ,EAAK,OAAO;GACzEE,EAAc,WACbD,EAAQ,oBAAoB,KAAA,IACxB,KAAA,IACA,IAAIA,EAAQ,gBAAgB;EAClC,QAAQI;CACV;AACF;AAWA,IAAaC,IAAb,MAA4B;CAE1B,YAAY,IAAoC,CAAC,GAAG;EAA/B,KAAA,SAAAC;CAAgC;CAUrD,MAAM,KACJ,GACA,GACA,IAAgC,CAAC,GACN;EAC3B,IAAI;GACF,IAAMC,IAAW,MAAM,KAAK,KAAKC,GAAMC,GAAMT,CAAO;GACpD,OAAO,MAAMU,EAAuBH,CAAQ;EAC9C,SAASI,GAAO;GACd,IACEX,EAAQ,mBACRW,aAAiBC,KACjBD,EAAM,WAAW,KAAA,GAEjB,OAAOA,EAAM;GAEf,MAAMA;EACR;CACF;CAWA,MAAM,OACJ,GACA,GACA,IAAgC,CAAC,GACA;EACjC,OAAOE,EACL,MAAM,KAAK,KAAKL,GAAMC,GAAMT,GAAS,mBAAmB,CAC1D;CACF;CAaA,MAAM,UACJ,GACA,GACA,GACA,GACA,IAA0B,CAAC,GACA;EAC3B,IAAMc,IAAO,GAAGC,EAAc,GAAG,mBAAmBC,CAAE;EACtD,IAAIC,MAAYtB,EAAkB,kBAAkB;GAClD,IAAMY,IAAW,MAAMW,EAAK,KAAK,QAAQ;IACvC,QAAQ;IACR,MAAMJ;IACN,SAAShB,EAAeE,CAAO;IAC/B;GACF,CAAC;GACD,OAAOU,EAAuBH,CAAQ;EACxC;EACA,OAAO,KAAK,KACV,GAAGO,EAAK,GAAGlB,EAAeqB,CAAO,KACjCR,KAAQ,CAAC,GACTT,CACF;CACF;CAEA,KACE,GACA,GACA,GACA,GACmB;EACnB,OAAOkB,EAAK,KAAK,QAAQ;GACvB,QAAQ;GACR,MAAMV,EAAK,SAAS,MAAM,IACtBW,EAAWX,GAAM,EAAE,IAAIR,EAAQ,MAAM,GAAG,CAAC,IACzCQ;GACJ,SAASV,EAAeE,GAASI,CAAM;GACvC,MAAMK,KAAQ,CAAC;GACf;EACF,CAAC;CACH;AACF"}
package/dist/v10/http.cjs DELETED
@@ -1,2 +0,0 @@
1
- const e=require("./problem.cjs");let t=require("@ahoo-wang/fetcher");var n={REQUEST_ID:`Wow-Request-Id`,WAIT:`Wow-Wait`,WAIT_TIMEOUT:`Wow-Wait-Timeout`,SCOPE:`Wow-Scope`,SPACE:`Wow-Space`,IF_MATCH:`If-Match`,IF_NONE_MATCH:`If-None-Match`,ETAG:`ETag`,RETRY_AFTER:`Retry-After`};function r(e){return`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}"`}function i(e){let t=[e.tenantId===void 0?void 0:`tenant=${r(e.tenantId)}`,e.ownerId===void 0?void 0:`owner=${r(e.ownerId)}`,e.spaceId===void 0?void 0:`space=${r(e.spaceId)}`].filter(e=>e!==void 0);if(t.length===0)throw TypeError(`Wow-Scope names a tenant, an owner or a space.`);return t.join(`, `)}function a(e,t){return e.replace(/\{([^}]+)\}/g,(n,r)=>{let i=t[r];if(i===void 0||i===``)throw TypeError(`The path ${e} needs ${r}.`);return encodeURIComponent(i)})}function o(e){if(!e)return``;let t=new URLSearchParams;for(let[n,r]of Object.entries(e))r!==void 0&&t.append(n,String(r));let n=t.toString();return n?`?${n}`:``}async function s(r,a){let s=a.options??{},c={};for(let[e,t]of Object.entries({...a.headers,...s.scope===void 0?{}:{[n.SCOPE]:i(s.scope)},...s.space===void 0?{}:{[n.SPACE]:s.space},...s.headers}))t!==void 0&&(c[e]=t);let l=`${r.basePath??``}${a.path}${o(a.query)}`;try{return await(r.fetcher??t.fetcher).fetch(l,{method:a.method,headers:c,...a.body===void 0?{}:{body:a.body},...s.signal===void 0?{}:{signal:s.signal}})}catch(t){let n=t?.exchange?.response;if(a.notModified&&n?.status===304)return n;throw await e.toWowProblemError(t)??t}}async function c(e){return await e.json()}function l(e){let t=e.headers.get(n.ETAG);return t===null?void 0:t.replace(/^W\//,``).replace(/"/g,``)}exports.WowV10Headers=n,exports.entityTag=l,exports.expandPath=a,exports.formatScope=i,exports.json=c,exports.send=s;
2
- //# sourceMappingURL=http.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.cjs","names":["defaultFetcher","toWowProblemError","require_problem","_ahoo_wang_fetcher","WowV10Headers","quote","value","formatScope","members","scope","member","expandPath","path","params","name","queryString","query","text","send","options","call","headers","url","client","error","response","json","entityTag","tag"],"sources":["../../src/v10/http.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 Fetcher, fetcher as defaultFetcher } from '@ahoo-wang/fetcher';\nimport { toWowProblemError } from './problem.js';\n\n/**\n * The request headers of a Wow V10 service's public port (decisions D95,\n * D96, D98, D99).\n */\nexport const WowV10Headers = {\n /** The caller's id of the request: a retry with the same one is deduplicated. */\n REQUEST_ID: 'Wow-Request-Id',\n /** The wait plan (decision D99). */\n WAIT: 'Wow-Wait',\n /** How long to wait: `500ms`, `10s` or an ISO-8601 duration. */\n WAIT_TIMEOUT: 'Wow-Wait-Timeout',\n /** The scope to act in, for a caller allowed to act across scopes (decision D95). */\n SCOPE: 'Wow-Scope',\n /** The space, among the caller's own, to act in (decision D96). */\n SPACE: 'Wow-Space',\n /** The expected version of the aggregate, as an entity tag. */\n IF_MATCH: 'If-Match',\n /** The version, or descriptor version, a read already holds. */\n IF_NONE_MATCH: 'If-None-Match',\n /** The version of a state read, or of a query descriptor. */\n ETAG: 'ETag',\n /** The seconds after which a failed request may be retried. */\n RETRY_AFTER: 'Retry-After',\n} as const;\n\n/** How a V10 client reaches its service. */\nexport interface WowClientOptions {\n /**\n * The fetcher requests go through, with its base URL and interceptors\n * (authentication, say); the default fetcher when absent.\n */\n readonly fetcher?: Fetcher;\n /** A path put before every route, such as a gateway's prefix. */\n readonly basePath?: string;\n}\n\n/**\n * The scope a caller allowed to act across scopes acts in: the `Wow-Scope`\n * header (decision D95).\n */\nexport interface TargetScope {\n readonly tenantId?: string;\n readonly ownerId?: string;\n readonly spaceId?: string;\n}\n\nfunction quote(value: string): string {\n return `\"${value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"')}\"`;\n}\n\n/**\n * A target scope as the `Wow-Scope` header spells it, an RFC 8941\n * dictionary: `tenant=\"t1\", owner=\"u1\", space=\"s1\"`.\n *\n * @param scope - The scope; at least one of its members is set\n */\nexport function formatScope(scope: TargetScope): string {\n const members = [\n scope.tenantId === undefined\n ? undefined\n : `tenant=${quote(scope.tenantId)}`,\n scope.ownerId === undefined ? undefined : `owner=${quote(scope.ownerId)}`,\n scope.spaceId === undefined ? undefined : `space=${quote(scope.spaceId)}`,\n ].filter(member => member !== undefined);\n if (members.length === 0) {\n throw new TypeError('Wow-Scope names a tenant, an owner or a space.');\n }\n return members.join(', ');\n}\n\n/** What every V10 request may carry beside its own parameters. */\nexport interface RequestOptions {\n /** The scope to act in (`Wow-Scope`), for a caller allowed to. */\n readonly scope?: TargetScope;\n /** The space to act in (`Wow-Space`), among the caller's own. */\n readonly space?: string;\n /** More headers: the request facts the service records, say. */\n readonly headers?: Readonly<Record<string, string>>;\n /** Cancels the request. */\n readonly signal?: AbortSignal;\n}\n\n/** One request of a V10 client. */\nexport interface Call {\n readonly method: 'GET' | 'POST' | 'DELETE';\n readonly path: string;\n readonly query?: Readonly<Record<string, string | number | undefined>>;\n readonly headers?: Readonly<Record<string, string | undefined>>;\n readonly body?: unknown;\n readonly options?: RequestOptions;\n /** Answers a 304 rather than rejecting with it. */\n readonly notModified?: boolean;\n}\n\n/** `{name}` segments of `path` filled from `params`, each encoded. */\nexport function expandPath(\n path: string,\n params: Readonly<Record<string, string>>,\n): string {\n return path.replace(/\\{([^}]+)\\}/g, (segment, name: string) => {\n const value = params[name];\n if (value === undefined || value === '') {\n throw new TypeError(`The path ${path} needs ${name}.`);\n }\n return encodeURIComponent(value);\n });\n}\n\nfunction queryString(\n query: Readonly<Record<string, string | number | undefined>> | undefined,\n): string {\n if (!query) return '';\n const params = new URLSearchParams();\n for (const [name, value] of Object.entries(query)) {\n if (value !== undefined) params.append(name, String(value));\n }\n const text = params.toString();\n return text ? `?${text}` : '';\n}\n\n/**\n * Sends one request through the client's fetcher and answers its response;\n * a response that is not 2xx rejects with a {@link WowProblemError}.\n *\n * @param client - The client's options\n * @param call - The request\n */\nexport async function send(\n client: WowClientOptions,\n call: Call,\n): Promise<Response> {\n const options = call.options ?? {};\n const headers: Record<string, string> = {};\n for (const [name, value] of Object.entries({\n ...call.headers,\n ...(options.scope === undefined\n ? {}\n : { [WowV10Headers.SCOPE]: formatScope(options.scope) }),\n ...(options.space === undefined\n ? {}\n : { [WowV10Headers.SPACE]: options.space }),\n ...options.headers,\n })) {\n if (value !== undefined) headers[name] = value;\n }\n const url = `${client.basePath ?? ''}${call.path}${queryString(call.query)}`;\n try {\n return await (client.fetcher ?? defaultFetcher).fetch(url, {\n method: call.method,\n headers,\n ...(call.body === undefined ? {} : { body: call.body as object }),\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n });\n } catch (error) {\n const response = (error as { exchange?: { response?: Response } })?.exchange\n ?.response;\n if (call.notModified && response?.status === 304) return response;\n throw (await toWowProblemError(error)) ?? error;\n }\n}\n\n/** The JSON body of a 2xx response. */\nexport async function json<T>(response: Response): Promise<T> {\n return (await response.json()) as T;\n}\n\n/** The entity tag of a response without its quotes or weak marker. */\nexport function entityTag(response: Response): string | undefined {\n const tag = response.headers.get(WowV10Headers.ETAG);\n return tag === null ? undefined : tag.replace(/^W\\//, '').replace(/\"/g, '');\n}\n"],"mappings":"qEAoBA,IAAaI,EAAgB,CAE3B,WAAY,iBAEZ,KAAM,WAEN,aAAc,mBAEd,MAAO,YAEP,MAAO,YAEP,SAAU,WAEV,cAAe,gBAEf,KAAM,OAEN,YAAa,aACf,EAuBA,SAASC,EAAM,EAAuB,CACpC,MAAO,I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,KAAK,CAAE,EACxD,GAAIA,EAAQ,QAAU,IAAA,GAClB,CAAC,EACD,EAAGf,EAAc,OAAQe,EAAQ,KAAM,EAC3C,GAAGA,EAAQ,OACb,CAAC,EACKb,IAAU,IAAA,KAAW,EAAQQ,GAAQR,GAE3C,IAAMgB,EAAM,GAAGC,EAAO,UAAY,KAAKH,EAAK,OAAOL,EAAYK,EAAK,KAAK,IACzE,GAAI,CACF,OAAO,MAAOG,EAAO,SAAWvB,EAAAA,QAAAA,CAAgB,MAAMsB,EAAK,CACzD,OAAQF,EAAK,OACb,UACA,GAAIA,EAAK,OAAS,IAAA,GAAY,CAAC,EAAI,CAAE,KAAMA,EAAK,IAAe,EAC/D,GAAID,EAAQ,SAAW,IAAA,GAAY,CAAC,EAAI,CAAE,OAAQA,EAAQ,MAAO,CACnE,CAAC,CACH,OAASK,EAAO,CACd,IAAMC,EAAYD,GAAkD,UAChE,SACJ,GAAIJ,EAAK,aAAeK,GAAU,SAAW,IAAK,OAAOA,EACzD,MAAO,MAAMxB,EAAAA,kBAAkBuB,CAAK,GAAMA,CAC5C,CACF,CAGA,eAAsBE,EAAQ,EAAgC,CAC5D,OAAQ,MAAMD,EAAS,KAAK,CAC9B,CAGA,SAAgBE,EAAU,EAAwC,CAChE,IAAMC,EAAMH,EAAS,QAAQ,IAAIrB,EAAc,IAAI,EACnD,OAAOwB,IAAQ,KAAO,IAAA,GAAYA,EAAI,QAAQ,OAAQ,EAAE,CAAC,CAAC,QAAQ,KAAM,EAAE,CAC5E"}
@@ -1,73 +0,0 @@
1
- import { toWowProblemError as e } from "./problem.es.js";
2
- import { fetcher as t } from "@ahoo-wang/fetcher";
3
- //#region src/v10/http.ts
4
- var n = {
5
- REQUEST_ID: "Wow-Request-Id",
6
- WAIT: "Wow-Wait",
7
- WAIT_TIMEOUT: "Wow-Wait-Timeout",
8
- SCOPE: "Wow-Scope",
9
- SPACE: "Wow-Space",
10
- IF_MATCH: "If-Match",
11
- IF_NONE_MATCH: "If-None-Match",
12
- ETAG: "ETag",
13
- RETRY_AFTER: "Retry-After"
14
- };
15
- function r(e) {
16
- return `"${e.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
17
- }
18
- function i(e) {
19
- let t = [
20
- e.tenantId === void 0 ? void 0 : `tenant=${r(e.tenantId)}`,
21
- e.ownerId === void 0 ? void 0 : `owner=${r(e.ownerId)}`,
22
- e.spaceId === void 0 ? void 0 : `space=${r(e.spaceId)}`
23
- ].filter((e) => e !== void 0);
24
- if (t.length === 0) throw TypeError("Wow-Scope names a tenant, an owner or a space.");
25
- return t.join(", ");
26
- }
27
- function a(e, t) {
28
- return e.replace(/\{([^}]+)\}/g, (n, r) => {
29
- let i = t[r];
30
- if (i === void 0 || i === "") throw TypeError(`The path ${e} needs ${r}.`);
31
- return encodeURIComponent(i);
32
- });
33
- }
34
- function o(e) {
35
- if (!e) return "";
36
- let t = new URLSearchParams();
37
- for (let [n, r] of Object.entries(e)) r !== void 0 && t.append(n, String(r));
38
- let n = t.toString();
39
- return n ? `?${n}` : "";
40
- }
41
- async function s(r, a) {
42
- let s = a.options ?? {}, c = {};
43
- for (let [e, t] of Object.entries({
44
- ...a.headers,
45
- ...s.scope === void 0 ? {} : { [n.SCOPE]: i(s.scope) },
46
- ...s.space === void 0 ? {} : { [n.SPACE]: s.space },
47
- ...s.headers
48
- })) t !== void 0 && (c[e] = t);
49
- let l = `${r.basePath ?? ""}${a.path}${o(a.query)}`;
50
- try {
51
- return await (r.fetcher ?? t).fetch(l, {
52
- method: a.method,
53
- headers: c,
54
- ...a.body === void 0 ? {} : { body: a.body },
55
- ...s.signal === void 0 ? {} : { signal: s.signal }
56
- });
57
- } catch (t) {
58
- let n = t?.exchange?.response;
59
- if (a.notModified && n?.status === 304) return n;
60
- throw await e(t) ?? t;
61
- }
62
- }
63
- async function c(e) {
64
- return await e.json();
65
- }
66
- function l(e) {
67
- let t = e.headers.get(n.ETAG);
68
- return t === null ? void 0 : t.replace(/^W\//, "").replace(/"/g, "");
69
- }
70
- //#endregion
71
- export { n as WowV10Headers, l as entityTag, a as expandPath, i as formatScope, c as json, s as send };
72
-
73
- //# sourceMappingURL=http.es.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.es.js","names":["defaultFetcher","WowV10Headers","quote","value","formatScope","members","scope","member","expandPath","path","params","name","queryString","query","text","send","options","call","headers","url","client","fetcher","error","response","toWowProblemError","json","entityTag","tag"],"sources":["../../src/v10/http.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 Fetcher, fetcher as defaultFetcher } from '@ahoo-wang/fetcher';\nimport { toWowProblemError } from './problem.js';\n\n/**\n * The request headers of a Wow V10 service's public port (decisions D95,\n * D96, D98, D99).\n */\nexport const WowV10Headers = {\n /** The caller's id of the request: a retry with the same one is deduplicated. */\n REQUEST_ID: 'Wow-Request-Id',\n /** The wait plan (decision D99). */\n WAIT: 'Wow-Wait',\n /** How long to wait: `500ms`, `10s` or an ISO-8601 duration. */\n WAIT_TIMEOUT: 'Wow-Wait-Timeout',\n /** The scope to act in, for a caller allowed to act across scopes (decision D95). */\n SCOPE: 'Wow-Scope',\n /** The space, among the caller's own, to act in (decision D96). */\n SPACE: 'Wow-Space',\n /** The expected version of the aggregate, as an entity tag. */\n IF_MATCH: 'If-Match',\n /** The version, or descriptor version, a read already holds. */\n IF_NONE_MATCH: 'If-None-Match',\n /** The version of a state read, or of a query descriptor. */\n ETAG: 'ETag',\n /** The seconds after which a failed request may be retried. */\n RETRY_AFTER: 'Retry-After',\n} as const;\n\n/** How a V10 client reaches its service. */\nexport interface WowClientOptions {\n /**\n * The fetcher requests go through, with its base URL and interceptors\n * (authentication, say); the default fetcher when absent.\n */\n readonly fetcher?: Fetcher;\n /** A path put before every route, such as a gateway's prefix. */\n readonly basePath?: string;\n}\n\n/**\n * The scope a caller allowed to act across scopes acts in: the `Wow-Scope`\n * header (decision D95).\n */\nexport interface TargetScope {\n readonly tenantId?: string;\n readonly ownerId?: string;\n readonly spaceId?: string;\n}\n\nfunction quote(value: string): string {\n return `\"${value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"')}\"`;\n}\n\n/**\n * A target scope as the `Wow-Scope` header spells it, an RFC 8941\n * dictionary: `tenant=\"t1\", owner=\"u1\", space=\"s1\"`.\n *\n * @param scope - The scope; at least one of its members is set\n */\nexport function formatScope(scope: TargetScope): string {\n const members = [\n scope.tenantId === undefined\n ? undefined\n : `tenant=${quote(scope.tenantId)}`,\n scope.ownerId === undefined ? undefined : `owner=${quote(scope.ownerId)}`,\n scope.spaceId === undefined ? undefined : `space=${quote(scope.spaceId)}`,\n ].filter(member => member !== undefined);\n if (members.length === 0) {\n throw new TypeError('Wow-Scope names a tenant, an owner or a space.');\n }\n return members.join(', ');\n}\n\n/** What every V10 request may carry beside its own parameters. */\nexport interface RequestOptions {\n /** The scope to act in (`Wow-Scope`), for a caller allowed to. */\n readonly scope?: TargetScope;\n /** The space to act in (`Wow-Space`), among the caller's own. */\n readonly space?: string;\n /** More headers: the request facts the service records, say. */\n readonly headers?: Readonly<Record<string, string>>;\n /** Cancels the request. */\n readonly signal?: AbortSignal;\n}\n\n/** One request of a V10 client. */\nexport interface Call {\n readonly method: 'GET' | 'POST' | 'DELETE';\n readonly path: string;\n readonly query?: Readonly<Record<string, string | number | undefined>>;\n readonly headers?: Readonly<Record<string, string | undefined>>;\n readonly body?: unknown;\n readonly options?: RequestOptions;\n /** Answers a 304 rather than rejecting with it. */\n readonly notModified?: boolean;\n}\n\n/** `{name}` segments of `path` filled from `params`, each encoded. */\nexport function expandPath(\n path: string,\n params: Readonly<Record<string, string>>,\n): string {\n return path.replace(/\\{([^}]+)\\}/g, (segment, name: string) => {\n const value = params[name];\n if (value === undefined || value === '') {\n throw new TypeError(`The path ${path} needs ${name}.`);\n }\n return encodeURIComponent(value);\n });\n}\n\nfunction queryString(\n query: Readonly<Record<string, string | number | undefined>> | undefined,\n): string {\n if (!query) return '';\n const params = new URLSearchParams();\n for (const [name, value] of Object.entries(query)) {\n if (value !== undefined) params.append(name, String(value));\n }\n const text = params.toString();\n return text ? `?${text}` : '';\n}\n\n/**\n * Sends one request through the client's fetcher and answers its response;\n * a response that is not 2xx rejects with a {@link WowProblemError}.\n *\n * @param client - The client's options\n * @param call - The request\n */\nexport async function send(\n client: WowClientOptions,\n call: Call,\n): Promise<Response> {\n const options = call.options ?? {};\n const headers: Record<string, string> = {};\n for (const [name, value] of Object.entries({\n ...call.headers,\n ...(options.scope === undefined\n ? {}\n : { [WowV10Headers.SCOPE]: formatScope(options.scope) }),\n ...(options.space === undefined\n ? {}\n : { [WowV10Headers.SPACE]: options.space }),\n ...options.headers,\n })) {\n if (value !== undefined) headers[name] = value;\n }\n const url = `${client.basePath ?? ''}${call.path}${queryString(call.query)}`;\n try {\n return await (client.fetcher ?? defaultFetcher).fetch(url, {\n method: call.method,\n headers,\n ...(call.body === undefined ? {} : { body: call.body as object }),\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n });\n } catch (error) {\n const response = (error as { exchange?: { response?: Response } })?.exchange\n ?.response;\n if (call.notModified && response?.status === 304) return response;\n throw (await toWowProblemError(error)) ?? error;\n }\n}\n\n/** The JSON body of a 2xx response. */\nexport async function json<T>(response: Response): Promise<T> {\n return (await response.json()) as T;\n}\n\n/** The entity tag of a response without its quotes or weak marker. */\nexport function entityTag(response: Response): string | undefined {\n const tag = response.headers.get(WowV10Headers.ETAG);\n return tag === null ? undefined : tag.replace(/^W\\//, '').replace(/\"/g, '');\n}\n"],"mappings":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UC,EAAK,WAAW,CAAC,GAC3BC,IAAkC,CAAC;CACzC,KAAK,IAAM,CAACP,GAAMR,MAAU,OAAO,QAAQ;EACzC,GAAGc,EAAK;EACR,GAAID,EAAQ,UAAU,KAAA,IAClB,CAAC,IACD,GAAGf,EAAc,QAAQG,EAAYY,EAAQ,KAAK,EAAE;EACxD,GAAIA,EAAQ,UAAU,KAAA,IAClB,CAAC,IACD,GAAGf,EAAc,QAAQe,EAAQ,MAAM;EAC3C,GAAGA,EAAQ;CACb,CAAC,GACC,AAAIb,MAAU,KAAA,MAAW,EAAQQ,KAAQR;CAE3C,IAAMgB,IAAM,GAAGC,EAAO,YAAY,KAAKH,EAAK,OAAOL,EAAYK,EAAK,KAAK;CACzE,IAAI;EACF,OAAO,OAAOG,EAAO,WAAWpB,EAAAA,CAAgB,MAAMmB,GAAK;GACzD,QAAQF,EAAK;GACb;GACA,GAAIA,EAAK,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAMA,EAAK,KAAe;GAC/D,GAAID,EAAQ,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQA,EAAQ,OAAO;EACnE,CAAC;CACH,SAASM,GAAO;EACd,IAAMC,IAAYD,GAAkD,UAChE;EACJ,IAAIL,EAAK,eAAeM,GAAU,WAAW,KAAK,OAAOA;EACzD,MAAO,MAAMC,EAAkBF,CAAK,KAAMA;CAC5C;AACF;AAGA,eAAsBG,EAAQ,GAAgC;CAC5D,OAAQ,MAAMF,EAAS,KAAK;AAC9B;AAGA,SAAgBG,EAAU,GAAwC;CAChE,IAAMC,IAAMJ,EAAS,QAAQ,IAAItB,EAAc,IAAI;CACnD,OAAO0B,MAAQ,OAAO,KAAA,IAAYA,EAAI,QAAQ,QAAQ,EAAE,CAAC,CAAC,QAAQ,MAAM,EAAE;AAC5E"}
@@ -1,19 +0,0 @@
1
- /**
2
- * `@ahoo-wang/wow-client/v10`: the client of a Wow V10 service's public
3
- * routes — commands with `Wow-Wait` and their event streams, state reads and
4
- * traces, the snapshot, event and dataset query routes, the Manifest, and
5
- * RFC 9457 problems as {@link WowProblemError}s with retry hints. Code
6
- * `wow-generator` generates from a Manifest builds on it.
7
- *
8
- * It is additive: the root entry keeps serving Wow 9.x services. Build
9
- * queries with the DSL of `@ahoo-wang/wow-client/dsl`.
10
- */
11
- export { type ApplyTags, CommandGateway, type CommandOptions, commandSegment, type CreateCommandOptions, type LifecycleCommand, LifecycleCommands, type TransferOwner, type TransferSpace, } from './commands.cjs';
12
- export { formatScope, type RequestOptions, type TargetScope, type WowClientOptions, WowV10Headers, } from './http.cjs';
13
- export { type AggregateManifest, type CommandManifest, type ContextManifest, type Creation, type ErrorManifest, type EventManifest, fetchManifest, type Manifest, MANIFEST_FORMAT, type QueryManifest, type RouteManifest, type SubscriptionManifest, } from './manifest.cjs';
14
- export * from './wire.cjs';
15
- export { FRAMEWORK_ERROR_PREFIX, type FrameworkErrorCode, FrameworkErrorCodes, isProblem, parseRetryAfter, type Problem, PROBLEM_TYPE_PREFIX, readProblem, type RetryHint, retryHintOf, toWowProblemError, WowProblemError, } from './problem.cjs';
16
- export { type CountQuery, type CountResult, DatasetClient, type DescriptorResult, EventQueryClient, type PagedQuery, type PagedResult, QueryModelClient, queryPath, SnapshotQueryClient, type TotalMode, } from './queries.cjs';
17
- export { StateClient, type StateReadOptions, type StateReadResult, type StateTraceOptions, } from './state.cjs';
18
- export { type CommandResultStream } from './streams.cjs';
19
- export { formatHop, formatWaitPlan, formatWaitTimeout, SNAPSHOT_SUBSCRIPTION, wait, type WaitOptions, } from './wait.cjs';
@@ -1,19 +0,0 @@
1
- /**
2
- * `@ahoo-wang/wow-client/v10`: the client of a Wow V10 service's public
3
- * routes — commands with `Wow-Wait` and their event streams, state reads and
4
- * traces, the snapshot, event and dataset query routes, the Manifest, and
5
- * RFC 9457 problems as {@link WowProblemError}s with retry hints. Code
6
- * `wow-generator` generates from a Manifest builds on it.
7
- *
8
- * It is additive: the root entry keeps serving Wow 9.x services. Build
9
- * queries with the DSL of `@ahoo-wang/wow-client/dsl`.
10
- */
11
- export { type ApplyTags, CommandGateway, type CommandOptions, commandSegment, type CreateCommandOptions, type LifecycleCommand, LifecycleCommands, type TransferOwner, type TransferSpace, } from './commands.js';
12
- export { formatScope, type RequestOptions, type TargetScope, type WowClientOptions, WowV10Headers, } from './http.js';
13
- export { type AggregateManifest, type CommandManifest, type ContextManifest, type Creation, type ErrorManifest, type EventManifest, fetchManifest, type Manifest, MANIFEST_FORMAT, type QueryManifest, type RouteManifest, type SubscriptionManifest, } from './manifest.js';
14
- export * from './wire.js';
15
- export { FRAMEWORK_ERROR_PREFIX, type FrameworkErrorCode, FrameworkErrorCodes, isProblem, parseRetryAfter, type Problem, PROBLEM_TYPE_PREFIX, readProblem, type RetryHint, retryHintOf, toWowProblemError, WowProblemError, } from './problem.js';
16
- export { type CountQuery, type CountResult, DatasetClient, type DescriptorResult, EventQueryClient, type PagedQuery, type PagedResult, QueryModelClient, queryPath, SnapshotQueryClient, type TotalMode, } from './queries.js';
17
- export { StateClient, type StateReadOptions, type StateReadResult, type StateTraceOptions, } from './state.js';
18
- export { type CommandResultStream } from './streams.js';
19
- export { formatHop, formatWaitPlan, formatWaitTimeout, SNAPSHOT_SUBSCRIPTION, wait, type WaitOptions, } from './wait.js';
@@ -1 +0,0 @@
1
- {"version":3,"file":"manifest.cjs","names":["json","send","require_http","MANIFEST_FORMAT","fetchManifest","client"],"sources":["../../src/v10/manifest.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 json,\n type RequestOptions,\n send,\n type WowClientOptions,\n} from './http.js';\nimport type { Ownership } from './wire.js';\n\n/** A route of the Manifest: a method and a path, `{id}` the aggregate id. */\nexport interface RouteManifest {\n readonly method: string;\n readonly path: string;\n}\n\n/** Whether a command creates its aggregate. */\nexport type Creation = 'NONE' | 'REQUIRED' | 'ALLOWED';\n\n/** A command of an aggregate (decisions D104, D176, D182). */\nexport interface CommandManifest {\n readonly name: string;\n readonly aliases?: readonly string[];\n /** `#/$defs/<key>`. */\n readonly schema: string;\n readonly creation?: Creation;\n readonly produces?: readonly string[];\n readonly routes?: readonly RouteManifest[];\n readonly mounted?: boolean;\n readonly transformsTo?: readonly string[];\n}\n\n/** An event of an aggregate and its revision. */\nexport interface EventManifest {\n readonly name: string;\n readonly aliases?: readonly string[];\n readonly revision?: number;\n readonly schema: string;\n}\n\n/** A query model of an aggregate: `snapshot` or `events` (decision D128). */\nexport interface QueryManifest {\n readonly model: string;\n readonly routes?: readonly RouteManifest[];\n}\n\n/** An aggregate of a bounded context. */\nexport interface AggregateManifest {\n readonly name: string;\n readonly description?: string;\n readonly state: { readonly schema: string; readonly fingerprint?: string };\n readonly snapshot?: { readonly enabled?: boolean };\n readonly commands?: readonly CommandManifest[];\n readonly events?: readonly EventManifest[];\n readonly lifecycle?: readonly string[];\n readonly queries?: readonly QueryManifest[];\n readonly schedules?: readonly string[];\n readonly ownership?: Ownership;\n}\n\n/** A subscription of a bounded context (design 04 §1). */\nexport interface SubscriptionManifest {\n /** `processor.function`, as a `handled` hop names it. */\n readonly name: string;\n readonly kind: 'PROJECTION' | 'REACTOR' | 'SAGA';\n readonly source: {\n readonly context?: string;\n readonly aggregates?: readonly string[];\n readonly events?: readonly string[];\n };\n readonly derives?: readonly string[];\n readonly rejected?: readonly string[];\n readonly committed?: readonly string[];\n readonly [property: string]: unknown;\n}\n\n/** An error code and the HTTP status it is answered with. */\nexport interface ErrorManifest {\n readonly code: string;\n readonly status: number;\n readonly description?: string;\n}\n\n/** A bounded context of the Manifest. */\nexport interface ContextManifest {\n readonly name: string;\n readonly description?: string;\n readonly aggregates?: readonly AggregateManifest[];\n readonly subscriptions?: readonly SubscriptionManifest[];\n readonly published?: readonly {\n readonly aggregate: string;\n readonly topic: string;\n readonly includeState?: boolean;\n }[];\n readonly errors?: readonly ErrorManifest[];\n}\n\n/**\n * A service's Manifest (decisions D17, D73–D76): its contexts, aggregates,\n * commands, events, routes and error codes, and the JSON Schemas they refer\n * to under `$defs`. `wow-generator` generates typed clients from it.\n */\nexport interface Manifest {\n readonly format: number;\n readonly service?: { readonly name: string; readonly version?: string };\n readonly contexts: readonly ContextManifest[];\n readonly errors?: readonly ErrorManifest[];\n readonly $defs?: Readonly<Record<string, unknown>>;\n}\n\n/** The format of the Manifest this client reads. */\nexport const MANIFEST_FORMAT = 1;\n\n/**\n * The service's Manifest, `GET /wow/manifest`, authorized as any API.\n *\n * @param client - How the service is reached\n * @param options - Headers and cancellation\n */\nexport async function fetchManifest(\n client: WowClientOptions = {},\n options?: RequestOptions,\n): Promise<Manifest> {\n return json<Manifest>(\n await send(client, { method: 'GET', path: '/wow/manifest', options }),\n );\n}\n"],"mappings":"8BA0HA,IAAaG,EAAkB,EAQ/B,eAAsBC,EACpB,EAA2B,CAAC,EAC5B,EACmB,CACnB,OAAOJ,EAAAA,KACL,MAAMC,EAAAA,KAAKI,EAAQ,CAAE,OAAQ,MAAO,KAAM,gBAAiB,SAAQ,CAAC,CACtE,CACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"manifest.es.js","names":["MANIFEST_FORMAT","fetchManifest","json","send","client"],"sources":["../../src/v10/manifest.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 json,\n type RequestOptions,\n send,\n type WowClientOptions,\n} from './http.js';\nimport type { Ownership } from './wire.js';\n\n/** A route of the Manifest: a method and a path, `{id}` the aggregate id. */\nexport interface RouteManifest {\n readonly method: string;\n readonly path: string;\n}\n\n/** Whether a command creates its aggregate. */\nexport type Creation = 'NONE' | 'REQUIRED' | 'ALLOWED';\n\n/** A command of an aggregate (decisions D104, D176, D182). */\nexport interface CommandManifest {\n readonly name: string;\n readonly aliases?: readonly string[];\n /** `#/$defs/<key>`. */\n readonly schema: string;\n readonly creation?: Creation;\n readonly produces?: readonly string[];\n readonly routes?: readonly RouteManifest[];\n readonly mounted?: boolean;\n readonly transformsTo?: readonly string[];\n}\n\n/** An event of an aggregate and its revision. */\nexport interface EventManifest {\n readonly name: string;\n readonly aliases?: readonly string[];\n readonly revision?: number;\n readonly schema: string;\n}\n\n/** A query model of an aggregate: `snapshot` or `events` (decision D128). */\nexport interface QueryManifest {\n readonly model: string;\n readonly routes?: readonly RouteManifest[];\n}\n\n/** An aggregate of a bounded context. */\nexport interface AggregateManifest {\n readonly name: string;\n readonly description?: string;\n readonly state: { readonly schema: string; readonly fingerprint?: string };\n readonly snapshot?: { readonly enabled?: boolean };\n readonly commands?: readonly CommandManifest[];\n readonly events?: readonly EventManifest[];\n readonly lifecycle?: readonly string[];\n readonly queries?: readonly QueryManifest[];\n readonly schedules?: readonly string[];\n readonly ownership?: Ownership;\n}\n\n/** A subscription of a bounded context (design 04 §1). */\nexport interface SubscriptionManifest {\n /** `processor.function`, as a `handled` hop names it. */\n readonly name: string;\n readonly kind: 'PROJECTION' | 'REACTOR' | 'SAGA';\n readonly source: {\n readonly context?: string;\n readonly aggregates?: readonly string[];\n readonly events?: readonly string[];\n };\n readonly derives?: readonly string[];\n readonly rejected?: readonly string[];\n readonly committed?: readonly string[];\n readonly [property: string]: unknown;\n}\n\n/** An error code and the HTTP status it is answered with. */\nexport interface ErrorManifest {\n readonly code: string;\n readonly status: number;\n readonly description?: string;\n}\n\n/** A bounded context of the Manifest. */\nexport interface ContextManifest {\n readonly name: string;\n readonly description?: string;\n readonly aggregates?: readonly AggregateManifest[];\n readonly subscriptions?: readonly SubscriptionManifest[];\n readonly published?: readonly {\n readonly aggregate: string;\n readonly topic: string;\n readonly includeState?: boolean;\n }[];\n readonly errors?: readonly ErrorManifest[];\n}\n\n/**\n * A service's Manifest (decisions D17, D73–D76): its contexts, aggregates,\n * commands, events, routes and error codes, and the JSON Schemas they refer\n * to under `$defs`. `wow-generator` generates typed clients from it.\n */\nexport interface Manifest {\n readonly format: number;\n readonly service?: { readonly name: string; readonly version?: string };\n readonly contexts: readonly ContextManifest[];\n readonly errors?: readonly ErrorManifest[];\n readonly $defs?: Readonly<Record<string, unknown>>;\n}\n\n/** The format of the Manifest this client reads. */\nexport const MANIFEST_FORMAT = 1;\n\n/**\n * The service's Manifest, `GET /wow/manifest`, authorized as any API.\n *\n * @param client - How the service is reached\n * @param options - Headers and cancellation\n */\nexport async function fetchManifest(\n client: WowClientOptions = {},\n options?: RequestOptions,\n): Promise<Manifest> {\n return json<Manifest>(\n await send(client, { method: 'GET', path: '/wow/manifest', options }),\n );\n}\n"],"mappings":";;AA0HA,IAAaA,IAAkB;AAQ/B,eAAsBC,EACpB,IAA2B,CAAC,GAC5B,GACmB;CACnB,OAAOC,EACL,MAAMC,EAAKC,GAAQ;EAAE,QAAQ;EAAO,MAAM;EAAiB;CAAQ,CAAC,CACtE;AACF"}
@@ -1,2 +0,0 @@
1
- var e={AUTH_UNAUTHENTICATED:`wow.auth.unauthenticated`,AUTH_FORBIDDEN:`wow.auth.forbidden`,AGGREGATE_FORBIDDEN:`wow.aggregate.forbidden`,COMMAND_MALFORMED:`wow.command.malformed`,COMMAND_INVALID:`wow.command.invalid`,WAIT_INVALID:`wow.wait.invalid`,COMMAND_UNHANDLED:`wow.command.unhandled`,AGGREGATE_NOT_FOUND:`wow.aggregate.not-found`,AGGREGATE_EXISTS:`wow.aggregate.exists`,AGGREGATE_VERSION_MISMATCH:`wow.aggregate.version-mismatch`,COMMAND_REQUEST_ID_REUSED:`wow.command.request-id-reused`,COMMAND_CONTENDED:`wow.command.contended`,AGGREGATE_DELETED:`wow.aggregate.deleted`,COMMAND_BUSY:`wow.command.busy`,COMMAND_UNKNOWN:`wow.command.unknown`,NODE_CLOSING:`wow.node.closing`,STORAGE_UNAVAILABLE:`wow.storage.unavailable`,SCHEDULE_NOT_DUE:`wow.schedule.not-due`,SCHEDULE_JOB_INVALID:`wow.schedule.job-invalid`,SUBSCRIPTION_PARKED:`wow.subscription.parked`,WAIT_TIMEOUT:`wow.wait.timeout`,QUERY_MALFORMED:`wow.query.malformed`,QUERY_INVALID:`wow.query.invalid`,QUERY_FAILED:`wow.query.failed`,QUERY_TIMEOUT:`wow.query.timeout`},t=`wow.`,n=`urn:wow:error:`,r=new Set([`type`,`title`,`status`,`detail`,`instance`,`code`,`violations`,`result`,`extensions`]);function i(e){if(e.extensions!==void 0)return e;let t=Object.fromEntries(Object.entries(e).filter(([e])=>!r.has(e)));return Object.keys(t).length===0?e:{...e,extensions:t}}var a=new Map([[e.COMMAND_UNKNOWN,!0],[e.NODE_CLOSING,!0],[e.STORAGE_UNAVAILABLE,!0],[e.SCHEDULE_NOT_DUE,!0],[e.QUERY_TIMEOUT,!1],[e.COMMAND_BUSY,!0],[e.COMMAND_CONTENDED,!0],[e.WAIT_TIMEOUT,!0]]);function o(e,t,n){let r=e===void 0?void 0:a.get(e),i=r!==void 0||e===void 0&&t===503;return{retryable:i,sameRequestId:r??i,...n===void 0?{}:{afterMs:n}}}var s=class extends Error{constructor(e,t={}){super(e.code?`[${e.code}] ${e.detail??e.title}`:`${e.status} ${e.detail??e.title}`),this.name=`WowProblemError`,this.problem=i(e),this.status=e.status,e.code!==void 0&&(this.code=e.code),this.violations=e.violations??[],e.result!==void 0&&(this.result=e.result),this.retry=o(e.code,e.status,t.retryAfterMs),t.cause!==void 0&&(this.cause=t.cause)}get isFramework(){return this.code?.startsWith(`wow.`)??!1}};function c(e){return typeof e==`object`&&!!e&&typeof e.status==`number`}function l(e,t=Date.now()){if(!e)return;let n=e.trim();if(/^\d+$/.test(n))return Number(n)*1e3;let r=Date.parse(n);return Number.isNaN(r)?void 0:Math.max(0,r-t)}async function u(e){let t;try{t=await e.clone().json()}catch{}if(c(t)){let n=t.code??(t.type?.startsWith(`urn:wow:error:`)?t.type.slice(14):void 0);return i({...t,type:t.type??`about:blank`,title:t.title??e.statusText,...n===void 0?{}:{code:n}})}return{type:`about:blank`,title:e.statusText,status:e.status}}async function d(e){if(e instanceof s)return e;if(typeof e!=`object`||!e)return;let{exchange:t,cause:n}=e;if(n instanceof s)return n;let r=t?.response;if(!r||r.ok)return;let i=await u(r),a=l(r.headers.get(`Retry-After`));return new s(i,{cause:e,...a===void 0?{}:{retryAfterMs:a}})}exports.FRAMEWORK_ERROR_PREFIX=t,exports.FrameworkErrorCodes=e,exports.PROBLEM_TYPE_PREFIX=n,exports.WowProblemError=s,exports.isProblem=c,exports.parseRetryAfter=l,exports.readProblem=u,exports.retryHintOf=o,exports.toWowProblemError=d;
2
- //# sourceMappingURL=problem.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"problem.cjs","names":["FrameworkErrorCodes","FRAMEWORK_ERROR_PREFIX","PROBLEM_TYPE_PREFIX","PROBLEM_MEMBERS","withExtensions","problem","extensions","name","RETRYABLE","retryHintOf","sameRequestId","code","retryable","status","afterMs","WowProblemError","options","isProblem","value","parseRetryAfter","trimmed","date","now","readProblem","body","response","toWowProblemError","error","cause","exchange","retryAfterMs"],"sources":["../../src/v10/problem.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 { CommandResult, Violation } from './wire.js';\n\n/**\n * The framework's error codes (design 05 §3, decisions D102, D103, D130),\n * each answered with the status of the Manifest's `errors` table. A domain\n * rejection has a code of its own, answered with 422 unless the service\n * configures another status.\n */\nexport const FrameworkErrorCodes = {\n /** 401: the request carries no valid credentials. */\n AUTH_UNAUTHENTICATED: 'wow.auth.unauthenticated',\n /** 403: the caller may not send this command. */\n AUTH_FORBIDDEN: 'wow.auth.forbidden',\n /** 403: the aggregate is outside the caller's scope. */\n AGGREGATE_FORBIDDEN: 'wow.aggregate.forbidden',\n /** 400: the command body cannot be read as the command type. */\n COMMAND_MALFORMED: 'wow.command.malformed',\n /** 400: the command failed validation; the problem lists the violations. */\n COMMAND_INVALID: 'wow.command.invalid',\n /** 400: the wait is not a chain the runtime can follow. */\n WAIT_INVALID: 'wow.wait.invalid',\n /** 400: the aggregate does not handle this command. */\n COMMAND_UNHANDLED: 'wow.command.unhandled',\n /** 404: the aggregate does not exist. */\n AGGREGATE_NOT_FOUND: 'wow.aggregate.not-found',\n /** 409: the aggregate already exists. */\n AGGREGATE_EXISTS: 'wow.aggregate.exists',\n /** 409, or 412 with `If-Match`: the aggregate is not at the expected version. */\n AGGREGATE_VERSION_MISMATCH: 'wow.aggregate.version-mismatch',\n /** 409: the request id was used by another command. */\n COMMAND_REQUEST_ID_REUSED: 'wow.command.request-id-reused',\n /** 409: concurrent writers kept winning; retrying with the same request id is safe. */\n COMMAND_CONTENDED: 'wow.command.contended',\n /** 410: the aggregate is deleted; only RestoreAggregate applies. */\n AGGREGATE_DELETED: 'wow.aggregate.deleted',\n /** 429: the node has too many commands in flight; retry later. */\n COMMAND_BUSY: 'wow.command.busy',\n /** 503: whether the command committed is unknown; retrying with the same request id is safe. */\n COMMAND_UNKNOWN: 'wow.command.unknown',\n /** 503: the node is shutting down; retry on another node. */\n NODE_CLOSING: 'wow.node.closing',\n /** 503, with `Retry-After`: a store could not be reached in time; retry later. */\n STORAGE_UNAVAILABLE: 'wow.storage.unavailable',\n /** 503: a scheduled command arrived too long before its due time; it is sent again later. */\n SCHEDULE_NOT_DUE: 'wow.schedule.not-due',\n /** 400: the job command does not fit its job or instance (decision D198). */\n SCHEDULE_JOB_INVALID: 'wow.schedule.job-invalid',\n /** 500: a subscription on the wait chain parked the aggregate. */\n SUBSCRIPTION_PARKED: 'wow.subscription.parked',\n /** 504: the wait ran out of time; the command may have committed. */\n WAIT_TIMEOUT: 'wow.wait.timeout',\n /** 400: the query body cannot be read as a query. */\n QUERY_MALFORMED: 'wow.query.malformed',\n /** 400: the query failed admission; each violation has its code. */\n QUERY_INVALID: 'wow.query.invalid',\n /** 500: the query backend failed to run the query. */\n QUERY_FAILED: 'wow.query.failed',\n /** 503: the query ran longer than its budget allows. */\n QUERY_TIMEOUT: 'wow.query.timeout',\n} as const;\n\n/** A {@link FrameworkErrorCodes} value. */\nexport type FrameworkErrorCode =\n (typeof FrameworkErrorCodes)[keyof typeof FrameworkErrorCodes];\n\n/** The prefix of every framework code, and of no domain code. */\nexport const FRAMEWORK_ERROR_PREFIX = 'wow.';\n\n/** The prefix of a problem's `type` that carries a Wow code. */\nexport const PROBLEM_TYPE_PREFIX = 'urn:wow:error:';\n\n/**\n * An RFC 9457 problem as a Wow V10 service writes it (decisions D101, D102):\n * `type` is `urn:wow:error:<code>`, or `about:blank` for an error that is\n * only HTTP's (a missing route, 406, 415).\n */\nexport interface Problem {\n readonly type: string;\n readonly title: string;\n readonly status: number;\n readonly detail?: string;\n /** The Wow code; absent for an error that is only HTTP's. */\n readonly code?: string;\n readonly violations?: readonly Violation[];\n /** The whole result of a command that has a ref. */\n readonly result?: CommandResult;\n /**\n * The problem's extension members (RFC 9457): every member the server\n * wrote besides the ones above and `instance`, such as a rejection's\n * structured data (decision D211). Absent when it wrote none.\n */\n readonly extensions?: Readonly<Record<string, unknown>>;\n}\n\n/** The members of a problem that are not extension members. */\nconst PROBLEM_MEMBERS: ReadonlySet<string> = new Set([\n 'type',\n 'title',\n 'status',\n 'detail',\n 'instance',\n 'code',\n 'violations',\n 'result',\n 'extensions',\n]);\n\n/**\n * `problem` with its extension members gathered as `extensions` (internal):\n * a problem read from the wire carries them as top-level members.\n */\nfunction withExtensions(problem: Problem): Problem {\n if (problem.extensions !== undefined) return problem;\n const extensions = Object.fromEntries(\n Object.entries(problem).filter(([name]) => !PROBLEM_MEMBERS.has(name)),\n );\n return Object.keys(extensions).length === 0\n ? problem\n : { ...problem, extensions };\n}\n\n/**\n * What a client may do about a failed request: whether retrying can succeed,\n * whether to keep the request id (`Wow-Request-Id`) so the server\n * deduplicates a command that did commit, and how long to wait first.\n */\nexport interface RetryHint {\n readonly retryable: boolean;\n /** Retry with the same `Wow-Request-Id`: a commit is then answered as a duplicate. */\n readonly sameRequestId: boolean;\n /** The server's `Retry-After`, in milliseconds. */\n readonly afterMs?: number;\n}\n\n/**\n * The codes a retry may get past, each with whether to keep the request id:\n * the 503s (`wow.command.unknown`, `wow.node.closing`,\n * `wow.storage.unavailable`, `wow.schedule.not-due`, `wow.query.timeout`),\n * the 429 `wow.command.busy`, the 409 `wow.command.contended` and the 504\n * `wow.wait.timeout`, whose command may have committed.\n */\nconst RETRYABLE: ReadonlyMap<string, boolean> = new Map([\n [FrameworkErrorCodes.COMMAND_UNKNOWN, true],\n [FrameworkErrorCodes.NODE_CLOSING, true],\n [FrameworkErrorCodes.STORAGE_UNAVAILABLE, true],\n [FrameworkErrorCodes.SCHEDULE_NOT_DUE, true],\n [FrameworkErrorCodes.QUERY_TIMEOUT, false],\n [FrameworkErrorCodes.COMMAND_BUSY, true],\n [FrameworkErrorCodes.COMMAND_CONTENDED, true],\n [FrameworkErrorCodes.WAIT_TIMEOUT, true],\n]);\n\n/**\n * The retry hint of a problem with `code` and `status`: a code of the\n * retryable table, or a 503 without a code (a proxy's), may be retried.\n *\n * @param code - The problem's Wow code, if any\n * @param status - The HTTP status\n * @param afterMs - The `Retry-After` the response carried, in milliseconds\n */\nexport function retryHintOf(\n code: string | undefined,\n status: number,\n afterMs?: number,\n): RetryHint {\n const sameRequestId = code === undefined ? undefined : RETRYABLE.get(code);\n const retryable =\n sameRequestId !== undefined || (code === undefined && status === 503);\n return {\n retryable,\n sameRequestId: sameRequestId ?? retryable,\n ...(afterMs === undefined ? {} : { afterMs }),\n };\n}\n\n/**\n * A request a Wow V10 service answered with a problem: a non-2xx response, a\n * command result that did not succeed, or the `error` event that ends a\n * streamed query.\n */\nexport class WowProblemError extends Error {\n override readonly name = 'WowProblemError';\n /** The problem as the server wrote it. */\n readonly problem: Problem;\n /** The HTTP status. */\n readonly status: number;\n /** The Wow code; absent for an error that is only HTTP's. */\n readonly code?: string;\n readonly violations: readonly Violation[];\n /** The command's result, when the command had a ref. */\n readonly result?: CommandResult;\n /** What a client may do about it. */\n readonly retry: RetryHint;\n /** The error this one explains: the fetcher's, or the stream's. */\n readonly cause?: unknown;\n\n /**\n * @param problem - The problem the server answered with\n * @param options - The response's `Retry-After` in milliseconds, and the\n * error this one explains\n */\n constructor(\n problem: Problem,\n options: { retryAfterMs?: number; cause?: unknown } = {},\n ) {\n super(\n problem.code\n ? `[${problem.code}] ${problem.detail ?? problem.title}`\n : `${problem.status} ${problem.detail ?? problem.title}`,\n );\n this.problem = withExtensions(problem);\n this.status = problem.status;\n if (problem.code !== undefined) this.code = problem.code;\n this.violations = problem.violations ?? [];\n if (problem.result !== undefined) this.result = problem.result;\n this.retry = retryHintOf(\n problem.code,\n problem.status,\n options.retryAfterMs,\n );\n if (options.cause !== undefined) this.cause = options.cause;\n }\n\n /** Whether the code is a framework one (`wow.*`) rather than the domain's. */\n get isFramework(): boolean {\n return this.code?.startsWith(FRAMEWORK_ERROR_PREFIX) ?? false;\n }\n}\n\n/** Whether `value` reads as a problem: an object with a numeric `status`. */\nexport function isProblem(value: unknown): value is Problem {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { status?: unknown }).status === 'number'\n );\n}\n\n/**\n * The milliseconds of a `Retry-After` header: delay seconds or an HTTP date.\n *\n * @param value - The header's value\n * @param now - The current time, in epoch milliseconds\n */\nexport function parseRetryAfter(\n value: string | null | undefined,\n now: number = Date.now(),\n): number | undefined {\n if (!value) return undefined;\n const trimmed = value.trim();\n if (/^\\d+$/.test(trimmed)) return Number(trimmed) * 1000;\n const date = Date.parse(trimmed);\n return Number.isNaN(date) ? undefined : Math.max(0, date - now);\n}\n\n/**\n * The problem a response that did not succeed carries: its body when it is\n * a problem (or a code the `type` names), else one made of its status.\n *\n * @param response - A response that is not 2xx\n */\nexport async function readProblem(response: Response): Promise<Problem> {\n let body: unknown;\n try {\n body = await response.clone().json();\n } catch {\n // Not JSON, or already read: the status is all there is.\n }\n if (isProblem(body)) {\n const code =\n body.code ??\n (body.type?.startsWith(PROBLEM_TYPE_PREFIX)\n ? body.type.slice(PROBLEM_TYPE_PREFIX.length)\n : undefined);\n return withExtensions({\n ...body,\n type: body.type ?? 'about:blank',\n title: body.title ?? response.statusText,\n ...(code === undefined ? {} : { code }),\n });\n }\n return {\n type: 'about:blank',\n title: response.statusText,\n status: response.status,\n };\n}\n\ninterface ExchangeLike {\n exchange?: { response?: Response };\n cause?: unknown;\n}\n\n/**\n * The {@link WowProblemError} of an error a request rejected with: the\n * fetcher's `ExchangeError` of a response that is not 2xx, read as a problem.\n * Undefined for a failure no server answered (a network error, an abort).\n *\n * @param error - What the request rejected with\n */\nexport async function toWowProblemError(\n error: unknown,\n): Promise<WowProblemError | undefined> {\n if (error instanceof WowProblemError) return error;\n if (typeof error !== 'object' || error === null) return undefined;\n const { exchange, cause } = error as ExchangeLike;\n if (cause instanceof WowProblemError) return cause;\n const response = exchange?.response;\n if (!response || response.ok) return undefined;\n const problem = await readProblem(response);\n const retryAfterMs = parseRetryAfter(response.headers.get('Retry-After'));\n return new WowProblemError(problem, {\n cause: error,\n ...(retryAfterMs === undefined ? {} : { retryAfterMs }),\n });\n}\n"],"mappings":"AAqBA,IAAaA,EAAsB,CAEjC,qBAAsB,2BAEtB,eAAgB,qBAEhB,oBAAqB,0BAErB,kBAAmB,wBAEnB,gBAAiB,sBAEjB,aAAc,mBAEd,kBAAmB,wBAEnB,oBAAqB,0BAErB,iBAAkB,uBAElB,2BAA4B,iCAE5B,0BAA2B,gCAE3B,kBAAmB,wBAEnB,kBAAmB,wBAEnB,aAAc,mBAEd,gBAAiB,sBAEjB,aAAc,mBAEd,oBAAqB,0BAErB,iBAAkB,uBAElB,qBAAsB,2BAEtB,oBAAqB,0BAErB,aAAc,mBAEd,gBAAiB,sBAEjB,cAAe,oBAEf,aAAc,mBAEd,cAAe,mBACjB,EAOaC,EAAyB,OAGzBC,EAAsB,iBA0B7BC,EAAuC,IAAI,IAAI,CACnD,OACA,QACA,SACA,SACA,WACA,OACA,aACA,SACA,YACF,CAAC,EAMD,SAASC,EAAe,EAA2B,CACjD,GAAIC,EAAQ,aAAe,IAAA,GAAW,OAAOA,EAC7C,IAAMC,EAAa,OAAO,YACxB,OAAO,QAAQD,CAAO,CAAC,CAAC,QAAQ,CAACE,KAAU,CAACJ,EAAgB,IAAII,CAAI,CAAC,CACvE,EACA,OAAO,OAAO,KAAKD,CAAU,CAAC,CAAC,SAAW,EACtCD,EACA,CAAE,GAAGA,EAAS,YAAW,CAC/B,CAsBA,IAAMG,EAA0C,IAAI,IAAI,CACtD,CAACR,EAAoB,gBAAiB,EAAI,EAC1C,CAACA,EAAoB,aAAc,EAAI,EACvC,CAACA,EAAoB,oBAAqB,EAAI,EAC9C,CAACA,EAAoB,iBAAkB,EAAI,EAC3C,CAACA,EAAoB,cAAe,EAAK,EACzC,CAACA,EAAoB,aAAc,EAAI,EACvC,CAACA,EAAoB,kBAAmB,EAAI,EAC5C,CAACA,EAAoB,aAAc,EA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AAMC,CAAI,EAAI,IAAA,GAAY,KAAK,IAAI,EAAGA,EAAOC,CAAG,CAChE,CAQA,eAAsBC,EAAY,EAAsC,CACtE,IAAIC,EACJ,GAAI,CACF,EAAO,MAAMC,EAAS,MAAM,CAAC,CAAC,KAAK,CACrC,MAAQ,CAER,CACA,GAAIR,EAAUO,CAAI,EAAG,CACnB,IAAMb,EACJa,EAAK,OACJA,EAAK,MAAM,WAAA,gBAA8B,EACtCA,EAAK,KAAK,MAAM,EAA0B,EAC1C,IAAA,IACN,OAAOpB,EAAe,CACpB,GAAGoB,EACH,KAAMA,EAAK,MAAQ,cACnB,MAAOA,EAAK,OAASC,EAAS,WAC9B,GAAId,IAAS,IAAA,GAAY,CAAC,EAAI,CAAE,MAAK,CACvC,CAAC,CACH,CACA,MAAO,CACL,KAAM,cACN,MAAOc,EAAS,WAChB,OAAQA,EAAS,MACnB,CACF,CAcA,eAAsBC,EACpB,EACsC,CACtC,GAAIC,aAAiBZ,EAAiB,OAAOY,EAC7C,GAAI,OAAOA,GAAU,WAAYA,EAAgB,OACjD,GAAM,CAAE,WAAU,SAAUA,EAC5B,GAAIC,aAAiBb,EAAiB,OAAOa,EAC7C,IAAMH,EAAWI,GAAU,SAC3B,GAAI,CAACJ,GAAYA,EAAS,GAAI,OAC9B,IAAMpB,EAAU,MAAMkB,EAAYE,CAAQ,EACpCK,EAAeX,EAAgBM,EAAS,QAAQ,IAAI,aAAa,CAAC,EACxE,OAAO,IAAIV,EAAgBV,EAAS,CAClC,MAAOsB,EACP,GAAIG,IAAiB,IAAA,GAAY,CAAC,EAAI,CAAE,cAAa,CACvD,CAAC,CACH"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"problem.es.js","names":["FrameworkErrorCodes","FRAMEWORK_ERROR_PREFIX","PROBLEM_TYPE_PREFIX","PROBLEM_MEMBERS","withExtensions","problem","extensions","name","RETRYABLE","retryHintOf","sameRequestId","code","retryable","status","afterMs","WowProblemError","options","isProblem","value","parseRetryAfter","trimmed","date","now","readProblem","body","response","toWowProblemError","error","cause","exchange","retryAfterMs"],"sources":["../../src/v10/problem.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 { CommandResult, Violation } from './wire.js';\n\n/**\n * The framework's error codes (design 05 §3, decisions D102, D103, D130),\n * each answered with the status of the Manifest's `errors` table. A domain\n * rejection has a code of its own, answered with 422 unless the service\n * configures another status.\n */\nexport const FrameworkErrorCodes = {\n /** 401: the request carries no valid credentials. */\n AUTH_UNAUTHENTICATED: 'wow.auth.unauthenticated',\n /** 403: the caller may not send this command. */\n AUTH_FORBIDDEN: 'wow.auth.forbidden',\n /** 403: the aggregate is outside the caller's scope. */\n AGGREGATE_FORBIDDEN: 'wow.aggregate.forbidden',\n /** 400: the command body cannot be read as the command type. */\n COMMAND_MALFORMED: 'wow.command.malformed',\n /** 400: the command failed validation; the problem lists the violations. */\n COMMAND_INVALID: 'wow.command.invalid',\n /** 400: the wait is not a chain the runtime can follow. */\n WAIT_INVALID: 'wow.wait.invalid',\n /** 400: the aggregate does not handle this command. */\n COMMAND_UNHANDLED: 'wow.command.unhandled',\n /** 404: the aggregate does not exist. */\n AGGREGATE_NOT_FOUND: 'wow.aggregate.not-found',\n /** 409: the aggregate already exists. */\n AGGREGATE_EXISTS: 'wow.aggregate.exists',\n /** 409, or 412 with `If-Match`: the aggregate is not at the expected version. */\n AGGREGATE_VERSION_MISMATCH: 'wow.aggregate.version-mismatch',\n /** 409: the request id was used by another command. */\n COMMAND_REQUEST_ID_REUSED: 'wow.command.request-id-reused',\n /** 409: concurrent writers kept winning; retrying with the same request id is safe. */\n COMMAND_CONTENDED: 'wow.command.contended',\n /** 410: the aggregate is deleted; only RestoreAggregate applies. */\n AGGREGATE_DELETED: 'wow.aggregate.deleted',\n /** 429: the node has too many commands in flight; retry later. */\n COMMAND_BUSY: 'wow.command.busy',\n /** 503: whether the command committed is unknown; retrying with the same request id is safe. */\n COMMAND_UNKNOWN: 'wow.command.unknown',\n /** 503: the node is shutting down; retry on another node. */\n NODE_CLOSING: 'wow.node.closing',\n /** 503, with `Retry-After`: a store could not be reached in time; retry later. */\n STORAGE_UNAVAILABLE: 'wow.storage.unavailable',\n /** 503: a scheduled command arrived too long before its due time; it is sent again later. */\n SCHEDULE_NOT_DUE: 'wow.schedule.not-due',\n /** 400: the job command does not fit its job or instance (decision D198). */\n SCHEDULE_JOB_INVALID: 'wow.schedule.job-invalid',\n /** 500: a subscription on the wait chain parked the aggregate. */\n SUBSCRIPTION_PARKED: 'wow.subscription.parked',\n /** 504: the wait ran out of time; the command may have committed. */\n WAIT_TIMEOUT: 'wow.wait.timeout',\n /** 400: the query body cannot be read as a query. */\n QUERY_MALFORMED: 'wow.query.malformed',\n /** 400: the query failed admission; each violation has its code. */\n QUERY_INVALID: 'wow.query.invalid',\n /** 500: the query backend failed to run the query. */\n QUERY_FAILED: 'wow.query.failed',\n /** 503: the query ran longer than its budget allows. */\n QUERY_TIMEOUT: 'wow.query.timeout',\n} as const;\n\n/** A {@link FrameworkErrorCodes} value. */\nexport type FrameworkErrorCode =\n (typeof FrameworkErrorCodes)[keyof typeof FrameworkErrorCodes];\n\n/** The prefix of every framework code, and of no domain code. */\nexport const FRAMEWORK_ERROR_PREFIX = 'wow.';\n\n/** The prefix of a problem's `type` that carries a Wow code. */\nexport const PROBLEM_TYPE_PREFIX = 'urn:wow:error:';\n\n/**\n * An RFC 9457 problem as a Wow V10 service writes it (decisions D101, D102):\n * `type` is `urn:wow:error:<code>`, or `about:blank` for an error that is\n * only HTTP's (a missing route, 406, 415).\n */\nexport interface Problem {\n readonly type: string;\n readonly title: string;\n readonly status: number;\n readonly detail?: string;\n /** The Wow code; absent for an error that is only HTTP's. */\n readonly code?: string;\n readonly violations?: readonly Violation[];\n /** The whole result of a command that has a ref. */\n readonly result?: CommandResult;\n /**\n * The problem's extension members (RFC 9457): every member the server\n * wrote besides the ones above and `instance`, such as a rejection's\n * structured data (decision D211). Absent when it wrote none.\n */\n readonly extensions?: Readonly<Record<string, unknown>>;\n}\n\n/** The members of a problem that are not extension members. */\nconst PROBLEM_MEMBERS: ReadonlySet<string> = new Set([\n 'type',\n 'title',\n 'status',\n 'detail',\n 'instance',\n 'code',\n 'violations',\n 'result',\n 'extensions',\n]);\n\n/**\n * `problem` with its extension members gathered as `extensions` (internal):\n * a problem read from the wire carries them as top-level members.\n */\nfunction withExtensions(problem: Problem): Problem {\n if (problem.extensions !== undefined) return problem;\n const extensions = Object.fromEntries(\n Object.entries(problem).filter(([name]) => !PROBLEM_MEMBERS.has(name)),\n );\n return Object.keys(extensions).length === 0\n ? problem\n : { ...problem, extensions };\n}\n\n/**\n * What a client may do about a failed request: whether retrying can succeed,\n * whether to keep the request id (`Wow-Request-Id`) so the server\n * deduplicates a command that did commit, and how long to wait first.\n */\nexport interface RetryHint {\n readonly retryable: boolean;\n /** Retry with the same `Wow-Request-Id`: a commit is then answered as a duplicate. */\n readonly sameRequestId: boolean;\n /** The server's `Retry-After`, in milliseconds. */\n readonly afterMs?: number;\n}\n\n/**\n * The codes a retry may get past, each with whether to keep the request id:\n * the 503s (`wow.command.unknown`, `wow.node.closing`,\n * `wow.storage.unavailable`, `wow.schedule.not-due`, `wow.query.timeout`),\n * the 429 `wow.command.busy`, the 409 `wow.command.contended` and the 504\n * `wow.wait.timeout`, whose command may have committed.\n */\nconst RETRYABLE: ReadonlyMap<string, boolean> = new Map([\n [FrameworkErrorCodes.COMMAND_UNKNOWN, true],\n [FrameworkErrorCodes.NODE_CLOSING, true],\n [FrameworkErrorCodes.STORAGE_UNAVAILABLE, true],\n [FrameworkErrorCodes.SCHEDULE_NOT_DUE, true],\n [FrameworkErrorCodes.QUERY_TIMEOUT, false],\n [FrameworkErrorCodes.COMMAND_BUSY, true],\n [FrameworkErrorCodes.COMMAND_CONTENDED, true],\n [FrameworkErrorCodes.WAIT_TIMEOUT, true],\n]);\n\n/**\n * The retry hint of a problem with `code` and `status`: a code of the\n * retryable table, or a 503 without a code (a proxy's), may be retried.\n *\n * @param code - The problem's Wow code, if any\n * @param status - The HTTP status\n * @param afterMs - The `Retry-After` the response carried, in milliseconds\n */\nexport function retryHintOf(\n code: string | undefined,\n status: number,\n afterMs?: number,\n): RetryHint {\n const sameRequestId = code === undefined ? undefined : RETRYABLE.get(code);\n const retryable =\n sameRequestId !== undefined || (code === undefined && status === 503);\n return {\n retryable,\n sameRequestId: sameRequestId ?? retryable,\n ...(afterMs === undefined ? {} : { afterMs }),\n };\n}\n\n/**\n * A request a Wow V10 service answered with a problem: a non-2xx response, a\n * command result that did not succeed, or the `error` event that ends a\n * streamed query.\n */\nexport class WowProblemError extends Error {\n override readonly name = 'WowProblemError';\n /** The problem as the server wrote it. */\n readonly problem: Problem;\n /** The HTTP status. */\n readonly status: number;\n /** The Wow code; absent for an error that is only HTTP's. */\n readonly code?: string;\n readonly violations: readonly Violation[];\n /** The command's result, when the command had a ref. */\n readonly result?: CommandResult;\n /** What a client may do about it. */\n readonly retry: RetryHint;\n /** The error this one explains: the fetcher's, or the stream's. */\n readonly cause?: unknown;\n\n /**\n * @param problem - The problem the server answered with\n * @param options - The response's `Retry-After` in milliseconds, and the\n * error this one explains\n */\n constructor(\n problem: Problem,\n options: { retryAfterMs?: number; cause?: unknown } = {},\n ) {\n super(\n problem.code\n ? `[${problem.code}] ${problem.detail ?? problem.title}`\n : `${problem.status} ${problem.detail ?? problem.title}`,\n );\n this.problem = withExtensions(problem);\n this.status = problem.status;\n if (problem.code !== undefined) this.code = problem.code;\n this.violations = problem.violations ?? [];\n if (problem.result !== undefined) this.result = problem.result;\n this.retry = retryHintOf(\n problem.code,\n problem.status,\n options.retryAfterMs,\n );\n if (options.cause !== undefined) this.cause = options.cause;\n }\n\n /** Whether the code is a framework one (`wow.*`) rather than the domain's. */\n get isFramework(): boolean {\n return this.code?.startsWith(FRAMEWORK_ERROR_PREFIX) ?? false;\n }\n}\n\n/** Whether `value` reads as a problem: an object with a numeric `status`. */\nexport function isProblem(value: unknown): value is Problem {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { status?: unknown }).status === 'number'\n );\n}\n\n/**\n * The milliseconds of a `Retry-After` header: delay seconds or an HTTP date.\n *\n * @param value - The header's value\n * @param now - The current time, in epoch milliseconds\n */\nexport function parseRetryAfter(\n value: string | null | undefined,\n now: number = Date.now(),\n): number | undefined {\n if (!value) return undefined;\n const trimmed = value.trim();\n if (/^\\d+$/.test(trimmed)) return Number(trimmed) * 1000;\n const date = Date.parse(trimmed);\n return Number.isNaN(date) ? undefined : Math.max(0, date - now);\n}\n\n/**\n * The problem a response that did not succeed carries: its body when it is\n * a problem (or a code the `type` names), else one made of its status.\n *\n * @param response - A response that is not 2xx\n */\nexport async function readProblem(response: Response): Promise<Problem> {\n let body: unknown;\n try {\n body = await response.clone().json();\n } catch {\n // Not JSON, or already read: the status is all there is.\n }\n if (isProblem(body)) {\n const code =\n body.code ??\n (body.type?.startsWith(PROBLEM_TYPE_PREFIX)\n ? body.type.slice(PROBLEM_TYPE_PREFIX.length)\n : undefined);\n return withExtensions({\n ...body,\n type: body.type ?? 'about:blank',\n title: body.title ?? response.statusText,\n ...(code === undefined ? {} : { code }),\n });\n }\n return {\n type: 'about:blank',\n title: response.statusText,\n status: response.status,\n };\n}\n\ninterface ExchangeLike {\n exchange?: { response?: Response };\n cause?: unknown;\n}\n\n/**\n * The {@link WowProblemError} of an error a request rejected with: the\n * fetcher's `ExchangeError` of a response that is not 2xx, read as a problem.\n * Undefined for a failure no server answered (a network error, an abort).\n *\n * @param error - What the request rejected with\n */\nexport async function toWowProblemError(\n error: unknown,\n): Promise<WowProblemError | undefined> {\n if (error instanceof WowProblemError) return error;\n if (typeof error !== 'object' || error === null) return undefined;\n const { exchange, cause } = error as ExchangeLike;\n if (cause instanceof WowProblemError) return cause;\n const response = exchange?.response;\n if (!response || response.ok) return undefined;\n const problem = await readProblem(response);\n const retryAfterMs = parseRetryAfter(response.headers.get('Retry-After'));\n return new WowProblemError(problem, {\n cause: error,\n ...(retryAfterMs === undefined ? {} : { retryAfterMs }),\n });\n}\n"],"mappings":";AAqBA,IAAaA,IAAsB;CAEjC,sBAAsB;CAEtB,gBAAgB;CAEhB,qBAAqB;CAErB,mBAAmB;CAEnB,iBAAiB;CAEjB,cAAc;CAEd,mBAAmB;CAEnB,qBAAqB;CAErB,kBAAkB;CAElB,4BAA4B;CAE5B,2BAA2B;CAE3B,mBAAmB;CAEnB,mBAAmB;CAEnB,cAAc;CAEd,iBAAiB;CAEjB,cAAc;CAEd,qBAAqB;CAErB,kBAAkB;CAElB,sBAAsB;CAEtB,qBAAqB;CAErB,cAAc;CAEd,iBAAiB;CAEjB,eAAe;CAEf,cAAc;CAEd,eAAe;AACjB,GAOaC,IAAyB,QAGzBC,IAAsB,kBA0B7BC,oBAAuC,IAAI,IAAI;CACnD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAMD,SAASC,EAAe,GAA2B;CACjD,IAAIC,EAAQ,eAAe,KAAA,GAAW,OAAOA;CAC7C,IAAMC,IAAa,OAAO,YACxB,OAAO,QAAQD,CAAO,CAAC,CAAC,QAAQ,CAACE,OAAU,CAACJ,EAAgB,IAAII,CAAI,CAAC,CACvE;CACA,OAAO,OAAO,KAAKD,CAAU,CAAC,CAAC,WAAW,IACtCD,IACA;EAAE,GAAGA;EAAS;CAAW;AAC/B;AAsBA,IAAMG,oBAA0C,IAAI,IAAI;CACtD,CAACR,EAAoB,iBAAiB,EAAI;CAC1C,CAACA,EAAoB,cAAc,EAAI;CACvC,CAACA,EA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=require("./http.cjs"),t=require("./streams.cjs");var n=class{constructor(e,t={}){this.path=e,this.client=t}async list(t,n){return e.json(await this.post(`list`,t,n))}async listStream(e,n){return t.queryRows(await this.post(`list`,e,n,`text/event-stream`))}async paged(t,n){return e.json(await this.post(`paged`,t,n))}async cursor(t,n){return e.json(await this.post(`cursor`,t,n))}async single(t,n){return e.json(await this.post(`single`,t,n))}async count(t,n){return e.json(await this.post(`count`,t,n))}async aggregate(t,n){return e.json(await this.post(`aggregate`,t,n))}async describe(t,n){let r=await e.send(this.client,{method:`GET`,path:this.path,headers:{[e.WowV10Headers.IF_NONE_MATCH]:t===void 0?void 0:`"${t}"`},options:n,notModified:!0}),i=e.entityTag(r);return r.status===304?{notModified:!0,version:i??t??``}:{notModified:!1,...i===void 0?{}:{version:i},descriptor:await e.json(r)}}post(t,n,r,i){return e.send(this.client,{method:`POST`,path:this.path,headers:{Accept:i},body:{...n,kind:t},options:r})}};function r(e,t){return`/${e.context}/${e.name}/${t}/query`}var i=class extends n{constructor(e,t){super(r(e,`snapshot`),t),this.type=e}},a=class extends n{constructor(e,t){super(r(e,`events`),t),this.type=e}},o=class{constructor(e={}){this.client=e}async list(t){return e.json(await e.send(this.client,{method:`GET`,path:`/wow/dataset`,options:t}))}dataset(e,t){return new n(`/wow/dataset/${encodeURIComponent(e)}/${encodeURIComponent(t)}/query`,this.client)}};exports.DatasetClient=o,exports.EventQueryClient=a,exports.QueryModelClient=n,exports.SnapshotQueryClient=i,exports.queryPath=r;
2
- //# sourceMappingURL=queries.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"queries.cjs","names":["json","queryRows","send","WowV10Headers","entityTag","require_http","require_streams","QueryModelClient","path","client","query","options","response","version","tag","accept","queryPath","type","model","SnapshotQueryClient","EventQueryClient","DatasetClient","context","dataset"],"sources":["../../src/v10/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 { 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 WowV10Headers,\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 { queryRows } from './streams.js';\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 V10 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 V10 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 V10 service: `POST {path}` with a body\n * whose `kind` names the operation, `GET {path}` for the capability\n * descriptor (decisions D127, D145).\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 */\n constructor(\n readonly path: string,\n readonly client: WowClientOptions = {},\n ) {}\n\n /** The records that match, at most `limit` (the server's default when absent). */\n async list(\n query: FilterListQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<R[]> {\n return json<R[]>(await this.post('list', query, options));\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.\n */\n async listStream(\n query: FilterListQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<ReadableStream<R>> {\n return queryRows<R>(\n await this.post('list', query, options, 'text/event-stream'),\n );\n }\n\n /** One page of the records that match, and their total. */\n async paged(\n query: PagedQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<PagedResult<R>> {\n return json<PagedResult<R>>(await this.post('paged', query, options));\n }\n\n /** One page of a forward-only cursor over the records that match. */\n async cursor(\n query: CursorQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<CursorPage<R>> {\n return json<CursorPage<R>>(await this.post('cursor', query, options));\n }\n\n /** The first record that matches; rejects with 404 when none does. */\n async single(\n query: FilterSingleQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<R> {\n return json<R>(await this.post('single', query, options));\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 [WowV10Headers.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 ): Promise<Response> {\n return send(this.client, {\n method: 'POST',\n path: this.path,\n headers: { Accept: accept },\n body: { ...query, kind },\n options,\n });\n }\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(queryPath(type, 'snapshot'), client);\n }\n}\n\n/**\n * Queries an aggregate type's event streams (decision D131), one aggregate\n * at a time: a filter names its `aggregateId`, and may bound `version` or\n * `commitTime`.\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 super(queryPath(type, 'events'), client);\n }\n}\n\n/**\n * The datasets of a Wow V10 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":"yDAgGA,IAAaO,EAAb,KAAiE,CAK/D,YACE,EACA,EAAoC,CAAC,EACrC,CAFS,KAAA,KAAAC,EACA,KAAA,OAAAC,CACR,CAGH,MAAM,KACJ,EACA,EACc,CACd,OAAOT,EAAAA,KAAU,MAAM,KAAK,KAAK,OAAQU,EAAOC,CAAO,CAAC,CAC1D,CAMA,MAAM,WACJ,EACA,EAC4B,CAC5B,OAAOV,EAAAA,UACL,MAAM,KAAK,KAAK,OAAQS,EAAOC,EAAS,mBAAmB,CAC7D,CACF,CAGA,MAAM,MACJ,EACA,EACyB,CACzB,OAAOX,EAAAA,KAAqB,MAAM,KAAK,KAAK,QAASU,EAAOC,CAAO,CAAC,CACtE,CAGA,MAAM,OACJ,EACA,EACwB,CACxB,OAAOX,EAAAA,KAAoB,MAAM,KAAK,KAAK,SAAUU,EAAOC,CAAO,CAAC,CACtE,CAGA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Ub,CAAyD,CAKjE,YACE,EACA,EACA,CACA,MAAMS,EAAUC,EAAM,QAAQ,EAAGR,CAAM,EAH9B,KAAA,KAAAQ,CAIX,CACF,EAOaI,EAAb,KAA2B,CAEzB,YAAY,EAAoC,CAAC,EAAG,CAA/B,KAAA,OAAAZ,CAAgC,CAGrD,MAAM,KAAK,EAAmD,CAC5D,OAAOT,EAAAA,KACL,MAAME,EAAAA,KAAK,KAAK,OAAQ,CAAE,OAAQ,MAAO,KAAM,eAAgB,SAAQ,CAAC,CAC1E,CACF,CAQA,QACE,EACA,EAC6B,CAC7B,OAAO,IAAIK,EACT,gBAAgB,mBAAmBe,CAAO,EAAE,GAAG,mBAAmBC,CAAO,EAAE,QAC3E,KAAK,MACP,CACF,CACF"}
@@ -1,88 +0,0 @@
1
- import { WowV10Headers as e, entityTag as t, json as n, send as r } from "./http.es.js";
2
- import { queryRows as i } from "./streams.es.js";
3
- //#region src/v10/queries.ts
4
- var a = class {
5
- constructor(e, t = {}) {
6
- this.path = e, this.client = t;
7
- }
8
- async list(e, t) {
9
- return n(await this.post("list", e, t));
10
- }
11
- async listStream(e, t) {
12
- return i(await this.post("list", e, t, "text/event-stream"));
13
- }
14
- async paged(e, t) {
15
- return n(await this.post("paged", e, t));
16
- }
17
- async cursor(e, t) {
18
- return n(await this.post("cursor", e, t));
19
- }
20
- async single(e, t) {
21
- return n(await this.post("single", e, t));
22
- }
23
- async count(e, t) {
24
- return n(await this.post("count", e, t));
25
- }
26
- async aggregate(e, t) {
27
- return n(await this.post("aggregate", e, t));
28
- }
29
- async describe(i, a) {
30
- let o = await r(this.client, {
31
- method: "GET",
32
- path: this.path,
33
- headers: { [e.IF_NONE_MATCH]: i === void 0 ? void 0 : `"${i}"` },
34
- options: a,
35
- notModified: !0
36
- }), s = t(o);
37
- return o.status === 304 ? {
38
- notModified: !0,
39
- version: s ?? i ?? ""
40
- } : {
41
- notModified: !1,
42
- ...s === void 0 ? {} : { version: s },
43
- descriptor: await n(o)
44
- };
45
- }
46
- post(e, t, n, i) {
47
- return r(this.client, {
48
- method: "POST",
49
- path: this.path,
50
- headers: { Accept: i },
51
- body: {
52
- ...t,
53
- kind: e
54
- },
55
- options: n
56
- });
57
- }
58
- };
59
- function o(e, t) {
60
- return `/${e.context}/${e.name}/${t}/query`;
61
- }
62
- var s = class extends a {
63
- constructor(e, t) {
64
- super(o(e, "snapshot"), t), this.type = e;
65
- }
66
- }, c = class extends a {
67
- constructor(e, t) {
68
- super(o(e, "events"), t), this.type = e;
69
- }
70
- }, l = class {
71
- constructor(e = {}) {
72
- this.client = e;
73
- }
74
- async list(e) {
75
- return n(await r(this.client, {
76
- method: "GET",
77
- path: "/wow/dataset",
78
- options: e
79
- }));
80
- }
81
- dataset(e, t) {
82
- return new a(`/wow/dataset/${encodeURIComponent(e)}/${encodeURIComponent(t)}/query`, this.client);
83
- }
84
- };
85
- //#endregion
86
- export { l as DatasetClient, c as EventQueryClient, a as QueryModelClient, s as SnapshotQueryClient, o as queryPath };
87
-
88
- //# sourceMappingURL=queries.es.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"queries.es.js","names":["QueryModelClient","path","client","json","query","options","queryRows","response","send","WowV10Headers","version","tag","entityTag","accept","queryPath","type","model","SnapshotQueryClient","EventQueryClient","DatasetClient","context","dataset"],"sources":["../../src/v10/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 { 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 WowV10Headers,\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 { queryRows } from './streams.js';\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 V10 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 V10 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 V10 service: `POST {path}` with a body\n * whose `kind` names the operation, `GET {path}` for the capability\n * descriptor (decisions D127, D145).\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 */\n constructor(\n readonly path: string,\n readonly client: WowClientOptions = {},\n ) {}\n\n /** The records that match, at most `limit` (the server's default when absent). */\n async list(\n query: FilterListQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<R[]> {\n return json<R[]>(await this.post('list', query, options));\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.\n */\n async listStream(\n query: FilterListQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<ReadableStream<R>> {\n return queryRows<R>(\n await this.post('list', query, options, 'text/event-stream'),\n );\n }\n\n /** One page of the records that match, and their total. */\n async paged(\n query: PagedQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<PagedResult<R>> {\n return json<PagedResult<R>>(await this.post('paged', query, options));\n }\n\n /** One page of a forward-only cursor over the records that match. */\n async cursor(\n query: CursorQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<CursorPage<R>> {\n return json<CursorPage<R>>(await this.post('cursor', query, options));\n }\n\n /** The first record that matches; rejects with 404 when none does. */\n async single(\n query: FilterSingleQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<R> {\n return json<R>(await this.post('single', query, options));\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 [WowV10Headers.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 ): Promise<Response> {\n return send(this.client, {\n method: 'POST',\n path: this.path,\n headers: { Accept: accept },\n body: { ...query, kind },\n options,\n });\n }\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(queryPath(type, 'snapshot'), client);\n }\n}\n\n/**\n * Queries an aggregate type's event streams (decision D131), one aggregate\n * at a time: a filter names its `aggregateId`, and may bound `version` or\n * `commitTime`.\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 super(queryPath(type, 'events'), client);\n }\n}\n\n/**\n * The datasets of a Wow V10 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":";;;AAgGA,IAAaA,IAAb,MAAiE;CAK/D,YACE,GACA,IAAoC,CAAC,GACrC;EADS,AADA,KAAA,OAAAC,GACA,KAAA,SAAAC;CACR;CAGH,MAAM,KACJ,GACA,GACc;EACd,OAAOC,EAAU,MAAM,KAAK,KAAK,QAAQC,GAAOC,CAAO,CAAC;CAC1D;CAMA,MAAM,WACJ,GACA,GAC4B;EAC5B,OAAOC,EACL,MAAM,KAAK,KAAK,QAAQF,GAAOC,GAAS,mBAAmB,CAC7D;CACF;CAGA,MAAM,MACJ,GACA,GACyB;EACzB,OAAOF,EAAqB,MAAM,KAAK,KAAK,SAASC,GAAOC,CAAO,CAAC;CACtE;CAGA,MAAM,OACJ,GACA,GACwB;EACxB,OAAOF,EAAoB,MAAM,KAAK,KAAK,UAAUC,GAAOC,CAAO,CAAC;CACtE;CAGA,MAAM,OACJ,GACA,GACY;EACZ,OAAOF,EAAQ,MAAM,KAAK,KAAK,UAAUC,GAAOC,CAAO,CAAC;CAC1D;CAGA,MAAM,MACJ,GACA,GACsB;EACtB,OAAOF,EAAkB,MAAM,KAAK,KAAK,SAASC,GAAOC,CAAO,CAAC;CACnE;CAGA,MAAM,UACJ,GACA,GACgB;EAChB,OAAOF,EAAY,MAAM,KAAK,KAAK,aAAaC,GAAOC,CAAO,CAAC;CACjE;CAMA,MAAM,SACJ,GACA,GAC2B;EAC3B,IAAME,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