@ahoo-wang/fetcher-wow 0.10.0 → 0.11.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 CHANGED
@@ -124,30 +124,18 @@ const commandResult: CommandResult = {
124
124
 
125
125
  #### CommandResultEventStream
126
126
 
127
- Utilities for working with command result event streams:
127
+ Type alias for a readable stream of CommandResult events:
128
128
 
129
129
  ```typescript
130
- import {
131
- toCommandResultEventStream,
132
- CommandResultEvent,
133
- } from '@ahoo-wang/fetcher-wow';
134
- import { fetchEventStream } from '@ahoo-wang/fetcher-eventstream';
135
-
136
- // Convert ServerSentEventStream to CommandResultEventStream
137
- const eventStream = fetchEventStream('/commands/stream');
138
- const commandResultStream = toCommandResultEventStream(eventStream);
130
+ import { CommandResult } from '@ahoo-wang/fetcher-wow';
131
+ import { JsonServerSentEventStream } from '@ahoo-wang/fetcher-eventstream';
139
132
 
140
- // Process command results as they arrive
141
- const reader = commandResultStream.getReader();
142
- while (true) {
143
- const { done, value } = await reader.read();
144
- if (done) break;
145
-
146
- const commandResult: CommandResult = value.data;
147
- console.log('Command result:', commandResult);
148
- }
133
+ // CommandResultEventStream is a JsonServerSentEventStream of CommandResult
134
+ type CommandResultEventStream = JsonServerSentEventStream<CommandResult>;
149
135
  ```
150
136
 
137
+ ````
138
+
151
139
  ### Query Module
152
140
 
153
141
  #### Condition Builder
@@ -196,7 +184,7 @@ const dateConditions = [
196
184
  thisWeek('updatedAt'),
197
185
  lastMonth('createdDate'),
198
186
  ];
199
- ```
187
+ ````
200
188
 
201
189
  #### Operators
202
190
 
@@ -372,7 +360,6 @@ import {
372
360
  CommandHeaders,
373
361
  CommandResult,
374
362
  CommandStage,
375
- toCommandResultEventStream,
376
363
  } from '@ahoo-wang/fetcher-wow';
377
364
  import { fetchEventStream } from '@ahoo-wang/fetcher-eventstream';
378
365
 
@@ -408,7 +395,7 @@ async function executeCommand(request: CommandRequest): Promise<CommandResult> {
408
395
  // 3. Stream command results in real-time
409
396
  async function streamCommandResults() {
410
397
  const eventStream = fetchEventStream('/commands/stream');
411
- const commandResultStream = toCommandResultEventStream(eventStream);
398
+ const commandResultStream = eventStream as CommandResultEventStream;
412
399
 
413
400
  const reader = commandResultStream.getReader();
414
401
  try {
package/README.zh-CN.md CHANGED
@@ -123,29 +123,25 @@ const commandResult: CommandResult = {
123
123
 
124
124
  #### CommandResultEventStream
125
125
 
126
- 用于处理命令结果事件流的工具:
126
+ 命令结果事件流的类型别名:
127
127
 
128
128
  ```typescript
129
- import {
130
- toCommandResultEventStream,
131
- CommandResultEvent,
132
- } from '@ahoo-wang/fetcher-wow';
133
- import { fetchEventStream } from '@ahoo-wang/fetcher-eventstream';
129
+ import { CommandResult } from '@ahoo-wang/fetcher-wow';
130
+ import { JsonServerSentEventStream } from '@ahoo-wang/fetcher-eventstream';
134
131
 
135
- // ServerSentEventStream 转换为 CommandResultEventStream
136
- const eventStream = fetchEventStream('/commands/stream');
137
- const commandResultStream = toCommandResultEventStream(eventStream);
132
+ // CommandResultEventStream CommandResult 的 JsonServerSentEventStream
133
+ type CommandResultEventStream = JsonServerSentEventStream<CommandResult>;
134
+ ```
138
135
 
139
- // 处理实时到达的命令结果
140
- const reader = commandResultStream.getReader();
141
136
  while (true) {
142
- const { done, value } = await reader.read();
143
- if (done) break;
137
+ const { done, value } = await reader.read();
138
+ if (done) break;
144
139
 
145
- const commandResult: CommandResult = value.data;
146
- console.log('命令结果:', commandResult);
140
+ const commandResult: CommandResult = value.data;
141
+ console.log('命令结果:', commandResult);
147
142
  }
148
- ```
143
+
144
+ ````
149
145
 
150
146
  ### 查询模块
151
147
 
@@ -195,7 +191,7 @@ const dateConditions = [
195
191
  thisWeek('updatedAt'),
196
192
  lastMonth('createdDate'),
197
193
  ];
198
- ```
194
+ ````
199
195
 
200
196
  #### 操作符
201
197
 
@@ -371,7 +367,6 @@ import {
371
367
  CommandHeaders,
372
368
  CommandResult,
373
369
  CommandStage,
374
- toCommandResultEventStream,
375
370
  } from '@ahoo-wang/fetcher-wow';
376
371
  import { fetchEventStream } from '@ahoo-wang/fetcher-eventstream';
377
372
 
@@ -407,7 +402,7 @@ async function executeCommand(request: CommandRequest): Promise<CommandResult> {
407
402
  // 3. 实时流式处理命令结果
408
403
  async function streamCommandResults() {
409
404
  const eventStream = fetchEventStream('/commands/stream');
410
- const commandResultStream = toCommandResultEventStream(eventStream);
405
+ const commandResultStream = eventStream as CommandResultEventStream;
411
406
 
412
407
  const reader = commandResultStream.getReader();
413
408
  try {
@@ -1,15 +1,58 @@
1
1
  import { NullableAggregateVersionCapable } from './types';
2
2
  import { HttpMethod, RequestHeaders } from '@ahoo-wang/fetcher';
3
+ /**
4
+ * Command request interface
5
+ *
6
+ * Represents a command request with all necessary metadata for execution.
7
+ * This interface extends NullableAggregateVersionCapable to include optional aggregate version information.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const commandRequest: CommandRequest = {
12
+ * path: '/commands/user/CreateUser',
13
+ * method: HttpMethod.POST,
14
+ * headers: {
15
+ * [CommandHeaders.TENANT_ID]: 'tenant-123',
16
+ * [CommandHeaders.REQUEST_ID]: 'req-' + Date.now()
17
+ * },
18
+ * body: {
19
+ * name: 'John Doe',
20
+ * email: 'john@example.com'
21
+ * },
22
+ * timeout: 10000,
23
+ * localFirst: true,
24
+ * stream: false
25
+ * };
26
+ * ```
27
+ */
3
28
  export interface CommandRequest extends NullableAggregateVersionCapable {
29
+ /**
30
+ * The path for the command request
31
+ */
4
32
  path: string;
33
+ /**
34
+ * Path parameters for the command request
35
+ */
5
36
  pathParams?: Record<string, any>;
37
+ /**
38
+ * HTTP method for the command request
39
+ */
6
40
  method: HttpMethod;
41
+ /**
42
+ * HTTP headers for the command request
43
+ */
7
44
  headers: RequestHeaders;
45
+ /**
46
+ * Request body containing the command data
47
+ */
8
48
  body: Record<string, any>;
9
49
  /**
10
- * Command timeout period. Milliseconds
50
+ * Command timeout period in milliseconds
11
51
  */
12
52
  timeout?: number;
53
+ /**
54
+ * Aggregate ID for the command
55
+ */
13
56
  aggregateId?: string;
14
57
  /**
15
58
  * The version of the target aggregate, which is used to control version conflicts
@@ -1 +1 @@
1
- {"version":3,"file":"commandRequest.d.ts","sourceRoot":"","sources":["../../src/command/commandRequest.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEhE,MAAM,WAAW,cAAe,SAAQ,+BAA+B;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,cAAc,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB"}
1
+ {"version":3,"file":"commandRequest.d.ts","sourceRoot":"","sources":["../../src/command/commandRequest.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,WAAW,cAAe,SAAQ,+BAA+B;IACrE;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEjC;;OAEG;IACH,MAAM,EAAE,UAAU,CAAC;IAEnB;;OAEG;IACH,OAAO,EAAE,cAAc,CAAC;IAExB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE1B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB"}
@@ -1,12 +1,39 @@
1
1
  import { AggregateId, AggregateNameCapable, ErrorInfo, FunctionInfoCapable, Identifier, NamedBoundedContext } from '../types';
2
2
  import { CommandId, CommandResultCapable, CommandStageCapable, NullableAggregateVersionCapable, RequestId, SignalTimeCapable, WaitCommandIdCapable } from './types';
3
+ import { JsonServerSentEvent } from '@ahoo-wang/fetcher-eventstream';
4
+ /**
5
+ * Command execution result interface
6
+ *
7
+ * Represents the result of a command execution, containing information about:
8
+ * - Command identification (commandId, requestId)
9
+ * - Execution context (bounded context, aggregate information)
10
+ * - Execution status and errors
11
+ * - Timing information (signalTime)
12
+ * - Version tracking (aggregateVersion)
13
+ */
3
14
  export interface CommandResult extends Identifier, WaitCommandIdCapable, CommandStageCapable, NamedBoundedContext, AggregateNameCapable, AggregateId, ErrorInfo, CommandId, RequestId, ErrorInfo, FunctionInfoCapable, CommandResultCapable, SignalTimeCapable, NullableAggregateVersionCapable {
4
15
  /**
5
- * 聚合根版本号
6
- * - 命令处理成功时,为聚合根完成命令处理后的版本号
7
- * - 当命令在命令网关验证失败时,为 null
8
- * - 当命令在命令处理器中执行失败时,为聚合根的当前版本号
16
+ * Aggregate root version number
17
+ * - When command processing succeeds, this is the version number after the aggregate root has completed command processing
18
+ * - When command validation fails at the command gateway, this is null
19
+ * - When command execution fails in the command handler, this is the current version number of the aggregate root
9
20
  */
10
21
  aggregateVersion?: number;
11
22
  }
23
+ /**
24
+ * Command result event stream type
25
+ *
26
+ * A readable stream of JSON Server-Sent Events containing command execution results.
27
+ * This stream allows real-time consumption of command results as they are processed.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const eventStream: CommandResultEventStream = getCommandResultStream();
32
+ * for await (const event of eventStream) {
33
+ * const commandResult: CommandResult = event.data;
34
+ * console.log('Command result received:', commandResult);
35
+ * }
36
+ * ```
37
+ */
38
+ export type CommandResultEventStream = ReadableStream<JsonServerSentEvent<CommandResult>>;
12
39
  //# sourceMappingURL=commandResult.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commandResult.d.ts","sourceRoot":"","sources":["../../src/command/commandResult.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,WAAW,EACX,oBAAoB,EACpB,SAAS,EACT,mBAAmB,EACnB,UAAU,EACV,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,mBAAmB,EACnB,+BAA+B,EAC/B,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,aACf,SAAQ,UAAU,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,mBAAmB,EAChF,oBAAoB,EACpB,WAAW,EACX,SAAS,EACT,SAAS,EACT,SAAS,EAAE,SAAS,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,+BAA+B;IACrH;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAE3B"}
1
+ {"version":3,"file":"commandResult.d.ts","sourceRoot":"","sources":["../../src/command/commandResult.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,WAAW,EACX,oBAAoB,EACpB,SAAS,EACT,mBAAmB,EACnB,UAAU,EACV,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,mBAAmB,EACnB,+BAA+B,EAC/B,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE;;;;;;;;;GASG;AACH,MAAM,WAAW,aACf,SAAQ,UAAU,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,WAAW,EACX,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,+BAA+B;IACjC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,wBAAwB,GAAG,cAAc,CACnD,mBAAmB,CAAC,aAAa,CAAC,CACnC,CAAC"}
@@ -1,6 +1,5 @@
1
1
  export * from './commandHeaders';
2
2
  export * from './commandRequest';
3
3
  export * from './commandResult';
4
- export * from './commandResultEventStream';
5
4
  export * from './types';
6
5
  //# sourceMappingURL=index.d.ts.map
@@ -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,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC"}
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,47 +1,87 @@
1
+ /**
2
+ * Command identifier interface
3
+ *
4
+ * Represents the unique identifier for a command.
5
+ */
1
6
  export interface CommandId {
2
7
  commandId: string;
3
8
  }
9
+ /**
10
+ * Wait command identifier capable interface
11
+ *
12
+ * Represents the identifier of the command being waited for.
13
+ */
4
14
  export interface WaitCommandIdCapable {
5
15
  waitCommandId: string;
6
16
  }
17
+ /**
18
+ * Request identifier interface
19
+ *
20
+ * Represents the unique identifier for a request, used for idempotency control.
21
+ */
7
22
  export interface RequestId {
8
23
  requestId: string;
9
24
  }
25
+ /**
26
+ * Command execution stage enum
27
+ *
28
+ * Represents the different stages of command execution lifecycle.
29
+ */
10
30
  export declare enum CommandStage {
11
31
  /**
12
- * 当命令发布到命令总线/队列后,生成完成信号.
32
+ * When the command is published to the command bus/queue, a completion signal is generated.
13
33
  */
14
34
  SENT = "SENT",
15
35
  /**
16
- * 当命令被聚合根处理完成后,生成完成信号.
36
+ * When the command is processed by the aggregate root, a completion signal is generated.
17
37
  */
18
38
  PROCESSED = "PROCESSED",
19
39
  /**
20
- * 当快照被生成后,生成完成信号.
40
+ * When the snapshot is generated, a completion signal is generated.
21
41
  */
22
42
  SNAPSHOT = "SNAPSHOT",
23
43
  /**
24
- * 当命令产生的事件*投影*完成后,生成完成信号.
44
+ * When the events generated by the command are *projected*, a completion signal is generated.
25
45
  */
26
46
  PROJECTED = "PROJECTED",
27
47
  /**
28
- * 当命令产生的事件被*事件处理器*处理完成后,生成完成信号.
48
+ * When the events generated by the command are processed by *event handlers*, a completion signal is generated.
29
49
  */
30
50
  EVENT_HANDLED = "EVENT_HANDLED",
31
51
  /**
32
- * 当命令产生的事件被*Saga*处理完成后,生成完成信号.
52
+ * When the events generated by the command are processed by *Saga*, a completion signal is generated.
33
53
  */
34
54
  SAGA_HANDLED = "SAGA_HANDLED"
35
55
  }
56
+ /**
57
+ * Command stage capable interface
58
+ *
59
+ * Represents an object that has a command execution stage.
60
+ */
36
61
  export interface CommandStageCapable {
37
62
  stage: CommandStage;
38
63
  }
64
+ /**
65
+ * Command result capable interface
66
+ *
67
+ * Represents an object that contains command execution results.
68
+ */
39
69
  export interface CommandResultCapable {
40
70
  result: Record<string, any>;
41
71
  }
72
+ /**
73
+ * Signal time capable interface
74
+ *
75
+ * Represents an object that has a signal time (timestamp).
76
+ */
42
77
  export interface SignalTimeCapable {
43
78
  signalTime: number;
44
79
  }
80
+ /**
81
+ * Nullable aggregate version capable interface
82
+ *
83
+ * Represents an object that may have an aggregate version for optimistic concurrency control.
84
+ */
45
85
  export interface NullableAggregateVersionCapable {
46
86
  /**
47
87
  * The aggregate version of the aggregate.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/command/types.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,oBAAY,YAAY;IACtB;;OAEG;IACH,IAAI,SAAS;IACb;;OAEG;IACH,SAAS,cAAc;IACvB;;OAEG;IACH,QAAQ,aAAa;IACrB;;OAEG;IACH,SAAS,cAAc;IACvB;;OAEG;IACH,aAAa,kBAAkB;IAE/B;;OAEG;IACH,YAAY,iBAAiB;CAC9B;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,YAAY,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC7B;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,+BAA+B;IAC9C;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/command/types.ts"],"names":[],"mappings":"AAaA;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,oBAAY,YAAY;IACtB;;OAEG;IACH,IAAI,SAAS;IAEb;;OAEG;IACH,SAAS,cAAc;IAEvB;;OAEG;IACH,QAAQ,aAAa;IAErB;;OAEG;IACH,SAAS,cAAc;IAEvB;;OAEG;IACH,aAAa,kBAAkB;IAE/B;;OAEG;IACH,YAAY,iBAAiB;CAC9B;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,YAAY,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B"}