@orpc/client 0.0.0-next.f16d90e → 0.0.0-next.f21e305
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 +8 -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 +12 -12
- package/dist/adapters/message-port/index.d.ts +12 -12
- package/dist/adapters/message-port/index.mjs +9 -8
- 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 +25 -10
- 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 +12 -4
- package/dist/plugins/index.d.ts +12 -4
- package/dist/plugins/index.mjs +45 -25
- package/dist/shared/{client.C0KbSWlC.d.ts → client.BG98rYdO.d.ts} +1 -2
- package/dist/shared/{client.DpICn1BD.mjs → client.BIYmXux0.mjs} +62 -20
- 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.BMoG_EdN.d.mts → client.Bwgm6dgk.d.mts} +1 -2
- package/dist/shared/{client.CRWEpqLB.mjs → client.C9Q9FzmH.mjs} +66 -33
- package/dist/shared/{client.7UM0t5o-.d.ts → client.CVVVqf1Y.d.ts} +3 -3
- package/dist/shared/{client.BdD8cpjs.d.mts → client._Y_enhib.d.mts} +3 -3
- package/package.json +6 -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.C9Q9FzmH.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 };
|
@@ -26,4 +26,4 @@ interface ClientLink<TClientContext extends ClientContext> {
|
|
26
26
|
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
27
27
|
}
|
28
28
|
|
29
|
-
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N,
|
29
|
+
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f };
|
@@ -26,4 +26,4 @@ interface ClientLink<TClientContext extends ClientContext> {
|
|
26
26
|
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
27
27
|
}
|
28
28
|
|
29
|
-
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N,
|
29
|
+
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f };
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Interceptor } from '@orpc/shared';
|
2
2
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
3
|
-
import {
|
3
|
+
import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.BOYsZIRq.mjs';
|
4
4
|
|
5
5
|
interface StandardLinkPlugin<T extends ClientContext> {
|
6
6
|
order?: number;
|
@@ -33,7 +33,6 @@ interface StandardLinkOptions<T extends ClientContext> {
|
|
33
33
|
plugins?: StandardLinkPlugin<T>[];
|
34
34
|
}
|
35
35
|
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
36
|
-
#private;
|
37
36
|
readonly codec: StandardLinkCodec<T>;
|
38
37
|
readonly sender: StandardLinkClient<T>;
|
39
38
|
private readonly interceptors;
|
@@ -1,6 +1,9 @@
|
|
1
|
-
import { isObject, isTypescriptObject } from '@orpc/shared';
|
1
|
+
import { resolveMaybeOptionalOptions, getConstructor, isObject, AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
|
2
2
|
import { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
3
3
|
|
4
|
+
const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
|
5
|
+
const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.f21e305";
|
6
|
+
|
4
7
|
const COMMON_ORPC_ERROR_DEFS = {
|
5
8
|
BAD_REQUEST: {
|
6
9
|
status: 400,
|
@@ -85,21 +88,25 @@ function fallbackORPCErrorStatus(code, status) {
|
|
85
88
|
function fallbackORPCErrorMessage(code, message) {
|
86
89
|
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
87
90
|
}
|
91
|
+
const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(`__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`);
|
92
|
+
void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet());
|
93
|
+
const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL];
|
88
94
|
class ORPCError extends Error {
|
89
95
|
defined;
|
90
96
|
code;
|
91
97
|
status;
|
92
98
|
data;
|
93
|
-
constructor(code, ...
|
94
|
-
|
99
|
+
constructor(code, ...rest) {
|
100
|
+
const options = resolveMaybeOptionalOptions(rest);
|
101
|
+
if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
|
95
102
|
throw new Error("[ORPCError] Invalid error status code.");
|
96
103
|
}
|
97
|
-
const message = fallbackORPCErrorMessage(code, options
|
104
|
+
const message = fallbackORPCErrorMessage(code, options.message);
|
98
105
|
super(message, options);
|
99
106
|
this.code = code;
|
100
|
-
this.status = fallbackORPCErrorStatus(code, options
|
101
|
-
this.defined = options
|
102
|
-
this.data = options
|
107
|
+
this.status = fallbackORPCErrorStatus(code, options.status);
|
108
|
+
this.defined = options.defined ?? false;
|
109
|
+
this.data = options.data;
|
103
110
|
}
|
104
111
|
toJSON() {
|
105
112
|
return {
|
@@ -110,7 +117,29 @@ class ORPCError extends Error {
|
|
110
117
|
data: this.data
|
111
118
|
};
|
112
119
|
}
|
120
|
+
/**
|
121
|
+
* Workaround for Next.js where different contexts use separate
|
122
|
+
* dependency graphs, causing multiple ORPCError constructors existing and breaking
|
123
|
+
* `instanceof` checks across contexts.
|
124
|
+
*
|
125
|
+
* This is particularly problematic with "Optimized SSR", where orpc-client
|
126
|
+
* executes in one context but is invoked from another. When an error is thrown
|
127
|
+
* in the execution context, `instanceof ORPCError` checks fail in the
|
128
|
+
* invocation context due to separate class constructors.
|
129
|
+
*
|
130
|
+
* @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
|
131
|
+
*/
|
132
|
+
static [Symbol.hasInstance](instance) {
|
133
|
+
if (globalORPCErrorConstructors.has(this)) {
|
134
|
+
const constructor = getConstructor(instance);
|
135
|
+
if (constructor && globalORPCErrorConstructors.has(constructor)) {
|
136
|
+
return true;
|
137
|
+
}
|
138
|
+
}
|
139
|
+
return super[Symbol.hasInstance](instance);
|
140
|
+
}
|
113
141
|
}
|
142
|
+
globalORPCErrorConstructors.add(ORPCError);
|
114
143
|
function isDefinedError(error) {
|
115
144
|
return error instanceof ORPCError && error.defined;
|
116
145
|
}
|
@@ -141,35 +170,39 @@ function createORPCErrorFromJson(json, options = {}) {
|
|
141
170
|
}
|
142
171
|
|
143
172
|
function mapEventIterator(iterator, maps) {
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
const meta = getEventMeta(value);
|
151
|
-
if (meta && isTypescriptObject(mappedValue)) {
|
152
|
-
mappedValue = withEventMeta(mappedValue, meta);
|
153
|
-
}
|
154
|
-
}
|
155
|
-
if (done) {
|
156
|
-
return mappedValue;
|
157
|
-
}
|
158
|
-
yield mappedValue;
|
173
|
+
const mapError = async (error) => {
|
174
|
+
let mappedError = await maps.error(error);
|
175
|
+
if (mappedError !== error) {
|
176
|
+
const meta = getEventMeta(error);
|
177
|
+
if (meta && isTypescriptObject(mappedError)) {
|
178
|
+
mappedError = withEventMeta(mappedError, meta);
|
159
179
|
}
|
160
|
-
}
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
180
|
+
}
|
181
|
+
return mappedError;
|
182
|
+
};
|
183
|
+
return new AsyncIteratorClass(async () => {
|
184
|
+
const { done, value } = await (async () => {
|
185
|
+
try {
|
186
|
+
return await iterator.next();
|
187
|
+
} catch (error) {
|
188
|
+
throw await mapError(error);
|
189
|
+
}
|
190
|
+
})();
|
191
|
+
let mappedValue = await maps.value(value, done);
|
192
|
+
if (mappedValue !== value) {
|
193
|
+
const meta = getEventMeta(value);
|
194
|
+
if (meta && isTypescriptObject(mappedValue)) {
|
195
|
+
mappedValue = withEventMeta(mappedValue, meta);
|
167
196
|
}
|
168
|
-
|
169
|
-
|
197
|
+
}
|
198
|
+
return { done, value: mappedValue };
|
199
|
+
}, async () => {
|
200
|
+
try {
|
170
201
|
await iterator.return?.();
|
202
|
+
} catch (error) {
|
203
|
+
throw await mapError(error);
|
171
204
|
}
|
172
|
-
}
|
205
|
+
});
|
173
206
|
}
|
174
207
|
|
175
|
-
export { COMMON_ORPC_ERROR_DEFS as C,
|
208
|
+
export { COMMON_ORPC_ERROR_DEFS as C, ORPC_CLIENT_PACKAGE_NAME as O, ORPC_CLIENT_PACKAGE_VERSION as a, fallbackORPCErrorMessage as b, ORPCError as c, isORPCErrorStatus as d, isORPCErrorJson as e, fallbackORPCErrorStatus as f, createORPCErrorFromJson as g, isDefinedError as i, mapEventIterator as m, toORPCError as t };
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.
|
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
3
|
import { Segment, Value, Promisable } from '@orpc/shared';
|
4
4
|
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
5
5
|
|
@@ -67,7 +67,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
67
67
|
/**
|
68
68
|
* Inject headers to the request.
|
69
69
|
*/
|
70
|
-
headers?: Value<Promisable<StandardHeaders>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
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,5 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.
|
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
3
|
import { Segment, Value, Promisable } from '@orpc/shared';
|
4
4
|
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
5
5
|
|
@@ -67,7 +67,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
67
67
|
/**
|
68
68
|
* Inject headers to the request.
|
69
69
|
*/
|
70
|
-
headers?: Value<Promisable<StandardHeaders>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
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.f21e305",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -49,13 +49,13 @@
|
|
49
49
|
"dist"
|
50
50
|
],
|
51
51
|
"dependencies": {
|
52
|
-
"@orpc/standard-server": "0.0.0-next.
|
53
|
-
"@orpc/
|
54
|
-
"@orpc/
|
55
|
-
"@orpc/standard-server-peer": "0.0.0-next.
|
52
|
+
"@orpc/standard-server": "0.0.0-next.f21e305",
|
53
|
+
"@orpc/shared": "0.0.0-next.f21e305",
|
54
|
+
"@orpc/standard-server-fetch": "0.0.0-next.f21e305",
|
55
|
+
"@orpc/standard-server-peer": "0.0.0-next.f21e305"
|
56
56
|
},
|
57
57
|
"devDependencies": {
|
58
|
-
"zod": "^
|
58
|
+
"zod": "^4.1.5"
|
59
59
|
},
|
60
60
|
"scripts": {
|
61
61
|
"build": "unbuild",
|