@orpc/client 0.0.0-next.954e6e2 → 0.0.0-next.96f9dd3
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/README.md +14 -1
- package/dist/adapters/fetch/index.d.mts +10 -15
- package/dist/adapters/fetch/index.d.ts +10 -15
- package/dist/adapters/fetch/index.mjs +11 -13
- package/dist/adapters/standard/index.d.mts +8 -147
- package/dist/adapters/standard/index.d.ts +8 -147
- package/dist/adapters/standard/index.mjs +2 -2
- package/dist/index.d.mts +22 -20
- package/dist/index.d.ts +22 -20
- package/dist/index.mjs +35 -33
- package/dist/plugins/index.d.mts +112 -0
- package/dist/plugins/index.d.ts +112 -0
- package/dist/plugins/index.mjs +256 -0
- package/dist/shared/{client.Ch8Gzz9n.mjs → client.BhQShZ_Q.mjs} +158 -142
- package/dist/shared/client.C7z5zk4v.d.mts +40 -0
- package/dist/shared/client.CDvsX60w.d.ts +87 -0
- package/dist/shared/client.CRWEpqLB.mjs +175 -0
- package/dist/shared/client.CUq1_W_X.d.mts +87 -0
- package/dist/shared/client.CipPQkhk.d.mts +29 -0
- package/dist/shared/client.CipPQkhk.d.ts +29 -0
- package/dist/shared/client.p3ON_yzu.d.ts +40 -0
- package/package.json +10 -5
- package/dist/shared/client.D_CzLDyB.d.mts +0 -42
- package/dist/shared/client.D_CzLDyB.d.ts +0 -42
- package/dist/shared/client.DcaJQZfy.mjs +0 -265
|
@@ -1,106 +1,107 @@
|
|
|
1
|
-
import { intercept,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { toArray, intercept, isObject, value, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
|
|
2
|
+
import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
|
|
3
|
+
import { C as COMMON_ORPC_ERROR_DEFS, b as isORPCErrorStatus, c as isORPCErrorJson, d as createORPCErrorFromJson, O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.CRWEpqLB.mjs';
|
|
4
4
|
|
|
5
5
|
class InvalidEventIteratorRetryResponse extends Error {
|
|
6
6
|
}
|
|
7
7
|
class StandardLink {
|
|
8
|
-
constructor(codec, sender, options) {
|
|
8
|
+
constructor(codec, sender, options = {}) {
|
|
9
9
|
this.codec = codec;
|
|
10
10
|
this.sender = sender;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.interceptors = options.interceptors
|
|
15
|
-
this.clientInterceptors = options.clientInterceptors
|
|
11
|
+
for (const plugin of toArray(options.plugins)) {
|
|
12
|
+
plugin.init?.(options);
|
|
13
|
+
}
|
|
14
|
+
this.interceptors = toArray(options.interceptors);
|
|
15
|
+
this.clientInterceptors = toArray(options.clientInterceptors);
|
|
16
16
|
}
|
|
17
|
-
eventIteratorMaxRetries;
|
|
18
|
-
eventIteratorRetryDelay;
|
|
19
|
-
eventIteratorShouldRetry;
|
|
20
17
|
interceptors;
|
|
21
18
|
clientInterceptors;
|
|
22
19
|
call(path, input, options) {
|
|
23
|
-
return intercept(this.interceptors, { path, input
|
|
20
|
+
return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
|
|
24
21
|
const output = await this.#call(path2, input2, options2);
|
|
25
|
-
|
|
26
|
-
return output;
|
|
27
|
-
}
|
|
28
|
-
return createAutoRetryEventIterator(output, async (reconnectOptions) => {
|
|
29
|
-
const maxRetries = await value(this.eventIteratorMaxRetries, reconnectOptions, options2, path2, input2);
|
|
30
|
-
if (options2.signal?.aborted || reconnectOptions.retryTimes > maxRetries) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
const shouldRetry = await value(this.eventIteratorShouldRetry, reconnectOptions, options2, path2, input2);
|
|
34
|
-
if (!shouldRetry) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
const retryDelay = await value(this.eventIteratorRetryDelay, reconnectOptions, options2, path2, input2);
|
|
38
|
-
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
39
|
-
const updatedOptions = { ...options2, lastEventId: reconnectOptions.lastEventId };
|
|
40
|
-
const maybeIterator = await this.#call(path2, input2, updatedOptions);
|
|
41
|
-
if (!isAsyncIteratorObject(maybeIterator)) {
|
|
42
|
-
throw new InvalidEventIteratorRetryResponse("Invalid Event Iterator retry response");
|
|
43
|
-
}
|
|
44
|
-
return maybeIterator;
|
|
45
|
-
}, options2.lastEventId);
|
|
22
|
+
return output;
|
|
46
23
|
});
|
|
47
24
|
}
|
|
48
25
|
async #call(path, input, options) {
|
|
49
26
|
const request = await this.codec.encode(path, input, options);
|
|
50
27
|
const response = await intercept(
|
|
51
28
|
this.clientInterceptors,
|
|
52
|
-
{ request },
|
|
53
|
-
({ request: request2 }) => this.sender.call(request2,
|
|
29
|
+
{ ...options, input, path, request },
|
|
30
|
+
({ input: input2, path: path2, request: request2, ...options2 }) => this.sender.call(request2, options2, path2, input2)
|
|
54
31
|
);
|
|
55
32
|
const output = await this.codec.decode(response, options, path, input);
|
|
56
33
|
return output;
|
|
57
34
|
}
|
|
58
35
|
}
|
|
59
36
|
|
|
60
|
-
|
|
37
|
+
const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES = {
|
|
38
|
+
BIGINT: 0,
|
|
39
|
+
DATE: 1,
|
|
40
|
+
NAN: 2,
|
|
41
|
+
UNDEFINED: 3,
|
|
42
|
+
URL: 4,
|
|
43
|
+
REGEXP: 5,
|
|
44
|
+
SET: 6,
|
|
45
|
+
MAP: 7
|
|
46
|
+
};
|
|
47
|
+
class StandardRPCJsonSerializer {
|
|
48
|
+
customSerializers;
|
|
49
|
+
constructor(options = {}) {
|
|
50
|
+
this.customSerializers = options.customJsonSerializers ?? [];
|
|
51
|
+
if (this.customSerializers.length !== new Set(this.customSerializers.map((custom) => custom.type)).size) {
|
|
52
|
+
throw new Error("Custom serializer type must be unique.");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
61
55
|
serialize(data, segments = [], meta = [], maps = [], blobs = []) {
|
|
56
|
+
for (const custom of this.customSerializers) {
|
|
57
|
+
if (custom.condition(data)) {
|
|
58
|
+
const result = this.serialize(custom.serialize(data), segments, meta, maps, blobs);
|
|
59
|
+
meta.push([custom.type, ...segments]);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
62
63
|
if (data instanceof Blob) {
|
|
63
64
|
maps.push(segments);
|
|
64
65
|
blobs.push(data);
|
|
65
66
|
return [data, meta, maps, blobs];
|
|
66
67
|
}
|
|
67
68
|
if (typeof data === "bigint") {
|
|
68
|
-
meta.push([
|
|
69
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT, ...segments]);
|
|
69
70
|
return [data.toString(), meta, maps, blobs];
|
|
70
71
|
}
|
|
71
72
|
if (data instanceof Date) {
|
|
72
|
-
meta.push([
|
|
73
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE, ...segments]);
|
|
73
74
|
if (Number.isNaN(data.getTime())) {
|
|
74
75
|
return [null, meta, maps, blobs];
|
|
75
76
|
}
|
|
76
77
|
return [data.toISOString(), meta, maps, blobs];
|
|
77
78
|
}
|
|
78
79
|
if (Number.isNaN(data)) {
|
|
79
|
-
meta.push([
|
|
80
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN, ...segments]);
|
|
80
81
|
return [null, meta, maps, blobs];
|
|
81
82
|
}
|
|
82
83
|
if (data instanceof URL) {
|
|
83
|
-
meta.push([
|
|
84
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL, ...segments]);
|
|
84
85
|
return [data.toString(), meta, maps, blobs];
|
|
85
86
|
}
|
|
86
87
|
if (data instanceof RegExp) {
|
|
87
|
-
meta.push([
|
|
88
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP, ...segments]);
|
|
88
89
|
return [data.toString(), meta, maps, blobs];
|
|
89
90
|
}
|
|
90
91
|
if (data instanceof Set) {
|
|
91
92
|
const result = this.serialize(Array.from(data), segments, meta, maps, blobs);
|
|
92
|
-
meta.push([
|
|
93
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET, ...segments]);
|
|
93
94
|
return result;
|
|
94
95
|
}
|
|
95
96
|
if (data instanceof Map) {
|
|
96
97
|
const result = this.serialize(Array.from(data.entries()), segments, meta, maps, blobs);
|
|
97
|
-
meta.push([
|
|
98
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP, ...segments]);
|
|
98
99
|
return result;
|
|
99
100
|
}
|
|
100
101
|
if (Array.isArray(data)) {
|
|
101
102
|
const json = data.map((v, i) => {
|
|
102
103
|
if (v === void 0) {
|
|
103
|
-
meta.push([
|
|
104
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED, ...segments, i]);
|
|
104
105
|
return v;
|
|
105
106
|
}
|
|
106
107
|
return this.serialize(v, [...segments, i], meta, maps, blobs)[0];
|
|
@@ -110,6 +111,9 @@ class RPCJsonSerializer {
|
|
|
110
111
|
if (isObject(data)) {
|
|
111
112
|
const json = {};
|
|
112
113
|
for (const k in data) {
|
|
114
|
+
if (k === "toJSON" && typeof data[k] === "function") {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
113
117
|
json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0];
|
|
114
118
|
}
|
|
115
119
|
return [json, meta, maps, blobs];
|
|
@@ -129,38 +133,45 @@ class RPCJsonSerializer {
|
|
|
129
133
|
currentRef[preSegment] = getBlob(i);
|
|
130
134
|
});
|
|
131
135
|
}
|
|
132
|
-
for (const
|
|
136
|
+
for (const item of meta) {
|
|
137
|
+
const type = item[0];
|
|
133
138
|
let currentRef = ref;
|
|
134
139
|
let preSegment = "data";
|
|
135
|
-
|
|
140
|
+
for (let i = 1; i < item.length; i++) {
|
|
136
141
|
currentRef = currentRef[preSegment];
|
|
137
|
-
preSegment =
|
|
138
|
-
}
|
|
142
|
+
preSegment = item[i];
|
|
143
|
+
}
|
|
144
|
+
for (const custom of this.customSerializers) {
|
|
145
|
+
if (custom.type === type) {
|
|
146
|
+
currentRef[preSegment] = custom.deserialize(currentRef[preSegment]);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
139
150
|
switch (type) {
|
|
140
|
-
case
|
|
151
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT:
|
|
141
152
|
currentRef[preSegment] = BigInt(currentRef[preSegment]);
|
|
142
153
|
break;
|
|
143
|
-
case
|
|
154
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE:
|
|
144
155
|
currentRef[preSegment] = new Date(currentRef[preSegment] ?? "Invalid Date");
|
|
145
156
|
break;
|
|
146
|
-
case
|
|
157
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN:
|
|
147
158
|
currentRef[preSegment] = Number.NaN;
|
|
148
159
|
break;
|
|
149
|
-
case
|
|
160
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED:
|
|
150
161
|
currentRef[preSegment] = void 0;
|
|
151
162
|
break;
|
|
152
|
-
case
|
|
163
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL:
|
|
153
164
|
currentRef[preSegment] = new URL(currentRef[preSegment]);
|
|
154
165
|
break;
|
|
155
|
-
case
|
|
166
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP: {
|
|
156
167
|
const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
|
|
157
168
|
currentRef[preSegment] = new RegExp(pattern, flags);
|
|
158
169
|
break;
|
|
159
170
|
}
|
|
160
|
-
case
|
|
171
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET:
|
|
161
172
|
currentRef[preSegment] = new Set(currentRef[preSegment]);
|
|
162
173
|
break;
|
|
163
|
-
case
|
|
174
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP:
|
|
164
175
|
currentRef[preSegment] = new Map(currentRef[preSegment]);
|
|
165
176
|
break;
|
|
166
177
|
}
|
|
@@ -169,8 +180,93 @@ class RPCJsonSerializer {
|
|
|
169
180
|
}
|
|
170
181
|
}
|
|
171
182
|
|
|
172
|
-
|
|
173
|
-
|
|
183
|
+
function toHttpPath(path) {
|
|
184
|
+
return `/${path.map(encodeURIComponent).join("/")}`;
|
|
185
|
+
}
|
|
186
|
+
function getMalformedResponseErrorCode(status) {
|
|
187
|
+
return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE";
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
class StandardRPCLinkCodec {
|
|
191
|
+
constructor(serializer, options) {
|
|
192
|
+
this.serializer = serializer;
|
|
193
|
+
this.baseUrl = options.url;
|
|
194
|
+
this.maxUrlLength = options.maxUrlLength ?? 2083;
|
|
195
|
+
this.fallbackMethod = options.fallbackMethod ?? "POST";
|
|
196
|
+
this.expectedMethod = options.method ?? this.fallbackMethod;
|
|
197
|
+
this.headers = options.headers ?? {};
|
|
198
|
+
}
|
|
199
|
+
baseUrl;
|
|
200
|
+
maxUrlLength;
|
|
201
|
+
fallbackMethod;
|
|
202
|
+
expectedMethod;
|
|
203
|
+
headers;
|
|
204
|
+
async encode(path, input, options) {
|
|
205
|
+
const expectedMethod = await value(this.expectedMethod, options, path, input);
|
|
206
|
+
let headers = await value(this.headers, options, path, input);
|
|
207
|
+
const baseUrl = await value(this.baseUrl, options, path, input);
|
|
208
|
+
const url = new URL(baseUrl);
|
|
209
|
+
url.pathname = `${url.pathname.replace(/\/$/, "")}${toHttpPath(path)}`;
|
|
210
|
+
if (options.lastEventId !== void 0) {
|
|
211
|
+
headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
|
|
212
|
+
}
|
|
213
|
+
const serialized = this.serializer.serialize(input);
|
|
214
|
+
if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
|
|
215
|
+
const maxUrlLength = await value(this.maxUrlLength, options, path, input);
|
|
216
|
+
const getUrl = new URL(url);
|
|
217
|
+
getUrl.searchParams.append("data", stringifyJSON(serialized));
|
|
218
|
+
if (getUrl.toString().length <= maxUrlLength) {
|
|
219
|
+
return {
|
|
220
|
+
body: void 0,
|
|
221
|
+
method: expectedMethod,
|
|
222
|
+
headers,
|
|
223
|
+
url: getUrl,
|
|
224
|
+
signal: options.signal
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
url,
|
|
230
|
+
method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
|
|
231
|
+
headers,
|
|
232
|
+
body: serialized,
|
|
233
|
+
signal: options.signal
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
async decode(response) {
|
|
237
|
+
const isOk = !isORPCErrorStatus(response.status);
|
|
238
|
+
const deserialized = await (async () => {
|
|
239
|
+
let isBodyOk = false;
|
|
240
|
+
try {
|
|
241
|
+
const body = await response.body();
|
|
242
|
+
isBodyOk = true;
|
|
243
|
+
return this.serializer.deserialize(body);
|
|
244
|
+
} catch (error) {
|
|
245
|
+
if (!isBodyOk) {
|
|
246
|
+
throw new Error("Cannot parse response body, please check the response body and content-type.", {
|
|
247
|
+
cause: error
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
throw new Error("Invalid RPC response format.", {
|
|
251
|
+
cause: error
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
})();
|
|
255
|
+
if (!isOk) {
|
|
256
|
+
if (isORPCErrorJson(deserialized)) {
|
|
257
|
+
throw createORPCErrorFromJson(deserialized);
|
|
258
|
+
}
|
|
259
|
+
throw new ORPCError(getMalformedResponseErrorCode(response.status), {
|
|
260
|
+
status: response.status,
|
|
261
|
+
data: { ...response, body: deserialized }
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
return deserialized;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
class StandardRPCSerializer {
|
|
269
|
+
constructor(jsonSerializer) {
|
|
174
270
|
this.jsonSerializer = jsonSerializer;
|
|
175
271
|
}
|
|
176
272
|
serialize(data) {
|
|
@@ -188,9 +284,6 @@ class RPCSerializer {
|
|
|
188
284
|
return this.#serialize(data, true);
|
|
189
285
|
}
|
|
190
286
|
#serialize(data, enableFormData) {
|
|
191
|
-
if (data === void 0 || data instanceof Blob) {
|
|
192
|
-
return data;
|
|
193
|
-
}
|
|
194
287
|
const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data);
|
|
195
288
|
const meta = meta_.length === 0 ? void 0 : meta_;
|
|
196
289
|
if (!enableFormData || blobs.length === 0) {
|
|
@@ -215,8 +308,8 @@ class RPCSerializer {
|
|
|
215
308
|
return e;
|
|
216
309
|
}
|
|
217
310
|
const deserialized = this.#deserialize(e.data);
|
|
218
|
-
if (
|
|
219
|
-
return
|
|
311
|
+
if (isORPCErrorJson(deserialized)) {
|
|
312
|
+
return createORPCErrorFromJson(deserialized, { cause: e });
|
|
220
313
|
}
|
|
221
314
|
return new ErrorEvent({
|
|
222
315
|
data: deserialized,
|
|
@@ -228,9 +321,6 @@ class RPCSerializer {
|
|
|
228
321
|
return this.#deserialize(data);
|
|
229
322
|
}
|
|
230
323
|
#deserialize(data) {
|
|
231
|
-
if (data === void 0 || data instanceof Blob) {
|
|
232
|
-
return data;
|
|
233
|
-
}
|
|
234
324
|
if (!(data instanceof FormData)) {
|
|
235
325
|
return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
|
|
236
326
|
}
|
|
@@ -244,78 +334,4 @@ class RPCSerializer {
|
|
|
244
334
|
}
|
|
245
335
|
}
|
|
246
336
|
|
|
247
|
-
|
|
248
|
-
baseUrl;
|
|
249
|
-
maxUrlLength;
|
|
250
|
-
fallbackMethod;
|
|
251
|
-
expectedMethod;
|
|
252
|
-
headers;
|
|
253
|
-
rpcSerializer;
|
|
254
|
-
constructor(options) {
|
|
255
|
-
this.baseUrl = options.url;
|
|
256
|
-
this.maxUrlLength = options.maxUrlLength ?? 2083;
|
|
257
|
-
this.fallbackMethod = options.fallbackMethod ?? "POST";
|
|
258
|
-
this.expectedMethod = options.method ?? this.fallbackMethod;
|
|
259
|
-
this.headers = options.headers ?? {};
|
|
260
|
-
this.rpcSerializer = options.rpcSerializer ?? new RPCSerializer();
|
|
261
|
-
}
|
|
262
|
-
async encode(path, input, options) {
|
|
263
|
-
const expectedMethod = await value(this.expectedMethod, options, path, input);
|
|
264
|
-
const headers = await value(this.headers, options, path, input);
|
|
265
|
-
const baseUrl = await value(this.baseUrl, options, path, input);
|
|
266
|
-
const url = new URL(`${trim(baseUrl.toString(), "/")}/${path.map(encodeURIComponent).join("/")}`);
|
|
267
|
-
const serialized = this.rpcSerializer.serialize(input);
|
|
268
|
-
if (expectedMethod === "GET" && !(serialized instanceof FormData) && !(serialized instanceof Blob) && !isAsyncIteratorObject(serialized)) {
|
|
269
|
-
const maxUrlLength = await value(this.maxUrlLength, options, path, input);
|
|
270
|
-
const getUrl = new URL(url);
|
|
271
|
-
getUrl.searchParams.append("data", stringifyJSON(serialized) ?? "");
|
|
272
|
-
if (getUrl.toString().length <= maxUrlLength) {
|
|
273
|
-
return {
|
|
274
|
-
body: void 0,
|
|
275
|
-
method: expectedMethod,
|
|
276
|
-
headers,
|
|
277
|
-
url: getUrl,
|
|
278
|
-
signal: options.signal
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
return {
|
|
283
|
-
url,
|
|
284
|
-
method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
|
|
285
|
-
headers,
|
|
286
|
-
body: serialized,
|
|
287
|
-
signal: options.signal
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
async decode(response) {
|
|
291
|
-
const isOk = response.status >= 200 && response.status < 300;
|
|
292
|
-
const deserialized = await (async () => {
|
|
293
|
-
let isBodyOk = false;
|
|
294
|
-
try {
|
|
295
|
-
const body = await response.body();
|
|
296
|
-
isBodyOk = true;
|
|
297
|
-
return this.rpcSerializer.deserialize(body);
|
|
298
|
-
} catch (error) {
|
|
299
|
-
if (!isBodyOk) {
|
|
300
|
-
throw new Error("Cannot parse response body, please check the response body and content-type.", {
|
|
301
|
-
cause: error
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
throw new Error("Invalid RPC response format.", {
|
|
305
|
-
cause: error
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
})();
|
|
309
|
-
if (!isOk) {
|
|
310
|
-
if (ORPCError.isValidJSON(deserialized)) {
|
|
311
|
-
throw ORPCError.fromJSON(deserialized);
|
|
312
|
-
}
|
|
313
|
-
throw new Error("Invalid RPC error response format.", {
|
|
314
|
-
cause: deserialized
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
return deserialized;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
export { InvalidEventIteratorRetryResponse as I, RPCJsonSerializer as R, StandardLink as S, StandardRPCLinkCodec as a, RPCSerializer as b };
|
|
337
|
+
export { InvalidEventIteratorRetryResponse as I, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLinkCodec as c, StandardRPCSerializer as d, getMalformedResponseErrorCode as g, toHttpPath as t };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Interceptor, ThrowableError } from '@orpc/shared';
|
|
2
|
+
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
+
import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.CipPQkhk.mjs';
|
|
4
|
+
|
|
5
|
+
interface StandardLinkCodec<T extends ClientContext> {
|
|
6
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
7
|
+
decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
interface StandardLinkClient<T extends ClientContext> {
|
|
10
|
+
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare class InvalidEventIteratorRetryResponse extends Error {
|
|
14
|
+
}
|
|
15
|
+
interface StandardLinkPlugin<T extends ClientContext> {
|
|
16
|
+
init?(options: StandardLinkOptions<T>): void;
|
|
17
|
+
}
|
|
18
|
+
interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
19
|
+
path: readonly string[];
|
|
20
|
+
input: unknown;
|
|
21
|
+
}
|
|
22
|
+
interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
|
23
|
+
request: StandardRequest;
|
|
24
|
+
}
|
|
25
|
+
interface StandardLinkOptions<T extends ClientContext> {
|
|
26
|
+
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, unknown, ThrowableError>[];
|
|
27
|
+
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, StandardLazyResponse, ThrowableError>[];
|
|
28
|
+
plugins?: StandardLinkPlugin<T>[];
|
|
29
|
+
}
|
|
30
|
+
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
31
|
+
#private;
|
|
32
|
+
readonly codec: StandardLinkCodec<T>;
|
|
33
|
+
readonly sender: StandardLinkClient<T>;
|
|
34
|
+
private readonly interceptors;
|
|
35
|
+
private readonly clientInterceptors;
|
|
36
|
+
constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
|
|
37
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { InvalidEventIteratorRetryResponse as I, type StandardLinkClientInterceptorOptions as S, type StandardLinkPlugin as a, type StandardLinkOptions as b, type StandardLinkInterceptorOptions as c, StandardLink as d, type StandardLinkCodec as e, type StandardLinkClient as f };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.CipPQkhk.js';
|
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions } from './client.p3ON_yzu.js';
|
|
3
|
+
import { Segment, Value } from '@orpc/shared';
|
|
4
|
+
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
|
+
|
|
6
|
+
declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
|
|
7
|
+
readonly BIGINT: 0;
|
|
8
|
+
readonly DATE: 1;
|
|
9
|
+
readonly NAN: 2;
|
|
10
|
+
readonly UNDEFINED: 3;
|
|
11
|
+
readonly URL: 4;
|
|
12
|
+
readonly REGEXP: 5;
|
|
13
|
+
readonly SET: 6;
|
|
14
|
+
readonly MAP: 7;
|
|
15
|
+
};
|
|
16
|
+
type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
|
|
17
|
+
type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
|
|
18
|
+
interface StandardRPCCustomJsonSerializer {
|
|
19
|
+
type: number;
|
|
20
|
+
condition(data: unknown): boolean;
|
|
21
|
+
serialize(data: any): unknown;
|
|
22
|
+
deserialize(serialized: any): unknown;
|
|
23
|
+
}
|
|
24
|
+
interface StandardRPCJsonSerializerOptions {
|
|
25
|
+
customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
|
|
26
|
+
}
|
|
27
|
+
declare class StandardRPCJsonSerializer {
|
|
28
|
+
private readonly customSerializers;
|
|
29
|
+
constructor(options?: StandardRPCJsonSerializerOptions);
|
|
30
|
+
serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
|
|
31
|
+
deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
|
|
32
|
+
deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare class StandardRPCSerializer {
|
|
36
|
+
#private;
|
|
37
|
+
private readonly jsonSerializer;
|
|
38
|
+
constructor(jsonSerializer: StandardRPCJsonSerializer);
|
|
39
|
+
serialize(data: unknown): object;
|
|
40
|
+
deserialize(data: unknown): unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
44
|
+
/**
|
|
45
|
+
* Base url for all requests.
|
|
46
|
+
*/
|
|
47
|
+
url: Value<string | URL, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
48
|
+
/**
|
|
49
|
+
* The maximum length of the URL.
|
|
50
|
+
*
|
|
51
|
+
* @default 2083
|
|
52
|
+
*/
|
|
53
|
+
maxUrlLength?: Value<number, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
54
|
+
/**
|
|
55
|
+
* The method used to make the request.
|
|
56
|
+
*
|
|
57
|
+
* @default 'POST'
|
|
58
|
+
*/
|
|
59
|
+
method?: Value<HTTPMethod, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
60
|
+
/**
|
|
61
|
+
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
62
|
+
* GET is not allowed, it's very dangerous.
|
|
63
|
+
*
|
|
64
|
+
* @default 'POST'
|
|
65
|
+
*/
|
|
66
|
+
fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
|
|
67
|
+
/**
|
|
68
|
+
* Inject headers to the request.
|
|
69
|
+
*/
|
|
70
|
+
headers?: Value<StandardHeaders, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
71
|
+
}
|
|
72
|
+
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
73
|
+
private readonly serializer;
|
|
74
|
+
private readonly baseUrl;
|
|
75
|
+
private readonly maxUrlLength;
|
|
76
|
+
private readonly fallbackMethod;
|
|
77
|
+
private readonly expectedMethod;
|
|
78
|
+
private readonly headers;
|
|
79
|
+
constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
|
|
80
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
81
|
+
decode(response: StandardLazyResponse): Promise<unknown>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, type StandardRPCJsonSerializedMetaItem as a, type StandardRPCJsonSerialized as b, type StandardRPCCustomJsonSerializer as c, type StandardRPCJsonSerializerOptions as d, StandardRPCJsonSerializer as e, type StandardRPCLinkOptions as f, type StandardRPCLinkCodecOptions as g, StandardRPCLinkCodec as h, StandardRPCSerializer as i };
|