@orpc/client 0.0.0-next.cd121e3 → 0.0.0-next.ce2f84d

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/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { N as NestedClient, b as ClientLink, I as InferClientContext, C as ClientContext, a as ClientOptionsOut, c as ClientPromiseResult } from './shared/client.D_CzLDyB.js';
2
- export { g as Client, e as ClientOptions, f as ClientRest, E as EventIteratorReconnectOptions, d as createAutoRetryEventIterator, m as mapEventIterator } from './shared/client.D_CzLDyB.js';
3
- import { Promisable, MaybeOptionalOptions } from '@orpc/shared';
1
+ import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientContext, b as ClientOptions, c as ClientPromiseResult, F as FriendlyClientOptions } from './shared/client.C0lT7w02.js';
2
+ export { f as Client, e as ClientRest, d as HTTPMethod, H as HTTPPath } from './shared/client.C0lT7w02.js';
3
+ import { Promisable, MaybeOptionalOptions, ThrowableError } from '@orpc/shared';
4
+ export { Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
4
5
  export { ErrorEvent } from '@orpc/standard-server';
5
6
 
6
7
  interface createORPCClientOptions {
@@ -17,8 +18,8 @@ declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<
17
18
  */
18
19
  declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
19
20
  private readonly linkResolver;
20
- constructor(linkResolver: (options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
21
- call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
21
+ constructor(linkResolver: (options: ClientOptions<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
22
+ call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
22
23
  }
23
24
 
24
25
  declare const COMMON_ORPC_ERROR_DEFS: {
@@ -125,29 +126,30 @@ declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
125
126
  type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
126
127
  declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
127
128
  declare function toORPCError(error: unknown): ORPCError<any, any>;
129
+ declare function isORPCErrorStatus(status: number): boolean;
128
130
 
129
- type ConnectionStatus = 'reconnecting' | 'connected' | 'closed';
130
- interface EventIteratorState {
131
- status: ConnectionStatus;
132
- listeners: Array<(newStatus: ConnectionStatus) => void>;
133
- }
134
- declare function registerEventIteratorState(iterator: AsyncIteratorObject<unknown, unknown, void>, state: EventIteratorState): void;
135
- declare function updateEventIteratorStatus(state: EventIteratorState, status: ConnectionStatus): void;
136
- declare function onEventIteratorStatusChange(iterator: AsyncIteratorObject<unknown, unknown, void>, callback: (status: ConnectionStatus) => void, notifyImmediately?: boolean): () => void;
131
+ declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
132
+ value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
133
+ error: (error: unknown) => Promise<unknown>;
134
+ }): AsyncGenerator<TMap, TMap, TNext>;
137
135
 
138
- type SafeResult<TOutput, TError extends Error> = [error: null, data: TOutput, isDefined: false] & {
136
+ type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, isSuccess: true] & {
139
137
  error: null;
140
138
  data: TOutput;
141
139
  isDefined: false;
142
- } | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false] & {
140
+ isSuccess: true;
141
+ } | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, isSuccess: false] & {
143
142
  error: Exclude<TError, ORPCError<any, any>>;
144
143
  data: undefined;
145
144
  isDefined: false;
146
- } | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true] & {
145
+ isSuccess: false;
146
+ } | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, isSuccess: false] & {
147
147
  error: Extract<TError, ORPCError<any, any>>;
148
148
  data: undefined;
149
149
  isDefined: true;
150
+ isSuccess: false;
150
151
  };
151
- declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
152
+ declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
153
+ declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
152
154
 
153
- export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptionsOut, ClientPromiseResult, type CommonORPCErrorCode, type ConnectionStatus, DynamicLink, type EventIteratorState, InferClientContext, NestedClient, ORPCError, type ORPCErrorCode, type ORPCErrorJSON, type ORPCErrorOptions, type SafeResult, createORPCClient, type createORPCClientOptions, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, onEventIteratorStatusChange, registerEventIteratorState, safe, toORPCError, updateEventIteratorStatus };
155
+ export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, type CommonORPCErrorCode, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, type ORPCErrorCode, type ORPCErrorJSON, type ORPCErrorOptions, type SafeResult, createORPCClient, type createORPCClientOptions, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
package/dist/index.mjs CHANGED
@@ -1,17 +1,41 @@
1
- import { i as isDefinedError } from './shared/client.Ly4zGQrc.mjs';
2
- export { C as COMMON_ORPC_ERROR_DEFS, O as ORPCError, c as createAutoRetryEventIterator, a as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, m as mapEventIterator, o as onEventIteratorStatusChange, r as registerEventIteratorState, t as toORPCError, u as updateEventIteratorStatus } from './shared/client.Ly4zGQrc.mjs';
1
+ import { i as isDefinedError } from './shared/client.jKEwIsRd.mjs';
2
+ export { C as COMMON_ORPC_ERROR_DEFS, O as ORPCError, a as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, b as isORPCErrorStatus, m as mapEventIterator, t as toORPCError } from './shared/client.jKEwIsRd.mjs';
3
+ export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
3
4
  export { ErrorEvent } from '@orpc/standard-server';
4
- import '@orpc/shared';
5
+
6
+ async function safe(promise) {
7
+ try {
8
+ const output = await promise;
9
+ return Object.assign(
10
+ [null, output, false, true],
11
+ { error: null, data: output, isDefined: false, isSuccess: true }
12
+ );
13
+ } catch (e) {
14
+ const error = e;
15
+ if (isDefinedError(error)) {
16
+ return Object.assign(
17
+ [error, void 0, true, false],
18
+ { error, data: void 0, isDefined: true, isSuccess: false }
19
+ );
20
+ }
21
+ return Object.assign(
22
+ [error, void 0, false, false],
23
+ { error, data: void 0, isDefined: false, isSuccess: false }
24
+ );
25
+ }
26
+ }
27
+ function resolveFriendlyClientOptions(options) {
28
+ return {
29
+ ...options,
30
+ context: options?.context ?? {}
31
+ // Context only optional if all fields are optional
32
+ };
33
+ }
5
34
 
6
35
  function createORPCClient(link, options) {
7
36
  const path = options?.path ?? [];
8
- const procedureClient = async (...[input, options2]) => {
9
- const optionsOut = {
10
- ...options2,
11
- context: options2?.context ?? {}
12
- // options.context can be undefined when all field is optional
13
- };
14
- return await link.call(path, input, optionsOut);
37
+ const procedureClient = async (...[input, options2 = {}]) => {
38
+ return await link.call(path, input, resolveFriendlyClientOptions(options2));
15
39
  };
16
40
  const recursive = new Proxy(procedureClient, {
17
41
  get(target, key) {
@@ -38,26 +62,4 @@ class DynamicLink {
38
62
  }
39
63
  }
40
64
 
41
- async function safe(promise) {
42
- try {
43
- const output = await promise;
44
- return Object.assign(
45
- [null, output, false],
46
- { error: null, data: output, isDefined: false }
47
- );
48
- } catch (e) {
49
- const error = e;
50
- if (isDefinedError(error)) {
51
- return Object.assign(
52
- [error, void 0, true],
53
- { error, data: void 0, isDefined: true }
54
- );
55
- }
56
- return Object.assign(
57
- [error, void 0, false],
58
- { error, data: void 0, isDefined: false }
59
- );
60
- }
61
- }
62
-
63
- export { DynamicLink, createORPCClient, isDefinedError, safe };
65
+ export { DynamicLink, createORPCClient, isDefinedError, resolveFriendlyClientOptions, safe };
@@ -0,0 +1,65 @@
1
+ import { Value } from '@orpc/shared';
2
+ import { S as StandardLinkPlugin, a as StandardLinkOptions } from '../shared/client.5813Ufvs.mjs';
3
+ import { b as ClientOptions } from '../shared/client.C0lT7w02.mjs';
4
+ import '@orpc/standard-server';
5
+
6
+ interface ClientRetryPluginAttemptOptions {
7
+ lastEventRetry: number | undefined;
8
+ lastEventId: string | undefined;
9
+ attemptIndex: number;
10
+ error: unknown;
11
+ }
12
+ interface ClientRetryPluginContext {
13
+ /**
14
+ * Maximum retry attempts before throwing
15
+ * Use `Number.POSITIVE_INFINITY` for infinite retries (e.g., when handling Server-Sent Events).
16
+ *
17
+ * @default 0
18
+ */
19
+ retry?: Value<number, [
20
+ clientOptions: ClientOptions<ClientRetryPluginContext>,
21
+ path: readonly string[],
22
+ input: unknown
23
+ ]>;
24
+ /**
25
+ * Delay (in ms) before retrying.
26
+ *
27
+ * @default (o) => o.lastEventRetry ?? 2000
28
+ */
29
+ retryDelay?: Value<number, [
30
+ attemptOptions: ClientRetryPluginAttemptOptions,
31
+ clientOptions: ClientOptions<ClientRetryPluginContext>,
32
+ path: readonly string[],
33
+ input: unknown
34
+ ]>;
35
+ /**
36
+ * Determine should retry or not.
37
+ *
38
+ * @default true
39
+ */
40
+ shouldRetry?: Value<boolean, [
41
+ attemptOptions: ClientRetryPluginAttemptOptions,
42
+ clientOptions: ClientOptions<ClientRetryPluginContext>,
43
+ path: readonly string[],
44
+ input: unknown
45
+ ]>;
46
+ /**
47
+ * The hook called when retrying, and return the unsubscribe function.
48
+ */
49
+ onRetry?: (options: ClientRetryPluginAttemptOptions, clientOptions: ClientOptions<ClientRetryPluginContext>, path: readonly string[], input: unknown) => void | (() => void);
50
+ }
51
+ declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
52
+ }
53
+ interface ClientRetryPluginOptions {
54
+ default?: ClientRetryPluginContext;
55
+ }
56
+ declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
57
+ private readonly defaultRetry;
58
+ private readonly defaultRetryDelay;
59
+ private readonly defaultShouldRetry;
60
+ private readonly defaultOnRetry;
61
+ constructor(options?: ClientRetryPluginOptions);
62
+ init(options: StandardLinkOptions<T>): void;
63
+ }
64
+
65
+ export { ClientRetryPlugin, type ClientRetryPluginAttemptOptions, type ClientRetryPluginContext, ClientRetryPluginInvalidEventIteratorRetryResponse, type ClientRetryPluginOptions };
@@ -0,0 +1,65 @@
1
+ import { Value } from '@orpc/shared';
2
+ import { S as StandardLinkPlugin, a as StandardLinkOptions } from '../shared/client.grRbC25r.js';
3
+ import { b as ClientOptions } from '../shared/client.C0lT7w02.js';
4
+ import '@orpc/standard-server';
5
+
6
+ interface ClientRetryPluginAttemptOptions {
7
+ lastEventRetry: number | undefined;
8
+ lastEventId: string | undefined;
9
+ attemptIndex: number;
10
+ error: unknown;
11
+ }
12
+ interface ClientRetryPluginContext {
13
+ /**
14
+ * Maximum retry attempts before throwing
15
+ * Use `Number.POSITIVE_INFINITY` for infinite retries (e.g., when handling Server-Sent Events).
16
+ *
17
+ * @default 0
18
+ */
19
+ retry?: Value<number, [
20
+ clientOptions: ClientOptions<ClientRetryPluginContext>,
21
+ path: readonly string[],
22
+ input: unknown
23
+ ]>;
24
+ /**
25
+ * Delay (in ms) before retrying.
26
+ *
27
+ * @default (o) => o.lastEventRetry ?? 2000
28
+ */
29
+ retryDelay?: Value<number, [
30
+ attemptOptions: ClientRetryPluginAttemptOptions,
31
+ clientOptions: ClientOptions<ClientRetryPluginContext>,
32
+ path: readonly string[],
33
+ input: unknown
34
+ ]>;
35
+ /**
36
+ * Determine should retry or not.
37
+ *
38
+ * @default true
39
+ */
40
+ shouldRetry?: Value<boolean, [
41
+ attemptOptions: ClientRetryPluginAttemptOptions,
42
+ clientOptions: ClientOptions<ClientRetryPluginContext>,
43
+ path: readonly string[],
44
+ input: unknown
45
+ ]>;
46
+ /**
47
+ * The hook called when retrying, and return the unsubscribe function.
48
+ */
49
+ onRetry?: (options: ClientRetryPluginAttemptOptions, clientOptions: ClientOptions<ClientRetryPluginContext>, path: readonly string[], input: unknown) => void | (() => void);
50
+ }
51
+ declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
52
+ }
53
+ interface ClientRetryPluginOptions {
54
+ default?: ClientRetryPluginContext;
55
+ }
56
+ declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
57
+ private readonly defaultRetry;
58
+ private readonly defaultRetryDelay;
59
+ private readonly defaultShouldRetry;
60
+ private readonly defaultOnRetry;
61
+ constructor(options?: ClientRetryPluginOptions);
62
+ init(options: StandardLinkOptions<T>): void;
63
+ }
64
+
65
+ export { ClientRetryPlugin, type ClientRetryPluginAttemptOptions, type ClientRetryPluginContext, ClientRetryPluginInvalidEventIteratorRetryResponse, type ClientRetryPluginOptions };
@@ -0,0 +1,131 @@
1
+ import { value, isAsyncIteratorObject } from '@orpc/shared';
2
+ import { getEventMeta } from '@orpc/standard-server';
3
+
4
+ class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
5
+ }
6
+ class ClientRetryPlugin {
7
+ defaultRetry;
8
+ defaultRetryDelay;
9
+ defaultShouldRetry;
10
+ defaultOnRetry;
11
+ constructor(options = {}) {
12
+ this.defaultRetry = options.default?.retry ?? 0;
13
+ this.defaultRetryDelay = options.default?.retryDelay ?? ((o) => o.lastEventRetry ?? 2e3);
14
+ this.defaultShouldRetry = options.default?.shouldRetry ?? true;
15
+ this.defaultOnRetry = options.default?.onRetry;
16
+ }
17
+ init(options) {
18
+ options.interceptors ??= [];
19
+ options.interceptors.push(async (interceptorOptions) => {
20
+ const maxAttempts = await value(
21
+ interceptorOptions.options.context.retry ?? this.defaultRetry,
22
+ interceptorOptions.options,
23
+ interceptorOptions.path,
24
+ interceptorOptions.input
25
+ );
26
+ const retryDelay = interceptorOptions.options.context.retryDelay ?? this.defaultRetryDelay;
27
+ const shouldRetry = interceptorOptions.options.context.shouldRetry ?? this.defaultShouldRetry;
28
+ const onRetry = interceptorOptions.options.context.onRetry ?? this.defaultOnRetry;
29
+ if (maxAttempts <= 0) {
30
+ return interceptorOptions.next();
31
+ }
32
+ let lastEventId = interceptorOptions.options.lastEventId;
33
+ let lastEventRetry;
34
+ let unsubscribe;
35
+ let attemptIndex = 0;
36
+ const next = async (initial) => {
37
+ let current = initial;
38
+ while (true) {
39
+ const newClientOptions = { ...interceptorOptions.options, lastEventId };
40
+ if (current) {
41
+ if (attemptIndex >= maxAttempts) {
42
+ throw current.error;
43
+ }
44
+ const attemptOptions = {
45
+ attemptIndex,
46
+ error: current.error,
47
+ lastEventId,
48
+ lastEventRetry
49
+ };
50
+ const shouldRetryBool = await value(
51
+ shouldRetry,
52
+ attemptOptions,
53
+ newClientOptions,
54
+ interceptorOptions.path,
55
+ interceptorOptions.input
56
+ );
57
+ if (!shouldRetryBool) {
58
+ throw current.error;
59
+ }
60
+ unsubscribe = onRetry?.(
61
+ attemptOptions,
62
+ newClientOptions,
63
+ interceptorOptions.path,
64
+ interceptorOptions.input
65
+ );
66
+ const retryDelayMs = await value(
67
+ retryDelay,
68
+ attemptOptions,
69
+ newClientOptions,
70
+ interceptorOptions.path,
71
+ interceptorOptions.input
72
+ );
73
+ await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
74
+ attemptIndex++;
75
+ }
76
+ try {
77
+ const output2 = await interceptorOptions.next({
78
+ ...interceptorOptions,
79
+ options: newClientOptions
80
+ });
81
+ return output2;
82
+ } catch (error) {
83
+ if (newClientOptions.signal?.aborted === true) {
84
+ throw error;
85
+ }
86
+ current = { error };
87
+ } finally {
88
+ unsubscribe?.();
89
+ unsubscribe = void 0;
90
+ }
91
+ }
92
+ };
93
+ const output = await next();
94
+ if (!isAsyncIteratorObject(output)) {
95
+ return output;
96
+ }
97
+ return async function* () {
98
+ let current = output;
99
+ try {
100
+ while (true) {
101
+ try {
102
+ const item = await current.next();
103
+ const meta = getEventMeta(item.value);
104
+ lastEventId = meta?.id ?? lastEventId;
105
+ lastEventRetry = meta?.retry ?? lastEventRetry;
106
+ if (item.done) {
107
+ return item.value;
108
+ }
109
+ yield item.value;
110
+ } catch (error) {
111
+ const meta = getEventMeta(error);
112
+ lastEventId = meta?.id ?? lastEventId;
113
+ lastEventRetry = meta?.retry ?? lastEventRetry;
114
+ const maybeEventIterator = await next({ error });
115
+ if (!isAsyncIteratorObject(maybeEventIterator)) {
116
+ throw new ClientRetryPluginInvalidEventIteratorRetryResponse(
117
+ "RetryPlugin: Expected an Event Iterator, got a non-Event Iterator"
118
+ );
119
+ }
120
+ current = maybeEventIterator;
121
+ }
122
+ }
123
+ } finally {
124
+ await current.return?.();
125
+ }
126
+ }();
127
+ });
128
+ }
129
+ }
130
+
131
+ export { ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse };
@@ -0,0 +1,39 @@
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.C0lT7w02.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 StandardLinkOptions<T extends ClientContext> {
19
+ interceptors?: Interceptor<{
20
+ path: readonly string[];
21
+ input: unknown;
22
+ options: ClientOptions<T>;
23
+ }, unknown, ThrowableError>[];
24
+ clientInterceptors?: Interceptor<{
25
+ request: StandardRequest;
26
+ }, StandardLazyResponse, ThrowableError>[];
27
+ plugins?: StandardLinkPlugin<T>[];
28
+ }
29
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
30
+ #private;
31
+ readonly codec: StandardLinkCodec<T>;
32
+ readonly sender: StandardLinkClient<T>;
33
+ private readonly interceptors;
34
+ private readonly clientInterceptors;
35
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
36
+ call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
37
+ }
38
+
39
+ export { InvalidEventIteratorRetryResponse as I, type StandardLinkPlugin as S, type StandardLinkOptions as a, StandardLink as b, type StandardLinkCodec as c, type StandardLinkClient as d };
@@ -0,0 +1,103 @@
1
+ import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.C0lT7w02.mjs';
2
+ import { c as StandardLinkCodec, a as StandardLinkOptions } from './client.5813Ufvs.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, [
48
+ options: ClientOptions<T>,
49
+ path: readonly string[],
50
+ input: unknown
51
+ ]>;
52
+ /**
53
+ * The maximum length of the URL.
54
+ *
55
+ * @default 2083
56
+ */
57
+ maxUrlLength?: Value<number, [
58
+ options: ClientOptions<T>,
59
+ path: readonly string[],
60
+ input: unknown
61
+ ]>;
62
+ /**
63
+ * The method used to make the request.
64
+ *
65
+ * @default 'POST'
66
+ */
67
+ method?: Value<HTTPMethod, [
68
+ options: ClientOptions<T>,
69
+ path: readonly string[],
70
+ input: unknown
71
+ ]>;
72
+ /**
73
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
74
+ * GET is not allowed, it's very dangerous.
75
+ *
76
+ * @default 'POST'
77
+ */
78
+ fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
79
+ /**
80
+ * Inject headers to the request.
81
+ */
82
+ headers?: Value<StandardHeaders, [
83
+ options: ClientOptions<T>,
84
+ path: readonly string[],
85
+ input: unknown
86
+ ]>;
87
+ }
88
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
89
+ private readonly serializer;
90
+ private readonly baseUrl;
91
+ private readonly maxUrlLength;
92
+ private readonly fallbackMethod;
93
+ private readonly expectedMethod;
94
+ private readonly headers;
95
+ constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
96
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
97
+ decode(response: StandardLazyResponse): Promise<unknown>;
98
+ }
99
+
100
+ interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
101
+ }
102
+
103
+ 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,30 @@
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
+ type FriendlyClientOptions<TClientContext extends ClientContext> = {
7
+ signal?: AbortSignal;
8
+ lastEventId?: string | undefined;
9
+ } & (Record<never, never> extends TClientContext ? {
10
+ context?: TClientContext;
11
+ } : {
12
+ context: TClientContext;
13
+ });
14
+ 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
+ type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
16
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
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 ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
24
+ context: TClientContext;
25
+ };
26
+ interface ClientLink<TClientContext extends ClientContext> {
27
+ call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
28
+ }
29
+
30
+ 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,30 @@
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
+ type FriendlyClientOptions<TClientContext extends ClientContext> = {
7
+ signal?: AbortSignal;
8
+ lastEventId?: string | undefined;
9
+ } & (Record<never, never> extends TClientContext ? {
10
+ context?: TClientContext;
11
+ } : {
12
+ context: TClientContext;
13
+ });
14
+ 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
+ type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
16
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
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 ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
24
+ context: TClientContext;
25
+ };
26
+ interface ClientLink<TClientContext extends ClientContext> {
27
+ call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
28
+ }
29
+
30
+ 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 };