@xdcobra/react-native-grpc 1.1.0 → 1.1.8
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/LICENSE.md +22 -22
- package/README.md +284 -284
- package/android/build.gradle +127 -127
- package/android/gradle.properties +4 -4
- package/android/src/main/AndroidManifest.xml +3 -3
- package/android/src/main/java/com/reactnativegrpc/GrpcMarshaller.java +27 -27
- package/android/src/main/java/com/reactnativegrpc/GrpcModule.java +730 -730
- package/android/src/main/java/com/reactnativegrpc/GrpcPackage.java +27 -27
- package/android/src/main/java/com/reactnativegrpc/SpkiPinTrustManager.java +101 -101
- package/android/src/main/java/com/reactnativegrpc/TrustManagers.java +51 -51
- package/ios/Grpc.h +22 -22
- package/ios/Grpc.m +625 -625
- package/ios/SpkiPinning.h +22 -22
- package/ios/SpkiPinning.m +114 -114
- package/lib/commonjs/bidi-streaming.js.map +1 -1
- package/lib/commonjs/channel.js +9 -9
- package/lib/commonjs/channel.js.map +1 -1
- package/lib/commonjs/client-streaming.js +3 -3
- package/lib/commonjs/client-streaming.js.map +1 -1
- package/lib/commonjs/client.js +24 -24
- package/lib/commonjs/client.js.map +1 -1
- package/lib/commonjs/create-client.js +5 -5
- package/lib/commonjs/create-client.js.map +1 -1
- package/lib/commonjs/errors.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/interceptors.js +3 -3
- package/lib/commonjs/interceptors.js.map +1 -1
- package/lib/commonjs/native.js.map +1 -1
- package/lib/commonjs/retry.js.map +1 -1
- package/lib/commonjs/server-streaming.js.map +1 -1
- package/lib/commonjs/status.js.map +1 -1
- package/lib/commonjs/types.js +5 -5
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/unary.js.map +1 -1
- package/lib/module/bidi-streaming.js.map +1 -1
- package/lib/module/channel.js +9 -9
- package/lib/module/channel.js.map +1 -1
- package/lib/module/client-streaming.js +3 -3
- package/lib/module/client-streaming.js.map +1 -1
- package/lib/module/client.js +24 -24
- package/lib/module/client.js.map +1 -1
- package/lib/module/create-client.js +5 -5
- package/lib/module/create-client.js.map +1 -1
- package/lib/module/errors.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/interceptors.js +3 -3
- package/lib/module/interceptors.js.map +1 -1
- package/lib/module/native.js.map +1 -1
- package/lib/module/retry.js.map +1 -1
- package/lib/module/server-streaming.js.map +1 -1
- package/lib/module/status.js.map +1 -1
- package/lib/module/types.js +5 -5
- package/lib/module/types.js.map +1 -1
- package/lib/module/unary.js.map +1 -1
- package/package.json +209 -210
- package/react-native-grpc.podspec +29 -29
- package/src/bidi-streaming.ts +78 -78
- package/src/channel.ts +110 -110
- package/src/client-streaming.ts +106 -106
- package/src/client.ts +1046 -1046
- package/src/create-client.ts +391 -391
- package/src/errors.ts +11 -11
- package/src/index.ts +28 -28
- package/src/interceptors.ts +167 -167
- package/src/native.ts +99 -99
- package/src/retry.ts +208 -208
- package/src/server-streaming.ts +105 -105
- package/src/status.ts +50 -50
- package/src/types.ts +171 -171
- package/src/unary.ts +71 -71
package/src/errors.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { GrpcMetadata } from './types';
|
|
2
|
-
|
|
3
|
-
export class GrpcError extends Error {
|
|
4
|
-
constructor(
|
|
5
|
-
public error: string,
|
|
6
|
-
public code?: number,
|
|
7
|
-
public trailers?: GrpcMetadata
|
|
8
|
-
) {
|
|
9
|
-
super(error);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
import { GrpcMetadata } from './types';
|
|
2
|
+
|
|
3
|
+
export class GrpcError extends Error {
|
|
4
|
+
constructor(
|
|
5
|
+
public error: string,
|
|
6
|
+
public code?: number,
|
|
7
|
+
public trailers?: GrpcMetadata
|
|
8
|
+
) {
|
|
9
|
+
super(error);
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { GrpcClient as GrpcClientImpl } from './client';
|
|
2
|
-
|
|
3
|
-
const GrpcClient = new GrpcClientImpl();
|
|
4
|
-
|
|
5
|
-
export * from './types';
|
|
6
|
-
export * from './unary';
|
|
7
|
-
export * from './server-streaming';
|
|
8
|
-
export * from './client-streaming';
|
|
9
|
-
export * from './bidi-streaming';
|
|
10
|
-
export * from './errors';
|
|
11
|
-
export { createChannel, GrpcChannel } from './channel';
|
|
12
|
-
export type { GrpcInterceptStart, GrpcInterceptor } from './interceptors';
|
|
13
|
-
export type { GrpcHedgingPolicy, GrpcRetryPolicy } from './retry';
|
|
14
|
-
export { GrpcStatusCode } from './status';
|
|
15
|
-
export {
|
|
16
|
-
createClient,
|
|
17
|
-
type BidiStreamingCall,
|
|
18
|
-
type BidiStreamingMethod,
|
|
19
|
-
type Client,
|
|
20
|
-
type ClientStreamingCall,
|
|
21
|
-
type ClientStreamingMethod,
|
|
22
|
-
type GrpcTransport,
|
|
23
|
-
type ServerStreamingCall,
|
|
24
|
-
type ServerStreamingMethod,
|
|
25
|
-
type TypedServerOutputStream,
|
|
26
|
-
type UnaryMethod,
|
|
27
|
-
} from './create-client';
|
|
28
|
-
export { GrpcClient };
|
|
1
|
+
import { GrpcClient as GrpcClientImpl } from './client';
|
|
2
|
+
|
|
3
|
+
const GrpcClient = new GrpcClientImpl();
|
|
4
|
+
|
|
5
|
+
export * from './types';
|
|
6
|
+
export * from './unary';
|
|
7
|
+
export * from './server-streaming';
|
|
8
|
+
export * from './client-streaming';
|
|
9
|
+
export * from './bidi-streaming';
|
|
10
|
+
export * from './errors';
|
|
11
|
+
export { createChannel, GrpcChannel } from './channel';
|
|
12
|
+
export type { GrpcInterceptStart, GrpcInterceptor } from './interceptors';
|
|
13
|
+
export type { GrpcHedgingPolicy, GrpcRetryPolicy } from './retry';
|
|
14
|
+
export { GrpcStatusCode } from './status';
|
|
15
|
+
export {
|
|
16
|
+
createClient,
|
|
17
|
+
type BidiStreamingCall,
|
|
18
|
+
type BidiStreamingMethod,
|
|
19
|
+
type Client,
|
|
20
|
+
type ClientStreamingCall,
|
|
21
|
+
type ClientStreamingMethod,
|
|
22
|
+
type GrpcTransport,
|
|
23
|
+
type ServerStreamingCall,
|
|
24
|
+
type ServerStreamingMethod,
|
|
25
|
+
type TypedServerOutputStream,
|
|
26
|
+
type UnaryMethod,
|
|
27
|
+
} from './create-client';
|
|
28
|
+
export { GrpcClient };
|
package/src/interceptors.ts
CHANGED
|
@@ -1,167 +1,167 @@
|
|
|
1
|
-
import { GrpcError } from './errors';
|
|
2
|
-
import { GrpcCallOptions, GrpcMetadata } from './types';
|
|
3
|
-
|
|
4
|
-
/** Mutable start payload; interceptors may replace fields before the native call. */
|
|
5
|
-
export type GrpcInterceptStart = {
|
|
6
|
-
method: string;
|
|
7
|
-
headers: GrpcMetadata;
|
|
8
|
-
options: GrpcCallOptions;
|
|
9
|
-
/** Present for unary / server-streaming; optional for client/bidi until first send. */
|
|
10
|
-
request?: Uint8Array;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Request/response middleware hooks.
|
|
15
|
-
* Outbound hooks run index 0→n; inbound hooks run n→0 (onion).
|
|
16
|
-
*/
|
|
17
|
-
export type GrpcInterceptor = {
|
|
18
|
-
/**
|
|
19
|
-
* Outbound: before native start. Throw to abort (rejected call).
|
|
20
|
-
* Return a value to replace the start payload; `void` keeps the previous value.
|
|
21
|
-
*/
|
|
22
|
-
onStart?(
|
|
23
|
-
start: GrpcInterceptStart
|
|
24
|
-
): void | GrpcInterceptStart | Promise<void | GrpcInterceptStart>;
|
|
25
|
-
/**
|
|
26
|
-
* Each outbound message (unary/server request, every client/bidi send).
|
|
27
|
-
*/
|
|
28
|
-
onSendMessage?(
|
|
29
|
-
message: Uint8Array,
|
|
30
|
-
method: string
|
|
31
|
-
): void | Uint8Array | Promise<void | Uint8Array>;
|
|
32
|
-
/** Inbound response headers. */
|
|
33
|
-
onHeaders?(headers: GrpcMetadata, method: string): void | GrpcMetadata;
|
|
34
|
-
/** Each inbound message. */
|
|
35
|
-
onMessage?(message: Uint8Array, method: string): void | Uint8Array;
|
|
36
|
-
/** Successful close trailers. */
|
|
37
|
-
onTrailers?(trailers: GrpcMetadata, method: string): void | GrpcMetadata;
|
|
38
|
-
/** Error path. May remap to another Error / GrpcError. */
|
|
39
|
-
onError?(error: GrpcError, method: string): void | GrpcError | Error;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/** Channel interceptors first, then per-call interceptors. */
|
|
43
|
-
export function combineInterceptors(
|
|
44
|
-
channel: readonly GrpcInterceptor[] | undefined,
|
|
45
|
-
perCall: readonly GrpcInterceptor[] | undefined
|
|
46
|
-
): GrpcInterceptor[] {
|
|
47
|
-
const out: GrpcInterceptor[] = [];
|
|
48
|
-
if (channel && channel.length > 0) {
|
|
49
|
-
out.push(...channel);
|
|
50
|
-
}
|
|
51
|
-
if (perCall && perCall.length > 0) {
|
|
52
|
-
out.push(...perCall);
|
|
53
|
-
}
|
|
54
|
-
return out;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export async function runOnStart(
|
|
58
|
-
interceptors: readonly GrpcInterceptor[],
|
|
59
|
-
start: GrpcInterceptStart
|
|
60
|
-
): Promise<GrpcInterceptStart> {
|
|
61
|
-
let current = start;
|
|
62
|
-
for (const interceptor of interceptors) {
|
|
63
|
-
if (!interceptor.onStart) {
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
const result = await interceptor.onStart(current);
|
|
67
|
-
if (result !== undefined) {
|
|
68
|
-
current = result;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return current;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export async function runOnSendMessage(
|
|
75
|
-
interceptors: readonly GrpcInterceptor[],
|
|
76
|
-
message: Uint8Array,
|
|
77
|
-
method: string
|
|
78
|
-
): Promise<Uint8Array> {
|
|
79
|
-
let current = message;
|
|
80
|
-
for (const interceptor of interceptors) {
|
|
81
|
-
if (!interceptor.onSendMessage) {
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
const result = await interceptor.onSendMessage(current, method);
|
|
85
|
-
if (result !== undefined) {
|
|
86
|
-
current = result;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return current;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function runOnHeaders(
|
|
93
|
-
interceptors: readonly GrpcInterceptor[],
|
|
94
|
-
headers: GrpcMetadata,
|
|
95
|
-
method: string
|
|
96
|
-
): GrpcMetadata {
|
|
97
|
-
let current = headers;
|
|
98
|
-
for (let i = interceptors.length - 1; i >= 0; i--) {
|
|
99
|
-
const result = interceptors[i].onHeaders?.(current, method);
|
|
100
|
-
if (result !== undefined) {
|
|
101
|
-
current = result;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return current;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function runOnMessage(
|
|
108
|
-
interceptors: readonly GrpcInterceptor[],
|
|
109
|
-
message: Uint8Array,
|
|
110
|
-
method: string
|
|
111
|
-
): Uint8Array {
|
|
112
|
-
let current = message;
|
|
113
|
-
for (let i = interceptors.length - 1; i >= 0; i--) {
|
|
114
|
-
const result = interceptors[i].onMessage?.(current, method);
|
|
115
|
-
if (result !== undefined) {
|
|
116
|
-
current = result;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return current;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function runOnTrailers(
|
|
123
|
-
interceptors: readonly GrpcInterceptor[],
|
|
124
|
-
trailers: GrpcMetadata,
|
|
125
|
-
method: string
|
|
126
|
-
): GrpcMetadata {
|
|
127
|
-
let current = trailers;
|
|
128
|
-
for (let i = interceptors.length - 1; i >= 0; i--) {
|
|
129
|
-
const result = interceptors[i].onTrailers?.(current, method);
|
|
130
|
-
if (result !== undefined) {
|
|
131
|
-
current = result;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return current;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export function runOnError(
|
|
138
|
-
interceptors: readonly GrpcInterceptor[],
|
|
139
|
-
error: GrpcError,
|
|
140
|
-
method: string
|
|
141
|
-
): GrpcError {
|
|
142
|
-
let current: GrpcError | Error = error;
|
|
143
|
-
for (let i = interceptors.length - 1; i >= 0; i--) {
|
|
144
|
-
const asGrpc =
|
|
145
|
-
current instanceof GrpcError
|
|
146
|
-
? current
|
|
147
|
-
: new GrpcError(current.message || String(current));
|
|
148
|
-
const result = interceptors[i].onError?.(asGrpc, method);
|
|
149
|
-
if (result !== undefined) {
|
|
150
|
-
current = result;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (current instanceof GrpcError) {
|
|
154
|
-
return current;
|
|
155
|
-
}
|
|
156
|
-
return new GrpcError(current.message || String(current));
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export function toGrpcError(reason: unknown): GrpcError {
|
|
160
|
-
if (reason instanceof GrpcError) {
|
|
161
|
-
return reason;
|
|
162
|
-
}
|
|
163
|
-
if (reason instanceof Error) {
|
|
164
|
-
return new GrpcError(reason.message);
|
|
165
|
-
}
|
|
166
|
-
return new GrpcError(String(reason));
|
|
167
|
-
}
|
|
1
|
+
import { GrpcError } from './errors';
|
|
2
|
+
import { GrpcCallOptions, GrpcMetadata } from './types';
|
|
3
|
+
|
|
4
|
+
/** Mutable start payload; interceptors may replace fields before the native call. */
|
|
5
|
+
export type GrpcInterceptStart = {
|
|
6
|
+
method: string;
|
|
7
|
+
headers: GrpcMetadata;
|
|
8
|
+
options: GrpcCallOptions;
|
|
9
|
+
/** Present for unary / server-streaming; optional for client/bidi until first send. */
|
|
10
|
+
request?: Uint8Array;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Request/response middleware hooks.
|
|
15
|
+
* Outbound hooks run index 0→n; inbound hooks run n→0 (onion).
|
|
16
|
+
*/
|
|
17
|
+
export type GrpcInterceptor = {
|
|
18
|
+
/**
|
|
19
|
+
* Outbound: before native start. Throw to abort (rejected call).
|
|
20
|
+
* Return a value to replace the start payload; `void` keeps the previous value.
|
|
21
|
+
*/
|
|
22
|
+
onStart?(
|
|
23
|
+
start: GrpcInterceptStart
|
|
24
|
+
): void | GrpcInterceptStart | Promise<void | GrpcInterceptStart>;
|
|
25
|
+
/**
|
|
26
|
+
* Each outbound message (unary/server request, every client/bidi send).
|
|
27
|
+
*/
|
|
28
|
+
onSendMessage?(
|
|
29
|
+
message: Uint8Array,
|
|
30
|
+
method: string
|
|
31
|
+
): void | Uint8Array | Promise<void | Uint8Array>;
|
|
32
|
+
/** Inbound response headers. */
|
|
33
|
+
onHeaders?(headers: GrpcMetadata, method: string): void | GrpcMetadata;
|
|
34
|
+
/** Each inbound message. */
|
|
35
|
+
onMessage?(message: Uint8Array, method: string): void | Uint8Array;
|
|
36
|
+
/** Successful close trailers. */
|
|
37
|
+
onTrailers?(trailers: GrpcMetadata, method: string): void | GrpcMetadata;
|
|
38
|
+
/** Error path. May remap to another Error / GrpcError. */
|
|
39
|
+
onError?(error: GrpcError, method: string): void | GrpcError | Error;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Channel interceptors first, then per-call interceptors. */
|
|
43
|
+
export function combineInterceptors(
|
|
44
|
+
channel: readonly GrpcInterceptor[] | undefined,
|
|
45
|
+
perCall: readonly GrpcInterceptor[] | undefined
|
|
46
|
+
): GrpcInterceptor[] {
|
|
47
|
+
const out: GrpcInterceptor[] = [];
|
|
48
|
+
if (channel && channel.length > 0) {
|
|
49
|
+
out.push(...channel);
|
|
50
|
+
}
|
|
51
|
+
if (perCall && perCall.length > 0) {
|
|
52
|
+
out.push(...perCall);
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function runOnStart(
|
|
58
|
+
interceptors: readonly GrpcInterceptor[],
|
|
59
|
+
start: GrpcInterceptStart
|
|
60
|
+
): Promise<GrpcInterceptStart> {
|
|
61
|
+
let current = start;
|
|
62
|
+
for (const interceptor of interceptors) {
|
|
63
|
+
if (!interceptor.onStart) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const result = await interceptor.onStart(current);
|
|
67
|
+
if (result !== undefined) {
|
|
68
|
+
current = result;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return current;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function runOnSendMessage(
|
|
75
|
+
interceptors: readonly GrpcInterceptor[],
|
|
76
|
+
message: Uint8Array,
|
|
77
|
+
method: string
|
|
78
|
+
): Promise<Uint8Array> {
|
|
79
|
+
let current = message;
|
|
80
|
+
for (const interceptor of interceptors) {
|
|
81
|
+
if (!interceptor.onSendMessage) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const result = await interceptor.onSendMessage(current, method);
|
|
85
|
+
if (result !== undefined) {
|
|
86
|
+
current = result;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return current;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function runOnHeaders(
|
|
93
|
+
interceptors: readonly GrpcInterceptor[],
|
|
94
|
+
headers: GrpcMetadata,
|
|
95
|
+
method: string
|
|
96
|
+
): GrpcMetadata {
|
|
97
|
+
let current = headers;
|
|
98
|
+
for (let i = interceptors.length - 1; i >= 0; i--) {
|
|
99
|
+
const result = interceptors[i].onHeaders?.(current, method);
|
|
100
|
+
if (result !== undefined) {
|
|
101
|
+
current = result;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return current;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function runOnMessage(
|
|
108
|
+
interceptors: readonly GrpcInterceptor[],
|
|
109
|
+
message: Uint8Array,
|
|
110
|
+
method: string
|
|
111
|
+
): Uint8Array {
|
|
112
|
+
let current = message;
|
|
113
|
+
for (let i = interceptors.length - 1; i >= 0; i--) {
|
|
114
|
+
const result = interceptors[i].onMessage?.(current, method);
|
|
115
|
+
if (result !== undefined) {
|
|
116
|
+
current = result;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return current;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function runOnTrailers(
|
|
123
|
+
interceptors: readonly GrpcInterceptor[],
|
|
124
|
+
trailers: GrpcMetadata,
|
|
125
|
+
method: string
|
|
126
|
+
): GrpcMetadata {
|
|
127
|
+
let current = trailers;
|
|
128
|
+
for (let i = interceptors.length - 1; i >= 0; i--) {
|
|
129
|
+
const result = interceptors[i].onTrailers?.(current, method);
|
|
130
|
+
if (result !== undefined) {
|
|
131
|
+
current = result;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return current;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function runOnError(
|
|
138
|
+
interceptors: readonly GrpcInterceptor[],
|
|
139
|
+
error: GrpcError,
|
|
140
|
+
method: string
|
|
141
|
+
): GrpcError {
|
|
142
|
+
let current: GrpcError | Error = error;
|
|
143
|
+
for (let i = interceptors.length - 1; i >= 0; i--) {
|
|
144
|
+
const asGrpc =
|
|
145
|
+
current instanceof GrpcError
|
|
146
|
+
? current
|
|
147
|
+
: new GrpcError(current.message || String(current));
|
|
148
|
+
const result = interceptors[i].onError?.(asGrpc, method);
|
|
149
|
+
if (result !== undefined) {
|
|
150
|
+
current = result;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (current instanceof GrpcError) {
|
|
154
|
+
return current;
|
|
155
|
+
}
|
|
156
|
+
return new GrpcError(current.message || String(current));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function toGrpcError(reason: unknown): GrpcError {
|
|
160
|
+
if (reason instanceof GrpcError) {
|
|
161
|
+
return reason;
|
|
162
|
+
}
|
|
163
|
+
if (reason instanceof Error) {
|
|
164
|
+
return new GrpcError(reason.message);
|
|
165
|
+
}
|
|
166
|
+
return new GrpcError(String(reason));
|
|
167
|
+
}
|
package/src/native.ts
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
import { NativeModules } from 'react-native';
|
|
2
|
-
import { GrpcMetadata } from './types';
|
|
3
|
-
|
|
4
|
-
export type GrpcRequestObject = {
|
|
5
|
-
data: string;
|
|
6
|
-
/** Optional per-call override; native falls back to channel default when omitted. */
|
|
7
|
-
deadlineSeconds?: number;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type NativeTlsOptions = {
|
|
11
|
-
rootCertsPem: string | null;
|
|
12
|
-
certificateChainPem: string | null;
|
|
13
|
-
privateKeyPem: string | null;
|
|
14
|
-
hostNameOverride: string | null;
|
|
15
|
-
spkiSha256Pins: string[] | null;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type NativeChannelConfig = {
|
|
19
|
-
host: string;
|
|
20
|
-
insecure: boolean;
|
|
21
|
-
tls: NativeTlsOptions | null;
|
|
22
|
-
callDeadlineSeconds: number;
|
|
23
|
-
responseSizeLimit: number | null;
|
|
24
|
-
compressionEnable: boolean;
|
|
25
|
-
compressorName: string;
|
|
26
|
-
keepAliveEnable: boolean;
|
|
27
|
-
keepAliveTime: number;
|
|
28
|
-
keepAliveTimeOut: number;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type GrpcNativeModule = {
|
|
32
|
-
getHost: () => Promise<string>;
|
|
33
|
-
getIsInsecure: () => Promise<boolean>;
|
|
34
|
-
setHost(host: string): void;
|
|
35
|
-
setInsecure(insecure: boolean): void;
|
|
36
|
-
setTlsOptions(options: NativeTlsOptions): void;
|
|
37
|
-
setCompression(enable: boolean, compressorName: string): void;
|
|
38
|
-
setResponseSizeLimit(limitInBytes: number): void;
|
|
39
|
-
setCallDeadlineSeconds(seconds: number): void;
|
|
40
|
-
initGrpcChannel(): void;
|
|
41
|
-
createChannel(channelId: string, config: NativeChannelConfig): void;
|
|
42
|
-
closeChannel(channelId: string): void;
|
|
43
|
-
unaryCall(
|
|
44
|
-
id: number,
|
|
45
|
-
path: string,
|
|
46
|
-
obj: GrpcRequestObject,
|
|
47
|
-
requestHeaders: GrpcMetadata,
|
|
48
|
-
channelId: string
|
|
49
|
-
): Promise<void>;
|
|
50
|
-
serverStreamingCall(
|
|
51
|
-
id: number,
|
|
52
|
-
path: string,
|
|
53
|
-
obj: GrpcRequestObject,
|
|
54
|
-
requestHeaders: GrpcMetadata,
|
|
55
|
-
channelId: string
|
|
56
|
-
): Promise<void>;
|
|
57
|
-
cancelGrpcCall: (id: number) => Promise<boolean>;
|
|
58
|
-
clientStreamingCall(
|
|
59
|
-
id: number,
|
|
60
|
-
path: string,
|
|
61
|
-
obj: GrpcRequestObject,
|
|
62
|
-
requestHeaders: GrpcMetadata,
|
|
63
|
-
channelId: string
|
|
64
|
-
): Promise<void>;
|
|
65
|
-
bidiStreamingCall(
|
|
66
|
-
id: number,
|
|
67
|
-
path: string,
|
|
68
|
-
obj: GrpcRequestObject,
|
|
69
|
-
requestHeaders: GrpcMetadata,
|
|
70
|
-
channelId: string
|
|
71
|
-
): Promise<void>;
|
|
72
|
-
finishClientStreaming(id: number): Promise<void>;
|
|
73
|
-
resetConnection(message: string): void;
|
|
74
|
-
setKeepAlive(
|
|
75
|
-
enable: boolean,
|
|
76
|
-
keepAliveTime: number,
|
|
77
|
-
keepAliveTimeOut: number
|
|
78
|
-
): void;
|
|
79
|
-
onConnectionStateChange(): void;
|
|
80
|
-
setUiLogEnabled(enable: boolean): void;
|
|
81
|
-
enterIdle(): void;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/** Lazy binding to NativeModules.Grpc (works with Jest mocks / late link). */
|
|
85
|
-
export function nativeGrpc(): GrpcNativeModule {
|
|
86
|
-
const grpc = (NativeModules as { Grpc: GrpcNativeModule }).Grpc;
|
|
87
|
-
if (!grpc) {
|
|
88
|
-
throw new Error('NativeModules.Grpc is not linked');
|
|
89
|
-
}
|
|
90
|
-
return grpc;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export const Grpc: GrpcNativeModule = new Proxy({} as GrpcNativeModule, {
|
|
94
|
-
get(_target, prop) {
|
|
95
|
-
const native = nativeGrpc();
|
|
96
|
-
const value = (native as any)[prop as string];
|
|
97
|
-
return typeof value === 'function' ? value.bind(native) : value;
|
|
98
|
-
},
|
|
99
|
-
});
|
|
1
|
+
import { NativeModules } from 'react-native';
|
|
2
|
+
import { GrpcMetadata } from './types';
|
|
3
|
+
|
|
4
|
+
export type GrpcRequestObject = {
|
|
5
|
+
data: string;
|
|
6
|
+
/** Optional per-call override; native falls back to channel default when omitted. */
|
|
7
|
+
deadlineSeconds?: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type NativeTlsOptions = {
|
|
11
|
+
rootCertsPem: string | null;
|
|
12
|
+
certificateChainPem: string | null;
|
|
13
|
+
privateKeyPem: string | null;
|
|
14
|
+
hostNameOverride: string | null;
|
|
15
|
+
spkiSha256Pins: string[] | null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type NativeChannelConfig = {
|
|
19
|
+
host: string;
|
|
20
|
+
insecure: boolean;
|
|
21
|
+
tls: NativeTlsOptions | null;
|
|
22
|
+
callDeadlineSeconds: number;
|
|
23
|
+
responseSizeLimit: number | null;
|
|
24
|
+
compressionEnable: boolean;
|
|
25
|
+
compressorName: string;
|
|
26
|
+
keepAliveEnable: boolean;
|
|
27
|
+
keepAliveTime: number;
|
|
28
|
+
keepAliveTimeOut: number;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type GrpcNativeModule = {
|
|
32
|
+
getHost: () => Promise<string>;
|
|
33
|
+
getIsInsecure: () => Promise<boolean>;
|
|
34
|
+
setHost(host: string): void;
|
|
35
|
+
setInsecure(insecure: boolean): void;
|
|
36
|
+
setTlsOptions(options: NativeTlsOptions): void;
|
|
37
|
+
setCompression(enable: boolean, compressorName: string): void;
|
|
38
|
+
setResponseSizeLimit(limitInBytes: number): void;
|
|
39
|
+
setCallDeadlineSeconds(seconds: number): void;
|
|
40
|
+
initGrpcChannel(): void;
|
|
41
|
+
createChannel(channelId: string, config: NativeChannelConfig): void;
|
|
42
|
+
closeChannel(channelId: string): void;
|
|
43
|
+
unaryCall(
|
|
44
|
+
id: number,
|
|
45
|
+
path: string,
|
|
46
|
+
obj: GrpcRequestObject,
|
|
47
|
+
requestHeaders: GrpcMetadata,
|
|
48
|
+
channelId: string
|
|
49
|
+
): Promise<void>;
|
|
50
|
+
serverStreamingCall(
|
|
51
|
+
id: number,
|
|
52
|
+
path: string,
|
|
53
|
+
obj: GrpcRequestObject,
|
|
54
|
+
requestHeaders: GrpcMetadata,
|
|
55
|
+
channelId: string
|
|
56
|
+
): Promise<void>;
|
|
57
|
+
cancelGrpcCall: (id: number) => Promise<boolean>;
|
|
58
|
+
clientStreamingCall(
|
|
59
|
+
id: number,
|
|
60
|
+
path: string,
|
|
61
|
+
obj: GrpcRequestObject,
|
|
62
|
+
requestHeaders: GrpcMetadata,
|
|
63
|
+
channelId: string
|
|
64
|
+
): Promise<void>;
|
|
65
|
+
bidiStreamingCall(
|
|
66
|
+
id: number,
|
|
67
|
+
path: string,
|
|
68
|
+
obj: GrpcRequestObject,
|
|
69
|
+
requestHeaders: GrpcMetadata,
|
|
70
|
+
channelId: string
|
|
71
|
+
): Promise<void>;
|
|
72
|
+
finishClientStreaming(id: number): Promise<void>;
|
|
73
|
+
resetConnection(message: string): void;
|
|
74
|
+
setKeepAlive(
|
|
75
|
+
enable: boolean,
|
|
76
|
+
keepAliveTime: number,
|
|
77
|
+
keepAliveTimeOut: number
|
|
78
|
+
): void;
|
|
79
|
+
onConnectionStateChange(): void;
|
|
80
|
+
setUiLogEnabled(enable: boolean): void;
|
|
81
|
+
enterIdle(): void;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** Lazy binding to NativeModules.Grpc (works with Jest mocks / late link). */
|
|
85
|
+
export function nativeGrpc(): GrpcNativeModule {
|
|
86
|
+
const grpc = (NativeModules as { Grpc: GrpcNativeModule }).Grpc;
|
|
87
|
+
if (!grpc) {
|
|
88
|
+
throw new Error('NativeModules.Grpc is not linked');
|
|
89
|
+
}
|
|
90
|
+
return grpc;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const Grpc: GrpcNativeModule = new Proxy({} as GrpcNativeModule, {
|
|
94
|
+
get(_target, prop) {
|
|
95
|
+
const native = nativeGrpc();
|
|
96
|
+
const value = (native as any)[prop as string];
|
|
97
|
+
return typeof value === 'function' ? value.bind(native) : value;
|
|
98
|
+
},
|
|
99
|
+
});
|