@xdcobra/react-native-grpc 1.1.0 → 2.0.0

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.
Files changed (114) hide show
  1. package/LICENSE.md +22 -22
  2. package/README.md +302 -284
  3. package/android/build.gradle +31 -127
  4. package/android/src/main/AndroidManifest.xml +3 -3
  5. package/android/src/main/java/com/reactnativegrpc/GrpcMarshaller.java +27 -27
  6. package/android/src/main/java/com/reactnativegrpc/GrpcModule.java +730 -730
  7. package/android/src/main/java/com/reactnativegrpc/GrpcPackage.java +27 -27
  8. package/android/src/main/java/com/reactnativegrpc/SpkiPinTrustManager.java +101 -101
  9. package/android/src/main/java/com/reactnativegrpc/TrustManagers.java +51 -51
  10. package/ios/Grpc.h +22 -22
  11. package/ios/Grpc.m +627 -625
  12. package/ios/SpkiPinning.h +22 -22
  13. package/ios/SpkiPinning.m +162 -114
  14. package/lib/commonjs/bidi-streaming.js.map +1 -1
  15. package/lib/commonjs/channel.js +9 -9
  16. package/lib/commonjs/channel.js.map +1 -1
  17. package/lib/commonjs/client-streaming.js +3 -3
  18. package/lib/commonjs/client-streaming.js.map +1 -1
  19. package/lib/commonjs/client.js +24 -24
  20. package/lib/commonjs/client.js.map +1 -1
  21. package/lib/commonjs/create-client.js +5 -5
  22. package/lib/commonjs/create-client.js.map +1 -1
  23. package/lib/commonjs/errors.js.map +1 -1
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/interceptors.js +3 -3
  26. package/lib/commonjs/interceptors.js.map +1 -1
  27. package/lib/commonjs/native.js.map +1 -1
  28. package/lib/commonjs/retry.js.map +1 -1
  29. package/lib/commonjs/server-streaming.js.map +1 -1
  30. package/lib/commonjs/status.js.map +1 -1
  31. package/lib/commonjs/types.js +5 -5
  32. package/lib/commonjs/types.js.map +1 -1
  33. package/lib/commonjs/unary.js.map +1 -1
  34. package/lib/module/bidi-streaming.js.map +1 -1
  35. package/lib/module/channel.js +9 -9
  36. package/lib/module/channel.js.map +1 -1
  37. package/lib/module/client-streaming.js +3 -3
  38. package/lib/module/client-streaming.js.map +1 -1
  39. package/lib/module/client.js +24 -24
  40. package/lib/module/client.js.map +1 -1
  41. package/lib/module/create-client.js +5 -5
  42. package/lib/module/create-client.js.map +1 -1
  43. package/lib/module/errors.js.map +1 -1
  44. package/lib/module/index.js.map +1 -1
  45. package/lib/module/interceptors.js +3 -3
  46. package/lib/module/interceptors.js.map +1 -1
  47. package/lib/module/native.js.map +1 -1
  48. package/lib/module/retry.js.map +1 -1
  49. package/lib/module/server-streaming.js.map +1 -1
  50. package/lib/module/status.js.map +1 -1
  51. package/lib/module/types.js +5 -5
  52. package/lib/module/types.js.map +1 -1
  53. package/lib/module/unary.js.map +1 -1
  54. package/lib/typescript/src/bidi-streaming.d.ts.map +1 -0
  55. package/lib/typescript/src/channel.d.ts.map +1 -0
  56. package/lib/typescript/src/client-streaming.d.ts.map +1 -0
  57. package/lib/typescript/src/client.d.ts.map +1 -0
  58. package/lib/typescript/src/create-client.d.ts.map +1 -0
  59. package/lib/typescript/src/errors.d.ts.map +1 -0
  60. package/lib/typescript/src/index.d.ts.map +1 -0
  61. package/lib/typescript/src/interceptors.d.ts.map +1 -0
  62. package/lib/typescript/src/native.d.ts.map +1 -0
  63. package/lib/typescript/src/retry.d.ts.map +1 -0
  64. package/lib/typescript/src/server-streaming.d.ts.map +1 -0
  65. package/lib/typescript/src/status.d.ts.map +1 -0
  66. package/lib/typescript/src/types.d.ts.map +1 -0
  67. package/lib/typescript/src/unary.d.ts.map +1 -0
  68. package/lib/typescript/test/app/App.d.ts +3 -0
  69. package/lib/typescript/test/app/App.d.ts.map +1 -0
  70. package/package.json +209 -210
  71. package/react-native-grpc.podspec +33 -29
  72. package/src/bidi-streaming.ts +78 -78
  73. package/src/channel.ts +110 -110
  74. package/src/client-streaming.ts +106 -106
  75. package/src/client.ts +1046 -1046
  76. package/src/create-client.ts +391 -391
  77. package/src/errors.ts +11 -11
  78. package/src/index.ts +28 -28
  79. package/src/interceptors.ts +167 -167
  80. package/src/native.ts +99 -99
  81. package/src/retry.ts +208 -208
  82. package/src/server-streaming.ts +105 -105
  83. package/src/status.ts +50 -50
  84. package/src/types.ts +171 -171
  85. package/src/unary.ts +71 -71
  86. package/android/gradle.properties +0 -4
  87. package/lib/typescript/bidi-streaming.d.ts.map +0 -1
  88. package/lib/typescript/channel.d.ts.map +0 -1
  89. package/lib/typescript/client-streaming.d.ts.map +0 -1
  90. package/lib/typescript/client.d.ts.map +0 -1
  91. package/lib/typescript/create-client.d.ts.map +0 -1
  92. package/lib/typescript/errors.d.ts.map +0 -1
  93. package/lib/typescript/index.d.ts.map +0 -1
  94. package/lib/typescript/interceptors.d.ts.map +0 -1
  95. package/lib/typescript/native.d.ts.map +0 -1
  96. package/lib/typescript/retry.d.ts.map +0 -1
  97. package/lib/typescript/server-streaming.d.ts.map +0 -1
  98. package/lib/typescript/status.d.ts.map +0 -1
  99. package/lib/typescript/types.d.ts.map +0 -1
  100. package/lib/typescript/unary.d.ts.map +0 -1
  101. /package/lib/typescript/{bidi-streaming.d.ts → src/bidi-streaming.d.ts} +0 -0
  102. /package/lib/typescript/{channel.d.ts → src/channel.d.ts} +0 -0
  103. /package/lib/typescript/{client-streaming.d.ts → src/client-streaming.d.ts} +0 -0
  104. /package/lib/typescript/{client.d.ts → src/client.d.ts} +0 -0
  105. /package/lib/typescript/{create-client.d.ts → src/create-client.d.ts} +0 -0
  106. /package/lib/typescript/{errors.d.ts → src/errors.d.ts} +0 -0
  107. /package/lib/typescript/{index.d.ts → src/index.d.ts} +0 -0
  108. /package/lib/typescript/{interceptors.d.ts → src/interceptors.d.ts} +0 -0
  109. /package/lib/typescript/{native.d.ts → src/native.d.ts} +0 -0
  110. /package/lib/typescript/{retry.d.ts → src/retry.d.ts} +0 -0
  111. /package/lib/typescript/{server-streaming.d.ts → src/server-streaming.d.ts} +0 -0
  112. /package/lib/typescript/{status.d.ts → src/status.d.ts} +0 -0
  113. /package/lib/typescript/{types.d.ts → src/types.d.ts} +0 -0
  114. /package/lib/typescript/{unary.d.ts → src/unary.d.ts} +0 -0
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 };
@@ -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
+ });