@orpc/shared 0.0.0-next.dc23561 → 0.0.0-next.dc2afcb

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 CHANGED
@@ -1,22 +1,25 @@
1
1
  <div align="center">
2
- <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
2
+ <image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" />
3
3
  </div>
4
4
 
5
5
  <h1></h1>
6
6
 
7
7
  <div align="center">
8
- <a href="https://codecov.io/gh/unnoq/orpc">
9
- <img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
8
+ <a href="https://codecov.io/gh/middleapi/orpc">
9
+ <img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/main/graph/badge.svg">
10
10
  </a>
11
11
  <a href="https://www.npmjs.com/package/@orpc/shared">
12
12
  <img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fshared?logo=npm" />
13
13
  </a>
14
- <a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
15
- <img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
14
+ <a href="https://github.com/middleapi/orpc/blob/main/LICENSE">
15
+ <img alt="MIT License" src="https://img.shields.io/github/license/middleapi/orpc?logo=open-source-initiative" />
16
16
  </a>
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/middleapi/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>
@@ -42,7 +45,7 @@
42
45
 
43
46
  ## Documentation
44
47
 
45
- You can find the full documentation [here](https://orpc.unnoq.com).
48
+ You can find the full documentation [here](https://orpc.dev).
46
49
 
47
50
  ## Packages
48
51
 
@@ -75,4 +78,4 @@ Provides shared utilities for oRPC packages.
75
78
 
76
79
  ## License
77
80
 
78
- Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
81
+ Distributed under the MIT License. See [LICENSE](https://github.com/middleapi/orpc/blob/main/LICENSE) for more information.
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.dc23561";
33
+ declare const ORPC_SHARED_PACKAGE_VERSION = "0.0.0-next.dc2afcb";
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;
@@ -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
  */
@@ -272,18 +285,35 @@ declare function isObject(value: unknown): value is Record<PropertyKey, unknown>
272
285
  */
273
286
  declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
274
287
  declare function clone<T>(value: T): T;
275
- declare function get(object: unknown, path: readonly string[]): unknown;
288
+ declare function get(object: unknown, path: readonly PropertyKey[]): unknown;
276
289
  declare function isPropertyKey(value: unknown): value is PropertyKey;
277
290
  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
- type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
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.dc23561";
33
+ declare const ORPC_SHARED_PACKAGE_VERSION = "0.0.0-next.dc2afcb";
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;
@@ -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
  */
@@ -272,18 +285,35 @@ declare function isObject(value: unknown): value is Record<PropertyKey, unknown>
272
285
  */
273
286
  declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
274
287
  declare function clone<T>(value: T): T;
275
- declare function get(object: unknown, path: readonly string[]): unknown;
288
+ declare function get(object: unknown, path: readonly PropertyKey[]): unknown;
276
289
  declare function isPropertyKey(value: unknown): value is PropertyKey;
277
290
  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
- type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
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.dc23561";
24
+ const ORPC_SHARED_PACKAGE_VERSION = "0.0.0-next.dc2afcb";
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
- pendingPulls.forEach(([, reject]) => {
214
- reject(reason ?? new Error(`[AsyncIdQueue] Queue[${id2}] was closed or aborted while waiting for pulling.`));
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
- this.waiters.get(id)?.forEach(([, reject]) => {
223
- reject(reason ?? new Error(`[AsyncIdQueue] Queue[${id}] was closed or aborted while waiting for pulling.`));
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);
@@ -304,53 +302,51 @@ class AsyncIteratorClass {
304
302
  }
305
303
  function replicateAsyncIterator(source, count) {
306
304
  const queue = new AsyncIdQueue();
307
- const replicated = [];
308
- let error;
305
+ const ids = Array.from({ length: count }, (_, i) => i.toString());
306
+ let isSourceFinished = false;
309
307
  const start = once(async () => {
310
308
  try {
311
309
  while (true) {
312
310
  const item = await source.next();
313
- for (let i = 0; i < count; i++) {
314
- const id = i.toString();
311
+ ids.forEach((id) => {
315
312
  if (queue.isOpen(id)) {
316
- queue.push(id, item);
313
+ queue.push(id, { next: item });
317
314
  }
318
- }
315
+ });
319
316
  if (item.done) {
320
317
  break;
321
318
  }
322
319
  }
323
- } catch (reason) {
324
- error = { value: reason };
325
- queue.waiterIds.forEach((id) => {
326
- queue.close({ id, reason });
320
+ } catch (error) {
321
+ ids.forEach((id) => {
322
+ if (queue.isOpen(id)) {
323
+ queue.push(id, { error });
324
+ }
327
325
  });
326
+ } finally {
327
+ isSourceFinished = true;
328
328
  }
329
329
  });
330
- for (let i = 0; i < count; i++) {
331
- const id = i.toString();
330
+ const replicated = ids.map((id) => {
332
331
  queue.open(id);
333
- replicated.push(new AsyncIteratorClass(
334
- () => {
332
+ return new AsyncIteratorClass(
333
+ async () => {
335
334
  start();
336
- return new Promise((resolve, reject) => {
337
- if (!error || queue.hasBufferedItems(id)) {
338
- queue.pull(id).then(resolve).catch(reject);
339
- } else {
340
- reject(error.value);
341
- }
342
- });
335
+ const item = await queue.pull(id);
336
+ if (item.next) {
337
+ return item.next;
338
+ }
339
+ throw item.error;
343
340
  },
344
341
  async (reason) => {
345
342
  queue.close({ id });
346
- if (reason !== "next") {
347
- if (!queue.length) {
348
- await source?.return?.();
349
- }
343
+ if (reason !== "next" && !queue.length && !isSourceFinished) {
344
+ isSourceFinished = true;
345
+ await source?.return?.();
350
346
  }
351
347
  }
352
- ));
353
- }
348
+ );
349
+ });
354
350
  return replicated;
355
351
  }
356
352
  function asyncIteratorWithSpan({ name, ...options }, iterator) {
@@ -407,15 +403,15 @@ class EventPublisher {
407
403
  if (typeof listenerOrOptions === "function") {
408
404
  let listeners = this.#listenersMap.get(event);
409
405
  if (!listeners) {
410
- this.#listenersMap.set(event, listeners = /* @__PURE__ */ new Set());
406
+ this.#listenersMap.set(event, listeners = []);
411
407
  }
412
- listeners.add(listenerOrOptions);
413
- return () => {
414
- listeners.delete(listenerOrOptions);
415
- if (listeners.size === 0) {
408
+ listeners.push(listenerOrOptions);
409
+ return once(() => {
410
+ listeners.splice(listeners.indexOf(listenerOrOptions), 1);
411
+ if (listeners.length === 0) {
416
412
  this.#listenersMap.delete(event);
417
413
  }
418
- };
414
+ });
419
415
  }
420
416
  const signal = listenerOrOptions?.signal;
421
417
  const maxBufferedEvents = listenerOrOptions?.maxBufferedEvents ?? this.#maxBufferedEvents;
@@ -461,13 +457,19 @@ class EventPublisher {
461
457
  }
462
458
 
463
459
  class SequentialIdGenerator {
464
- index = BigInt(0);
460
+ index = BigInt(1);
465
461
  generate() {
466
- const id = this.index.toString(32);
462
+ const id = this.index.toString(36);
467
463
  this.index++;
468
464
  return id;
469
465
  }
470
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
+ }
471
473
 
472
474
  function onStart(callback) {
473
475
  return async (options, ...rest) => {
@@ -546,6 +548,12 @@ function findDeepMatches(check, payload, segments = [], maps = [], values = [])
546
548
  }
547
549
  return { maps, values };
548
550
  }
551
+ function getConstructor(value) {
552
+ if (!isTypescriptObject(value)) {
553
+ return null;
554
+ }
555
+ return Object.getPrototypeOf(value)?.constructor;
556
+ }
549
557
  function isObject(value) {
550
558
  if (!value || typeof value !== "object") {
551
559
  return false;
@@ -565,6 +573,9 @@ function clone(value) {
565
573
  for (const key in value) {
566
574
  result[key] = clone(value[key]);
567
575
  }
576
+ for (const sym of Object.getOwnPropertySymbols(value)) {
577
+ result[sym] = clone(value[sym]);
578
+ }
568
579
  return result;
569
580
  }
570
581
  return value;
@@ -591,14 +602,24 @@ const NullProtoObj = /* @__PURE__ */ (() => {
591
602
  return e;
592
603
  })();
593
604
 
605
+ function value(value2, ...args) {
606
+ if (typeof value2 === "function") {
607
+ return value2(...args);
608
+ }
609
+ return value2;
610
+ }
611
+ function fallback(value2, fallback2) {
612
+ return value2 === void 0 ? fallback2 : value2;
613
+ }
614
+
594
615
  function preventNativeAwait(target) {
595
616
  return new Proxy(target, {
596
617
  get(target2, prop, receiver) {
597
- const value = Reflect.get(target2, prop, receiver);
598
- if (prop !== "then" || typeof value !== "function") {
599
- return value;
618
+ const value2 = Reflect.get(target2, prop, receiver);
619
+ if (prop !== "then" || typeof value2 !== "function") {
620
+ return value2;
600
621
  }
601
- return new Proxy(value, {
622
+ return new Proxy(value2, {
602
623
  apply(targetFn, thisArg, args) {
603
624
  if (args.length !== 2 || args.some((arg) => !isNativeFunction(arg))) {
604
625
  return Reflect.apply(targetFn, thisArg, args);
@@ -622,6 +643,19 @@ const NATIVE_FUNCTION_REGEX = /^\s*function\s*\(\)\s*\{\s*\[native code\]\s*\}\s
622
643
  function isNativeFunction(fn) {
623
644
  return typeof fn === "function" && NATIVE_FUNCTION_REGEX.test(fn.toString());
624
645
  }
646
+ function overlayProxy(target, partial) {
647
+ const proxy = new Proxy(typeof target === "function" ? partial : target, {
648
+ get(_, prop) {
649
+ const targetValue = prop in partial ? partial : value(target);
650
+ const v = Reflect.get(targetValue, prop);
651
+ return typeof v === "function" ? v.bind(targetValue) : v;
652
+ },
653
+ has(_, prop) {
654
+ return Reflect.has(partial, prop) || Reflect.has(value(target), prop);
655
+ }
656
+ });
657
+ return proxy;
658
+ }
625
659
 
626
660
  function streamToAsyncIteratorClass(stream) {
627
661
  const reader = stream.getReader();
@@ -649,6 +683,22 @@ function asyncIteratorToStream(iterator) {
649
683
  }
650
684
  });
651
685
  }
686
+ function asyncIteratorToUnproxiedDataStream(iterator) {
687
+ return new ReadableStream({
688
+ async pull(controller) {
689
+ const { done, value } = await iterator.next();
690
+ if (done) {
691
+ controller.close();
692
+ } else {
693
+ const unproxied = isObject(value) ? { ...value } : Array.isArray(value) ? value.map((i) => i) : value;
694
+ controller.enqueue(unproxied);
695
+ }
696
+ },
697
+ async cancel() {
698
+ await iterator.return?.();
699
+ }
700
+ });
701
+ }
652
702
 
653
703
  function tryDecodeURIComponent(value) {
654
704
  try {
@@ -658,11 +708,4 @@ function tryDecodeURIComponent(value) {
658
708
  }
659
709
  }
660
710
 
661
- function value(value2, ...args) {
662
- if (typeof value2 === "function") {
663
- return value2(...args);
664
- }
665
- return value2;
666
- }
667
-
668
- 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 };
711
+ 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,16 +1,15 @@
1
1
  {
2
2
  "name": "@orpc/shared",
3
3
  "type": "module",
4
- "version": "0.0.0-next.dc23561",
4
+ "version": "0.0.0-next.dc2afcb",
5
5
  "license": "MIT",
6
- "homepage": "https://orpc.unnoq.com",
6
+ "homepage": "https://orpc.dev",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/unnoq/orpc.git",
9
+ "url": "git+https://github.com/middleapi/orpc.git",
10
10
  "directory": "packages/shared"
11
11
  },
12
12
  "keywords": [
13
- "unnoq",
14
13
  "orpc"
15
14
  ],
16
15
  "exports": {
@@ -33,13 +32,13 @@
33
32
  },
34
33
  "dependencies": {
35
34
  "radash": "^12.1.1",
36
- "type-fest": "^4.39.1"
35
+ "type-fest": "^5.4.4"
37
36
  },
38
37
  "devDependencies": {
39
38
  "@opentelemetry/api": "^1.9.0",
40
- "arktype": "2.1.20",
41
- "valibot": "^1.1.0",
42
- "zod": "^4.1.1"
39
+ "arktype": "2.1.29",
40
+ "valibot": "^1.2.0",
41
+ "zod": "^4.3.6"
43
42
  },
44
43
  "scripts": {
45
44
  "build": "unbuild",