@ahoo-wang/fetcher-wow 1.1.0 → 1.2.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 +275 -357
- package/README.zh-CN.md +283 -279
- package/dist/command/commandClient.d.ts +146 -0
- package/dist/command/commandClient.d.ts.map +1 -0
- package/dist/command/{commandHeaders.d.ts → commandHttpHeaders.d.ts} +6 -7
- package/dist/command/commandHttpHeaders.d.ts.map +1 -0
- package/dist/command/commandRequest.d.ts +26 -62
- package/dist/command/commandRequest.d.ts.map +1 -1
- package/dist/command/index.d.ts +2 -3
- package/dist/command/index.d.ts.map +1 -1
- package/dist/index.es.js +467 -226
- 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 +49 -4
- package/dist/query/event/domainEventStream.d.ts.map +1 -1
- package/dist/query/event/eventStreamQueryApi.d.ts +6 -0
- package/dist/query/event/eventStreamQueryApi.d.ts.map +1 -1
- package/dist/query/event/eventStreamQueryClient.d.ts +46 -0
- package/dist/query/event/eventStreamQueryClient.d.ts.map +1 -0
- package/dist/query/event/index.d.ts +1 -0
- package/dist/query/event/index.d.ts.map +1 -1
- package/dist/query/queryApi.d.ts +62 -0
- package/dist/query/queryApi.d.ts.map +1 -1
- package/dist/query/snapshot/index.d.ts +1 -0
- package/dist/query/snapshot/index.d.ts.map +1 -1
- package/dist/query/snapshot/snapshot.d.ts +2 -2
- package/dist/query/snapshot/snapshot.d.ts.map +1 -1
- package/dist/query/snapshot/snapshotQueryApi.d.ts +28 -0
- package/dist/query/snapshot/snapshotQueryApi.d.ts.map +1 -1
- package/dist/query/snapshot/snapshotQueryClient.d.ts +74 -0
- package/dist/query/snapshot/snapshotQueryClient.d.ts.map +1 -0
- package/dist/query/sort.d.ts +4 -0
- package/dist/query/sort.d.ts.map +1 -1
- package/dist/types/client.d.ts +15 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/endpoints.d.ts +28 -0
- package/dist/types/endpoints.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/command/commandHeaders.d.ts.map +0 -1
- package/dist/command/commandHttpClient.d.ts +0 -133
- package/dist/command/commandHttpClient.d.ts.map +0 -1
- package/dist/command/commandHttpRequest.d.ts +0 -48
- package/dist/command/commandHttpRequest.d.ts.map +0 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { CommandResult, CommandResultEventStream } from './commandResult';
|
|
2
|
+
import { ResultExtractor } from '@ahoo-wang/fetcher-decorator';
|
|
3
|
+
import { CommandRequest } from './commandRequest';
|
|
4
|
+
import { ClientOptions } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* HTTP client for sending commands to a remote service.
|
|
7
|
+
* Provides methods for sending commands and handling command results,
|
|
8
|
+
* including support for streaming responses.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Create a fetcher instance
|
|
13
|
+
* const wowFetcher = new Fetcher({
|
|
14
|
+
* baseURL: 'http://localhost:8080/',
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Add interceptor to handle URL parameters if needed
|
|
18
|
+
* wowFetcher.interceptors.request.use({
|
|
19
|
+
* name: 'UrlParamsInterceptor',
|
|
20
|
+
* order: URL_RESOLVE_INTERCEPTOR_ORDER - 1,
|
|
21
|
+
* intercept(exchange) {
|
|
22
|
+
* exchange.request.urlParams = {
|
|
23
|
+
* path: {
|
|
24
|
+
* ...exchange.request.urlParams?.path,
|
|
25
|
+
* },
|
|
26
|
+
* query: exchange.request.urlParams?.query,
|
|
27
|
+
* };
|
|
28
|
+
* },
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Create CommandClient instance
|
|
32
|
+
* const CommandClient = new CommandClient({
|
|
33
|
+
* fetcher: wowFetcher,
|
|
34
|
+
* basePath: 'owner/{ownerId}/cart'
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // Send a command
|
|
38
|
+
* const command = {
|
|
39
|
+
* method: HttpMethod.POST,
|
|
40
|
+
* headers: {
|
|
41
|
+
* [CommandHeaders.WAIT_STAGE]: CommandStage.SNAPSHOT,
|
|
42
|
+
* },
|
|
43
|
+
* urlParams: {
|
|
44
|
+
* path: {
|
|
45
|
+
* ownerId: 'ownerId',
|
|
46
|
+
* },
|
|
47
|
+
* },
|
|
48
|
+
* body: {
|
|
49
|
+
* productId: 'productId',
|
|
50
|
+
* quantity: 1,
|
|
51
|
+
* },
|
|
52
|
+
* };
|
|
53
|
+
*
|
|
54
|
+
* const result = await CommandClient.send('add_cart_item', command);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare class CommandClient {
|
|
58
|
+
protected readonly options: ClientOptions;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new CommandClient instance.
|
|
61
|
+
* @param options - The client configuration options including the fetcher and base path
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const CommandClient = new CommandClient({
|
|
66
|
+
* fetcher: wowFetcher,
|
|
67
|
+
* basePath: 'owner/{ownerId}/cart'
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
constructor(options: ClientOptions);
|
|
72
|
+
/**
|
|
73
|
+
* Sends a command to the specified path and returns the result.
|
|
74
|
+
* This is a protected generic method that handles the common logic for sending commands.
|
|
75
|
+
* @template R The type of the result to be returned
|
|
76
|
+
* @param path - The endpoint path to send the command to
|
|
77
|
+
* @param commandHttpRequest - The command HTTP request containing headers, method, and body
|
|
78
|
+
* @param extractor - Function to extract the result from the response, defaults to JSON extractor
|
|
79
|
+
* @returns A promise that resolves to the extracted result of type R
|
|
80
|
+
*/
|
|
81
|
+
protected sendCommand<R>(path: string, commandHttpRequest: CommandRequest, extractor?: ResultExtractor): Promise<R>;
|
|
82
|
+
/**
|
|
83
|
+
* Sends a command to the specified path and waits for a response.
|
|
84
|
+
*
|
|
85
|
+
* @param path - The endpoint path to send the command to
|
|
86
|
+
* @param commandHttpRequest - The command HTTP request containing headers, method, and body
|
|
87
|
+
* @returns A promise that resolves to a CommandResult
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const command = {
|
|
92
|
+
* method: HttpMethod.POST,
|
|
93
|
+
* headers: {
|
|
94
|
+
* [CommandHeaders.WAIT_STAGE]: CommandStage.SNAPSHOT,
|
|
95
|
+
* },
|
|
96
|
+
* urlParams: {
|
|
97
|
+
* path: {
|
|
98
|
+
* ownerId: 'ownerId',
|
|
99
|
+
* },
|
|
100
|
+
* },
|
|
101
|
+
* body: {
|
|
102
|
+
* productId: 'productId',
|
|
103
|
+
* quantity: 1,
|
|
104
|
+
* },
|
|
105
|
+
* };
|
|
106
|
+
*
|
|
107
|
+
* const result = await CommandClient.send('add_cart_item', command);
|
|
108
|
+
* console.log('Command result:', result);
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
send(path: string, commandHttpRequest: CommandRequest): Promise<CommandResult>;
|
|
112
|
+
/**
|
|
113
|
+
* Sends a command to the specified path and waits for a streaming response.
|
|
114
|
+
* Sets the Accept header to text/event-stream to indicate that the response should be streamed.
|
|
115
|
+
*
|
|
116
|
+
* @param path - The endpoint path to send the command to
|
|
117
|
+
* @param commandHttpRequest - The command HTTP request containing headers, method, and body
|
|
118
|
+
* @returns A promise that resolves to a CommandResultEventStream for handling streaming responses
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const command = {
|
|
123
|
+
* method: HttpMethod.POST,
|
|
124
|
+
* headers: {
|
|
125
|
+
* [CommandHeaders.WAIT_STAGE]: CommandStage.SNAPSHOT,
|
|
126
|
+
* },
|
|
127
|
+
* urlParams: {
|
|
128
|
+
* path: {
|
|
129
|
+
* ownerId: 'ownerId',
|
|
130
|
+
* },
|
|
131
|
+
* },
|
|
132
|
+
* body: {
|
|
133
|
+
* productId: 'productId',
|
|
134
|
+
* quantity: 1,
|
|
135
|
+
* },
|
|
136
|
+
* };
|
|
137
|
+
*
|
|
138
|
+
* const commandResultStream = await CommandClient.sendAndWaitStream('add_cart_item', command);
|
|
139
|
+
* for await (const commandResultEvent of commandResultStream) {
|
|
140
|
+
* console.log('Received:', commandResultEvent.data);
|
|
141
|
+
* }
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
sendAndWaitStream(path: string, commandHttpRequest: CommandRequest): Promise<CommandResultEventStream>;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=commandClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandClient.d.ts","sourceRoot":"","sources":["../../src/command/commandClient.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EACL,eAAe,EAEhB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,qBAAa,aAAa;IAaZ,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,aAAa;IAZrD;;;;;;;;;;;OAWG;gBAC4B,OAAO,EAAE,aAAa;IAGrD;;;;;;;;OAQG;cACa,WAAW,CAAC,CAAC,EAC3B,IAAI,EAAE,MAAM,EACZ,kBAAkB,EAAE,cAAc,EAClC,SAAS,GAAE,eAAuC,GACjD,OAAO,CAAC,CAAC,CAAC;IAUb;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,IAAI,CACF,IAAI,EAAE,MAAM,EACZ,kBAAkB,EAAE,cAAc,GACjC,OAAO,CAAC,aAAa,CAAC;IAIzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACG,iBAAiB,CACrB,IAAI,EAAE,MAAM,EACZ,kBAAkB,EAAE,cAAc,GACjC,OAAO,CAAC,wBAAwB,CAAC;CAWrC"}
|
|
@@ -8,17 +8,16 @@
|
|
|
8
8
|
* ```typescript
|
|
9
9
|
* // Using header constants in a request
|
|
10
10
|
* const request = {
|
|
11
|
-
* method: 'POST',
|
|
12
11
|
* headers: {
|
|
13
|
-
* [
|
|
14
|
-
* [
|
|
15
|
-
* [
|
|
12
|
+
* [CommandHttpHeaders.TENANT_ID]: 'tenant-123',
|
|
13
|
+
* [CommandHttpHeaders.AGGREGATE_ID]: 'aggregate-456',
|
|
14
|
+
* [CommandHttpHeaders.REQUEST_ID]: 'request-789'
|
|
16
15
|
* },
|
|
17
|
-
* body:
|
|
16
|
+
* body: command
|
|
18
17
|
* };
|
|
19
18
|
* ```
|
|
20
19
|
*/
|
|
21
|
-
export declare class
|
|
20
|
+
export declare class CommandHttpHeaders {
|
|
22
21
|
/**
|
|
23
22
|
* Prefix for all command-related headers
|
|
24
23
|
*/
|
|
@@ -127,4 +126,4 @@ export declare class CommandHeaders {
|
|
|
127
126
|
*/
|
|
128
127
|
static readonly COMMAND_HEADER_X_PREFIX: string;
|
|
129
128
|
}
|
|
130
|
-
//# sourceMappingURL=
|
|
129
|
+
//# sourceMappingURL=commandHttpHeaders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandHttpHeaders.d.ts","sourceRoot":"","sources":["../../src/command/commandHttpHeaders.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,kBAAkB;IAC7B;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,sBAAsB,cAAc;IAEpD;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,SAAS,SAA2D;IAEpF;;;OAGG;IACH,MAAM,CAAC,QAAQ,CA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chRequestInit, RequestHeaders, UrlParams } from '@ahoo-wang/fetcher';
|
|
2
|
+
import { PathParams } from '../types/endpoints';
|
|
3
3
|
/**
|
|
4
|
-
* Command
|
|
4
|
+
* Command Request Headers Interface
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* This interface extends
|
|
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
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
* ```typescript
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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
|
|
11
|
+
* // Using CommandRequestHeaders in a request
|
|
12
|
+
* const headers: CommandRequestHeaders = {
|
|
13
|
+
* [CommandHeaders.TENANT_ID]: 'tenant-123',
|
|
14
|
+
* [CommandHeaders.AGGREGATE_ID]: 'aggregate-456',
|
|
15
|
+
* [CommandHeaders.REQUEST_ID]: 'request-789'
|
|
25
16
|
* };
|
|
26
17
|
* ```
|
|
27
18
|
*/
|
|
28
|
-
export interface
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* HTTP headers for the command request
|
|
43
|
-
*/
|
|
44
|
-
headers: RequestHeaders;
|
|
45
|
-
/**
|
|
46
|
-
* Request body containing the command data
|
|
47
|
-
*/
|
|
48
|
-
body: Record<string, any>;
|
|
49
|
-
/**
|
|
50
|
-
* Command timeout period in milliseconds
|
|
51
|
-
*/
|
|
52
|
-
timeout?: number;
|
|
53
|
-
/**
|
|
54
|
-
* Aggregate ID for the command
|
|
55
|
-
*/
|
|
56
|
-
aggregateId?: string;
|
|
57
|
-
/**
|
|
58
|
-
* The version of the target aggregate, which is used to control version conflicts
|
|
59
|
-
*/
|
|
60
|
-
aggregateVersion?: number;
|
|
61
|
-
/**
|
|
62
|
-
* The request ID of the command message, which is used to check the idempotency of the command message
|
|
63
|
-
*/
|
|
64
|
-
requestId?: string;
|
|
65
|
-
/**
|
|
66
|
-
* Whether to enable local priority mode, if false, it will be turned off, and the default is true.
|
|
67
|
-
*/
|
|
68
|
-
localFirst?: boolean;
|
|
19
|
+
export interface CommandRequestHeaders extends RequestHeaders {
|
|
20
|
+
}
|
|
21
|
+
export interface CommandUrlParams extends Omit<UrlParams, 'path' | 'query'> {
|
|
22
|
+
path?: PathParams;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Command HTTP Request Interface
|
|
26
|
+
*
|
|
27
|
+
* Extends RequestHeaders to provide type-safe access to command-related HTTP headers.
|
|
28
|
+
* This interface includes only the essential command headers commonly used in HTTP requests.
|
|
29
|
+
*/
|
|
30
|
+
export interface CommandRequest<C extends object = object> extends FetchRequestInit {
|
|
31
|
+
urlParams?: CommandUrlParams;
|
|
32
|
+
headers?: CommandRequestHeaders;
|
|
69
33
|
/**
|
|
70
|
-
*
|
|
34
|
+
* The body of the command request.
|
|
71
35
|
*/
|
|
72
|
-
|
|
36
|
+
body: C;
|
|
73
37
|
}
|
|
74
38
|
//# sourceMappingURL=commandRequest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandRequest.d.ts","sourceRoot":"","sources":["../../src/command/commandRequest.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"commandRequest.d.ts","sourceRoot":"","sources":["../../src/command/commandRequest.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,SAAS,EACV,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,qBAAsB,SAAQ,cAAc;CA4G5D;AAED,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IACzE,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,gBAAgB;IACjF,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAChC;;OAEG;IACH,IAAI,EAAE,CAAC,CAAC;CACT"}
|
package/dist/command/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './commandHttpRequest';
|
|
1
|
+
export * from './commandClient';
|
|
2
|
+
export * from './commandHttpHeaders';
|
|
4
3
|
export * from './commandRequest';
|
|
5
4
|
export * from './commandResult';
|
|
6
5
|
export * from './types';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/command/index.ts"],"names":[],"mappings":"AAaA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/command/index.ts"],"names":[],"mappings":"AAaA,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
|