@ahoo-wang/wow-client 10.0.0-alpha.6 → 10.0.0-beta.1
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.
- package/README.md +77 -23
- package/README.zh-CN.md +67 -19
- package/dist/commands.cjs +1 -1
- package/dist/commands.cjs.map +1 -1
- package/dist/commands.d.cts +134 -61
- package/dist/commands.d.ts +134 -61
- package/dist/commands.es.js +129 -59
- package/dist/commands.es.js.map +1 -1
- package/dist/developmentCaller.cjs +2 -0
- package/dist/developmentCaller.cjs.map +1 -0
- package/dist/developmentCaller.d.cts +61 -0
- package/dist/developmentCaller.d.ts +61 -0
- package/dist/developmentCaller.es.js +26 -0
- package/dist/developmentCaller.es.js.map +1 -0
- package/dist/dsl/aggregation/admit.cjs +1 -1
- package/dist/dsl/aggregation/admit.cjs.map +1 -1
- package/dist/dsl/aggregation/admit.es.js +93 -93
- package/dist/dsl/aggregation/admit.es.js.map +1 -1
- package/dist/dsl/aggregation/builders.cjs +1 -1
- package/dist/dsl/aggregation/builders.cjs.map +1 -1
- package/dist/dsl/aggregation/builders.d.cts +20 -20
- package/dist/dsl/aggregation/builders.d.ts +20 -20
- package/dist/dsl/aggregation/builders.es.js +88 -88
- package/dist/dsl/aggregation/builders.es.js.map +1 -1
- package/dist/dsl/aggregation/derived.cjs.map +1 -1
- package/dist/dsl/aggregation/derived.d.cts +8 -8
- package/dist/dsl/aggregation/derived.d.ts +8 -8
- package/dist/dsl/aggregation/derived.es.js +1 -2
- package/dist/dsl/aggregation/derived.es.js.map +1 -1
- package/dist/dsl/aggregation/expressionTrees.cjs.map +1 -1
- package/dist/dsl/aggregation/expressionTrees.es.js +1 -2
- package/dist/dsl/aggregation/having.cjs +1 -1
- package/dist/dsl/aggregation/having.cjs.map +1 -1
- package/dist/dsl/aggregation/having.d.cts +12 -12
- package/dist/dsl/aggregation/having.d.ts +12 -12
- package/dist/dsl/aggregation/having.es.js +33 -33
- package/dist/dsl/aggregation/having.es.js.map +1 -1
- package/dist/dsl/aggregation/sort.cjs.map +1 -1
- package/dist/dsl/aggregation/sort.es.js +1 -2
- package/dist/dsl/aggregation/types.cjs +1 -1
- package/dist/dsl/aggregation/types.cjs.map +1 -1
- package/dist/dsl/aggregation/types.d.cts +69 -69
- package/dist/dsl/aggregation/types.d.ts +69 -69
- package/dist/dsl/aggregation/types.es.js +15 -16
- package/dist/dsl/aggregation/types.es.js.map +1 -1
- package/dist/dsl/constantName.cjs +2 -0
- package/dist/dsl/constantName.cjs.map +1 -0
- package/dist/dsl/constantName.d.cts +9 -0
- package/dist/dsl/constantName.d.ts +9 -0
- package/dist/dsl/constantName.es.js +7 -0
- package/dist/dsl/constantName.es.js.map +1 -0
- package/dist/dsl/cursorQuery.cjs.map +1 -1
- package/dist/dsl/cursorQuery.es.js +1 -2
- package/dist/dsl/deletionState.cjs +1 -1
- package/dist/dsl/deletionState.cjs.map +1 -1
- package/dist/dsl/deletionState.d.cts +3 -3
- package/dist/dsl/deletionState.d.ts +3 -3
- package/dist/dsl/deletionState.es.js +2 -3
- package/dist/dsl/deletionState.es.js.map +1 -1
- package/dist/dsl/descriptor.cjs +1 -1
- package/dist/dsl/descriptor.cjs.map +1 -1
- package/dist/dsl/descriptor.d.cts +99 -42
- package/dist/dsl/descriptor.d.ts +99 -42
- package/dist/dsl/descriptor.es.js +37 -29
- package/dist/dsl/descriptor.es.js.map +1 -1
- package/dist/dsl/field.cjs.map +1 -1
- package/dist/dsl/field.es.js +1 -2
- package/dist/dsl/filter/builders.cjs +1 -1
- package/dist/dsl/filter/builders.cjs.map +1 -1
- package/dist/dsl/filter/builders.d.cts +53 -53
- package/dist/dsl/filter/builders.d.ts +53 -53
- package/dist/dsl/filter/builders.es.js +111 -111
- package/dist/dsl/filter/builders.es.js.map +1 -1
- package/dist/dsl/filter/datePattern.cjs.map +1 -1
- package/dist/dsl/filter/datePattern.es.js +1 -2
- package/dist/dsl/filter/operator.cjs +1 -1
- package/dist/dsl/filter/operator.cjs.map +1 -1
- package/dist/dsl/filter/operator.d.cts +57 -57
- package/dist/dsl/filter/operator.d.ts +57 -57
- package/dist/dsl/filter/operator.es.js +4 -5
- package/dist/dsl/filter/operator.es.js.map +1 -1
- package/dist/dsl/filter/scope.cjs +1 -1
- package/dist/dsl/filter/scope.cjs.map +1 -1
- package/dist/dsl/filter/scope.es.js +12 -12
- package/dist/dsl/filter/scope.es.js.map +1 -1
- package/dist/dsl/filter/validate.cjs +1 -1
- package/dist/dsl/filter/validate.cjs.map +1 -1
- package/dist/dsl/filter/validate.es.js +23 -23
- package/dist/dsl/filter/validate.es.js.map +1 -1
- package/dist/dsl/pagination.cjs.map +1 -1
- package/dist/dsl/pagination.es.js +1 -2
- package/dist/dsl/projection.cjs.map +1 -1
- package/dist/dsl/projection.d.cts +1 -1
- package/dist/dsl/projection.d.ts +1 -1
- package/dist/dsl/projection.es.js +1 -2
- package/dist/dsl/projection.es.js.map +1 -1
- package/dist/dsl/queryErrorCodes.cjs +1 -1
- package/dist/dsl/queryErrorCodes.cjs.map +1 -1
- package/dist/dsl/queryErrorCodes.d.cts +59 -48
- package/dist/dsl/queryErrorCodes.d.ts +59 -48
- package/dist/dsl/queryErrorCodes.es.js +51 -50
- package/dist/dsl/queryErrorCodes.es.js.map +1 -1
- package/dist/dsl/queryable.cjs +1 -1
- package/dist/dsl/queryable.cjs.map +1 -1
- package/dist/dsl/queryable.d.cts +25 -21
- package/dist/dsl/queryable.d.ts +25 -21
- package/dist/dsl/queryable.es.js +5 -5
- package/dist/dsl/queryable.es.js.map +1 -1
- package/dist/dsl/sort.cjs +1 -1
- package/dist/dsl/sort.cjs.map +1 -1
- package/dist/dsl/sort.d.cts +2 -2
- package/dist/dsl/sort.d.ts +2 -2
- package/dist/dsl/sort.es.js +4 -5
- package/dist/dsl/sort.es.js.map +1 -1
- package/dist/dsl.cjs +1 -1
- package/dist/dsl.es.js +3 -3
- package/dist/exactJson.cjs.map +1 -1
- package/dist/exactJson.d.cts +4 -4
- package/dist/exactJson.d.ts +4 -4
- package/dist/exactJson.es.js +1 -2
- package/dist/exactJson.es.js.map +1 -1
- package/dist/frameworkErrors.cjs +2 -0
- package/dist/frameworkErrors.cjs.map +1 -0
- package/dist/frameworkErrors.d.cts +121 -0
- package/dist/frameworkErrors.d.ts +121 -0
- package/dist/frameworkErrors.es.js +95 -0
- package/dist/frameworkErrors.es.js.map +1 -0
- package/dist/http.cjs +1 -1
- package/dist/http.cjs.map +1 -1
- package/dist/http.d.cts +4 -7
- package/dist/http.d.ts +4 -7
- package/dist/http.es.js +12 -20
- package/dist/http.es.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +9 -7
- package/dist/index.d.ts +9 -7
- package/dist/index.es.js +11 -9
- package/dist/manifest.cjs +1 -1
- package/dist/manifest.cjs.map +1 -1
- package/dist/manifest.d.cts +37 -95
- package/dist/manifest.d.ts +37 -95
- package/dist/manifest.es.js +12 -7
- package/dist/manifest.es.js.map +1 -1
- package/dist/manifestTypes.d.cts +195 -0
- package/dist/manifestTypes.d.ts +195 -0
- package/dist/problem.cjs +1 -1
- package/dist/problem.cjs.map +1 -1
- package/dist/problem.d.cts +76 -115
- package/dist/problem.d.ts +76 -115
- package/dist/problem.es.js +45 -80
- package/dist/problem.es.js.map +1 -1
- package/dist/queries.cjs +1 -1
- package/dist/queries.cjs.map +1 -1
- package/dist/queries.d.cts +28 -51
- package/dist/queries.d.ts +28 -51
- package/dist/queries.es.js +49 -40
- package/dist/queries.es.js.map +1 -1
- package/dist/routes.cjs +2 -0
- package/dist/routes.cjs.map +1 -0
- package/dist/routes.d.cts +49 -0
- package/dist/routes.d.ts +49 -0
- package/dist/routes.es.js +33 -0
- package/dist/routes.es.js.map +1 -0
- package/dist/state.cjs +1 -1
- package/dist/state.cjs.map +1 -1
- package/dist/state.d.cts +56 -11
- package/dist/state.d.ts +56 -11
- package/dist/state.es.js +56 -21
- package/dist/state.es.js.map +1 -1
- package/dist/streams.cjs +1 -1
- package/dist/streams.cjs.map +1 -1
- package/dist/streams.d.cts +17 -13
- package/dist/streams.d.ts +17 -13
- package/dist/streams.es.js +50 -50
- package/dist/streams.es.js.map +1 -1
- package/dist/testing/wire.cjs +2 -0
- package/dist/testing/wire.cjs.map +1 -0
- package/dist/testing/wire.d.cts +29 -0
- package/dist/testing/wire.d.ts +29 -0
- package/dist/testing/wire.es.js +88 -0
- package/dist/testing/wire.es.js.map +1 -0
- package/dist/testing.cjs +1 -0
- package/dist/testing.d.cts +12 -0
- package/dist/testing.d.ts +12 -0
- package/dist/testing.es.js +3 -0
- package/dist/wait.cjs +1 -1
- package/dist/wait.cjs.map +1 -1
- package/dist/wait.d.cts +68 -19
- package/dist/wait.d.ts +68 -19
- package/dist/wait.es.js +61 -14
- package/dist/wait.es.js.map +1 -1
- package/dist/wire.cjs +1 -1
- package/dist/wire.cjs.map +1 -1
- package/dist/wire.d.cts +101 -50
- package/dist/wire.d.ts +101 -50
- package/dist/wire.es.js +17 -6
- package/dist/wire.es.js.map +1 -1
- package/package.json +23 -3
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ const active = await carts.list(
|
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
`single`, `list`, `paged`, `cursor`, `count` and `aggregate` each answer one
|
|
53
|
-
operation; `
|
|
53
|
+
operation; `stream` reads a list as server-sent events and resumes a
|
|
54
54
|
stream the service cut off where it stopped. `describe(version?)` reads the
|
|
55
55
|
query model's capability descriptor (`GET` on the same route): the fields
|
|
56
56
|
with the operators, sorts and aggregation each admits, and the limits;
|
|
@@ -79,37 +79,57 @@ declare const fetcher: Fetcher;
|
|
|
79
79
|
-->
|
|
80
80
|
|
|
81
81
|
```ts
|
|
82
|
-
import {
|
|
83
|
-
|
|
84
|
-
const commands = new
|
|
85
|
-
const result = await commands.
|
|
86
|
-
'
|
|
87
|
-
{ productId: 'p-1', quantity: 1 },
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
import { CommandClient, WaitPlan } from '@ahoo-wang/wow-client';
|
|
83
|
+
|
|
84
|
+
const commands = new CommandClient({ fetcher });
|
|
85
|
+
const result = await commands.wait({
|
|
86
|
+
command: 'shop.cart.AddCartItem',
|
|
87
|
+
body: { productId: 'p-1', quantity: 1 },
|
|
88
|
+
id: 'cart-42',
|
|
89
|
+
wait: WaitPlan.SNAPSHOT,
|
|
90
|
+
timeout: 10_000,
|
|
91
|
+
});
|
|
90
92
|
```
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
`command` is the full type name, `context.aggregate.Command`. The command is
|
|
95
|
+
sent by its route as the service's Manifest lists it: the Manifest the client
|
|
96
|
+
is given (`new CommandClient(options, { manifest })`, a whole Manifest or a
|
|
97
|
+
generated client's `manifest.ts`, its routes alone), else the service's,
|
|
98
|
+
fetched once (`GET /wow/manifest`). A command that
|
|
99
|
+
may create its aggregate leaves `id` out and goes by the route without one. As with Kotlin's `CommandClient`,
|
|
100
|
+
`send` answers once the command is accepted, `wait` with the result its plan
|
|
101
|
+
ends with (the server's default plan when there is none), and `stream` one
|
|
102
|
+
`CommandResult` per hop. `wait` is a `WaitPlan`, as Kotlin's:
|
|
103
|
+
`WaitPlan.ACCEPTED`, `COMMITTED`, `SNAPSHOT`, or `WaitPlan.of(...hops)` of the
|
|
104
|
+
`wait` hops (`accepted`, `committed`, `snapshot`, or a subscription's
|
|
105
|
+
`handled`, also across a saga's derived commands), `.within(ms)` its timeout;
|
|
106
|
+
`timeout` is in milliseconds and overrides it. `parseWaitPlan` and
|
|
107
|
+
`formatWaitPlan` read and write the `Wow-Wait` header. `targetTenant` and `targetScope`
|
|
108
|
+
(`{ ownerId?, spaceId? }`) act in another tenant, owner or space. Every command carries a request id
|
|
97
109
|
(`Wow-Request-Id`), given or generated: a retry with the same one is answered
|
|
98
110
|
as the first commit's duplicate, and `requestIdOf(error)` hands back the one
|
|
99
|
-
a failure was sent with.
|
|
100
|
-
aggregate lists (
|
|
111
|
+
a failure was sent with. A system command, such as a lifecycle
|
|
112
|
+
command an aggregate lists (`LifecycleCommands.DELETE_AGGREGATE`, …), also
|
|
113
|
+
names the aggregate's `type: { context, name }`, and a lifecycle command its
|
|
114
|
+
`id`.
|
|
101
115
|
|
|
102
116
|
`StateClient` reads an aggregate's state, at a version or a time, and its
|
|
103
|
-
trace; `
|
|
117
|
+
trace; `find(id, options?)` answers `undefined` for an aggregate that does
|
|
118
|
+
not exist (404 `wow.aggregate.not-found`), where `get` and `read` reject, and
|
|
119
|
+
any other 404 still rejects; `fetchManifest` reads the service's Manifest (`GET /wow/manifest`).
|
|
104
120
|
|
|
105
121
|
## Errors
|
|
106
122
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
`
|
|
111
|
-
|
|
112
|
-
`
|
|
123
|
+
`send` and `wait` resolve only a result that succeeded, and map the rest by
|
|
124
|
+
the result's status, as Kotlin's `CommandClient`: a rejected command, by its
|
|
125
|
+
aggregate or at admission, rejects with a `CommandRejectedError` (its `code`,
|
|
126
|
+
its `result`, and the `problem` when the service answered one); anything
|
|
127
|
+
else with a `WowProblemError`: the RFC 9457 `problem` as written, its
|
|
128
|
+
`status`, its Wow `code`, its `violations`, and the `result` when the
|
|
129
|
+
service sent one. `stream` emits every result after admission, whatever
|
|
130
|
+
its status; a command refused at admission rejects the `stream` call itself
|
|
131
|
+
with a `WowProblemError` whose `result.status` is `rejected`. A stream that
|
|
132
|
+
fails midway errors with the same error, so a `for await` throws it.
|
|
113
133
|
|
|
114
134
|
```ts
|
|
115
135
|
import { FrameworkErrorCodes, WowProblemError } from '@ahoo-wang/wow-client';
|
|
@@ -138,6 +158,40 @@ without the clients: no Fetcher, and none of the stream patches
|
|
|
138
158
|
`aggregation.query()` admits a whole aggregation against the rules Wow
|
|
139
159
|
enforces on arrival, so a bad query fails where it was built.
|
|
140
160
|
|
|
161
|
+
## Test against a service: `@ahoo-wang/wow-client/testing`
|
|
162
|
+
|
|
163
|
+
A development run of a Wow service reads its caller from headers
|
|
164
|
+
(`DevelopmentCallerHeaders`); `developmentCaller` sends them on every request
|
|
165
|
+
of a fetcher. `commandResultOf`, `problemOf`, `problemResponse` and
|
|
166
|
+
`snapshotOf` build the service's answers for a fake. The entry loads no test
|
|
167
|
+
runner.
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
import { Fetcher } from '@ahoo-wang/fetcher';
|
|
171
|
+
import {
|
|
172
|
+
commandResultOf,
|
|
173
|
+
developmentCaller,
|
|
174
|
+
problemOf,
|
|
175
|
+
problemResponse,
|
|
176
|
+
} from '@ahoo-wang/wow-client/testing';
|
|
177
|
+
|
|
178
|
+
const fetcher = new Fetcher({ baseURL: 'http://localhost:8080' });
|
|
179
|
+
fetcher.interceptors.request.use(
|
|
180
|
+
developmentCaller({ user: 'alice', owner: 'alice', tenant: 'acme' }),
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
const mug = {
|
|
184
|
+
type: { context: 'eshop-catalog', name: 'product' },
|
|
185
|
+
tenantId: 'acme',
|
|
186
|
+
id: 'mug',
|
|
187
|
+
};
|
|
188
|
+
const refused = problemResponse(
|
|
189
|
+
problemOf(409, 'wow.command.refused', {
|
|
190
|
+
result: commandResultOf(mug, { status: 'rejected' }),
|
|
191
|
+
}),
|
|
192
|
+
);
|
|
193
|
+
```
|
|
194
|
+
|
|
141
195
|
## Documentation
|
|
142
196
|
|
|
143
197
|
- [TypeScript guide](https://wow.ahoo.me/typescript/)
|
package/README.zh-CN.md
CHANGED
|
@@ -47,7 +47,7 @@ const active = await carts.list(
|
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
`single`、`list`、`paged`、`cursor`、`count`、`aggregate` 各对应一种操作;
|
|
50
|
-
`
|
|
50
|
+
`stream` 以服务端推送事件读列表,服务中断的流从中断处续读。`describe(version?)`
|
|
51
51
|
读查询模型的能力描述(同一路由的 `GET`):每个字段可用的运算符、排序与聚合,以及
|
|
52
52
|
各项上限;传入已持有的版本,304 时返回 `{ notModified: true, version }`。
|
|
53
53
|
`EventQueryClient` 以同样方式查询聚合的事件流,`QueryModelClient` 查询任意查询路由,
|
|
@@ -73,32 +73,47 @@ declare const fetcher: Fetcher;
|
|
|
73
73
|
-->
|
|
74
74
|
|
|
75
75
|
```ts
|
|
76
|
-
import {
|
|
77
|
-
|
|
78
|
-
const commands = new
|
|
79
|
-
const result = await commands.
|
|
80
|
-
'
|
|
81
|
-
{ productId: 'p-1', quantity: 1 },
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
import { CommandClient, WaitPlan } from '@ahoo-wang/wow-client';
|
|
77
|
+
|
|
78
|
+
const commands = new CommandClient({ fetcher });
|
|
79
|
+
const result = await commands.wait({
|
|
80
|
+
command: 'shop.cart.AddCartItem',
|
|
81
|
+
body: { productId: 'p-1', quantity: 1 },
|
|
82
|
+
id: 'cart-42',
|
|
83
|
+
wait: WaitPlan.SNAPSHOT,
|
|
84
|
+
timeout: 10_000,
|
|
85
|
+
});
|
|
84
86
|
```
|
|
85
87
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
`
|
|
88
|
+
`command` 是完整类型名 `context.aggregate.Command`。命令按服务 Manifest 列出的路由发送:
|
|
89
|
+
交给客户端的 Manifest(`new CommandClient(options, { manifest })`,完整的 Manifest,或生成的客户端的
|
|
90
|
+
`manifest.ts`,只有路由),否则取服务的 Manifest(`GET /wow/manifest`,只取一次)。可以创建聚合的命令不带 `id`,走不带 id 的路由。
|
|
91
|
+
与 Kotlin 的 `CommandClient` 一样,`send` 在命令被接受后应答,`wait` 以等待计划最后
|
|
92
|
+
一跳的结果应答(没有计划时用服务端的默认计划),`stream` 每到一跳应答一个
|
|
93
|
+
`CommandResult`。`wait` 是与 Kotlin 一致的 `WaitPlan`:`WaitPlan.ACCEPTED`、`COMMITTED`、
|
|
94
|
+
`SNAPSHOT`,或由 `wait` 各跳(`accepted`、`committed`、`snapshot`,或某个订阅的 `handled`,
|
|
95
|
+
也可以跨过 Saga 派生的命令)组成的 `WaitPlan.of(...hops)`,`.within(ms)` 给它超时;
|
|
96
|
+
`timeout` 以毫秒计并覆盖计划的超时。`parseWaitPlan` 和 `formatWaitPlan` 读写 `Wow-Wait` 头。`targetTenant` 和
|
|
97
|
+
`targetScope`(`{ ownerId?, spaceId? }`)在另一个租户、所有者或空间中操作。
|
|
89
98
|
每条命令都带请求 id(`Wow-Request-Id`),传入的或生成的:用同一个 id 重试,应答的是
|
|
90
|
-
第一次提交的重复结果;`requestIdOf(error)` 取回失败请求所用的 id
|
|
91
|
-
|
|
99
|
+
第一次提交的重复结果;`requestIdOf(error)` 取回失败请求所用的 id。系统命令(例如聚合列出的生命周期命令
|
|
100
|
+
`LifecycleCommands.DELETE_AGGREGATE` 等)还要指明聚合的 `type: { context, name }`,
|
|
101
|
+
生命周期命令还要指明 `id`。
|
|
92
102
|
|
|
93
|
-
`StateClient`
|
|
103
|
+
`StateClient` 按版本或时间读取聚合的状态及其轨迹;聚合不存在时(404
|
|
104
|
+
`wow.aggregate.not-found`)`get` 和 `read` 拒绝,`find(id, options?)` 则返回
|
|
105
|
+
`undefined`,其他 404 仍然拒绝;`fetchManifest` 读取服务的
|
|
94
106
|
Manifest(`GET /wow/manifest`)。
|
|
95
107
|
|
|
96
108
|
## 错误
|
|
97
109
|
|
|
98
|
-
|
|
99
|
-
`
|
|
100
|
-
|
|
101
|
-
|
|
110
|
+
`send` 和 `wait` 只以成功的结果 resolve,其余按结果的状态区分,与 Kotlin 的
|
|
111
|
+
`CommandClient` 一致:被拒绝的命令(聚合拒绝或在准入时拒绝)以 `CommandRejectedError`
|
|
112
|
+
reject(它的 `code`、`result`,服务回答了问题时还有 `problem`);其他情况以
|
|
113
|
+
`WowProblemError` reject:原样的 RFC 9457 `problem`、`status`、Wow 的 `code`、
|
|
114
|
+
`violations`,服务发送了结果时还有 `result`。`stream` 发出准入之后的每个结果,不论
|
|
115
|
+
状态;在准入时被拒绝的命令,让 `stream` 调用本身以 `result.status` 为 `rejected` 的
|
|
116
|
+
`WowProblemError` reject。中途失败的流以同一个错误结束,`for await` 会抛出它。
|
|
102
117
|
|
|
103
118
|
```ts
|
|
104
119
|
import { FrameworkErrorCodes, WowProblemError } from '@ahoo-wang/wow-client';
|
|
@@ -124,6 +139,39 @@ if (
|
|
|
124
139
|
补丁。只构建查询的包用它。`aggregation.query()` 按 Wow 收到聚合时执行的规则校验整个
|
|
125
140
|
聚合,错误的查询在构建处就失败。
|
|
126
141
|
|
|
142
|
+
## 对着服务测试:`@ahoo-wang/wow-client/testing`
|
|
143
|
+
|
|
144
|
+
Wow 服务的开发模式从请求头读取调用者(`DevelopmentCallerHeaders`);
|
|
145
|
+
`developmentCaller` 在一个 fetcher 的每个请求上发送它们。`commandResultOf`、
|
|
146
|
+
`problemOf`、`problemResponse` 和 `snapshotOf` 为假服务构造服务的应答。这个入口不加载
|
|
147
|
+
任何测试运行器。
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { Fetcher } from '@ahoo-wang/fetcher';
|
|
151
|
+
import {
|
|
152
|
+
commandResultOf,
|
|
153
|
+
developmentCaller,
|
|
154
|
+
problemOf,
|
|
155
|
+
problemResponse,
|
|
156
|
+
} from '@ahoo-wang/wow-client/testing';
|
|
157
|
+
|
|
158
|
+
const fetcher = new Fetcher({ baseURL: 'http://localhost:8080' });
|
|
159
|
+
fetcher.interceptors.request.use(
|
|
160
|
+
developmentCaller({ user: 'alice', owner: 'alice', tenant: 'acme' }),
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
const mug = {
|
|
164
|
+
type: { context: 'eshop-catalog', name: 'product' },
|
|
165
|
+
tenantId: 'acme',
|
|
166
|
+
id: 'mug',
|
|
167
|
+
};
|
|
168
|
+
const refused = problemResponse(
|
|
169
|
+
problemOf(409, 'wow.command.refused', {
|
|
170
|
+
result: commandResultOf(mug, { status: 'rejected' }),
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
173
|
+
```
|
|
174
|
+
|
|
127
175
|
## 文档
|
|
128
176
|
|
|
129
177
|
- [TypeScript 指南](https://wow.ahoo.me/zh/typescript/)
|
package/dist/commands.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./
|
|
1
|
+
const e=require("./frameworkErrors.cjs"),t=require("./wire.cjs"),n=require("./problem.cjs"),r=require("./http.cjs"),i=require("./manifest.cjs"),a=require("./streams.cjs"),o=require("./wait.cjs");var s={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 c(){let e=globalThis.crypto;if(typeof e?.randomUUID==`function`)return e.randomUUID();let t=new Uint8Array(16);if(typeof e?.getRandomValues==`function`)e.getRandomValues(t);else for(let e=0;e<t.length;e++)t[e]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;let n=Array.from(t,e=>e.toString(16).padStart(2,`0`));return[n.slice(0,4),n.slice(4,6),n.slice(6,8),n.slice(8,10),n.slice(10,16)].map(e=>e.join(``)).join(`-`)}async function l(e,t){try{return await t()}catch(t){throw n.rememberRequestId(t,e),t}}var u=`wow.`,d=`{id}`;function f(e){return e.hops.length===1&&e.hops[0].stage===t.Stage.ACCEPTED}function p(e){return e.timeout===void 0?e.wait:(e.wait??o.WaitPlan.DEFAULT).within(e.timeout)}function m(e,t,n){let r=t.find(e=>e.path.includes(d)===(n!==void 0));if(r===void 0)throw TypeError(n===void 0?`${e.command} has no route without an aggregate id: set the request's id.`:`${e.command} has no route to an aggregate by its id: send it without an id.`);if(n===``)throw TypeError(`The path ${r.path} of ${e.command} needs id.`);let i=r.method;if(i!==`POST`&&i!==`DELETE`)throw TypeError(`${e.command} is routed by ${i}: a command is sent by POST or DELETE.`);return{method:i,path:n===void 0?r.path:r.path.replace(d,encodeURIComponent(n))}}function h(e,t){let n=e.body??{},r=e.id;if(t===void 0||r===void 0)return n;let i=n[t];if(i==null)return{...n,[t]:r};if(i!==r)throw TypeError(`The request names the aggregate ${r}, but the body of ${e.command} names ${String(i)}: send it without an id.`);return n}function g(e){let t=e.split(`.`);if(t.length<3||t.some(e=>e===``))throw TypeError(`${e} is not a full type name, context.aggregate.Command: name it so, or set the request's type.`);return{context:t[0],name:t[1]}}function _(e,t,n,i){return{[r.WowHeaders.REQUEST_ID]:n,[r.WowHeaders.WAIT]:t===void 0||t.isDefault?void 0:o.formatWaitPlan(t),[r.WowHeaders.WAIT_TIMEOUT]:t!==void 0&&(e.timeout!==void 0||t.timeout!==o.WaitPlan.DEFAULT_TIMEOUT)?o.formatWaitTimeout(t.timeout):void 0,[r.WowHeaders.IF_MATCH]:e.expectedVersion===void 0?void 0:`"${e.expectedVersion}"`,Accept:i}}function v(e){if(e.targetTenant!==void 0||e.targetScope!==void 0)return{tenantId:e.targetTenant,...e.targetScope}}var y=class{constructor(e={},t={}){this.client=e,this.manifest=t.manifest===void 0?void 0:Promise.resolve(i.checkManifest(t.manifest)),this.bodyNumbers=t.bodyNumbers??{}}async send(e){let t=p(e);if(t!==void 0&&!t.isDefault&&!f(t))throw TypeError(`send answers on acceptance: use wait() for the plan ${o.formatWaitPlan(t)}.`);return this.exchange(e,o.WaitPlan.ACCEPTED.within(e.timeout??o.WaitPlan.DEFAULT_TIMEOUT))}wait(e){return this.exchange(e,p(e))}async stream(e){let t=e.requestId??c();return l(t,async()=>a.commandResults(await this.post(e,p(e),t,`text/event-stream`)))}async exchange(e,i){let a=e.requestId??c();return l(a,async()=>{let o;try{o=await r.json(await this.post(e,i,a))}catch(e){throw e instanceof n.WowProblemError&&e.result?.status===t.CommandResultStatus.REJECTED?new n.CommandRejectedError(e.result,{problem:e.problem,cause:e}):e}return b(o)})}async post(e,t,n,i){let a=await this.commandOf(e),o=a.idProperty,s=m(e,a.routes,o===void 0?e.id:void 0),c=v(e),l=this.bodyNumbers[e.command];return r.send(this.client,{method:s.method,path:s.path,headers:_(e,t,n,i),...s.method===`DELETE`?{}:{body:h(e,o)},...l===void 0?{}:{bodyNumbers:l},options:{...c===void 0?{}:{scope:c},...e.space===void 0?{}:{space:e.space},...e.headers===void 0?{}:{headers:e.headers},...e.signal===void 0?{}:{signal:e.signal}}})}async commandOf(e){let t=e.command,n=t.startsWith(u),r=e.type??(n?void 0:g(t));if(r===void 0)throw TypeError(`${t} is a system command every aggregate takes: set the request's type.`);let i=`${r.context}.${r.name}.`,a=t.startsWith(i)?t.slice(i.length):t,o=(await this.manifestOf()).contexts.find(e=>e.name===r.context),s=o?.aggregates?.find(e=>e.name===r.name)?.commands?.find(e=>e.name===a||e.aliases?.includes(a)===!0)??(n?o?.commands?.find(e=>e.name===a):void 0);if(s?.routes===void 0)throw TypeError(`The Manifest lists no command ${a} of ${r.context}.${r.name}.`);return s}manifestOf(){return this.manifest??=i.fetchManifest(this.client).catch(e=>{throw this.manifest=void 0,e}),this.manifest}};function b(r){if(r.status===t.CommandResultStatus.REJECTED)throw new n.CommandRejectedError(r);if(!x.has(r.status))throw new n.WowProblemError({type:`urn:wow:error:${e.FrameworkErrorCodes.COMMAND_FAILED}`,title:`Unknown command status`,status:200,code:e.FrameworkErrorCodes.COMMAND_FAILED,detail:`The command was answered with the status ${r.status}, which this client does not know: the service is newer than this client, so upgrade it.`,result:r});return r}var x=new Set(Object.values(t.CommandResultStatus));exports.CommandClient=y,exports.LifecycleCommands=s,exports.newRequestId=c;
|
|
2
2
|
//# sourceMappingURL=commands.cjs.map
|
package/dist/commands.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.cjs","names":["WowHeaders","formatWaitPlan","formatWaitTimeout","json","WowProblemError","commandResults","send","expandPath","require_problem","require_http","require_streams","require_wait","LifecycleCommands","commandSegment","name","newRequestId","crypto","bytes","index","hex","byte","group","withRequestId","sending","error","requestId","commandHeaders","wait","options","accept","CommandGateway","client","path","body","base","aggregatePath","id","command","response"],"sources":["../src/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 type { TextNumbers } from './exactJson.js';\nimport {\n expandPath,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowHeaders,\n} from './http.js';\nimport type { CommandResult } from './wire.js';\nimport { rememberRequestId, 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. When absent, the\n * gateway generates one ({@link newRequestId}), which a failure carries\n * ({@link requestIdOf}): retry with it, not with a new one.\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 * The body's numbers written as their exact text, unquoted JSON numbers\n * (review R4-Q, Q-9; decision D122): a generated client sets it for a\n * command with `int64`, `bigint` or `decimal` fields, which it types as\n * `string`.\n */\n readonly bodyNumbers?: TextNumbers;\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\n/**\n * A new request id (`Wow-Request-Id`): a random UUID. The gateway generates\n * one for a command sent without; generate it first to retry with it however\n * the request fails.\n */\nexport function newRequestId(): string {\n const crypto = globalThis.crypto;\n if (typeof crypto?.randomUUID === 'function') return crypto.randomUUID();\n // An insecure browser context has no randomUUID: a version 4 UUID by hand.\n const bytes = new Uint8Array(16);\n if (typeof crypto?.getRandomValues === 'function') {\n crypto.getRandomValues(bytes);\n } else {\n for (let index = 0; index < bytes.length; index++) {\n bytes[index] = Math.floor(Math.random() * 256);\n }\n }\n bytes[6] = (bytes[6] & 0x0f) | 0x40;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, '0'));\n return [\n hex.slice(0, 4),\n hex.slice(4, 6),\n hex.slice(6, 8),\n hex.slice(8, 10),\n hex.slice(10, 16),\n ]\n .map(group => group.join(''))\n .join('-');\n}\n\n/** Sends with the request id `requestId`, which a failure carries. */\nasync function withRequestId<T>(\n requestId: string,\n sending: () => Promise<T>,\n): Promise<T> {\n try {\n return await sending();\n } catch (error) {\n rememberRequestId(error, requestId);\n throw error;\n }\n}\n\nfunction commandHeaders(\n options: CommandOptions,\n requestId: string,\n accept?: string,\n): Record<string, string | undefined> {\n const wait = options.wait;\n return {\n [WowHeaders.REQUEST_ID]: requestId,\n [WowHeaders.WAIT]:\n wait?.plan === undefined ? undefined : formatWaitPlan(wait.plan),\n [WowHeaders.WAIT_TIMEOUT]:\n wait?.timeout === undefined ? undefined : formatWaitTimeout(wait.timeout),\n [WowHeaders.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 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. Every command carries a\n * request id, the options' or a generated one, and whatever it rejects with\n * carries that id ({@link requestIdOf}).\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 const requestId = options.requestId ?? newRequestId();\n try {\n return await withRequestId(requestId, async () =>\n json<CommandResult<R>>(await this.post(path, body, options, requestId)),\n );\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 const requestId = options.requestId ?? newRequestId();\n return withRequestId(requestId, async () =>\n commandResults<R>(\n await this.post(path, body, options, requestId, 'text/event-stream'),\n ),\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 requestId = options.requestId ?? newRequestId();\n return withRequestId(requestId, async () => {\n const response = await send(this.client, {\n method: 'DELETE',\n path: base,\n headers: commandHeaders(options, requestId),\n options,\n });\n return json<CommandResult<R>>(response);\n });\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 requestId: string,\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, requestId, accept),\n body: body ?? {},\n ...(options.bodyNumbers === undefined\n ? {}\n : { bodyNumbers: options.bodyNumbers }),\n options,\n });\n }\n}\n"],"mappings":"4GAgEA,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,CAOA,SAAgBC,GAAuB,CACrC,IAAMC,EAAS,WAAW,OAC1B,GAAI,OAAOA,GAAQ,YAAe,WAAY,OAAOA,EAAO,WAAW,EAEvE,IAAMC,EAAQ,IAAI,WAAW,EAAE,EAC/B,GAAI,OAAOD,GAAQ,iBAAoB,WACrCA,EAAO,gBAAgBC,CAAK,OAE5B,IAAK,IAAIC,EAAQ,EAAGA,EAAQD,EAAM,OAAQ,IACxC,EAAMC,GAAS,KAAK,MAAM,KAAK,OAAO,EAAI,GAAG,EAGjD,EAAM,GAAMD,EAAM,GAAK,GAAQ,GAC/B,EAAM,GAAMA,EAAM,GAAK,GAAQ,IAC/B,IAAME,EAAM,MAAM,KAAKF,EAAO,GAAQG,EAAK,SAAS,EAAE,CAAC,CAAC,SAAS,EAAG,GAAG,CAAC,EACxE,MAAO,CACLD,EAAI,MAAM,EAAG,CAAC,EACdA,EAAI,MAAM,EAAG,CAAC,EACdA,EAAI,MAAM,EAAG,CAAC,EACdA,EAAI,MAAM,EAAG,EAAE,EACfA,EAAI,MAAM,GAAI,EAAE,CAClB,CAAC,CACE,IAAI,GAASE,EAAM,KAAK,EAAE,CAAC,CAAC,CAC5B,KAAK,GAAG,CACb,CAGA,eAAeC,EACb,EACA,EACY,CACZ,GAAI,CACF,OAAO,MAAMC,EAAQ,CACvB,OAASC,EAAO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,EAAkB,iBAAkB,CAClD,IAAMa,EAAYG,EAAQ,WAAab,EAAa,EACpD,OAAOO,EAAcG,EAAW,SAAY,CAC1C,IAAMa,EAAW,MAAMhC,EAAAA,KAAK,KAAK,OAAQ,CACvC,OAAQ,SACR,KAAM4B,EACN,QAASR,EAAeE,EAASH,CAAS,EAC1C,SACF,CAAC,EACD,OAAOtB,EAAAA,KAAuBmC,CAAQ,CACxC,CAAC,CACH,CACA,OAAO,KAAK,KACV,GAAGJ,EAAK,GAAGrB,EAAewB,CAAO,IACjCJ,GAAQ,CAAC,EACTL,CACF,CACF,CAEA,KACE,EACA,EACA,EACA,EACA,EACmB,CACnB,OAAOtB,EAAAA,KAAK,KAAK,OAAQ,CACvB,OAAQ,OACR,KAAM0B,EAAK,SAAS,MAAM,EACtBzB,EAAAA,WAAWyB,EAAM,CAAE,GAAIJ,EAAQ,IAAM,EAAG,CAAC,EACzCI,EACJ,QAASN,EAAeE,EAASH,EAAWI,CAAM,EAClD,KAAMI,GAAQ,CAAC,EACf,GAAIL,EAAQ,cAAgB,IAAA,GACxB,CAAC,EACD,CAAE,YAAaA,EAAQ,WAAY,EACvC,SACF,CAAC,CACH,CACF"}
|
|
1
|
+
{"version":3,"file":"commands.cjs","names":["Stage","WaitPlan","WowHeaders","formatWaitPlan","formatWaitTimeout","checkManifest","commandResults","json","WowProblemError","CommandResultStatus","CommandRejectedError","send","fetchManifest","FrameworkErrorCodes","require_frameworkErrors","require_wire","require_problem","require_http","require_manifest","require_streams","require_wait","LifecycleCommands","newRequestId","crypto","bytes","index","hex","byte","group","withRequestId","sending","error","requestId","SYSTEM_PREFIX","ID","acceptedOnly","plan","planOf","request","routeOf","route","routes","item","id","method","bodyOf","body","idProperty","named","typeNamed","parts","command","part","commandHeaders","accept","targetOf","CommandClient","client","options","result","settled","declared","scope","bodyNumbers","system","type","prefix","name","context","aggregate","KNOWN_STATUSES"],"sources":["../src/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 type { TextNumbers } from './exactJson.js';\nimport {\n json,\n type RequestOptions,\n send,\n type TargetScope,\n type WowClientOptions,\n WowHeaders,\n} from './http.js';\nimport {\n type AggregateType,\n type CommandResult,\n CommandResultStatus,\n type RefusedResult,\n Stage,\n} from './wire.js';\nimport {\n checkManifest,\n fetchManifest,\n type RouteManifest,\n type RoutingCommand,\n type RoutingManifest,\n} from './manifest.js';\nimport {\n CommandRejectedError,\n FrameworkErrorCodes,\n rememberRequestId,\n WowProblemError,\n} from './problem.js';\nimport { commandResults, type CommandResultStream } from './streams.js';\nimport { formatWaitPlan, formatWaitTimeout, WaitPlan } from './wait.js';\n\n/**\n * One command a {@link CommandClient} sends, and how: the TypeScript\n * `CommandRequest` of Kotlin's `me.ahoo.wow.api.client`, with the same\n * fields. Kotlin's `command` is the command object, whose class names it;\n * here `command` is the command's name and `body` its payload, as the wire\n * carries them.\n *\n * - `command`: the full type name, `context.aggregate.Command`, which names\n * the aggregate type too; or a system command (`wow.*`, a lifecycle command\n * of {@link LifecycleCommands} among them), which needs `type`.\n * - `id`: the aggregate's id. Absent when the command names no aggregate id:\n * a creation, whose id the server assigns, an `@Unaddressed` command, or\n * any command of an aggregate whose id is its owner's (the Manifest's\n * `idSource: \"owner\"`), which goes to the caller's own; the route without\n * `{id}` then sends it. A command whose body names its aggregate (the\n * Manifest's `idProperty`) goes by that route too, whether `id` is given or\n * not: a given one is the one its body names, or is written into a body\n * that names none.\n * - `targetTenant`, `targetScope`: the tenant and scope a caller allowed to\n * act across scopes acts in (`Wow-Scope`); the caller's own when absent.\n * - `wait` (`Wow-Wait`), a {@link WaitPlan}, and `timeout` in milliseconds\n * (`Wow-Wait-Timeout`), which overrides the plan's: the plan the command\n * waits with is `wait` within `timeout`, the server's default plan when\n * only a timeout is given, and the server's default without either.\n * - `requestId` (`Wow-Request-Id`) and `expectedVersion` (`If-Match`).\n */\nexport interface CommandRequest extends Omit<RequestOptions, 'scope'> {\n /** The command's full type name, or a system command's. */\n readonly command: string;\n /** The command's body; `{}` when absent. */\n readonly body?: object;\n /**\n * The aggregate's id; absent for a creation, an unaddressed command or the\n * caller's own aggregate of one whose id is its owner's.\n */\n readonly id?: string;\n /**\n * The aggregate type, which `command` names unless it is a system command:\n * then it is required.\n */\n readonly type?: AggregateType;\n /** The tenant to act in, for a caller allowed to (`Wow-Scope`). */\n readonly targetTenant?: string;\n /** The owner and space to act in, for a caller allowed to (`Wow-Scope`). */\n readonly targetScope?: Omit<TargetScope, 'tenantId'>;\n /**\n * Not a command's: a query's `Wow-Scope`. A command names the scope it acts\n * in with `targetTenant` and `targetScope`, so a query's options spread into\n * a command's fail to compile rather than drop their scope.\n */\n readonly scope?: never;\n /** How far to wait for the command (`Wow-Wait`). */\n readonly wait?: WaitPlan;\n /** How long to wait, in milliseconds, over the plan's own timeout. */\n readonly timeout?: number;\n /**\n * The request id (`Wow-Request-Id`): a retry with the same one is\n * deduplicated, answered as the first commit's duplicate. When absent, the\n * client generates one ({@link newRequestId}), which a failure carries\n * ({@link requestIdOf}). A request sent again without one is another\n * request: for an application-level retry, set it (or keep the one the\n * failure or the first result carries) and send that request again.\n */\n readonly requestId?: string;\n /** The version the aggregate must be at (`If-Match`). */\n readonly expectedVersion?: number;\n}\n\n/** How a {@link CommandClient} sends, beside how it reaches the service. */\nexport interface CommandClientOptions {\n /**\n * The Manifest whose routes send each command: a whole Manifest, or the\n * routing part a generated client carries (`manifest.ts`). Without it the\n * client fetches the service's once, when it first sends\n * (`GET /wow/manifest`), and again after a failed fetch.\n */\n readonly manifest?: RoutingManifest;\n /**\n * The body numbers each command writes as their exact text, unquoted JSON\n * numbers (decision D122), by the command's full type name: a generated\n * client sets them for commands with `int64`, `bigint` or `decimal` fields,\n * which it types as `string`.\n */\n readonly bodyNumbers?: Readonly<Record<string, TextNumbers>>;\n}\n\n/**\n * The options of a generated client's command method: a {@link CommandRequest}\n * without what the method fixes, its command, body and type.\n */\nexport type CommandOptions = Omit<\n CommandRequest,\n 'command' | 'body' | 'type' | 'id'\n>;\n\n/** The options of a command that may create its aggregate, with its 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. */\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 * A new request id (`Wow-Request-Id`): a random UUID. The client generates\n * one for a command sent without; generate it first to retry with it however\n * the request fails.\n */\nexport function newRequestId(): string {\n const crypto = globalThis.crypto;\n if (typeof crypto?.randomUUID === 'function') return crypto.randomUUID();\n // An insecure browser context has no randomUUID: a version 4 UUID by hand.\n const bytes = new Uint8Array(16);\n if (typeof crypto?.getRandomValues === 'function') {\n crypto.getRandomValues(bytes);\n } else {\n for (let index = 0; index < bytes.length; index++) {\n bytes[index] = Math.floor(Math.random() * 256);\n }\n }\n bytes[6] = (bytes[6] & 0x0f) | 0x40;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, '0'));\n return [\n hex.slice(0, 4),\n hex.slice(4, 6),\n hex.slice(6, 8),\n hex.slice(8, 10),\n hex.slice(10, 16),\n ]\n .map(group => group.join(''))\n .join('-');\n}\n\n/** Sends with the request id `requestId`, which a failure carries. */\nasync function withRequestId<T>(\n requestId: string,\n sending: () => Promise<T>,\n): Promise<T> {\n try {\n return await sending();\n } catch (error) {\n rememberRequestId(error, requestId);\n throw error;\n }\n}\n\n/** The prefix of the system commands' names, the lifecycle commands' among them. */\nconst SYSTEM_PREFIX = 'wow.';\n\n/** The aggregate id of a route's path. */\nconst ID = '{id}';\n\n/** Whether `plan` waits for acceptance alone. */\nfunction acceptedOnly(plan: WaitPlan): boolean {\n return plan.hops.length === 1 && plan.hops[0].stage === Stage.ACCEPTED;\n}\n\n/**\n * The plan `request` waits with, as Kotlin's `CommandRequest.plan`: its\n * `wait` within its `timeout`, the default plan when only a timeout is given.\n */\nfunction planOf(request: CommandRequest): WaitPlan | undefined {\n if (request.timeout === undefined) return request.wait;\n return (request.wait ?? WaitPlan.DEFAULT).within(request.timeout);\n}\n\n/**\n * The route of `request` among `routes`, by `id` (the request's, none for a\n * command whose body names its aggregate): its method and path, the id in it.\n * An empty id is refused before anything is sent: it would leave the path's\n * segment empty (`/<context>/<aggregate>//…`), a route no service has.\n */\nfunction routeOf(\n request: CommandRequest,\n routes: readonly RouteManifest[],\n id: string | undefined,\n): { method: 'POST' | 'DELETE'; path: string } {\n const route = routes.find(\n item => item.path.includes(ID) === (id !== undefined),\n );\n if (route === undefined) {\n throw new TypeError(\n id === undefined\n ? `${request.command} has no route without an aggregate id: set the request's id.`\n : `${request.command} has no route to an aggregate by its id: send it without an id.`,\n );\n }\n if (id === '') {\n throw new TypeError(\n `The path ${route.path} of ${request.command} needs id.`,\n );\n }\n const method = route.method;\n if (method !== 'POST' && method !== 'DELETE') {\n throw new TypeError(\n `${request.command} is routed by ${method}: a command is sent by POST or DELETE.`,\n );\n }\n return {\n method,\n path:\n id === undefined\n ? route.path\n : route.path.replace(ID, encodeURIComponent(id)),\n };\n}\n\n/**\n * The body `request` sends, `{}` when it has none. Of a command whose body\n * names its aggregate in `idProperty`, the route has no id: the request's id,\n * when it names one, is the body's too, written into a body that names none.\n *\n * @throws TypeError when the body names another aggregate than the request\n */\nfunction bodyOf(\n request: CommandRequest,\n idProperty: string | undefined,\n): object {\n const body = request.body ?? {};\n const id = request.id;\n if (idProperty === undefined || id === undefined) return body;\n const named: unknown = (body as Record<string, unknown>)[idProperty];\n if (named === undefined || named === null) {\n return { ...body, [idProperty]: id };\n }\n if (named !== id) {\n throw new TypeError(\n `The request names the aggregate ${id}, but the body of ${request.command} names ${String(named)}: send it without an id.`,\n );\n }\n return body;\n}\n\n/** The aggregate type a full type name `context.aggregate.Command` names. */\nfunction typeNamed(command: string): AggregateType {\n const parts = command.split('.');\n if (parts.length < 3 || parts.some(part => part === '')) {\n throw new TypeError(\n `${command} is not a full type name, context.aggregate.Command: name it so, or set the request's type.`,\n );\n }\n return { context: parts[0], name: parts[1] };\n}\n\nfunction commandHeaders(\n request: CommandRequest,\n plan: WaitPlan | undefined,\n requestId: string,\n accept?: string,\n): Record<string, string | undefined> {\n return {\n [WowHeaders.REQUEST_ID]: requestId,\n // The default plan is the service's to pick: it sends no plan.\n [WowHeaders.WAIT]:\n plan === undefined || plan.isDefault ? undefined : formatWaitPlan(plan),\n // A plan's own timeout, or the request's; the service's default otherwise.\n [WowHeaders.WAIT_TIMEOUT]:\n plan !== undefined &&\n (request.timeout !== undefined ||\n plan.timeout !== WaitPlan.DEFAULT_TIMEOUT)\n ? formatWaitTimeout(plan.timeout)\n : undefined,\n [WowHeaders.IF_MATCH]:\n request.expectedVersion === undefined\n ? undefined\n : `\"${request.expectedVersion}\"`,\n Accept: accept,\n };\n}\n\n/** The `Wow-Scope` a request targets, when it targets one. */\nfunction targetOf(request: CommandRequest): TargetScope | undefined {\n if (request.targetTenant === undefined && request.targetScope === undefined) {\n return undefined;\n }\n return { tenantId: request.targetTenant, ...request.targetScope };\n}\n\n/**\n * Sends commands to the command routes of a Wow service as its Manifest lists\n * them (`POST /{context}/{aggregate}/{id}/{command}`, the route without\n * `{id}` for a request that names none, `DELETE /{context}/{aggregate}/{id}`\n * for `DeleteAggregate`): the Manifest the client is given, else the\n * service's, fetched once (`GET /wow/manifest`). The TypeScript\n * `CommandClient` of Kotlin's `me.ahoo.wow.api.client`: {@link send} answers\n * once the command is accepted, {@link wait} with the result its wait plan\n * ends with, {@link stream} with one result per hop. Generated aggregate\n * clients build on it.\n *\n * `send` and `wait` resolve only a result that succeeded. A rejected one,\n * by the aggregate or at admission, rejects with a\n * {@link CommandRejectedError}; anything else that did not succeed with a\n * {@link WowProblemError} (the table on {@link CommandRejectedError} says\n * which). Every command carries a request id, the request's or a generated\n * one, and whatever it rejects with carries that id ({@link requestIdOf}).\n */\nexport class CommandClient {\n private manifest: Promise<RoutingManifest> | undefined;\n private readonly bodyNumbers: Readonly<Record<string, TextNumbers>>;\n\n /**\n * @param client - How the service is reached\n * @param options - The service's Manifest, and the commands' exact numbers\n */\n constructor(\n readonly client: WowClientOptions = {},\n options: CommandClientOptions = {},\n ) {\n this.manifest =\n options.manifest === undefined\n ? undefined\n : Promise.resolve(checkManifest(options.manifest));\n this.bodyNumbers = options.bodyNumbers ?? {};\n }\n\n /**\n * Sends a command and answers once it is accepted (202), within the\n * request's timeout (10 seconds without one), as Kotlin's\n * `CommandClient.send`. A request whose `wait` waits for more rejects with a\n * `TypeError` before it is sent: {@link wait} answers with that plan's result.\n *\n * @param request - The command and how to send it\n */\n async send<R = Record<string, unknown>>(\n request: CommandRequest,\n ): Promise<CommandResult<R>> {\n const plan = planOf(request);\n if (plan !== undefined && !plan.isDefault && !acceptedOnly(plan)) {\n throw new TypeError(\n `send answers on acceptance: use wait() for the plan ${formatWaitPlan(plan)}.`,\n );\n }\n return this.exchange<R>(\n request,\n WaitPlan.ACCEPTED.within(request.timeout ?? WaitPlan.DEFAULT_TIMEOUT),\n );\n }\n\n /**\n * Sends a command and answers the result its wait plan ends with: 200, or\n * 202 for a plan that ends at `accepted`. Without a plan, the server's\n * default: the snapshot, or the commit where the aggregate keeps no\n * snapshot (decision D69).\n *\n * @param request - The command and how to send it\n */\n wait<R = Record<string, unknown>>(\n request: CommandRequest,\n ): Promise<CommandResult<R>> {\n return this.exchange<R>(request, planOf(request));\n }\n\n /**\n * Sends a command with `Accept: text/event-stream` and answers one result\n * per hop as the wait advances, whatever its status. An admission refusal\n * rejects with its problem; a rejection after admission is the stream's\n * last result.\n *\n * @param request - The command and how to send it\n */\n async stream<R = Record<string, unknown>>(\n request: CommandRequest,\n ): Promise<CommandResultStream<R>> {\n const requestId = request.requestId ?? newRequestId();\n return withRequestId(requestId, async () =>\n commandResults<R>(\n await this.post(\n request,\n planOf(request),\n requestId,\n 'text/event-stream',\n ),\n ),\n );\n }\n\n private async exchange<R>(\n request: CommandRequest,\n plan: WaitPlan | undefined,\n ): Promise<CommandResult<R>> {\n const requestId = request.requestId ?? newRequestId();\n return withRequestId(requestId, async () => {\n let result: CommandResult<R>;\n try {\n result = await json<CommandResult<R>>(\n await this.post(request, plan, requestId),\n );\n } catch (error) {\n if (\n error instanceof WowProblemError &&\n error.result?.status === CommandResultStatus.REJECTED\n ) {\n throw new CommandRejectedError(error.result, {\n problem: error.problem,\n cause: error,\n });\n }\n throw error;\n }\n return settled(result);\n });\n }\n\n private async post(\n request: CommandRequest,\n plan: WaitPlan | undefined,\n requestId: string,\n accept?: string,\n ): Promise<Response> {\n const declared = await this.commandOf(request);\n const idProperty = declared.idProperty;\n const route = routeOf(\n request,\n declared.routes,\n idProperty === undefined ? request.id : undefined,\n );\n const scope = targetOf(request);\n const bodyNumbers = this.bodyNumbers[request.command];\n return send(this.client, {\n method: route.method,\n path: route.path,\n headers: commandHeaders(request, plan, requestId, accept),\n ...(route.method === 'DELETE'\n ? {}\n : { body: bodyOf(request, idProperty) }),\n ...(bodyNumbers === undefined ? {} : { bodyNumbers }),\n options: {\n ...(scope === undefined ? {} : { scope }),\n ...(request.space === undefined ? {} : { space: request.space }),\n ...(request.headers === undefined ? {} : { headers: request.headers }),\n ...(request.signal === undefined ? {} : { signal: request.signal }),\n },\n });\n }\n\n /**\n * `request`'s command as the Manifest lists it, with its routes: a domain\n * command among its aggregate's commands, by name or former name; a system\n * command among its type's, else among its context's (a job's).\n */\n private async commandOf(request: CommandRequest): Promise<RoutingCommand> {\n const command = request.command;\n const system = command.startsWith(SYSTEM_PREFIX);\n const type = request.type ?? (system ? undefined : typeNamed(command));\n if (type === undefined) {\n throw new TypeError(\n `${command} is a system command every aggregate takes: set the request's type.`,\n );\n }\n const prefix = `${type.context}.${type.name}.`;\n const name = command.startsWith(prefix)\n ? command.slice(prefix.length)\n : command;\n const context = (await this.manifestOf()).contexts.find(\n item => item.name === type.context,\n );\n const declared =\n context?.aggregates\n ?.find(aggregate => aggregate.name === type.name)\n ?.commands?.find(\n item => item.name === name || item.aliases?.includes(name) === true,\n ) ??\n (system\n ? context?.commands?.find(item => item.name === name)\n : undefined);\n if (declared?.routes === undefined) {\n throw new TypeError(\n `The Manifest lists no command ${name} of ${type.context}.${type.name}.`,\n );\n }\n return declared;\n }\n\n /** The Manifest given, or the service's, fetched once (again after a failure). */\n private manifestOf(): Promise<RoutingManifest> {\n this.manifest ??= fetchManifest(this.client).catch((error: unknown) => {\n this.manifest = undefined;\n throw error;\n });\n return this.manifest;\n }\n}\n\n/**\n * The result a command was answered with, when it succeeded; else the error\n * that says why it did not, as Kotlin's `HttpCommandClient` settles one: a\n * rejected result rejects with a {@link CommandRejectedError}, a status this\n * client does not know (a newer service's) with a {@link WowProblemError}.\n */\nfunction settled<R>(result: CommandResult<R>): CommandResult<R> {\n if (result.status === CommandResultStatus.REJECTED) {\n throw new CommandRejectedError(result as RefusedResult);\n }\n if (!KNOWN_STATUSES.has(result.status)) {\n throw new WowProblemError({\n type: `urn:wow:error:${FrameworkErrorCodes.COMMAND_FAILED}`,\n title: 'Unknown command status',\n status: 200,\n code: FrameworkErrorCodes.COMMAND_FAILED,\n detail: `The command was answered with the status ${result.status}, which this client does not know: the service is newer than this client, so upgrade it.`,\n result: result as RefusedResult,\n });\n }\n return result;\n}\n\nconst KNOWN_STATUSES: ReadonlySet<string> = new Set(\n Object.values(CommandResultStatus),\n);\n"],"mappings":"A,mMAsJA,IAAaqB,EAAoB,CAC/B,iBAAkB,gCAClB,kBAAmB,iCACnB,eAAgB,8BAChB,eAAgB,8BAChB,WAAY,yBACd,EA0BA,SAAgBC,GAAuB,CACrC,IAAMC,EAAS,WAAW,OAC1B,GAAI,OAAOA,GAAQ,YAAe,WAAY,OAAOA,EAAO,WAAW,EAEvE,IAAMC,EAAQ,IAAI,WAAW,EAAE,EAC/B,GAAI,OAAOD,GAAQ,iBAAoB,WACrCA,EAAO,gBAAgBC,CAAK,OAE5B,IAAK,IAAIC,EAAQ,EAAGA,EAAQD,EAAM,OAAQ,IACxC,EAAMC,GAAS,KAAK,MAAM,KAAK,OAAO,EAAI,GAAG,EAGjD,EAAM,GAAMD,EAAM,GAAK,GAAQ,GAC/B,EAAM,GAAMA,EAAM,GAAK,GAAQ,IAC/B,IAAME,EAAM,MAAM,KAAKF,EAAO,GAAQG,EAAK,SAAS,EAAE,CAAC,CAAC,SAAS,EAAG,GAAG,CAAC,EACxE,MAAO,CACLD,EAAI,MAAM,EAAG,CAAC,EACdA,EAAI,MAAM,EAAG,CAAC,EACdA,EAAI,MAAM,EAAG,CAAC,EACdA,EAAI,MAAM,EAAG,EAAE,EACfA,EAAI,MAAM,GAAI,EAAE,CAClB,CAAC,CACE,IAAI,GAASE,EAAM,KAAK,EAAE,CAAC,CAAC,CAC5B,KAAK,GAAG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Q1B,EAAK,OAASyB,CAAI,EAClD,IAAA,IACN,GAAIN,GAAU,SAAW,IAAA,GACvB,MAAU,UACR,iCAAiCM,EAAK,MAAMF,EAAK,QAAQ,GAAGA,EAAK,KAAK,EACxE,EAEF,OAAOJ,CACT,CAGA,YAA+C,CAK7C,MAJA,MAAK,WAAajD,EAAAA,cAAc,KAAK,MAAM,CAAC,CAAC,MAAO,GAAmB,CAErE,KADA,MAAK,SAAW,IAAA,GACVmB,CACR,CAAC,EACM,KAAK,QACd,CACF,EAQA,SAAS6B,EAAW,EAA4C,CAC9D,GAAID,EAAO,SAAWlD,EAAAA,oBAAoB,SACxC,MAAM,IAAIC,EAAAA,qBAAqBiD,CAAuB,EAExD,GAAI,CAACW,EAAe,IAAIX,EAAO,MAAM,EACnC,MAAM,IAAInD,EAAAA,gBAAgB,CACxB,KAAM,iBAAiBK,EAAAA,oBAAoB,iBAC3C,MAAO,yBACP,OAAQ,IACR,KAAMA,EAAAA,oBAAoB,eAC1B,OAAQ,4CAA4C8C,EAAO,OAAO,0FAC1D,QACV,CAAC,EAEH,OAAOA,CACT,CAEA,IAAMW,EAAsC,IAAI,IAC9C,OAAO,OAAO7D,EAAAA,mBAAmB,CACnC,E"}
|
package/dist/commands.d.cts
CHANGED
|
@@ -1,35 +1,99 @@
|
|
|
1
1
|
import { TextNumbers } from './exactJson.cjs';
|
|
2
|
-
import { RequestOptions, WowClientOptions } from './http.cjs';
|
|
3
|
-
import { CommandResult } from './wire.cjs';
|
|
2
|
+
import { RequestOptions, TargetScope, WowClientOptions } from './http.cjs';
|
|
3
|
+
import { AggregateType, CommandResult } from './wire.cjs';
|
|
4
|
+
import { RoutingManifest } from './manifest.cjs';
|
|
4
5
|
import { CommandResultStream } from './streams.cjs';
|
|
5
|
-
import {
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
import { WaitPlan } from './wait.cjs';
|
|
7
|
+
/**
|
|
8
|
+
* One command a {@link CommandClient} sends, and how: the TypeScript
|
|
9
|
+
* `CommandRequest` of Kotlin's `me.ahoo.wow.api.client`, with the same
|
|
10
|
+
* fields. Kotlin's `command` is the command object, whose class names it;
|
|
11
|
+
* here `command` is the command's name and `body` its payload, as the wire
|
|
12
|
+
* carries them.
|
|
13
|
+
*
|
|
14
|
+
* - `command`: the full type name, `context.aggregate.Command`, which names
|
|
15
|
+
* the aggregate type too; or a system command (`wow.*`, a lifecycle command
|
|
16
|
+
* of {@link LifecycleCommands} among them), which needs `type`.
|
|
17
|
+
* - `id`: the aggregate's id. Absent when the command names no aggregate id:
|
|
18
|
+
* a creation, whose id the server assigns, an `@Unaddressed` command, or
|
|
19
|
+
* any command of an aggregate whose id is its owner's (the Manifest's
|
|
20
|
+
* `idSource: "owner"`), which goes to the caller's own; the route without
|
|
21
|
+
* `{id}` then sends it. A command whose body names its aggregate (the
|
|
22
|
+
* Manifest's `idProperty`) goes by that route too, whether `id` is given or
|
|
23
|
+
* not: a given one is the one its body names, or is written into a body
|
|
24
|
+
* that names none.
|
|
25
|
+
* - `targetTenant`, `targetScope`: the tenant and scope a caller allowed to
|
|
26
|
+
* act across scopes acts in (`Wow-Scope`); the caller's own when absent.
|
|
27
|
+
* - `wait` (`Wow-Wait`), a {@link WaitPlan}, and `timeout` in milliseconds
|
|
28
|
+
* (`Wow-Wait-Timeout`), which overrides the plan's: the plan the command
|
|
29
|
+
* waits with is `wait` within `timeout`, the server's default plan when
|
|
30
|
+
* only a timeout is given, and the server's default without either.
|
|
31
|
+
* - `requestId` (`Wow-Request-Id`) and `expectedVersion` (`If-Match`).
|
|
32
|
+
*/
|
|
33
|
+
export interface CommandRequest extends Omit<RequestOptions, 'scope'> {
|
|
34
|
+
/** The command's full type name, or a system command's. */
|
|
35
|
+
readonly command: string;
|
|
36
|
+
/** The command's body; `{}` when absent. */
|
|
37
|
+
readonly body?: object;
|
|
38
|
+
/**
|
|
39
|
+
* The aggregate's id; absent for a creation, an unaddressed command or the
|
|
40
|
+
* caller's own aggregate of one whose id is its owner's.
|
|
41
|
+
*/
|
|
42
|
+
readonly id?: string;
|
|
43
|
+
/**
|
|
44
|
+
* The aggregate type, which `command` names unless it is a system command:
|
|
45
|
+
* then it is required.
|
|
46
|
+
*/
|
|
47
|
+
readonly type?: AggregateType;
|
|
48
|
+
/** The tenant to act in, for a caller allowed to (`Wow-Scope`). */
|
|
49
|
+
readonly targetTenant?: string;
|
|
50
|
+
/** The owner and space to act in, for a caller allowed to (`Wow-Scope`). */
|
|
51
|
+
readonly targetScope?: Omit<TargetScope, 'tenantId'>;
|
|
52
|
+
/**
|
|
53
|
+
* Not a command's: a query's `Wow-Scope`. A command names the scope it acts
|
|
54
|
+
* in with `targetTenant` and `targetScope`, so a query's options spread into
|
|
55
|
+
* a command's fail to compile rather than drop their scope.
|
|
56
|
+
*/
|
|
57
|
+
readonly scope?: never;
|
|
58
|
+
/** How far to wait for the command (`Wow-Wait`). */
|
|
59
|
+
readonly wait?: WaitPlan;
|
|
60
|
+
/** How long to wait, in milliseconds, over the plan's own timeout. */
|
|
61
|
+
readonly timeout?: number;
|
|
8
62
|
/**
|
|
9
63
|
* The request id (`Wow-Request-Id`): a retry with the same one is
|
|
10
64
|
* deduplicated, answered as the first commit's duplicate. When absent, the
|
|
11
|
-
*
|
|
12
|
-
* ({@link requestIdOf})
|
|
65
|
+
* client generates one ({@link newRequestId}), which a failure carries
|
|
66
|
+
* ({@link requestIdOf}). A request sent again without one is another
|
|
67
|
+
* request: for an application-level retry, set it (or keep the one the
|
|
68
|
+
* failure or the first result carries) and send that request again.
|
|
13
69
|
*/
|
|
14
70
|
readonly requestId?: string;
|
|
15
|
-
/** What to wait for, and for how long. */
|
|
16
|
-
readonly wait?: WaitOptions;
|
|
17
71
|
/** The version the aggregate must be at (`If-Match`). */
|
|
18
72
|
readonly expectedVersion?: number;
|
|
73
|
+
}
|
|
74
|
+
/** How a {@link CommandClient} sends, beside how it reaches the service. */
|
|
75
|
+
export interface CommandClientOptions {
|
|
19
76
|
/**
|
|
20
|
-
* The
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* `
|
|
77
|
+
* The Manifest whose routes send each command: a whole Manifest, or the
|
|
78
|
+
* routing part a generated client carries (`manifest.ts`). Without it the
|
|
79
|
+
* client fetches the service's once, when it first sends
|
|
80
|
+
* (`GET /wow/manifest`), and again after a failed fetch.
|
|
24
81
|
*/
|
|
25
|
-
readonly
|
|
82
|
+
readonly manifest?: RoutingManifest;
|
|
26
83
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
84
|
+
* The body numbers each command writes as their exact text, unquoted JSON
|
|
85
|
+
* numbers (decision D122), by the command's full type name: a generated
|
|
86
|
+
* client sets them for commands with `int64`, `bigint` or `decimal` fields,
|
|
87
|
+
* which it types as `string`.
|
|
29
88
|
*/
|
|
30
|
-
readonly
|
|
89
|
+
readonly bodyNumbers?: Readonly<Record<string, TextNumbers>>;
|
|
31
90
|
}
|
|
32
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* The options of a generated client's command method: a {@link CommandRequest}
|
|
93
|
+
* without what the method fixes, its command, body and type.
|
|
94
|
+
*/
|
|
95
|
+
export type CommandOptions = Omit<CommandRequest, 'command' | 'body' | 'type' | 'id'>;
|
|
96
|
+
/** The options of a command that may create its aggregate, with its id or not. */
|
|
33
97
|
export interface CreateCommandOptions extends CommandOptions {
|
|
34
98
|
/**
|
|
35
99
|
* The id of the aggregate to create (decision D176); the service generates
|
|
@@ -37,7 +101,7 @@ export interface CreateCommandOptions extends CommandOptions {
|
|
|
37
101
|
*/
|
|
38
102
|
readonly id?: string;
|
|
39
103
|
}
|
|
40
|
-
/** The lifecycle commands an aggregate may list
|
|
104
|
+
/** The lifecycle commands an aggregate may list. */
|
|
41
105
|
export declare const LifecycleCommands: {
|
|
42
106
|
readonly DELETE_AGGREGATE: "wow.lifecycle.DeleteAggregate";
|
|
43
107
|
readonly RESTORE_AGGREGATE: "wow.lifecycle.RestoreAggregate";
|
|
@@ -60,64 +124,73 @@ export interface ApplyTags {
|
|
|
60
124
|
readonly tags: Readonly<Record<string, readonly string[]>>;
|
|
61
125
|
}
|
|
62
126
|
/**
|
|
63
|
-
*
|
|
64
|
-
* dots kept (`AddCartItem` → `add-cart-item`,
|
|
65
|
-
* `wow.lifecycle.RestoreAggregate` → `wow.lifecycle.restore-aggregate`).
|
|
66
|
-
*
|
|
67
|
-
* @param name - The command's name
|
|
68
|
-
*/
|
|
69
|
-
export declare function commandSegment(name: string): string;
|
|
70
|
-
/**
|
|
71
|
-
* A new request id (`Wow-Request-Id`): a random UUID. The gateway generates
|
|
127
|
+
* A new request id (`Wow-Request-Id`): a random UUID. The client generates
|
|
72
128
|
* one for a command sent without; generate it first to retry with it however
|
|
73
129
|
* the request fails.
|
|
74
130
|
*/
|
|
75
131
|
export declare function newRequestId(): string;
|
|
76
132
|
/**
|
|
77
|
-
* Sends commands to the command routes of a Wow service
|
|
78
|
-
* (`POST /{context}/{aggregate}/{id}/{command}`,
|
|
79
|
-
*
|
|
80
|
-
*
|
|
133
|
+
* Sends commands to the command routes of a Wow service as its Manifest lists
|
|
134
|
+
* them (`POST /{context}/{aggregate}/{id}/{command}`, the route without
|
|
135
|
+
* `{id}` for a request that names none, `DELETE /{context}/{aggregate}/{id}`
|
|
136
|
+
* for `DeleteAggregate`): the Manifest the client is given, else the
|
|
137
|
+
* service's, fetched once (`GET /wow/manifest`). The TypeScript
|
|
138
|
+
* `CommandClient` of Kotlin's `me.ahoo.wow.api.client`: {@link send} answers
|
|
139
|
+
* once the command is accepted, {@link wait} with the result its wait plan
|
|
140
|
+
* ends with, {@link stream} with one result per hop. Generated aggregate
|
|
141
|
+
* clients build on it.
|
|
81
142
|
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
143
|
+
* `send` and `wait` resolve only a result that succeeded. A rejected one,
|
|
144
|
+
* by the aggregate or at admission, rejects with a
|
|
145
|
+
* {@link CommandRejectedError}; anything else that did not succeed with a
|
|
146
|
+
* {@link WowProblemError} (the table on {@link CommandRejectedError} says
|
|
147
|
+
* which). Every command carries a request id, the request's or a generated
|
|
148
|
+
* one, and whatever it rejects with carries that id ({@link requestIdOf}).
|
|
86
149
|
*/
|
|
87
|
-
export declare class
|
|
150
|
+
export declare class CommandClient {
|
|
88
151
|
readonly client: WowClientOptions;
|
|
89
|
-
|
|
90
|
-
|
|
152
|
+
private manifest;
|
|
153
|
+
private readonly bodyNumbers;
|
|
91
154
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
155
|
+
* @param client - How the service is reached
|
|
156
|
+
* @param options - The service's Manifest, and the commands' exact numbers
|
|
157
|
+
*/
|
|
158
|
+
constructor(client?: WowClientOptions, options?: CommandClientOptions);
|
|
159
|
+
/**
|
|
160
|
+
* Sends a command and answers once it is accepted (202), within the
|
|
161
|
+
* request's timeout (10 seconds without one), as Kotlin's
|
|
162
|
+
* `CommandClient.send`. A request whose `wait` waits for more rejects with a
|
|
163
|
+
* `TypeError` before it is sent: {@link wait} answers with that plan's result.
|
|
94
164
|
*
|
|
95
|
-
* @param
|
|
96
|
-
* @param body - The command's body; `{}` when absent
|
|
97
|
-
* @param options - Headers, wait and the aggregate id
|
|
165
|
+
* @param request - The command and how to send it
|
|
98
166
|
*/
|
|
99
|
-
send<R = Record<string, unknown>>(
|
|
167
|
+
send<R = Record<string, unknown>>(request: CommandRequest): Promise<CommandResult<R>>;
|
|
100
168
|
/**
|
|
101
|
-
* Sends a command
|
|
102
|
-
*
|
|
103
|
-
*
|
|
169
|
+
* Sends a command and answers the result its wait plan ends with: 200, or
|
|
170
|
+
* 202 for a plan that ends at `accepted`. Without a plan, the server's
|
|
171
|
+
* default: the snapshot, or the commit where the aggregate keeps no
|
|
172
|
+
* snapshot (decision D69).
|
|
104
173
|
*
|
|
105
|
-
* @param
|
|
106
|
-
* @param body - The command's body; `{}` when absent
|
|
107
|
-
* @param options - Headers, wait and the aggregate id
|
|
174
|
+
* @param request - The command and how to send it
|
|
108
175
|
*/
|
|
109
|
-
|
|
176
|
+
wait<R = Record<string, unknown>>(request: CommandRequest): Promise<CommandResult<R>>;
|
|
110
177
|
/**
|
|
111
|
-
* Sends a
|
|
112
|
-
*
|
|
113
|
-
*
|
|
178
|
+
* Sends a command with `Accept: text/event-stream` and answers one result
|
|
179
|
+
* per hop as the wait advances, whatever its status. An admission refusal
|
|
180
|
+
* rejects with its problem; a rejection after admission is the stream's
|
|
181
|
+
* last result.
|
|
114
182
|
*
|
|
115
|
-
* @param
|
|
116
|
-
* @param id - The aggregate's id
|
|
117
|
-
* @param command - The lifecycle command
|
|
118
|
-
* @param body - Its body, for the commands that have one
|
|
119
|
-
* @param options - Headers and wait
|
|
183
|
+
* @param request - The command and how to send it
|
|
120
184
|
*/
|
|
121
|
-
|
|
185
|
+
stream<R = Record<string, unknown>>(request: CommandRequest): Promise<CommandResultStream<R>>;
|
|
186
|
+
private exchange;
|
|
122
187
|
private post;
|
|
188
|
+
/**
|
|
189
|
+
* `request`'s command as the Manifest lists it, with its routes: a domain
|
|
190
|
+
* command among its aggregate's commands, by name or former name; a system
|
|
191
|
+
* command among its type's, else among its context's (a job's).
|
|
192
|
+
*/
|
|
193
|
+
private commandOf;
|
|
194
|
+
/** The Manifest given, or the service's, fetched once (again after a failure). */
|
|
195
|
+
private manifestOf;
|
|
123
196
|
}
|