@orpc/shared 0.0.0-next.f17a1a0 → 0.0.0-next.f21e305
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -21
- package/dist/index.d.mts +321 -0
- package/dist/index.d.ts +321 -0
- package/dist/index.mjs +670 -0
- package/package.json +21 -12
- package/dist/index.js +0 -155
- package/dist/src/chain.d.ts +0 -5
- package/dist/src/error.d.ts +0 -2
- package/dist/src/function.d.ts +0 -2
- package/dist/src/index.d.ts +0 -10
- package/dist/src/interceptor.d.ts +0 -45
- package/dist/src/object.d.ts +0 -12
- package/dist/src/types.d.ts +0 -3
- package/dist/src/value.d.ts +0 -4
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
|
|
2
|
+
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<h1></h1>
|
|
@@ -21,28 +21,24 @@
|
|
|
21
21
|
|
|
22
22
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
23
|
|
|
24
|
-
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
24
|
+
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
|
28
28
|
## Highlights
|
|
29
29
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
- **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
|
|
43
|
-
- **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
|
|
44
|
-
- **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
|
|
45
|
-
- **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
|
|
30
|
+
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
|
+
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
|
+
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
34
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
35
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
36
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
37
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
38
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
|
39
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
40
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
41
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
46
42
|
|
|
47
43
|
## Documentation
|
|
48
44
|
|
|
@@ -53,16 +49,30 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
53
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
56
|
-
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
57
|
-
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
58
|
-
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
59
52
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
53
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
|
54
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
55
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
56
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
57
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
58
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
59
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
60
60
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
61
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
62
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
61
63
|
|
|
62
64
|
## `@orpc/shared`
|
|
63
65
|
|
|
64
66
|
Provides shared utilities for oRPC packages.
|
|
65
67
|
|
|
68
|
+
## Sponsors
|
|
69
|
+
|
|
70
|
+
<p align="center">
|
|
71
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
|
72
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
|
73
|
+
</a>
|
|
74
|
+
</p>
|
|
75
|
+
|
|
66
76
|
## License
|
|
67
77
|
|
|
68
78
|
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { Promisable } from 'type-fest';
|
|
2
|
+
export { IsEqual, IsNever, JsonValue, PartialDeep, Promisable } from 'type-fest';
|
|
3
|
+
import { Tracer, TraceAPI, ContextAPI, PropagationAPI, SpanOptions, Context, Span, AttributeValue, Exception } from '@opentelemetry/api';
|
|
4
|
+
export { group, guard, mapEntries, mapValues, omit } from 'radash';
|
|
5
|
+
|
|
6
|
+
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
7
|
+
declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
|
8
|
+
|
|
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
|
+
|
|
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];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
declare const ORPC_NAME = "orpc";
|
|
32
|
+
declare const ORPC_SHARED_PACKAGE_NAME = "@orpc/shared";
|
|
33
|
+
declare const ORPC_SHARED_PACKAGE_VERSION = "0.0.0-next.f21e305";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Error thrown when an operation is aborted.
|
|
37
|
+
* Uses the standardized 'AbortError' name for consistency with JavaScript APIs.
|
|
38
|
+
*/
|
|
39
|
+
declare class AbortError extends Error {
|
|
40
|
+
constructor(...rest: ConstructorParameters<typeof Error>);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface EventPublisherOptions {
|
|
44
|
+
/**
|
|
45
|
+
* Maximum number of events to buffer for async iterator subscribers.
|
|
46
|
+
*
|
|
47
|
+
* If the buffer exceeds this limit, the oldest event is dropped.
|
|
48
|
+
* This prevents unbounded memory growth if consumers process events slowly.
|
|
49
|
+
*
|
|
50
|
+
* Set to:
|
|
51
|
+
* - `0`: Disable buffering. Events must be consumed before the next one arrives.
|
|
52
|
+
* - `1`: Only keep the latest event. Useful for real-time updates where only the most recent value matters.
|
|
53
|
+
* - `Infinity`: Keep all events. Ensures no data loss, but may lead to high memory usage.
|
|
54
|
+
*
|
|
55
|
+
* @default 100
|
|
56
|
+
*/
|
|
57
|
+
maxBufferedEvents?: number;
|
|
58
|
+
}
|
|
59
|
+
interface EventPublisherSubscribeIteratorOptions extends EventPublisherOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Aborts the async iterator. Throws if aborted before or during pulling.
|
|
62
|
+
*/
|
|
63
|
+
signal?: AbortSignal | undefined;
|
|
64
|
+
}
|
|
65
|
+
declare class EventPublisher<T extends Record<PropertyKey, any>> {
|
|
66
|
+
#private;
|
|
67
|
+
constructor(options?: EventPublisherOptions);
|
|
68
|
+
get size(): number;
|
|
69
|
+
/**
|
|
70
|
+
* Emits an event and delivers the payload to all subscribed listeners.
|
|
71
|
+
*/
|
|
72
|
+
publish<K extends keyof T>(event: K, payload: T[K]): void;
|
|
73
|
+
/**
|
|
74
|
+
* Subscribes to a specific event using a callback function.
|
|
75
|
+
* Returns an unsubscribe function to remove the listener.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const unsubscribe = publisher.subscribe('event', (payload) => {
|
|
80
|
+
* console.log(payload)
|
|
81
|
+
* })
|
|
82
|
+
*
|
|
83
|
+
* // Later
|
|
84
|
+
* unsubscribe()
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
subscribe<K extends keyof T>(event: K, listener: (payload: T[K]) => void): () => void;
|
|
88
|
+
/**
|
|
89
|
+
* Subscribes to a specific event using an async iterator.
|
|
90
|
+
* Useful for `for await...of` loops with optional buffering and abort support.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* for await (const payload of publisher.subscribe('event', { signal })) {
|
|
95
|
+
* console.log(payload)
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
subscribe<K extends keyof T>(event: K, options?: EventPublisherSubscribeIteratorOptions): AsyncGenerator<T[K]> & AsyncIteratorObject<T[K]>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
declare class SequentialIdGenerator {
|
|
103
|
+
private index;
|
|
104
|
+
generate(): string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
108
|
+
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
109
|
+
type PromiseWithError<T, TError> = Promise<T> & {
|
|
110
|
+
__error?: {
|
|
111
|
+
type: TError;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* The place where you can config the orpc types.
|
|
116
|
+
*
|
|
117
|
+
* - `throwableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
|
|
118
|
+
*/
|
|
119
|
+
interface Registry {
|
|
120
|
+
}
|
|
121
|
+
type ThrowableError = Registry extends {
|
|
122
|
+
throwableError: infer T;
|
|
123
|
+
} ? T : Error;
|
|
124
|
+
type InferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : never;
|
|
125
|
+
|
|
126
|
+
type InterceptableOptions = Record<string, any>;
|
|
127
|
+
type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
128
|
+
next(options?: TOptions): TResult;
|
|
129
|
+
};
|
|
130
|
+
type Interceptor<TOptions extends InterceptableOptions, TResult> = (options: InterceptorOptions<TOptions, TResult>) => TResult;
|
|
131
|
+
/**
|
|
132
|
+
* Can used for interceptors or middlewares
|
|
133
|
+
*/
|
|
134
|
+
declare function onStart<T, TOptions extends {
|
|
135
|
+
next(): any;
|
|
136
|
+
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
137
|
+
/**
|
|
138
|
+
* Can used for interceptors or middlewares
|
|
139
|
+
*/
|
|
140
|
+
declare function onSuccess<T, TOptions extends {
|
|
141
|
+
next(): any;
|
|
142
|
+
}, TRest extends any[]>(callback: NoInfer<(result: Awaited<ReturnType<TOptions['next']>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
143
|
+
/**
|
|
144
|
+
* Can used for interceptors or middlewares
|
|
145
|
+
*/
|
|
146
|
+
declare function onError<T, TOptions extends {
|
|
147
|
+
next(): any;
|
|
148
|
+
}, 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']>>>;
|
|
149
|
+
type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
|
|
150
|
+
/**
|
|
151
|
+
* Can used for interceptors or middlewares
|
|
152
|
+
*/
|
|
153
|
+
declare function onFinish<T, TOptions extends {
|
|
154
|
+
next(): any;
|
|
155
|
+
}, 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']>>>;
|
|
156
|
+
declare function intercept<TOptions extends InterceptableOptions, TResult>(interceptors: Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>): TResult;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Only import types from @opentelemetry/api to avoid runtime dependencies.
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
interface OtelConfig {
|
|
163
|
+
tracer: Tracer;
|
|
164
|
+
trace: TraceAPI;
|
|
165
|
+
context: ContextAPI;
|
|
166
|
+
propagation: PropagationAPI;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Sets the global OpenTelemetry config.
|
|
170
|
+
* Call this once at app startup. Use `undefined` to disable tracing.
|
|
171
|
+
*/
|
|
172
|
+
declare function setGlobalOtelConfig(config: OtelConfig | undefined): void;
|
|
173
|
+
/**
|
|
174
|
+
* Gets the global OpenTelemetry config.
|
|
175
|
+
* Returns `undefined` if OpenTelemetry is not configured, initialized, or enabled.
|
|
176
|
+
*/
|
|
177
|
+
declare function getGlobalOtelConfig(): OtelConfig | undefined;
|
|
178
|
+
/**
|
|
179
|
+
* Starts a new OpenTelemetry span with the given name and options.
|
|
180
|
+
*
|
|
181
|
+
* @returns The new span, or `undefined` if no tracer is set.
|
|
182
|
+
*/
|
|
183
|
+
declare function startSpan(name: string, options?: SpanOptions, context?: Context): Span | undefined;
|
|
184
|
+
interface SetSpanErrorOptions {
|
|
185
|
+
/**
|
|
186
|
+
* Span error status is not set if error is due to cancellation by the signal.
|
|
187
|
+
*/
|
|
188
|
+
signal?: AbortSignal;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Records and sets the error status on the given span.
|
|
192
|
+
* If the span is `undefined`, it does nothing.
|
|
193
|
+
*/
|
|
194
|
+
declare function setSpanError(span: Span | undefined, error: unknown, options?: SetSpanErrorOptions): void;
|
|
195
|
+
declare function setSpanAttribute(span: Span | undefined, key: string, value: AttributeValue | undefined): void;
|
|
196
|
+
/**
|
|
197
|
+
* Converts an error to an OpenTelemetry Exception.
|
|
198
|
+
*/
|
|
199
|
+
declare function toOtelException(error: unknown): Exclude<Exception, string>;
|
|
200
|
+
/**
|
|
201
|
+
* Converts a value to a string suitable for OpenTelemetry span attributes.
|
|
202
|
+
*/
|
|
203
|
+
declare function toSpanAttributeValue(data: unknown): string;
|
|
204
|
+
interface RunWithSpanOptions extends SpanOptions, SetSpanErrorOptions {
|
|
205
|
+
/**
|
|
206
|
+
* The name of the span to create.
|
|
207
|
+
*/
|
|
208
|
+
name: string;
|
|
209
|
+
/**
|
|
210
|
+
* Context to use for the span.
|
|
211
|
+
*/
|
|
212
|
+
context?: Context;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Runs a function within the context of a new OpenTelemetry span.
|
|
216
|
+
* The span is ended automatically, and errors are recorded to the span.
|
|
217
|
+
*/
|
|
218
|
+
declare function runWithSpan<T>({ name, context, ...options }: RunWithSpanOptions, fn: (span?: Span) => Promisable<T>): Promise<T>;
|
|
219
|
+
/**
|
|
220
|
+
* Runs a function within the context of an existing OpenTelemetry span.
|
|
221
|
+
*/
|
|
222
|
+
declare function runInSpanContext<T>(span: Span | undefined, fn: () => Promisable<T>): Promise<T>;
|
|
223
|
+
|
|
224
|
+
declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
|
|
225
|
+
interface AsyncIteratorClassNextFn<T, TReturn> {
|
|
226
|
+
(): Promise<IteratorResult<T, TReturn>>;
|
|
227
|
+
}
|
|
228
|
+
interface AsyncIteratorClassCleanupFn {
|
|
229
|
+
(reason: 'return' | 'throw' | 'next' | 'dispose'): Promise<void>;
|
|
230
|
+
}
|
|
231
|
+
declare const fallbackAsyncDisposeSymbol: unique symbol;
|
|
232
|
+
declare const asyncDisposeSymbol: typeof Symbol extends {
|
|
233
|
+
asyncDispose: infer T;
|
|
234
|
+
} ? T : typeof fallbackAsyncDisposeSymbol;
|
|
235
|
+
declare class AsyncIteratorClass<T, TReturn = unknown, TNext = unknown> implements AsyncIteratorObject<T, TReturn, TNext>, AsyncGenerator<T, TReturn, TNext> {
|
|
236
|
+
#private;
|
|
237
|
+
constructor(next: AsyncIteratorClassNextFn<T, TReturn>, cleanup: AsyncIteratorClassCleanupFn);
|
|
238
|
+
next(): Promise<IteratorResult<T, TReturn>>;
|
|
239
|
+
return(value?: any): Promise<IteratorResult<T, TReturn>>;
|
|
240
|
+
throw(err: any): Promise<IteratorResult<T, TReturn>>;
|
|
241
|
+
/**
|
|
242
|
+
* asyncDispose symbol only available in esnext, we should fallback to Symbol.for('asyncDispose')
|
|
243
|
+
*/
|
|
244
|
+
[asyncDisposeSymbol](): Promise<void>;
|
|
245
|
+
[Symbol.asyncIterator](): this;
|
|
246
|
+
}
|
|
247
|
+
declare function replicateAsyncIterator<T, TReturn, TNext>(source: AsyncIterator<T, TReturn, TNext>, count: number): (AsyncIteratorClass<T, TReturn, TNext>)[];
|
|
248
|
+
interface AsyncIteratorWithSpanOptions extends SetSpanErrorOptions {
|
|
249
|
+
/**
|
|
250
|
+
* The name of the span to create.
|
|
251
|
+
*/
|
|
252
|
+
name: string;
|
|
253
|
+
}
|
|
254
|
+
declare function asyncIteratorWithSpan<T, TReturn, TNext>({ name, ...options }: AsyncIteratorWithSpanOptions, iterator: AsyncIterator<T, TReturn, TNext>): AsyncIteratorClass<T, TReturn, TNext>;
|
|
255
|
+
|
|
256
|
+
declare function parseEmptyableJSON(text: string | null | undefined): unknown;
|
|
257
|
+
declare function stringifyJSON<T>(value: T | {
|
|
258
|
+
toJSON(): T;
|
|
259
|
+
}): undefined extends T ? undefined | string : string;
|
|
260
|
+
|
|
261
|
+
type Segment = string | number;
|
|
262
|
+
declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
263
|
+
maps: Segment[][];
|
|
264
|
+
values: unknown[];
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Get constructor of the value
|
|
268
|
+
*
|
|
269
|
+
*/
|
|
270
|
+
declare function getConstructor(value: unknown): Function | null | undefined;
|
|
271
|
+
/**
|
|
272
|
+
* Check if the value is an object even it created by `Object.create(null)` or more tricky way.
|
|
273
|
+
*/
|
|
274
|
+
declare function isObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
275
|
+
/**
|
|
276
|
+
* Check if the value satisfy a `object` type in typescript
|
|
277
|
+
*/
|
|
278
|
+
declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
|
|
279
|
+
declare function clone<T>(value: T): T;
|
|
280
|
+
declare function get(object: unknown, path: readonly string[]): unknown;
|
|
281
|
+
declare function isPropertyKey(value: unknown): value is PropertyKey;
|
|
282
|
+
declare const NullProtoObj: ({
|
|
283
|
+
new <T extends Record<PropertyKey, unknown>>(): T;
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Prevents objects from being awaitable by intercepting the `then` method
|
|
288
|
+
* when called by the native await mechanism. This is useful for preventing
|
|
289
|
+
* accidental awaiting of objects that aren't meant to be promises.
|
|
290
|
+
*/
|
|
291
|
+
declare function preventNativeAwait<T extends object>(target: T): T;
|
|
292
|
+
|
|
293
|
+
interface AsyncIdQueueCloseOptions {
|
|
294
|
+
id?: string;
|
|
295
|
+
reason?: unknown;
|
|
296
|
+
}
|
|
297
|
+
declare class AsyncIdQueue<T> {
|
|
298
|
+
private readonly openIds;
|
|
299
|
+
private readonly queues;
|
|
300
|
+
private readonly waiters;
|
|
301
|
+
get length(): number;
|
|
302
|
+
get waiterIds(): string[];
|
|
303
|
+
hasBufferedItems(id: string): boolean;
|
|
304
|
+
open(id: string): void;
|
|
305
|
+
isOpen(id: string): boolean;
|
|
306
|
+
push(id: string, item: T): void;
|
|
307
|
+
pull(id: string): Promise<T>;
|
|
308
|
+
close({ id, reason }?: AsyncIdQueueCloseOptions): void;
|
|
309
|
+
assertOpen(id: string): void;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
declare function streamToAsyncIteratorClass<T>(stream: ReadableStream<T>): AsyncIteratorClass<T>;
|
|
313
|
+
declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
314
|
+
|
|
315
|
+
declare function tryDecodeURIComponent(value: string): string;
|
|
316
|
+
|
|
317
|
+
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
|
|
318
|
+
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
|
319
|
+
|
|
320
|
+
export { AbortError, AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, asyncIteratorToStream, asyncIteratorWithSpan, clone, defer, findDeepMatches, get, getConstructor, getGlobalOtelConfig, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, preventNativeAwait, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
|
|
321
|
+
export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, AsyncIteratorWithSpanOptions, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, InferAsyncIterableYield, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OmitChainMethodDeep, OnFinishState, OtelConfig, PromiseWithError, Registry, RunWithSpanOptions, Segment, SetOptional, SetSpanErrorOptions, ThrowableError, Value };
|