@orpc/client 0.0.0-next.c59d67c → 0.0.0-next.ca29a36

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.js CHANGED
@@ -1,83 +1,90 @@
1
- // src/procedure.ts
2
1
  import {
3
- ORPC_HEADER,
4
- ORPC_HEADER_VALUE
5
- } from "@orpc/contract";
6
- import { trim } from "@orpc/shared";
7
- import { ORPCError } from "@orpc/shared/error";
8
- import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
9
- function createProcedureClient(options) {
10
- const serializer = new ORPCSerializer();
11
- const deserializer = new ORPCDeserializer();
12
- const client = async (input) => {
13
- const fetch_ = options.fetch ?? fetch;
14
- const url = `${trim(options.baseURL, "/")}/${options.path.map(encodeURIComponent).join("/")}`;
15
- let headers = await options.headers?.(input);
16
- headers = headers instanceof Headers ? headers : new Headers(headers);
17
- const { body, headers: headers_ } = serializer.serialize(input);
18
- for (const [key, value] of headers_.entries()) {
19
- headers.set(key, value);
20
- }
21
- headers.set(ORPC_HEADER, ORPC_HEADER_VALUE);
22
- const response = await fetch_(url, {
23
- method: "POST",
24
- headers,
25
- body
26
- });
27
- const json = await (async () => {
28
- try {
29
- return await deserializer.deserialize(response);
30
- } catch (e) {
31
- throw new ORPCError({
32
- code: "INTERNAL_SERVER_ERROR",
33
- message: "Cannot parse response.",
34
- cause: e
35
- });
2
+ COMMON_ORPC_ERROR_DEFS,
3
+ ORPCError,
4
+ createAutoRetryEventIterator,
5
+ fallbackORPCErrorMessage,
6
+ fallbackORPCErrorStatus,
7
+ isDefinedError,
8
+ mapEventIterator,
9
+ onEventIteratorStatusChange,
10
+ registerEventIteratorState,
11
+ toORPCError,
12
+ updateEventIteratorStatus
13
+ } from "./chunk-7F3XVLRJ.js";
14
+
15
+ // src/client.ts
16
+ function createORPCClient(link, options) {
17
+ const path = options?.path ?? [];
18
+ const procedureClient = async (...[input, options2]) => {
19
+ const optionsOut = {
20
+ ...options2,
21
+ context: options2?.context ?? {}
22
+ // options.context can be undefined when all field is optional
23
+ };
24
+ return await link.call(path, input, optionsOut);
25
+ };
26
+ const recursive = new Proxy(procedureClient, {
27
+ get(target, key) {
28
+ if (typeof key !== "string") {
29
+ return Reflect.get(target, key);
36
30
  }
37
- })();
38
- if (!response.ok) {
39
- throw ORPCError.fromJSON(json) ?? new ORPCError({
40
- status: response.status,
41
- code: "INTERNAL_SERVER_ERROR",
42
- message: "Internal server error"
31
+ return createORPCClient(link, {
32
+ ...options,
33
+ path: [...path, key]
43
34
  });
44
35
  }
45
- return json;
46
- };
47
- return client;
36
+ });
37
+ return recursive;
48
38
  }
49
39
 
50
- // src/router.ts
51
- function createRouterClient(options) {
52
- const path = options?.path ?? [];
53
- const client = new Proxy(
54
- createProcedureClient({
55
- baseURL: options.baseURL,
56
- fetch: options.fetch,
57
- headers: options.headers,
58
- path
59
- }),
60
- {
61
- get(target, key) {
62
- if (typeof key !== "string") {
63
- return Reflect.get(target, key);
64
- }
65
- return createRouterClient({
66
- ...options,
67
- path: [...path, key]
68
- });
69
- }
40
+ // src/dynamic-link.ts
41
+ var DynamicLink = class {
42
+ constructor(linkResolver) {
43
+ this.linkResolver = linkResolver;
44
+ }
45
+ async call(path, input, options) {
46
+ const resolvedLink = await this.linkResolver(options, path, input);
47
+ const output = await resolvedLink.call(path, input, options);
48
+ return output;
49
+ }
50
+ };
51
+
52
+ // src/utils.ts
53
+ async function safe(promise) {
54
+ try {
55
+ const output = await promise;
56
+ return Object.assign(
57
+ [null, output, false],
58
+ { error: null, data: output, isDefined: false }
59
+ );
60
+ } catch (e) {
61
+ const error = e;
62
+ if (isDefinedError(error)) {
63
+ return Object.assign(
64
+ [error, void 0, true],
65
+ { error, data: void 0, isDefined: true }
66
+ );
70
67
  }
71
- );
72
- return client;
68
+ return Object.assign(
69
+ [error, void 0, false],
70
+ { error, data: void 0, isDefined: false }
71
+ );
72
+ }
73
73
  }
74
-
75
- // src/index.ts
76
- export * from "@orpc/shared/error";
77
- var createORPCClient = createRouterClient;
78
74
  export {
75
+ COMMON_ORPC_ERROR_DEFS,
76
+ DynamicLink,
77
+ ORPCError,
78
+ createAutoRetryEventIterator,
79
79
  createORPCClient,
80
- createProcedureClient,
81
- createRouterClient
80
+ fallbackORPCErrorMessage,
81
+ fallbackORPCErrorStatus,
82
+ isDefinedError,
83
+ mapEventIterator,
84
+ onEventIteratorStatusChange,
85
+ registerEventIteratorState,
86
+ safe,
87
+ toORPCError,
88
+ updateEventIteratorStatus
82
89
  };
83
90
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,232 @@
1
+ import {
2
+ ORPCError,
3
+ mapEventIterator,
4
+ toORPCError
5
+ } from "./chunk-7F3XVLRJ.js";
6
+
7
+ // src/openapi/bracket-notation.ts
8
+ import { isObject } from "@orpc/shared";
9
+ var BracketNotationSerializer = class {
10
+ serialize(data, segments = [], result = []) {
11
+ if (Array.isArray(data)) {
12
+ data.forEach((item, i) => {
13
+ this.serialize(item, [...segments, i], result);
14
+ });
15
+ } else if (isObject(data)) {
16
+ for (const key in data) {
17
+ this.serialize(data[key], [...segments, key], result);
18
+ }
19
+ } else {
20
+ result.push([this.stringifyPath(segments), data]);
21
+ }
22
+ return result;
23
+ }
24
+ deserialize(serialized) {
25
+ const arrayPushStyles = /* @__PURE__ */ new WeakSet();
26
+ const ref = { value: [] };
27
+ for (const [path, value] of serialized) {
28
+ const segments = this.parsePath(path);
29
+ let currentRef = ref;
30
+ let nextSegment = "value";
31
+ segments.forEach((segment, i) => {
32
+ if (!Array.isArray(currentRef[nextSegment]) && !isObject(currentRef[nextSegment])) {
33
+ currentRef[nextSegment] = [];
34
+ }
35
+ if (i !== segments.length - 1) {
36
+ if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment)) {
37
+ currentRef[nextSegment] = { ...currentRef[nextSegment] };
38
+ }
39
+ } else {
40
+ if (Array.isArray(currentRef[nextSegment])) {
41
+ if (segment === "") {
42
+ if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
43
+ currentRef[nextSegment] = { ...currentRef[nextSegment] };
44
+ }
45
+ } else {
46
+ if (arrayPushStyles.has(currentRef[nextSegment])) {
47
+ currentRef[nextSegment] = { "": currentRef[nextSegment].at(-1) };
48
+ } else if (!isValidArrayIndex(segment)) {
49
+ currentRef[nextSegment] = { ...currentRef[nextSegment] };
50
+ }
51
+ }
52
+ }
53
+ }
54
+ currentRef = currentRef[nextSegment];
55
+ nextSegment = segment;
56
+ });
57
+ if (Array.isArray(currentRef)) {
58
+ if (nextSegment === "") {
59
+ arrayPushStyles.add(currentRef);
60
+ currentRef.push(value);
61
+ } else {
62
+ currentRef[Number(nextSegment)] = value;
63
+ }
64
+ } else {
65
+ currentRef[nextSegment] = value;
66
+ }
67
+ }
68
+ return ref.value;
69
+ }
70
+ stringifyPath(segments) {
71
+ return segments.map((segment) => {
72
+ return segment.toString().replace(/[\\[\]]/g, (match) => {
73
+ switch (match) {
74
+ case "\\":
75
+ return "\\\\";
76
+ case "[":
77
+ return "\\[";
78
+ case "]":
79
+ return "\\]";
80
+ /* v8 ignore next 2 */
81
+ default:
82
+ return match;
83
+ }
84
+ });
85
+ }).reduce((result, segment, i) => {
86
+ if (i === 0) {
87
+ return segment;
88
+ }
89
+ return `${result}[${segment}]`;
90
+ }, "");
91
+ }
92
+ parsePath(path) {
93
+ const segments = [];
94
+ let inBrackets = false;
95
+ let currentSegment = "";
96
+ let backslashCount = 0;
97
+ for (let i = 0; i < path.length; i++) {
98
+ const char = path[i];
99
+ const nextChar = path[i + 1];
100
+ if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[") && backslashCount % 2 === 0) {
101
+ if (nextChar === void 0) {
102
+ inBrackets = false;
103
+ }
104
+ segments.push(currentSegment);
105
+ currentSegment = "";
106
+ i++;
107
+ } else if (segments.length === 0 && char === "[" && backslashCount % 2 === 0) {
108
+ inBrackets = true;
109
+ segments.push(currentSegment);
110
+ currentSegment = "";
111
+ } else if (char === "\\") {
112
+ backslashCount++;
113
+ } else {
114
+ currentSegment += "\\".repeat(backslashCount / 2) + char;
115
+ backslashCount = 0;
116
+ }
117
+ }
118
+ return inBrackets || segments.length === 0 ? [path] : segments;
119
+ }
120
+ };
121
+ function isValidArrayIndex(value) {
122
+ return /^0$|^[1-9]\d*$/.test(value);
123
+ }
124
+
125
+ // src/openapi/json-serializer.ts
126
+ import { isObject as isObject2 } from "@orpc/shared";
127
+ var OpenAPIJsonSerializer = class {
128
+ serialize(data, hasBlobRef = { value: false }) {
129
+ if (data instanceof Blob) {
130
+ hasBlobRef.value = true;
131
+ return [data, hasBlobRef.value];
132
+ }
133
+ if (data instanceof Set) {
134
+ return this.serialize(Array.from(data), hasBlobRef);
135
+ }
136
+ if (data instanceof Map) {
137
+ return this.serialize(Array.from(data.entries()), hasBlobRef);
138
+ }
139
+ if (Array.isArray(data)) {
140
+ const json = data.map((v) => v === void 0 ? null : this.serialize(v, hasBlobRef)[0]);
141
+ return [json, hasBlobRef.value];
142
+ }
143
+ if (isObject2(data)) {
144
+ const json = {};
145
+ for (const k in data) {
146
+ json[k] = this.serialize(data[k], hasBlobRef)[0];
147
+ }
148
+ return [json, hasBlobRef.value];
149
+ }
150
+ if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
151
+ return [data.toString(), hasBlobRef.value];
152
+ }
153
+ if (data instanceof Date) {
154
+ return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
155
+ }
156
+ if (Number.isNaN(data)) {
157
+ return [null, hasBlobRef.value];
158
+ }
159
+ return [data, hasBlobRef.value];
160
+ }
161
+ };
162
+
163
+ // src/openapi/serializer.ts
164
+ import { isAsyncIteratorObject } from "@orpc/shared";
165
+ import { ErrorEvent } from "@orpc/standard-server";
166
+ var OpenAPISerializer = class {
167
+ constructor(jsonSerializer = new OpenAPIJsonSerializer(), bracketNotation = new BracketNotationSerializer()) {
168
+ this.jsonSerializer = jsonSerializer;
169
+ this.bracketNotation = bracketNotation;
170
+ }
171
+ serialize(data) {
172
+ if (isAsyncIteratorObject(data)) {
173
+ return mapEventIterator(data, {
174
+ value: async (value) => this.#serialize(value, false),
175
+ error: async (e) => {
176
+ if (e instanceof ErrorEvent) {
177
+ return new ErrorEvent({
178
+ data: this.#serialize(e.data, false),
179
+ cause: e
180
+ });
181
+ }
182
+ return new ErrorEvent({
183
+ data: this.#serialize(toORPCError(e).toJSON(), false),
184
+ cause: e
185
+ });
186
+ }
187
+ });
188
+ }
189
+ return this.#serialize(data, true);
190
+ }
191
+ #serialize(data, enableFormData) {
192
+ if (data instanceof Blob || data === void 0) {
193
+ return data;
194
+ }
195
+ const [json, hasBlob] = this.jsonSerializer.serialize(data);
196
+ if (!enableFormData || !hasBlob) {
197
+ return json;
198
+ }
199
+ const form = new FormData();
200
+ for (const [path, value] of this.bracketNotation.serialize(json)) {
201
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
202
+ form.append(path, value.toString());
203
+ } else if (value instanceof Blob) {
204
+ form.append(path, value);
205
+ }
206
+ }
207
+ return form;
208
+ }
209
+ deserialize(data) {
210
+ if (data instanceof URLSearchParams || data instanceof FormData) {
211
+ return this.bracketNotation.deserialize(Array.from(data.entries()));
212
+ }
213
+ if (isAsyncIteratorObject(data)) {
214
+ return mapEventIterator(data, {
215
+ value: async (value) => value,
216
+ error: async (e) => {
217
+ if (e instanceof ErrorEvent && ORPCError.isValidJSON(e.data)) {
218
+ return ORPCError.fromJSON(e.data, { cause: e });
219
+ }
220
+ return e;
221
+ }
222
+ });
223
+ }
224
+ return data;
225
+ }
226
+ };
227
+ export {
228
+ BracketNotationSerializer,
229
+ OpenAPIJsonSerializer,
230
+ OpenAPISerializer
231
+ };
232
+ //# sourceMappingURL=openapi.js.map
package/dist/rpc.js ADDED
@@ -0,0 +1,10 @@
1
+ import {
2
+ RPCJsonSerializer,
3
+ RPCSerializer
4
+ } from "./chunk-FF5VXXNP.js";
5
+ import "./chunk-7F3XVLRJ.js";
6
+ export {
7
+ RPCJsonSerializer,
8
+ RPCSerializer
9
+ };
10
+ //# sourceMappingURL=rpc.js.map
@@ -0,0 +1,3 @@
1
+ export * from './rpc-link';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,98 @@
1
+ import type { Value } from '@orpc/shared';
2
+ import type { ClientContext, ClientLink, ClientOptionsOut } from '../../types';
3
+ import type { FetchWithContext } from './types';
4
+ import { type EventIteratorReconnectOptions } from '../../event-iterator';
5
+ import { RPCSerializer } from '../../rpc';
6
+ type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
7
+ export declare class InvalidEventSourceRetryResponse extends Error {
8
+ }
9
+ export interface RPCLinkOptions<TClientContext extends ClientContext> {
10
+ /**
11
+ * Base url for all requests.
12
+ */
13
+ url: string;
14
+ /**
15
+ * The maximum length of the URL.
16
+ *
17
+ * @default 2083
18
+ */
19
+ maxUrlLength?: number;
20
+ /**
21
+ * The method used to make the request.
22
+ *
23
+ * @default 'POST'
24
+ */
25
+ method?: Value<HTTPMethod, [
26
+ options: ClientOptionsOut<TClientContext>,
27
+ path: readonly string[],
28
+ input: unknown
29
+ ]>;
30
+ /**
31
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
32
+ * GET is not allowed, it's very dangerous.
33
+ *
34
+ * @default 'POST'
35
+ */
36
+ fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
37
+ /**
38
+ * Inject headers to the request.
39
+ */
40
+ headers?: Value<[string, string][] | Record<string, string> | Headers, [
41
+ options: ClientOptionsOut<TClientContext>,
42
+ path: readonly string[],
43
+ input: unknown
44
+ ]>;
45
+ /**
46
+ * Custom fetch implementation.
47
+ *
48
+ * @default globalThis.fetch.bind(globalThis)
49
+ */
50
+ fetch?: FetchWithContext<TClientContext>;
51
+ rpcSerializer?: RPCSerializer;
52
+ /**
53
+ * Maximum number of retry attempts for EventSource errors before throwing.
54
+ *
55
+ * @default 5
56
+ */
57
+ eventSourceMaxNumberOfRetries?: number;
58
+ /**
59
+ * Delay (in ms) before retrying an EventSource call.
60
+ *
61
+ * @default ({retryTimes, lastRetry}) => lastRetry ?? (1000 * 2 ** retryTimes)
62
+ */
63
+ eventSourceRetryDelay?: Value<number, [
64
+ reconnectOptions: EventIteratorReconnectOptions,
65
+ options: ClientOptionsOut<TClientContext>,
66
+ path: readonly string[],
67
+ input: unknown
68
+ ]>;
69
+ /**
70
+ * Function to determine if an error is retryable.
71
+ *
72
+ * @default true
73
+ */
74
+ eventSourceRetry?: Value<boolean, [
75
+ reconnectOptions: EventIteratorReconnectOptions,
76
+ options: ClientOptionsOut<TClientContext>,
77
+ path: readonly string[],
78
+ input: unknown
79
+ ]>;
80
+ }
81
+ export declare class RPCLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
82
+ private readonly fetch;
83
+ private readonly rpcSerializer;
84
+ private readonly maxUrlLength;
85
+ private readonly fallbackMethod;
86
+ private readonly method;
87
+ private readonly headers;
88
+ private readonly url;
89
+ private readonly eventSourceMaxNumberOfRetries;
90
+ private readonly eventSourceRetryDelay;
91
+ private readonly eventSourceRetry;
92
+ constructor(options: RPCLinkOptions<TClientContext>);
93
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
94
+ private performCall;
95
+ private encodeRequest;
96
+ }
97
+ export {};
98
+ //# sourceMappingURL=rpc-link.d.ts.map
@@ -0,0 +1,5 @@
1
+ import type { ClientContext, ClientOptionsOut } from '../../types';
2
+ export interface FetchWithContext<TClientContext extends ClientContext> {
3
+ (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
4
+ }
5
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,9 @@
1
+ import type { ClientLink, InferClientContext, NestedClient } from './types';
2
+ export interface createORPCClientOptions {
3
+ /**
4
+ * Use as base path for all procedure, useful when you only want to call a subset of the procedure.
5
+ */
6
+ path?: string[];
7
+ }
8
+ export declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
9
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,12 @@
1
+ import type { Promisable } from '@orpc/shared';
2
+ import type { ClientContext, ClientLink, ClientOptionsOut } from './types';
3
+ /**
4
+ * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
5
+ * based on the request path, input, and context.
6
+ */
7
+ export declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
8
+ private readonly linkResolver;
9
+ constructor(linkResolver: (options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
10
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
11
+ }
12
+ //# sourceMappingURL=dynamic-link.d.ts.map
@@ -0,0 +1,106 @@
1
+ import { type MaybeOptionalOptions } from '@orpc/shared';
2
+ export declare const COMMON_ORPC_ERROR_DEFS: {
3
+ readonly BAD_REQUEST: {
4
+ readonly status: 400;
5
+ readonly message: "Bad Request";
6
+ };
7
+ readonly UNAUTHORIZED: {
8
+ readonly status: 401;
9
+ readonly message: "Unauthorized";
10
+ };
11
+ readonly FORBIDDEN: {
12
+ readonly status: 403;
13
+ readonly message: "Forbidden";
14
+ };
15
+ readonly NOT_FOUND: {
16
+ readonly status: 404;
17
+ readonly message: "Not Found";
18
+ };
19
+ readonly METHOD_NOT_SUPPORTED: {
20
+ readonly status: 405;
21
+ readonly message: "Method Not Supported";
22
+ };
23
+ readonly NOT_ACCEPTABLE: {
24
+ readonly status: 406;
25
+ readonly message: "Not Acceptable";
26
+ };
27
+ readonly TIMEOUT: {
28
+ readonly status: 408;
29
+ readonly message: "Request Timeout";
30
+ };
31
+ readonly CONFLICT: {
32
+ readonly status: 409;
33
+ readonly message: "Conflict";
34
+ };
35
+ readonly PRECONDITION_FAILED: {
36
+ readonly status: 412;
37
+ readonly message: "Precondition Failed";
38
+ };
39
+ readonly PAYLOAD_TOO_LARGE: {
40
+ readonly status: 413;
41
+ readonly message: "Payload Too Large";
42
+ };
43
+ readonly UNSUPPORTED_MEDIA_TYPE: {
44
+ readonly status: 415;
45
+ readonly message: "Unsupported Media Type";
46
+ };
47
+ readonly UNPROCESSABLE_CONTENT: {
48
+ readonly status: 422;
49
+ readonly message: "Unprocessable Content";
50
+ };
51
+ readonly TOO_MANY_REQUESTS: {
52
+ readonly status: 429;
53
+ readonly message: "Too Many Requests";
54
+ };
55
+ readonly CLIENT_CLOSED_REQUEST: {
56
+ readonly status: 499;
57
+ readonly message: "Client Closed Request";
58
+ };
59
+ readonly INTERNAL_SERVER_ERROR: {
60
+ readonly status: 500;
61
+ readonly message: "Internal Server Error";
62
+ };
63
+ readonly NOT_IMPLEMENTED: {
64
+ readonly status: 501;
65
+ readonly message: "Not Implemented";
66
+ };
67
+ readonly BAD_GATEWAY: {
68
+ readonly status: 502;
69
+ readonly message: "Bad Gateway";
70
+ };
71
+ readonly SERVICE_UNAVAILABLE: {
72
+ readonly status: 503;
73
+ readonly message: "Service Unavailable";
74
+ };
75
+ readonly GATEWAY_TIMEOUT: {
76
+ readonly status: 504;
77
+ readonly message: "Gateway Timeout";
78
+ };
79
+ };
80
+ export type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
81
+ export type ORPCErrorCode = CommonORPCErrorCode | (string & {});
82
+ export declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
83
+ export declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
84
+ export type ORPCErrorOptions<TData> = ErrorOptions & {
85
+ defined?: boolean;
86
+ status?: number;
87
+ message?: string;
88
+ } & (undefined extends TData ? {
89
+ data?: TData;
90
+ } : {
91
+ data: TData;
92
+ });
93
+ export declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
94
+ readonly defined: boolean;
95
+ readonly code: TCode;
96
+ readonly status: number;
97
+ readonly data: TData;
98
+ constructor(code: TCode, ...[options]: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
99
+ toJSON(): ORPCErrorJSON<TCode, TData>;
100
+ static fromJSON<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
101
+ static isValidJSON(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
102
+ }
103
+ export type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
104
+ export declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
105
+ export declare function toORPCError(error: unknown): ORPCError<any, any>;
106
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1,9 @@
1
+ export type ConnectionStatus = 'reconnecting' | 'connected' | 'closed';
2
+ export interface EventIteratorState {
3
+ status: ConnectionStatus;
4
+ listeners: Array<(newStatus: ConnectionStatus) => void>;
5
+ }
6
+ export declare function registerEventIteratorState(iterator: AsyncIteratorObject<unknown, unknown, void>, state: EventIteratorState): void;
7
+ export declare function updateEventIteratorStatus(state: EventIteratorState, status: ConnectionStatus): void;
8
+ export declare function onEventIteratorStatusChange(iterator: AsyncIteratorObject<unknown, unknown, void>, callback: (status: ConnectionStatus) => void, notifyImmediately?: boolean): () => void;
9
+ //# sourceMappingURL=event-iterator-state.d.ts.map
@@ -0,0 +1,12 @@
1
+ export declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
2
+ value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
3
+ error: (error: unknown) => Promise<unknown>;
4
+ }): AsyncGenerator<TMap, TMap, TNext>;
5
+ export interface EventIteratorReconnectOptions {
6
+ lastRetry: number | undefined;
7
+ lastEventId: string | undefined;
8
+ retryTimes: number;
9
+ error: unknown;
10
+ }
11
+ export 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>;
12
+ //# sourceMappingURL=event-iterator.d.ts.map