@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.
- package/android/src/main/java/com/vishalsharma7nov/reactnativeproto/ReactNativeProtoNativeGrpcModule.java +142 -0
- package/app.plugin.js +63 -0
- package/bin/react-native-proto.js +956 -0
- package/ios/ReactNativeProtoNativeGrpc.m +129 -0
- package/lib/commonjs/auth.js +72 -0
- package/lib/commonjs/auth.js.map +1 -0
- package/lib/commonjs/client-factory.js +81 -0
- package/lib/commonjs/client-factory.js.map +1 -0
- package/lib/commonjs/codecs.js +41 -0
- package/lib/commonjs/codecs.js.map +1 -0
- package/lib/commonjs/connect/envelope.js +100 -0
- package/lib/commonjs/connect/envelope.js.map +1 -0
- package/lib/commonjs/connect/errors.js +71 -0
- package/lib/commonjs/connect/errors.js.map +1 -0
- package/lib/commonjs/errors.js +54 -0
- package/lib/commonjs/errors.js.map +1 -0
- package/lib/commonjs/generated/create-api.js +29 -0
- package/lib/commonjs/generated/create-api.js.map +1 -0
- package/lib/commonjs/generated/message-types.js +2 -0
- package/lib/commonjs/generated/message-types.js.map +1 -0
- package/lib/commonjs/generated/messages.js +47 -0
- package/lib/commonjs/generated/messages.js.map +1 -0
- package/lib/commonjs/generated/messages.pb.js +2787 -0
- package/lib/commonjs/generated/messages.pb.js.map +1 -0
- package/lib/commonjs/generated/method-map.js +68 -0
- package/lib/commonjs/generated/method-map.js.map +1 -0
- package/lib/commonjs/index.js +283 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/interceptors.js +19 -0
- package/lib/commonjs/interceptors.js.map +1 -0
- package/lib/commonjs/logging.js +54 -0
- package/lib/commonjs/logging.js.map +1 -0
- package/lib/commonjs/metro/index.js +35 -0
- package/lib/commonjs/metro/index.js.map +1 -0
- package/lib/commonjs/metro/transformer.js +33 -0
- package/lib/commonjs/metro/transformer.js.map +1 -0
- package/lib/commonjs/mock-server/index.js +125 -0
- package/lib/commonjs/mock-server/index.js.map +1 -0
- package/lib/commonjs/native-grpc/index.js +242 -0
- package/lib/commonjs/native-grpc/index.js.map +1 -0
- package/lib/commonjs/offline-queue.js +137 -0
- package/lib/commonjs/offline-queue.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/path-templates.js +44 -0
- package/lib/commonjs/path-templates.js.map +1 -0
- package/lib/commonjs/react-query/index.js +30 -0
- package/lib/commonjs/react-query/index.js.map +1 -0
- package/lib/commonjs/streaming.js +251 -0
- package/lib/commonjs/streaming.js.map +1 -0
- package/lib/commonjs/transport.js +323 -0
- package/lib/commonjs/transport.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/validation/zod.js +48 -0
- package/lib/commonjs/validation/zod.js.map +1 -0
- package/lib/commonjs/version-check.js +102 -0
- package/lib/commonjs/version-check.js.map +1 -0
- package/lib/module/auth.js +67 -0
- package/lib/module/auth.js.map +1 -0
- package/lib/module/client-factory.js +77 -0
- package/lib/module/client-factory.js.map +1 -0
- package/lib/module/codecs.js +36 -0
- package/lib/module/codecs.js.map +1 -0
- package/lib/module/connect/envelope.js +93 -0
- package/lib/module/connect/envelope.js.map +1 -0
- package/lib/module/connect/errors.js +65 -0
- package/lib/module/connect/errors.js.map +1 -0
- package/lib/module/errors.js +46 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/generated/create-api.js +13 -0
- package/lib/module/generated/create-api.js.map +1 -0
- package/lib/module/generated/message-types.js +2 -0
- package/lib/module/generated/message-types.js.map +1 -0
- package/lib/module/generated/messages.js +43 -0
- package/lib/module/generated/messages.js.map +1 -0
- package/lib/module/generated/messages.pb.js +2787 -0
- package/lib/module/generated/messages.pb.js.map +1 -0
- package/lib/module/generated/method-map.js +64 -0
- package/lib/module/generated/method-map.js.map +1 -0
- package/lib/module/index.js +53 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/interceptors.js +15 -0
- package/lib/module/interceptors.js.map +1 -0
- package/lib/module/logging.js +50 -0
- package/lib/module/logging.js.map +1 -0
- package/lib/module/metro/index.js +25 -0
- package/lib/module/metro/index.js.map +1 -0
- package/lib/module/metro/transformer.js +29 -0
- package/lib/module/metro/transformer.js.map +1 -0
- package/lib/module/mock-server/index.js +120 -0
- package/lib/module/mock-server/index.js.map +1 -0
- package/lib/module/native-grpc/index.js +233 -0
- package/lib/module/native-grpc/index.js.map +1 -0
- package/lib/module/offline-queue.js +132 -0
- package/lib/module/offline-queue.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/path-templates.js +39 -0
- package/lib/module/path-templates.js.map +1 -0
- package/lib/module/react-query/index.js +25 -0
- package/lib/module/react-query/index.js.map +1 -0
- package/lib/module/streaming.js +246 -0
- package/lib/module/streaming.js.map +1 -0
- package/lib/module/transport.js +316 -0
- package/lib/module/transport.js.map +1 -0
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/validation/zod.js +43 -0
- package/lib/module/validation/zod.js.map +1 -0
- package/lib/module/version-check.js +93 -0
- package/lib/module/version-check.js.map +1 -0
- package/lib/typescript/src/auth.d.ts +26 -0
- package/lib/typescript/src/auth.d.ts.map +1 -0
- package/lib/typescript/src/client-factory.d.ts +7 -0
- package/lib/typescript/src/client-factory.d.ts.map +1 -0
- package/lib/typescript/src/codecs.d.ts +5 -0
- package/lib/typescript/src/codecs.d.ts.map +1 -0
- package/lib/typescript/src/connect/envelope.d.ts +18 -0
- package/lib/typescript/src/connect/envelope.d.ts.map +1 -0
- package/lib/typescript/src/connect/errors.d.ts +11 -0
- package/lib/typescript/src/connect/errors.d.ts.map +1 -0
- package/lib/typescript/src/errors.d.ts +21 -0
- package/lib/typescript/src/errors.d.ts.map +1 -0
- package/lib/typescript/src/generated/create-api.d.ts +34 -0
- package/lib/typescript/src/generated/create-api.d.ts.map +1 -0
- package/lib/typescript/src/generated/message-types.d.ts +54 -0
- package/lib/typescript/src/generated/message-types.d.ts.map +1 -0
- package/lib/typescript/src/generated/messages.d.ts +17 -0
- package/lib/typescript/src/generated/messages.d.ts.map +1 -0
- package/lib/typescript/src/generated/method-map.d.ts +7 -0
- package/lib/typescript/src/generated/method-map.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +53 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/interceptors.d.ts +17 -0
- package/lib/typescript/src/interceptors.d.ts.map +1 -0
- package/lib/typescript/src/logging.d.ts +16 -0
- package/lib/typescript/src/logging.d.ts.map +1 -0
- package/lib/typescript/src/metro/index.d.ts +15 -0
- package/lib/typescript/src/metro/index.d.ts.map +1 -0
- package/lib/typescript/src/metro/transformer.d.ts +16 -0
- package/lib/typescript/src/metro/transformer.d.ts.map +1 -0
- package/lib/typescript/src/mock-server/index.d.ts +27 -0
- package/lib/typescript/src/mock-server/index.d.ts.map +1 -0
- package/lib/typescript/src/native-grpc/index.d.ts +36 -0
- package/lib/typescript/src/native-grpc/index.d.ts.map +1 -0
- package/lib/typescript/src/offline-queue.d.ts +47 -0
- package/lib/typescript/src/offline-queue.d.ts.map +1 -0
- package/lib/typescript/src/path-templates.d.ts +17 -0
- package/lib/typescript/src/path-templates.d.ts.map +1 -0
- package/lib/typescript/src/react-query/index.d.ts +14 -0
- package/lib/typescript/src/react-query/index.d.ts.map +1 -0
- package/lib/typescript/src/streaming.d.ts +10 -0
- package/lib/typescript/src/streaming.d.ts.map +1 -0
- package/lib/typescript/src/transport.d.ts +19 -0
- package/lib/typescript/src/transport.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +78 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/validation/zod.d.ts +33 -0
- package/lib/typescript/src/validation/zod.d.ts.map +1 -0
- package/lib/typescript/src/version-check.d.ts +40 -0
- package/lib/typescript/src/version-check.d.ts.map +1 -0
- package/metro/index.js +23 -0
- package/metro/transformer.js +21 -0
- package/package.json +144 -0
- package/react-native-proto.podspec +15 -0
- package/src/auth.ts +97 -0
- package/src/client-factory.ts +109 -0
- package/src/codecs.ts +42 -0
- package/src/connect/envelope.ts +112 -0
- package/src/connect/errors.ts +86 -0
- package/src/errors.ts +81 -0
- package/src/generated/create-api.ts +40 -0
- package/src/generated/message-types.ts +63 -0
- package/src/generated/messages.pb.js +3207 -0
- package/src/generated/messages.ts +45 -0
- package/src/generated/method-map.ts +71 -0
- package/src/index.ts +113 -0
- package/src/interceptors.ts +32 -0
- package/src/logging.ts +67 -0
- package/src/metro/index.ts +27 -0
- package/src/metro/transformer.ts +38 -0
- package/src/mock-server/index.ts +164 -0
- package/src/native-grpc/index.ts +302 -0
- package/src/offline-queue.ts +160 -0
- package/src/path-templates.ts +65 -0
- package/src/react-query/index.ts +40 -0
- package/src/streaming.ts +326 -0
- package/src/transport.ts +427 -0
- package/src/types.ts +94 -0
- package/src/validation/zod.ts +75 -0
- package/src/version-check.ts +121 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#if __has_include(<React/RCTBridgeModule.h>)
|
|
2
|
+
#import <React/RCTBridgeModule.h>
|
|
3
|
+
#else
|
|
4
|
+
#import <React-Core/React/RCTBridgeModule.h>
|
|
5
|
+
#endif
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* HTTP+protobuf unary bridge for transport "native-grpc".
|
|
9
|
+
* POSTs application/x-protobuf bodies via NSURLSession.
|
|
10
|
+
*/
|
|
11
|
+
@interface ReactNativeProtoNativeGrpc : NSObject <RCTBridgeModule>
|
|
12
|
+
@end
|
|
13
|
+
|
|
14
|
+
@implementation ReactNativeProtoNativeGrpc
|
|
15
|
+
|
|
16
|
+
RCT_EXPORT_MODULE();
|
|
17
|
+
|
|
18
|
+
RCT_REMAP_METHOD(isAvailable,
|
|
19
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
20
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
21
|
+
{
|
|
22
|
+
resolve(@YES);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
RCT_EXPORT_METHOD(unary:(NSString *)baseUrl
|
|
26
|
+
rpcPath:(NSString *)rpcPath
|
|
27
|
+
requestBase64:(NSString *)requestBase64
|
|
28
|
+
headersJson:(NSString *)headersJson
|
|
29
|
+
timeoutMs:(nonnull NSNumber *)timeoutMs
|
|
30
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
31
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
32
|
+
{
|
|
33
|
+
if (baseUrl.length == 0) {
|
|
34
|
+
reject(@"INVALID_ARGUMENT", @"baseUrl is required", nil);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (rpcPath.length == 0) {
|
|
38
|
+
reject(@"INVALID_ARGUMENT", @"rpcPath is required", nil);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
NSData *body = [[NSData alloc] initWithBase64EncodedString:(requestBase64 ?: @"")
|
|
43
|
+
options:NSDataBase64DecodingIgnoreUnknownCharacters];
|
|
44
|
+
if (body == nil && requestBase64.length > 0) {
|
|
45
|
+
reject(@"INVALID_ARGUMENT", @"requestBase64 is not valid base64", nil);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (body == nil) {
|
|
49
|
+
body = [NSData data];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
NSString *path = rpcPath;
|
|
53
|
+
if (![path hasPrefix:@"/"]) {
|
|
54
|
+
path = [NSString stringWithFormat:@"/%@", path];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
NSString *trimmedBase = [baseUrl hasSuffix:@"/"]
|
|
58
|
+
? [baseUrl substringToIndex:baseUrl.length - 1]
|
|
59
|
+
: baseUrl;
|
|
60
|
+
NSString *urlString = [NSString stringWithFormat:@"%@%@", trimmedBase, path];
|
|
61
|
+
NSURL *url = [NSURL URLWithString:urlString];
|
|
62
|
+
if (url == nil) {
|
|
63
|
+
reject(@"INVALID_ARGUMENT", @"Could not build request URL", nil);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
|
|
68
|
+
request.HTTPMethod = @"POST";
|
|
69
|
+
request.HTTPBody = body;
|
|
70
|
+
[request setValue:@"application/x-protobuf" forHTTPHeaderField:@"Content-Type"];
|
|
71
|
+
[request setValue:@"application/x-protobuf" forHTTPHeaderField:@"Accept"];
|
|
72
|
+
|
|
73
|
+
NSTimeInterval timeoutSec = MAX(timeoutMs.doubleValue / 1000.0, 0.001);
|
|
74
|
+
request.timeoutInterval = timeoutSec;
|
|
75
|
+
|
|
76
|
+
if (headersJson.length > 0) {
|
|
77
|
+
NSData *jsonData = [headersJson dataUsingEncoding:NSUTF8StringEncoding];
|
|
78
|
+
NSError *jsonError = nil;
|
|
79
|
+
id parsed = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&jsonError];
|
|
80
|
+
if (jsonError != nil) {
|
|
81
|
+
reject(@"INVALID_ARGUMENT", @"headersJson is not valid JSON", jsonError);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if ([parsed isKindOfClass:[NSDictionary class]]) {
|
|
85
|
+
NSDictionary *headers = (NSDictionary *)parsed;
|
|
86
|
+
for (NSString *key in headers) {
|
|
87
|
+
id value = headers[key];
|
|
88
|
+
if ([value isKindOfClass:[NSString class]]) {
|
|
89
|
+
[request setValue:(NSString *)value forHTTPHeaderField:key];
|
|
90
|
+
} else if (value != nil && value != [NSNull null]) {
|
|
91
|
+
[request setValue:[value description] forHTTPHeaderField:key];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
|
|
98
|
+
config.timeoutIntervalForRequest = timeoutSec;
|
|
99
|
+
config.timeoutIntervalForResource = timeoutSec;
|
|
100
|
+
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
|
|
101
|
+
|
|
102
|
+
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
|
|
103
|
+
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
|
|
104
|
+
if (error != nil) {
|
|
105
|
+
reject(@"NETWORK", error.localizedDescription ?: @"Network request failed", error);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
NSHTTPURLResponse *http = (NSHTTPURLResponse *)response;
|
|
110
|
+
if (![http isKindOfClass:[NSHTTPURLResponse class]]) {
|
|
111
|
+
reject(@"NETWORK", @"Unexpected non-HTTP response", nil);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (http.statusCode < 200 || http.statusCode >= 300) {
|
|
116
|
+
NSString *msg = [NSString stringWithFormat:@"HTTP %ld", (long)http.statusCode];
|
|
117
|
+
reject(@"HTTP_ERROR", msg, nil);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
NSData *responseData = data ?: [NSData data];
|
|
122
|
+
NSString *responseBase64 = [responseData base64EncodedStringWithOptions:0];
|
|
123
|
+
resolve(responseBase64 ?: @"");
|
|
124
|
+
}];
|
|
125
|
+
|
|
126
|
+
[task resume];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createAuthInterceptor = createAuthInterceptor;
|
|
7
|
+
exports.createBearerTokenHeaders = createBearerTokenHeaders;
|
|
8
|
+
var _errors = require("./errors");
|
|
9
|
+
function defaultIsUnauthorized(error) {
|
|
10
|
+
if (!(0, _errors.isProtoClientError)(error)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
if (error.status === 401) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
const msg = error.message.toLowerCase();
|
|
17
|
+
return error.code === "RPC" && (msg.includes("unauthenticated") || msg.includes("unauthorized"));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Adds Authorization (or custom) headers and optionally retries once after refresh.
|
|
22
|
+
*/
|
|
23
|
+
function createAuthInterceptor(options) {
|
|
24
|
+
const headerName = options.headerName ?? "Authorization";
|
|
25
|
+
const scheme = options.scheme ?? "Bearer ";
|
|
26
|
+
const isUnauthorized = options.isUnauthorized ?? defaultIsUnauthorized;
|
|
27
|
+
return async (ctx, next) => {
|
|
28
|
+
const applyToken = (headers, token) => {
|
|
29
|
+
if (!token) {
|
|
30
|
+
return headers;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
...headers,
|
|
34
|
+
[headerName]: token.startsWith(scheme) ? token : `${scheme}${token}`
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const token = await options.getAccessToken();
|
|
38
|
+
const firstCtx = {
|
|
39
|
+
...ctx,
|
|
40
|
+
headers: applyToken(ctx.headers, token)
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
return await next(firstCtx);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (!options.refreshAccessToken || !isUnauthorized(error)) {
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
const refreshed = await options.refreshAccessToken();
|
|
49
|
+
const retryCtx = {
|
|
50
|
+
...ctx,
|
|
51
|
+
headers: applyToken(ctx.headers, refreshed)
|
|
52
|
+
};
|
|
53
|
+
return next(retryCtx);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Simple helper that only injects a static or async token (no refresh).
|
|
60
|
+
*/
|
|
61
|
+
function createBearerTokenHeaders(getToken) {
|
|
62
|
+
return async () => {
|
|
63
|
+
const token = await getToken();
|
|
64
|
+
if (!token) {
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
Authorization: token.startsWith('Bearer ') ? token : `Bearer ${token}`
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_errors","require","defaultIsUnauthorized","error","isProtoClientError","status","msg","message","toLowerCase","code","includes","createAuthInterceptor","options","headerName","scheme","isUnauthorized","ctx","next","applyToken","headers","token","startsWith","getAccessToken","firstCtx","refreshAccessToken","refreshed","retryCtx","createBearerTokenHeaders","getToken","Authorization"],"sourceRoot":"../../src","sources":["auth.ts"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAoBA,SAASC,qBAAqBA,CAACC,KAAc,EAAW;EACtD,IAAI,CAAC,IAAAC,0BAAkB,EAACD,KAAK,CAAC,EAAE;IAC9B,OAAO,KAAK;EACd;EACA,IAAIA,KAAK,CAACE,MAAM,KAAK,GAAG,EAAE;IACxB,OAAO,IAAI;EACb;EACA,MAAMC,GAAG,GAAGH,KAAK,CAACI,OAAO,CAACC,WAAW,CAAC,CAAC;EACvC,OACEL,KAAK,CAACM,IAAI,KAAK,KAAK,KACnBH,GAAG,CAACI,QAAQ,CAAC,iBAAiB,CAAC,IAAIJ,GAAG,CAACI,QAAQ,CAAC,cAAc,CAAC,CAAC;AAErE;;AAEA;AACA;AACA;AACO,SAASC,qBAAqBA,CACnCC,OAA+B,EAClB;EACb,MAAMC,UAAU,GAAGD,OAAO,CAACC,UAAU,IAAI,eAAe;EACxD,MAAMC,MAAM,GAAGF,OAAO,CAACE,MAAM,IAAI,SAAS;EAC1C,MAAMC,cAAc,GAAGH,OAAO,CAACG,cAAc,IAAIb,qBAAqB;EAEtE,OAAO,OAAOc,GAAG,EAAEC,IAAI,KAAK;IAC1B,MAAMC,UAAU,GAAGA,CACjBC,OAAkB,EAClBC,KAAoB,KACN;MACd,IAAI,CAACA,KAAK,EAAE;QACV,OAAOD,OAAO;MAChB;MACA,O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6
|
+
exports.createClientFromMap = createClientFromMap;
|
|
7
|
+
var _errors = require("./errors");
|
|
8
|
+
var _streaming = require("./streaming");
|
|
9
|
+
var _transport = require("./transport");
|
|
10
|
+
const MAX_METHODS = 2_000;
|
|
11
|
+
function toCamelServiceName(serviceName) {
|
|
12
|
+
if (!serviceName) {
|
|
13
|
+
return serviceName;
|
|
14
|
+
}
|
|
15
|
+
return serviceName.charAt(0).toLowerCase() + serviceName.slice(1);
|
|
16
|
+
}
|
|
17
|
+
function assertMethodMap(methodMap) {
|
|
18
|
+
if (!Array.isArray(methodMap)) {
|
|
19
|
+
throw new _errors.ProtoClientError({
|
|
20
|
+
code: 'INVALID_CONFIG',
|
|
21
|
+
message: 'methodMap must be an array'
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (methodMap.length === 0) {
|
|
25
|
+
throw new _errors.ProtoClientError({
|
|
26
|
+
code: 'INVALID_CONFIG',
|
|
27
|
+
message: 'methodMap is empty — generate from your .proto files first'
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (methodMap.length > MAX_METHODS) {
|
|
31
|
+
throw new _errors.ProtoClientError({
|
|
32
|
+
code: 'INVALID_CONFIG',
|
|
33
|
+
message: `methodMap exceeds max methods (${MAX_METHODS})`
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function createMethodHandler(entry, config, codecs) {
|
|
38
|
+
if (entry.kind === 'unary') {
|
|
39
|
+
return async (request = {}, options) => (0, _transport.unaryCall)(config, codecs, {
|
|
40
|
+
entry,
|
|
41
|
+
request,
|
|
42
|
+
signal: options?.signal
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return (request = {}, options) => (0, _streaming.streamCall)(config, codecs, {
|
|
46
|
+
entry,
|
|
47
|
+
request,
|
|
48
|
+
signal: options?.signal
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Builds a dynamic client from a generated method map and message codecs.
|
|
54
|
+
* Apps typically call `createClient(config)` which uses the package defaults.
|
|
55
|
+
*/
|
|
56
|
+
function createClientFromMap(config, methodMap, codecs) {
|
|
57
|
+
const resolved = (0, _transport.resolveConfig)(config);
|
|
58
|
+
assertMethodMap(methodMap);
|
|
59
|
+
const services = {};
|
|
60
|
+
for (let i = 0; i < methodMap.length; i += 1) {
|
|
61
|
+
const entry = methodMap[i];
|
|
62
|
+
if (!entry) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const serviceKey = toCamelServiceName(entry.serviceName);
|
|
66
|
+
const existing = services[serviceKey] ?? {};
|
|
67
|
+
const methodKey = entry.methodName.charAt(0).toLowerCase() + entry.methodName.slice(1);
|
|
68
|
+
existing[methodKey] = createMethodHandler(entry, resolved, codecs);
|
|
69
|
+
services[serviceKey] = existing;
|
|
70
|
+
}
|
|
71
|
+
return Object.assign(services, {
|
|
72
|
+
config: {
|
|
73
|
+
...config,
|
|
74
|
+
baseUrl: resolved.baseUrl,
|
|
75
|
+
timeoutMs: resolved.timeoutMs,
|
|
76
|
+
maxResponseBytes: resolved.maxResponseBytes,
|
|
77
|
+
transport: resolved.transport
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=client-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_errors","require","_streaming","_transport","MAX_METHODS","toCamelServiceName","serviceName","charAt","toLowerCase","slice","assertMethodMap","methodMap","Array","isArray","ProtoClientError","code","message","length","createMethodHandler","entry","config","codecs","kind","request","options","unaryCall","signal","streamCall","createClientFromMap","resolved","resolveConfig","services","i","serviceKey","existing","methodKey","methodName","Object","assign","baseUrl","timeoutMs","maxResponseBytes","transport"],"sourceRoot":"../../src","sources":["client-factory.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAUA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 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.codecFromType = codecFromType;
|
|
7
|
+
exports.createCodecRegistry = createCodecRegistry;
|
|
8
|
+
function codecFromType(type) {
|
|
9
|
+
return {
|
|
10
|
+
encode(message) {
|
|
11
|
+
const value = type.fromObject ? type.fromObject(message) : type.create(message);
|
|
12
|
+
return type.encode(value).finish();
|
|
13
|
+
},
|
|
14
|
+
decode(bytes) {
|
|
15
|
+
return type.decode(bytes);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function createCodecRegistry(types) {
|
|
20
|
+
const map = new Map();
|
|
21
|
+
const keys = Object.keys(types);
|
|
22
|
+
for (let i = 0; i < keys.length; i += 1) {
|
|
23
|
+
const key = keys[i];
|
|
24
|
+
if (!key) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const type = types[key];
|
|
28
|
+
if (type) {
|
|
29
|
+
map.set(key, codecFromType(type));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
get(typeName) {
|
|
34
|
+
return map.get(typeName);
|
|
35
|
+
},
|
|
36
|
+
has(typeName) {
|
|
37
|
+
return map.has(typeName);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=codecs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["codecFromType","type","encode","message","value","fromObject","create","finish","decode","bytes","createCodecRegistry","types","map","Map","keys","Object","i","length","key","set","get","typeName","has"],"sourceRoot":"../../src","sources":["codecs.ts"],"mappings":";;;;;;;AAGO,SAASA,aAAaA,CAACC,IAAsB,EAAgB;EAClE,OAAO;IACLC,MAAMA,CAACC,OAAgC,EAAE;MACvC,MAAMC,KAAK,GAAGH,IAAI,CAACI,UAAU,GACzBJ,IAAI,CAACI,UAAU,CAACF,OAAO,CAAC,GACxBF,IAAI,CAACK,MAAM,CAACH,OAAO,CAAC;MACxB,OAAOF,IAAI,CAACC,MAAM,CAACE,KAAK,CAAC,CAACG,MAAM,CAAC,CAAC;IACpC,CAAC;IACDC,MAAMA,CAACC,KAAiB,EAAE;MACxB,OAAOR,IAAI,CAACO,MAAM,CAACC,KAAK,CAAC;IAC3B;EACF,CAAC;AACH;AAEO,SAASC,mBAAmBA,CACjCC,KAA8C,EAC/B;EACf,MAAMC,GAAG,GAAG,IAAIC,GAAG,CAAuB,CAAC;EAC3C,MAAMC,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACH,KAAK,CAAC;EAC/B,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,IAAI,CAACG,MAAM,EAAED,CAAC,IAAI,CAAC,EAAE;IACvC,MAAME,GAAG,GAAGJ,IAAI,CAACE,CAAC,CAAC;IACnB,IAAI,CAACE,GAAG,EAAE;MACR;IACF;IACA,MAAMjB,IAAI,GAAGU,KAAK,CAACO,GAAG,CAAC;IACvB,IAAIjB,IAAI,EAAE;MACRW,GAAG,CAACO,GAAG,CAACD,GAAG,EAAElB,aAAa,CAACC,IAAI,CAAC,CAAC;IACnC;EACF;EAEA,OAAO;IACLmB,GAAGA,CAACC,QAAgB,EAAE;MACpB,OAAOT,GAAG,CAACQ,GAAG,CAACC,QAAQ,CAAC;IAC1B,CAAC;IACDC,GAAGA,CAACD,QAAgB,EAAE;MACpB,OAAOT,GAAG,CAACU,GAAG,CAACD,QAAQ,CAAC;IAC1B;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CONNECT_FLAG_END_STREAM = exports.CONNECT_FLAG_COMPRESSED = void 0;
|
|
7
|
+
exports.decodeConnectEnvelopes = decodeConnectEnvelopes;
|
|
8
|
+
exports.encodeConnectEnvelope = encodeConnectEnvelope;
|
|
9
|
+
exports.readConnectEnvelopeStream = readConnectEnvelopeStream;
|
|
10
|
+
/**
|
|
11
|
+
* Connect protocol envelope framing (unary streaming / server streaming).
|
|
12
|
+
* Spec: 1 flag byte + 4-byte big-endian length + payload.
|
|
13
|
+
*
|
|
14
|
+
* Flag bits:
|
|
15
|
+
* - 0x01 compressed
|
|
16
|
+
* - 0x02 end-stream (JSON trailer / error)
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const CONNECT_FLAG_COMPRESSED = exports.CONNECT_FLAG_COMPRESSED = 0x01;
|
|
20
|
+
const CONNECT_FLAG_END_STREAM = exports.CONNECT_FLAG_END_STREAM = 0x02;
|
|
21
|
+
function encodeConnectEnvelope(data, flags = 0) {
|
|
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
|
+
function decodeConnectEnvelopes(buffer) {
|
|
33
|
+
const envelopes = [];
|
|
34
|
+
let offset = 0;
|
|
35
|
+
while (offset + 5 <= buffer.byteLength) {
|
|
36
|
+
const flags = buffer[offset];
|
|
37
|
+
const len = (buffer[offset + 1] << 24 | buffer[offset + 2] << 16 | buffer[offset + 3] << 8 | buffer[offset + 4]) >>> 0;
|
|
38
|
+
offset += 5;
|
|
39
|
+
if (offset + len > buffer.byteLength) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
envelopes.push({
|
|
43
|
+
flags,
|
|
44
|
+
data: buffer.subarray(offset, offset + len)
|
|
45
|
+
});
|
|
46
|
+
offset += len;
|
|
47
|
+
}
|
|
48
|
+
return envelopes;
|
|
49
|
+
}
|
|
50
|
+
async function* readConnectEnvelopeStream(body, maxBytes) {
|
|
51
|
+
if (!body) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const reader = body.getReader();
|
|
55
|
+
let pending = new Uint8Array(0);
|
|
56
|
+
let total = 0;
|
|
57
|
+
const append = chunk => {
|
|
58
|
+
total += chunk.byteLength;
|
|
59
|
+
if (total > maxBytes) {
|
|
60
|
+
throw new Error(`Connect stream exceeded maxResponseBytes (${maxBytes})`);
|
|
61
|
+
}
|
|
62
|
+
const next = new Uint8Array(pending.byteLength + chunk.byteLength);
|
|
63
|
+
next.set(pending, 0);
|
|
64
|
+
next.set(chunk, pending.byteLength);
|
|
65
|
+
pending = next;
|
|
66
|
+
};
|
|
67
|
+
try {
|
|
68
|
+
while (true) {
|
|
69
|
+
while (pending.byteLength >= 5) {
|
|
70
|
+
const len = (pending[1] << 24 | pending[2] << 16 | pending[3] << 8 | pending[4]) >>> 0;
|
|
71
|
+
if (pending.byteLength < 5 + len) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
const flags = pending[0];
|
|
75
|
+
const data = pending.subarray(5, 5 + len);
|
|
76
|
+
pending = pending.subarray(5 + len);
|
|
77
|
+
yield {
|
|
78
|
+
flags,
|
|
79
|
+
data
|
|
80
|
+
};
|
|
81
|
+
if (flags & CONNECT_FLAG_END_STREAM) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const {
|
|
86
|
+
done,
|
|
87
|
+
value
|
|
88
|
+
} = await reader.read();
|
|
89
|
+
if (done) {
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
if (value) {
|
|
93
|
+
append(value);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} finally {
|
|
97
|
+
reader.releaseLock();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=envelope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CONNECT_FLAG_COMPRESSED","exports","CONNECT_FLAG_END_STREAM","encodeConnectEnvelope","data","flags","out","Uint8Array","byteLength","len","set","decodeConnectEnvelopes","buffer","envelopes","offset","push","subarray","readConnectEnvelopeStream","body","maxBytes","reader","getReader","pending","total","append","chunk","Error","next","done","value","read","releaseLock"],"sourceRoot":"../../../src","sources":["connect/envelope.ts"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,MAAMA,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAG,IAAI;AACpC,MAAME,uBAAuB,GAAAD,OAAA,CAAAC,uBAAA,GAAG,IAAI;AAOpC,SAASC,qBAAqBA,CACnCC,IAAgB,EAChBC,KAAK,GAAG,CAAC,EACG;EACZ,MAAMC,GAAG,GAAG,IAAIC,UAAU,CAAC,CAAC,GAAGH,IAAI,CAACI,UAAU,CAAC;EAC/CF,GAAG,CAAC,CAAC,CAAC,GAAGD,KAAK,GAAG,IAAI;EACrB,MAAMI,GAAG,GAAGL,IAAI,CAACI,UAAU;EAC3BF,GAAG,CAAC,CAAC,CAAC,GAAIG,GAAG,KAAK,EAAE,GAAI,IAAI;EAC5BH,GAAG,CAAC,CAAC,CAAC,GAAIG,GAAG,KAAK,EAAE,GAAI,IAAI;EAC5BH,GAAG,CAAC,CAAC,CAAC,GAAIG,GAAG,KAAK,CAAC,GAAI,IAAI;EAC3BH,GAAG,CAAC,CAAC,CAAC,GAAGG,GAAG,GAAG,IAAI;EACnBH,GAAG,CAACI,GAAG,CAACN,IAAI,EAAE,CAAC,CAAC;EAChB,OAAOE,GAAG;AACZ;AAEO,SAASK,sBAAsBA,CAACC,MAAkB,EAAqB;EAC5E,MAAMC,SAA4B,GAAG,EAAE;EACvC,IAAIC,MAAM,GAAG,CAAC;EACd,OAAOA,MAAM,GAAG,CAAC,IAAIF,MAAM,CAACJ,UAAU,EAAE;IACtC,MAAMH,K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AAC;IACnCc,OAAO,GAAGK,IAAI;EAChB,CAAC;EAED,IAAI;IACF,OAAO,IAAI,EAAE;MACX,OAAOL,OAAO,CAACd,UAAU,IAAI,CAAC,EAAE;QAC9B,MAAMC,GAAG,GACP,CAAEa,OAAO,CAAC,CAAC,CAAC,IAAK,EAAE,GAChBA,OAAO,CAAC,CAAC,CAAC,IAAK,EAAG,GAClBA,OAAO,CAAC,CAAC,CAAC,IAAK,CAAE,GAClBA,OAAO,CAAC,CAAC,CAAE,MACb,CAAC;QACH,IAAIA,OAAO,CAACd,UAAU,GAAG,CAAC,GAAGC,GAAG,EAAE;UAChC;QACF;QACA,MAAMJ,KAAK,GAAGiB,OAAO,CAAC,CAAC,CAAE;QACzB,MAAMlB,IAAI,GAAGkB,OAAO,CAACN,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAGP,GAAG,CAAC;QACzCa,OAAO,GAAGA,OAAO,CAACN,QAAQ,CAAC,CAAC,GAAGP,GAAG,CAAC;QACnC,MAAM;UAAEJ,KAAK;UAAED;QAAK,CAAC;QACrB,IAAIC,KAAK,GAAGH,uBAAuB,EAAE;UACnC;QACF;MACF;MAEA,MAAM;QAAE0B,IAAI;QAAEC;MAAM,CAAC,GAAG,MAAMT,MAAM,CAACU,IAAI,CAAC,CAAC;MAC3C,IAAIF,IAAI,EAAE;QACR;MACF;MACA,IAAIC,KAAK,EAAE;QACTL,MAAM,CAACK,KAAK,CAAC;MACf;IACF;EACF,CAAC,SAAS;IACRT,MAAM,CAACW,WAAW,CAAC,CAAC;EACtB;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.bytesToUtf8 = bytesToUtf8;
|
|
7
|
+
exports.connectErrorFromJson = connectErrorFromJson;
|
|
8
|
+
exports.mapConnectCode = mapConnectCode;
|
|
9
|
+
exports.tryParseConnectError = tryParseConnectError;
|
|
10
|
+
var _errors = require("../errors");
|
|
11
|
+
/** Connect / gRPC-like code strings → client error codes */
|
|
12
|
+
const CONNECT_CODE_MAP = {
|
|
13
|
+
canceled: 'ABORTED',
|
|
14
|
+
unknown: 'RPC',
|
|
15
|
+
invalid_argument: 'INVALID_ARGUMENT',
|
|
16
|
+
deadline_exceeded: 'TIMEOUT',
|
|
17
|
+
not_found: 'RPC',
|
|
18
|
+
already_exists: 'RPC',
|
|
19
|
+
permission_denied: 'RPC',
|
|
20
|
+
resource_exhausted: 'RPC',
|
|
21
|
+
failed_precondition: 'RPC',
|
|
22
|
+
aborted: 'ABORTED',
|
|
23
|
+
out_of_range: 'INVALID_ARGUMENT',
|
|
24
|
+
unimplemented: 'UNSUPPORTED',
|
|
25
|
+
internal: 'INTERNAL',
|
|
26
|
+
unavailable: 'NETWORK',
|
|
27
|
+
data_loss: 'DECODE',
|
|
28
|
+
unauthenticated: 'RPC'
|
|
29
|
+
};
|
|
30
|
+
function mapConnectCode(code) {
|
|
31
|
+
if (!code) return 'RPC';
|
|
32
|
+
return CONNECT_CODE_MAP[code.toLowerCase()] ?? 'RPC';
|
|
33
|
+
}
|
|
34
|
+
function connectErrorFromJson(body, rpcPath, status) {
|
|
35
|
+
const connectCode = (body.code ?? 'unknown').toLowerCase();
|
|
36
|
+
const retryable = connectCode === 'unavailable' || connectCode === 'resource_exhausted' || connectCode === 'deadline_exceeded';
|
|
37
|
+
return new _errors.ProtoClientError({
|
|
38
|
+
code: mapConnectCode(connectCode),
|
|
39
|
+
message: body.message ? `Connect ${connectCode}: ${body.message}` : `Connect error ${connectCode} for ${rpcPath}`,
|
|
40
|
+
status,
|
|
41
|
+
rpcPath,
|
|
42
|
+
retryable,
|
|
43
|
+
cause: body
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function tryParseConnectError(text, rpcPath, status) {
|
|
47
|
+
const trimmed = text.trim();
|
|
48
|
+
if (!trimmed.startsWith('{')) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const parsed = JSON.parse(trimmed);
|
|
53
|
+
if (parsed && (parsed.code || parsed.message)) {
|
|
54
|
+
return connectErrorFromJson(parsed, rpcPath, status);
|
|
55
|
+
}
|
|
56
|
+
} catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
function bytesToUtf8(bytes) {
|
|
62
|
+
if (typeof TextDecoder !== 'undefined') {
|
|
63
|
+
return new TextDecoder('utf-8').decode(bytes);
|
|
64
|
+
}
|
|
65
|
+
let out = '';
|
|
66
|
+
for (let i = 0; i < bytes.byteLength; i += 1) {
|
|
67
|
+
out += String.fromCharCode(bytes[i]);
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_errors","require","CONNECT_CODE_MAP","canceled","unknown","invalid_argument","deadline_exceeded","not_found","already_exists","permission_denied","resource_exhausted","failed_precondition","aborted","out_of_range","unimplemented","internal","unavailable","data_loss","unauthenticated","mapConnectCode","code","toLowerCase","connectErrorFromJson","body","rpcPath","status","connectCode","retryable","ProtoClientError","message","cause","tryParseConnectError","text","trimmed","trim","startsWith","parsed","JSON","parse","bytesToUtf8","bytes","TextDecoder","decode","out","i","byteLength","String","fromCharCode"],"sourceRoot":"../../../src","sources":["connect/errors.ts"],"mappings":";;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEA;AACA,MAAMC,gBAAgD,GAAG;EACvDC,QAAQ,EAAE,SAAS;EACnBC,OAAO,EAAE,KAAK;EACdC,gBAAgB,EAAE,kBAAkB;EACpCC,iBAAiB,EAAE,SAAS;EAC5BC,SAAS,EAAE,KAAK;EAChBC,cAAc,EAAE,KAAK;EACrBC,iBAAiB,EAAE,KAAK;EACxBC,kBAAkB,EAAE,KAAK;EACz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M,CAAChB,IAAI,IAAIgB,MAAM,CAACP,OAAO,CAAC,EAAE;MAC7C,OAAOP,oBAAoB,CAACc,MAAM,EAAEZ,OAAO,EAAEC,MAAM,CAAC;IACtD;EACF,CAAC,CAAC,MAAM;IACN,OAAO,IAAI;EACb;EACA,OAAO,IAAI;AACb;AAEO,SAASc,WAAWA,CAACC,KAAiB,EAAU;EACrD,IAAI,OAAOC,WAAW,KAAK,WAAW,EAAE;IACtC,OAAO,IAAIA,WAAW,CAAC,OAAO,CAAC,CAACC,MAAM,CAACF,KAAK,CAAC;EAC/C;EACA,IAAIG,GAAG,GAAG,EAAE;EACZ,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGJ,KAAK,CAACK,UAAU,EAAED,CAAC,IAAI,CAAC,EAAE;IAC5CD,GAAG,IAAIG,MAAM,CAACC,YAAY,CAACP,KAAK,CAACI,CAAC,CAAE,CAAC;EACvC;EACA,OAAOD,GAAG;AACZ","ignoreList":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ProtoClientError = void 0;
|
|
7
|
+
exports.getErrorCode = getErrorCode;
|
|
8
|
+
exports.isProtoClientError = isProtoClientError;
|
|
9
|
+
exports.wrapUnknownError = wrapUnknownError;
|
|
10
|
+
class ProtoClientError extends Error {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
super(options.message);
|
|
13
|
+
this.name = 'ProtoClientError';
|
|
14
|
+
this.code = options.code;
|
|
15
|
+
this.status = options.status;
|
|
16
|
+
this.rpcPath = options.rpcPath;
|
|
17
|
+
this.cause = options.cause;
|
|
18
|
+
this.retryable = options.retryable === true;
|
|
19
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ProtoClientError = ProtoClientError;
|
|
23
|
+
function isProtoClientError(value) {
|
|
24
|
+
return value instanceof ProtoClientError;
|
|
25
|
+
}
|
|
26
|
+
function getErrorCode(value) {
|
|
27
|
+
if (isProtoClientError(value)) {
|
|
28
|
+
return value.code;
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
function wrapUnknownError(value, rpcPath) {
|
|
33
|
+
if (isProtoClientError(value)) {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
if (value instanceof Error && value.name === 'AbortError') {
|
|
37
|
+
return new ProtoClientError({
|
|
38
|
+
code: 'ABORTED',
|
|
39
|
+
message: 'Request was aborted',
|
|
40
|
+
rpcPath,
|
|
41
|
+
cause: value,
|
|
42
|
+
retryable: false
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const message = value instanceof Error ? value.message : 'Unexpected client failure';
|
|
46
|
+
return new ProtoClientError({
|
|
47
|
+
code: 'INTERNAL',
|
|
48
|
+
message,
|
|
49
|
+
rpcPath,
|
|
50
|
+
cause: value,
|
|
51
|
+
retryable: false
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ProtoClientError","Error","constructor","options","message","name","code","status","rpcPath","cause","retryable","Object","setPrototypeOf","new","target","prototype","exports","isProtoClientError","value","getErrorCode","undefined","wrapUnknownError"],"sourceRoot":"../../src","sources":["errors.ts"],"mappings":";;;;;;;;;AAsBO,MAAMA,gBAAgB,SAASC,KAAK,CAAC;EAO1CC,WAAWA,CAACC,OAAgC,EAAE;IAC5C,KAAK,CAACA,OAAO,CAACC,OAAO,CAAC;IACtB,IAAI,CAACC,IAAI,GAAG,kBAAkB;IAC9B,IAAI,CAACC,IAAI,GAAGH,OAAO,CAACG,IAAI;IACxB,IAAI,CAACC,MAAM,GAAGJ,OAAO,CAACI,MAAM;IAC5B,IAAI,CAACC,OAAO,GAAGL,OAAO,CAACK,OAAO;I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6
|
+
exports.createApi = createApi;
|
|
7
|
+
Object.defineProperty(exports, "defaultCodecs", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _messages.defaultCodecs;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "methodMap", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _methodMap.methodMap;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
var _clientFactory = require("../client-factory");
|
|
20
|
+
var _methodMap = require("./method-map");
|
|
21
|
+
var _messages = require("./messages");
|
|
22
|
+
/**
|
|
23
|
+
* Auto-generated typed API factory. Do not edit by hand.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
function createApi(config) {
|
|
27
|
+
return (0, _clientFactory.createClientFromMap)(config, _methodMap.methodMap, _messages.defaultCodecs);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=create-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_clientFactory","require","_methodMap","_messages","createApi","config","createClientFromMap","methodMap","defaultCodecs"],"sourceRoot":"../../../src","sources":["generated/create-api.ts"],"mappings":";;;;;;;;;;;;;;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AANA;AACA;AACA;;AAiCO,SAASG,SAASA,CAACC,MAAyB,EAAgB;EACjE,OAAO,IAAAC,kCAAmB,EAACD,MAAM,EAAEE,oBAAS,EAAEC,uBAAa,CAAC;AAC9D","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["generated/message-types.ts"],"mappings":"","ignoreList":[]}
|