@ahoo-wang/fetcher-wow 1.0.2 → 1.0.6
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 +113 -96
- package/README.zh-CN.md +1 -86
- package/dist/command/commandHttpClient.d.ts +133 -0
- package/dist/command/commandHttpClient.d.ts.map +1 -0
- package/dist/command/commandHttpRequest.d.ts +48 -0
- package/dist/command/commandHttpRequest.d.ts.map +1 -0
- package/dist/command/index.d.ts +2 -0
- package/dist/command/index.d.ts.map +1 -1
- package/dist/index.es.js +241 -170
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/query/event/domainEventStream.d.ts +25 -0
- package/dist/query/event/domainEventStream.d.ts.map +1 -0
- package/dist/query/event/eventStreamQueryApi.d.ts +5 -0
- package/dist/query/event/eventStreamQueryApi.d.ts.map +1 -0
- package/dist/query/event/index.d.ts +3 -0
- package/dist/query/event/index.d.ts.map +1 -0
- package/dist/query/index.d.ts +5 -0
- package/dist/query/index.d.ts.map +1 -1
- package/dist/query/pagination.d.ts +23 -0
- package/dist/query/pagination.d.ts.map +1 -0
- package/dist/query/projection.d.ts +26 -0
- package/dist/query/projection.d.ts.map +1 -0
- package/dist/query/queryApi.d.ts +11 -0
- package/dist/query/queryApi.d.ts.map +1 -0
- package/dist/query/queryable.d.ts +3 -42
- package/dist/query/queryable.d.ts.map +1 -1
- package/dist/query/snapshot/index.d.ts +3 -0
- package/dist/query/snapshot/index.d.ts.map +1 -0
- package/dist/query/{snapshot.d.ts → snapshot/snapshot.d.ts} +1 -1
- package/dist/query/snapshot/snapshot.d.ts.map +1 -0
- package/dist/query/snapshot/snapshotQueryApi.d.ts +5 -0
- package/dist/query/snapshot/snapshotQueryApi.d.ts.map +1 -0
- package/dist/query/sort.d.ts +30 -0
- package/dist/query/sort.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/messaging.d.ts +4 -0
- package/dist/types/messaging.d.ts.map +1 -0
- package/package.json +4 -3
- package/dist/query/snapshot.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ const request = {
|
|
|
53
53
|
[CommandHeaders.AGGREGATE_ID]: 'aggregate-456',
|
|
54
54
|
[CommandHeaders.REQUEST_ID]: 'request-789',
|
|
55
55
|
},
|
|
56
|
-
body:
|
|
56
|
+
body: command,
|
|
57
57
|
};
|
|
58
58
|
```
|
|
59
59
|
|
|
@@ -99,28 +99,122 @@ Interface representing the result of command execution:
|
|
|
99
99
|
|
|
100
100
|
```typescript
|
|
101
101
|
import { CommandResult, CommandStage } from '@ahoo-wang/fetcher-wow';
|
|
102
|
+
```
|
|
102
103
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
104
|
+
#### CommandHttpClient
|
|
105
|
+
|
|
106
|
+
HTTP client for sending commands to the Wow framework. This client provides methods to send commands and receive results
|
|
107
|
+
either synchronously or as a stream of events.
|
|
108
|
+
|
|
109
|
+
##### Usage
|
|
110
|
+
|
|
111
|
+
First, create a fetcher instance with base configuration and add the EventStreamInterceptor:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { Fetcher } from '@ahoo-wang/fetcher';
|
|
115
|
+
import { EventStreamInterceptor } from '@ahoo-wang/fetcher-eventstream';
|
|
116
|
+
|
|
117
|
+
const wowFetcher = new Fetcher({
|
|
118
|
+
baseURL: 'http://localhost:8080/',
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Add EventStreamInterceptor to handle Server-Sent Events
|
|
122
|
+
wowFetcher.interceptors.response.use(new EventStreamInterceptor());
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Then create a CommandHttpClient instance:
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { CommandHttpClient } from '@ahoo-wang/fetcher-wow';
|
|
129
|
+
|
|
130
|
+
const commandHttpClient = new CommandHttpClient(wowFetcher);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
##### Sending a Command
|
|
134
|
+
|
|
135
|
+
To send a command and wait for the result:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import {
|
|
139
|
+
CommandHeaders,
|
|
140
|
+
CommandStage,
|
|
141
|
+
HttpMethod,
|
|
142
|
+
} from '@ahoo-wang/fetcher-wow';
|
|
143
|
+
|
|
144
|
+
const command = {
|
|
145
|
+
path: 'owner/{ownerId}/cart/add_cart_item',
|
|
146
|
+
method: HttpMethod.POST,
|
|
147
|
+
headers: {
|
|
148
|
+
[CommandHeaders.WAIT_STAGE]: CommandStage.SNAPSHOT,
|
|
149
|
+
},
|
|
150
|
+
urlParams: {
|
|
151
|
+
path: {
|
|
152
|
+
ownerId: 'ownerId',
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
body: {
|
|
156
|
+
productId: 'productId',
|
|
157
|
+
quantity: 1,
|
|
119
158
|
},
|
|
120
|
-
signalTime: Date.now(),
|
|
121
159
|
};
|
|
160
|
+
|
|
161
|
+
const result = await commandHttpClient.send(command);
|
|
162
|
+
console.log('Command result:', result);
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
##### Sending a Command and Receiving Stream Results
|
|
166
|
+
|
|
167
|
+
For long-running commands, you can receive results as a stream of events:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
const commandResultStream = await commandHttpClient.sendAndWaitStream(command);
|
|
171
|
+
for await (const commandResultEvent of commandResultStream) {
|
|
172
|
+
console.log('Received:', commandResultEvent.data);
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
##### API
|
|
177
|
+
|
|
178
|
+
**Constructor**
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
new CommandHttpClient(fetcher
|
|
182
|
+
:
|
|
183
|
+
Fetcher
|
|
184
|
+
)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Creates a new CommandHttpClient instance.
|
|
188
|
+
|
|
189
|
+
- `fetcher` - The Fetcher instance to use for HTTP requests
|
|
190
|
+
|
|
191
|
+
**send**
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
send(commandHttpRequest
|
|
195
|
+
:
|
|
196
|
+
CommandHttpRequest
|
|
197
|
+
):
|
|
198
|
+
Promise<CommandResult>
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Sends a command and waits for the result. This method sends a command to the Wow framework and waits for the processing
|
|
202
|
+
to complete before returning the result.
|
|
203
|
+
|
|
204
|
+
**sendAndWaitStream**
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
sendAndWaitStream(commandHttpRequest
|
|
208
|
+
:
|
|
209
|
+
CommandHttpRequest
|
|
210
|
+
):
|
|
211
|
+
Promise<CommandResultEventStream>
|
|
122
212
|
```
|
|
123
213
|
|
|
214
|
+
Sends a command and returns a stream of results as events. This method sets the Accept header to text/event-stream to
|
|
215
|
+
receive Server-Sent Events, and uses a JSON event stream result extractor to parse the response. It's useful for
|
|
216
|
+
long-running commands where you want to receive progress updates or multiple results.
|
|
217
|
+
|
|
124
218
|
#### CommandResultEventStream
|
|
125
219
|
|
|
126
220
|
Type alias for a readable stream of CommandResult events:
|
|
@@ -133,8 +227,6 @@ import { JsonServerSentEventStream } from '@ahoo-wang/fetcher-eventstream';
|
|
|
133
227
|
type CommandResultEventStream = JsonServerSentEventStream<CommandResult>;
|
|
134
228
|
```
|
|
135
229
|
|
|
136
|
-
````
|
|
137
|
-
|
|
138
230
|
### Query Module
|
|
139
231
|
|
|
140
232
|
#### Condition Builder
|
|
@@ -183,7 +275,7 @@ const dateConditions = [
|
|
|
183
275
|
thisWeek('updatedAt'),
|
|
184
276
|
lastMonth('createdDate'),
|
|
185
277
|
];
|
|
186
|
-
|
|
278
|
+
```
|
|
187
279
|
|
|
188
280
|
#### Operators
|
|
189
281
|
|
|
@@ -351,81 +443,6 @@ const functionInfo: FunctionInfo = {
|
|
|
351
443
|
|
|
352
444
|
## 🛠️ Advanced Usage
|
|
353
445
|
|
|
354
|
-
### Complete Command Flow Example
|
|
355
|
-
|
|
356
|
-
```typescript
|
|
357
|
-
import {
|
|
358
|
-
CommandRequest,
|
|
359
|
-
CommandHeaders,
|
|
360
|
-
CommandResult,
|
|
361
|
-
CommandStage,
|
|
362
|
-
} from '@ahoo-wang/fetcher-wow';
|
|
363
|
-
import { fetchEventStream } from '@ahoo-wang/fetcher-eventstream';
|
|
364
|
-
|
|
365
|
-
// 1. Create command request
|
|
366
|
-
const commandRequest: CommandRequest = {
|
|
367
|
-
path: '/commands/user/CreateUser',
|
|
368
|
-
method: 'POST',
|
|
369
|
-
headers: {
|
|
370
|
-
[CommandHeaders.TENANT_ID]: 'tenant-123',
|
|
371
|
-
[CommandHeaders.REQUEST_ID]: 'req-' + Date.now(),
|
|
372
|
-
},
|
|
373
|
-
body: {
|
|
374
|
-
name: 'John Doe',
|
|
375
|
-
email: 'john@example.com',
|
|
376
|
-
},
|
|
377
|
-
timeout: 10000,
|
|
378
|
-
localFirst: true,
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
// 2. Execute command and wait for result
|
|
382
|
-
async function executeCommand(request: CommandRequest): Promise<CommandResult> {
|
|
383
|
-
// Implementation depends on your HTTP client
|
|
384
|
-
// This is just an example structure
|
|
385
|
-
const response = await fetch('/api' + request.path, {
|
|
386
|
-
method: request.method,
|
|
387
|
-
headers: request.headers,
|
|
388
|
-
body: JSON.stringify(request.body),
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
return response.json();
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// 3. Stream command results in real-time
|
|
395
|
-
async function streamCommandResults() {
|
|
396
|
-
const eventStream = fetchEventStream('/commands/stream');
|
|
397
|
-
const commandResultStream = eventStream as CommandResultEventStream;
|
|
398
|
-
|
|
399
|
-
const reader = commandResultStream.getReader();
|
|
400
|
-
try {
|
|
401
|
-
while (true) {
|
|
402
|
-
const { done, value } = await reader.read();
|
|
403
|
-
if (done) break;
|
|
404
|
-
|
|
405
|
-
const result: CommandResult = value.data;
|
|
406
|
-
|
|
407
|
-
// Handle different stages
|
|
408
|
-
switch (result.stage) {
|
|
409
|
-
case CommandStage.SENT:
|
|
410
|
-
console.log('Command sent to bus');
|
|
411
|
-
break;
|
|
412
|
-
case CommandStage.PROCESSED:
|
|
413
|
-
console.log('Command processed by aggregate');
|
|
414
|
-
break;
|
|
415
|
-
case CommandStage.SNAPSHOT:
|
|
416
|
-
console.log('Snapshot generated');
|
|
417
|
-
break;
|
|
418
|
-
case CommandStage.PROJECTED:
|
|
419
|
-
console.log('Events projected to read model');
|
|
420
|
-
break;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
} finally {
|
|
424
|
-
reader.releaseLock();
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
```
|
|
428
|
-
|
|
429
446
|
### Complex Query Building
|
|
430
447
|
|
|
431
448
|
```typescript
|
package/README.zh-CN.md
CHANGED
|
@@ -133,16 +133,6 @@ import { JsonServerSentEventStream } from '@ahoo-wang/fetcher-eventstream';
|
|
|
133
133
|
type CommandResultEventStream = JsonServerSentEventStream<CommandResult>;
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
while (true) {
|
|
137
|
-
const { done, value } = await reader.read();
|
|
138
|
-
if (done) break;
|
|
139
|
-
|
|
140
|
-
const commandResult: CommandResult = value.data;
|
|
141
|
-
console.log('命令结果:', commandResult);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
````
|
|
145
|
-
|
|
146
136
|
### 查询模块
|
|
147
137
|
|
|
148
138
|
#### 条件构建器
|
|
@@ -191,7 +181,7 @@ const dateConditions = [
|
|
|
191
181
|
thisWeek('updatedAt'),
|
|
192
182
|
lastMonth('createdDate'),
|
|
193
183
|
];
|
|
194
|
-
|
|
184
|
+
```
|
|
195
185
|
|
|
196
186
|
#### 操作符
|
|
197
187
|
|
|
@@ -359,81 +349,6 @@ const functionInfo: FunctionInfo = {
|
|
|
359
349
|
|
|
360
350
|
## 🛠️ 高级用法
|
|
361
351
|
|
|
362
|
-
### 完整命令流程示例
|
|
363
|
-
|
|
364
|
-
```typescript
|
|
365
|
-
import {
|
|
366
|
-
CommandRequest,
|
|
367
|
-
CommandHeaders,
|
|
368
|
-
CommandResult,
|
|
369
|
-
CommandStage,
|
|
370
|
-
} from '@ahoo-wang/fetcher-wow';
|
|
371
|
-
import { fetchEventStream } from '@ahoo-wang/fetcher-eventstream';
|
|
372
|
-
|
|
373
|
-
// 1. 创建命令请求
|
|
374
|
-
const commandRequest: CommandRequest = {
|
|
375
|
-
path: '/commands/user/CreateUser',
|
|
376
|
-
method: 'POST',
|
|
377
|
-
headers: {
|
|
378
|
-
[CommandHeaders.TENANT_ID]: 'tenant-123',
|
|
379
|
-
[CommandHeaders.REQUEST_ID]: 'req-' + Date.now(),
|
|
380
|
-
},
|
|
381
|
-
body: {
|
|
382
|
-
name: 'John Doe',
|
|
383
|
-
email: 'john@example.com',
|
|
384
|
-
},
|
|
385
|
-
timeout: 10000,
|
|
386
|
-
localFirst: true,
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
// 2. 执行命令并等待结果
|
|
390
|
-
async function executeCommand(request: CommandRequest): Promise<CommandResult> {
|
|
391
|
-
// 实现依赖于您的 HTTP 客户端
|
|
392
|
-
// 这只是一个示例结构
|
|
393
|
-
const response = await fetch('/api' + request.path, {
|
|
394
|
-
method: request.method,
|
|
395
|
-
headers: request.headers,
|
|
396
|
-
body: JSON.stringify(request.body),
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
return response.json();
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// 3. 实时流式处理命令结果
|
|
403
|
-
async function streamCommandResults() {
|
|
404
|
-
const eventStream = fetchEventStream('/commands/stream');
|
|
405
|
-
const commandResultStream = eventStream as CommandResultEventStream;
|
|
406
|
-
|
|
407
|
-
const reader = commandResultStream.getReader();
|
|
408
|
-
try {
|
|
409
|
-
while (true) {
|
|
410
|
-
const { done, value } = await reader.read();
|
|
411
|
-
if (done) break;
|
|
412
|
-
|
|
413
|
-
const result: CommandResult = value.data;
|
|
414
|
-
|
|
415
|
-
// 处理不同阶段
|
|
416
|
-
switch (result.stage) {
|
|
417
|
-
case CommandStage.SENT:
|
|
418
|
-
console.log('命令已发送到总线');
|
|
419
|
-
break;
|
|
420
|
-
case CommandStage.PROCESSED:
|
|
421
|
-
console.log('命令已被聚合根处理');
|
|
422
|
-
break;
|
|
423
|
-
case CommandStage.SNAPSHOT:
|
|
424
|
-
console.log('已生成快照');
|
|
425
|
-
break;
|
|
426
|
-
case CommandStage.PROJECTED:
|
|
427
|
-
console.log('事件已投影到读模型');
|
|
428
|
-
break;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
} finally {
|
|
432
|
-
reader.releaseLock();
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
```
|
|
436
|
-
|
|
437
352
|
### 复杂查询构建
|
|
438
353
|
|
|
439
354
|
```typescript
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Fetcher } from '@ahoo-wang/fetcher';
|
|
2
|
+
import { CommandResult, CommandResultEventStream } from './commandResult';
|
|
3
|
+
import { CommandHttpRequest } from './commandHttpRequest';
|
|
4
|
+
/**
|
|
5
|
+
* HTTP client for sending commands to the Wow framework.
|
|
6
|
+
*
|
|
7
|
+
* This client provides methods to send commands and receive results either
|
|
8
|
+
* synchronously or as a stream of events. It uses the fetcher-decorator
|
|
9
|
+
* library to handle HTTP communication with appropriate headers and
|
|
10
|
+
* result extraction.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Create a fetcher instance with base configuration
|
|
15
|
+
* const wowFetcher = new Fetcher({
|
|
16
|
+
* baseURL: 'http://localhost:8080/',
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Add EventStreamInterceptor to handle Server-Sent Events
|
|
20
|
+
* wowFetcher.interceptors.response.use(new EventStreamInterceptor());
|
|
21
|
+
*
|
|
22
|
+
* // Create CommandHttpClient instance
|
|
23
|
+
* const commandHttpClient = new CommandHttpClient(wowFetcher);
|
|
24
|
+
*
|
|
25
|
+
* // Define a command
|
|
26
|
+
* const command: CommandHttpRequest = {
|
|
27
|
+
* path: 'owner/{ownerId}/cart/add_cart_item',
|
|
28
|
+
* method: HttpMethod.POST,
|
|
29
|
+
* headers: {
|
|
30
|
+
* [CommandHeaders.WAIT_STAGE]: CommandStage.SNAPSHOT,
|
|
31
|
+
* },
|
|
32
|
+
* urlParams: {
|
|
33
|
+
* path: {
|
|
34
|
+
* ownerId: 'ownerId',
|
|
35
|
+
* },
|
|
36
|
+
* },
|
|
37
|
+
* body: {
|
|
38
|
+
* productId: 'productId',
|
|
39
|
+
* quantity: 1,
|
|
40
|
+
* },
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* // Send command and wait for result
|
|
44
|
+
* const commandResult = await commandHttpClient.send(command);
|
|
45
|
+
*
|
|
46
|
+
* // Send command and receive result as stream
|
|
47
|
+
* const commandResultStream = await commandHttpClient.sendAndWaitStream(command);
|
|
48
|
+
* for await (const commandResultEvent of commandResultStream) {
|
|
49
|
+
* console.log('Received:', commandResultEvent.data);
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare class CommandHttpClient {
|
|
54
|
+
readonly fetcher: Fetcher;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a new CommandHttpClient instance.
|
|
57
|
+
*
|
|
58
|
+
* @param fetcher - The Fetcher instance to use for HTTP requests
|
|
59
|
+
*/
|
|
60
|
+
constructor(fetcher: Fetcher);
|
|
61
|
+
/**
|
|
62
|
+
* Sends a command and waits for the result.
|
|
63
|
+
*
|
|
64
|
+
* This method sends a command to the Wow framework and waits for the processing
|
|
65
|
+
* to complete before returning the result. The command is sent as an HTTP request
|
|
66
|
+
* with the specified path, method, headers, and body.
|
|
67
|
+
*
|
|
68
|
+
* @param commandHttpRequest - The command HTTP request to send
|
|
69
|
+
* @returns A promise that resolves to the command result
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const command: CommandHttpRequest = {
|
|
74
|
+
* path: 'owner/{ownerId}/cart/add_cart_item',
|
|
75
|
+
* method: HttpMethod.POST,
|
|
76
|
+
* headers: {
|
|
77
|
+
* [CommandHeaders.WAIT_STAGE]: CommandStage.SNAPSHOT,
|
|
78
|
+
* },
|
|
79
|
+
* urlParams: {
|
|
80
|
+
* path: {
|
|
81
|
+
* ownerId: 'ownerId',
|
|
82
|
+
* },
|
|
83
|
+
* },
|
|
84
|
+
* body: {
|
|
85
|
+
* productId: 'productId',
|
|
86
|
+
* quantity: 1,
|
|
87
|
+
* },
|
|
88
|
+
* };
|
|
89
|
+
*
|
|
90
|
+
* const result = await commandHttpClient.send(command);
|
|
91
|
+
* console.log('Command result:', result);
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
send(commandHttpRequest: CommandHttpRequest): Promise<CommandResult>;
|
|
95
|
+
/**
|
|
96
|
+
* Sends a command and returns a stream of results as events.
|
|
97
|
+
*
|
|
98
|
+
* This method sets the Accept header to text/event-stream to receive
|
|
99
|
+
* Server-Sent Events, and uses a JSON event stream result extractor
|
|
100
|
+
* to parse the response. It's useful for long-running commands where
|
|
101
|
+
* you want to receive progress updates or multiple results.
|
|
102
|
+
*
|
|
103
|
+
* @param commandHttpRequest - The command HTTP request to send
|
|
104
|
+
* @returns A promise that resolves to a stream of command results
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const command: CommandHttpRequest = {
|
|
109
|
+
* path: 'owner/{ownerId}/cart/add_cart_item',
|
|
110
|
+
* method: HttpMethod.POST,
|
|
111
|
+
* headers: {
|
|
112
|
+
* [CommandHeaders.WAIT_STAGE]: CommandStage.SNAPSHOT,
|
|
113
|
+
* },
|
|
114
|
+
* urlParams: {
|
|
115
|
+
* path: {
|
|
116
|
+
* ownerId: 'ownerId',
|
|
117
|
+
* },
|
|
118
|
+
* },
|
|
119
|
+
* body: {
|
|
120
|
+
* productId: 'productId',
|
|
121
|
+
* quantity: 1,
|
|
122
|
+
* },
|
|
123
|
+
* };
|
|
124
|
+
*
|
|
125
|
+
* const stream = await commandHttpClient.sendAndWaitStream(command);
|
|
126
|
+
* for await (const event of stream) {
|
|
127
|
+
* console.log('Command result event:', event.data);
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
sendAndWaitStream(commandHttpRequest: CommandHttpRequest): Promise<CommandResultEventStream>;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=commandHttpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandHttpClient.d.ts","sourceRoot":"","sources":["../../src/command/commandHttpClient.ts"],"names":[],"mappings":"AAaA,OAAO,EAAqB,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAQ1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,qBACa,iBAAiB;aAMA,OAAO,EAAE,OAAO;IAL5C;;;;OAIG;gBACyB,OAAO,EAAE,OAAO;IAG5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IAEH,IAAI,CACS,kBAAkB,EAAE,kBAAkB,GAChD,OAAO,CAAC,aAAa,CAAC;IAIzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IAOG,iBAAiB,CACV,kBAAkB,EAAE,kBAAkB,GAChD,OAAO,CAAC,wBAAwB,CAAC;CAGrC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { RequestHeaders, UrlParams } from '@ahoo-wang/fetcher';
|
|
2
|
+
import { ParameterRequest } from '@ahoo-wang/fetcher-decorator';
|
|
3
|
+
/**
|
|
4
|
+
* Command HTTP Headers Interface
|
|
5
|
+
*
|
|
6
|
+
* Defines the HTTP header fields used in command processing within the Wow framework.
|
|
7
|
+
* This interface extends RequestHeaders to provide type-safe access to all command-related headers.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Using CommandHttpHeaders in a request
|
|
12
|
+
* const headers: CommandHttpHeaders = {
|
|
13
|
+
* [CommandHeaders.TENANT_ID]: 'tenant-123',
|
|
14
|
+
* [CommandHeaders.AGGREGATE_ID]: 'aggregate-456',
|
|
15
|
+
* [CommandHeaders.REQUEST_ID]: 'request-789'
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface CommandHttpHeaders extends RequestHeaders {
|
|
20
|
+
}
|
|
21
|
+
export interface CommandPathParams {
|
|
22
|
+
tenantId?: string;
|
|
23
|
+
ownerId?: string;
|
|
24
|
+
id?: string;
|
|
25
|
+
[key: string]: string | undefined;
|
|
26
|
+
}
|
|
27
|
+
export interface CommandUrlParams extends Omit<UrlParams, 'path' | 'query'> {
|
|
28
|
+
path?: CommandPathParams;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Command HTTP Request Interface
|
|
32
|
+
*
|
|
33
|
+
* Extends RequestHeaders to provide type-safe access to command-related HTTP headers.
|
|
34
|
+
* This interface includes only the essential command headers commonly used in HTTP requests.
|
|
35
|
+
*/
|
|
36
|
+
export interface CommandHttpRequest extends ParameterRequest {
|
|
37
|
+
/**
|
|
38
|
+
* Path for the command endpoint (relative to class base path).
|
|
39
|
+
*/
|
|
40
|
+
path: string;
|
|
41
|
+
urlParams?: CommandUrlParams;
|
|
42
|
+
headers?: CommandHttpHeaders;
|
|
43
|
+
/**
|
|
44
|
+
* The body of the command request.
|
|
45
|
+
*/
|
|
46
|
+
body: any;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=commandHttpRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandHttpRequest.d.ts","sourceRoot":"","sources":["../../src/command/commandHttpRequest.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,kBAAmB,SAAQ,cAAc;CA4GzD;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IACzE,IAAI,CAAC,EAAE,iBAAiB,CAAC;CAC1B;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B;;OAEG;IACH,IAAI,EAAE,GAAG,CAAC;CACX"}
|
package/dist/command/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/command/index.ts"],"names":[],"mappings":"AAaA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/command/index.ts"],"names":[],"mappings":"AAaA,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
|