@orpc/client 0.0.0-next.2546825 → 0.0.0-next.25532a8
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 +14 -1
- package/dist/adapters/fetch/index.d.mts +10 -13
- package/dist/adapters/fetch/index.d.ts +10 -13
- package/dist/adapters/fetch/index.mjs +7 -10
- package/dist/adapters/standard/index.d.mts +8 -146
- package/dist/adapters/standard/index.d.ts +8 -146
- package/dist/adapters/standard/index.mjs +2 -2
- package/dist/index.d.mts +20 -18
- package/dist/index.d.ts +20 -18
- package/dist/index.mjs +35 -33
- package/dist/plugins/index.d.mts +50 -0
- package/dist/plugins/index.d.ts +50 -0
- package/dist/plugins/index.mjs +111 -0
- package/dist/shared/{client.BMw2gtvr.mjs → client.BQuFq0Vi.mjs} +94 -76
- package/dist/shared/client.Bx07L657.d.mts +87 -0
- package/dist/shared/client.C486S9aU.d.mts +40 -0
- package/dist/shared/client.CipPQkhk.d.mts +29 -0
- package/dist/shared/client.CipPQkhk.d.ts +29 -0
- package/dist/shared/client.DKA6DQSn.d.ts +87 -0
- package/dist/shared/{client.DcaJQZfy.mjs → client.jKEwIsRd.mjs} +6 -96
- package/dist/shared/client.qdWq4aGG.d.ts +40 -0
- package/package.json +9 -4
- package/dist/shared/client.D_CzLDyB.d.mts +0 -42
- package/dist/shared/client.D_CzLDyB.d.ts +0 -42
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { a as ClientContext, d as HTTPMethod, b as ClientOptions } from './client.CipPQkhk.mjs';
|
|
2
|
+
import { S as StandardLinkInterceptorOptions, e as StandardLinkCodec, b as StandardLinkOptions } from './client.C486S9aU.mjs';
|
|
3
|
+
import { Segment, Value } 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<string | URL, [StandardLinkInterceptorOptions<T>]>;
|
|
48
|
+
/**
|
|
49
|
+
* The maximum length of the URL.
|
|
50
|
+
*
|
|
51
|
+
* @default 2083
|
|
52
|
+
*/
|
|
53
|
+
maxUrlLength?: Value<number, [StandardLinkInterceptorOptions<T>]>;
|
|
54
|
+
/**
|
|
55
|
+
* The method used to make the request.
|
|
56
|
+
*
|
|
57
|
+
* @default 'POST'
|
|
58
|
+
*/
|
|
59
|
+
method?: Value<HTTPMethod, [StandardLinkInterceptorOptions<T>]>;
|
|
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, 'GET'>;
|
|
67
|
+
/**
|
|
68
|
+
* Inject headers to the request.
|
|
69
|
+
*/
|
|
70
|
+
headers?: Value<StandardHeaders, [StandardLinkInterceptorOptions<T>]>;
|
|
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
|
+
|
|
87
|
+
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, type StandardRPCJsonSerializedMetaItem as a, type StandardRPCJsonSerialized as b, type StandardRPCCustomJsonSerializer as c, type StandardRPCJsonSerializerOptions as d, StandardRPCJsonSerializer as e, type StandardRPCLinkOptions as f, type StandardRPCLinkCodecOptions as g, StandardRPCLinkCodec as h, StandardRPCSerializer as i };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Interceptor, ThrowableError } from '@orpc/shared';
|
|
2
|
+
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
+
import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.CipPQkhk.mjs';
|
|
4
|
+
|
|
5
|
+
interface StandardLinkCodec<T extends ClientContext> {
|
|
6
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
7
|
+
decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
interface StandardLinkClient<T extends ClientContext> {
|
|
10
|
+
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare class InvalidEventIteratorRetryResponse extends Error {
|
|
14
|
+
}
|
|
15
|
+
interface StandardLinkPlugin<T extends ClientContext> {
|
|
16
|
+
init?(options: StandardLinkOptions<T>): void;
|
|
17
|
+
}
|
|
18
|
+
interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
19
|
+
path: readonly string[];
|
|
20
|
+
input: unknown;
|
|
21
|
+
}
|
|
22
|
+
interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
|
23
|
+
request: StandardRequest;
|
|
24
|
+
}
|
|
25
|
+
interface StandardLinkOptions<T extends ClientContext> {
|
|
26
|
+
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, unknown, ThrowableError>[];
|
|
27
|
+
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, StandardLazyResponse, ThrowableError>[];
|
|
28
|
+
plugins?: StandardLinkPlugin<T>[];
|
|
29
|
+
}
|
|
30
|
+
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
31
|
+
#private;
|
|
32
|
+
readonly codec: StandardLinkCodec<T>;
|
|
33
|
+
readonly sender: StandardLinkClient<T>;
|
|
34
|
+
private readonly interceptors;
|
|
35
|
+
private readonly clientInterceptors;
|
|
36
|
+
constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
|
|
37
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { InvalidEventIteratorRetryResponse as I, type StandardLinkInterceptorOptions as S, type StandardLinkPlugin as a, type StandardLinkOptions as b, type StandardLinkClientInterceptorOptions as c, StandardLink as d, type StandardLinkCodec as e, type StandardLinkClient as f };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PromiseWithError } from '@orpc/shared';
|
|
2
|
+
|
|
3
|
+
type HTTPPath = `/${string}`;
|
|
4
|
+
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
|
+
type ClientContext = Record<PropertyKey, any>;
|
|
6
|
+
interface ClientOptions<T extends ClientContext> {
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
lastEventId?: string | undefined;
|
|
9
|
+
context: T;
|
|
10
|
+
}
|
|
11
|
+
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
12
|
+
context?: T;
|
|
13
|
+
} : {
|
|
14
|
+
context: T;
|
|
15
|
+
});
|
|
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>];
|
|
17
|
+
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
|
18
|
+
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
19
|
+
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
20
|
+
}
|
|
21
|
+
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
22
|
+
[k: string]: NestedClient<TClientContext>;
|
|
23
|
+
};
|
|
24
|
+
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
25
|
+
interface ClientLink<TClientContext extends ClientContext> {
|
|
26
|
+
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientContext as a, ClientOptions as b, ClientPromiseResult as c, HTTPMethod as d, ClientRest as e, Client as f };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PromiseWithError } from '@orpc/shared';
|
|
2
|
+
|
|
3
|
+
type HTTPPath = `/${string}`;
|
|
4
|
+
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
|
+
type ClientContext = Record<PropertyKey, any>;
|
|
6
|
+
interface ClientOptions<T extends ClientContext> {
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
lastEventId?: string | undefined;
|
|
9
|
+
context: T;
|
|
10
|
+
}
|
|
11
|
+
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
12
|
+
context?: T;
|
|
13
|
+
} : {
|
|
14
|
+
context: T;
|
|
15
|
+
});
|
|
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>];
|
|
17
|
+
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
|
18
|
+
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
19
|
+
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
20
|
+
}
|
|
21
|
+
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
22
|
+
[k: string]: NestedClient<TClientContext>;
|
|
23
|
+
};
|
|
24
|
+
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
25
|
+
interface ClientLink<TClientContext extends ClientContext> {
|
|
26
|
+
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientContext as a, ClientOptions as b, ClientPromiseResult as c, HTTPMethod as d, ClientRest as e, Client as f };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { a as ClientContext, d as HTTPMethod, b as ClientOptions } from './client.CipPQkhk.js';
|
|
2
|
+
import { S as StandardLinkInterceptorOptions, e as StandardLinkCodec, b as StandardLinkOptions } from './client.qdWq4aGG.js';
|
|
3
|
+
import { Segment, Value } 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<string | URL, [StandardLinkInterceptorOptions<T>]>;
|
|
48
|
+
/**
|
|
49
|
+
* The maximum length of the URL.
|
|
50
|
+
*
|
|
51
|
+
* @default 2083
|
|
52
|
+
*/
|
|
53
|
+
maxUrlLength?: Value<number, [StandardLinkInterceptorOptions<T>]>;
|
|
54
|
+
/**
|
|
55
|
+
* The method used to make the request.
|
|
56
|
+
*
|
|
57
|
+
* @default 'POST'
|
|
58
|
+
*/
|
|
59
|
+
method?: Value<HTTPMethod, [StandardLinkInterceptorOptions<T>]>;
|
|
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, 'GET'>;
|
|
67
|
+
/**
|
|
68
|
+
* Inject headers to the request.
|
|
69
|
+
*/
|
|
70
|
+
headers?: Value<StandardHeaders, [StandardLinkInterceptorOptions<T>]>;
|
|
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
|
+
|
|
87
|
+
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, type StandardRPCJsonSerializedMetaItem as a, type StandardRPCJsonSerialized as b, type StandardRPCCustomJsonSerializer as c, type StandardRPCJsonSerializerOptions as d, StandardRPCJsonSerializer as e, type StandardRPCLinkOptions as f, type StandardRPCLinkCodecOptions as g, StandardRPCLinkCodec as h, StandardRPCSerializer as i };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isObject, isTypescriptObject
|
|
1
|
+
import { isObject, isTypescriptObject } from '@orpc/shared';
|
|
2
2
|
import { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
|
3
3
|
|
|
4
4
|
const COMMON_ORPC_ERROR_DEFS = {
|
|
@@ -91,8 +91,8 @@ class ORPCError extends Error {
|
|
|
91
91
|
status;
|
|
92
92
|
data;
|
|
93
93
|
constructor(code, ...[options]) {
|
|
94
|
-
if (options?.status && (options.status
|
|
95
|
-
throw new Error("[ORPCError]
|
|
94
|
+
if (options?.status && !isORPCErrorStatus(options.status)) {
|
|
95
|
+
throw new Error("[ORPCError] Invalid error status code.");
|
|
96
96
|
}
|
|
97
97
|
const message = fallbackORPCErrorMessage(code, options?.message);
|
|
98
98
|
super(message, options);
|
|
@@ -136,32 +136,8 @@ function toORPCError(error) {
|
|
|
136
136
|
cause: error
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
function registerEventIteratorState(iterator, state) {
|
|
142
|
-
iteratorStates.set(iterator, state);
|
|
143
|
-
}
|
|
144
|
-
function updateEventIteratorStatus(state, status) {
|
|
145
|
-
if (state.status !== status) {
|
|
146
|
-
state.status = status;
|
|
147
|
-
state.listeners.forEach((cb) => cb(status));
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function onEventIteratorStatusChange(iterator, callback, notifyImmediately = true) {
|
|
151
|
-
const state = iteratorStates.get(iterator);
|
|
152
|
-
if (!state) {
|
|
153
|
-
throw new Error("Iterator is not registered.");
|
|
154
|
-
}
|
|
155
|
-
if (notifyImmediately) {
|
|
156
|
-
callback(state.status);
|
|
157
|
-
}
|
|
158
|
-
state.listeners.push(callback);
|
|
159
|
-
return () => {
|
|
160
|
-
const index = state.listeners.indexOf(callback);
|
|
161
|
-
if (index !== -1) {
|
|
162
|
-
state.listeners.splice(index, 1);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
139
|
+
function isORPCErrorStatus(status) {
|
|
140
|
+
return status < 200 || status >= 400;
|
|
165
141
|
}
|
|
166
142
|
|
|
167
143
|
function mapEventIterator(iterator, maps) {
|
|
@@ -195,71 +171,5 @@ function mapEventIterator(iterator, maps) {
|
|
|
195
171
|
}
|
|
196
172
|
}();
|
|
197
173
|
}
|
|
198
|
-
const MAX_ALLOWED_RETRY_TIMES = 99;
|
|
199
|
-
function createAutoRetryEventIterator(initial, reconnect, initialLastEventId) {
|
|
200
|
-
const state = {
|
|
201
|
-
status: "connected",
|
|
202
|
-
listeners: []
|
|
203
|
-
};
|
|
204
|
-
const iterator = async function* () {
|
|
205
|
-
let current = initial;
|
|
206
|
-
let lastEventId = initialLastEventId;
|
|
207
|
-
let lastRetry;
|
|
208
|
-
let retryTimes = 0;
|
|
209
|
-
try {
|
|
210
|
-
while (true) {
|
|
211
|
-
try {
|
|
212
|
-
updateEventIteratorStatus(state, "connected");
|
|
213
|
-
const { done, value } = await current.next();
|
|
214
|
-
const meta = getEventMeta(value);
|
|
215
|
-
lastEventId = meta?.id ?? lastEventId;
|
|
216
|
-
lastRetry = meta?.retry ?? lastRetry;
|
|
217
|
-
retryTimes = 0;
|
|
218
|
-
if (done) {
|
|
219
|
-
return value;
|
|
220
|
-
}
|
|
221
|
-
yield value;
|
|
222
|
-
} catch (e) {
|
|
223
|
-
updateEventIteratorStatus(state, "reconnecting");
|
|
224
|
-
const meta = getEventMeta(e);
|
|
225
|
-
lastEventId = meta?.id ?? lastEventId;
|
|
226
|
-
lastRetry = meta?.retry ?? lastRetry;
|
|
227
|
-
let currentError = e;
|
|
228
|
-
current = await retry({ times: MAX_ALLOWED_RETRY_TIMES }, async (exit) => {
|
|
229
|
-
retryTimes += 1;
|
|
230
|
-
if (retryTimes > MAX_ALLOWED_RETRY_TIMES) {
|
|
231
|
-
throw exit(new Error(
|
|
232
|
-
`Exceeded maximum retry attempts (${MAX_ALLOWED_RETRY_TIMES}) for event iterator. Possible infinite retry loop detected. Please review the retry logic.`,
|
|
233
|
-
{ cause: currentError }
|
|
234
|
-
));
|
|
235
|
-
}
|
|
236
|
-
const reconnected = await (async () => {
|
|
237
|
-
try {
|
|
238
|
-
return await reconnect({
|
|
239
|
-
lastRetry,
|
|
240
|
-
lastEventId,
|
|
241
|
-
retryTimes,
|
|
242
|
-
error: currentError
|
|
243
|
-
});
|
|
244
|
-
} catch (e2) {
|
|
245
|
-
currentError = e2;
|
|
246
|
-
throw e2;
|
|
247
|
-
}
|
|
248
|
-
})();
|
|
249
|
-
if (!reconnected) {
|
|
250
|
-
throw exit(currentError);
|
|
251
|
-
}
|
|
252
|
-
return reconnected;
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
} finally {
|
|
257
|
-
updateEventIteratorStatus(state, "closed");
|
|
258
|
-
await current.return?.();
|
|
259
|
-
}
|
|
260
|
-
}();
|
|
261
|
-
registerEventIteratorState(iterator, state);
|
|
262
|
-
return iterator;
|
|
263
|
-
}
|
|
264
174
|
|
|
265
|
-
export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a,
|
|
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 };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Interceptor, ThrowableError } from '@orpc/shared';
|
|
2
|
+
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
+
import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.CipPQkhk.js';
|
|
4
|
+
|
|
5
|
+
interface StandardLinkCodec<T extends ClientContext> {
|
|
6
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
7
|
+
decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
interface StandardLinkClient<T extends ClientContext> {
|
|
10
|
+
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare class InvalidEventIteratorRetryResponse extends Error {
|
|
14
|
+
}
|
|
15
|
+
interface StandardLinkPlugin<T extends ClientContext> {
|
|
16
|
+
init?(options: StandardLinkOptions<T>): void;
|
|
17
|
+
}
|
|
18
|
+
interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
19
|
+
path: readonly string[];
|
|
20
|
+
input: unknown;
|
|
21
|
+
}
|
|
22
|
+
interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
|
23
|
+
request: StandardRequest;
|
|
24
|
+
}
|
|
25
|
+
interface StandardLinkOptions<T extends ClientContext> {
|
|
26
|
+
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, unknown, ThrowableError>[];
|
|
27
|
+
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, StandardLazyResponse, ThrowableError>[];
|
|
28
|
+
plugins?: StandardLinkPlugin<T>[];
|
|
29
|
+
}
|
|
30
|
+
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
31
|
+
#private;
|
|
32
|
+
readonly codec: StandardLinkCodec<T>;
|
|
33
|
+
readonly sender: StandardLinkClient<T>;
|
|
34
|
+
private readonly interceptors;
|
|
35
|
+
private readonly clientInterceptors;
|
|
36
|
+
constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
|
|
37
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { InvalidEventIteratorRetryResponse as I, type StandardLinkInterceptorOptions as S, type StandardLinkPlugin as a, type StandardLinkOptions as b, type StandardLinkClientInterceptorOptions as c, StandardLink as d, type StandardLinkCodec as e, type StandardLinkClient as f };
|
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.25532a8",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
"import": "./dist/index.mjs",
|
|
20
20
|
"default": "./dist/index.mjs"
|
|
21
21
|
},
|
|
22
|
+
"./plugins": {
|
|
23
|
+
"types": "./dist/plugins/index.d.mts",
|
|
24
|
+
"import": "./dist/plugins/index.mjs",
|
|
25
|
+
"default": "./dist/plugins/index.mjs"
|
|
26
|
+
},
|
|
22
27
|
"./standard": {
|
|
23
28
|
"types": "./dist/adapters/standard/index.d.mts",
|
|
24
29
|
"import": "./dist/adapters/standard/index.mjs",
|
|
@@ -34,9 +39,9 @@
|
|
|
34
39
|
"dist"
|
|
35
40
|
],
|
|
36
41
|
"dependencies": {
|
|
37
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
38
|
-
"@orpc/standard-server-fetch": "0.0.0-next.
|
|
39
|
-
"@orpc/shared": "0.0.0-next.
|
|
42
|
+
"@orpc/standard-server": "0.0.0-next.25532a8",
|
|
43
|
+
"@orpc/standard-server-fetch": "0.0.0-next.25532a8",
|
|
44
|
+
"@orpc/shared": "0.0.0-next.25532a8"
|
|
40
45
|
},
|
|
41
46
|
"devDependencies": {
|
|
42
47
|
"zod": "^3.24.2"
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
type ClientContext = Record<string, any>;
|
|
2
|
-
type ClientOptions<TClientContext extends ClientContext> = {
|
|
3
|
-
signal?: AbortSignal;
|
|
4
|
-
lastEventId?: string | undefined;
|
|
5
|
-
} & (Record<never, never> extends TClientContext ? {
|
|
6
|
-
context?: TClientContext;
|
|
7
|
-
} : {
|
|
8
|
-
context: TClientContext;
|
|
9
|
-
});
|
|
10
|
-
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options: ClientOptions<TClientContext>];
|
|
11
|
-
type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
|
|
12
|
-
__error?: {
|
|
13
|
-
type: TError;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
|
|
17
|
-
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
18
|
-
}
|
|
19
|
-
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
20
|
-
[k: string]: NestedClient<TClientContext>;
|
|
21
|
-
};
|
|
22
|
-
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
23
|
-
type ClientOptionsOut<TClientContext extends ClientContext> = ClientOptions<TClientContext> & {
|
|
24
|
-
context: TClientContext;
|
|
25
|
-
};
|
|
26
|
-
interface ClientLink<TClientContext extends ClientContext> {
|
|
27
|
-
call: (path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>) => Promise<unknown>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
|
|
31
|
-
value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
|
|
32
|
-
error: (error: unknown) => Promise<unknown>;
|
|
33
|
-
}): AsyncGenerator<TMap, TMap, TNext>;
|
|
34
|
-
interface EventIteratorReconnectOptions {
|
|
35
|
-
lastRetry: number | undefined;
|
|
36
|
-
lastEventId: string | undefined;
|
|
37
|
-
retryTimes: number;
|
|
38
|
-
error: unknown;
|
|
39
|
-
}
|
|
40
|
-
declare function createAutoRetryEventIterator<TYield, TReturn>(initial: AsyncIterator<TYield, TReturn, void>, reconnect: (options: EventIteratorReconnectOptions) => Promise<AsyncIterator<TYield, TReturn, void> | null>, initialLastEventId: string | undefined): AsyncGenerator<TYield, TReturn, void>;
|
|
41
|
-
|
|
42
|
-
export { type ClientContext as C, type EventIteratorReconnectOptions as E, type InferClientContext as I, type NestedClient as N, type ClientOptionsOut as a, type ClientLink as b, type ClientPromiseResult as c, createAutoRetryEventIterator as d, type ClientOptions as e, type ClientRest as f, type Client as g, mapEventIterator as m };
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
type ClientContext = Record<string, any>;
|
|
2
|
-
type ClientOptions<TClientContext extends ClientContext> = {
|
|
3
|
-
signal?: AbortSignal;
|
|
4
|
-
lastEventId?: string | undefined;
|
|
5
|
-
} & (Record<never, never> extends TClientContext ? {
|
|
6
|
-
context?: TClientContext;
|
|
7
|
-
} : {
|
|
8
|
-
context: TClientContext;
|
|
9
|
-
});
|
|
10
|
-
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options: ClientOptions<TClientContext>];
|
|
11
|
-
type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
|
|
12
|
-
__error?: {
|
|
13
|
-
type: TError;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
|
|
17
|
-
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
18
|
-
}
|
|
19
|
-
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
20
|
-
[k: string]: NestedClient<TClientContext>;
|
|
21
|
-
};
|
|
22
|
-
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
23
|
-
type ClientOptionsOut<TClientContext extends ClientContext> = ClientOptions<TClientContext> & {
|
|
24
|
-
context: TClientContext;
|
|
25
|
-
};
|
|
26
|
-
interface ClientLink<TClientContext extends ClientContext> {
|
|
27
|
-
call: (path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>) => Promise<unknown>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
|
|
31
|
-
value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
|
|
32
|
-
error: (error: unknown) => Promise<unknown>;
|
|
33
|
-
}): AsyncGenerator<TMap, TMap, TNext>;
|
|
34
|
-
interface EventIteratorReconnectOptions {
|
|
35
|
-
lastRetry: number | undefined;
|
|
36
|
-
lastEventId: string | undefined;
|
|
37
|
-
retryTimes: number;
|
|
38
|
-
error: unknown;
|
|
39
|
-
}
|
|
40
|
-
declare function createAutoRetryEventIterator<TYield, TReturn>(initial: AsyncIterator<TYield, TReturn, void>, reconnect: (options: EventIteratorReconnectOptions) => Promise<AsyncIterator<TYield, TReturn, void> | null>, initialLastEventId: string | undefined): AsyncGenerator<TYield, TReturn, void>;
|
|
41
|
-
|
|
42
|
-
export { type ClientContext as C, type EventIteratorReconnectOptions as E, type InferClientContext as I, type NestedClient as N, type ClientOptionsOut as a, type ClientLink as b, type ClientPromiseResult as c, createAutoRetryEventIterator as d, type ClientOptions as e, type ClientRest as f, type Client as g, mapEventIterator as m };
|