@orpc/client 0.0.0-next.e000d9a → 0.0.0-next.e02ffab
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 +11 -8
- package/dist/adapters/fetch/index.d.mts +23 -10
- package/dist/adapters/fetch/index.d.ts +23 -10
- package/dist/adapters/fetch/index.mjs +24 -8
- package/dist/adapters/message-port/index.d.mts +59 -0
- package/dist/adapters/message-port/index.d.ts +59 -0
- package/dist/adapters/message-port/index.mjs +72 -0
- package/dist/adapters/standard/index.d.mts +6 -5
- package/dist/adapters/standard/index.d.ts +6 -5
- package/dist/adapters/standard/index.mjs +3 -2
- package/dist/adapters/websocket/index.d.mts +12 -12
- package/dist/adapters/websocket/index.d.ts +12 -12
- package/dist/adapters/websocket/index.mjs +26 -11
- package/dist/index.d.mts +86 -25
- package/dist/index.d.ts +86 -25
- package/dist/index.mjs +54 -8
- package/dist/plugins/index.d.mts +58 -17
- package/dist/plugins/index.d.ts +58 -17
- package/dist/plugins/index.mjs +143 -27
- package/dist/shared/{client.7ZYxJok_.d.ts → client.BG98rYdO.d.ts} +4 -5
- package/dist/shared/{client.4TS_0JaO.d.mts → client.BOYsZIRq.d.mts} +1 -1
- package/dist/shared/{client.4TS_0JaO.d.ts → client.BOYsZIRq.d.ts} +1 -1
- package/dist/shared/{client.CRWEpqLB.mjs → client.BehDOHFi.mjs} +66 -33
- package/dist/shared/{client.ds1abV85.d.mts → client.Bwgm6dgk.d.mts} +4 -5
- package/dist/shared/{client.DpICn1BD.mjs → client.CUaaPQW9.mjs} +62 -20
- package/dist/shared/{client.B2432-Lu.d.ts → client.CVVVqf1Y.d.ts} +7 -7
- package/dist/shared/{client.ClwIM_ku.d.mts → client._Y_enhib.d.mts} +7 -7
- package/package.json +11 -6
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { toArray, intercept, isObject, value,
|
|
1
|
+
import { toArray, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, intercept, getGlobalOtelConfig, isObject, value, stringifyJSON } from '@orpc/shared';
|
|
2
2
|
import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
|
|
3
|
-
import { C as COMMON_ORPC_ERROR_DEFS,
|
|
3
|
+
import { C as COMMON_ORPC_ERROR_DEFS, d as isORPCErrorStatus, e as isORPCErrorJson, g as createORPCErrorFromJson, c as ORPCError, m as mapEventIterator, t as toORPCError } from './client.BehDOHFi.mjs';
|
|
4
|
+
import { toStandardHeaders as toStandardHeaders$1 } from '@orpc/standard-server-fetch';
|
|
4
5
|
|
|
5
6
|
class CompositeStandardLinkPlugin {
|
|
6
7
|
plugins;
|
|
@@ -26,20 +27,52 @@ class StandardLink {
|
|
|
26
27
|
interceptors;
|
|
27
28
|
clientInterceptors;
|
|
28
29
|
call(path, input, options) {
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
return runWithSpan(
|
|
31
|
+
{ name: `${ORPC_NAME}.${path.join("/")}`, signal: options.signal },
|
|
32
|
+
(span) => {
|
|
33
|
+
span?.setAttribute("rpc.system", ORPC_NAME);
|
|
34
|
+
span?.setAttribute("rpc.method", path.join("."));
|
|
35
|
+
if (isAsyncIteratorObject(input)) {
|
|
36
|
+
input = asyncIteratorWithSpan(
|
|
37
|
+
{ name: "consume_event_iterator_input", signal: options.signal },
|
|
38
|
+
input
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
|
|
42
|
+
const otelConfig = getGlobalOtelConfig();
|
|
43
|
+
let otelContext;
|
|
44
|
+
const currentSpan = otelConfig?.trace.getActiveSpan() ?? span;
|
|
45
|
+
if (currentSpan && otelConfig) {
|
|
46
|
+
otelContext = otelConfig?.trace.setSpan(otelConfig.context.active(), currentSpan);
|
|
47
|
+
}
|
|
48
|
+
const request = await runWithSpan(
|
|
49
|
+
{ name: "encode_request", context: otelContext },
|
|
50
|
+
() => this.codec.encode(path2, input2, options2)
|
|
51
|
+
);
|
|
52
|
+
const response = await intercept(
|
|
53
|
+
this.clientInterceptors,
|
|
54
|
+
{ ...options2, input: input2, path: path2, request },
|
|
55
|
+
({ input: input3, path: path3, request: request2, ...options3 }) => {
|
|
56
|
+
return runWithSpan(
|
|
57
|
+
{ name: "send_request", signal: options3.signal, context: otelContext },
|
|
58
|
+
() => this.sender.call(request2, options3, path3, input3)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
const output = await runWithSpan(
|
|
63
|
+
{ name: "decode_response", context: otelContext },
|
|
64
|
+
() => this.codec.decode(response, options2, path2, input2)
|
|
65
|
+
);
|
|
66
|
+
if (isAsyncIteratorObject(output)) {
|
|
67
|
+
return asyncIteratorWithSpan(
|
|
68
|
+
{ name: "consume_event_iterator_output", signal: options2.signal },
|
|
69
|
+
output
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return output;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
40
75
|
);
|
|
41
|
-
const output = await this.codec.decode(response, options, path, input);
|
|
42
|
-
return output;
|
|
43
76
|
}
|
|
44
77
|
}
|
|
45
78
|
|
|
@@ -192,6 +225,12 @@ class StandardRPCJsonSerializer {
|
|
|
192
225
|
function toHttpPath(path) {
|
|
193
226
|
return `/${path.map(encodeURIComponent).join("/")}`;
|
|
194
227
|
}
|
|
228
|
+
function toStandardHeaders(headers) {
|
|
229
|
+
if (typeof headers.forEach === "function") {
|
|
230
|
+
return toStandardHeaders$1(headers);
|
|
231
|
+
}
|
|
232
|
+
return headers;
|
|
233
|
+
}
|
|
195
234
|
function getMalformedResponseErrorCode(status) {
|
|
196
235
|
return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE";
|
|
197
236
|
}
|
|
@@ -211,14 +250,14 @@ class StandardRPCLinkCodec {
|
|
|
211
250
|
expectedMethod;
|
|
212
251
|
headers;
|
|
213
252
|
async encode(path, input, options) {
|
|
253
|
+
let headers = toStandardHeaders(await value(this.headers, options, path, input));
|
|
254
|
+
if (options.lastEventId !== void 0) {
|
|
255
|
+
headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
|
|
256
|
+
}
|
|
214
257
|
const expectedMethod = await value(this.expectedMethod, options, path, input);
|
|
215
|
-
let headers = await value(this.headers, options, path, input);
|
|
216
258
|
const baseUrl = await value(this.baseUrl, options, path, input);
|
|
217
259
|
const url = new URL(baseUrl);
|
|
218
260
|
url.pathname = `${url.pathname.replace(/\/$/, "")}${toHttpPath(path)}`;
|
|
219
|
-
if (options.lastEventId !== void 0) {
|
|
220
|
-
headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
|
|
221
|
-
}
|
|
222
261
|
const serialized = this.serializer.serialize(input);
|
|
223
262
|
if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
|
|
224
263
|
const maxUrlLength = await value(this.maxUrlLength, options, path, input);
|
|
@@ -330,6 +369,9 @@ class StandardRPCSerializer {
|
|
|
330
369
|
return this.#deserialize(data);
|
|
331
370
|
}
|
|
332
371
|
#deserialize(data) {
|
|
372
|
+
if (data === void 0) {
|
|
373
|
+
return void 0;
|
|
374
|
+
}
|
|
333
375
|
if (!(data instanceof FormData)) {
|
|
334
376
|
return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
|
|
335
377
|
}
|
|
@@ -352,4 +394,4 @@ class StandardRPCLink extends StandardLink {
|
|
|
352
394
|
}
|
|
353
395
|
}
|
|
354
396
|
|
|
355
|
-
export { CompositeStandardLinkPlugin as C, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLink as c, StandardRPCLinkCodec as d, StandardRPCSerializer as e, getMalformedResponseErrorCode as g, toHttpPath as t };
|
|
397
|
+
export { CompositeStandardLinkPlugin as C, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLink as c, StandardRPCLinkCodec as d, StandardRPCSerializer as e, toStandardHeaders as f, getMalformedResponseErrorCode as g, toHttpPath as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.
|
|
3
|
-
import { Segment, Value } from '@orpc/shared';
|
|
1
|
+
import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BOYsZIRq.js';
|
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.BG98rYdO.js';
|
|
3
|
+
import { Segment, Value, Promisable } from '@orpc/shared';
|
|
4
4
|
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
5
|
|
|
6
6
|
declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
|
|
@@ -44,19 +44,19 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Base url for all requests.
|
|
46
46
|
*/
|
|
47
|
-
url: Value<string | URL
|
|
47
|
+
url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
48
48
|
/**
|
|
49
49
|
* The maximum length of the URL.
|
|
50
50
|
*
|
|
51
51
|
* @default 2083
|
|
52
52
|
*/
|
|
53
|
-
maxUrlLength?: Value<number
|
|
53
|
+
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
54
54
|
/**
|
|
55
55
|
* The method used to make the request.
|
|
56
56
|
*
|
|
57
57
|
* @default 'POST'
|
|
58
58
|
*/
|
|
59
|
-
method?: Value<Exclude<HTTPMethod, 'HEAD'
|
|
59
|
+
method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
60
60
|
/**
|
|
61
61
|
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
62
62
|
* GET is not allowed, it's very dangerous.
|
|
@@ -67,7 +67,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
|
67
67
|
/**
|
|
68
68
|
* Inject headers to the request.
|
|
69
69
|
*/
|
|
70
|
-
headers?: Value<StandardHeaders
|
|
70
|
+
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
71
71
|
}
|
|
72
72
|
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
73
73
|
private readonly serializer;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.
|
|
3
|
-
import { Segment, Value } from '@orpc/shared';
|
|
1
|
+
import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BOYsZIRq.mjs';
|
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.Bwgm6dgk.mjs';
|
|
3
|
+
import { Segment, Value, Promisable } from '@orpc/shared';
|
|
4
4
|
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
5
|
|
|
6
6
|
declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
|
|
@@ -44,19 +44,19 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Base url for all requests.
|
|
46
46
|
*/
|
|
47
|
-
url: Value<string | URL
|
|
47
|
+
url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
48
48
|
/**
|
|
49
49
|
* The maximum length of the URL.
|
|
50
50
|
*
|
|
51
51
|
* @default 2083
|
|
52
52
|
*/
|
|
53
|
-
maxUrlLength?: Value<number
|
|
53
|
+
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
54
54
|
/**
|
|
55
55
|
* The method used to make the request.
|
|
56
56
|
*
|
|
57
57
|
* @default 'POST'
|
|
58
58
|
*/
|
|
59
|
-
method?: Value<Exclude<HTTPMethod, 'HEAD'
|
|
59
|
+
method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
60
60
|
/**
|
|
61
61
|
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
62
62
|
* GET is not allowed, it's very dangerous.
|
|
@@ -67,7 +67,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
|
67
67
|
/**
|
|
68
68
|
* Inject headers to the request.
|
|
69
69
|
*/
|
|
70
|
-
headers?: Value<StandardHeaders
|
|
70
|
+
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
71
71
|
}
|
|
72
72
|
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
73
73
|
private readonly serializer;
|
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.e02ffab",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -38,19 +38,24 @@
|
|
|
38
38
|
"types": "./dist/adapters/websocket/index.d.mts",
|
|
39
39
|
"import": "./dist/adapters/websocket/index.mjs",
|
|
40
40
|
"default": "./dist/adapters/websocket/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./message-port": {
|
|
43
|
+
"types": "./dist/adapters/message-port/index.d.mts",
|
|
44
|
+
"import": "./dist/adapters/message-port/index.mjs",
|
|
45
|
+
"default": "./dist/adapters/message-port/index.mjs"
|
|
41
46
|
}
|
|
42
47
|
},
|
|
43
48
|
"files": [
|
|
44
49
|
"dist"
|
|
45
50
|
],
|
|
46
51
|
"dependencies": {
|
|
47
|
-
"@orpc/shared": "0.0.0-next.
|
|
48
|
-
"@orpc/standard-server
|
|
49
|
-
"@orpc/standard-server-
|
|
50
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
52
|
+
"@orpc/shared": "0.0.0-next.e02ffab",
|
|
53
|
+
"@orpc/standard-server": "0.0.0-next.e02ffab",
|
|
54
|
+
"@orpc/standard-server-fetch": "0.0.0-next.e02ffab",
|
|
55
|
+
"@orpc/standard-server-peer": "0.0.0-next.e02ffab"
|
|
51
56
|
},
|
|
52
57
|
"devDependencies": {
|
|
53
|
-
"zod": "^
|
|
58
|
+
"zod": "^4.1.11"
|
|
54
59
|
},
|
|
55
60
|
"scripts": {
|
|
56
61
|
"build": "unbuild",
|