@temporary-name/shared 1.9.3-alpha.8dcf0da5d97e7b89ab5ce50c8d1733c158e629a8 → 1.9.3-alpha.907c7c78d0193d34752279de92d699e50d6bc3a1
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 +88 -80
- package/dist/index.d.ts +88 -80
- package/dist/index.mjs +25 -32
- package/package.json +3 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { MaybeOptionalOptions as MaybeOptionalOptions$1
|
|
1
|
+
import { MaybeOptionalOptions as MaybeOptionalOptions$1 } from '@temporary-name/shared';
|
|
2
2
|
import { Tracer, TraceAPI, ContextAPI, PropagationAPI, SpanOptions, Context, Span, AttributeValue, Exception } from '@opentelemetry/api';
|
|
3
3
|
export { group, guard, mapEntries, mapValues, omit, retry, sleep } from 'radash';
|
|
4
|
+
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
4
5
|
|
|
5
6
|
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
7
|
+
type OptionalIfEmpty<TOptions> = {} extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
6
8
|
declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
|
7
9
|
|
|
8
10
|
declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
|
|
@@ -27,9 +29,87 @@ type OmitChainMethodDeep<T extends object, K extends keyof any> = {
|
|
|
27
29
|
[P in keyof Omit<T, K>]: T[P] extends AnyFunction ? (...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K> : T[P];
|
|
28
30
|
};
|
|
29
31
|
|
|
32
|
+
type StandardBody = undefined | unknown | Blob | URLSearchParams | FormData | AsyncIterator<unknown | void, unknown | void, undefined>;
|
|
33
|
+
interface StandardRequest {
|
|
34
|
+
method: string;
|
|
35
|
+
url: URL;
|
|
36
|
+
headers: Headers;
|
|
37
|
+
/**
|
|
38
|
+
* The body has been parsed based on the content-type header.
|
|
39
|
+
*/
|
|
40
|
+
body: StandardBody;
|
|
41
|
+
signal: AbortSignal | undefined;
|
|
42
|
+
}
|
|
43
|
+
interface StandardLazyRequest extends Omit<StandardRequest, 'body'> {
|
|
44
|
+
/**
|
|
45
|
+
* The body has been parsed based on the content-type header.
|
|
46
|
+
* This method can safely call multiple times (cached).
|
|
47
|
+
*/
|
|
48
|
+
body: () => Promise<StandardBody>;
|
|
49
|
+
}
|
|
50
|
+
interface StandardResponse {
|
|
51
|
+
status: number;
|
|
52
|
+
headers: Headers;
|
|
53
|
+
/**
|
|
54
|
+
* The body has been parsed based on the content-type header.
|
|
55
|
+
*/
|
|
56
|
+
body: StandardBody;
|
|
57
|
+
}
|
|
58
|
+
interface StandardLazyResponse extends Omit<StandardResponse, 'body'> {
|
|
59
|
+
/**
|
|
60
|
+
* The body has been parsed based on the content-type header.
|
|
61
|
+
* This method can safely call multiple times (cached).
|
|
62
|
+
*/
|
|
63
|
+
body: () => Promise<StandardBody>;
|
|
64
|
+
}
|
|
65
|
+
type HTTPPath = `/${string}`;
|
|
66
|
+
declare const HTTPMethods: readonly ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"];
|
|
67
|
+
type HTTPMethod = (typeof HTTPMethods)[number];
|
|
68
|
+
type HTTPEndpoint = `${HTTPMethod} ${HTTPPath}`;
|
|
69
|
+
type ClientContext = Record<PropertyKey, any>;
|
|
70
|
+
interface ClientOptions<T extends ClientContext> {
|
|
71
|
+
request?: StandardLazyRequest;
|
|
72
|
+
signal?: AbortSignal;
|
|
73
|
+
lastEventId?: string | undefined;
|
|
74
|
+
context: T;
|
|
75
|
+
}
|
|
76
|
+
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
77
|
+
context?: T;
|
|
78
|
+
} : {
|
|
79
|
+
context: T;
|
|
80
|
+
});
|
|
81
|
+
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [
|
|
82
|
+
input?: TInput,
|
|
83
|
+
options?: FriendlyClientOptions<TClientContext>
|
|
84
|
+
] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
85
|
+
interface Client<TClientContext extends ClientContext, TInput, TOutput> {
|
|
86
|
+
(...rest: ClientRest<TClientContext, TInput>): Promise<TOutput>;
|
|
87
|
+
}
|
|
88
|
+
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any> | {
|
|
89
|
+
[k: string]: NestedClient<TClientContext>;
|
|
90
|
+
};
|
|
91
|
+
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
92
|
+
interface ClientLink<TClientContext extends ClientContext> {
|
|
93
|
+
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
94
|
+
}
|
|
95
|
+
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
96
|
+
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
97
|
+
type InferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : never;
|
|
98
|
+
type IsEqual<A, B> = (<G>() => G extends (A & G) | G ? 1 : 2) extends <G>() => G extends (B & G) | G ? 1 : 2 ? true : false;
|
|
99
|
+
type Promisable<T> = T | PromiseLike<T>;
|
|
100
|
+
|
|
101
|
+
type OutputStructure = 'compact' | 'detailed';
|
|
102
|
+
interface ContractConfig {
|
|
103
|
+
defaultMethod: HTTPMethod;
|
|
104
|
+
defaultSuccessStatus: number;
|
|
105
|
+
defaultSuccessDescription: string;
|
|
106
|
+
defaultOutputStructure: OutputStructure;
|
|
107
|
+
}
|
|
108
|
+
declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
|
|
109
|
+
|
|
30
110
|
declare const ORPC_NAME = "orpc";
|
|
31
111
|
declare const ORPC_SHARED_PACKAGE_NAME = "@temporary-name/shared";
|
|
32
|
-
declare const ORPC_SHARED_PACKAGE_VERSION = "1.9.3-alpha.
|
|
112
|
+
declare const ORPC_SHARED_PACKAGE_VERSION = "1.9.3-alpha.907c7c78d0193d34752279de92d699e50d6bc3a1";
|
|
33
113
|
|
|
34
114
|
declare const ORPC_CLIENT_PACKAGE_NAME = "__ORPC_CLIENT_PACKAGE_NAME_PLACEHOLDER__";
|
|
35
115
|
declare const ORPC_CLIENT_PACKAGE_VERSION = "__ORPC_CLIENT_PACKAGE_VERSION_PLACEHOLDER__";
|
|
@@ -223,57 +303,6 @@ declare class SequentialIdGenerator {
|
|
|
223
303
|
generate(): string;
|
|
224
304
|
}
|
|
225
305
|
|
|
226
|
-
type HTTPPath = `/${string}`;
|
|
227
|
-
declare const HTTPMethods: readonly ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"];
|
|
228
|
-
type HTTPMethod = (typeof HTTPMethods)[number];
|
|
229
|
-
type HTTPEndpoint = `${HTTPMethod} ${HTTPPath}`;
|
|
230
|
-
type ClientContext = Record<PropertyKey, any>;
|
|
231
|
-
interface ClientOptions<T extends ClientContext> {
|
|
232
|
-
signal?: AbortSignal;
|
|
233
|
-
lastEventId?: string | undefined;
|
|
234
|
-
context: T;
|
|
235
|
-
}
|
|
236
|
-
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
237
|
-
context?: T;
|
|
238
|
-
} : {
|
|
239
|
-
context: T;
|
|
240
|
-
});
|
|
241
|
-
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [
|
|
242
|
-
input?: TInput,
|
|
243
|
-
options?: FriendlyClientOptions<TClientContext>
|
|
244
|
-
] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
245
|
-
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
|
246
|
-
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
247
|
-
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
248
|
-
}
|
|
249
|
-
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
250
|
-
[k: string]: NestedClient<TClientContext>;
|
|
251
|
-
};
|
|
252
|
-
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
253
|
-
interface ClientLink<TClientContext extends ClientContext> {
|
|
254
|
-
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
255
|
-
}
|
|
256
|
-
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
257
|
-
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
258
|
-
type PromiseWithError<T, TError> = Promise<T> & {
|
|
259
|
-
__error?: {
|
|
260
|
-
type: TError;
|
|
261
|
-
};
|
|
262
|
-
};
|
|
263
|
-
/**
|
|
264
|
-
* The place where you can config the orpc types.
|
|
265
|
-
*
|
|
266
|
-
* - `throwableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
|
|
267
|
-
*/
|
|
268
|
-
interface Registry {
|
|
269
|
-
}
|
|
270
|
-
type ThrowableError = Registry extends {
|
|
271
|
-
throwableError: infer T;
|
|
272
|
-
} ? T : Error;
|
|
273
|
-
type InferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : never;
|
|
274
|
-
type IsEqual<A, B> = (<G>() => G extends (A & G) | G ? 1 : 2) extends <G>() => G extends (B & G) | G ? 1 : 2 ? true : false;
|
|
275
|
-
type Promisable<T> = T | PromiseLike<T>;
|
|
276
|
-
|
|
277
306
|
type InterceptableOptions = Record<string, any>;
|
|
278
307
|
type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
279
308
|
next(options?: TOptions): TResult;
|
|
@@ -296,14 +325,14 @@ declare function onSuccess<T, TOptions extends {
|
|
|
296
325
|
*/
|
|
297
326
|
declare function onError<T, TOptions extends {
|
|
298
327
|
next(): any;
|
|
299
|
-
}, TRest extends any[]>(callback: NoInfer<(error:
|
|
328
|
+
}, TRest extends any[]>(callback: NoInfer<(error: Error, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
300
329
|
type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
|
|
301
330
|
/**
|
|
302
331
|
* Can used for interceptors or middlewares
|
|
303
332
|
*/
|
|
304
333
|
declare function onFinish<T, TOptions extends {
|
|
305
334
|
next(): any;
|
|
306
|
-
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>,
|
|
335
|
+
}, 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']>>>;
|
|
307
336
|
declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
|
|
308
337
|
|
|
309
338
|
/**
|
|
@@ -482,30 +511,9 @@ declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableS
|
|
|
482
511
|
|
|
483
512
|
declare function tryDecodeURIComponent(value: string): string;
|
|
484
513
|
|
|
485
|
-
type SafeResult<TOutput, TError> = ([error: null, data: TOutput, isDefined: false, isSuccess: true] & {
|
|
486
|
-
error: null;
|
|
487
|
-
data: TOutput;
|
|
488
|
-
isDefined: false;
|
|
489
|
-
isSuccess: true;
|
|
490
|
-
}) | ([error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, isSuccess: false] & {
|
|
491
|
-
error: Exclude<TError, ORPCError<any, any>>;
|
|
492
|
-
data: undefined;
|
|
493
|
-
isDefined: false;
|
|
494
|
-
isSuccess: false;
|
|
495
|
-
}) | ([error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, isSuccess: false] & {
|
|
496
|
-
error: Extract<TError, ORPCError<any, any>>;
|
|
497
|
-
data: undefined;
|
|
498
|
-
isDefined: true;
|
|
499
|
-
isSuccess: false;
|
|
500
|
-
});
|
|
501
|
-
/**
|
|
502
|
-
* Works like try/catch, but can infer error types.
|
|
503
|
-
*
|
|
504
|
-
* @info support both tuple `[error, data, isDefined, isSuccess]` and object `{ error, data, isDefined, isSuccess }` styles.
|
|
505
|
-
* @see {@link https://orpc.unnoq.com/docs/client/error-handling Client Error Handling Docs}
|
|
506
|
-
*/
|
|
507
|
-
declare function safe<TOutput, TError = ThrowableError$1>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
|
508
514
|
declare function toHttpPath(path: readonly string[]): HTTPPath;
|
|
515
|
+
declare function splitFirst(str: string, separator: string): [string, string];
|
|
516
|
+
declare function assertNever(value: never): never;
|
|
509
517
|
|
|
510
|
-
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, 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,
|
|
511
|
-
export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, AsyncIteratorWithSpanOptions, Client, ClientContext, ClientLink, ClientOptions,
|
|
518
|
+
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, fallbackContractConfig, 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, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitFirst, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toHttpPath, toORPCError, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
|
|
519
|
+
export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, AsyncIteratorWithSpanOptions, Client, ClientContext, ClientLink, ClientOptions, ClientRest, CommonORPCErrorCode, ContractConfig, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, FriendlyClientOptions, HTTPEndpoint, HTTPMethod, HTTPPath, InferAsyncIterableYield, InferClientContext, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, IsEqual, MaybeOptionalOptions, NestedClient, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, OmitChainMethodDeep, OnFinishState, OptionalIfEmpty, OtelConfig, OutputStructure, Promisable, RunWithSpanOptions, Segment, SetOptional, SetSpanErrorOptions, StandardBody, StandardLazyRequest, StandardLazyResponse, StandardRequest, StandardResponse, Value };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { MaybeOptionalOptions as MaybeOptionalOptions$1
|
|
1
|
+
import { MaybeOptionalOptions as MaybeOptionalOptions$1 } from '@temporary-name/shared';
|
|
2
2
|
import { Tracer, TraceAPI, ContextAPI, PropagationAPI, SpanOptions, Context, Span, AttributeValue, Exception } from '@opentelemetry/api';
|
|
3
3
|
export { group, guard, mapEntries, mapValues, omit, retry, sleep } from 'radash';
|
|
4
|
+
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
4
5
|
|
|
5
6
|
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
7
|
+
type OptionalIfEmpty<TOptions> = {} extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
6
8
|
declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
|
7
9
|
|
|
8
10
|
declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
|
|
@@ -27,9 +29,87 @@ type OmitChainMethodDeep<T extends object, K extends keyof any> = {
|
|
|
27
29
|
[P in keyof Omit<T, K>]: T[P] extends AnyFunction ? (...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K> : T[P];
|
|
28
30
|
};
|
|
29
31
|
|
|
32
|
+
type StandardBody = undefined | unknown | Blob | URLSearchParams | FormData | AsyncIterator<unknown | void, unknown | void, undefined>;
|
|
33
|
+
interface StandardRequest {
|
|
34
|
+
method: string;
|
|
35
|
+
url: URL;
|
|
36
|
+
headers: Headers;
|
|
37
|
+
/**
|
|
38
|
+
* The body has been parsed based on the content-type header.
|
|
39
|
+
*/
|
|
40
|
+
body: StandardBody;
|
|
41
|
+
signal: AbortSignal | undefined;
|
|
42
|
+
}
|
|
43
|
+
interface StandardLazyRequest extends Omit<StandardRequest, 'body'> {
|
|
44
|
+
/**
|
|
45
|
+
* The body has been parsed based on the content-type header.
|
|
46
|
+
* This method can safely call multiple times (cached).
|
|
47
|
+
*/
|
|
48
|
+
body: () => Promise<StandardBody>;
|
|
49
|
+
}
|
|
50
|
+
interface StandardResponse {
|
|
51
|
+
status: number;
|
|
52
|
+
headers: Headers;
|
|
53
|
+
/**
|
|
54
|
+
* The body has been parsed based on the content-type header.
|
|
55
|
+
*/
|
|
56
|
+
body: StandardBody;
|
|
57
|
+
}
|
|
58
|
+
interface StandardLazyResponse extends Omit<StandardResponse, 'body'> {
|
|
59
|
+
/**
|
|
60
|
+
* The body has been parsed based on the content-type header.
|
|
61
|
+
* This method can safely call multiple times (cached).
|
|
62
|
+
*/
|
|
63
|
+
body: () => Promise<StandardBody>;
|
|
64
|
+
}
|
|
65
|
+
type HTTPPath = `/${string}`;
|
|
66
|
+
declare const HTTPMethods: readonly ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"];
|
|
67
|
+
type HTTPMethod = (typeof HTTPMethods)[number];
|
|
68
|
+
type HTTPEndpoint = `${HTTPMethod} ${HTTPPath}`;
|
|
69
|
+
type ClientContext = Record<PropertyKey, any>;
|
|
70
|
+
interface ClientOptions<T extends ClientContext> {
|
|
71
|
+
request?: StandardLazyRequest;
|
|
72
|
+
signal?: AbortSignal;
|
|
73
|
+
lastEventId?: string | undefined;
|
|
74
|
+
context: T;
|
|
75
|
+
}
|
|
76
|
+
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
77
|
+
context?: T;
|
|
78
|
+
} : {
|
|
79
|
+
context: T;
|
|
80
|
+
});
|
|
81
|
+
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [
|
|
82
|
+
input?: TInput,
|
|
83
|
+
options?: FriendlyClientOptions<TClientContext>
|
|
84
|
+
] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
85
|
+
interface Client<TClientContext extends ClientContext, TInput, TOutput> {
|
|
86
|
+
(...rest: ClientRest<TClientContext, TInput>): Promise<TOutput>;
|
|
87
|
+
}
|
|
88
|
+
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any> | {
|
|
89
|
+
[k: string]: NestedClient<TClientContext>;
|
|
90
|
+
};
|
|
91
|
+
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
92
|
+
interface ClientLink<TClientContext extends ClientContext> {
|
|
93
|
+
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
94
|
+
}
|
|
95
|
+
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
96
|
+
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
97
|
+
type InferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : never;
|
|
98
|
+
type IsEqual<A, B> = (<G>() => G extends (A & G) | G ? 1 : 2) extends <G>() => G extends (B & G) | G ? 1 : 2 ? true : false;
|
|
99
|
+
type Promisable<T> = T | PromiseLike<T>;
|
|
100
|
+
|
|
101
|
+
type OutputStructure = 'compact' | 'detailed';
|
|
102
|
+
interface ContractConfig {
|
|
103
|
+
defaultMethod: HTTPMethod;
|
|
104
|
+
defaultSuccessStatus: number;
|
|
105
|
+
defaultSuccessDescription: string;
|
|
106
|
+
defaultOutputStructure: OutputStructure;
|
|
107
|
+
}
|
|
108
|
+
declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
|
|
109
|
+
|
|
30
110
|
declare const ORPC_NAME = "orpc";
|
|
31
111
|
declare const ORPC_SHARED_PACKAGE_NAME = "@temporary-name/shared";
|
|
32
|
-
declare const ORPC_SHARED_PACKAGE_VERSION = "1.9.3-alpha.
|
|
112
|
+
declare const ORPC_SHARED_PACKAGE_VERSION = "1.9.3-alpha.907c7c78d0193d34752279de92d699e50d6bc3a1";
|
|
33
113
|
|
|
34
114
|
declare const ORPC_CLIENT_PACKAGE_NAME = "__ORPC_CLIENT_PACKAGE_NAME_PLACEHOLDER__";
|
|
35
115
|
declare const ORPC_CLIENT_PACKAGE_VERSION = "__ORPC_CLIENT_PACKAGE_VERSION_PLACEHOLDER__";
|
|
@@ -223,57 +303,6 @@ declare class SequentialIdGenerator {
|
|
|
223
303
|
generate(): string;
|
|
224
304
|
}
|
|
225
305
|
|
|
226
|
-
type HTTPPath = `/${string}`;
|
|
227
|
-
declare const HTTPMethods: readonly ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"];
|
|
228
|
-
type HTTPMethod = (typeof HTTPMethods)[number];
|
|
229
|
-
type HTTPEndpoint = `${HTTPMethod} ${HTTPPath}`;
|
|
230
|
-
type ClientContext = Record<PropertyKey, any>;
|
|
231
|
-
interface ClientOptions<T extends ClientContext> {
|
|
232
|
-
signal?: AbortSignal;
|
|
233
|
-
lastEventId?: string | undefined;
|
|
234
|
-
context: T;
|
|
235
|
-
}
|
|
236
|
-
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
237
|
-
context?: T;
|
|
238
|
-
} : {
|
|
239
|
-
context: T;
|
|
240
|
-
});
|
|
241
|
-
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [
|
|
242
|
-
input?: TInput,
|
|
243
|
-
options?: FriendlyClientOptions<TClientContext>
|
|
244
|
-
] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
245
|
-
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
|
246
|
-
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
247
|
-
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
248
|
-
}
|
|
249
|
-
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
250
|
-
[k: string]: NestedClient<TClientContext>;
|
|
251
|
-
};
|
|
252
|
-
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
253
|
-
interface ClientLink<TClientContext extends ClientContext> {
|
|
254
|
-
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
255
|
-
}
|
|
256
|
-
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
257
|
-
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
258
|
-
type PromiseWithError<T, TError> = Promise<T> & {
|
|
259
|
-
__error?: {
|
|
260
|
-
type: TError;
|
|
261
|
-
};
|
|
262
|
-
};
|
|
263
|
-
/**
|
|
264
|
-
* The place where you can config the orpc types.
|
|
265
|
-
*
|
|
266
|
-
* - `throwableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
|
|
267
|
-
*/
|
|
268
|
-
interface Registry {
|
|
269
|
-
}
|
|
270
|
-
type ThrowableError = Registry extends {
|
|
271
|
-
throwableError: infer T;
|
|
272
|
-
} ? T : Error;
|
|
273
|
-
type InferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : never;
|
|
274
|
-
type IsEqual<A, B> = (<G>() => G extends (A & G) | G ? 1 : 2) extends <G>() => G extends (B & G) | G ? 1 : 2 ? true : false;
|
|
275
|
-
type Promisable<T> = T | PromiseLike<T>;
|
|
276
|
-
|
|
277
306
|
type InterceptableOptions = Record<string, any>;
|
|
278
307
|
type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
279
308
|
next(options?: TOptions): TResult;
|
|
@@ -296,14 +325,14 @@ declare function onSuccess<T, TOptions extends {
|
|
|
296
325
|
*/
|
|
297
326
|
declare function onError<T, TOptions extends {
|
|
298
327
|
next(): any;
|
|
299
|
-
}, TRest extends any[]>(callback: NoInfer<(error:
|
|
328
|
+
}, TRest extends any[]>(callback: NoInfer<(error: Error, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
300
329
|
type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
|
|
301
330
|
/**
|
|
302
331
|
* Can used for interceptors or middlewares
|
|
303
332
|
*/
|
|
304
333
|
declare function onFinish<T, TOptions extends {
|
|
305
334
|
next(): any;
|
|
306
|
-
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>,
|
|
335
|
+
}, 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']>>>;
|
|
307
336
|
declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
|
|
308
337
|
|
|
309
338
|
/**
|
|
@@ -482,30 +511,9 @@ declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableS
|
|
|
482
511
|
|
|
483
512
|
declare function tryDecodeURIComponent(value: string): string;
|
|
484
513
|
|
|
485
|
-
type SafeResult<TOutput, TError> = ([error: null, data: TOutput, isDefined: false, isSuccess: true] & {
|
|
486
|
-
error: null;
|
|
487
|
-
data: TOutput;
|
|
488
|
-
isDefined: false;
|
|
489
|
-
isSuccess: true;
|
|
490
|
-
}) | ([error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, isSuccess: false] & {
|
|
491
|
-
error: Exclude<TError, ORPCError<any, any>>;
|
|
492
|
-
data: undefined;
|
|
493
|
-
isDefined: false;
|
|
494
|
-
isSuccess: false;
|
|
495
|
-
}) | ([error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, isSuccess: false] & {
|
|
496
|
-
error: Extract<TError, ORPCError<any, any>>;
|
|
497
|
-
data: undefined;
|
|
498
|
-
isDefined: true;
|
|
499
|
-
isSuccess: false;
|
|
500
|
-
});
|
|
501
|
-
/**
|
|
502
|
-
* Works like try/catch, but can infer error types.
|
|
503
|
-
*
|
|
504
|
-
* @info support both tuple `[error, data, isDefined, isSuccess]` and object `{ error, data, isDefined, isSuccess }` styles.
|
|
505
|
-
* @see {@link https://orpc.unnoq.com/docs/client/error-handling Client Error Handling Docs}
|
|
506
|
-
*/
|
|
507
|
-
declare function safe<TOutput, TError = ThrowableError$1>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
|
508
514
|
declare function toHttpPath(path: readonly string[]): HTTPPath;
|
|
515
|
+
declare function splitFirst(str: string, separator: string): [string, string];
|
|
516
|
+
declare function assertNever(value: never): never;
|
|
509
517
|
|
|
510
|
-
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, 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,
|
|
511
|
-
export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, AsyncIteratorWithSpanOptions, Client, ClientContext, ClientLink, ClientOptions,
|
|
518
|
+
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, fallbackContractConfig, 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, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitFirst, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toHttpPath, toORPCError, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
|
|
519
|
+
export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, AsyncIteratorWithSpanOptions, Client, ClientContext, ClientLink, ClientOptions, ClientRest, CommonORPCErrorCode, ContractConfig, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, FriendlyClientOptions, HTTPEndpoint, HTTPMethod, HTTPPath, InferAsyncIterableYield, InferClientContext, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, IsEqual, MaybeOptionalOptions, NestedClient, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, OmitChainMethodDeep, OnFinishState, OptionalIfEmpty, OtelConfig, OutputStructure, Promisable, RunWithSpanOptions, Segment, SetOptional, SetSpanErrorOptions, StandardBody, StandardLazyRequest, StandardLazyResponse, StandardRequest, StandardResponse, Value };
|
package/dist/index.mjs
CHANGED
|
@@ -20,9 +20,22 @@ function readAsBuffer(source) {
|
|
|
20
20
|
return source.arrayBuffer();
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
const DEFAULT_CONFIG = {
|
|
24
|
+
defaultMethod: "POST",
|
|
25
|
+
defaultSuccessStatus: 200,
|
|
26
|
+
defaultSuccessDescription: "OK",
|
|
27
|
+
defaultOutputStructure: "compact"
|
|
28
|
+
};
|
|
29
|
+
function fallbackContractConfig(key, value) {
|
|
30
|
+
if (value === void 0) {
|
|
31
|
+
return DEFAULT_CONFIG[key];
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
|
|
23
36
|
const ORPC_NAME = "orpc";
|
|
24
37
|
const ORPC_SHARED_PACKAGE_NAME = "@temporary-name/shared";
|
|
25
|
-
const ORPC_SHARED_PACKAGE_VERSION = "1.9.3-alpha.
|
|
38
|
+
const ORPC_SHARED_PACKAGE_VERSION = "1.9.3-alpha.907c7c78d0193d34752279de92d699e50d6bc3a1";
|
|
26
39
|
|
|
27
40
|
const ORPC_CLIENT_PACKAGE_NAME = "__ORPC_CLIENT_PACKAGE_NAME_PLACEHOLDER__";
|
|
28
41
|
const ORPC_CLIENT_PACKAGE_VERSION = "__ORPC_CLIENT_PACKAGE_VERSION_PLACEHOLDER__";
|
|
@@ -862,38 +875,18 @@ function tryDecodeURIComponent(value) {
|
|
|
862
875
|
}
|
|
863
876
|
}
|
|
864
877
|
|
|
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
878
|
function toHttpPath(path) {
|
|
896
879
|
return `/${path.map(encodeURIComponent).join("/")}`;
|
|
897
880
|
}
|
|
881
|
+
function splitFirst(str, separator) {
|
|
882
|
+
const index = str.indexOf(separator);
|
|
883
|
+
if (index === -1) {
|
|
884
|
+
return [str, ""];
|
|
885
|
+
}
|
|
886
|
+
return [str.slice(0, index), str.slice(index + separator.length)];
|
|
887
|
+
}
|
|
888
|
+
function assertNever(value) {
|
|
889
|
+
throw new Error(`Unexpected value: ${value}`);
|
|
890
|
+
}
|
|
898
891
|
|
|
899
|
-
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, 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,
|
|
892
|
+
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, fallbackContractConfig, 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, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitFirst, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toHttpPath, toORPCError, 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.
|
|
4
|
+
"version": "1.9.3-alpha.907c7c78d0193d34752279de92d699e50d6bc3a1",
|
|
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",
|
|
45
|
+
"clean": "tsc -b --clean",
|
|
44
46
|
"type:check": "tsc -b"
|
|
45
47
|
}
|
|
46
48
|
}
|