@orpc/client 1.14.9 → 1.14.11
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 +52 -68
- package/dist/adapters/fetch/index.d.mts +54 -35
- package/dist/adapters/fetch/index.d.ts +54 -35
- package/dist/adapters/fetch/index.mjs +74 -27
- package/dist/adapters/message-port/index.d.mts +25 -30
- package/dist/adapters/message-port/index.d.ts +25 -30
- package/dist/adapters/message-port/index.mjs +39 -30
- package/dist/adapters/standard/index.d.mts +59 -9
- package/dist/adapters/standard/index.d.ts +59 -9
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/websocket/index.d.mts +113 -21
- package/dist/adapters/websocket/index.d.ts +113 -21
- package/dist/adapters/websocket/index.mjs +95 -37
- package/dist/index.d.mts +75 -184
- package/dist/index.d.ts +75 -184
- package/dist/index.mjs +74 -63
- package/dist/plugins/index.d.mts +191 -122
- package/dist/plugins/index.d.ts +191 -122
- package/dist/plugins/index.mjs +627 -281
- package/dist/shared/client.8f4DNmdE.d.mts +96 -0
- package/dist/shared/client.BBZBQID8.d.mts +167 -0
- package/dist/shared/client.BBZBQID8.d.ts +167 -0
- package/dist/shared/client.BMKYqpdy.d.ts +96 -0
- package/dist/shared/client.BRJnOJ0R.mjs +174 -0
- package/dist/shared/client.BdItY5DT.d.mts +111 -0
- package/dist/shared/client.BdItY5DT.d.ts +111 -0
- package/dist/shared/client.Dnfj8jnT.mjs +92 -0
- package/dist/shared/client.DqYwRDUO.mjs +343 -0
- package/package.json +7 -7
- package/dist/shared/client.2jUAqzYU.d.ts +0 -45
- package/dist/shared/client.B3pNRBih.d.ts +0 -91
- package/dist/shared/client.BFAVy68H.d.mts +0 -91
- package/dist/shared/client.BLtwTQUg.mjs +0 -40
- package/dist/shared/client.CFQL4ewg.mjs +0 -174
- package/dist/shared/client.CpCa3si8.d.mts +0 -45
- package/dist/shared/client.D2nvAALa.mjs +0 -404
- package/dist/shared/client.i2uoJbEp.d.mts +0 -83
- package/dist/shared/client.i2uoJbEp.d.ts +0 -83
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { isPlainObject, wrapAsyncIterator, isTypescriptObject, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
|
|
2
|
+
import { getEventMeta, withEventMeta, ErrorEvent } from '@standardserver/core';
|
|
3
|
+
import { O as ORPCError } from './client.Dnfj8jnT.mjs';
|
|
4
|
+
|
|
5
|
+
function isInferableError(error) {
|
|
6
|
+
return error instanceof ORPCError && error.inferable;
|
|
7
|
+
}
|
|
8
|
+
function toORPCError(error) {
|
|
9
|
+
return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", { cause: error });
|
|
10
|
+
}
|
|
11
|
+
function isORPCErrorJson(json) {
|
|
12
|
+
if (!isPlainObject(json)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const validKeys = ["defined", "inferable", "code", "message", "data"];
|
|
16
|
+
if (Object.keys(json).some((k) => !validKeys.includes(k))) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return "defined" in json && typeof json.defined === "boolean" && "inferable" in json && typeof json.inferable === "boolean" && "code" in json && typeof json.code === "string" && "message" in json && typeof json.message === "string";
|
|
20
|
+
}
|
|
21
|
+
function createORPCErrorFromJson(json, options = {}) {
|
|
22
|
+
const error = new ORPCError(json.code, {
|
|
23
|
+
...json,
|
|
24
|
+
...options
|
|
25
|
+
});
|
|
26
|
+
error.defined = json.defined;
|
|
27
|
+
error.inferable = json.inferable;
|
|
28
|
+
return error;
|
|
29
|
+
}
|
|
30
|
+
function cloneORPCError(error) {
|
|
31
|
+
const cloned = new ORPCError(error.code, {
|
|
32
|
+
...error,
|
|
33
|
+
message: error.message,
|
|
34
|
+
data: error.data,
|
|
35
|
+
cause: error.cause
|
|
36
|
+
});
|
|
37
|
+
cloned.stack = error.stack;
|
|
38
|
+
cloned.defined = error.defined;
|
|
39
|
+
cloned.inferable = error.inferable;
|
|
40
|
+
return cloned;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function wrapAsyncIteratorPreservingEventMeta(iterator, { mapResult, mapError, ...rest }) {
|
|
44
|
+
return wrapAsyncIterator(iterator, {
|
|
45
|
+
...rest,
|
|
46
|
+
mapResult: mapResult && (async (result) => {
|
|
47
|
+
const mapped = await mapResult(result);
|
|
48
|
+
if (mapped.value !== result.value) {
|
|
49
|
+
const meta = getEventMeta(result.value);
|
|
50
|
+
if (meta && isTypescriptObject(mapped.value)) {
|
|
51
|
+
return { done: mapped.done, value: withEventMeta(mapped.value, meta) };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return mapped;
|
|
55
|
+
}),
|
|
56
|
+
mapError: mapError && (async (error) => {
|
|
57
|
+
const mapped = await mapError(error);
|
|
58
|
+
if (mapped !== error) {
|
|
59
|
+
const meta = getEventMeta(error);
|
|
60
|
+
if (meta && isTypescriptObject(mapped)) {
|
|
61
|
+
return withEventMeta(mapped, meta);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return mapped;
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const REGEX_STRING_PATTERN = /^\/(.*)\/([a-z]*)$/;
|
|
70
|
+
const DEFAULT_RPC_JSON_SERIALIZER_HANDLERS = {
|
|
71
|
+
undefined: {
|
|
72
|
+
condition(data) {
|
|
73
|
+
return data === void 0;
|
|
74
|
+
},
|
|
75
|
+
serialize() {
|
|
76
|
+
return null;
|
|
77
|
+
},
|
|
78
|
+
deserialize() {
|
|
79
|
+
return void 0;
|
|
80
|
+
},
|
|
81
|
+
isTerminal: true
|
|
82
|
+
},
|
|
83
|
+
bigint: {
|
|
84
|
+
condition(data) {
|
|
85
|
+
return typeof data === "bigint";
|
|
86
|
+
},
|
|
87
|
+
serialize(data) {
|
|
88
|
+
return data.toString();
|
|
89
|
+
},
|
|
90
|
+
deserialize(serialized) {
|
|
91
|
+
return BigInt(serialized);
|
|
92
|
+
},
|
|
93
|
+
isTerminal: true
|
|
94
|
+
},
|
|
95
|
+
date: {
|
|
96
|
+
condition(data) {
|
|
97
|
+
return data instanceof Date;
|
|
98
|
+
},
|
|
99
|
+
serialize(data) {
|
|
100
|
+
if (Number.isNaN(data.getTime())) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
return data.toISOString();
|
|
104
|
+
},
|
|
105
|
+
deserialize(serialized) {
|
|
106
|
+
return new Date(serialized ?? "Invalid Date");
|
|
107
|
+
},
|
|
108
|
+
isTerminal: true
|
|
109
|
+
},
|
|
110
|
+
nan: {
|
|
111
|
+
condition(data) {
|
|
112
|
+
return typeof data === "number" && Number.isNaN(data);
|
|
113
|
+
},
|
|
114
|
+
serialize() {
|
|
115
|
+
return null;
|
|
116
|
+
},
|
|
117
|
+
deserialize() {
|
|
118
|
+
return Number.NaN;
|
|
119
|
+
},
|
|
120
|
+
isTerminal: true
|
|
121
|
+
},
|
|
122
|
+
url: {
|
|
123
|
+
condition(data) {
|
|
124
|
+
return data instanceof URL;
|
|
125
|
+
},
|
|
126
|
+
serialize(data) {
|
|
127
|
+
return data.toString();
|
|
128
|
+
},
|
|
129
|
+
deserialize(serialized) {
|
|
130
|
+
return new URL(serialized);
|
|
131
|
+
},
|
|
132
|
+
isTerminal: true
|
|
133
|
+
},
|
|
134
|
+
regexp: {
|
|
135
|
+
condition(data) {
|
|
136
|
+
return data instanceof RegExp;
|
|
137
|
+
},
|
|
138
|
+
serialize(data) {
|
|
139
|
+
return data.toString();
|
|
140
|
+
},
|
|
141
|
+
deserialize(serialized) {
|
|
142
|
+
const [, pattern, flags] = serialized.match(REGEX_STRING_PATTERN);
|
|
143
|
+
return new RegExp(pattern, flags);
|
|
144
|
+
},
|
|
145
|
+
isTerminal: true
|
|
146
|
+
},
|
|
147
|
+
set: {
|
|
148
|
+
condition(data) {
|
|
149
|
+
return data instanceof Set;
|
|
150
|
+
},
|
|
151
|
+
serialize(data) {
|
|
152
|
+
return Array.from(data);
|
|
153
|
+
},
|
|
154
|
+
deserialize(serialized) {
|
|
155
|
+
return new Set(serialized);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
map: {
|
|
159
|
+
condition(data) {
|
|
160
|
+
return data instanceof Map;
|
|
161
|
+
},
|
|
162
|
+
serialize(data) {
|
|
163
|
+
return Array.from(data.entries());
|
|
164
|
+
},
|
|
165
|
+
deserialize(serialized) {
|
|
166
|
+
return new Map(serialized);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
class RPCJsonSerializer {
|
|
171
|
+
handlers;
|
|
172
|
+
omitUndefinedProperties;
|
|
173
|
+
constructor(options = {}) {
|
|
174
|
+
this.handlers = {
|
|
175
|
+
...DEFAULT_RPC_JSON_SERIALIZER_HANDLERS,
|
|
176
|
+
...options.handlers
|
|
177
|
+
};
|
|
178
|
+
this.omitUndefinedProperties = options.omitUndefinedProperties !== false;
|
|
179
|
+
}
|
|
180
|
+
serialize(data) {
|
|
181
|
+
const [json, meta_, maps, blobs] = this.serializeValue(data, [], [], [], []);
|
|
182
|
+
const meta = meta_.length === 0 ? void 0 : meta_;
|
|
183
|
+
if (maps.length === 0) {
|
|
184
|
+
return { json, meta };
|
|
185
|
+
}
|
|
186
|
+
return { json, meta, maps, blobs };
|
|
187
|
+
}
|
|
188
|
+
serializeValue(data, segments, meta, maps, blobs) {
|
|
189
|
+
for (const key in this.handlers) {
|
|
190
|
+
const handler = this.handlers[key];
|
|
191
|
+
if (handler && handler.condition(data)) {
|
|
192
|
+
const serialized = handler.serialize(data);
|
|
193
|
+
if (handler.isTerminal) {
|
|
194
|
+
meta.push([key, ...segments]);
|
|
195
|
+
return [serialized, meta, maps, blobs];
|
|
196
|
+
}
|
|
197
|
+
const result = this.serializeValue(serialized, segments, meta, maps, blobs);
|
|
198
|
+
meta.push([key, ...segments]);
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (data instanceof Blob) {
|
|
203
|
+
maps.push(segments);
|
|
204
|
+
blobs.push(data);
|
|
205
|
+
return [data, meta, maps, blobs];
|
|
206
|
+
}
|
|
207
|
+
if (Array.isArray(data)) {
|
|
208
|
+
const json = data.map((v, i) => {
|
|
209
|
+
return this.serializeValue(v, [...segments, i], meta, maps, blobs)[0];
|
|
210
|
+
});
|
|
211
|
+
return [json, meta, maps, blobs];
|
|
212
|
+
}
|
|
213
|
+
if (isPlainObject(data)) {
|
|
214
|
+
const json = {};
|
|
215
|
+
for (const k in data) {
|
|
216
|
+
const v = data[k];
|
|
217
|
+
if (k === "toJSON" && typeof v === "function") {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (v === void 0 && this.omitUndefinedProperties) {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
json[k] = this.serializeValue(v, [...segments, k], meta, maps, blobs)[0];
|
|
224
|
+
}
|
|
225
|
+
return [json, meta, maps, blobs];
|
|
226
|
+
}
|
|
227
|
+
return [data, meta, maps, blobs];
|
|
228
|
+
}
|
|
229
|
+
deserialize(serialized) {
|
|
230
|
+
const ref = { data: serialized.json };
|
|
231
|
+
if (serialized.blobs?.length) {
|
|
232
|
+
serialized.maps.forEach((segments, i) => {
|
|
233
|
+
let currentRef = ref;
|
|
234
|
+
let preSegment = "data";
|
|
235
|
+
segments.forEach((segment) => {
|
|
236
|
+
currentRef = currentRef[preSegment];
|
|
237
|
+
preSegment = segment;
|
|
238
|
+
if (!Object.hasOwn(currentRef, preSegment)) {
|
|
239
|
+
throw new Error(`Security error: Invalid serialized data. Segment "${preSegment}" does not exist.`);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
currentRef[preSegment] = serialized.blobs[i];
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
serialized.meta?.forEach((item) => {
|
|
246
|
+
const type = item[0];
|
|
247
|
+
let currentRef = ref;
|
|
248
|
+
let preSegment = "data";
|
|
249
|
+
for (let i = 1; i < item.length; i++) {
|
|
250
|
+
currentRef = currentRef[preSegment];
|
|
251
|
+
preSegment = item[i];
|
|
252
|
+
if (!Object.hasOwn(currentRef, preSegment)) {
|
|
253
|
+
throw new Error(`Security error: Invalid serialized data. Segment "${preSegment}" does not exist.`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
currentRef[preSegment] = this.handlers[type].deserialize(currentRef[preSegment]);
|
|
257
|
+
});
|
|
258
|
+
return ref.data;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
class RPCSerializer {
|
|
263
|
+
jsonSerializer;
|
|
264
|
+
defaultSerializeOptions;
|
|
265
|
+
constructor(options = {}) {
|
|
266
|
+
this.jsonSerializer = new RPCJsonSerializer(options);
|
|
267
|
+
this.defaultSerializeOptions = options.serialize;
|
|
268
|
+
}
|
|
269
|
+
serialize(data, options = {}) {
|
|
270
|
+
if (data === void 0 || data instanceof ReadableStream || data instanceof Blob) {
|
|
271
|
+
return data;
|
|
272
|
+
}
|
|
273
|
+
if (isAsyncIteratorObject(data)) {
|
|
274
|
+
return wrapAsyncIteratorPreservingEventMeta(data, {
|
|
275
|
+
mapResult: (result) => {
|
|
276
|
+
if (result.value === void 0) {
|
|
277
|
+
return result;
|
|
278
|
+
}
|
|
279
|
+
return { done: result.done, value: this.serializeValue(result.value, options) };
|
|
280
|
+
},
|
|
281
|
+
mapError: (e) => new ErrorEvent(
|
|
282
|
+
this.serializeValue(toORPCError(e).toJSON(), { ...options, useFormDataForBlobFields: false }),
|
|
283
|
+
{ cause: e }
|
|
284
|
+
)
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
return this.serializeValue(data, options);
|
|
288
|
+
}
|
|
289
|
+
serializeValue(data, options) {
|
|
290
|
+
const useFormDataForBlobs = options.useFormDataForBlobFields ?? this.defaultSerializeOptions?.useFormDataForBlobFields ?? true;
|
|
291
|
+
const { json, meta, maps, blobs } = this.jsonSerializer.serialize(data);
|
|
292
|
+
if (!useFormDataForBlobs || !blobs?.length) {
|
|
293
|
+
return { json, meta };
|
|
294
|
+
}
|
|
295
|
+
const form = new FormData();
|
|
296
|
+
form.set("data", stringifyJSON({ json, meta, maps }));
|
|
297
|
+
blobs.forEach((blob, i) => {
|
|
298
|
+
form.set(i.toString(), blob);
|
|
299
|
+
});
|
|
300
|
+
return form;
|
|
301
|
+
}
|
|
302
|
+
deserialize(data) {
|
|
303
|
+
if (data === void 0 || data instanceof ReadableStream || data instanceof Blob) {
|
|
304
|
+
return data;
|
|
305
|
+
}
|
|
306
|
+
if (isAsyncIteratorObject(data)) {
|
|
307
|
+
return wrapAsyncIteratorPreservingEventMeta(data, {
|
|
308
|
+
mapResult: (result) => {
|
|
309
|
+
if (result.value === void 0) {
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
return { done: result.done, value: this.deserializeValue(result.value) };
|
|
313
|
+
},
|
|
314
|
+
mapError: (e) => {
|
|
315
|
+
if (!(e instanceof ErrorEvent)) {
|
|
316
|
+
return e;
|
|
317
|
+
}
|
|
318
|
+
const deserialized = this.deserializeValue(e.data);
|
|
319
|
+
if (isORPCErrorJson(deserialized)) {
|
|
320
|
+
return createORPCErrorFromJson(deserialized, { cause: e });
|
|
321
|
+
}
|
|
322
|
+
return new ErrorEvent(deserialized, { cause: e });
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
return this.deserializeValue(data);
|
|
327
|
+
}
|
|
328
|
+
deserializeValue(data) {
|
|
329
|
+
if (!(data instanceof FormData)) {
|
|
330
|
+
return this.jsonSerializer.deserialize(data);
|
|
331
|
+
}
|
|
332
|
+
const serialized = JSON.parse(data.get("data"));
|
|
333
|
+
const blobs = [];
|
|
334
|
+
for (const [key, value] of data) {
|
|
335
|
+
if (value instanceof Blob) {
|
|
336
|
+
blobs[Number(key)] = value;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return this.jsonSerializer.deserialize({ ...serialized, blobs });
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export { RPCSerializer as R, isInferableError as a, RPCJsonSerializer as b, createORPCErrorFromJson as c, cloneORPCError as d, isORPCErrorJson as i, toORPCError as t, wrapAsyncIteratorPreservingEventMeta as w };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.14.
|
|
4
|
+
"version": "1.14.11",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"exports": {
|
|
17
|
+
"./package.json": "./package.json",
|
|
17
18
|
".": {
|
|
18
19
|
"types": "./dist/index.d.mts",
|
|
19
20
|
"import": "./dist/index.mjs",
|
|
@@ -49,17 +50,16 @@
|
|
|
49
50
|
"dist"
|
|
50
51
|
],
|
|
51
52
|
"dependencies": {
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
55
|
-
"@orpc/
|
|
53
|
+
"@standardserver/core": "^0.5.0",
|
|
54
|
+
"@standardserver/fetch": "^0.5.0",
|
|
55
|
+
"@standardserver/peer": "^0.5.0",
|
|
56
|
+
"@orpc/shared": "1.14.11"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
|
-
"zod": "^4.3
|
|
59
|
+
"zod": "^4.4.3"
|
|
59
60
|
},
|
|
60
61
|
"scripts": {
|
|
61
62
|
"build": "unbuild",
|
|
62
|
-
"build:watch": "pnpm run build --watch",
|
|
63
63
|
"type:check": "tsc -b"
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Interceptor } from '@orpc/shared';
|
|
2
|
-
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
-
import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.i2uoJbEp.js';
|
|
4
|
-
|
|
5
|
-
interface StandardLinkPlugin<T extends ClientContext> {
|
|
6
|
-
order?: number;
|
|
7
|
-
init?(options: StandardLinkOptions<T>): void;
|
|
8
|
-
}
|
|
9
|
-
declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin extends StandardLinkPlugin<T>> implements StandardLinkPlugin<T> {
|
|
10
|
-
protected readonly plugins: TPlugin[];
|
|
11
|
-
constructor(plugins?: readonly TPlugin[]);
|
|
12
|
-
init(options: StandardLinkOptions<T>): void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface StandardLinkCodec<T extends ClientContext> {
|
|
16
|
-
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
17
|
-
decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
|
|
18
|
-
}
|
|
19
|
-
interface StandardLinkClient<T extends ClientContext> {
|
|
20
|
-
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
24
|
-
path: readonly string[];
|
|
25
|
-
input: unknown;
|
|
26
|
-
}
|
|
27
|
-
interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
|
28
|
-
request: StandardRequest;
|
|
29
|
-
}
|
|
30
|
-
interface StandardLinkOptions<T extends ClientContext> {
|
|
31
|
-
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
|
|
32
|
-
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
|
|
33
|
-
plugins?: StandardLinkPlugin<T>[];
|
|
34
|
-
}
|
|
35
|
-
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
36
|
-
readonly codec: StandardLinkCodec<T>;
|
|
37
|
-
readonly sender: StandardLinkClient<T>;
|
|
38
|
-
private readonly interceptors;
|
|
39
|
-
private readonly clientInterceptors;
|
|
40
|
-
constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
|
|
41
|
-
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export { CompositeStandardLinkPlugin as C, StandardLink as d };
|
|
45
|
-
export type { StandardLinkClientInterceptorOptions as S, StandardLinkPlugin as a, StandardLinkOptions as b, StandardLinkInterceptorOptions as c, StandardLinkCodec as e, StandardLinkClient as f };
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.i2uoJbEp.js';
|
|
2
|
-
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.2jUAqzYU.js';
|
|
3
|
-
import { Segment, Value, Promisable } 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<Promisable<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<Promisable<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<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [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, 'HEAD' | 'GET'>;
|
|
67
|
-
/**
|
|
68
|
-
* Inject headers to the request.
|
|
69
|
-
*/
|
|
70
|
-
headers?: Value<Promisable<StandardHeaders | Headers>, [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
|
-
declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
87
|
-
constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
|
|
91
|
-
export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h };
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.i2uoJbEp.mjs';
|
|
2
|
-
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.CpCa3si8.mjs';
|
|
3
|
-
import { Segment, Value, Promisable } 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<Promisable<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<Promisable<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<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [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, 'HEAD' | 'GET'>;
|
|
67
|
-
/**
|
|
68
|
-
* Inject headers to the request.
|
|
69
|
-
*/
|
|
70
|
-
headers?: Value<Promisable<StandardHeaders | Headers>, [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
|
-
declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
87
|
-
constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
|
|
91
|
-
export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h };
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
|
|
2
|
-
import { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
|
3
|
-
|
|
4
|
-
function mapEventIterator(iterator, maps) {
|
|
5
|
-
const mapError = async (error) => {
|
|
6
|
-
let mappedError = await maps.error(error);
|
|
7
|
-
if (mappedError !== error) {
|
|
8
|
-
const meta = getEventMeta(error);
|
|
9
|
-
if (meta && isTypescriptObject(mappedError)) {
|
|
10
|
-
mappedError = withEventMeta(mappedError, meta);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return mappedError;
|
|
14
|
-
};
|
|
15
|
-
return new AsyncIteratorClass(async () => {
|
|
16
|
-
const { done, value } = await (async () => {
|
|
17
|
-
try {
|
|
18
|
-
return await iterator.next();
|
|
19
|
-
} catch (error) {
|
|
20
|
-
throw await mapError(error);
|
|
21
|
-
}
|
|
22
|
-
})();
|
|
23
|
-
let mappedValue = await maps.value(value, done);
|
|
24
|
-
if (mappedValue !== value) {
|
|
25
|
-
const meta = getEventMeta(value);
|
|
26
|
-
if (meta && isTypescriptObject(mappedValue)) {
|
|
27
|
-
mappedValue = withEventMeta(mappedValue, meta);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return { done, value: mappedValue };
|
|
31
|
-
}, async () => {
|
|
32
|
-
try {
|
|
33
|
-
await iterator.return?.();
|
|
34
|
-
} catch (error) {
|
|
35
|
-
throw await mapError(error);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export { mapEventIterator as m };
|