@orpc/client 0.0.0-next.f17a1a0 → 0.0.0-next.f4d410a
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 +4 -2
- package/dist/adapters/fetch/index.d.mts +29 -0
- package/dist/adapters/fetch/index.d.ts +29 -0
- package/dist/adapters/fetch/index.mjs +36 -0
- package/dist/adapters/standard/index.d.mts +169 -0
- package/dist/adapters/standard/index.d.ts +169 -0
- package/dist/adapters/standard/index.mjs +4 -0
- package/dist/index.d.mts +156 -0
- package/dist/index.d.ts +156 -0
- package/dist/{index.js → index.mjs} +20 -38
- package/dist/shared/client.CPmBUYbj.mjs +351 -0
- package/dist/shared/client.D_CzLDyB.d.mts +42 -0
- package/dist/shared/client.D_CzLDyB.d.ts +42 -0
- package/dist/{chunk-OGAGXWCU.js → shared/client.XAn8cDTM.mjs} +15 -30
- package/package.json +16 -26
- package/dist/chunk-4FUUNP74.js +0 -212
- package/dist/fetch.js +0 -128
- package/dist/openapi.js +0 -231
- package/dist/rpc.js +0 -10
- package/dist/src/adapters/fetch/index.d.ts +0 -3
- package/dist/src/adapters/fetch/rpc-link.d.ts +0 -98
- package/dist/src/adapters/fetch/types.d.ts +0 -5
- package/dist/src/client.d.ts +0 -9
- package/dist/src/dynamic-link.d.ts +0 -12
- package/dist/src/error.d.ts +0 -106
- package/dist/src/event-iterator-state.d.ts +0 -9
- package/dist/src/event-iterator.d.ts +0 -12
- package/dist/src/index.d.ts +0 -9
- package/dist/src/openapi/bracket-notation.d.ts +0 -9
- package/dist/src/openapi/index.d.ts +0 -4
- package/dist/src/openapi/json-serializer.d.ts +0 -7
- package/dist/src/openapi/serializer.d.ts +0 -11
- package/dist/src/rpc/index.d.ts +0 -3
- package/dist/src/rpc/json-serializer.d.ts +0 -12
- package/dist/src/rpc/serializer.d.ts +0 -9
- package/dist/src/types.d.ts +0 -29
- package/dist/src/utils.d.ts +0 -5
@@ -1,6 +1,7 @@
|
|
1
|
-
|
2
|
-
import {
|
3
|
-
|
1
|
+
import { isObject, isTypescriptObject, retry } from '@orpc/shared';
|
2
|
+
import { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
3
|
+
|
4
|
+
const COMMON_ORPC_ERROR_DEFS = {
|
4
5
|
BAD_REQUEST: {
|
5
6
|
status: 400,
|
6
7
|
message: "Bad Request"
|
@@ -84,7 +85,7 @@ function fallbackORPCErrorStatus(code, status) {
|
|
84
85
|
function fallbackORPCErrorMessage(code, message) {
|
85
86
|
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
86
87
|
}
|
87
|
-
|
88
|
+
class ORPCError extends Error {
|
88
89
|
defined;
|
89
90
|
code;
|
90
91
|
status;
|
@@ -110,7 +111,7 @@ var ORPCError = class _ORPCError extends Error {
|
|
110
111
|
};
|
111
112
|
}
|
112
113
|
static fromJSON(json, options) {
|
113
|
-
return new
|
114
|
+
return new ORPCError(json.code, {
|
114
115
|
...options,
|
115
116
|
...json
|
116
117
|
});
|
@@ -125,7 +126,7 @@ var ORPCError = class _ORPCError extends Error {
|
|
125
126
|
}
|
126
127
|
return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && "message" in json && typeof json.message === "string";
|
127
128
|
}
|
128
|
-
}
|
129
|
+
}
|
129
130
|
function isDefinedError(error) {
|
130
131
|
return error instanceof ORPCError && error.defined;
|
131
132
|
}
|
@@ -136,8 +137,7 @@ function toORPCError(error) {
|
|
136
137
|
});
|
137
138
|
}
|
138
139
|
|
139
|
-
|
140
|
-
var iteratorStates = /* @__PURE__ */ new WeakMap();
|
140
|
+
const iteratorStates = /* @__PURE__ */ new WeakMap();
|
141
141
|
function registerEventIteratorState(iterator, state) {
|
142
142
|
iteratorStates.set(iterator, state);
|
143
143
|
}
|
@@ -147,7 +147,8 @@ function updateEventIteratorStatus(state, status) {
|
|
147
147
|
state.listeners.forEach((cb) => cb(status));
|
148
148
|
}
|
149
149
|
}
|
150
|
-
function onEventIteratorStatusChange(iterator, callback,
|
150
|
+
function onEventIteratorStatusChange(iterator, callback, options = {}) {
|
151
|
+
const notifyImmediately = options.notifyImmediately ?? true;
|
151
152
|
const state = iteratorStates.get(iterator);
|
152
153
|
if (!state) {
|
153
154
|
throw new Error("Iterator is not registered.");
|
@@ -164,9 +165,6 @@ function onEventIteratorStatusChange(iterator, callback, notifyImmediately = tru
|
|
164
165
|
};
|
165
166
|
}
|
166
167
|
|
167
|
-
// src/event-iterator.ts
|
168
|
-
import { getEventMeta, isEventMetaContainer, withEventMeta } from "@orpc/server-standard";
|
169
|
-
import { retry } from "@orpc/shared";
|
170
168
|
function mapEventIterator(iterator, maps) {
|
171
169
|
return async function* () {
|
172
170
|
try {
|
@@ -175,7 +173,7 @@ function mapEventIterator(iterator, maps) {
|
|
175
173
|
let mappedValue = await maps.value(value, done);
|
176
174
|
if (mappedValue !== value) {
|
177
175
|
const meta = getEventMeta(value);
|
178
|
-
if (meta &&
|
176
|
+
if (meta && isTypescriptObject(mappedValue)) {
|
179
177
|
mappedValue = withEventMeta(mappedValue, meta);
|
180
178
|
}
|
181
179
|
}
|
@@ -188,7 +186,7 @@ function mapEventIterator(iterator, maps) {
|
|
188
186
|
let mappedError = await maps.error(error);
|
189
187
|
if (mappedError !== error) {
|
190
188
|
const meta = getEventMeta(error);
|
191
|
-
if (meta &&
|
189
|
+
if (meta && isTypescriptObject(mappedError)) {
|
192
190
|
mappedError = withEventMeta(mappedError, meta);
|
193
191
|
}
|
194
192
|
}
|
@@ -198,7 +196,7 @@ function mapEventIterator(iterator, maps) {
|
|
198
196
|
}
|
199
197
|
}();
|
200
198
|
}
|
201
|
-
|
199
|
+
const MAX_ALLOWED_RETRY_TIMES = 99;
|
202
200
|
function createAutoRetryEventIterator(initial, reconnect, initialLastEventId) {
|
203
201
|
const state = {
|
204
202
|
status: "connected",
|
@@ -232,7 +230,7 @@ function createAutoRetryEventIterator(initial, reconnect, initialLastEventId) {
|
|
232
230
|
retryTimes += 1;
|
233
231
|
if (retryTimes > MAX_ALLOWED_RETRY_TIMES) {
|
234
232
|
throw exit(new Error(
|
235
|
-
`Exceeded maximum retry attempts (${MAX_ALLOWED_RETRY_TIMES}) for event
|
233
|
+
`Exceeded maximum retry attempts (${MAX_ALLOWED_RETRY_TIMES}) for event iterator. Possible infinite retry loop detected. Please review the retry logic.`,
|
236
234
|
{ cause: currentError }
|
237
235
|
));
|
238
236
|
}
|
@@ -265,17 +263,4 @@ function createAutoRetryEventIterator(initial, reconnect, initialLastEventId) {
|
|
265
263
|
return iterator;
|
266
264
|
}
|
267
265
|
|
268
|
-
export {
|
269
|
-
COMMON_ORPC_ERROR_DEFS,
|
270
|
-
fallbackORPCErrorStatus,
|
271
|
-
fallbackORPCErrorMessage,
|
272
|
-
ORPCError,
|
273
|
-
isDefinedError,
|
274
|
-
toORPCError,
|
275
|
-
registerEventIteratorState,
|
276
|
-
updateEventIteratorStatus,
|
277
|
-
onEventIteratorStatusChange,
|
278
|
-
mapEventIterator,
|
279
|
-
createAutoRetryEventIterator
|
280
|
-
};
|
281
|
-
//# sourceMappingURL=chunk-OGAGXWCU.js.map
|
266
|
+
export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, createAutoRetryEventIterator as c, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, onEventIteratorStatusChange as o, registerEventIteratorState as r, toORPCError as t, updateEventIteratorStatus as u };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/client",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.f4d410a",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -15,44 +15,34 @@
|
|
15
15
|
],
|
16
16
|
"exports": {
|
17
17
|
".": {
|
18
|
-
"types": "./dist/
|
19
|
-
"import": "./dist/index.
|
20
|
-
"default": "./dist/index.
|
18
|
+
"types": "./dist/index.d.mts",
|
19
|
+
"import": "./dist/index.mjs",
|
20
|
+
"default": "./dist/index.mjs"
|
21
21
|
},
|
22
|
-
"./
|
23
|
-
"types": "./dist/
|
24
|
-
"import": "./dist/
|
25
|
-
"default": "./dist/
|
26
|
-
},
|
27
|
-
"./rpc": {
|
28
|
-
"types": "./dist/src/rpc/index.d.ts",
|
29
|
-
"import": "./dist/rpc.js",
|
30
|
-
"default": "./dist/rpc.js"
|
22
|
+
"./standard": {
|
23
|
+
"types": "./dist/adapters/standard/index.d.mts",
|
24
|
+
"import": "./dist/adapters/standard/index.mjs",
|
25
|
+
"default": "./dist/adapters/standard/index.mjs"
|
31
26
|
},
|
32
27
|
"./fetch": {
|
33
|
-
"types": "./dist/
|
34
|
-
"import": "./dist/fetch.
|
35
|
-
"default": "./dist/fetch.
|
36
|
-
},
|
37
|
-
"./🔒/*": {
|
38
|
-
"types": "./dist/src/*.d.ts"
|
28
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
29
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
30
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
39
31
|
}
|
40
32
|
},
|
41
33
|
"files": [
|
42
|
-
"!**/*.map",
|
43
|
-
"!**/*.tsbuildinfo",
|
44
34
|
"dist"
|
45
35
|
],
|
46
36
|
"dependencies": {
|
47
|
-
"@orpc/
|
48
|
-
"@orpc/
|
49
|
-
"@orpc/
|
37
|
+
"@orpc/shared": "0.0.0-next.f4d410a",
|
38
|
+
"@orpc/standard-server": "0.0.0-next.f4d410a",
|
39
|
+
"@orpc/standard-server-fetch": "0.0.0-next.f4d410a"
|
50
40
|
},
|
51
41
|
"devDependencies": {
|
52
|
-
"zod": "^3.24.
|
42
|
+
"zod": "^3.24.2"
|
53
43
|
},
|
54
44
|
"scripts": {
|
55
|
-
"build": "
|
45
|
+
"build": "unbuild",
|
56
46
|
"build:watch": "pnpm run build --watch",
|
57
47
|
"type:check": "tsc -b"
|
58
48
|
}
|
package/dist/chunk-4FUUNP74.js
DELETED
@@ -1,212 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
ORPCError,
|
3
|
-
mapEventIterator,
|
4
|
-
toORPCError
|
5
|
-
} from "./chunk-OGAGXWCU.js";
|
6
|
-
|
7
|
-
// src/rpc/json-serializer.ts
|
8
|
-
import { isObject } from "@orpc/shared";
|
9
|
-
var RPCJsonSerializer = class {
|
10
|
-
serialize(data, segments = [], meta = [], maps = [], blobs = []) {
|
11
|
-
if (data instanceof Blob) {
|
12
|
-
maps.push(segments);
|
13
|
-
blobs.push(data);
|
14
|
-
return [data, meta, maps, blobs];
|
15
|
-
}
|
16
|
-
if (typeof data === "bigint") {
|
17
|
-
meta.push([0, segments]);
|
18
|
-
return [data.toString(), meta, maps, blobs];
|
19
|
-
}
|
20
|
-
if (data instanceof Date) {
|
21
|
-
meta.push([1, segments]);
|
22
|
-
if (Number.isNaN(data.getTime())) {
|
23
|
-
return [null, meta, maps, blobs];
|
24
|
-
}
|
25
|
-
return [data.toISOString(), meta, maps, blobs];
|
26
|
-
}
|
27
|
-
if (Number.isNaN(data)) {
|
28
|
-
meta.push([2, segments]);
|
29
|
-
return [null, meta, maps, blobs];
|
30
|
-
}
|
31
|
-
if (data instanceof URL) {
|
32
|
-
meta.push([4, segments]);
|
33
|
-
return [data.toString(), meta, maps, blobs];
|
34
|
-
}
|
35
|
-
if (data instanceof RegExp) {
|
36
|
-
meta.push([5, segments]);
|
37
|
-
return [data.toString(), meta, maps, blobs];
|
38
|
-
}
|
39
|
-
if (data instanceof Set) {
|
40
|
-
const result = this.serialize(Array.from(data), segments, meta, maps, blobs);
|
41
|
-
meta.push([6, segments]);
|
42
|
-
return result;
|
43
|
-
}
|
44
|
-
if (data instanceof Map) {
|
45
|
-
const result = this.serialize(Array.from(data.entries()), segments, meta, maps, blobs);
|
46
|
-
meta.push([7, segments]);
|
47
|
-
return result;
|
48
|
-
}
|
49
|
-
if (Array.isArray(data)) {
|
50
|
-
const json = data.map((v, i) => {
|
51
|
-
if (v === void 0) {
|
52
|
-
meta.push([3, [...segments, i]]);
|
53
|
-
return v;
|
54
|
-
}
|
55
|
-
return this.serialize(v, [...segments, i], meta, maps, blobs)[0];
|
56
|
-
});
|
57
|
-
return [json, meta, maps, blobs];
|
58
|
-
}
|
59
|
-
if (isObject(data)) {
|
60
|
-
const json = {};
|
61
|
-
for (const k in data) {
|
62
|
-
json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0];
|
63
|
-
}
|
64
|
-
return [json, meta, maps, blobs];
|
65
|
-
}
|
66
|
-
return [data, meta, maps, blobs];
|
67
|
-
}
|
68
|
-
deserialize(json, meta, maps, getBlob) {
|
69
|
-
const ref = { data: json };
|
70
|
-
if (maps && getBlob) {
|
71
|
-
maps.forEach((segments, i) => {
|
72
|
-
let currentRef = ref;
|
73
|
-
let preSegment = "data";
|
74
|
-
segments.forEach((segment) => {
|
75
|
-
currentRef = currentRef[preSegment];
|
76
|
-
preSegment = segment;
|
77
|
-
});
|
78
|
-
currentRef[preSegment] = getBlob(i);
|
79
|
-
});
|
80
|
-
}
|
81
|
-
for (const [type, segments] of meta) {
|
82
|
-
let currentRef = ref;
|
83
|
-
let preSegment = "data";
|
84
|
-
segments.forEach((segment) => {
|
85
|
-
currentRef = currentRef[preSegment];
|
86
|
-
preSegment = segment;
|
87
|
-
});
|
88
|
-
switch (type) {
|
89
|
-
case 0:
|
90
|
-
currentRef[preSegment] = BigInt(currentRef[preSegment]);
|
91
|
-
break;
|
92
|
-
case 1:
|
93
|
-
currentRef[preSegment] = new Date(currentRef[preSegment] ?? "Invalid Date");
|
94
|
-
break;
|
95
|
-
case 2:
|
96
|
-
currentRef[preSegment] = Number.NaN;
|
97
|
-
break;
|
98
|
-
case 3:
|
99
|
-
currentRef[preSegment] = void 0;
|
100
|
-
break;
|
101
|
-
case 4:
|
102
|
-
currentRef[preSegment] = new URL(currentRef[preSegment]);
|
103
|
-
break;
|
104
|
-
case 5: {
|
105
|
-
const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
|
106
|
-
currentRef[preSegment] = new RegExp(pattern, flags);
|
107
|
-
break;
|
108
|
-
}
|
109
|
-
case 6:
|
110
|
-
currentRef[preSegment] = new Set(currentRef[preSegment]);
|
111
|
-
break;
|
112
|
-
case 7:
|
113
|
-
currentRef[preSegment] = new Map(currentRef[preSegment]);
|
114
|
-
break;
|
115
|
-
/* v8 ignore next 3 */
|
116
|
-
default: {
|
117
|
-
const _expected = type;
|
118
|
-
}
|
119
|
-
}
|
120
|
-
}
|
121
|
-
return ref.data;
|
122
|
-
}
|
123
|
-
};
|
124
|
-
|
125
|
-
// src/rpc/serializer.ts
|
126
|
-
import { ErrorEvent, isAsyncIteratorObject } from "@orpc/server-standard";
|
127
|
-
var RPCSerializer = class {
|
128
|
-
constructor(jsonSerializer = new RPCJsonSerializer()) {
|
129
|
-
this.jsonSerializer = jsonSerializer;
|
130
|
-
}
|
131
|
-
serialize(data) {
|
132
|
-
if (isAsyncIteratorObject(data)) {
|
133
|
-
return mapEventIterator(data, {
|
134
|
-
value: async (value) => this.#serialize(value, false),
|
135
|
-
error: async (e) => {
|
136
|
-
if (e instanceof ErrorEvent) {
|
137
|
-
return new ErrorEvent({
|
138
|
-
data: this.#serialize(e.data, false),
|
139
|
-
cause: e
|
140
|
-
});
|
141
|
-
}
|
142
|
-
return new ErrorEvent({
|
143
|
-
data: this.#serialize(toORPCError(e).toJSON(), false),
|
144
|
-
cause: e
|
145
|
-
});
|
146
|
-
}
|
147
|
-
});
|
148
|
-
}
|
149
|
-
return this.#serialize(data, true);
|
150
|
-
}
|
151
|
-
#serialize(data, enableFormData) {
|
152
|
-
if (data === void 0 || data instanceof Blob) {
|
153
|
-
return data;
|
154
|
-
}
|
155
|
-
const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data);
|
156
|
-
const meta = meta_.length === 0 ? void 0 : meta_;
|
157
|
-
if (!enableFormData || blobs.length === 0) {
|
158
|
-
return {
|
159
|
-
json,
|
160
|
-
meta
|
161
|
-
};
|
162
|
-
}
|
163
|
-
const form = new FormData();
|
164
|
-
form.set("data", JSON.stringify({ json, meta, maps }));
|
165
|
-
blobs.forEach((blob, i) => {
|
166
|
-
form.set(i.toString(), blob);
|
167
|
-
});
|
168
|
-
return form;
|
169
|
-
}
|
170
|
-
deserialize(data) {
|
171
|
-
if (isAsyncIteratorObject(data)) {
|
172
|
-
return mapEventIterator(data, {
|
173
|
-
value: async (value) => this.#deserialize(value),
|
174
|
-
error: async (e) => {
|
175
|
-
if (!(e instanceof ErrorEvent)) {
|
176
|
-
return e;
|
177
|
-
}
|
178
|
-
const deserialized = this.#deserialize(e.data);
|
179
|
-
if (ORPCError.isValidJSON(deserialized)) {
|
180
|
-
return ORPCError.fromJSON(deserialized, { cause: e });
|
181
|
-
}
|
182
|
-
return new ErrorEvent({
|
183
|
-
data: deserialized,
|
184
|
-
cause: e
|
185
|
-
});
|
186
|
-
}
|
187
|
-
});
|
188
|
-
}
|
189
|
-
return this.#deserialize(data);
|
190
|
-
}
|
191
|
-
#deserialize(data) {
|
192
|
-
if (data === void 0 || data instanceof Blob) {
|
193
|
-
return data;
|
194
|
-
}
|
195
|
-
if (!(data instanceof FormData)) {
|
196
|
-
return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
|
197
|
-
}
|
198
|
-
const serialized = JSON.parse(data.get("data"));
|
199
|
-
return this.jsonSerializer.deserialize(
|
200
|
-
serialized.json,
|
201
|
-
serialized.meta ?? [],
|
202
|
-
serialized.maps,
|
203
|
-
(i) => data.get(i.toString())
|
204
|
-
);
|
205
|
-
}
|
206
|
-
};
|
207
|
-
|
208
|
-
export {
|
209
|
-
RPCJsonSerializer,
|
210
|
-
RPCSerializer
|
211
|
-
};
|
212
|
-
//# sourceMappingURL=chunk-4FUUNP74.js.map
|
package/dist/fetch.js
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
RPCSerializer
|
3
|
-
} from "./chunk-4FUUNP74.js";
|
4
|
-
import {
|
5
|
-
ORPCError,
|
6
|
-
createAutoRetryEventIterator
|
7
|
-
} from "./chunk-OGAGXWCU.js";
|
8
|
-
|
9
|
-
// src/adapters/fetch/rpc-link.ts
|
10
|
-
import { isAsyncIteratorObject } from "@orpc/server-standard";
|
11
|
-
import { toFetchBody, toStandardBody } from "@orpc/server-standard-fetch";
|
12
|
-
import { trim, value } from "@orpc/shared";
|
13
|
-
var InvalidEventSourceRetryResponse = class extends Error {
|
14
|
-
};
|
15
|
-
var RPCLink = class {
|
16
|
-
fetch;
|
17
|
-
rpcSerializer;
|
18
|
-
maxUrlLength;
|
19
|
-
fallbackMethod;
|
20
|
-
method;
|
21
|
-
headers;
|
22
|
-
url;
|
23
|
-
eventSourceMaxNumberOfRetries;
|
24
|
-
eventSourceRetryDelay;
|
25
|
-
eventSourceRetry;
|
26
|
-
constructor(options) {
|
27
|
-
this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
28
|
-
this.rpcSerializer = options.rpcSerializer ?? new RPCSerializer();
|
29
|
-
this.maxUrlLength = options.maxUrlLength ?? 2083;
|
30
|
-
this.fallbackMethod = options.fallbackMethod ?? "POST";
|
31
|
-
this.url = options.url;
|
32
|
-
this.eventSourceMaxNumberOfRetries = options.eventSourceMaxNumberOfRetries ?? 5;
|
33
|
-
this.method = options.method ?? this.fallbackMethod;
|
34
|
-
this.headers = options.headers ?? {};
|
35
|
-
this.eventSourceRetry = options.eventSourceRetry ?? true;
|
36
|
-
this.eventSourceRetryDelay = options.eventSourceRetryDelay ?? (({ retryTimes, lastRetry }) => lastRetry ?? 1e3 * 2 ** retryTimes);
|
37
|
-
}
|
38
|
-
async call(path, input, options) {
|
39
|
-
const output = await this.performCall(path, input, options);
|
40
|
-
if (!isAsyncIteratorObject(output)) {
|
41
|
-
return output;
|
42
|
-
}
|
43
|
-
return createAutoRetryEventIterator(output, async (reconnectOptions) => {
|
44
|
-
if (options.signal?.aborted || reconnectOptions.retryTimes > this.eventSourceMaxNumberOfRetries) {
|
45
|
-
return null;
|
46
|
-
}
|
47
|
-
if (!await value(this.eventSourceRetry, reconnectOptions, options, path, input)) {
|
48
|
-
return null;
|
49
|
-
}
|
50
|
-
const delay = await value(this.eventSourceRetryDelay, reconnectOptions, options, path, input);
|
51
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
52
|
-
const updatedOptions = { ...options, lastEventId: reconnectOptions.lastEventId };
|
53
|
-
const maybeIterator = await this.performCall(path, input, updatedOptions);
|
54
|
-
if (!isAsyncIteratorObject(maybeIterator)) {
|
55
|
-
throw new InvalidEventSourceRetryResponse("Invalid EventSource retry response");
|
56
|
-
}
|
57
|
-
return maybeIterator;
|
58
|
-
}, void 0);
|
59
|
-
}
|
60
|
-
async performCall(path, input, options) {
|
61
|
-
const encoded = await this.encodeRequest(path, input, options);
|
62
|
-
const fetchBody = toFetchBody(encoded.body, encoded.headers);
|
63
|
-
if (options.lastEventId !== void 0) {
|
64
|
-
encoded.headers.set("last-event-id", options.lastEventId);
|
65
|
-
}
|
66
|
-
const response = await this.fetch(encoded.url, {
|
67
|
-
method: encoded.method,
|
68
|
-
headers: encoded.headers,
|
69
|
-
body: fetchBody,
|
70
|
-
signal: options.signal
|
71
|
-
}, options, path, input);
|
72
|
-
const body = await toStandardBody(response);
|
73
|
-
const deserialized = (() => {
|
74
|
-
try {
|
75
|
-
return this.rpcSerializer.deserialize(body);
|
76
|
-
} catch (error) {
|
77
|
-
if (response.ok) {
|
78
|
-
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
79
|
-
message: "Invalid RPC response",
|
80
|
-
cause: error
|
81
|
-
});
|
82
|
-
}
|
83
|
-
throw new ORPCError(response.status.toString(), {
|
84
|
-
message: response.statusText
|
85
|
-
});
|
86
|
-
}
|
87
|
-
})();
|
88
|
-
if (!response.ok) {
|
89
|
-
if (ORPCError.isValidJSON(deserialized)) {
|
90
|
-
throw ORPCError.fromJSON(deserialized);
|
91
|
-
}
|
92
|
-
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
93
|
-
message: "Invalid RPC error response",
|
94
|
-
cause: deserialized
|
95
|
-
});
|
96
|
-
}
|
97
|
-
return deserialized;
|
98
|
-
}
|
99
|
-
async encodeRequest(path, input, options) {
|
100
|
-
const expectedMethod = await value(this.method, options, path, input);
|
101
|
-
const headers = new Headers(await value(this.headers, options, path, input));
|
102
|
-
const url = new URL(`${trim(this.url, "/")}/${path.map(encodeURIComponent).join("/")}`);
|
103
|
-
const serialized = this.rpcSerializer.serialize(input);
|
104
|
-
if (expectedMethod === "GET" && !(serialized instanceof FormData) && !(serialized instanceof Blob) && !isAsyncIteratorObject(serialized)) {
|
105
|
-
const getUrl = new URL(url);
|
106
|
-
getUrl.searchParams.append("data", JSON.stringify(serialized) ?? "");
|
107
|
-
if (getUrl.toString().length <= this.maxUrlLength) {
|
108
|
-
return {
|
109
|
-
body: void 0,
|
110
|
-
method: expectedMethod,
|
111
|
-
headers,
|
112
|
-
url: getUrl
|
113
|
-
};
|
114
|
-
}
|
115
|
-
}
|
116
|
-
return {
|
117
|
-
url,
|
118
|
-
method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
|
119
|
-
headers,
|
120
|
-
body: serialized
|
121
|
-
};
|
122
|
-
}
|
123
|
-
};
|
124
|
-
export {
|
125
|
-
InvalidEventSourceRetryResponse,
|
126
|
-
RPCLink
|
127
|
-
};
|
128
|
-
//# sourceMappingURL=fetch.js.map
|