@yorun-ai/vrpc 0.9.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.
- package/CONTRIBUTING.md +82 -0
- package/LICENSE +201 -0
- package/README.md +232 -0
- package/README.zh-CN.md +231 -0
- package/dist/client.cjs +462 -0
- package/dist/client.d.cts +247 -0
- package/dist/client.d.ts +247 -0
- package/dist/client.es.js +442 -0
- package/dist/http.cjs +69 -0
- package/dist/http.d.cts +100 -0
- package/dist/http.d.ts +100 -0
- package/dist/http.es.js +64 -0
- package/dist/request-options-2HZzkj4w.cjs +353 -0
- package/dist/request-options-disym648.js +288 -0
- package/docs/guides/axios.md +115 -0
- package/docs/guides/usage.md +259 -0
- package/docs/maintainers/architecture.md +47 -0
- package/docs/maintainers/protocol.md +135 -0
- package/docs/maintainers/releasing.md +92 -0
- package/package.json +65 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
//#region src/contracts/types.d.ts
|
|
2
|
+
type HttpRequestInit = Omit<RequestInit, "method" | "body" | "headers">;
|
|
3
|
+
type HttpQueryPrimitive = string | number | boolean;
|
|
4
|
+
type HttpQueryValue = HttpQueryPrimitive | HttpQueryPrimitive[] | null | undefined;
|
|
5
|
+
type HttpQueryParams = Record<string, HttpQueryValue>;
|
|
6
|
+
type HttpRequestOptions = {
|
|
7
|
+
headers?: HeadersInit;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
requestInit?: HttpRequestInit;
|
|
10
|
+
suppressGlobalToast?: boolean;
|
|
11
|
+
};
|
|
12
|
+
type HttpRequestConfig = {
|
|
13
|
+
path: string;
|
|
14
|
+
method?: string;
|
|
15
|
+
query?: HttpQueryParams | URLSearchParams;
|
|
16
|
+
json?: unknown;
|
|
17
|
+
body?: BodyInit | null;
|
|
18
|
+
options?: HttpRequestOptions;
|
|
19
|
+
};
|
|
20
|
+
type HttpClientOptions = HttpRequestOptions & {
|
|
21
|
+
prefixUrl: string | URL;
|
|
22
|
+
fetchImpl?: typeof fetch;
|
|
23
|
+
transport?: HttpTransport;
|
|
24
|
+
interceptors?: HttpInterceptor[];
|
|
25
|
+
};
|
|
26
|
+
type HttpInvokeContext = {
|
|
27
|
+
url: string;
|
|
28
|
+
init: RequestInit;
|
|
29
|
+
request: HttpRequestConfig;
|
|
30
|
+
options: HttpRequestOptions;
|
|
31
|
+
};
|
|
32
|
+
type HttpInterceptor = {
|
|
33
|
+
beforeRequest?: (context: HttpInvokeContext) => void | Promise<void>;
|
|
34
|
+
afterResponse?: (response: Response, context: HttpInvokeContext) => void | Promise<void>;
|
|
35
|
+
onError?: (error: unknown, context: HttpInvokeContext) => void | Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
type HttpTransportRequest = {
|
|
38
|
+
url: string;
|
|
39
|
+
init: RequestInit;
|
|
40
|
+
method: string;
|
|
41
|
+
headers: HeadersInit;
|
|
42
|
+
body?: BodyInit | null;
|
|
43
|
+
timeoutMs?: number;
|
|
44
|
+
signal?: AbortSignal | null;
|
|
45
|
+
};
|
|
46
|
+
type HttpTransportResponse = {
|
|
47
|
+
status: number;
|
|
48
|
+
statusText?: string;
|
|
49
|
+
headers: Headers;
|
|
50
|
+
body: Uint8Array | null;
|
|
51
|
+
url: string;
|
|
52
|
+
};
|
|
53
|
+
type HttpTransport = {
|
|
54
|
+
request: (request: HttpTransportRequest) => Promise<HttpTransportResponse>;
|
|
55
|
+
close?: () => Promise<void> | void;
|
|
56
|
+
};
|
|
57
|
+
type HttpClient = {
|
|
58
|
+
request: <TResponse = unknown>(request: HttpRequestConfig) => Promise<TResponse>;
|
|
59
|
+
use: (interceptor: HttpInterceptor) => void;
|
|
60
|
+
};
|
|
61
|
+
type VrpcClientInfo = {
|
|
62
|
+
clientName: string;
|
|
63
|
+
clientVersion: string;
|
|
64
|
+
clientInstanceId: string;
|
|
65
|
+
};
|
|
66
|
+
type VrpcTrace = {
|
|
67
|
+
id: string;
|
|
68
|
+
span?: string;
|
|
69
|
+
};
|
|
70
|
+
type VrpcTraceMode = "portal" | "direct";
|
|
71
|
+
type GetClientInstanceIdOptions = {
|
|
72
|
+
key?: string;
|
|
73
|
+
};
|
|
74
|
+
type VrpcWireSchema = {
|
|
75
|
+
kind: "value";
|
|
76
|
+
nullable?: boolean;
|
|
77
|
+
} | {
|
|
78
|
+
kind: "binary";
|
|
79
|
+
nullable?: boolean;
|
|
80
|
+
} | {
|
|
81
|
+
kind: "list";
|
|
82
|
+
value: VrpcWireSchema;
|
|
83
|
+
nullable?: boolean;
|
|
84
|
+
} | {
|
|
85
|
+
kind: "map";
|
|
86
|
+
key: "int" | "string";
|
|
87
|
+
value: VrpcWireSchema;
|
|
88
|
+
nullable?: boolean;
|
|
89
|
+
} | {
|
|
90
|
+
kind: "object";
|
|
91
|
+
fields: Readonly<Record<string, VrpcWireSchema>> | (() => Readonly<Record<string, VrpcWireSchema>>);
|
|
92
|
+
nullable?: boolean;
|
|
93
|
+
};
|
|
94
|
+
type VrpcMethodWireSpec = {
|
|
95
|
+
arguments?: VrpcWireSchema;
|
|
96
|
+
result?: VrpcWireSchema;
|
|
97
|
+
};
|
|
98
|
+
type VrpcCborCodec = {
|
|
99
|
+
encode: (value: unknown) => Uint8Array | Promise<Uint8Array>;
|
|
100
|
+
decode: (bytes: Uint8Array) => unknown | Promise<unknown>;
|
|
101
|
+
};
|
|
102
|
+
type VrpcResponseLike = {
|
|
103
|
+
status: number;
|
|
104
|
+
statusText?: string;
|
|
105
|
+
headers?: Headers | HeadersInit | Record<string, unknown> | null;
|
|
106
|
+
url?: string;
|
|
107
|
+
method?: string;
|
|
108
|
+
};
|
|
109
|
+
type ParsedVrpcSuccessResponse<TResponse = unknown> = {
|
|
110
|
+
ok: true;
|
|
111
|
+
status: number;
|
|
112
|
+
statusText: string;
|
|
113
|
+
vrpcStatus: "OK";
|
|
114
|
+
headers: Headers;
|
|
115
|
+
url: string;
|
|
116
|
+
method: string;
|
|
117
|
+
payload: unknown;
|
|
118
|
+
result: TResponse;
|
|
119
|
+
error: null;
|
|
120
|
+
};
|
|
121
|
+
type ParsedVrpcErrorResponse = {
|
|
122
|
+
ok: false;
|
|
123
|
+
status: number;
|
|
124
|
+
statusText: string;
|
|
125
|
+
vrpcStatus: string | null;
|
|
126
|
+
headers: Headers;
|
|
127
|
+
url: string;
|
|
128
|
+
method: string;
|
|
129
|
+
payload: unknown;
|
|
130
|
+
result: unknown;
|
|
131
|
+
error: unknown;
|
|
132
|
+
};
|
|
133
|
+
type ParsedVrpcResponse<TResponse = unknown> = ParsedVrpcSuccessResponse<TResponse> | ParsedVrpcErrorResponse;
|
|
134
|
+
interface VrpcRequestParams {
|
|
135
|
+
[key: string]: unknown;
|
|
136
|
+
}
|
|
137
|
+
type VrpcRequestInit = HttpRequestInit;
|
|
138
|
+
interface VrpcRequestOptions extends HttpRequestOptions {
|
|
139
|
+
trace?: VrpcTrace;
|
|
140
|
+
wire?: VrpcMethodWireSpec;
|
|
141
|
+
}
|
|
142
|
+
type VrpcClientOptions = Omit<HttpClientOptions, "interceptors" | "transport"> & {
|
|
143
|
+
clientInfo: VrpcClientInfo;
|
|
144
|
+
traceMode?: VrpcTraceMode;
|
|
145
|
+
cborCodec?: VrpcCborCodec;
|
|
146
|
+
transport?: VrpcTransport;
|
|
147
|
+
interceptors?: VrpcInterceptor[];
|
|
148
|
+
};
|
|
149
|
+
interface VrpcInvokeRequest {
|
|
150
|
+
serviceName: string;
|
|
151
|
+
methodName: string;
|
|
152
|
+
params: VrpcRequestParams | null;
|
|
153
|
+
options?: VrpcRequestOptions;
|
|
154
|
+
}
|
|
155
|
+
type VrpcInvokeContext = {
|
|
156
|
+
url: string;
|
|
157
|
+
init: RequestInit;
|
|
158
|
+
request: VrpcInvokeRequest;
|
|
159
|
+
options: VrpcRequestOptions;
|
|
160
|
+
};
|
|
161
|
+
type VrpcInterceptor = {
|
|
162
|
+
beforeRequest?: (context: VrpcInvokeContext) => void | Promise<void>;
|
|
163
|
+
afterResponse?: (response: Response, context: VrpcInvokeContext) => void | Promise<void>;
|
|
164
|
+
onError?: (error: unknown, context: VrpcInvokeContext) => void | Promise<void>;
|
|
165
|
+
};
|
|
166
|
+
type VrpcInterceptors = VrpcInterceptor;
|
|
167
|
+
type VrpcTransportRequest = HttpTransportRequest;
|
|
168
|
+
type VrpcTransportResponse = HttpTransportResponse;
|
|
169
|
+
type VrpcTransport = HttpTransport;
|
|
170
|
+
interface VrpcClient {
|
|
171
|
+
invoke: <TResponse = unknown>(request: VrpcInvokeRequest) => Promise<TResponse>;
|
|
172
|
+
use: (interceptor: VrpcInterceptor) => void;
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/contracts/errors.d.ts
|
|
176
|
+
type HttpErrorPayload = {
|
|
177
|
+
type?: string;
|
|
178
|
+
code?: string;
|
|
179
|
+
message?: string;
|
|
180
|
+
reason?: string;
|
|
181
|
+
detail?: string;
|
|
182
|
+
};
|
|
183
|
+
type HttpErrorRequestMeta = {
|
|
184
|
+
url?: string;
|
|
185
|
+
method?: string;
|
|
186
|
+
};
|
|
187
|
+
declare const HTTP_TIMEOUT_ERROR_CODE: "HTTP_TIMEOUT";
|
|
188
|
+
declare class HttpTimeoutError extends Error {
|
|
189
|
+
code: typeof HTTP_TIMEOUT_ERROR_CODE;
|
|
190
|
+
timeoutMs: number;
|
|
191
|
+
constructor(timeoutMs: number);
|
|
192
|
+
}
|
|
193
|
+
declare class HttpInvokeError extends Error {
|
|
194
|
+
type?: string;
|
|
195
|
+
code?: string;
|
|
196
|
+
reason?: string;
|
|
197
|
+
detail?: string;
|
|
198
|
+
status: number;
|
|
199
|
+
statusText: string;
|
|
200
|
+
responseHeaders: Headers;
|
|
201
|
+
payload: unknown;
|
|
202
|
+
url: string;
|
|
203
|
+
method: string;
|
|
204
|
+
constructor(response: Response, payload: unknown, requestMeta?: HttpErrorRequestMeta);
|
|
205
|
+
}
|
|
206
|
+
type VrpcErrorPayload = HttpErrorPayload;
|
|
207
|
+
declare class VrpcInvokeError extends HttpInvokeError {
|
|
208
|
+
vrpcStatus: string | null;
|
|
209
|
+
constructor(response: Response, payload: unknown, requestMeta?: HttpErrorRequestMeta);
|
|
210
|
+
}
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region src/protocol/id.d.ts
|
|
213
|
+
declare const DEFAULT_CLIENT_INSTANCE_ID_STORAGE_KEY = "vrpc-client-instance-id";
|
|
214
|
+
declare function generateVrpcId(): string;
|
|
215
|
+
declare function generateVrpcSpan(): string;
|
|
216
|
+
declare function generateClientInstanceId(): string;
|
|
217
|
+
declare function getClientInstanceId({ key }?: GetClientInstanceIdOptions): string;
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/protocol/headers.d.ts
|
|
220
|
+
declare const VRPC_JSON_CONTENT_TYPE = "application/vrpc+json";
|
|
221
|
+
declare const VRPC_CBOR_CONTENT_TYPE = "application/vrpc+cbor";
|
|
222
|
+
type BuildVrpcHeadersOptions = {
|
|
223
|
+
clientInfo: VrpcClientInfo;
|
|
224
|
+
trace: VrpcTrace;
|
|
225
|
+
timeoutMs?: number;
|
|
226
|
+
requestUsesCbor?: boolean;
|
|
227
|
+
responseUsesCbor?: boolean;
|
|
228
|
+
};
|
|
229
|
+
declare function buildVrpcHeaders({ clientInfo, trace, timeoutMs, requestUsesCbor, responseUsesCbor }: BuildVrpcHeadersOptions): Headers;
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/protocol/request.d.ts
|
|
232
|
+
declare function buildVrpcPath(serviceName: string, methodName: string): string;
|
|
233
|
+
declare function buildVrpcRequestBody(params: VrpcRequestParams | null | undefined): string;
|
|
234
|
+
declare function encodeVrpcRequestBody(params: VrpcRequestParams | null, schema: VrpcWireSchema | undefined, cborCodec: VrpcCborCodec | undefined): Promise<string | ArrayBuffer>;
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/protocol/response.d.ts
|
|
237
|
+
declare function decodeVrpcResponsePayload(response: Response, cborCodec: VrpcCborCodec | undefined, resultSchema: VrpcWireSchema | undefined): Promise<any>;
|
|
238
|
+
declare function parseVrpcResponse<TResponse = unknown>(responseLike: VrpcResponseLike, payload: unknown): ParsedVrpcResponse<TResponse>;
|
|
239
|
+
declare function unwrapVrpcResponse<TResponse = unknown>(responseLike: VrpcResponseLike, payload: unknown): TResponse;
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/core/create-vrpc-client.d.ts
|
|
242
|
+
declare function createVrpcClient(options: VrpcClientOptions): VrpcClient;
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/transports/fetch-transport.d.ts
|
|
245
|
+
declare function createFetchTransport(fetchImpl?: typeof fetch): HttpTransport;
|
|
246
|
+
//#endregion
|
|
247
|
+
export { type BuildVrpcHeadersOptions, DEFAULT_CLIENT_INSTANCE_ID_STORAGE_KEY, type GetClientInstanceIdOptions, HTTP_TIMEOUT_ERROR_CODE, type HttpClient, type HttpClientOptions, type HttpErrorPayload, type HttpInterceptor, type HttpInvokeContext, HttpInvokeError, type HttpQueryParams, type HttpQueryPrimitive, type HttpQueryValue, type HttpRequestConfig, type HttpRequestInit, type HttpRequestOptions, HttpTimeoutError, type HttpTransport, type HttpTransportRequest, type HttpTransportResponse, type ParsedVrpcErrorResponse, type ParsedVrpcResponse, type ParsedVrpcSuccessResponse, VRPC_CBOR_CONTENT_TYPE, VRPC_JSON_CONTENT_TYPE, type VrpcCborCodec, type VrpcClient, type VrpcClientInfo, type VrpcClientOptions, type VrpcErrorPayload, type VrpcInterceptor, type VrpcInterceptors, type VrpcInvokeContext, VrpcInvokeError, type VrpcInvokeRequest, type VrpcMethodWireSpec, type VrpcRequestInit, type VrpcRequestOptions, type VrpcResponseLike, type VrpcTrace, type VrpcTraceMode, type VrpcTransport, type VrpcTransportRequest, type VrpcTransportResponse, type VrpcWireSchema, buildVrpcHeaders, buildVrpcPath, buildVrpcRequestBody, createFetchTransport, createVrpcClient, decodeVrpcResponsePayload, encodeVrpcRequestBody, generateClientInstanceId, generateVrpcId, generateVrpcSpan, getClientInstanceId, parseVrpcResponse, unwrapVrpcResponse };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
//#region src/contracts/types.d.ts
|
|
2
|
+
type HttpRequestInit = Omit<RequestInit, "method" | "body" | "headers">;
|
|
3
|
+
type HttpQueryPrimitive = string | number | boolean;
|
|
4
|
+
type HttpQueryValue = HttpQueryPrimitive | HttpQueryPrimitive[] | null | undefined;
|
|
5
|
+
type HttpQueryParams = Record<string, HttpQueryValue>;
|
|
6
|
+
type HttpRequestOptions = {
|
|
7
|
+
headers?: HeadersInit;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
requestInit?: HttpRequestInit;
|
|
10
|
+
suppressGlobalToast?: boolean;
|
|
11
|
+
};
|
|
12
|
+
type HttpRequestConfig = {
|
|
13
|
+
path: string;
|
|
14
|
+
method?: string;
|
|
15
|
+
query?: HttpQueryParams | URLSearchParams;
|
|
16
|
+
json?: unknown;
|
|
17
|
+
body?: BodyInit | null;
|
|
18
|
+
options?: HttpRequestOptions;
|
|
19
|
+
};
|
|
20
|
+
type HttpClientOptions = HttpRequestOptions & {
|
|
21
|
+
prefixUrl: string | URL;
|
|
22
|
+
fetchImpl?: typeof fetch;
|
|
23
|
+
transport?: HttpTransport;
|
|
24
|
+
interceptors?: HttpInterceptor[];
|
|
25
|
+
};
|
|
26
|
+
type HttpInvokeContext = {
|
|
27
|
+
url: string;
|
|
28
|
+
init: RequestInit;
|
|
29
|
+
request: HttpRequestConfig;
|
|
30
|
+
options: HttpRequestOptions;
|
|
31
|
+
};
|
|
32
|
+
type HttpInterceptor = {
|
|
33
|
+
beforeRequest?: (context: HttpInvokeContext) => void | Promise<void>;
|
|
34
|
+
afterResponse?: (response: Response, context: HttpInvokeContext) => void | Promise<void>;
|
|
35
|
+
onError?: (error: unknown, context: HttpInvokeContext) => void | Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
type HttpTransportRequest = {
|
|
38
|
+
url: string;
|
|
39
|
+
init: RequestInit;
|
|
40
|
+
method: string;
|
|
41
|
+
headers: HeadersInit;
|
|
42
|
+
body?: BodyInit | null;
|
|
43
|
+
timeoutMs?: number;
|
|
44
|
+
signal?: AbortSignal | null;
|
|
45
|
+
};
|
|
46
|
+
type HttpTransportResponse = {
|
|
47
|
+
status: number;
|
|
48
|
+
statusText?: string;
|
|
49
|
+
headers: Headers;
|
|
50
|
+
body: Uint8Array | null;
|
|
51
|
+
url: string;
|
|
52
|
+
};
|
|
53
|
+
type HttpTransport = {
|
|
54
|
+
request: (request: HttpTransportRequest) => Promise<HttpTransportResponse>;
|
|
55
|
+
close?: () => Promise<void> | void;
|
|
56
|
+
};
|
|
57
|
+
type HttpClient = {
|
|
58
|
+
request: <TResponse = unknown>(request: HttpRequestConfig) => Promise<TResponse>;
|
|
59
|
+
use: (interceptor: HttpInterceptor) => void;
|
|
60
|
+
};
|
|
61
|
+
type VrpcClientInfo = {
|
|
62
|
+
clientName: string;
|
|
63
|
+
clientVersion: string;
|
|
64
|
+
clientInstanceId: string;
|
|
65
|
+
};
|
|
66
|
+
type VrpcTrace = {
|
|
67
|
+
id: string;
|
|
68
|
+
span?: string;
|
|
69
|
+
};
|
|
70
|
+
type VrpcTraceMode = "portal" | "direct";
|
|
71
|
+
type GetClientInstanceIdOptions = {
|
|
72
|
+
key?: string;
|
|
73
|
+
};
|
|
74
|
+
type VrpcWireSchema = {
|
|
75
|
+
kind: "value";
|
|
76
|
+
nullable?: boolean;
|
|
77
|
+
} | {
|
|
78
|
+
kind: "binary";
|
|
79
|
+
nullable?: boolean;
|
|
80
|
+
} | {
|
|
81
|
+
kind: "list";
|
|
82
|
+
value: VrpcWireSchema;
|
|
83
|
+
nullable?: boolean;
|
|
84
|
+
} | {
|
|
85
|
+
kind: "map";
|
|
86
|
+
key: "int" | "string";
|
|
87
|
+
value: VrpcWireSchema;
|
|
88
|
+
nullable?: boolean;
|
|
89
|
+
} | {
|
|
90
|
+
kind: "object";
|
|
91
|
+
fields: Readonly<Record<string, VrpcWireSchema>> | (() => Readonly<Record<string, VrpcWireSchema>>);
|
|
92
|
+
nullable?: boolean;
|
|
93
|
+
};
|
|
94
|
+
type VrpcMethodWireSpec = {
|
|
95
|
+
arguments?: VrpcWireSchema;
|
|
96
|
+
result?: VrpcWireSchema;
|
|
97
|
+
};
|
|
98
|
+
type VrpcCborCodec = {
|
|
99
|
+
encode: (value: unknown) => Uint8Array | Promise<Uint8Array>;
|
|
100
|
+
decode: (bytes: Uint8Array) => unknown | Promise<unknown>;
|
|
101
|
+
};
|
|
102
|
+
type VrpcResponseLike = {
|
|
103
|
+
status: number;
|
|
104
|
+
statusText?: string;
|
|
105
|
+
headers?: Headers | HeadersInit | Record<string, unknown> | null;
|
|
106
|
+
url?: string;
|
|
107
|
+
method?: string;
|
|
108
|
+
};
|
|
109
|
+
type ParsedVrpcSuccessResponse<TResponse = unknown> = {
|
|
110
|
+
ok: true;
|
|
111
|
+
status: number;
|
|
112
|
+
statusText: string;
|
|
113
|
+
vrpcStatus: "OK";
|
|
114
|
+
headers: Headers;
|
|
115
|
+
url: string;
|
|
116
|
+
method: string;
|
|
117
|
+
payload: unknown;
|
|
118
|
+
result: TResponse;
|
|
119
|
+
error: null;
|
|
120
|
+
};
|
|
121
|
+
type ParsedVrpcErrorResponse = {
|
|
122
|
+
ok: false;
|
|
123
|
+
status: number;
|
|
124
|
+
statusText: string;
|
|
125
|
+
vrpcStatus: string | null;
|
|
126
|
+
headers: Headers;
|
|
127
|
+
url: string;
|
|
128
|
+
method: string;
|
|
129
|
+
payload: unknown;
|
|
130
|
+
result: unknown;
|
|
131
|
+
error: unknown;
|
|
132
|
+
};
|
|
133
|
+
type ParsedVrpcResponse<TResponse = unknown> = ParsedVrpcSuccessResponse<TResponse> | ParsedVrpcErrorResponse;
|
|
134
|
+
interface VrpcRequestParams {
|
|
135
|
+
[key: string]: unknown;
|
|
136
|
+
}
|
|
137
|
+
type VrpcRequestInit = HttpRequestInit;
|
|
138
|
+
interface VrpcRequestOptions extends HttpRequestOptions {
|
|
139
|
+
trace?: VrpcTrace;
|
|
140
|
+
wire?: VrpcMethodWireSpec;
|
|
141
|
+
}
|
|
142
|
+
type VrpcClientOptions = Omit<HttpClientOptions, "interceptors" | "transport"> & {
|
|
143
|
+
clientInfo: VrpcClientInfo;
|
|
144
|
+
traceMode?: VrpcTraceMode;
|
|
145
|
+
cborCodec?: VrpcCborCodec;
|
|
146
|
+
transport?: VrpcTransport;
|
|
147
|
+
interceptors?: VrpcInterceptor[];
|
|
148
|
+
};
|
|
149
|
+
interface VrpcInvokeRequest {
|
|
150
|
+
serviceName: string;
|
|
151
|
+
methodName: string;
|
|
152
|
+
params: VrpcRequestParams | null;
|
|
153
|
+
options?: VrpcRequestOptions;
|
|
154
|
+
}
|
|
155
|
+
type VrpcInvokeContext = {
|
|
156
|
+
url: string;
|
|
157
|
+
init: RequestInit;
|
|
158
|
+
request: VrpcInvokeRequest;
|
|
159
|
+
options: VrpcRequestOptions;
|
|
160
|
+
};
|
|
161
|
+
type VrpcInterceptor = {
|
|
162
|
+
beforeRequest?: (context: VrpcInvokeContext) => void | Promise<void>;
|
|
163
|
+
afterResponse?: (response: Response, context: VrpcInvokeContext) => void | Promise<void>;
|
|
164
|
+
onError?: (error: unknown, context: VrpcInvokeContext) => void | Promise<void>;
|
|
165
|
+
};
|
|
166
|
+
type VrpcInterceptors = VrpcInterceptor;
|
|
167
|
+
type VrpcTransportRequest = HttpTransportRequest;
|
|
168
|
+
type VrpcTransportResponse = HttpTransportResponse;
|
|
169
|
+
type VrpcTransport = HttpTransport;
|
|
170
|
+
interface VrpcClient {
|
|
171
|
+
invoke: <TResponse = unknown>(request: VrpcInvokeRequest) => Promise<TResponse>;
|
|
172
|
+
use: (interceptor: VrpcInterceptor) => void;
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/contracts/errors.d.ts
|
|
176
|
+
type HttpErrorPayload = {
|
|
177
|
+
type?: string;
|
|
178
|
+
code?: string;
|
|
179
|
+
message?: string;
|
|
180
|
+
reason?: string;
|
|
181
|
+
detail?: string;
|
|
182
|
+
};
|
|
183
|
+
type HttpErrorRequestMeta = {
|
|
184
|
+
url?: string;
|
|
185
|
+
method?: string;
|
|
186
|
+
};
|
|
187
|
+
declare const HTTP_TIMEOUT_ERROR_CODE: "HTTP_TIMEOUT";
|
|
188
|
+
declare class HttpTimeoutError extends Error {
|
|
189
|
+
code: typeof HTTP_TIMEOUT_ERROR_CODE;
|
|
190
|
+
timeoutMs: number;
|
|
191
|
+
constructor(timeoutMs: number);
|
|
192
|
+
}
|
|
193
|
+
declare class HttpInvokeError extends Error {
|
|
194
|
+
type?: string;
|
|
195
|
+
code?: string;
|
|
196
|
+
reason?: string;
|
|
197
|
+
detail?: string;
|
|
198
|
+
status: number;
|
|
199
|
+
statusText: string;
|
|
200
|
+
responseHeaders: Headers;
|
|
201
|
+
payload: unknown;
|
|
202
|
+
url: string;
|
|
203
|
+
method: string;
|
|
204
|
+
constructor(response: Response, payload: unknown, requestMeta?: HttpErrorRequestMeta);
|
|
205
|
+
}
|
|
206
|
+
type VrpcErrorPayload = HttpErrorPayload;
|
|
207
|
+
declare class VrpcInvokeError extends HttpInvokeError {
|
|
208
|
+
vrpcStatus: string | null;
|
|
209
|
+
constructor(response: Response, payload: unknown, requestMeta?: HttpErrorRequestMeta);
|
|
210
|
+
}
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region src/protocol/id.d.ts
|
|
213
|
+
declare const DEFAULT_CLIENT_INSTANCE_ID_STORAGE_KEY = "vrpc-client-instance-id";
|
|
214
|
+
declare function generateVrpcId(): string;
|
|
215
|
+
declare function generateVrpcSpan(): string;
|
|
216
|
+
declare function generateClientInstanceId(): string;
|
|
217
|
+
declare function getClientInstanceId({ key }?: GetClientInstanceIdOptions): string;
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/protocol/headers.d.ts
|
|
220
|
+
declare const VRPC_JSON_CONTENT_TYPE = "application/vrpc+json";
|
|
221
|
+
declare const VRPC_CBOR_CONTENT_TYPE = "application/vrpc+cbor";
|
|
222
|
+
type BuildVrpcHeadersOptions = {
|
|
223
|
+
clientInfo: VrpcClientInfo;
|
|
224
|
+
trace: VrpcTrace;
|
|
225
|
+
timeoutMs?: number;
|
|
226
|
+
requestUsesCbor?: boolean;
|
|
227
|
+
responseUsesCbor?: boolean;
|
|
228
|
+
};
|
|
229
|
+
declare function buildVrpcHeaders({ clientInfo, trace, timeoutMs, requestUsesCbor, responseUsesCbor }: BuildVrpcHeadersOptions): Headers;
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/protocol/request.d.ts
|
|
232
|
+
declare function buildVrpcPath(serviceName: string, methodName: string): string;
|
|
233
|
+
declare function buildVrpcRequestBody(params: VrpcRequestParams | null | undefined): string;
|
|
234
|
+
declare function encodeVrpcRequestBody(params: VrpcRequestParams | null, schema: VrpcWireSchema | undefined, cborCodec: VrpcCborCodec | undefined): Promise<string | ArrayBuffer>;
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/protocol/response.d.ts
|
|
237
|
+
declare function decodeVrpcResponsePayload(response: Response, cborCodec: VrpcCborCodec | undefined, resultSchema: VrpcWireSchema | undefined): Promise<any>;
|
|
238
|
+
declare function parseVrpcResponse<TResponse = unknown>(responseLike: VrpcResponseLike, payload: unknown): ParsedVrpcResponse<TResponse>;
|
|
239
|
+
declare function unwrapVrpcResponse<TResponse = unknown>(responseLike: VrpcResponseLike, payload: unknown): TResponse;
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/core/create-vrpc-client.d.ts
|
|
242
|
+
declare function createVrpcClient(options: VrpcClientOptions): VrpcClient;
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/transports/fetch-transport.d.ts
|
|
245
|
+
declare function createFetchTransport(fetchImpl?: typeof fetch): HttpTransport;
|
|
246
|
+
//#endregion
|
|
247
|
+
export { type BuildVrpcHeadersOptions, DEFAULT_CLIENT_INSTANCE_ID_STORAGE_KEY, type GetClientInstanceIdOptions, HTTP_TIMEOUT_ERROR_CODE, type HttpClient, type HttpClientOptions, type HttpErrorPayload, type HttpInterceptor, type HttpInvokeContext, HttpInvokeError, type HttpQueryParams, type HttpQueryPrimitive, type HttpQueryValue, type HttpRequestConfig, type HttpRequestInit, type HttpRequestOptions, HttpTimeoutError, type HttpTransport, type HttpTransportRequest, type HttpTransportResponse, type ParsedVrpcErrorResponse, type ParsedVrpcResponse, type ParsedVrpcSuccessResponse, VRPC_CBOR_CONTENT_TYPE, VRPC_JSON_CONTENT_TYPE, type VrpcCborCodec, type VrpcClient, type VrpcClientInfo, type VrpcClientOptions, type VrpcErrorPayload, type VrpcInterceptor, type VrpcInterceptors, type VrpcInvokeContext, VrpcInvokeError, type VrpcInvokeRequest, type VrpcMethodWireSpec, type VrpcRequestInit, type VrpcRequestOptions, type VrpcResponseLike, type VrpcTrace, type VrpcTraceMode, type VrpcTransport, type VrpcTransportRequest, type VrpcTransportResponse, type VrpcWireSchema, buildVrpcHeaders, buildVrpcPath, buildVrpcRequestBody, createFetchTransport, createVrpcClient, decodeVrpcResponsePayload, encodeVrpcRequestBody, generateClientInstanceId, generateVrpcId, generateVrpcSpan, getClientInstanceId, parseVrpcResponse, unwrapVrpcResponse };
|