@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/channel.ts CHANGED
@@ -1,110 +1,110 @@
1
- import { GrpcCallApi, normalizeTlsOptions } from './client';
2
- import type { GrpcInterceptor } from './interceptors';
3
- import { nativeGrpc } from './native';
4
- import {
5
- assertExclusivePolicies,
6
- normalizeHedgingPolicy,
7
- normalizeRetryPolicy,
8
- } from './retry';
9
- import { GrpcChannelConfig } from './types';
10
-
11
- let channelCtr = 1;
12
-
13
- /**
14
- * Independent gRPC channel bound to a host (and optional TLS / deadline / keepalive).
15
- * Create via {@link createChannel}; close when finished. Concurrent channels are supported.
16
- */
17
- export class GrpcChannel extends GrpcCallApi {
18
- private closed = false;
19
-
20
- constructor(
21
- channelId: string,
22
- private readonly host: string,
23
- interceptors: readonly GrpcInterceptor[] = [],
24
- channelDeadlineSeconds = 120,
25
- channelRetry: import('./retry').GrpcRetryPolicy | null = null,
26
- channelHedging: import('./retry').GrpcHedgingPolicy | null = null
27
- ) {
28
- super(
29
- channelId,
30
- interceptors,
31
- channelDeadlineSeconds,
32
- channelRetry,
33
- channelHedging
34
- );
35
- }
36
-
37
- /** Host this channel was created with. */
38
- getHost(): Promise<string> {
39
- return Promise.resolve(this.host);
40
- }
41
-
42
- /** Native channel id (for diagnostics). */
43
- getChannelId(): string {
44
- return this.channelId;
45
- }
46
-
47
- /**
48
- * Tear down this channel. Further RPCs will fail.
49
- * Does not affect the singleton `GrpcClient` default channel.
50
- */
51
- close(): void {
52
- if (this.closed) {
53
- return;
54
- }
55
- this.closed = true;
56
- nativeGrpc().closeChannel(this.channelId);
57
- }
58
- }
59
-
60
- /**
61
- * Create a concurrent channel with immutable config.
62
- * Prefer this over mutating `GrpcClient.setHost` when talking to multiple hosts.
63
- */
64
- export function createChannel(config: GrpcChannelConfig): GrpcChannel {
65
- if (!config?.host || typeof config.host !== 'string' || !config.host.trim()) {
66
- throw new Error('createChannel requires a non-empty host');
67
- }
68
-
69
- assertExclusivePolicies(config.retry, config.hedging);
70
- if (config.retry) {
71
- normalizeRetryPolicy(config.retry);
72
- }
73
- if (config.hedging) {
74
- normalizeHedgingPolicy(config.hedging);
75
- }
76
- const retry = config.retry ?? null;
77
- const hedging = config.hedging ?? null;
78
-
79
- const tls = config.tls ? normalizeTlsOptions(config.tls) : null;
80
- const channelId = `ch_${channelCtr++}`;
81
- const compression = config.compression;
82
- const keepAlive = config.keepAlive;
83
- const deadline =
84
- config.callDeadlineSeconds !== undefined
85
- ? Math.max(0, config.callDeadlineSeconds)
86
- : 120;
87
-
88
- nativeGrpc().createChannel(channelId, {
89
- host: config.host.trim(),
90
- insecure: !!config.insecure,
91
- tls,
92
- callDeadlineSeconds: deadline,
93
- responseSizeLimit:
94
- config.responseSizeLimit !== undefined ? config.responseSizeLimit : null,
95
- compressionEnable: !!compression?.enable,
96
- compressorName: compression?.compressorName ?? '',
97
- keepAliveEnable: !!keepAlive?.enable,
98
- keepAliveTime: keepAlive?.keepAliveTime ?? 0,
99
- keepAliveTimeOut: keepAlive?.keepAliveTimeOut ?? 0,
100
- });
101
-
102
- return new GrpcChannel(
103
- channelId,
104
- config.host.trim(),
105
- config.interceptors ?? [],
106
- deadline,
107
- retry,
108
- hedging
109
- );
110
- }
1
+ import { GrpcCallApi, normalizeTlsOptions } from './client';
2
+ import type { GrpcInterceptor } from './interceptors';
3
+ import { nativeGrpc } from './native';
4
+ import {
5
+ assertExclusivePolicies,
6
+ normalizeHedgingPolicy,
7
+ normalizeRetryPolicy,
8
+ } from './retry';
9
+ import { GrpcChannelConfig } from './types';
10
+
11
+ let channelCtr = 1;
12
+
13
+ /**
14
+ * Independent gRPC channel bound to a host (and optional TLS / deadline / keepalive).
15
+ * Create via {@link createChannel}; close when finished. Concurrent channels are supported.
16
+ */
17
+ export class GrpcChannel extends GrpcCallApi {
18
+ private closed = false;
19
+
20
+ constructor(
21
+ channelId: string,
22
+ private readonly host: string,
23
+ interceptors: readonly GrpcInterceptor[] = [],
24
+ channelDeadlineSeconds = 120,
25
+ channelRetry: import('./retry').GrpcRetryPolicy | null = null,
26
+ channelHedging: import('./retry').GrpcHedgingPolicy | null = null
27
+ ) {
28
+ super(
29
+ channelId,
30
+ interceptors,
31
+ channelDeadlineSeconds,
32
+ channelRetry,
33
+ channelHedging
34
+ );
35
+ }
36
+
37
+ /** Host this channel was created with. */
38
+ getHost(): Promise<string> {
39
+ return Promise.resolve(this.host);
40
+ }
41
+
42
+ /** Native channel id (for diagnostics). */
43
+ getChannelId(): string {
44
+ return this.channelId;
45
+ }
46
+
47
+ /**
48
+ * Tear down this channel. Further RPCs will fail.
49
+ * Does not affect the singleton `GrpcClient` default channel.
50
+ */
51
+ close(): void {
52
+ if (this.closed) {
53
+ return;
54
+ }
55
+ this.closed = true;
56
+ nativeGrpc().closeChannel(this.channelId);
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Create a concurrent channel with immutable config.
62
+ * Prefer this over mutating `GrpcClient.setHost` when talking to multiple hosts.
63
+ */
64
+ export function createChannel(config: GrpcChannelConfig): GrpcChannel {
65
+ if (!config?.host || typeof config.host !== 'string' || !config.host.trim()) {
66
+ throw new Error('createChannel requires a non-empty host');
67
+ }
68
+
69
+ assertExclusivePolicies(config.retry, config.hedging);
70
+ if (config.retry) {
71
+ normalizeRetryPolicy(config.retry);
72
+ }
73
+ if (config.hedging) {
74
+ normalizeHedgingPolicy(config.hedging);
75
+ }
76
+ const retry = config.retry ?? null;
77
+ const hedging = config.hedging ?? null;
78
+
79
+ const tls = config.tls ? normalizeTlsOptions(config.tls) : null;
80
+ const channelId = `ch_${channelCtr++}`;
81
+ const compression = config.compression;
82
+ const keepAlive = config.keepAlive;
83
+ const deadline =
84
+ config.callDeadlineSeconds !== undefined
85
+ ? Math.max(0, config.callDeadlineSeconds)
86
+ : 120;
87
+
88
+ nativeGrpc().createChannel(channelId, {
89
+ host: config.host.trim(),
90
+ insecure: !!config.insecure,
91
+ tls,
92
+ callDeadlineSeconds: deadline,
93
+ responseSizeLimit:
94
+ config.responseSizeLimit !== undefined ? config.responseSizeLimit : null,
95
+ compressionEnable: !!compression?.enable,
96
+ compressorName: compression?.compressorName ?? '',
97
+ keepAliveEnable: !!keepAlive?.enable,
98
+ keepAliveTime: keepAlive?.keepAliveTime ?? 0,
99
+ keepAliveTimeOut: keepAlive?.keepAliveTimeOut ?? 0,
100
+ });
101
+
102
+ return new GrpcChannel(
103
+ channelId,
104
+ config.host.trim(),
105
+ config.interceptors ?? [],
106
+ deadline,
107
+ retry,
108
+ hedging
109
+ );
110
+ }
@@ -1,106 +1,106 @@
1
- import { AbortController } from 'abort-controller';
2
- import {
3
- CompletedGrpcClientStreamingCall,
4
- GrpcMetadata,
5
- GrpcServerInputStream,
6
- } from './types';
7
-
8
- type SendNative = (data: Uint8Array, isFirst: boolean) => Promise<void>;
9
- type FinishNative = () => Promise<void>;
10
-
11
- /**
12
- * Client → server request stream for client-streaming RPCs.
13
- * Native call is created on the first `send`.
14
- */
15
- export class ServerInputStream implements GrpcServerInputStream {
16
- #started = false;
17
- #sendNative: SendNative;
18
- #finishNative: FinishNative;
19
-
20
- constructor(sendNative: SendNative, finishNative: FinishNative) {
21
- this.#sendNative = sendNative;
22
- this.#finishNative = finishNative;
23
- }
24
-
25
- send(data: Uint8Array): Promise<void> {
26
- const isFirst = !this.#started;
27
- this.#started = true;
28
- return this.#sendNative(data, isFirst);
29
- }
30
-
31
- complete(): Promise<void> {
32
- return this.#finishNative();
33
- }
34
- }
35
-
36
- export class GrpcClientStreamingCall
37
- implements PromiseLike<CompletedGrpcClientStreamingCall>
38
- {
39
- readonly method: string;
40
- readonly requestHeaders: GrpcMetadata;
41
- readonly requests: GrpcServerInputStream;
42
- readonly headers: Promise<GrpcMetadata>;
43
- readonly response: Promise<Uint8Array>;
44
- readonly trailers: Promise<GrpcMetadata>;
45
-
46
- #abort: AbortController;
47
-
48
- constructor(
49
- method: string,
50
- requestHeaders: GrpcMetadata,
51
- requests: GrpcServerInputStream,
52
- headers: Promise<GrpcMetadata>,
53
- response: Promise<Uint8Array>,
54
- trailers: Promise<GrpcMetadata>,
55
- abort: AbortController
56
- ) {
57
- this.method = method;
58
- this.requestHeaders = requestHeaders;
59
- this.requests = requests;
60
- this.headers = headers;
61
- this.response = response;
62
- this.trailers = trailers;
63
- this.#abort = abort;
64
- }
65
-
66
- then<TResult1 = CompletedGrpcClientStreamingCall, TResult2 = unknown>(
67
- onfulfilled?:
68
- | ((
69
- value: CompletedGrpcClientStreamingCall
70
- ) => TResult1 | PromiseLike<TResult1>)
71
- | null,
72
- onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
73
- ): PromiseLike<TResult1 | TResult2> {
74
- return this.completedPromise().then(
75
- (value) =>
76
- onfulfilled
77
- ? Promise.resolve(onfulfilled(value))
78
- : (value as unknown as TResult1),
79
- (reason) =>
80
- onrejected
81
- ? Promise.resolve(onrejected(reason))
82
- : Promise.reject(reason)
83
- );
84
- }
85
-
86
- cancel() {
87
- this.#abort.abort();
88
- }
89
-
90
- private async completedPromise(): Promise<CompletedGrpcClientStreamingCall> {
91
- const [headers, response, trailers] = await Promise.all([
92
- this.headers,
93
- this.response,
94
- this.trailers,
95
- ]);
96
-
97
- return {
98
- method: this.method,
99
- requestHeaders: this.requestHeaders,
100
- headers,
101
- trailers,
102
- response,
103
- status: 0,
104
- };
105
- }
106
- }
1
+ import { AbortController } from 'abort-controller';
2
+ import {
3
+ CompletedGrpcClientStreamingCall,
4
+ GrpcMetadata,
5
+ GrpcServerInputStream,
6
+ } from './types';
7
+
8
+ type SendNative = (data: Uint8Array, isFirst: boolean) => Promise<void>;
9
+ type FinishNative = () => Promise<void>;
10
+
11
+ /**
12
+ * Client → server request stream for client-streaming RPCs.
13
+ * Native call is created on the first `send`.
14
+ */
15
+ export class ServerInputStream implements GrpcServerInputStream {
16
+ #started = false;
17
+ #sendNative: SendNative;
18
+ #finishNative: FinishNative;
19
+
20
+ constructor(sendNative: SendNative, finishNative: FinishNative) {
21
+ this.#sendNative = sendNative;
22
+ this.#finishNative = finishNative;
23
+ }
24
+
25
+ send(data: Uint8Array): Promise<void> {
26
+ const isFirst = !this.#started;
27
+ this.#started = true;
28
+ return this.#sendNative(data, isFirst);
29
+ }
30
+
31
+ complete(): Promise<void> {
32
+ return this.#finishNative();
33
+ }
34
+ }
35
+
36
+ export class GrpcClientStreamingCall
37
+ implements PromiseLike<CompletedGrpcClientStreamingCall>
38
+ {
39
+ readonly method: string;
40
+ readonly requestHeaders: GrpcMetadata;
41
+ readonly requests: GrpcServerInputStream;
42
+ readonly headers: Promise<GrpcMetadata>;
43
+ readonly response: Promise<Uint8Array>;
44
+ readonly trailers: Promise<GrpcMetadata>;
45
+
46
+ #abort: AbortController;
47
+
48
+ constructor(
49
+ method: string,
50
+ requestHeaders: GrpcMetadata,
51
+ requests: GrpcServerInputStream,
52
+ headers: Promise<GrpcMetadata>,
53
+ response: Promise<Uint8Array>,
54
+ trailers: Promise<GrpcMetadata>,
55
+ abort: AbortController
56
+ ) {
57
+ this.method = method;
58
+ this.requestHeaders = requestHeaders;
59
+ this.requests = requests;
60
+ this.headers = headers;
61
+ this.response = response;
62
+ this.trailers = trailers;
63
+ this.#abort = abort;
64
+ }
65
+
66
+ then<TResult1 = CompletedGrpcClientStreamingCall, TResult2 = unknown>(
67
+ onfulfilled?:
68
+ | ((
69
+ value: CompletedGrpcClientStreamingCall
70
+ ) => TResult1 | PromiseLike<TResult1>)
71
+ | null,
72
+ onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
73
+ ): PromiseLike<TResult1 | TResult2> {
74
+ return this.completedPromise().then(
75
+ (value) =>
76
+ onfulfilled
77
+ ? Promise.resolve(onfulfilled(value))
78
+ : (value as unknown as TResult1),
79
+ (reason) =>
80
+ onrejected
81
+ ? Promise.resolve(onrejected(reason))
82
+ : Promise.reject(reason)
83
+ );
84
+ }
85
+
86
+ cancel() {
87
+ this.#abort.abort();
88
+ }
89
+
90
+ private async completedPromise(): Promise<CompletedGrpcClientStreamingCall> {
91
+ const [headers, response, trailers] = await Promise.all([
92
+ this.headers,
93
+ this.response,
94
+ this.trailers,
95
+ ]);
96
+
97
+ return {
98
+ method: this.method,
99
+ requestHeaders: this.requestHeaders,
100
+ headers,
101
+ trailers,
102
+ response,
103
+ status: 0,
104
+ };
105
+ }
106
+ }