@vishalsharma7nov/react-native-proto 0.2.2

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 (190) hide show
  1. package/android/src/main/java/com/vishalsharma7nov/reactnativeproto/ReactNativeProtoNativeGrpcModule.java +142 -0
  2. package/app.plugin.js +63 -0
  3. package/bin/react-native-proto.js +956 -0
  4. package/ios/ReactNativeProtoNativeGrpc.m +129 -0
  5. package/lib/commonjs/auth.js +72 -0
  6. package/lib/commonjs/auth.js.map +1 -0
  7. package/lib/commonjs/client-factory.js +81 -0
  8. package/lib/commonjs/client-factory.js.map +1 -0
  9. package/lib/commonjs/codecs.js +41 -0
  10. package/lib/commonjs/codecs.js.map +1 -0
  11. package/lib/commonjs/connect/envelope.js +100 -0
  12. package/lib/commonjs/connect/envelope.js.map +1 -0
  13. package/lib/commonjs/connect/errors.js +71 -0
  14. package/lib/commonjs/connect/errors.js.map +1 -0
  15. package/lib/commonjs/errors.js +54 -0
  16. package/lib/commonjs/errors.js.map +1 -0
  17. package/lib/commonjs/generated/create-api.js +29 -0
  18. package/lib/commonjs/generated/create-api.js.map +1 -0
  19. package/lib/commonjs/generated/message-types.js +2 -0
  20. package/lib/commonjs/generated/message-types.js.map +1 -0
  21. package/lib/commonjs/generated/messages.js +47 -0
  22. package/lib/commonjs/generated/messages.js.map +1 -0
  23. package/lib/commonjs/generated/messages.pb.js +2787 -0
  24. package/lib/commonjs/generated/messages.pb.js.map +1 -0
  25. package/lib/commonjs/generated/method-map.js +68 -0
  26. package/lib/commonjs/generated/method-map.js.map +1 -0
  27. package/lib/commonjs/index.js +283 -0
  28. package/lib/commonjs/index.js.map +1 -0
  29. package/lib/commonjs/interceptors.js +19 -0
  30. package/lib/commonjs/interceptors.js.map +1 -0
  31. package/lib/commonjs/logging.js +54 -0
  32. package/lib/commonjs/logging.js.map +1 -0
  33. package/lib/commonjs/metro/index.js +35 -0
  34. package/lib/commonjs/metro/index.js.map +1 -0
  35. package/lib/commonjs/metro/transformer.js +33 -0
  36. package/lib/commonjs/metro/transformer.js.map +1 -0
  37. package/lib/commonjs/mock-server/index.js +125 -0
  38. package/lib/commonjs/mock-server/index.js.map +1 -0
  39. package/lib/commonjs/native-grpc/index.js +242 -0
  40. package/lib/commonjs/native-grpc/index.js.map +1 -0
  41. package/lib/commonjs/offline-queue.js +137 -0
  42. package/lib/commonjs/offline-queue.js.map +1 -0
  43. package/lib/commonjs/package.json +1 -0
  44. package/lib/commonjs/path-templates.js +44 -0
  45. package/lib/commonjs/path-templates.js.map +1 -0
  46. package/lib/commonjs/react-query/index.js +30 -0
  47. package/lib/commonjs/react-query/index.js.map +1 -0
  48. package/lib/commonjs/streaming.js +251 -0
  49. package/lib/commonjs/streaming.js.map +1 -0
  50. package/lib/commonjs/transport.js +323 -0
  51. package/lib/commonjs/transport.js.map +1 -0
  52. package/lib/commonjs/types.js +6 -0
  53. package/lib/commonjs/types.js.map +1 -0
  54. package/lib/commonjs/validation/zod.js +48 -0
  55. package/lib/commonjs/validation/zod.js.map +1 -0
  56. package/lib/commonjs/version-check.js +102 -0
  57. package/lib/commonjs/version-check.js.map +1 -0
  58. package/lib/module/auth.js +67 -0
  59. package/lib/module/auth.js.map +1 -0
  60. package/lib/module/client-factory.js +77 -0
  61. package/lib/module/client-factory.js.map +1 -0
  62. package/lib/module/codecs.js +36 -0
  63. package/lib/module/codecs.js.map +1 -0
  64. package/lib/module/connect/envelope.js +93 -0
  65. package/lib/module/connect/envelope.js.map +1 -0
  66. package/lib/module/connect/errors.js +65 -0
  67. package/lib/module/connect/errors.js.map +1 -0
  68. package/lib/module/errors.js +46 -0
  69. package/lib/module/errors.js.map +1 -0
  70. package/lib/module/generated/create-api.js +13 -0
  71. package/lib/module/generated/create-api.js.map +1 -0
  72. package/lib/module/generated/message-types.js +2 -0
  73. package/lib/module/generated/message-types.js.map +1 -0
  74. package/lib/module/generated/messages.js +43 -0
  75. package/lib/module/generated/messages.js.map +1 -0
  76. package/lib/module/generated/messages.pb.js +2787 -0
  77. package/lib/module/generated/messages.pb.js.map +1 -0
  78. package/lib/module/generated/method-map.js +64 -0
  79. package/lib/module/generated/method-map.js.map +1 -0
  80. package/lib/module/index.js +53 -0
  81. package/lib/module/index.js.map +1 -0
  82. package/lib/module/interceptors.js +15 -0
  83. package/lib/module/interceptors.js.map +1 -0
  84. package/lib/module/logging.js +50 -0
  85. package/lib/module/logging.js.map +1 -0
  86. package/lib/module/metro/index.js +25 -0
  87. package/lib/module/metro/index.js.map +1 -0
  88. package/lib/module/metro/transformer.js +29 -0
  89. package/lib/module/metro/transformer.js.map +1 -0
  90. package/lib/module/mock-server/index.js +120 -0
  91. package/lib/module/mock-server/index.js.map +1 -0
  92. package/lib/module/native-grpc/index.js +233 -0
  93. package/lib/module/native-grpc/index.js.map +1 -0
  94. package/lib/module/offline-queue.js +132 -0
  95. package/lib/module/offline-queue.js.map +1 -0
  96. package/lib/module/package.json +1 -0
  97. package/lib/module/path-templates.js +39 -0
  98. package/lib/module/path-templates.js.map +1 -0
  99. package/lib/module/react-query/index.js +25 -0
  100. package/lib/module/react-query/index.js.map +1 -0
  101. package/lib/module/streaming.js +246 -0
  102. package/lib/module/streaming.js.map +1 -0
  103. package/lib/module/transport.js +316 -0
  104. package/lib/module/transport.js.map +1 -0
  105. package/lib/module/types.js +4 -0
  106. package/lib/module/types.js.map +1 -0
  107. package/lib/module/validation/zod.js +43 -0
  108. package/lib/module/validation/zod.js.map +1 -0
  109. package/lib/module/version-check.js +93 -0
  110. package/lib/module/version-check.js.map +1 -0
  111. package/lib/typescript/src/auth.d.ts +26 -0
  112. package/lib/typescript/src/auth.d.ts.map +1 -0
  113. package/lib/typescript/src/client-factory.d.ts +7 -0
  114. package/lib/typescript/src/client-factory.d.ts.map +1 -0
  115. package/lib/typescript/src/codecs.d.ts +5 -0
  116. package/lib/typescript/src/codecs.d.ts.map +1 -0
  117. package/lib/typescript/src/connect/envelope.d.ts +18 -0
  118. package/lib/typescript/src/connect/envelope.d.ts.map +1 -0
  119. package/lib/typescript/src/connect/errors.d.ts +11 -0
  120. package/lib/typescript/src/connect/errors.d.ts.map +1 -0
  121. package/lib/typescript/src/errors.d.ts +21 -0
  122. package/lib/typescript/src/errors.d.ts.map +1 -0
  123. package/lib/typescript/src/generated/create-api.d.ts +34 -0
  124. package/lib/typescript/src/generated/create-api.d.ts.map +1 -0
  125. package/lib/typescript/src/generated/message-types.d.ts +54 -0
  126. package/lib/typescript/src/generated/message-types.d.ts.map +1 -0
  127. package/lib/typescript/src/generated/messages.d.ts +17 -0
  128. package/lib/typescript/src/generated/messages.d.ts.map +1 -0
  129. package/lib/typescript/src/generated/method-map.d.ts +7 -0
  130. package/lib/typescript/src/generated/method-map.d.ts.map +1 -0
  131. package/lib/typescript/src/index.d.ts +53 -0
  132. package/lib/typescript/src/index.d.ts.map +1 -0
  133. package/lib/typescript/src/interceptors.d.ts +17 -0
  134. package/lib/typescript/src/interceptors.d.ts.map +1 -0
  135. package/lib/typescript/src/logging.d.ts +16 -0
  136. package/lib/typescript/src/logging.d.ts.map +1 -0
  137. package/lib/typescript/src/metro/index.d.ts +15 -0
  138. package/lib/typescript/src/metro/index.d.ts.map +1 -0
  139. package/lib/typescript/src/metro/transformer.d.ts +16 -0
  140. package/lib/typescript/src/metro/transformer.d.ts.map +1 -0
  141. package/lib/typescript/src/mock-server/index.d.ts +27 -0
  142. package/lib/typescript/src/mock-server/index.d.ts.map +1 -0
  143. package/lib/typescript/src/native-grpc/index.d.ts +36 -0
  144. package/lib/typescript/src/native-grpc/index.d.ts.map +1 -0
  145. package/lib/typescript/src/offline-queue.d.ts +47 -0
  146. package/lib/typescript/src/offline-queue.d.ts.map +1 -0
  147. package/lib/typescript/src/path-templates.d.ts +17 -0
  148. package/lib/typescript/src/path-templates.d.ts.map +1 -0
  149. package/lib/typescript/src/react-query/index.d.ts +14 -0
  150. package/lib/typescript/src/react-query/index.d.ts.map +1 -0
  151. package/lib/typescript/src/streaming.d.ts +10 -0
  152. package/lib/typescript/src/streaming.d.ts.map +1 -0
  153. package/lib/typescript/src/transport.d.ts +19 -0
  154. package/lib/typescript/src/transport.d.ts.map +1 -0
  155. package/lib/typescript/src/types.d.ts +78 -0
  156. package/lib/typescript/src/types.d.ts.map +1 -0
  157. package/lib/typescript/src/validation/zod.d.ts +33 -0
  158. package/lib/typescript/src/validation/zod.d.ts.map +1 -0
  159. package/lib/typescript/src/version-check.d.ts +40 -0
  160. package/lib/typescript/src/version-check.d.ts.map +1 -0
  161. package/metro/index.js +23 -0
  162. package/metro/transformer.js +21 -0
  163. package/package.json +144 -0
  164. package/react-native-proto.podspec +15 -0
  165. package/src/auth.ts +97 -0
  166. package/src/client-factory.ts +109 -0
  167. package/src/codecs.ts +42 -0
  168. package/src/connect/envelope.ts +112 -0
  169. package/src/connect/errors.ts +86 -0
  170. package/src/errors.ts +81 -0
  171. package/src/generated/create-api.ts +40 -0
  172. package/src/generated/message-types.ts +63 -0
  173. package/src/generated/messages.pb.js +3207 -0
  174. package/src/generated/messages.ts +45 -0
  175. package/src/generated/method-map.ts +71 -0
  176. package/src/index.ts +113 -0
  177. package/src/interceptors.ts +32 -0
  178. package/src/logging.ts +67 -0
  179. package/src/metro/index.ts +27 -0
  180. package/src/metro/transformer.ts +38 -0
  181. package/src/mock-server/index.ts +164 -0
  182. package/src/native-grpc/index.ts +302 -0
  183. package/src/offline-queue.ts +160 -0
  184. package/src/path-templates.ts +65 -0
  185. package/src/react-query/index.ts +40 -0
  186. package/src/streaming.ts +326 -0
  187. package/src/transport.ts +427 -0
  188. package/src/types.ts +94 -0
  189. package/src/validation/zod.ts +75 -0
  190. package/src/version-check.ts +121 -0
@@ -0,0 +1,109 @@
1
+ import { ProtoClientError } from './errors';
2
+ import { streamCall } from './streaming';
3
+ import { resolveConfig, unaryCall } from './transport';
4
+ import type {
5
+ ClientServices,
6
+ CodecRegistry,
7
+ MethodMap,
8
+ MethodMapEntry,
9
+ ProtoClient,
10
+ ProtoClientConfig,
11
+ } from './types';
12
+
13
+ const MAX_METHODS = 2_000;
14
+
15
+ function toCamelServiceName(serviceName: string): string {
16
+ if (!serviceName) {
17
+ return serviceName;
18
+ }
19
+ return serviceName.charAt(0).toLowerCase() + serviceName.slice(1);
20
+ }
21
+
22
+ function assertMethodMap(methodMap: MethodMap): void {
23
+ if (!Array.isArray(methodMap)) {
24
+ throw new ProtoClientError({
25
+ code: 'INVALID_CONFIG',
26
+ message: 'methodMap must be an array',
27
+ });
28
+ }
29
+ if (methodMap.length === 0) {
30
+ throw new ProtoClientError({
31
+ code: 'INVALID_CONFIG',
32
+ message: 'methodMap is empty — generate from your .proto files first',
33
+ });
34
+ }
35
+ if (methodMap.length > MAX_METHODS) {
36
+ throw new ProtoClientError({
37
+ code: 'INVALID_CONFIG',
38
+ message: `methodMap exceeds max methods (${MAX_METHODS})`,
39
+ });
40
+ }
41
+ }
42
+
43
+ function createMethodHandler(
44
+ entry: MethodMapEntry,
45
+ config: ReturnType<typeof resolveConfig>,
46
+ codecs: CodecRegistry
47
+ ) {
48
+ if (entry.kind === 'unary') {
49
+ return async (
50
+ request: Record<string, unknown> = {},
51
+ options?: { signal?: AbortSignal }
52
+ ) =>
53
+ unaryCall(config, codecs, {
54
+ entry,
55
+ request,
56
+ signal: options?.signal,
57
+ });
58
+ }
59
+
60
+ return (
61
+ request: Record<string, unknown> = {},
62
+ options?: { signal?: AbortSignal }
63
+ ) =>
64
+ streamCall(config, codecs, {
65
+ entry,
66
+ request,
67
+ signal: options?.signal,
68
+ });
69
+ }
70
+
71
+ /**
72
+ * Builds a dynamic client from a generated method map and message codecs.
73
+ * Apps typically call `createClient(config)` which uses the package defaults.
74
+ */
75
+ export function createClientFromMap(
76
+ config: ProtoClientConfig,
77
+ methodMap: MethodMap,
78
+ codecs: CodecRegistry
79
+ ): ProtoClient {
80
+ const resolved = resolveConfig(config);
81
+ assertMethodMap(methodMap);
82
+
83
+ const services: ClientServices = {};
84
+
85
+ for (let i = 0; i < methodMap.length; i += 1) {
86
+ const entry = methodMap[i];
87
+ if (!entry) {
88
+ continue;
89
+ }
90
+
91
+ const serviceKey = toCamelServiceName(entry.serviceName);
92
+ const existing = services[serviceKey] ?? {};
93
+ const methodKey =
94
+ entry.methodName.charAt(0).toLowerCase() + entry.methodName.slice(1);
95
+
96
+ existing[methodKey] = createMethodHandler(entry, resolved, codecs);
97
+ services[serviceKey] = existing;
98
+ }
99
+
100
+ return Object.assign(services, {
101
+ config: {
102
+ ...config,
103
+ baseUrl: resolved.baseUrl,
104
+ timeoutMs: resolved.timeoutMs,
105
+ maxResponseBytes: resolved.maxResponseBytes,
106
+ transport: resolved.transport,
107
+ },
108
+ }) as ProtoClient;
109
+ }
package/src/codecs.ts ADDED
@@ -0,0 +1,42 @@
1
+ import type { Type } from 'protobufjs';
2
+ import type { CodecRegistry, MessageCodec, ProtobufTypeLike } from './types';
3
+
4
+ export function codecFromType(type: ProtobufTypeLike): MessageCodec {
5
+ return {
6
+ encode(message: Record<string, unknown>) {
7
+ const value = type.fromObject
8
+ ? type.fromObject(message)
9
+ : type.create(message);
10
+ return type.encode(value).finish();
11
+ },
12
+ decode(bytes: Uint8Array) {
13
+ return type.decode(bytes) as unknown as Record<string, unknown>;
14
+ },
15
+ };
16
+ }
17
+
18
+ export function createCodecRegistry(
19
+ types: Record<string, ProtobufTypeLike | Type>
20
+ ): CodecRegistry {
21
+ const map = new Map<string, MessageCodec>();
22
+ const keys = Object.keys(types);
23
+ for (let i = 0; i < keys.length; i += 1) {
24
+ const key = keys[i];
25
+ if (!key) {
26
+ continue;
27
+ }
28
+ const type = types[key];
29
+ if (type) {
30
+ map.set(key, codecFromType(type));
31
+ }
32
+ }
33
+
34
+ return {
35
+ get(typeName: string) {
36
+ return map.get(typeName);
37
+ },
38
+ has(typeName: string) {
39
+ return map.has(typeName);
40
+ },
41
+ };
42
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Connect protocol envelope framing (unary streaming / server streaming).
3
+ * Spec: 1 flag byte + 4-byte big-endian length + payload.
4
+ *
5
+ * Flag bits:
6
+ * - 0x01 compressed
7
+ * - 0x02 end-stream (JSON trailer / error)
8
+ */
9
+
10
+ export const CONNECT_FLAG_COMPRESSED = 0x01;
11
+ export const CONNECT_FLAG_END_STREAM = 0x02;
12
+
13
+ export type ConnectEnvelope = {
14
+ flags: number;
15
+ data: Uint8Array;
16
+ };
17
+
18
+ export function encodeConnectEnvelope(
19
+ data: Uint8Array,
20
+ flags = 0
21
+ ): Uint8Array {
22
+ const out = new Uint8Array(5 + data.byteLength);
23
+ out[0] = flags & 0xff;
24
+ const len = data.byteLength;
25
+ out[1] = (len >>> 24) & 0xff;
26
+ out[2] = (len >>> 16) & 0xff;
27
+ out[3] = (len >>> 8) & 0xff;
28
+ out[4] = len & 0xff;
29
+ out.set(data, 5);
30
+ return out;
31
+ }
32
+
33
+ export function decodeConnectEnvelopes(buffer: Uint8Array): ConnectEnvelope[] {
34
+ const envelopes: ConnectEnvelope[] = [];
35
+ let offset = 0;
36
+ while (offset + 5 <= buffer.byteLength) {
37
+ const flags = buffer[offset]!;
38
+ const len =
39
+ ((buffer[offset + 1]! << 24) |
40
+ (buffer[offset + 2]! << 16) |
41
+ (buffer[offset + 3]! << 8) |
42
+ buffer[offset + 4]!) >>>
43
+ 0;
44
+ offset += 5;
45
+ if (offset + len > buffer.byteLength) {
46
+ break;
47
+ }
48
+ envelopes.push({
49
+ flags,
50
+ data: buffer.subarray(offset, offset + len),
51
+ });
52
+ offset += len;
53
+ }
54
+ return envelopes;
55
+ }
56
+
57
+ export async function* readConnectEnvelopeStream(
58
+ body: ReadableStream<Uint8Array> | null,
59
+ maxBytes: number
60
+ ): AsyncGenerator<ConnectEnvelope, void, undefined> {
61
+ if (!body) {
62
+ return;
63
+ }
64
+
65
+ const reader = body.getReader();
66
+ let pending = new Uint8Array(0);
67
+ let total = 0;
68
+
69
+ const append = (chunk: Uint8Array) => {
70
+ total += chunk.byteLength;
71
+ if (total > maxBytes) {
72
+ throw new Error(`Connect stream exceeded maxResponseBytes (${maxBytes})`);
73
+ }
74
+ const next = new Uint8Array(pending.byteLength + chunk.byteLength);
75
+ next.set(pending, 0);
76
+ next.set(chunk, pending.byteLength);
77
+ pending = next;
78
+ };
79
+
80
+ try {
81
+ while (true) {
82
+ while (pending.byteLength >= 5) {
83
+ const len =
84
+ ((pending[1]! << 24) |
85
+ (pending[2]! << 16) |
86
+ (pending[3]! << 8) |
87
+ pending[4]!) >>>
88
+ 0;
89
+ if (pending.byteLength < 5 + len) {
90
+ break;
91
+ }
92
+ const flags = pending[0]!;
93
+ const data = pending.subarray(5, 5 + len);
94
+ pending = pending.subarray(5 + len);
95
+ yield { flags, data };
96
+ if (flags & CONNECT_FLAG_END_STREAM) {
97
+ return;
98
+ }
99
+ }
100
+
101
+ const { done, value } = await reader.read();
102
+ if (done) {
103
+ break;
104
+ }
105
+ if (value) {
106
+ append(value);
107
+ }
108
+ }
109
+ } finally {
110
+ reader.releaseLock();
111
+ }
112
+ }
@@ -0,0 +1,86 @@
1
+ import { ProtoClientError, type ProtoErrorCode } from '../errors';
2
+
3
+ /** Connect / gRPC-like code strings → client error codes */
4
+ const CONNECT_CODE_MAP: Record<string, ProtoErrorCode> = {
5
+ canceled: 'ABORTED',
6
+ unknown: 'RPC',
7
+ invalid_argument: 'INVALID_ARGUMENT',
8
+ deadline_exceeded: 'TIMEOUT',
9
+ not_found: 'RPC',
10
+ already_exists: 'RPC',
11
+ permission_denied: 'RPC',
12
+ resource_exhausted: 'RPC',
13
+ failed_precondition: 'RPC',
14
+ aborted: 'ABORTED',
15
+ out_of_range: 'INVALID_ARGUMENT',
16
+ unimplemented: 'UNSUPPORTED',
17
+ internal: 'INTERNAL',
18
+ unavailable: 'NETWORK',
19
+ data_loss: 'DECODE',
20
+ unauthenticated: 'RPC',
21
+ };
22
+
23
+ export type ConnectErrorBody = {
24
+ code?: string;
25
+ message?: string;
26
+ details?: unknown[];
27
+ };
28
+
29
+ export function mapConnectCode(code: string | undefined): ProtoErrorCode {
30
+ if (!code) return 'RPC';
31
+ return CONNECT_CODE_MAP[code.toLowerCase()] ?? 'RPC';
32
+ }
33
+
34
+ export function connectErrorFromJson(
35
+ body: ConnectErrorBody,
36
+ rpcPath: string,
37
+ status?: number
38
+ ): ProtoClientError {
39
+ const connectCode = (body.code ?? 'unknown').toLowerCase();
40
+ const retryable =
41
+ connectCode === 'unavailable' ||
42
+ connectCode === 'resource_exhausted' ||
43
+ connectCode === 'deadline_exceeded';
44
+
45
+ return new ProtoClientError({
46
+ code: mapConnectCode(connectCode),
47
+ message: body.message
48
+ ? `Connect ${connectCode}: ${body.message}`
49
+ : `Connect error ${connectCode} for ${rpcPath}`,
50
+ status,
51
+ rpcPath,
52
+ retryable,
53
+ cause: body,
54
+ });
55
+ }
56
+
57
+ export function tryParseConnectError(
58
+ text: string,
59
+ rpcPath: string,
60
+ status?: number
61
+ ): ProtoClientError | null {
62
+ const trimmed = text.trim();
63
+ if (!trimmed.startsWith('{')) {
64
+ return null;
65
+ }
66
+ try {
67
+ const parsed = JSON.parse(trimmed) as ConnectErrorBody;
68
+ if (parsed && (parsed.code || parsed.message)) {
69
+ return connectErrorFromJson(parsed, rpcPath, status);
70
+ }
71
+ } catch {
72
+ return null;
73
+ }
74
+ return null;
75
+ }
76
+
77
+ export function bytesToUtf8(bytes: Uint8Array): string {
78
+ if (typeof TextDecoder !== 'undefined') {
79
+ return new TextDecoder('utf-8').decode(bytes);
80
+ }
81
+ let out = '';
82
+ for (let i = 0; i < bytes.byteLength; i += 1) {
83
+ out += String.fromCharCode(bytes[i]!);
84
+ }
85
+ return out;
86
+ }
package/src/errors.ts ADDED
@@ -0,0 +1,81 @@
1
+ export type ProtoErrorCode =
2
+ | 'INVALID_CONFIG'
3
+ | 'INVALID_ARGUMENT'
4
+ | 'TIMEOUT'
5
+ | 'NETWORK'
6
+ | 'HTTP'
7
+ | 'RPC'
8
+ | 'DECODE'
9
+ | 'PAYLOAD_TOO_LARGE'
10
+ | 'ABORTED'
11
+ | 'INTERNAL'
12
+ | 'UNSUPPORTED';
13
+
14
+ export type ProtoClientErrorOptions = {
15
+ code: ProtoErrorCode;
16
+ message: string;
17
+ status?: number;
18
+ rpcPath?: string;
19
+ cause?: unknown;
20
+ retryable?: boolean;
21
+ };
22
+
23
+ export class ProtoClientError extends Error {
24
+ readonly code: ProtoErrorCode;
25
+ readonly status?: number;
26
+ readonly rpcPath?: string;
27
+ readonly cause?: unknown;
28
+ readonly retryable: boolean;
29
+
30
+ constructor(options: ProtoClientErrorOptions) {
31
+ super(options.message);
32
+ this.name = 'ProtoClientError';
33
+ this.code = options.code;
34
+ this.status = options.status;
35
+ this.rpcPath = options.rpcPath;
36
+ this.cause = options.cause;
37
+ this.retryable = options.retryable === true;
38
+ Object.setPrototypeOf(this, new.target.prototype);
39
+ }
40
+ }
41
+
42
+ export function isProtoClientError(value: unknown): value is ProtoClientError {
43
+ return value instanceof ProtoClientError;
44
+ }
45
+
46
+ export function getErrorCode(value: unknown): ProtoErrorCode | undefined {
47
+ if (isProtoClientError(value)) {
48
+ return value.code;
49
+ }
50
+ return undefined;
51
+ }
52
+
53
+ export function wrapUnknownError(
54
+ value: unknown,
55
+ rpcPath?: string
56
+ ): ProtoClientError {
57
+ if (isProtoClientError(value)) {
58
+ return value;
59
+ }
60
+
61
+ if (value instanceof Error && value.name === 'AbortError') {
62
+ return new ProtoClientError({
63
+ code: 'ABORTED',
64
+ message: 'Request was aborted',
65
+ rpcPath,
66
+ cause: value,
67
+ retryable: false,
68
+ });
69
+ }
70
+
71
+ const message =
72
+ value instanceof Error ? value.message : 'Unexpected client failure';
73
+
74
+ return new ProtoClientError({
75
+ code: 'INTERNAL',
76
+ message,
77
+ rpcPath,
78
+ cause: value,
79
+ retryable: false,
80
+ });
81
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Auto-generated typed API factory. Do not edit by hand.
3
+ */
4
+ import { createClientFromMap } from '../client-factory';
5
+ import type { ProtoClientConfig } from '../types';
6
+ import { methodMap } from './method-map';
7
+ import { defaultCodecs } from './messages';
8
+ import type {
9
+ AddUserRequest,
10
+ DeleteUserRequest,
11
+ DeleteUserResponse,
12
+ GetUserByEmailRequest,
13
+ GetUserByPhoneRequest,
14
+ GetUserRequest,
15
+ ListUsersRequest,
16
+ ListUsersResponse,
17
+ UpdateUserRequest,
18
+ User,
19
+ } from './message-types';
20
+
21
+ export type UserServiceApi = {
22
+ addUser: (request?: AddUserRequest, options?: { signal?: AbortSignal }) => Promise<User>;
23
+ getUser: (request?: GetUserRequest, options?: { signal?: AbortSignal }) => Promise<User>;
24
+ getUserByEmail: (request?: GetUserByEmailRequest, options?: { signal?: AbortSignal }) => Promise<User>;
25
+ listUsers: (request?: ListUsersRequest, options?: { signal?: AbortSignal }) => Promise<ListUsersResponse>;
26
+ updateUser: (request?: UpdateUserRequest, options?: { signal?: AbortSignal }) => Promise<User>;
27
+ deleteUser: (request?: DeleteUserRequest, options?: { signal?: AbortSignal }) => Promise<DeleteUserResponse>;
28
+ getUserByPhone: (request?: GetUserByPhoneRequest, options?: { signal?: AbortSignal }) => Promise<User>;
29
+ };
30
+
31
+ export type GeneratedApi = {
32
+ userService: UserServiceApi;
33
+ readonly config: ProtoClientConfig;
34
+ };
35
+
36
+ export function createApi(config: ProtoClientConfig): GeneratedApi {
37
+ return createClientFromMap(config, methodMap, defaultCodecs) as unknown as GeneratedApi;
38
+ }
39
+
40
+ export { methodMap, defaultCodecs };
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Auto-generated TypeScript message types. Do not edit by hand.
3
+ * Parsed from .proto message field definitions (simple regex parser).
4
+ */
5
+
6
+ export type AddUserRequest = {
7
+ name?: string;
8
+ email?: string;
9
+ age?: number;
10
+ phone?: string;
11
+ };
12
+
13
+ export type DeleteUserRequest = {
14
+ id?: string;
15
+ };
16
+
17
+ export type DeleteUserResponse = {
18
+ success?: boolean;
19
+ id?: string;
20
+ };
21
+
22
+ export type GetUserByEmailRequest = {
23
+ email?: string;
24
+ };
25
+
26
+ export type GetUserByPhoneRequest = {
27
+ phone?: string;
28
+ };
29
+
30
+ export type GetUserRequest = {
31
+ id?: string;
32
+ };
33
+
34
+ export type ListUsersRequest = {
35
+ page?: number;
36
+ page_size?: number;
37
+ page_token?: string;
38
+ query?: string;
39
+ };
40
+
41
+ export type ListUsersResponse = {
42
+ users?: User[];
43
+ next_page_token?: string;
44
+ total_count?: number;
45
+ };
46
+
47
+ export type UpdateUserRequest = {
48
+ id?: string;
49
+ name?: string;
50
+ email?: string;
51
+ age?: number;
52
+ phone?: string;
53
+ };
54
+
55
+ export type User = {
56
+ id?: string;
57
+ name?: string;
58
+ email?: string;
59
+ age?: number;
60
+ phone?: string;
61
+ created_at?: number;
62
+ updated_at?: number;
63
+ };