@orpc/shared 0.0.0-next.35fabdb → 0.0.0-next.3647437
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 +3 -0
- package/dist/index.d.mts +44 -6
- package/dist/index.d.ts +44 -6
- package/dist/index.mjs +70 -28
- 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>
|
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.3647437";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Error thrown when an operation is aborted.
|
|
@@ -103,6 +103,14 @@ declare class SequentialIdGenerator {
|
|
|
103
103
|
private index;
|
|
104
104
|
generate(): string;
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Compares two sequential IDs.
|
|
108
|
+
* Returns:
|
|
109
|
+
* - negative if `a` < `b`
|
|
110
|
+
* - positive if `a` > `b`
|
|
111
|
+
* - 0 if equal
|
|
112
|
+
*/
|
|
113
|
+
declare function compareSequentialIds(a: string, b: string): number;
|
|
106
114
|
|
|
107
115
|
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
108
116
|
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
@@ -263,6 +271,11 @@ declare function findDeepMatches(check: (value: unknown) => boolean, payload: un
|
|
|
263
271
|
maps: Segment[][];
|
|
264
272
|
values: unknown[];
|
|
265
273
|
};
|
|
274
|
+
/**
|
|
275
|
+
* Get constructor of the value
|
|
276
|
+
*
|
|
277
|
+
*/
|
|
278
|
+
declare function getConstructor(value: unknown): Function | null | undefined;
|
|
266
279
|
/**
|
|
267
280
|
* Check if the value is an object even it created by `Object.create(null)` or more tricky way.
|
|
268
281
|
*/
|
|
@@ -278,12 +291,29 @@ declare const NullProtoObj: ({
|
|
|
278
291
|
new <T extends Record<PropertyKey, unknown>>(): T;
|
|
279
292
|
});
|
|
280
293
|
|
|
294
|
+
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
|
|
295
|
+
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
|
296
|
+
/**
|
|
297
|
+
* Returns the value if it is defined, otherwise returns the fallback
|
|
298
|
+
*/
|
|
299
|
+
declare function fallback<T>(value: T | undefined, fallback: T): T;
|
|
300
|
+
|
|
281
301
|
/**
|
|
282
302
|
* Prevents objects from being awaitable by intercepting the `then` method
|
|
283
303
|
* when called by the native await mechanism. This is useful for preventing
|
|
284
304
|
* accidental awaiting of objects that aren't meant to be promises.
|
|
285
305
|
*/
|
|
286
306
|
declare function preventNativeAwait<T extends object>(target: T): T;
|
|
307
|
+
/**
|
|
308
|
+
* Create a proxy that overlays one object (`overlay`) on top of another (`target`).
|
|
309
|
+
*
|
|
310
|
+
* - Properties from `overlay` take precedence.
|
|
311
|
+
* - Properties not in `overlay` fall back to `target`.
|
|
312
|
+
* - Methods from either object are bound to `overlay` so `this` is consistent.
|
|
313
|
+
*
|
|
314
|
+
* Useful when you want to override or extend behavior without fully copying/merging objects.
|
|
315
|
+
*/
|
|
316
|
+
declare function overlayProxy<T extends object, U extends object>(target: Value<T>, partial: U): U & Omit<T, keyof U>;
|
|
287
317
|
|
|
288
318
|
interface AsyncIdQueueCloseOptions {
|
|
289
319
|
id?: string;
|
|
@@ -304,13 +334,21 @@ declare class AsyncIdQueue<T> {
|
|
|
304
334
|
assertOpen(id: string): void;
|
|
305
335
|
}
|
|
306
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Converts a `ReadableStream` into an `AsyncIteratorClass`.
|
|
339
|
+
*/
|
|
307
340
|
declare function streamToAsyncIteratorClass<T>(stream: ReadableStream<T>): AsyncIteratorClass<T>;
|
|
341
|
+
/**
|
|
342
|
+
* Converts an `AsyncIterator` into a `ReadableStream`.
|
|
343
|
+
*/
|
|
308
344
|
declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
345
|
+
/**
|
|
346
|
+
* Converts an `AsyncIterator` into a `ReadableStream`, ensuring that
|
|
347
|
+
* all emitted object values are *unproxied* before enqueuing.
|
|
348
|
+
*/
|
|
349
|
+
declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
309
350
|
|
|
310
351
|
declare function tryDecodeURIComponent(value: string): string;
|
|
311
352
|
|
|
312
|
-
|
|
313
|
-
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
|
314
|
-
|
|
315
|
-
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, preventNativeAwait, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
|
|
353
|
+
export { AbortError, AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, asyncIteratorWithSpan, clone, compareSequentialIds, 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 };
|
|
316
354
|
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.3647437";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Error thrown when an operation is aborted.
|
|
@@ -103,6 +103,14 @@ declare class SequentialIdGenerator {
|
|
|
103
103
|
private index;
|
|
104
104
|
generate(): string;
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Compares two sequential IDs.
|
|
108
|
+
* Returns:
|
|
109
|
+
* - negative if `a` < `b`
|
|
110
|
+
* - positive if `a` > `b`
|
|
111
|
+
* - 0 if equal
|
|
112
|
+
*/
|
|
113
|
+
declare function compareSequentialIds(a: string, b: string): number;
|
|
106
114
|
|
|
107
115
|
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
108
116
|
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
@@ -263,6 +271,11 @@ declare function findDeepMatches(check: (value: unknown) => boolean, payload: un
|
|
|
263
271
|
maps: Segment[][];
|
|
264
272
|
values: unknown[];
|
|
265
273
|
};
|
|
274
|
+
/**
|
|
275
|
+
* Get constructor of the value
|
|
276
|
+
*
|
|
277
|
+
*/
|
|
278
|
+
declare function getConstructor(value: unknown): Function | null | undefined;
|
|
266
279
|
/**
|
|
267
280
|
* Check if the value is an object even it created by `Object.create(null)` or more tricky way.
|
|
268
281
|
*/
|
|
@@ -278,12 +291,29 @@ declare const NullProtoObj: ({
|
|
|
278
291
|
new <T extends Record<PropertyKey, unknown>>(): T;
|
|
279
292
|
});
|
|
280
293
|
|
|
294
|
+
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
|
|
295
|
+
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
|
296
|
+
/**
|
|
297
|
+
* Returns the value if it is defined, otherwise returns the fallback
|
|
298
|
+
*/
|
|
299
|
+
declare function fallback<T>(value: T | undefined, fallback: T): T;
|
|
300
|
+
|
|
281
301
|
/**
|
|
282
302
|
* Prevents objects from being awaitable by intercepting the `then` method
|
|
283
303
|
* when called by the native await mechanism. This is useful for preventing
|
|
284
304
|
* accidental awaiting of objects that aren't meant to be promises.
|
|
285
305
|
*/
|
|
286
306
|
declare function preventNativeAwait<T extends object>(target: T): T;
|
|
307
|
+
/**
|
|
308
|
+
* Create a proxy that overlays one object (`overlay`) on top of another (`target`).
|
|
309
|
+
*
|
|
310
|
+
* - Properties from `overlay` take precedence.
|
|
311
|
+
* - Properties not in `overlay` fall back to `target`.
|
|
312
|
+
* - Methods from either object are bound to `overlay` so `this` is consistent.
|
|
313
|
+
*
|
|
314
|
+
* Useful when you want to override or extend behavior without fully copying/merging objects.
|
|
315
|
+
*/
|
|
316
|
+
declare function overlayProxy<T extends object, U extends object>(target: Value<T>, partial: U): U & Omit<T, keyof U>;
|
|
287
317
|
|
|
288
318
|
interface AsyncIdQueueCloseOptions {
|
|
289
319
|
id?: string;
|
|
@@ -304,13 +334,21 @@ declare class AsyncIdQueue<T> {
|
|
|
304
334
|
assertOpen(id: string): void;
|
|
305
335
|
}
|
|
306
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Converts a `ReadableStream` into an `AsyncIteratorClass`.
|
|
339
|
+
*/
|
|
307
340
|
declare function streamToAsyncIteratorClass<T>(stream: ReadableStream<T>): AsyncIteratorClass<T>;
|
|
341
|
+
/**
|
|
342
|
+
* Converts an `AsyncIterator` into a `ReadableStream`.
|
|
343
|
+
*/
|
|
308
344
|
declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
345
|
+
/**
|
|
346
|
+
* Converts an `AsyncIterator` into a `ReadableStream`, ensuring that
|
|
347
|
+
* all emitted object values are *unproxied* before enqueuing.
|
|
348
|
+
*/
|
|
349
|
+
declare function asyncIteratorToUnproxiedDataStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
|
|
309
350
|
|
|
310
351
|
declare function tryDecodeURIComponent(value: string): string;
|
|
311
352
|
|
|
312
|
-
|
|
313
|
-
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
|
|
314
|
-
|
|
315
|
-
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, preventNativeAwait, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
|
|
353
|
+
export { AbortError, AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, asyncIteratorWithSpan, clone, compareSequentialIds, 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 };
|
|
316
354
|
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.3647437";
|
|
25
25
|
|
|
26
26
|
class AbortError extends Error {
|
|
27
27
|
constructor(...rest) {
|
|
@@ -210,18 +210,16 @@ class AsyncIdQueue {
|
|
|
210
210
|
close({ id, reason } = {}) {
|
|
211
211
|
if (id === void 0) {
|
|
212
212
|
this.waiters.forEach((pendingPulls, id2) => {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
});
|
|
213
|
+
const error2 = reason ?? new AbortError(`[AsyncIdQueue] Queue[${id2}] was closed or aborted while waiting for pulling.`);
|
|
214
|
+
pendingPulls.forEach(([, reject]) => reject(error2));
|
|
216
215
|
});
|
|
217
216
|
this.waiters.clear();
|
|
218
217
|
this.openIds.clear();
|
|
219
218
|
this.queues.clear();
|
|
220
219
|
return;
|
|
221
220
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
});
|
|
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));
|
|
225
223
|
this.waiters.delete(id);
|
|
226
224
|
this.openIds.delete(id);
|
|
227
225
|
this.queues.delete(id);
|
|
@@ -405,15 +403,15 @@ class EventPublisher {
|
|
|
405
403
|
if (typeof listenerOrOptions === "function") {
|
|
406
404
|
let listeners = this.#listenersMap.get(event);
|
|
407
405
|
if (!listeners) {
|
|
408
|
-
this.#listenersMap.set(event, listeners =
|
|
406
|
+
this.#listenersMap.set(event, listeners = []);
|
|
409
407
|
}
|
|
410
|
-
listeners.
|
|
411
|
-
return () => {
|
|
412
|
-
listeners.
|
|
413
|
-
if (listeners.
|
|
408
|
+
listeners.push(listenerOrOptions);
|
|
409
|
+
return once(() => {
|
|
410
|
+
listeners.splice(listeners.indexOf(listenerOrOptions), 1);
|
|
411
|
+
if (listeners.length === 0) {
|
|
414
412
|
this.#listenersMap.delete(event);
|
|
415
413
|
}
|
|
416
|
-
};
|
|
414
|
+
});
|
|
417
415
|
}
|
|
418
416
|
const signal = listenerOrOptions?.signal;
|
|
419
417
|
const maxBufferedEvents = listenerOrOptions?.maxBufferedEvents ?? this.#maxBufferedEvents;
|
|
@@ -459,13 +457,19 @@ class EventPublisher {
|
|
|
459
457
|
}
|
|
460
458
|
|
|
461
459
|
class SequentialIdGenerator {
|
|
462
|
-
index = BigInt(
|
|
460
|
+
index = BigInt(1);
|
|
463
461
|
generate() {
|
|
464
|
-
const id = this.index.toString(
|
|
462
|
+
const id = this.index.toString(36);
|
|
465
463
|
this.index++;
|
|
466
464
|
return id;
|
|
467
465
|
}
|
|
468
466
|
}
|
|
467
|
+
function compareSequentialIds(a, b) {
|
|
468
|
+
if (a.length !== b.length) {
|
|
469
|
+
return a.length - b.length;
|
|
470
|
+
}
|
|
471
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
472
|
+
}
|
|
469
473
|
|
|
470
474
|
function onStart(callback) {
|
|
471
475
|
return async (options, ...rest) => {
|
|
@@ -544,6 +548,12 @@ function findDeepMatches(check, payload, segments = [], maps = [], values = [])
|
|
|
544
548
|
}
|
|
545
549
|
return { maps, values };
|
|
546
550
|
}
|
|
551
|
+
function getConstructor(value) {
|
|
552
|
+
if (!isTypescriptObject(value)) {
|
|
553
|
+
return null;
|
|
554
|
+
}
|
|
555
|
+
return Object.getPrototypeOf(value)?.constructor;
|
|
556
|
+
}
|
|
547
557
|
function isObject(value) {
|
|
548
558
|
if (!value || typeof value !== "object") {
|
|
549
559
|
return false;
|
|
@@ -589,14 +599,24 @@ const NullProtoObj = /* @__PURE__ */ (() => {
|
|
|
589
599
|
return e;
|
|
590
600
|
})();
|
|
591
601
|
|
|
602
|
+
function value(value2, ...args) {
|
|
603
|
+
if (typeof value2 === "function") {
|
|
604
|
+
return value2(...args);
|
|
605
|
+
}
|
|
606
|
+
return value2;
|
|
607
|
+
}
|
|
608
|
+
function fallback(value2, fallback2) {
|
|
609
|
+
return value2 === void 0 ? fallback2 : value2;
|
|
610
|
+
}
|
|
611
|
+
|
|
592
612
|
function preventNativeAwait(target) {
|
|
593
613
|
return new Proxy(target, {
|
|
594
614
|
get(target2, prop, receiver) {
|
|
595
|
-
const
|
|
596
|
-
if (prop !== "then" || typeof
|
|
597
|
-
return
|
|
615
|
+
const value2 = Reflect.get(target2, prop, receiver);
|
|
616
|
+
if (prop !== "then" || typeof value2 !== "function") {
|
|
617
|
+
return value2;
|
|
598
618
|
}
|
|
599
|
-
return new Proxy(
|
|
619
|
+
return new Proxy(value2, {
|
|
600
620
|
apply(targetFn, thisArg, args) {
|
|
601
621
|
if (args.length !== 2 || args.some((arg) => !isNativeFunction(arg))) {
|
|
602
622
|
return Reflect.apply(targetFn, thisArg, args);
|
|
@@ -620,6 +640,19 @@ const NATIVE_FUNCTION_REGEX = /^\s*function\s*\(\)\s*\{\s*\[native code\]\s*\}\s
|
|
|
620
640
|
function isNativeFunction(fn) {
|
|
621
641
|
return typeof fn === "function" && NATIVE_FUNCTION_REGEX.test(fn.toString());
|
|
622
642
|
}
|
|
643
|
+
function overlayProxy(target, partial) {
|
|
644
|
+
const proxy = new Proxy(typeof target === "function" ? partial : target, {
|
|
645
|
+
get(_, prop) {
|
|
646
|
+
const targetValue = prop in partial ? partial : value(target);
|
|
647
|
+
const v = Reflect.get(targetValue, prop);
|
|
648
|
+
return typeof v === "function" ? v.bind(targetValue) : v;
|
|
649
|
+
},
|
|
650
|
+
has(_, prop) {
|
|
651
|
+
return Reflect.has(partial, prop) || Reflect.has(value(target), prop);
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
return proxy;
|
|
655
|
+
}
|
|
623
656
|
|
|
624
657
|
function streamToAsyncIteratorClass(stream) {
|
|
625
658
|
const reader = stream.getReader();
|
|
@@ -647,6 +680,22 @@ function asyncIteratorToStream(iterator) {
|
|
|
647
680
|
}
|
|
648
681
|
});
|
|
649
682
|
}
|
|
683
|
+
function asyncIteratorToUnproxiedDataStream(iterator) {
|
|
684
|
+
return new ReadableStream({
|
|
685
|
+
async pull(controller) {
|
|
686
|
+
const { done, value } = await iterator.next();
|
|
687
|
+
if (done) {
|
|
688
|
+
controller.close();
|
|
689
|
+
} else {
|
|
690
|
+
const unproxied = isObject(value) ? { ...value } : Array.isArray(value) ? value.map((i) => i) : value;
|
|
691
|
+
controller.enqueue(unproxied);
|
|
692
|
+
}
|
|
693
|
+
},
|
|
694
|
+
async cancel() {
|
|
695
|
+
await iterator.return?.();
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
}
|
|
650
699
|
|
|
651
700
|
function tryDecodeURIComponent(value) {
|
|
652
701
|
try {
|
|
@@ -656,11 +705,4 @@ function tryDecodeURIComponent(value) {
|
|
|
656
705
|
}
|
|
657
706
|
}
|
|
658
707
|
|
|
659
|
-
|
|
660
|
-
if (typeof value2 === "function") {
|
|
661
|
-
return value2(...args);
|
|
662
|
-
}
|
|
663
|
-
return value2;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
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, preventNativeAwait, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, runInSpanContext, runWithSpan, sequential, setGlobalOtelConfig, setSpanAttribute, setSpanError, splitInHalf, startSpan, streamToAsyncIteratorClass, stringifyJSON, toArray, toOtelException, toSpanAttributeValue, tryDecodeURIComponent, value };
|
|
708
|
+
export { AbortError, AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, ORPC_NAME, ORPC_SHARED_PACKAGE_NAME, ORPC_SHARED_PACKAGE_VERSION, SequentialIdGenerator, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, asyncIteratorWithSpan, clone, compareSequentialIds, 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.3647437",
|
|
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.1.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@opentelemetry/api": "^1.9.0",
|
|
40
|
-
"arktype": "2.1.
|
|
40
|
+
"arktype": "2.1.23",
|
|
41
41
|
"valibot": "^1.1.0",
|
|
42
|
-
"zod": "^4.1.
|
|
42
|
+
"zod": "^4.1.12"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "unbuild",
|