@temporary-name/shared 1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05 → 1.9.3-alpha.62d88f5cf3908d4411b5278f1824b69334da8072

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.mts CHANGED
@@ -1,157 +1,95 @@
1
- import { MaybeOptionalOptions as MaybeOptionalOptions$1, ThrowableError as ThrowableError$1 } from '@temporary-name/shared';
2
1
  import { Tracer, TraceAPI, ContextAPI, PropagationAPI, SpanOptions, Context, Span, AttributeValue, Exception } from '@opentelemetry/api';
3
2
  export { group, guard, mapEntries, mapValues, omit, retry, sleep } from 'radash';
3
+ export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
4
4
 
5
- type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
5
+ type MaybeOptionalOptions<TOptions> = object extends TOptions ? [options?: TOptions] : [options: TOptions];
6
6
  type OptionalIfEmpty<TOptions> = {} extends TOptions ? [options?: TOptions] : [options: TOptions];
7
7
  declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
8
8
 
9
9
  declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
10
- declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
11
10
 
12
- /**
13
- * Converts Request/Response/Blob/File/.. to a buffer (ArrayBuffer or Uint8Array).
14
- *
15
- * Prefers the newer `.bytes` method when available as it more efficient but not widely supported yet.
16
- */
17
- declare function readAsBuffer(source: Pick<Blob, 'arrayBuffer' | 'bytes'>): Promise<ArrayBuffer | Uint8Array>;
18
-
19
- type AnyFunction = (...args: any[]) => any;
20
- declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
21
- declare function sequential<A extends any[], R>(fn: (...args: A) => Promise<R>): (...args: A) => Promise<R>;
22
- /**
23
- * Executes the callback function after the current call stack has been cleared.
24
- */
25
- declare function defer(callback: () => void): void;
26
-
27
- type OmitChainMethodDeep<T extends object, K extends keyof any> = {
28
- [P in keyof Omit<T, K>]: T[P] extends AnyFunction ? (...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K> : T[P];
11
+ type StandardBody = undefined | unknown | Blob | URLSearchParams | FormData | AsyncIterator<unknown | void, unknown | void, undefined>;
12
+ interface StandardRequest {
13
+ method: string;
14
+ url: URL;
15
+ headers: Headers;
16
+ /**
17
+ * The body has been parsed based on the content-type header.
18
+ */
19
+ body: StandardBody;
20
+ signal: AbortSignal | undefined;
21
+ }
22
+ interface StandardLazyRequest extends Omit<StandardRequest, 'body'> {
23
+ /**
24
+ * The body has been parsed based on the content-type header.
25
+ * This method can safely call multiple times (cached).
26
+ */
27
+ body: () => Promise<StandardBody>;
28
+ }
29
+ interface StandardResponse {
30
+ status: number;
31
+ headers: Headers;
32
+ /**
33
+ * The body has been parsed based on the content-type header.
34
+ */
35
+ body: StandardBody;
36
+ }
37
+ interface StandardLazyResponse extends Omit<StandardResponse, 'body'> {
38
+ /**
39
+ * The body has been parsed based on the content-type header.
40
+ * This method can safely call multiple times (cached).
41
+ */
42
+ body: () => Promise<StandardBody>;
43
+ }
44
+ type HTTPPath = `/${string}`;
45
+ declare const HTTPMethods: readonly ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"];
46
+ type HTTPMethod = (typeof HTTPMethods)[number];
47
+ type HTTPEndpoint = `${HTTPMethod} ${HTTPPath}`;
48
+ type ClientContext = object;
49
+ interface ClientOptions<T extends ClientContext> {
50
+ request?: StandardLazyRequest;
51
+ signal?: AbortSignal;
52
+ lastEventId?: string | undefined;
53
+ context: T;
54
+ }
55
+ type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? {
56
+ context?: T;
57
+ } : {
58
+ context: T;
59
+ });
60
+ type ClientRest<TClientContext extends ClientContext, TInput> = object extends TClientContext ? undefined extends TInput ? [
61
+ input?: TInput,
62
+ options?: FriendlyClientOptions<TClientContext>
63
+ ] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
64
+ interface Client<TClientContext extends ClientContext, TInput, TOutput> {
65
+ (...rest: ClientRest<TClientContext, TInput>): Promise<TOutput>;
66
+ }
67
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any> | {
68
+ [k: string]: NestedClient<TClientContext>;
29
69
  };
70
+ type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
71
+ interface ClientLink<TClientContext extends ClientContext> {
72
+ call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
73
+ }
74
+ type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
75
+ type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
76
+ type InferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : never;
77
+ type IsEqual<A, B> = (<G>() => G extends (A & G) | G ? 1 : 2) extends <G>() => G extends (B & G) | G ? 1 : 2 ? true : false;
78
+ type Promisable<T> = T | PromiseLike<T>;
79
+
80
+ type OutputStructure = 'compact' | 'detailed';
81
+ interface ContractConfig {
82
+ defaultMethod: HTTPMethod;
83
+ defaultSuccessStatus: number;
84
+ defaultSuccessDescription: string;
85
+ defaultOutputStructure: OutputStructure;
86
+ }
87
+ declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
30
88
 
31
89
  declare const ORPC_NAME = "orpc";
32
90
  declare const ORPC_SHARED_PACKAGE_NAME = "@temporary-name/shared";
33
- declare const ORPC_SHARED_PACKAGE_VERSION = "1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05";
91
+ declare const ORPC_SHARED_PACKAGE_VERSION = "1.9.3-alpha.62d88f5cf3908d4411b5278f1824b69334da8072";
34
92
 
35
- declare const ORPC_CLIENT_PACKAGE_NAME = "__ORPC_CLIENT_PACKAGE_NAME_PLACEHOLDER__";
36
- declare const ORPC_CLIENT_PACKAGE_VERSION = "__ORPC_CLIENT_PACKAGE_VERSION_PLACEHOLDER__";
37
- declare const COMMON_ORPC_ERROR_DEFS: {
38
- readonly BAD_REQUEST: {
39
- readonly status: 400;
40
- readonly message: "Bad Request";
41
- };
42
- readonly UNAUTHORIZED: {
43
- readonly status: 401;
44
- readonly message: "Unauthorized";
45
- };
46
- readonly FORBIDDEN: {
47
- readonly status: 403;
48
- readonly message: "Forbidden";
49
- };
50
- readonly NOT_FOUND: {
51
- readonly status: 404;
52
- readonly message: "Not Found";
53
- };
54
- readonly METHOD_NOT_SUPPORTED: {
55
- readonly status: 405;
56
- readonly message: "Method Not Supported";
57
- };
58
- readonly NOT_ACCEPTABLE: {
59
- readonly status: 406;
60
- readonly message: "Not Acceptable";
61
- };
62
- readonly TIMEOUT: {
63
- readonly status: 408;
64
- readonly message: "Request Timeout";
65
- };
66
- readonly CONFLICT: {
67
- readonly status: 409;
68
- readonly message: "Conflict";
69
- };
70
- readonly PRECONDITION_FAILED: {
71
- readonly status: 412;
72
- readonly message: "Precondition Failed";
73
- };
74
- readonly PAYLOAD_TOO_LARGE: {
75
- readonly status: 413;
76
- readonly message: "Payload Too Large";
77
- };
78
- readonly UNSUPPORTED_MEDIA_TYPE: {
79
- readonly status: 415;
80
- readonly message: "Unsupported Media Type";
81
- };
82
- readonly UNPROCESSABLE_CONTENT: {
83
- readonly status: 422;
84
- readonly message: "Unprocessable Content";
85
- };
86
- readonly TOO_MANY_REQUESTS: {
87
- readonly status: 429;
88
- readonly message: "Too Many Requests";
89
- };
90
- readonly CLIENT_CLOSED_REQUEST: {
91
- readonly status: 499;
92
- readonly message: "Client Closed Request";
93
- };
94
- readonly INTERNAL_SERVER_ERROR: {
95
- readonly status: 500;
96
- readonly message: "Internal Server Error";
97
- };
98
- readonly NOT_IMPLEMENTED: {
99
- readonly status: 501;
100
- readonly message: "Not Implemented";
101
- };
102
- readonly BAD_GATEWAY: {
103
- readonly status: 502;
104
- readonly message: "Bad Gateway";
105
- };
106
- readonly SERVICE_UNAVAILABLE: {
107
- readonly status: 503;
108
- readonly message: "Service Unavailable";
109
- };
110
- readonly GATEWAY_TIMEOUT: {
111
- readonly status: 504;
112
- readonly message: "Gateway Timeout";
113
- };
114
- };
115
- type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
116
- type ORPCErrorCode = CommonORPCErrorCode | (string & {});
117
- declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
118
- declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
119
- type ORPCErrorOptions<TData> = ErrorOptions & {
120
- defined?: boolean;
121
- status?: number;
122
- message?: string;
123
- } & (undefined extends TData ? {
124
- data?: TData;
125
- } : {
126
- data: TData;
127
- });
128
- declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
129
- readonly defined: boolean;
130
- readonly code: TCode;
131
- readonly status: number;
132
- readonly data: TData;
133
- constructor(code: TCode, ...rest: MaybeOptionalOptions$1<ORPCErrorOptions<TData>>);
134
- toJSON(): ORPCErrorJSON<TCode, TData>;
135
- /**
136
- * Workaround for Next.js where different contexts use separate
137
- * dependency graphs, causing multiple ORPCError constructors existing and breaking
138
- * `instanceof` checks across contexts.
139
- *
140
- * This is particularly problematic with "Optimized SSR", where orpc-client
141
- * executes in one context but is invoked from another. When an error is thrown
142
- * in the execution context, `instanceof ORPCError` checks fail in the
143
- * invocation context due to separate class constructors.
144
- *
145
- * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
146
- */
147
- static [Symbol.hasInstance](instance: unknown): boolean;
148
- }
149
- type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
150
- declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
151
- declare function toORPCError(error: unknown): ORPCError<any, any>;
152
- declare function isORPCErrorStatus(status: number): boolean;
153
- declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
154
- declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
155
93
  /**
156
94
  * Error thrown when an operation is aborted.
157
95
  * Uses the standardized 'AbortError' name for consistency with JavaScript APIs.
@@ -219,101 +157,14 @@ declare class EventPublisher<T extends Record<PropertyKey, any>> {
219
157
  subscribe<K extends keyof T>(event: K, options?: EventPublisherSubscribeIteratorOptions): AsyncGenerator<T[K]> & AsyncIteratorObject<T[K]>;
220
158
  }
221
159
 
222
- declare class SequentialIdGenerator {
223
- private index;
224
- generate(): string;
225
- }
226
-
227
- type StandardBody = undefined | unknown | Blob | URLSearchParams | FormData | AsyncIterator<unknown | void, unknown | void, undefined>;
228
- interface StandardRequest {
229
- method: string;
230
- url: URL;
231
- headers: Headers;
232
- /**
233
- * The body has been parsed based on the content-type header.
234
- */
235
- body: StandardBody;
236
- signal: AbortSignal | undefined;
237
- }
238
- interface StandardLazyRequest extends Omit<StandardRequest, 'body'> {
239
- /**
240
- * The body has been parsed based on the content-type header.
241
- * This method can safely call multiple times (cached).
242
- */
243
- body: () => Promise<StandardBody>;
244
- }
245
- interface StandardResponse {
246
- status: number;
247
- headers: Headers;
248
- /**
249
- * The body has been parsed based on the content-type header.
250
- */
251
- body: StandardBody;
252
- }
253
- interface StandardLazyResponse extends Omit<StandardResponse, 'body'> {
254
- /**
255
- * The body has been parsed based on the content-type header.
256
- * This method can safely call multiple times (cached).
257
- */
258
- body: () => Promise<StandardBody>;
259
- }
260
- type HTTPPath = `/${string}`;
261
- declare const HTTPMethods: readonly ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"];
262
- type HTTPMethod = (typeof HTTPMethods)[number];
263
- type HTTPEndpoint = `${HTTPMethod} ${HTTPPath}`;
264
- type ClientContext = Record<PropertyKey, any>;
265
- interface ClientOptions<T extends ClientContext> {
266
- request?: StandardLazyRequest;
267
- signal?: AbortSignal;
268
- lastEventId?: string | undefined;
269
- context: T;
270
- }
271
- type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
272
- context?: T;
273
- } : {
274
- context: T;
275
- });
276
- type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [
277
- input?: TInput,
278
- options?: FriendlyClientOptions<TClientContext>
279
- ] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
280
- type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
281
- interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
282
- (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
283
- }
284
- type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
285
- [k: string]: NestedClient<TClientContext>;
286
- };
287
- type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
288
- interface ClientLink<TClientContext extends ClientContext> {
289
- call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
290
- }
291
- type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
292
- type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
293
- type PromiseWithError<T, TError> = Promise<T> & {
294
- __error?: {
295
- type: TError;
296
- };
297
- };
160
+ type AnyFunction = (...args: any[]) => any;
161
+ declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
162
+ declare function sequential<A extends any[], R>(fn: (...args: A) => Promise<R>): (...args: A) => Promise<R>;
298
163
  /**
299
- * The place where you can config the orpc types.
300
- *
301
- * - `throwableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
164
+ * Executes the callback function after the current call stack has been cleared.
302
165
  */
303
- interface Registry {
304
- }
305
- type ThrowableError = Registry extends {
306
- throwableError: infer T;
307
- } ? T : Error;
308
- type InferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : never;
309
- type IsEqual<A, B> = (<G>() => G extends (A & G) | G ? 1 : 2) extends <G>() => G extends (B & G) | G ? 1 : 2 ? true : false;
310
- type Promisable<T> = T | PromiseLike<T>;
166
+ declare function defer(callback: () => void): void;
311
167
 
312
- type InterceptableOptions = Record<string, any>;
313
- type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
314
- next(options?: TOptions): TResult;
315
- };
316
- type Interceptor<TOptions extends InterceptableOptions, TResult> = (options: InterceptorOptions<TOptions, TResult>) => TResult;
317
168
  /**
318
169
  * Can used for interceptors or middlewares
319
170
  */
@@ -331,15 +182,14 @@ declare function onSuccess<T, TOptions extends {
331
182
  */
332
183
  declare function onError<T, TOptions extends {
333
184
  next(): any;
334
- }, TRest extends any[]>(callback: NoInfer<(error: ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
185
+ }, TRest extends any[]>(callback: NoInfer<(error: Error, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
335
186
  type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
336
187
  /**
337
188
  * Can used for interceptors or middlewares
338
189
  */
339
190
  declare function onFinish<T, TOptions extends {
340
191
  next(): any;
341
- }, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>, ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
342
- declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
192
+ }, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>, Error>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
343
193
 
344
194
  /**
345
195
  * Only import types from @opentelemetry/api to avoid runtime dependencies.
@@ -471,17 +321,7 @@ declare const NullProtoObj: {
471
321
 
472
322
  type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
473
323
  declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
474
- /**
475
- * Returns the value if it is defined, otherwise returns the fallback
476
- */
477
- declare function fallback<T>(value: T | undefined, fallback: T): T;
478
324
 
479
- /**
480
- * Prevents objects from being awaitable by intercepting the `then` method
481
- * when called by the native await mechanism. This is useful for preventing
482
- * accidental awaiting of objects that aren't meant to be promises.
483
- */
484
- declare function preventNativeAwait<T extends object>(target: T): T;
485
325
  /**
486
326
  * Create a proxy that overlays one object (`overlay`) on top of another (`target`).
487
327
  *
@@ -517,32 +357,9 @@ declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableS
517
357
 
518
358
  declare function tryDecodeURIComponent(value: string): string;
519
359
 
520
- type SafeResult<TOutput, TError> = ([error: null, data: TOutput, isDefined: false, isSuccess: true] & {
521
- error: null;
522
- data: TOutput;
523
- isDefined: false;
524
- isSuccess: true;
525
- }) | ([error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, isSuccess: false] & {
526
- error: Exclude<TError, ORPCError<any, any>>;
527
- data: undefined;
528
- isDefined: false;
529
- isSuccess: false;
530
- }) | ([error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, isSuccess: false] & {
531
- error: Extract<TError, ORPCError<any, any>>;
532
- data: undefined;
533
- isDefined: true;
534
- isSuccess: false;
535
- });
536
- /**
537
- * Works like try/catch, but can infer error types.
538
- *
539
- * @info support both tuple `[error, data, isDefined, isSuccess]` and object `{ error, data, isDefined, isSuccess }` styles.
540
- * @see {@link https://orpc.unnoq.com/docs/client/error-handling Client Error Handling Docs}
541
- */
542
- declare function safe<TOutput, TError = ThrowableError$1>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
543
360
  declare function toHttpPath(path: readonly string[]): HTTPPath;
544
361
  declare function splitFirst(str: string, separator: string): [string, string];
545
- declare function assertNever(value: never): never;
362
+ declare function assertNever(value: never, message?: string): never;
546
363
 
547
- export { AbortError, AsyncIdQueue, AsyncIteratorClass, COMMON_ORPC_ERROR_DEFS, EventPublisher, HTTPMethods, NullProtoObj, ORPCError, ORPC_CLIENT_PACKAGE_NAME, ORPC_CLIENT_PACKAGE_VERSION, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, assertNever, asyncIteratorToStream, asyncIteratorWithSpan, clone, createORPCErrorFromJson, defer, fallback, fallbackORPCErrorMessage, fallbackORPCErrorStatus, findDeepMatches, get, getConstructor, getGlobalOtelConfig, intercept, isAsyncIteratorObject, isDefinedError, isORPCErrorJson, isORPCErrorStatus, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, overlayProxy, parseEmptyableJSON, preventNativeAwait, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, safe, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitFirst, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toHttpPath, toORPCError, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
548
- export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, AsyncIteratorWithSpanOptions, Client, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, ClientRest, CommonORPCErrorCode, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, FriendlyClientOptions, HTTPEndpoint, HTTPMethod, HTTPPath, InferAsyncIterableYield, InferClientContext, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, IsEqual, MaybeOptionalOptions, NestedClient, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, OmitChainMethodDeep, OnFinishState, OptionalIfEmpty, OtelConfig, Promisable, PromiseWithError, Registry, RunWithSpanOptions, SafeResult, Segment, SetOptional, SetSpanErrorOptions, StandardBody, StandardLazyRequest, StandardLazyResponse, StandardRequest, StandardResponse, ThrowableError, Value };
364
+ export { AbortError, AsyncIdQueue, AsyncIteratorClass, EventPublisher, HTTPMethods, NullProtoObj, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, assertNever, asyncIteratorToStream, asyncIteratorWithSpan, clone, defer, fallbackContractConfig, findDeepMatches, get, getConstructor, getGlobalOtelConfig, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, overlayProxy, parseEmptyableJSON, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitFirst, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toHttpPath, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
365
+ export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, AsyncIteratorWithSpanOptions, Client, ClientContext, ClientLink, ClientOptions, ClientRest, ContractConfig, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, FriendlyClientOptions, HTTPEndpoint, HTTPMethod, HTTPPath, InferAsyncIterableYield, InferClientContext, IntersectPick, IsEqual, MaybeOptionalOptions, NestedClient, OnFinishState, OptionalIfEmpty, OtelConfig, OutputStructure, Promisable, RunWithSpanOptions, Segment, SetOptional, SetSpanErrorOptions, StandardBody, StandardLazyRequest, StandardLazyResponse, StandardRequest, StandardResponse, Value };
package/dist/index.d.ts CHANGED
@@ -1,157 +1,95 @@
1
- import { MaybeOptionalOptions as MaybeOptionalOptions$1, ThrowableError as ThrowableError$1 } from '@temporary-name/shared';
2
1
  import { Tracer, TraceAPI, ContextAPI, PropagationAPI, SpanOptions, Context, Span, AttributeValue, Exception } from '@opentelemetry/api';
3
2
  export { group, guard, mapEntries, mapValues, omit, retry, sleep } from 'radash';
3
+ export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
4
4
 
5
- type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
5
+ type MaybeOptionalOptions<TOptions> = object extends TOptions ? [options?: TOptions] : [options: TOptions];
6
6
  type OptionalIfEmpty<TOptions> = {} extends TOptions ? [options?: TOptions] : [options: TOptions];
7
7
  declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
8
8
 
9
9
  declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
10
- declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
11
10
 
12
- /**
13
- * Converts Request/Response/Blob/File/.. to a buffer (ArrayBuffer or Uint8Array).
14
- *
15
- * Prefers the newer `.bytes` method when available as it more efficient but not widely supported yet.
16
- */
17
- declare function readAsBuffer(source: Pick<Blob, 'arrayBuffer' | 'bytes'>): Promise<ArrayBuffer | Uint8Array>;
18
-
19
- type AnyFunction = (...args: any[]) => any;
20
- declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
21
- declare function sequential<A extends any[], R>(fn: (...args: A) => Promise<R>): (...args: A) => Promise<R>;
22
- /**
23
- * Executes the callback function after the current call stack has been cleared.
24
- */
25
- declare function defer(callback: () => void): void;
26
-
27
- type OmitChainMethodDeep<T extends object, K extends keyof any> = {
28
- [P in keyof Omit<T, K>]: T[P] extends AnyFunction ? (...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K> : T[P];
11
+ type StandardBody = undefined | unknown | Blob | URLSearchParams | FormData | AsyncIterator<unknown | void, unknown | void, undefined>;
12
+ interface StandardRequest {
13
+ method: string;
14
+ url: URL;
15
+ headers: Headers;
16
+ /**
17
+ * The body has been parsed based on the content-type header.
18
+ */
19
+ body: StandardBody;
20
+ signal: AbortSignal | undefined;
21
+ }
22
+ interface StandardLazyRequest extends Omit<StandardRequest, 'body'> {
23
+ /**
24
+ * The body has been parsed based on the content-type header.
25
+ * This method can safely call multiple times (cached).
26
+ */
27
+ body: () => Promise<StandardBody>;
28
+ }
29
+ interface StandardResponse {
30
+ status: number;
31
+ headers: Headers;
32
+ /**
33
+ * The body has been parsed based on the content-type header.
34
+ */
35
+ body: StandardBody;
36
+ }
37
+ interface StandardLazyResponse extends Omit<StandardResponse, 'body'> {
38
+ /**
39
+ * The body has been parsed based on the content-type header.
40
+ * This method can safely call multiple times (cached).
41
+ */
42
+ body: () => Promise<StandardBody>;
43
+ }
44
+ type HTTPPath = `/${string}`;
45
+ declare const HTTPMethods: readonly ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"];
46
+ type HTTPMethod = (typeof HTTPMethods)[number];
47
+ type HTTPEndpoint = `${HTTPMethod} ${HTTPPath}`;
48
+ type ClientContext = object;
49
+ interface ClientOptions<T extends ClientContext> {
50
+ request?: StandardLazyRequest;
51
+ signal?: AbortSignal;
52
+ lastEventId?: string | undefined;
53
+ context: T;
54
+ }
55
+ type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? {
56
+ context?: T;
57
+ } : {
58
+ context: T;
59
+ });
60
+ type ClientRest<TClientContext extends ClientContext, TInput> = object extends TClientContext ? undefined extends TInput ? [
61
+ input?: TInput,
62
+ options?: FriendlyClientOptions<TClientContext>
63
+ ] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
64
+ interface Client<TClientContext extends ClientContext, TInput, TOutput> {
65
+ (...rest: ClientRest<TClientContext, TInput>): Promise<TOutput>;
66
+ }
67
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any> | {
68
+ [k: string]: NestedClient<TClientContext>;
29
69
  };
70
+ type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
71
+ interface ClientLink<TClientContext extends ClientContext> {
72
+ call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
73
+ }
74
+ type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
75
+ type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
76
+ type InferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : never;
77
+ type IsEqual<A, B> = (<G>() => G extends (A & G) | G ? 1 : 2) extends <G>() => G extends (B & G) | G ? 1 : 2 ? true : false;
78
+ type Promisable<T> = T | PromiseLike<T>;
79
+
80
+ type OutputStructure = 'compact' | 'detailed';
81
+ interface ContractConfig {
82
+ defaultMethod: HTTPMethod;
83
+ defaultSuccessStatus: number;
84
+ defaultSuccessDescription: string;
85
+ defaultOutputStructure: OutputStructure;
86
+ }
87
+ declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
30
88
 
31
89
  declare const ORPC_NAME = "orpc";
32
90
  declare const ORPC_SHARED_PACKAGE_NAME = "@temporary-name/shared";
33
- declare const ORPC_SHARED_PACKAGE_VERSION = "1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05";
91
+ declare const ORPC_SHARED_PACKAGE_VERSION = "1.9.3-alpha.62d88f5cf3908d4411b5278f1824b69334da8072";
34
92
 
35
- declare const ORPC_CLIENT_PACKAGE_NAME = "__ORPC_CLIENT_PACKAGE_NAME_PLACEHOLDER__";
36
- declare const ORPC_CLIENT_PACKAGE_VERSION = "__ORPC_CLIENT_PACKAGE_VERSION_PLACEHOLDER__";
37
- declare const COMMON_ORPC_ERROR_DEFS: {
38
- readonly BAD_REQUEST: {
39
- readonly status: 400;
40
- readonly message: "Bad Request";
41
- };
42
- readonly UNAUTHORIZED: {
43
- readonly status: 401;
44
- readonly message: "Unauthorized";
45
- };
46
- readonly FORBIDDEN: {
47
- readonly status: 403;
48
- readonly message: "Forbidden";
49
- };
50
- readonly NOT_FOUND: {
51
- readonly status: 404;
52
- readonly message: "Not Found";
53
- };
54
- readonly METHOD_NOT_SUPPORTED: {
55
- readonly status: 405;
56
- readonly message: "Method Not Supported";
57
- };
58
- readonly NOT_ACCEPTABLE: {
59
- readonly status: 406;
60
- readonly message: "Not Acceptable";
61
- };
62
- readonly TIMEOUT: {
63
- readonly status: 408;
64
- readonly message: "Request Timeout";
65
- };
66
- readonly CONFLICT: {
67
- readonly status: 409;
68
- readonly message: "Conflict";
69
- };
70
- readonly PRECONDITION_FAILED: {
71
- readonly status: 412;
72
- readonly message: "Precondition Failed";
73
- };
74
- readonly PAYLOAD_TOO_LARGE: {
75
- readonly status: 413;
76
- readonly message: "Payload Too Large";
77
- };
78
- readonly UNSUPPORTED_MEDIA_TYPE: {
79
- readonly status: 415;
80
- readonly message: "Unsupported Media Type";
81
- };
82
- readonly UNPROCESSABLE_CONTENT: {
83
- readonly status: 422;
84
- readonly message: "Unprocessable Content";
85
- };
86
- readonly TOO_MANY_REQUESTS: {
87
- readonly status: 429;
88
- readonly message: "Too Many Requests";
89
- };
90
- readonly CLIENT_CLOSED_REQUEST: {
91
- readonly status: 499;
92
- readonly message: "Client Closed Request";
93
- };
94
- readonly INTERNAL_SERVER_ERROR: {
95
- readonly status: 500;
96
- readonly message: "Internal Server Error";
97
- };
98
- readonly NOT_IMPLEMENTED: {
99
- readonly status: 501;
100
- readonly message: "Not Implemented";
101
- };
102
- readonly BAD_GATEWAY: {
103
- readonly status: 502;
104
- readonly message: "Bad Gateway";
105
- };
106
- readonly SERVICE_UNAVAILABLE: {
107
- readonly status: 503;
108
- readonly message: "Service Unavailable";
109
- };
110
- readonly GATEWAY_TIMEOUT: {
111
- readonly status: 504;
112
- readonly message: "Gateway Timeout";
113
- };
114
- };
115
- type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
116
- type ORPCErrorCode = CommonORPCErrorCode | (string & {});
117
- declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
118
- declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
119
- type ORPCErrorOptions<TData> = ErrorOptions & {
120
- defined?: boolean;
121
- status?: number;
122
- message?: string;
123
- } & (undefined extends TData ? {
124
- data?: TData;
125
- } : {
126
- data: TData;
127
- });
128
- declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
129
- readonly defined: boolean;
130
- readonly code: TCode;
131
- readonly status: number;
132
- readonly data: TData;
133
- constructor(code: TCode, ...rest: MaybeOptionalOptions$1<ORPCErrorOptions<TData>>);
134
- toJSON(): ORPCErrorJSON<TCode, TData>;
135
- /**
136
- * Workaround for Next.js where different contexts use separate
137
- * dependency graphs, causing multiple ORPCError constructors existing and breaking
138
- * `instanceof` checks across contexts.
139
- *
140
- * This is particularly problematic with "Optimized SSR", where orpc-client
141
- * executes in one context but is invoked from another. When an error is thrown
142
- * in the execution context, `instanceof ORPCError` checks fail in the
143
- * invocation context due to separate class constructors.
144
- *
145
- * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
146
- */
147
- static [Symbol.hasInstance](instance: unknown): boolean;
148
- }
149
- type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
150
- declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
151
- declare function toORPCError(error: unknown): ORPCError<any, any>;
152
- declare function isORPCErrorStatus(status: number): boolean;
153
- declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
154
- declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
155
93
  /**
156
94
  * Error thrown when an operation is aborted.
157
95
  * Uses the standardized 'AbortError' name for consistency with JavaScript APIs.
@@ -219,101 +157,14 @@ declare class EventPublisher<T extends Record<PropertyKey, any>> {
219
157
  subscribe<K extends keyof T>(event: K, options?: EventPublisherSubscribeIteratorOptions): AsyncGenerator<T[K]> & AsyncIteratorObject<T[K]>;
220
158
  }
221
159
 
222
- declare class SequentialIdGenerator {
223
- private index;
224
- generate(): string;
225
- }
226
-
227
- type StandardBody = undefined | unknown | Blob | URLSearchParams | FormData | AsyncIterator<unknown | void, unknown | void, undefined>;
228
- interface StandardRequest {
229
- method: string;
230
- url: URL;
231
- headers: Headers;
232
- /**
233
- * The body has been parsed based on the content-type header.
234
- */
235
- body: StandardBody;
236
- signal: AbortSignal | undefined;
237
- }
238
- interface StandardLazyRequest extends Omit<StandardRequest, 'body'> {
239
- /**
240
- * The body has been parsed based on the content-type header.
241
- * This method can safely call multiple times (cached).
242
- */
243
- body: () => Promise<StandardBody>;
244
- }
245
- interface StandardResponse {
246
- status: number;
247
- headers: Headers;
248
- /**
249
- * The body has been parsed based on the content-type header.
250
- */
251
- body: StandardBody;
252
- }
253
- interface StandardLazyResponse extends Omit<StandardResponse, 'body'> {
254
- /**
255
- * The body has been parsed based on the content-type header.
256
- * This method can safely call multiple times (cached).
257
- */
258
- body: () => Promise<StandardBody>;
259
- }
260
- type HTTPPath = `/${string}`;
261
- declare const HTTPMethods: readonly ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"];
262
- type HTTPMethod = (typeof HTTPMethods)[number];
263
- type HTTPEndpoint = `${HTTPMethod} ${HTTPPath}`;
264
- type ClientContext = Record<PropertyKey, any>;
265
- interface ClientOptions<T extends ClientContext> {
266
- request?: StandardLazyRequest;
267
- signal?: AbortSignal;
268
- lastEventId?: string | undefined;
269
- context: T;
270
- }
271
- type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
272
- context?: T;
273
- } : {
274
- context: T;
275
- });
276
- type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [
277
- input?: TInput,
278
- options?: FriendlyClientOptions<TClientContext>
279
- ] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
280
- type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
281
- interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
282
- (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
283
- }
284
- type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
285
- [k: string]: NestedClient<TClientContext>;
286
- };
287
- type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
288
- interface ClientLink<TClientContext extends ClientContext> {
289
- call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
290
- }
291
- type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
292
- type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
293
- type PromiseWithError<T, TError> = Promise<T> & {
294
- __error?: {
295
- type: TError;
296
- };
297
- };
160
+ type AnyFunction = (...args: any[]) => any;
161
+ declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
162
+ declare function sequential<A extends any[], R>(fn: (...args: A) => Promise<R>): (...args: A) => Promise<R>;
298
163
  /**
299
- * The place where you can config the orpc types.
300
- *
301
- * - `throwableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
164
+ * Executes the callback function after the current call stack has been cleared.
302
165
  */
303
- interface Registry {
304
- }
305
- type ThrowableError = Registry extends {
306
- throwableError: infer T;
307
- } ? T : Error;
308
- type InferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : never;
309
- type IsEqual<A, B> = (<G>() => G extends (A & G) | G ? 1 : 2) extends <G>() => G extends (B & G) | G ? 1 : 2 ? true : false;
310
- type Promisable<T> = T | PromiseLike<T>;
166
+ declare function defer(callback: () => void): void;
311
167
 
312
- type InterceptableOptions = Record<string, any>;
313
- type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
314
- next(options?: TOptions): TResult;
315
- };
316
- type Interceptor<TOptions extends InterceptableOptions, TResult> = (options: InterceptorOptions<TOptions, TResult>) => TResult;
317
168
  /**
318
169
  * Can used for interceptors or middlewares
319
170
  */
@@ -331,15 +182,14 @@ declare function onSuccess<T, TOptions extends {
331
182
  */
332
183
  declare function onError<T, TOptions extends {
333
184
  next(): any;
334
- }, TRest extends any[]>(callback: NoInfer<(error: ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
185
+ }, TRest extends any[]>(callback: NoInfer<(error: Error, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
335
186
  type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
336
187
  /**
337
188
  * Can used for interceptors or middlewares
338
189
  */
339
190
  declare function onFinish<T, TOptions extends {
340
191
  next(): any;
341
- }, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>, ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
342
- declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
192
+ }, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>, Error>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
343
193
 
344
194
  /**
345
195
  * Only import types from @opentelemetry/api to avoid runtime dependencies.
@@ -471,17 +321,7 @@ declare const NullProtoObj: {
471
321
 
472
322
  type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
473
323
  declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
474
- /**
475
- * Returns the value if it is defined, otherwise returns the fallback
476
- */
477
- declare function fallback<T>(value: T | undefined, fallback: T): T;
478
324
 
479
- /**
480
- * Prevents objects from being awaitable by intercepting the `then` method
481
- * when called by the native await mechanism. This is useful for preventing
482
- * accidental awaiting of objects that aren't meant to be promises.
483
- */
484
- declare function preventNativeAwait<T extends object>(target: T): T;
485
325
  /**
486
326
  * Create a proxy that overlays one object (`overlay`) on top of another (`target`).
487
327
  *
@@ -517,32 +357,9 @@ declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableS
517
357
 
518
358
  declare function tryDecodeURIComponent(value: string): string;
519
359
 
520
- type SafeResult<TOutput, TError> = ([error: null, data: TOutput, isDefined: false, isSuccess: true] & {
521
- error: null;
522
- data: TOutput;
523
- isDefined: false;
524
- isSuccess: true;
525
- }) | ([error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, isSuccess: false] & {
526
- error: Exclude<TError, ORPCError<any, any>>;
527
- data: undefined;
528
- isDefined: false;
529
- isSuccess: false;
530
- }) | ([error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, isSuccess: false] & {
531
- error: Extract<TError, ORPCError<any, any>>;
532
- data: undefined;
533
- isDefined: true;
534
- isSuccess: false;
535
- });
536
- /**
537
- * Works like try/catch, but can infer error types.
538
- *
539
- * @info support both tuple `[error, data, isDefined, isSuccess]` and object `{ error, data, isDefined, isSuccess }` styles.
540
- * @see {@link https://orpc.unnoq.com/docs/client/error-handling Client Error Handling Docs}
541
- */
542
- declare function safe<TOutput, TError = ThrowableError$1>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
543
360
  declare function toHttpPath(path: readonly string[]): HTTPPath;
544
361
  declare function splitFirst(str: string, separator: string): [string, string];
545
- declare function assertNever(value: never): never;
362
+ declare function assertNever(value: never, message?: string): never;
546
363
 
547
- export { AbortError, AsyncIdQueue, AsyncIteratorClass, COMMON_ORPC_ERROR_DEFS, EventPublisher, HTTPMethods, NullProtoObj, ORPCError, ORPC_CLIENT_PACKAGE_NAME, ORPC_CLIENT_PACKAGE_VERSION, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, assertNever, asyncIteratorToStream, asyncIteratorWithSpan, clone, createORPCErrorFromJson, defer, fallback, fallbackORPCErrorMessage, fallbackORPCErrorStatus, findDeepMatches, get, getConstructor, getGlobalOtelConfig, intercept, isAsyncIteratorObject, isDefinedError, isORPCErrorJson, isORPCErrorStatus, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, overlayProxy, parseEmptyableJSON, preventNativeAwait, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, safe, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitFirst, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toHttpPath, toORPCError, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
548
- export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, AsyncIteratorWithSpanOptions, Client, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, ClientRest, CommonORPCErrorCode, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, FriendlyClientOptions, HTTPEndpoint, HTTPMethod, HTTPPath, InferAsyncIterableYield, InferClientContext, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, IsEqual, MaybeOptionalOptions, NestedClient, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, OmitChainMethodDeep, OnFinishState, OptionalIfEmpty, OtelConfig, Promisable, PromiseWithError, Registry, RunWithSpanOptions, SafeResult, Segment, SetOptional, SetSpanErrorOptions, StandardBody, StandardLazyRequest, StandardLazyResponse, StandardRequest, StandardResponse, ThrowableError, Value };
364
+ export { AbortError, AsyncIdQueue, AsyncIteratorClass, EventPublisher, HTTPMethods, NullProtoObj, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, assertNever, asyncIteratorToStream, asyncIteratorWithSpan, clone, defer, fallbackContractConfig, findDeepMatches, get, getConstructor, getGlobalOtelConfig, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, overlayProxy, parseEmptyableJSON, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitFirst, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toHttpPath, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
365
+ export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, AsyncIteratorWithSpanOptions, Client, ClientContext, ClientLink, ClientOptions, ClientRest, ContractConfig, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, FriendlyClientOptions, HTTPEndpoint, HTTPMethod, HTTPPath, InferAsyncIterableYield, InferClientContext, IntersectPick, IsEqual, MaybeOptionalOptions, NestedClient, OnFinishState, OptionalIfEmpty, OtelConfig, OutputStructure, Promisable, RunWithSpanOptions, Segment, SetOptional, SetSpanErrorOptions, StandardBody, StandardLazyRequest, StandardLazyResponse, StandardRequest, StandardResponse, Value };
package/dist/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
- import { resolveMaybeOptionalOptions as resolveMaybeOptionalOptions$1, getConstructor as getConstructor$1, isObject as isObject$1 } from '@temporary-name/shared';
2
1
  export { group, guard, mapEntries, mapValues, omit, retry, sleep } from 'radash';
3
2
 
4
3
  function resolveMaybeOptionalOptions(rest) {
@@ -8,190 +7,24 @@ function resolveMaybeOptionalOptions(rest) {
8
7
  function toArray(value) {
9
8
  return Array.isArray(value) ? value : value === void 0 || value === null ? [] : [value];
10
9
  }
11
- function splitInHalf(arr) {
12
- const half = Math.ceil(arr.length / 2);
13
- return [arr.slice(0, half), arr.slice(half)];
14
- }
15
10
 
16
- function readAsBuffer(source) {
17
- if (typeof source.bytes === "function") {
18
- return source.bytes();
11
+ const DEFAULT_CONFIG = {
12
+ defaultMethod: "POST",
13
+ defaultSuccessStatus: 200,
14
+ defaultSuccessDescription: "OK",
15
+ defaultOutputStructure: "compact"
16
+ };
17
+ function fallbackContractConfig(key, value) {
18
+ if (value === void 0) {
19
+ return DEFAULT_CONFIG[key];
19
20
  }
20
- return source.arrayBuffer();
21
+ return value;
21
22
  }
22
23
 
23
24
  const ORPC_NAME = "orpc";
24
25
  const ORPC_SHARED_PACKAGE_NAME = "@temporary-name/shared";
25
- const ORPC_SHARED_PACKAGE_VERSION = "1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05";
26
+ const ORPC_SHARED_PACKAGE_VERSION = "1.9.3-alpha.62d88f5cf3908d4411b5278f1824b69334da8072";
26
27
 
27
- const ORPC_CLIENT_PACKAGE_NAME = "__ORPC_CLIENT_PACKAGE_NAME_PLACEHOLDER__";
28
- const ORPC_CLIENT_PACKAGE_VERSION = "__ORPC_CLIENT_PACKAGE_VERSION_PLACEHOLDER__";
29
- const COMMON_ORPC_ERROR_DEFS = {
30
- BAD_REQUEST: {
31
- status: 400,
32
- message: "Bad Request"
33
- },
34
- UNAUTHORIZED: {
35
- status: 401,
36
- message: "Unauthorized"
37
- },
38
- FORBIDDEN: {
39
- status: 403,
40
- message: "Forbidden"
41
- },
42
- NOT_FOUND: {
43
- status: 404,
44
- message: "Not Found"
45
- },
46
- METHOD_NOT_SUPPORTED: {
47
- status: 405,
48
- message: "Method Not Supported"
49
- },
50
- NOT_ACCEPTABLE: {
51
- status: 406,
52
- message: "Not Acceptable"
53
- },
54
- TIMEOUT: {
55
- status: 408,
56
- message: "Request Timeout"
57
- },
58
- CONFLICT: {
59
- status: 409,
60
- message: "Conflict"
61
- },
62
- PRECONDITION_FAILED: {
63
- status: 412,
64
- message: "Precondition Failed"
65
- },
66
- PAYLOAD_TOO_LARGE: {
67
- status: 413,
68
- message: "Payload Too Large"
69
- },
70
- UNSUPPORTED_MEDIA_TYPE: {
71
- status: 415,
72
- message: "Unsupported Media Type"
73
- },
74
- UNPROCESSABLE_CONTENT: {
75
- status: 422,
76
- message: "Unprocessable Content"
77
- },
78
- TOO_MANY_REQUESTS: {
79
- status: 429,
80
- message: "Too Many Requests"
81
- },
82
- CLIENT_CLOSED_REQUEST: {
83
- status: 499,
84
- message: "Client Closed Request"
85
- },
86
- INTERNAL_SERVER_ERROR: {
87
- status: 500,
88
- message: "Internal Server Error"
89
- },
90
- NOT_IMPLEMENTED: {
91
- status: 501,
92
- message: "Not Implemented"
93
- },
94
- BAD_GATEWAY: {
95
- status: 502,
96
- message: "Bad Gateway"
97
- },
98
- SERVICE_UNAVAILABLE: {
99
- status: 503,
100
- message: "Service Unavailable"
101
- },
102
- GATEWAY_TIMEOUT: {
103
- status: 504,
104
- message: "Gateway Timeout"
105
- }
106
- };
107
- function fallbackORPCErrorStatus(code, status) {
108
- return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
109
- }
110
- function fallbackORPCErrorMessage(code, message) {
111
- return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
112
- }
113
- const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(
114
- `__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`
115
- );
116
- void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet());
117
- const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL];
118
- class ORPCError extends Error {
119
- defined;
120
- code;
121
- status;
122
- data;
123
- constructor(code, ...rest) {
124
- const options = resolveMaybeOptionalOptions$1(rest);
125
- if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
126
- throw new Error("[ORPCError] Invalid error status code.");
127
- }
128
- const message = fallbackORPCErrorMessage(code, options.message);
129
- super(message, options);
130
- this.code = code;
131
- this.status = fallbackORPCErrorStatus(code, options.status);
132
- this.defined = options.defined ?? false;
133
- this.data = options.data;
134
- }
135
- toJSON() {
136
- return {
137
- defined: this.defined,
138
- code: this.code,
139
- status: this.status,
140
- message: this.message,
141
- data: this.data
142
- };
143
- }
144
- /**
145
- * Workaround for Next.js where different contexts use separate
146
- * dependency graphs, causing multiple ORPCError constructors existing and breaking
147
- * `instanceof` checks across contexts.
148
- *
149
- * This is particularly problematic with "Optimized SSR", where orpc-client
150
- * executes in one context but is invoked from another. When an error is thrown
151
- * in the execution context, `instanceof ORPCError` checks fail in the
152
- * invocation context due to separate class constructors.
153
- *
154
- * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
155
- */
156
- static [Symbol.hasInstance](instance) {
157
- if (globalORPCErrorConstructors.has(this)) {
158
- const constructor = getConstructor$1(instance);
159
- if (constructor && globalORPCErrorConstructors.has(constructor)) {
160
- return true;
161
- }
162
- }
163
- return super[Symbol.hasInstance](instance);
164
- }
165
- }
166
- globalORPCErrorConstructors.add(ORPCError);
167
- function isDefinedError(error) {
168
- return error instanceof ORPCError && error.defined;
169
- }
170
- function toORPCError(error) {
171
- return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
172
- message: "Internal server error",
173
- cause: error
174
- });
175
- }
176
- function isORPCErrorStatus(status) {
177
- return status < 200 || status >= 400;
178
- }
179
- function isORPCErrorJson(json) {
180
- if (!isObject$1(json)) {
181
- return false;
182
- }
183
- const validKeys = ["defined", "code", "status", "message", "data"];
184
- if (Object.keys(json).some((k) => !validKeys.includes(k))) {
185
- return false;
186
- }
187
- 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";
188
- }
189
- function createORPCErrorFromJson(json, options = {}) {
190
- return new ORPCError(json.code, {
191
- ...options,
192
- ...json
193
- });
194
- }
195
28
  class AbortError extends Error {
196
29
  constructor(...rest) {
197
30
  super(...rest);
@@ -628,15 +461,6 @@ class EventPublisher {
628
461
  }
629
462
  }
630
463
 
631
- class SequentialIdGenerator {
632
- index = BigInt(0);
633
- generate() {
634
- const id = this.index.toString(32);
635
- this.index++;
636
- return id;
637
- }
638
- }
639
-
640
464
  function onStart(callback) {
641
465
  return async (options, ...rest) => {
642
466
  await callback(options, ...rest);
@@ -675,19 +499,6 @@ function onFinish(callback) {
675
499
  }
676
500
  };
677
501
  }
678
- function intercept(interceptors, options, main) {
679
- const next = (options2, index) => {
680
- const interceptor = interceptors[index];
681
- if (!interceptor) {
682
- return main(options2);
683
- }
684
- return interceptor({
685
- ...options2,
686
- next: (newOptions = options2) => next(newOptions, index + 1)
687
- });
688
- };
689
- return next(options, 0);
690
- }
691
502
 
692
503
  function parseEmptyableJSON(text) {
693
504
  if (!text) {
@@ -771,46 +582,7 @@ function value(value2, ...args) {
771
582
  }
772
583
  return value2;
773
584
  }
774
- function fallback(value2, fallback2) {
775
- return value2 === void 0 ? fallback2 : value2;
776
- }
777
585
 
778
- function preventNativeAwait(target) {
779
- return new Proxy(target, {
780
- get(target2, prop, receiver) {
781
- const value2 = Reflect.get(target2, prop, receiver);
782
- if (prop !== "then" || typeof value2 !== "function") {
783
- return value2;
784
- }
785
- return new Proxy(value2, {
786
- apply(targetFn, thisArg, args) {
787
- if (args.length !== 2 || args.some((arg) => !isNativeFunction(arg))) {
788
- return Reflect.apply(targetFn, thisArg, args);
789
- }
790
- let shouldOmit = true;
791
- args[0].call(
792
- thisArg,
793
- preventNativeAwait(
794
- new Proxy(target2, {
795
- get: (target3, prop2, receiver2) => {
796
- if (shouldOmit && prop2 === "then") {
797
- shouldOmit = false;
798
- return void 0;
799
- }
800
- return Reflect.get(target3, prop2, receiver2);
801
- }
802
- })
803
- )
804
- );
805
- }
806
- });
807
- }
808
- });
809
- }
810
- const NATIVE_FUNCTION_REGEX = /^\s*function\s*\(\)\s*\{\s*\[native code\]\s*\}\s*$/;
811
- function isNativeFunction(fn) {
812
- return typeof fn === "function" && NATIVE_FUNCTION_REGEX.test(fn.toString());
813
- }
814
586
  function overlayProxy(target, partial) {
815
587
  const proxy = new Proxy(typeof target === "function" ? partial : target, {
816
588
  get(_, prop) {
@@ -862,36 +634,6 @@ function tryDecodeURIComponent(value) {
862
634
  }
863
635
  }
864
636
 
865
- async function safe(promise) {
866
- try {
867
- const output = await promise;
868
- return Object.assign([null, output, false, true], {
869
- error: null,
870
- data: output,
871
- isDefined: false,
872
- isSuccess: true
873
- });
874
- } catch (e) {
875
- const error = e;
876
- if (isDefinedError(error)) {
877
- return Object.assign([error, void 0, true, false], {
878
- error,
879
- data: void 0,
880
- isDefined: true,
881
- isSuccess: false
882
- });
883
- }
884
- return Object.assign(
885
- [error, void 0, false, false],
886
- {
887
- error,
888
- data: void 0,
889
- isDefined: false,
890
- isSuccess: false
891
- }
892
- );
893
- }
894
- }
895
637
  function toHttpPath(path) {
896
638
  return `/${path.map(encodeURIComponent).join("/")}`;
897
639
  }
@@ -902,8 +644,8 @@ function splitFirst(str, separator) {
902
644
  }
903
645
  return [str.slice(0, index), str.slice(index + separator.length)];
904
646
  }
905
- function assertNever(value) {
906
- throw new Error(`Unexpected value: ${value}`);
647
+ function assertNever(value, message) {
648
+ throw new Error(message ?? `Unexpected value: ${value}`);
907
649
  }
908
650
 
909
- export { AbortError, AsyncIdQueue, AsyncIteratorClass, COMMON_ORPC_ERROR_DEFS, EventPublisher, HTTPMethods, NullProtoObj, ORPCError, ORPC_CLIENT_PACKAGE_NAME, ORPC_CLIENT_PACKAGE_VERSION, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, assertNever, asyncIteratorToStream, asyncIteratorWithSpan, clone, createORPCErrorFromJson, defer, fallback, fallbackORPCErrorMessage, fallbackORPCErrorStatus, findDeepMatches, get, getConstructor, getGlobalOtelConfig, intercept, isAsyncIteratorObject, isDefinedError, isORPCErrorJson, isORPCErrorStatus, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, overlayProxy, parseEmptyableJSON, preventNativeAwait, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, safe, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitFirst, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toHttpPath, toORPCError, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
651
+ export { AbortError, AsyncIdQueue, AsyncIteratorClass, EventPublisher, HTTPMethods, NullProtoObj, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, assertNever, asyncIteratorToStream, asyncIteratorWithSpan, clone, defer, fallbackContractConfig, findDeepMatches, get, getConstructor, getGlobalOtelConfig, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, overlayProxy, parseEmptyableJSON, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitFirst, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toHttpPath, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@temporary-name/shared",
3
3
  "type": "module",
4
- "version": "1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05",
4
+ "version": "1.9.3-alpha.62d88f5cf3908d4411b5278f1824b69334da8072",
5
5
  "license": "MIT",
6
6
  "homepage": "https://www.stainless.com/",
7
7
  "repository": {
@@ -32,6 +32,7 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
+ "openapi-types": "^12.1.3",
35
36
  "radash": "^12.1.1"
36
37
  },
37
38
  "devDependencies": {
@@ -41,6 +42,7 @@
41
42
  "scripts": {
42
43
  "build": "unbuild",
43
44
  "build:watch": "pnpm run build --watch",
44
- "type:check": "tsc -b"
45
+ "clean": "tsc -b --clean",
46
+ "lint:tsc": "tsc -b"
45
47
  }
46
48
  }