@takentrade/takentrade-libs 1.2.52 → 1.2.53
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/dist/rpc/index.d.ts +15 -4
- package/dist/rpc/index.js +16 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
package/dist/rpc/index.d.ts
CHANGED
|
@@ -8,13 +8,19 @@ export interface TakeNTradeRPCError {
|
|
|
8
8
|
errors: string[];
|
|
9
9
|
timestamp: string;
|
|
10
10
|
}
|
|
11
|
+
export interface TakeNTradeRPCResponse<V> {
|
|
12
|
+
status: 'success';
|
|
13
|
+
message: string;
|
|
14
|
+
data: V;
|
|
15
|
+
}
|
|
11
16
|
export declare class TakeNTradeRpc {
|
|
12
17
|
/**
|
|
13
18
|
* Wraps a promise returned by an RPC request handler.
|
|
14
19
|
* @param promise - A Promise resolving to the response value.
|
|
15
20
|
* @param ctx - Optional NatsContext object.
|
|
21
|
+
* @param successMessage - Custom success message for the response.
|
|
16
22
|
*/
|
|
17
|
-
static handleRequest<V>(promise: Promise<V>, ctx?: NatsContext): Promise<V | RpcException>;
|
|
23
|
+
static handleRequest<V>(promise: Promise<V>, ctx?: NatsContext, successMessage?: string): Promise<TakeNTradeRPCResponse<V> | RpcException>;
|
|
18
24
|
/**
|
|
19
25
|
* Handles errors from an RPC request handler and returns a TakeNTradeRPCError wrapped in RpcException.
|
|
20
26
|
* @param err - Error to be handled.
|
|
@@ -26,15 +32,18 @@ export declare class TakeNTradeRpc {
|
|
|
26
32
|
* Handles NATS request response.
|
|
27
33
|
* @param obs - An instance of an Observable.
|
|
28
34
|
*/
|
|
29
|
-
static withReply<V>(obs: Observable<V>
|
|
35
|
+
static withReply<V>(obs: Observable<TakeNTradeRPCResponse<V> | {
|
|
36
|
+
error: TakeNTradeRPCError;
|
|
37
|
+
}>): Promise<V>;
|
|
30
38
|
}
|
|
31
39
|
export declare class TakeNTradeRpcV2 {
|
|
32
40
|
/**
|
|
33
41
|
* Wraps a promise returned by an RPC request handler.
|
|
34
42
|
* @param promise - A Promise resolving to the response value.
|
|
35
43
|
* @param ctx - Optional NatsContext object.
|
|
44
|
+
* @param successMessage - Custom success message for the response.
|
|
36
45
|
*/
|
|
37
|
-
static handleRequest<V>(promise: Promise<V>, ctx?: NatsContext): Promise<V | TakeNTradeRPCError>;
|
|
46
|
+
static handleRequest<V>(promise: Promise<V>, ctx?: NatsContext, successMessage?: string): Promise<TakeNTradeRPCResponse<V> | TakeNTradeRPCError>;
|
|
38
47
|
/**
|
|
39
48
|
* Handles errors from an RPC request handler and returns a TakeNTradeRPCError.
|
|
40
49
|
* @param err - Error to be handled.
|
|
@@ -46,5 +55,7 @@ export declare class TakeNTradeRpcV2 {
|
|
|
46
55
|
* Handles NATS request response.
|
|
47
56
|
* @param obs - An instance of an Observable.
|
|
48
57
|
*/
|
|
49
|
-
static withReply<V>(obs: Observable<V>
|
|
58
|
+
static withReply<V>(obs: Observable<TakeNTradeRPCResponse<V> | {
|
|
59
|
+
error: TakeNTradeRPCError;
|
|
60
|
+
}>): Promise<V>;
|
|
50
61
|
}
|
package/dist/rpc/index.js
CHANGED
|
@@ -27,10 +27,15 @@ class TakeNTradeRpc {
|
|
|
27
27
|
* Wraps a promise returned by an RPC request handler.
|
|
28
28
|
* @param promise - A Promise resolving to the response value.
|
|
29
29
|
* @param ctx - Optional NatsContext object.
|
|
30
|
+
* @param successMessage - Custom success message for the response.
|
|
30
31
|
*/
|
|
31
|
-
static async handleRequest(promise, ctx) {
|
|
32
|
+
static async handleRequest(promise, ctx, successMessage = 'Operation successful') {
|
|
32
33
|
return promise
|
|
33
|
-
.then((value) =>
|
|
34
|
+
.then((value) => ({
|
|
35
|
+
status: 'success',
|
|
36
|
+
message: successMessage,
|
|
37
|
+
data: value,
|
|
38
|
+
}))
|
|
34
39
|
.catch((err) => this.catch(err, ctx));
|
|
35
40
|
}
|
|
36
41
|
/**
|
|
@@ -72,7 +77,7 @@ class TakeNTradeRpc {
|
|
|
72
77
|
cause: result.error.errors,
|
|
73
78
|
});
|
|
74
79
|
}
|
|
75
|
-
return result;
|
|
80
|
+
return result.data;
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
exports.TakeNTradeRpc = TakeNTradeRpc;
|
|
@@ -81,10 +86,15 @@ class TakeNTradeRpcV2 {
|
|
|
81
86
|
* Wraps a promise returned by an RPC request handler.
|
|
82
87
|
* @param promise - A Promise resolving to the response value.
|
|
83
88
|
* @param ctx - Optional NatsContext object.
|
|
89
|
+
* @param successMessage - Custom success message for the response.
|
|
84
90
|
*/
|
|
85
|
-
static async handleRequest(promise, ctx) {
|
|
91
|
+
static async handleRequest(promise, ctx, successMessage = 'Operation successful') {
|
|
86
92
|
return promise
|
|
87
|
-
.then((value) =>
|
|
93
|
+
.then((value) => ({
|
|
94
|
+
status: 'success',
|
|
95
|
+
message: successMessage,
|
|
96
|
+
data: value,
|
|
97
|
+
}))
|
|
88
98
|
.catch((err) => this.catch(err, ctx));
|
|
89
99
|
}
|
|
90
100
|
/**
|
|
@@ -125,7 +135,7 @@ class TakeNTradeRpcV2 {
|
|
|
125
135
|
cause: result.error.errors,
|
|
126
136
|
});
|
|
127
137
|
}
|
|
128
|
-
return result;
|
|
138
|
+
return result.data;
|
|
129
139
|
}
|
|
130
140
|
}
|
|
131
141
|
exports.TakeNTradeRpcV2 = TakeNTradeRpcV2;
|