@orpc/client 0.0.0-next.ee46dab → 0.0.0-next.ee89076
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 +19 -22
- package/dist/adapters/fetch/index.d.mts +31 -11
- package/dist/adapters/fetch/index.d.ts +31 -11
- package/dist/adapters/fetch/index.mjs +26 -13
- 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 +29 -0
- package/dist/adapters/websocket/index.d.ts +29 -0
- package/dist/adapters/websocket/index.mjs +46 -0
- package/dist/index.d.mts +53 -23
- package/dist/index.d.ts +53 -23
- package/dist/index.mjs +25 -8
- package/dist/plugins/index.d.mts +162 -25
- package/dist/plugins/index.d.ts +162 -25
- package/dist/plugins/index.mjs +331 -56
- package/dist/shared/{client.5813Ufvs.d.mts → client.BG98rYdO.d.ts} +21 -15
- package/dist/shared/{client.C0lT7w02.d.mts → client.BOYsZIRq.d.mts} +8 -9
- package/dist/shared/{client.C0lT7w02.d.ts → client.BOYsZIRq.d.ts} +8 -9
- package/dist/shared/{client.DSPm2IGZ.mjs → client.Bp1jlnBk.mjs} +89 -29
- package/dist/shared/{client.grRbC25r.d.ts → client.Bwgm6dgk.d.mts} +21 -15
- package/dist/shared/{client.D-jrSuDb.d.ts → client.CVVVqf1Y.d.ts} +13 -25
- package/dist/shared/{client.Bt94sjrK.d.mts → client._Y_enhib.d.mts} +13 -25
- package/dist/shared/{client.jKEwIsRd.mjs → client.txdq_i5V.mjs} +54 -49
- package/package.json +16 -5
@@ -1,6 +1,16 @@
|
|
1
|
-
import { Interceptor
|
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.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
|
+
}
|
4
14
|
|
5
15
|
interface StandardLinkCodec<T extends ClientContext> {
|
6
16
|
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
@@ -10,24 +20,19 @@ interface StandardLinkClient<T extends ClientContext> {
|
|
10
20
|
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
11
21
|
}
|
12
22
|
|
13
|
-
|
23
|
+
interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
24
|
+
path: readonly string[];
|
25
|
+
input: unknown;
|
14
26
|
}
|
15
|
-
interface
|
16
|
-
|
27
|
+
interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
28
|
+
request: StandardRequest;
|
17
29
|
}
|
18
30
|
interface StandardLinkOptions<T extends ClientContext> {
|
19
|
-
interceptors?: Interceptor<
|
20
|
-
|
21
|
-
input: unknown;
|
22
|
-
options: ClientOptions<T>;
|
23
|
-
}, unknown, ThrowableError>[];
|
24
|
-
clientInterceptors?: Interceptor<{
|
25
|
-
request: StandardRequest;
|
26
|
-
}, StandardLazyResponse, ThrowableError>[];
|
31
|
+
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
|
32
|
+
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
|
27
33
|
plugins?: StandardLinkPlugin<T>[];
|
28
34
|
}
|
29
35
|
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
30
|
-
#private;
|
31
36
|
readonly codec: StandardLinkCodec<T>;
|
32
37
|
readonly sender: StandardLinkClient<T>;
|
33
38
|
private readonly interceptors;
|
@@ -36,4 +41,5 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
36
41
|
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
37
42
|
}
|
38
43
|
|
39
|
-
export {
|
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,15 +1,17 @@
|
|
1
1
|
import { PromiseWithError } from '@orpc/shared';
|
2
2
|
|
3
3
|
type HTTPPath = `/${string}`;
|
4
|
-
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
4
|
+
type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
5
5
|
type ClientContext = Record<PropertyKey, any>;
|
6
|
-
|
6
|
+
interface ClientOptions<T extends ClientContext> {
|
7
7
|
signal?: AbortSignal;
|
8
8
|
lastEventId?: string | undefined;
|
9
|
-
|
10
|
-
|
9
|
+
context: T;
|
10
|
+
}
|
11
|
+
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
12
|
+
context?: T;
|
11
13
|
} : {
|
12
|
-
context:
|
14
|
+
context: T;
|
13
15
|
});
|
14
16
|
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
15
17
|
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
@@ -20,11 +22,8 @@ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext,
|
|
20
22
|
[k: string]: NestedClient<TClientContext>;
|
21
23
|
};
|
22
24
|
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
23
|
-
type ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
|
24
|
-
context: TClientContext;
|
25
|
-
};
|
26
25
|
interface ClientLink<TClientContext extends ClientContext> {
|
27
26
|
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
28
27
|
}
|
29
28
|
|
30
|
-
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,15 +1,17 @@
|
|
1
1
|
import { PromiseWithError } from '@orpc/shared';
|
2
2
|
|
3
3
|
type HTTPPath = `/${string}`;
|
4
|
-
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
4
|
+
type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
5
5
|
type ClientContext = Record<PropertyKey, any>;
|
6
|
-
|
6
|
+
interface ClientOptions<T extends ClientContext> {
|
7
7
|
signal?: AbortSignal;
|
8
8
|
lastEventId?: string | undefined;
|
9
|
-
|
10
|
-
|
9
|
+
context: T;
|
10
|
+
}
|
11
|
+
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
12
|
+
context?: T;
|
11
13
|
} : {
|
12
|
-
context:
|
14
|
+
context: T;
|
13
15
|
});
|
14
16
|
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
15
17
|
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
@@ -20,11 +22,8 @@ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext,
|
|
20
22
|
[k: string]: NestedClient<TClientContext>;
|
21
23
|
};
|
22
24
|
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
23
|
-
type ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
|
24
|
-
context: TClientContext;
|
25
|
-
};
|
26
25
|
interface ClientLink<TClientContext extends ClientContext> {
|
27
26
|
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
28
27
|
}
|
29
28
|
|
30
|
-
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,36 +1,78 @@
|
|
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, b as isORPCErrorStatus, O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.
|
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.txdq_i5V.mjs';
|
4
|
+
import { toStandardHeaders as toStandardHeaders$1 } from '@orpc/standard-server-fetch';
|
4
5
|
|
5
|
-
class
|
6
|
+
class CompositeStandardLinkPlugin {
|
7
|
+
plugins;
|
8
|
+
constructor(plugins = []) {
|
9
|
+
this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
10
|
+
}
|
11
|
+
init(options) {
|
12
|
+
for (const plugin of this.plugins) {
|
13
|
+
plugin.init?.(options);
|
14
|
+
}
|
15
|
+
}
|
6
16
|
}
|
17
|
+
|
7
18
|
class StandardLink {
|
8
19
|
constructor(codec, sender, options = {}) {
|
9
20
|
this.codec = codec;
|
10
21
|
this.sender = sender;
|
11
|
-
|
12
|
-
|
13
|
-
}
|
22
|
+
const plugin = new CompositeStandardLinkPlugin(options.plugins);
|
23
|
+
plugin.init(options);
|
14
24
|
this.interceptors = toArray(options.interceptors);
|
15
25
|
this.clientInterceptors = toArray(options.clientInterceptors);
|
16
26
|
}
|
17
27
|
interceptors;
|
18
28
|
clientInterceptors;
|
19
29
|
call(path, input, options) {
|
20
|
-
return
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
+
}
|
31
75
|
);
|
32
|
-
const output = await this.codec.decode(response, options, path, input);
|
33
|
-
return output;
|
34
76
|
}
|
35
77
|
}
|
36
78
|
|
@@ -183,6 +225,12 @@ class StandardRPCJsonSerializer {
|
|
183
225
|
function toHttpPath(path) {
|
184
226
|
return `/${path.map(encodeURIComponent).join("/")}`;
|
185
227
|
}
|
228
|
+
function toStandardHeaders(headers) {
|
229
|
+
if (typeof headers.forEach === "function") {
|
230
|
+
return toStandardHeaders$1(headers);
|
231
|
+
}
|
232
|
+
return headers;
|
233
|
+
}
|
186
234
|
function getMalformedResponseErrorCode(status) {
|
187
235
|
return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE";
|
188
236
|
}
|
@@ -202,14 +250,14 @@ class StandardRPCLinkCodec {
|
|
202
250
|
expectedMethod;
|
203
251
|
headers;
|
204
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
|
+
}
|
205
257
|
const expectedMethod = await value(this.expectedMethod, options, path, input);
|
206
|
-
let headers = await value(this.headers, options, path, input);
|
207
258
|
const baseUrl = await value(this.baseUrl, options, path, input);
|
208
259
|
const url = new URL(baseUrl);
|
209
260
|
url.pathname = `${url.pathname.replace(/\/$/, "")}${toHttpPath(path)}`;
|
210
|
-
if (options.lastEventId !== void 0) {
|
211
|
-
headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
|
212
|
-
}
|
213
261
|
const serialized = this.serializer.serialize(input);
|
214
262
|
if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
|
215
263
|
const maxUrlLength = await value(this.maxUrlLength, options, path, input);
|
@@ -253,12 +301,12 @@ class StandardRPCLinkCodec {
|
|
253
301
|
}
|
254
302
|
})();
|
255
303
|
if (!isOk) {
|
256
|
-
if (
|
257
|
-
throw
|
304
|
+
if (isORPCErrorJson(deserialized)) {
|
305
|
+
throw createORPCErrorFromJson(deserialized);
|
258
306
|
}
|
259
307
|
throw new ORPCError(getMalformedResponseErrorCode(response.status), {
|
260
308
|
status: response.status,
|
261
|
-
data: deserialized
|
309
|
+
data: { ...response, body: deserialized }
|
262
310
|
});
|
263
311
|
}
|
264
312
|
return deserialized;
|
@@ -308,8 +356,8 @@ class StandardRPCSerializer {
|
|
308
356
|
return e;
|
309
357
|
}
|
310
358
|
const deserialized = this.#deserialize(e.data);
|
311
|
-
if (
|
312
|
-
return
|
359
|
+
if (isORPCErrorJson(deserialized)) {
|
360
|
+
return createORPCErrorFromJson(deserialized, { cause: e });
|
313
361
|
}
|
314
362
|
return new ErrorEvent({
|
315
363
|
data: deserialized,
|
@@ -321,6 +369,9 @@ class StandardRPCSerializer {
|
|
321
369
|
return this.#deserialize(data);
|
322
370
|
}
|
323
371
|
#deserialize(data) {
|
372
|
+
if (data === void 0) {
|
373
|
+
return void 0;
|
374
|
+
}
|
324
375
|
if (!(data instanceof FormData)) {
|
325
376
|
return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
|
326
377
|
}
|
@@ -334,4 +385,13 @@ class StandardRPCSerializer {
|
|
334
385
|
}
|
335
386
|
}
|
336
387
|
|
337
|
-
|
388
|
+
class StandardRPCLink extends StandardLink {
|
389
|
+
constructor(linkClient, options) {
|
390
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
391
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
392
|
+
const linkCodec = new StandardRPCLinkCodec(serializer, options);
|
393
|
+
super(linkCodec, linkClient, options);
|
394
|
+
}
|
395
|
+
}
|
396
|
+
|
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,16 @@
|
|
1
|
-
import { Interceptor
|
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
|
+
|
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
|
+
}
|
4
14
|
|
5
15
|
interface StandardLinkCodec<T extends ClientContext> {
|
6
16
|
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
@@ -10,24 +20,19 @@ interface StandardLinkClient<T extends ClientContext> {
|
|
10
20
|
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
11
21
|
}
|
12
22
|
|
13
|
-
|
23
|
+
interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
24
|
+
path: readonly string[];
|
25
|
+
input: unknown;
|
14
26
|
}
|
15
|
-
interface
|
16
|
-
|
27
|
+
interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
28
|
+
request: StandardRequest;
|
17
29
|
}
|
18
30
|
interface StandardLinkOptions<T extends ClientContext> {
|
19
|
-
interceptors?: Interceptor<
|
20
|
-
|
21
|
-
input: unknown;
|
22
|
-
options: ClientOptions<T>;
|
23
|
-
}, unknown, ThrowableError>[];
|
24
|
-
clientInterceptors?: Interceptor<{
|
25
|
-
request: StandardRequest;
|
26
|
-
}, StandardLazyResponse, ThrowableError>[];
|
31
|
+
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
|
32
|
+
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
|
27
33
|
plugins?: StandardLinkPlugin<T>[];
|
28
34
|
}
|
29
35
|
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
30
|
-
#private;
|
31
36
|
readonly codec: StandardLinkCodec<T>;
|
32
37
|
readonly sender: StandardLinkClient<T>;
|
33
38
|
private readonly interceptors;
|
@@ -36,4 +41,5 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
36
41
|
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
37
42
|
}
|
38
43
|
|
39
|
-
export {
|
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,6 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
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,46 +44,30 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
44
44
|
/**
|
45
45
|
* Base url for all requests.
|
46
46
|
*/
|
47
|
-
url: Value<string | URL,
|
48
|
-
options: ClientOptions<T>,
|
49
|
-
path: readonly string[],
|
50
|
-
input: unknown
|
51
|
-
]>;
|
47
|
+
url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
52
48
|
/**
|
53
49
|
* The maximum length of the URL.
|
54
50
|
*
|
55
51
|
* @default 2083
|
56
52
|
*/
|
57
|
-
maxUrlLength?: Value<number,
|
58
|
-
options: ClientOptions<T>,
|
59
|
-
path: readonly string[],
|
60
|
-
input: unknown
|
61
|
-
]>;
|
53
|
+
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
62
54
|
/**
|
63
55
|
* The method used to make the request.
|
64
56
|
*
|
65
57
|
* @default 'POST'
|
66
58
|
*/
|
67
|
-
method?: Value<HTTPMethod, [
|
68
|
-
options: ClientOptions<T>,
|
69
|
-
path: readonly string[],
|
70
|
-
input: unknown
|
71
|
-
]>;
|
59
|
+
method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
72
60
|
/**
|
73
61
|
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
74
62
|
* GET is not allowed, it's very dangerous.
|
75
63
|
*
|
76
64
|
* @default 'POST'
|
77
65
|
*/
|
78
|
-
fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
|
66
|
+
fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
|
79
67
|
/**
|
80
68
|
* Inject headers to the request.
|
81
69
|
*/
|
82
|
-
headers?: Value<StandardHeaders,
|
83
|
-
options: ClientOptions<T>,
|
84
|
-
path: readonly string[],
|
85
|
-
input: unknown
|
86
|
-
]>;
|
70
|
+
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
87
71
|
}
|
88
72
|
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
89
73
|
private readonly serializer;
|
@@ -99,5 +83,9 @@ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardL
|
|
99
83
|
|
100
84
|
interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
|
101
85
|
}
|
86
|
+
declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
|
87
|
+
constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
|
88
|
+
}
|
102
89
|
|
103
|
-
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S,
|
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,6 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
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,46 +44,30 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
44
44
|
/**
|
45
45
|
* Base url for all requests.
|
46
46
|
*/
|
47
|
-
url: Value<string | URL,
|
48
|
-
options: ClientOptions<T>,
|
49
|
-
path: readonly string[],
|
50
|
-
input: unknown
|
51
|
-
]>;
|
47
|
+
url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
52
48
|
/**
|
53
49
|
* The maximum length of the URL.
|
54
50
|
*
|
55
51
|
* @default 2083
|
56
52
|
*/
|
57
|
-
maxUrlLength?: Value<number,
|
58
|
-
options: ClientOptions<T>,
|
59
|
-
path: readonly string[],
|
60
|
-
input: unknown
|
61
|
-
]>;
|
53
|
+
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
62
54
|
/**
|
63
55
|
* The method used to make the request.
|
64
56
|
*
|
65
57
|
* @default 'POST'
|
66
58
|
*/
|
67
|
-
method?: Value<HTTPMethod, [
|
68
|
-
options: ClientOptions<T>,
|
69
|
-
path: readonly string[],
|
70
|
-
input: unknown
|
71
|
-
]>;
|
59
|
+
method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
72
60
|
/**
|
73
61
|
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
74
62
|
* GET is not allowed, it's very dangerous.
|
75
63
|
*
|
76
64
|
* @default 'POST'
|
77
65
|
*/
|
78
|
-
fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
|
66
|
+
fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
|
79
67
|
/**
|
80
68
|
* Inject headers to the request.
|
81
69
|
*/
|
82
|
-
headers?: Value<StandardHeaders,
|
83
|
-
options: ClientOptions<T>,
|
84
|
-
path: readonly string[],
|
85
|
-
input: unknown
|
86
|
-
]>;
|
70
|
+
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
87
71
|
}
|
88
72
|
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
89
73
|
private readonly serializer;
|
@@ -99,5 +83,9 @@ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardL
|
|
99
83
|
|
100
84
|
interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
|
101
85
|
}
|
86
|
+
declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
|
87
|
+
constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
|
88
|
+
}
|
102
89
|
|
103
|
-
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S,
|
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,4 +1,4 @@
|
|
1
|
-
import { isObject, isTypescriptObject } from '@orpc/shared';
|
1
|
+
import { resolveMaybeOptionalOptions, isObject, AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
|
2
2
|
import { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
3
3
|
|
4
4
|
const COMMON_ORPC_ERROR_DEFS = {
|
@@ -90,16 +90,17 @@ class ORPCError extends Error {
|
|
90
90
|
code;
|
91
91
|
status;
|
92
92
|
data;
|
93
|
-
constructor(code, ...
|
94
|
-
|
93
|
+
constructor(code, ...rest) {
|
94
|
+
const options = resolveMaybeOptionalOptions(rest);
|
95
|
+
if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
|
95
96
|
throw new Error("[ORPCError] Invalid error status code.");
|
96
97
|
}
|
97
|
-
const message = fallbackORPCErrorMessage(code, options
|
98
|
+
const message = fallbackORPCErrorMessage(code, options.message);
|
98
99
|
super(message, options);
|
99
100
|
this.code = code;
|
100
|
-
this.status = fallbackORPCErrorStatus(code, options
|
101
|
-
this.defined = options
|
102
|
-
this.data = options
|
101
|
+
this.status = fallbackORPCErrorStatus(code, options.status);
|
102
|
+
this.defined = options.defined ?? false;
|
103
|
+
this.data = options.data;
|
103
104
|
}
|
104
105
|
toJSON() {
|
105
106
|
return {
|
@@ -110,22 +111,6 @@ class ORPCError extends Error {
|
|
110
111
|
data: this.data
|
111
112
|
};
|
112
113
|
}
|
113
|
-
static fromJSON(json, options) {
|
114
|
-
return new ORPCError(json.code, {
|
115
|
-
...options,
|
116
|
-
...json
|
117
|
-
});
|
118
|
-
}
|
119
|
-
static isValidJSON(json) {
|
120
|
-
if (!isObject(json)) {
|
121
|
-
return false;
|
122
|
-
}
|
123
|
-
const validKeys = ["defined", "code", "status", "message", "data"];
|
124
|
-
if (Object.keys(json).some((k) => !validKeys.includes(k))) {
|
125
|
-
return false;
|
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";
|
128
|
-
}
|
129
114
|
}
|
130
115
|
function isDefinedError(error) {
|
131
116
|
return error instanceof ORPCError && error.defined;
|
@@ -139,37 +124,57 @@ function toORPCError(error) {
|
|
139
124
|
function isORPCErrorStatus(status) {
|
140
125
|
return status < 200 || status >= 400;
|
141
126
|
}
|
127
|
+
function isORPCErrorJson(json) {
|
128
|
+
if (!isObject(json)) {
|
129
|
+
return false;
|
130
|
+
}
|
131
|
+
const validKeys = ["defined", "code", "status", "message", "data"];
|
132
|
+
if (Object.keys(json).some((k) => !validKeys.includes(k))) {
|
133
|
+
return false;
|
134
|
+
}
|
135
|
+
return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && isORPCErrorStatus(json.status) && "message" in json && typeof json.message === "string";
|
136
|
+
}
|
137
|
+
function createORPCErrorFromJson(json, options = {}) {
|
138
|
+
return new ORPCError(json.code, {
|
139
|
+
...options,
|
140
|
+
...json
|
141
|
+
});
|
142
|
+
}
|
142
143
|
|
143
144
|
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;
|
145
|
+
const mapError = async (error) => {
|
146
|
+
let mappedError = await maps.error(error);
|
147
|
+
if (mappedError !== error) {
|
148
|
+
const meta = getEventMeta(error);
|
149
|
+
if (meta && isTypescriptObject(mappedError)) {
|
150
|
+
mappedError = withEventMeta(mappedError, meta);
|
159
151
|
}
|
160
|
-
}
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
152
|
+
}
|
153
|
+
return mappedError;
|
154
|
+
};
|
155
|
+
return new AsyncIteratorClass(async () => {
|
156
|
+
const { done, value } = await (async () => {
|
157
|
+
try {
|
158
|
+
return await iterator.next();
|
159
|
+
} catch (error) {
|
160
|
+
throw await mapError(error);
|
161
|
+
}
|
162
|
+
})();
|
163
|
+
let mappedValue = await maps.value(value, done);
|
164
|
+
if (mappedValue !== value) {
|
165
|
+
const meta = getEventMeta(value);
|
166
|
+
if (meta && isTypescriptObject(mappedValue)) {
|
167
|
+
mappedValue = withEventMeta(mappedValue, meta);
|
167
168
|
}
|
168
|
-
|
169
|
-
|
169
|
+
}
|
170
|
+
return { done, value: mappedValue };
|
171
|
+
}, async () => {
|
172
|
+
try {
|
170
173
|
await iterator.return?.();
|
174
|
+
} catch (error) {
|
175
|
+
throw await mapError(error);
|
171
176
|
}
|
172
|
-
}
|
177
|
+
});
|
173
178
|
}
|
174
179
|
|
175
|
-
export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, isORPCErrorStatus as b, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
|
180
|
+
export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, isORPCErrorStatus as b, isORPCErrorJson as c, createORPCErrorFromJson as d, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
|