@orpc/shared 0.0.0-next.d53d856 → 0.0.0-next.d53e45e
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 +5 -1
- package/dist/index.d.mts +39 -10
- package/dist/index.d.ts +39 -10
- package/dist/index.mjs +118 -58
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
18
|
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
19
|
</a>
|
|
20
|
+
<a href="https://deepwiki.com/unnoq/orpc">
|
|
21
|
+
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
|
|
22
|
+
</a>
|
|
20
23
|
</div>
|
|
21
24
|
|
|
22
25
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
@@ -31,7 +34,7 @@
|
|
|
31
34
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
35
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
36
|
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
34
|
-
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
|
|
37
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
35
38
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
36
39
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
37
40
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
@@ -54,6 +57,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
54
57
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
55
58
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
56
59
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
60
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
57
61
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
58
62
|
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
59
63
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Promisable } from 'type-fest';
|
|
2
2
|
export { IsEqual, IsNever, JsonValue, PartialDeep, Promisable } from 'type-fest';
|
|
3
3
|
import { Tracer, TraceAPI, ContextAPI, PropagationAPI, SpanOptions, Context, Span, AttributeValue, Exception } from '@opentelemetry/api';
|
|
4
|
-
export { group, guard, mapEntries, mapValues, omit } from 'radash';
|
|
4
|
+
export { group, guard, mapEntries, mapValues, omit, retry, sleep } from 'radash';
|
|
5
5
|
|
|
6
6
|
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
7
7
|
declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
|
@@ -30,7 +30,7 @@ type OmitChainMethodDeep<T extends object, K extends keyof any> = {
|
|
|
30
30
|
|
|
31
31
|
declare const ORPC_NAME = "orpc";
|
|
32
32
|
declare const ORPC_SHARED_PACKAGE_NAME = "@orpc/shared";
|
|
33
|
-
declare const ORPC_SHARED_PACKAGE_VERSION = "0.0.0-next.
|
|
33
|
+
declare const ORPC_SHARED_PACKAGE_VERSION = "0.0.0-next.d53e45e";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Error thrown when an operation is aborted.
|
|
@@ -60,7 +60,7 @@ interface EventPublisherSubscribeIteratorOptions extends EventPublisherOptions {
|
|
|
60
60
|
/**
|
|
61
61
|
* Aborts the async iterator. Throws if aborted before or during pulling.
|
|
62
62
|
*/
|
|
63
|
-
signal?: AbortSignal;
|
|
63
|
+
signal?: AbortSignal | undefined;
|
|
64
64
|
}
|
|
65
65
|
declare class EventPublisher<T extends Record<PropertyKey, any>> {
|
|
66
66
|
#private;
|
|
@@ -121,6 +121,7 @@ interface Registry {
|
|
|
121
121
|
type ThrowableError = Registry extends {
|
|
122
122
|
throwableError: infer T;
|
|
123
123
|
} ? T : Error;
|
|
124
|
+
type InferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : never;
|
|
124
125
|
|
|
125
126
|
type InterceptableOptions = Record<string, any>;
|
|
126
127
|
type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
@@ -262,6 +263,11 @@ declare function findDeepMatches(check: (value: unknown) => boolean, payload: un
|
|
|
262
263
|
maps: Segment[][];
|
|
263
264
|
values: unknown[];
|
|
264
265
|
};
|
|
266
|
+
/**
|
|
267
|
+
* Get constructor of the value
|
|
268
|
+
*
|
|
269
|
+
*/
|
|
270
|
+
declare function getConstructor(value: unknown): Function | null | undefined;
|
|
265
271
|
/**
|
|
266
272
|
* Check if the value is an object even it created by `Object.create(null)` or more tricky way.
|
|
267
273
|
*/
|
|
@@ -277,15 +283,41 @@ declare const NullProtoObj: ({
|
|
|
277
283
|
new <T extends Record<PropertyKey, unknown>>(): T;
|
|
278
284
|
});
|
|
279
285
|
|
|
286
|
+
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
|
|
287
|
+
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
|
288
|
+
/**
|
|
289
|
+
* Returns the value if it is defined, otherwise returns the fallback
|
|
290
|
+
*/
|
|
291
|
+
declare function fallback<T>(value: T | undefined, fallback: T): T;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Prevents objects from being awaitable by intercepting the `then` method
|
|
295
|
+
* when called by the native await mechanism. This is useful for preventing
|
|
296
|
+
* accidental awaiting of objects that aren't meant to be promises.
|
|
297
|
+
*/
|
|
298
|
+
declare function preventNativeAwait<T extends object>(target: T): T;
|
|
299
|
+
/**
|
|
300
|
+
* Create a proxy that overlays one object (`overlay`) on top of another (`target`).
|
|
301
|
+
*
|
|
302
|
+
* - Properties from `overlay` take precedence.
|
|
303
|
+
* - Properties not in `overlay` fall back to `target`.
|
|
304
|
+
* - Methods from either object are bound to `overlay` so `this` is consistent.
|
|
305
|
+
*
|
|
306
|
+
* Useful when you want to override or extend behavior without fully copying/merging objects.
|
|
307
|
+
*/
|
|
308
|
+
declare function overlayProxy<T extends object, U extends object>(target: Value<T>, partial: U): U & Omit<T, keyof U>;
|
|
309
|
+
|
|
280
310
|
interface AsyncIdQueueCloseOptions {
|
|
281
311
|
id?: string;
|
|
282
312
|
reason?: unknown;
|
|
283
313
|
}
|
|
284
314
|
declare class AsyncIdQueue<T> {
|
|
285
315
|
private readonly openIds;
|
|
286
|
-
private readonly
|
|
287
|
-
private readonly
|
|
316
|
+
private readonly queues;
|
|
317
|
+
private readonly waiters;
|
|
288
318
|
get length(): number;
|
|
319
|
+
get waiterIds(): string[];
|
|
320
|
+
hasBufferedItems(id: string): boolean;
|
|
289
321
|
open(id: string): void;
|
|
290
322
|
isOpen(id: string): boolean;
|
|
291
323
|
push(id: string, item: T): void;
|
|
@@ -299,8 +331,5 @@ declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableS
|
|
|
299
331
|
|
|
300
332
|
declare function tryDecodeURIComponent(value: string): string;
|
|
301
333
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
export { AbortError, AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, asyncIteratorToStream, asyncIteratorWithSpan, clone, defer, findDeepMatches, get, getGlobalOtelConfig, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
|
|
306
|
-
export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, AsyncIteratorWithSpanOptions, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OmitChainMethodDeep, OnFinishState, OtelConfig, PromiseWithError, Registry, RunWithSpanOptions, Segment, SetOptional, SetSpanErrorOptions, ThrowableError, Value };
|
|
334
|
+
export { AbortError, AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, asyncIteratorToStream, asyncIteratorWithSpan, clone, defer, fallback, findDeepMatches, get, getConstructor, getGlobalOtelConfig, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, overlayProxy, parseEmptyableJSON, preventNativeAwait, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
|
|
335
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Promisable } from 'type-fest';
|
|
2
2
|
export { IsEqual, IsNever, JsonValue, PartialDeep, Promisable } from 'type-fest';
|
|
3
3
|
import { Tracer, TraceAPI, ContextAPI, PropagationAPI, SpanOptions, Context, Span, AttributeValue, Exception } from '@opentelemetry/api';
|
|
4
|
-
export { group, guard, mapEntries, mapValues, omit } from 'radash';
|
|
4
|
+
export { group, guard, mapEntries, mapValues, omit, retry, sleep } from 'radash';
|
|
5
5
|
|
|
6
6
|
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
7
7
|
declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
|
@@ -30,7 +30,7 @@ type OmitChainMethodDeep<T extends object, K extends keyof any> = {
|
|
|
30
30
|
|
|
31
31
|
declare const ORPC_NAME = "orpc";
|
|
32
32
|
declare const ORPC_SHARED_PACKAGE_NAME = "@orpc/shared";
|
|
33
|
-
declare const ORPC_SHARED_PACKAGE_VERSION = "0.0.0-next.
|
|
33
|
+
declare const ORPC_SHARED_PACKAGE_VERSION = "0.0.0-next.d53e45e";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Error thrown when an operation is aborted.
|
|
@@ -60,7 +60,7 @@ interface EventPublisherSubscribeIteratorOptions extends EventPublisherOptions {
|
|
|
60
60
|
/**
|
|
61
61
|
* Aborts the async iterator. Throws if aborted before or during pulling.
|
|
62
62
|
*/
|
|
63
|
-
signal?: AbortSignal;
|
|
63
|
+
signal?: AbortSignal | undefined;
|
|
64
64
|
}
|
|
65
65
|
declare class EventPublisher<T extends Record<PropertyKey, any>> {
|
|
66
66
|
#private;
|
|
@@ -121,6 +121,7 @@ interface Registry {
|
|
|
121
121
|
type ThrowableError = Registry extends {
|
|
122
122
|
throwableError: infer T;
|
|
123
123
|
} ? T : Error;
|
|
124
|
+
type InferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : never;
|
|
124
125
|
|
|
125
126
|
type InterceptableOptions = Record<string, any>;
|
|
126
127
|
type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
@@ -262,6 +263,11 @@ declare function findDeepMatches(check: (value: unknown) => boolean, payload: un
|
|
|
262
263
|
maps: Segment[][];
|
|
263
264
|
values: unknown[];
|
|
264
265
|
};
|
|
266
|
+
/**
|
|
267
|
+
* Get constructor of the value
|
|
268
|
+
*
|
|
269
|
+
*/
|
|
270
|
+
declare function getConstructor(value: unknown): Function | null | undefined;
|
|
265
271
|
/**
|
|
266
272
|
* Check if the value is an object even it created by `Object.create(null)` or more tricky way.
|
|
267
273
|
*/
|
|
@@ -277,15 +283,41 @@ declare const NullProtoObj: ({
|
|
|
277
283
|
new <T extends Record<PropertyKey, unknown>>(): T;
|
|
278
284
|
});
|
|
279
285
|
|
|
286
|
+
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
|
|
287
|
+
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
|
288
|
+
/**
|
|
289
|
+
* Returns the value if it is defined, otherwise returns the fallback
|
|
290
|
+
*/
|
|
291
|
+
declare function fallback<T>(value: T | undefined, fallback: T): T;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Prevents objects from being awaitable by intercepting the `then` method
|
|
295
|
+
* when called by the native await mechanism. This is useful for preventing
|
|
296
|
+
* accidental awaiting of objects that aren't meant to be promises.
|
|
297
|
+
*/
|
|
298
|
+
declare function preventNativeAwait<T extends object>(target: T): T;
|
|
299
|
+
/**
|
|
300
|
+
* Create a proxy that overlays one object (`overlay`) on top of another (`target`).
|
|
301
|
+
*
|
|
302
|
+
* - Properties from `overlay` take precedence.
|
|
303
|
+
* - Properties not in `overlay` fall back to `target`.
|
|
304
|
+
* - Methods from either object are bound to `overlay` so `this` is consistent.
|
|
305
|
+
*
|
|
306
|
+
* Useful when you want to override or extend behavior without fully copying/merging objects.
|
|
307
|
+
*/
|
|
308
|
+
declare function overlayProxy<T extends object, U extends object>(target: Value<T>, partial: U): U & Omit<T, keyof U>;
|
|
309
|
+
|
|
280
310
|
interface AsyncIdQueueCloseOptions {
|
|
281
311
|
id?: string;
|
|
282
312
|
reason?: unknown;
|
|
283
313
|
}
|
|
284
314
|
declare class AsyncIdQueue<T> {
|
|
285
315
|
private readonly openIds;
|
|
286
|
-
private readonly
|
|
287
|
-
private readonly
|
|
316
|
+
private readonly queues;
|
|
317
|
+
private readonly waiters;
|
|
288
318
|
get length(): number;
|
|
319
|
+
get waiterIds(): string[];
|
|
320
|
+
hasBufferedItems(id: string): boolean;
|
|
289
321
|
open(id: string): void;
|
|
290
322
|
isOpen(id: string): boolean;
|
|
291
323
|
push(id: string, item: T): void;
|
|
@@ -299,8 +331,5 @@ declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableS
|
|
|
299
331
|
|
|
300
332
|
declare function tryDecodeURIComponent(value: string): string;
|
|
301
333
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
export { AbortError, AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, asyncIteratorToStream, asyncIteratorWithSpan, clone, defer, findDeepMatches, get, getGlobalOtelConfig, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
|
|
306
|
-
export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, AsyncIteratorWithSpanOptions, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OmitChainMethodDeep, OnFinishState, OtelConfig, PromiseWithError, Registry, RunWithSpanOptions, Segment, SetOptional, SetSpanErrorOptions, ThrowableError, Value };
|
|
334
|
+
export { AbortError, AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, asyncIteratorToStream, asyncIteratorWithSpan, clone, defer, fallback, findDeepMatches, get, getConstructor, getGlobalOtelConfig, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, overlayProxy, parseEmptyableJSON, preventNativeAwait, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
|
|
335
|
+
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { group, guard, mapEntries, mapValues, omit } from 'radash';
|
|
1
|
+
export { group, guard, mapEntries, mapValues, omit, retry, sleep } from 'radash';
|
|
2
2
|
|
|
3
3
|
function resolveMaybeOptionalOptions(rest) {
|
|
4
4
|
return rest[0] ?? {};
|
|
@@ -21,7 +21,7 @@ function readAsBuffer(source) {
|
|
|
21
21
|
|
|
22
22
|
const ORPC_NAME = "orpc";
|
|
23
23
|
const ORPC_SHARED_PACKAGE_NAME = "@orpc/shared";
|
|
24
|
-
const ORPC_SHARED_PACKAGE_VERSION = "0.0.0-next.
|
|
24
|
+
const ORPC_SHARED_PACKAGE_VERSION = "0.0.0-next.d53e45e";
|
|
25
25
|
|
|
26
26
|
class AbortError extends Error {
|
|
27
27
|
constructor(...rest) {
|
|
@@ -153,11 +153,17 @@ async function runInSpanContext(span, fn) {
|
|
|
153
153
|
|
|
154
154
|
class AsyncIdQueue {
|
|
155
155
|
openIds = /* @__PURE__ */ new Set();
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
queues = /* @__PURE__ */ new Map();
|
|
157
|
+
waiters = /* @__PURE__ */ new Map();
|
|
158
158
|
get length() {
|
|
159
159
|
return this.openIds.size;
|
|
160
160
|
}
|
|
161
|
+
get waiterIds() {
|
|
162
|
+
return Array.from(this.waiters.keys());
|
|
163
|
+
}
|
|
164
|
+
hasBufferedItems(id) {
|
|
165
|
+
return Boolean(this.queues.get(id)?.length);
|
|
166
|
+
}
|
|
161
167
|
open(id) {
|
|
162
168
|
this.openIds.add(id);
|
|
163
169
|
}
|
|
@@ -166,59 +172,57 @@ class AsyncIdQueue {
|
|
|
166
172
|
}
|
|
167
173
|
push(id, item) {
|
|
168
174
|
this.assertOpen(id);
|
|
169
|
-
const pending = this.
|
|
175
|
+
const pending = this.waiters.get(id);
|
|
170
176
|
if (pending?.length) {
|
|
171
177
|
pending.shift()[0](item);
|
|
172
178
|
if (pending.length === 0) {
|
|
173
|
-
this.
|
|
179
|
+
this.waiters.delete(id);
|
|
174
180
|
}
|
|
175
181
|
} else {
|
|
176
|
-
const items = this.
|
|
182
|
+
const items = this.queues.get(id);
|
|
177
183
|
if (items) {
|
|
178
184
|
items.push(item);
|
|
179
185
|
} else {
|
|
180
|
-
this.
|
|
186
|
+
this.queues.set(id, [item]);
|
|
181
187
|
}
|
|
182
188
|
}
|
|
183
189
|
}
|
|
184
190
|
async pull(id) {
|
|
185
191
|
this.assertOpen(id);
|
|
186
|
-
const items = this.
|
|
192
|
+
const items = this.queues.get(id);
|
|
187
193
|
if (items?.length) {
|
|
188
194
|
const item = items.shift();
|
|
189
195
|
if (items.length === 0) {
|
|
190
|
-
this.
|
|
196
|
+
this.queues.delete(id);
|
|
191
197
|
}
|
|
192
198
|
return item;
|
|
193
199
|
}
|
|
194
200
|
return new Promise((resolve, reject) => {
|
|
195
|
-
const waitingPulls = this.
|
|
201
|
+
const waitingPulls = this.waiters.get(id);
|
|
196
202
|
const pending = [resolve, reject];
|
|
197
203
|
if (waitingPulls) {
|
|
198
204
|
waitingPulls.push(pending);
|
|
199
205
|
} else {
|
|
200
|
-
this.
|
|
206
|
+
this.waiters.set(id, [pending]);
|
|
201
207
|
}
|
|
202
208
|
});
|
|
203
209
|
}
|
|
204
210
|
close({ id, reason } = {}) {
|
|
205
211
|
if (id === void 0) {
|
|
206
|
-
this.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
});
|
|
212
|
+
this.waiters.forEach((pendingPulls, id2) => {
|
|
213
|
+
const error2 = reason ?? new AbortError(`[AsyncIdQueue] Queue[${id2}] was closed or aborted while waiting for pulling.`);
|
|
214
|
+
pendingPulls.forEach(([, reject]) => reject(error2));
|
|
210
215
|
});
|
|
211
|
-
this.
|
|
216
|
+
this.waiters.clear();
|
|
212
217
|
this.openIds.clear();
|
|
213
|
-
this.
|
|
218
|
+
this.queues.clear();
|
|
214
219
|
return;
|
|
215
220
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
this.pendingPulls.delete(id);
|
|
221
|
+
const error = reason ?? new AbortError(`[AsyncIdQueue] Queue[${id}] was closed or aborted while waiting for pulling.`);
|
|
222
|
+
this.waiters.get(id)?.forEach(([, reject]) => reject(error));
|
|
223
|
+
this.waiters.delete(id);
|
|
220
224
|
this.openIds.delete(id);
|
|
221
|
-
this.
|
|
225
|
+
this.queues.delete(id);
|
|
222
226
|
}
|
|
223
227
|
assertOpen(id) {
|
|
224
228
|
if (!this.isOpen(id)) {
|
|
@@ -298,49 +302,51 @@ class AsyncIteratorClass {
|
|
|
298
302
|
}
|
|
299
303
|
function replicateAsyncIterator(source, count) {
|
|
300
304
|
const queue = new AsyncIdQueue();
|
|
301
|
-
const
|
|
302
|
-
let
|
|
305
|
+
const ids = Array.from({ length: count }, (_, i) => i.toString());
|
|
306
|
+
let isSourceFinished = false;
|
|
303
307
|
const start = once(async () => {
|
|
304
308
|
try {
|
|
305
309
|
while (true) {
|
|
306
310
|
const item = await source.next();
|
|
307
|
-
|
|
308
|
-
if (queue.isOpen(id
|
|
309
|
-
queue.push(id
|
|
311
|
+
ids.forEach((id) => {
|
|
312
|
+
if (queue.isOpen(id)) {
|
|
313
|
+
queue.push(id, { next: item });
|
|
310
314
|
}
|
|
311
|
-
}
|
|
315
|
+
});
|
|
312
316
|
if (item.done) {
|
|
313
317
|
break;
|
|
314
318
|
}
|
|
315
319
|
}
|
|
316
|
-
} catch (
|
|
317
|
-
|
|
320
|
+
} catch (error) {
|
|
321
|
+
ids.forEach((id) => {
|
|
322
|
+
if (queue.isOpen(id)) {
|
|
323
|
+
queue.push(id, { error });
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
} finally {
|
|
327
|
+
isSourceFinished = true;
|
|
318
328
|
}
|
|
319
329
|
});
|
|
320
|
-
|
|
321
|
-
queue.open(id
|
|
322
|
-
|
|
323
|
-
() => {
|
|
330
|
+
const replicated = ids.map((id) => {
|
|
331
|
+
queue.open(id);
|
|
332
|
+
return new AsyncIteratorClass(
|
|
333
|
+
async () => {
|
|
324
334
|
start();
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
});
|
|
335
|
+
const item = await queue.pull(id);
|
|
336
|
+
if (item.next) {
|
|
337
|
+
return item.next;
|
|
338
|
+
}
|
|
339
|
+
throw item.error;
|
|
333
340
|
},
|
|
334
341
|
async (reason) => {
|
|
335
|
-
queue.close({ id
|
|
336
|
-
if (reason !== "next") {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}
|
|
342
|
+
queue.close({ id });
|
|
343
|
+
if (reason !== "next" && !queue.length && !isSourceFinished) {
|
|
344
|
+
isSourceFinished = true;
|
|
345
|
+
await source?.return?.();
|
|
340
346
|
}
|
|
341
347
|
}
|
|
342
|
-
)
|
|
343
|
-
}
|
|
348
|
+
);
|
|
349
|
+
});
|
|
344
350
|
return replicated;
|
|
345
351
|
}
|
|
346
352
|
function asyncIteratorWithSpan({ name, ...options }, iterator) {
|
|
@@ -536,6 +542,12 @@ function findDeepMatches(check, payload, segments = [], maps = [], values = [])
|
|
|
536
542
|
}
|
|
537
543
|
return { maps, values };
|
|
538
544
|
}
|
|
545
|
+
function getConstructor(value) {
|
|
546
|
+
if (!isTypescriptObject(value)) {
|
|
547
|
+
return null;
|
|
548
|
+
}
|
|
549
|
+
return Object.getPrototypeOf(value)?.constructor;
|
|
550
|
+
}
|
|
539
551
|
function isObject(value) {
|
|
540
552
|
if (!value || typeof value !== "object") {
|
|
541
553
|
return false;
|
|
@@ -581,6 +593,61 @@ const NullProtoObj = /* @__PURE__ */ (() => {
|
|
|
581
593
|
return e;
|
|
582
594
|
})();
|
|
583
595
|
|
|
596
|
+
function value(value2, ...args) {
|
|
597
|
+
if (typeof value2 === "function") {
|
|
598
|
+
return value2(...args);
|
|
599
|
+
}
|
|
600
|
+
return value2;
|
|
601
|
+
}
|
|
602
|
+
function fallback(value2, fallback2) {
|
|
603
|
+
return value2 === void 0 ? fallback2 : value2;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function preventNativeAwait(target) {
|
|
607
|
+
return new Proxy(target, {
|
|
608
|
+
get(target2, prop, receiver) {
|
|
609
|
+
const value2 = Reflect.get(target2, prop, receiver);
|
|
610
|
+
if (prop !== "then" || typeof value2 !== "function") {
|
|
611
|
+
return value2;
|
|
612
|
+
}
|
|
613
|
+
return new Proxy(value2, {
|
|
614
|
+
apply(targetFn, thisArg, args) {
|
|
615
|
+
if (args.length !== 2 || args.some((arg) => !isNativeFunction(arg))) {
|
|
616
|
+
return Reflect.apply(targetFn, thisArg, args);
|
|
617
|
+
}
|
|
618
|
+
let shouldOmit = true;
|
|
619
|
+
args[0].call(thisArg, preventNativeAwait(new Proxy(target2, {
|
|
620
|
+
get: (target3, prop2, receiver2) => {
|
|
621
|
+
if (shouldOmit && prop2 === "then") {
|
|
622
|
+
shouldOmit = false;
|
|
623
|
+
return void 0;
|
|
624
|
+
}
|
|
625
|
+
return Reflect.get(target3, prop2, receiver2);
|
|
626
|
+
}
|
|
627
|
+
})));
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
const NATIVE_FUNCTION_REGEX = /^\s*function\s*\(\)\s*\{\s*\[native code\]\s*\}\s*$/;
|
|
634
|
+
function isNativeFunction(fn) {
|
|
635
|
+
return typeof fn === "function" && NATIVE_FUNCTION_REGEX.test(fn.toString());
|
|
636
|
+
}
|
|
637
|
+
function overlayProxy(target, partial) {
|
|
638
|
+
const proxy = new Proxy(typeof target === "function" ? partial : target, {
|
|
639
|
+
get(_, prop) {
|
|
640
|
+
const targetValue = prop in partial ? partial : value(target);
|
|
641
|
+
const v = Reflect.get(targetValue, prop);
|
|
642
|
+
return typeof v === "function" ? v.bind(targetValue) : v;
|
|
643
|
+
},
|
|
644
|
+
has(_, prop) {
|
|
645
|
+
return Reflect.has(partial, prop) || Reflect.has(value(target), prop);
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
return proxy;
|
|
649
|
+
}
|
|
650
|
+
|
|
584
651
|
function streamToAsyncIteratorClass(stream) {
|
|
585
652
|
const reader = stream.getReader();
|
|
586
653
|
return new AsyncIteratorClass(
|
|
@@ -616,11 +683,4 @@ function tryDecodeURIComponent(value) {
|
|
|
616
683
|
}
|
|
617
684
|
}
|
|
618
685
|
|
|
619
|
-
|
|
620
|
-
if (typeof value2 === "function") {
|
|
621
|
-
return value2(...args);
|
|
622
|
-
}
|
|
623
|
-
return value2;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
export { AbortError, AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, asyncIteratorToStream, asyncIteratorWithSpan, clone, defer, findDeepMatches, get, getGlobalOtelConfig, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
|
|
686
|
+
export { AbortError, AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, asyncIteratorToStream, asyncIteratorWithSpan, clone, defer, fallback, findDeepMatches, get, getConstructor, getGlobalOtelConfig, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, overlayProxy, parseEmptyableJSON, preventNativeAwait, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.d53e45e",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"radash": "^12.1.1",
|
|
36
|
-
"type-fest": "^
|
|
36
|
+
"type-fest": "^5.0.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@opentelemetry/api": "^1.9.0",
|
|
40
|
-
"arktype": "2.1.
|
|
40
|
+
"arktype": "2.1.22",
|
|
41
41
|
"valibot": "^1.1.0",
|
|
42
|
-
"zod": "^4.
|
|
42
|
+
"zod": "^4.1.11"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "unbuild",
|