@orpc/shared 1.8.4 → 1.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -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 = "1.8.4";
33
+ declare const ORPC_SHARED_PACKAGE_VERSION = "1.8.6";
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;
package/dist/index.d.ts CHANGED
@@ -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 = "1.8.4";
33
+ declare const ORPC_SHARED_PACKAGE_VERSION = "1.8.6";
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;
package/dist/index.mjs CHANGED
@@ -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 = "1.8.4";
24
+ const ORPC_SHARED_PACKAGE_VERSION = "1.8.6";
25
25
 
26
26
  class AbortError extends Error {
27
27
  constructor(...rest) {
@@ -304,53 +304,51 @@ class AsyncIteratorClass {
304
304
  }
305
305
  function replicateAsyncIterator(source, count) {
306
306
  const queue = new AsyncIdQueue();
307
- const replicated = [];
308
- let error;
307
+ const ids = Array.from({ length: count }, (_, i) => i.toString());
308
+ let isSourceFinished = false;
309
309
  const start = once(async () => {
310
310
  try {
311
311
  while (true) {
312
312
  const item = await source.next();
313
- for (let i = 0; i < count; i++) {
314
- const id = i.toString();
313
+ ids.forEach((id) => {
315
314
  if (queue.isOpen(id)) {
316
- queue.push(id, item);
315
+ queue.push(id, { next: item });
317
316
  }
318
- }
317
+ });
319
318
  if (item.done) {
320
319
  break;
321
320
  }
322
321
  }
323
- } catch (reason) {
324
- error = { value: reason };
325
- queue.waiterIds.forEach((id) => {
326
- queue.close({ id, reason });
322
+ } catch (error) {
323
+ ids.forEach((id) => {
324
+ if (queue.isOpen(id)) {
325
+ queue.push(id, { error });
326
+ }
327
327
  });
328
+ } finally {
329
+ isSourceFinished = true;
328
330
  }
329
331
  });
330
- for (let i = 0; i < count; i++) {
331
- const id = i.toString();
332
+ const replicated = ids.map((id) => {
332
333
  queue.open(id);
333
- replicated.push(new AsyncIteratorClass(
334
- () => {
334
+ return new AsyncIteratorClass(
335
+ async () => {
335
336
  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
- });
337
+ const item = await queue.pull(id);
338
+ if (item.next) {
339
+ return item.next;
340
+ }
341
+ throw item.error;
343
342
  },
344
343
  async (reason) => {
345
344
  queue.close({ id });
346
- if (reason !== "next") {
347
- if (!queue.length) {
348
- await source?.return?.();
349
- }
345
+ if (reason !== "next" && !queue.length && !isSourceFinished) {
346
+ isSourceFinished = true;
347
+ await source?.return?.();
350
348
  }
351
349
  }
352
- ));
353
- }
350
+ );
351
+ });
354
352
  return replicated;
355
353
  }
356
354
  function asyncIteratorWithSpan({ name, ...options }, iterator) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/shared",
3
3
  "type": "module",
4
- "version": "1.8.4",
4
+ "version": "1.8.6",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -39,7 +39,7 @@
39
39
  "@opentelemetry/api": "^1.9.0",
40
40
  "arktype": "2.1.20",
41
41
  "valibot": "^1.1.0",
42
- "zod": "^4.0.17"
42
+ "zod": "^4.1.3"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "unbuild",