@orpc/shared 0.0.0-next.e710b76 → 0.0.0-next.e788265

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
@@ -8,6 +8,13 @@ declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>):
8
8
  declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
9
9
  declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
10
10
 
11
+ /**
12
+ * Converts Request/Response/Blob/File/.. to a buffer (ArrayBuffer or Uint8Array).
13
+ *
14
+ * Prefers the newer `.bytes` method when available as it more efficient but not widely supported yet.
15
+ */
16
+ declare function readAsBuffer(source: Pick<Blob, 'arrayBuffer' | 'bytes'>): Promise<ArrayBuffer | Uint8Array>;
17
+
11
18
  type AnyFunction = (...args: any[]) => any;
12
19
  declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
13
20
  declare function sequential<A extends any[], R>(fn: (...args: A) => Promise<R>): (...args: A) => Promise<R>;
@@ -178,7 +185,7 @@ declare function isObject(value: unknown): value is Record<PropertyKey, unknown>
178
185
  */
179
186
  declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
180
187
  declare function clone<T>(value: T): T;
181
- declare function get(object: object, path: readonly string[]): unknown;
188
+ declare function get(object: unknown, path: readonly string[]): unknown;
182
189
  declare function isPropertyKey(value: unknown): value is PropertyKey;
183
190
  declare const NullProtoObj: ({
184
191
  new <T extends Record<PropertyKey, unknown>>(): T;
@@ -201,8 +208,11 @@ declare class AsyncIdQueue<T> {
201
208
  assertOpen(id: string): void;
202
209
  }
203
210
 
211
+ declare function streamToAsyncIteratorClass<T>(stream: ReadableStream<T>): AsyncIteratorClass<T>;
212
+ declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
213
+
204
214
  type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
205
215
  declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
206
216
 
207
- export { AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, SequentialIdGenerator, clone, defer, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, replicateAsyncIterator, resolveMaybeOptionalOptions, sequential, splitInHalf, stringifyJSON, toArray, value };
217
+ export { AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, SequentialIdGenerator, asyncIteratorToStream, clone, defer, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, sequential, splitInHalf, streamToAsyncIteratorClass, stringifyJSON, toArray, value };
208
218
  export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OmitChainMethodDeep, OnFinishState, PromiseWithError, Registry, Segment, SetOptional, ThrowableError, Value };
package/dist/index.d.ts CHANGED
@@ -8,6 +8,13 @@ declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>):
8
8
  declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
9
9
  declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
10
10
 
11
+ /**
12
+ * Converts Request/Response/Blob/File/.. to a buffer (ArrayBuffer or Uint8Array).
13
+ *
14
+ * Prefers the newer `.bytes` method when available as it more efficient but not widely supported yet.
15
+ */
16
+ declare function readAsBuffer(source: Pick<Blob, 'arrayBuffer' | 'bytes'>): Promise<ArrayBuffer | Uint8Array>;
17
+
11
18
  type AnyFunction = (...args: any[]) => any;
12
19
  declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
13
20
  declare function sequential<A extends any[], R>(fn: (...args: A) => Promise<R>): (...args: A) => Promise<R>;
@@ -178,7 +185,7 @@ declare function isObject(value: unknown): value is Record<PropertyKey, unknown>
178
185
  */
179
186
  declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
180
187
  declare function clone<T>(value: T): T;
181
- declare function get(object: object, path: readonly string[]): unknown;
188
+ declare function get(object: unknown, path: readonly string[]): unknown;
182
189
  declare function isPropertyKey(value: unknown): value is PropertyKey;
183
190
  declare const NullProtoObj: ({
184
191
  new <T extends Record<PropertyKey, unknown>>(): T;
@@ -201,8 +208,11 @@ declare class AsyncIdQueue<T> {
201
208
  assertOpen(id: string): void;
202
209
  }
203
210
 
211
+ declare function streamToAsyncIteratorClass<T>(stream: ReadableStream<T>): AsyncIteratorClass<T>;
212
+ declare function asyncIteratorToStream<T>(iterator: AsyncIterator<T>): ReadableStream<T>;
213
+
204
214
  type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
205
215
  declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
206
216
 
207
- export { AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, SequentialIdGenerator, clone, defer, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, replicateAsyncIterator, resolveMaybeOptionalOptions, sequential, splitInHalf, stringifyJSON, toArray, value };
217
+ export { AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, SequentialIdGenerator, asyncIteratorToStream, clone, defer, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, sequential, splitInHalf, streamToAsyncIteratorClass, stringifyJSON, toArray, value };
208
218
  export type { AnyFunction, AsyncIdQueueCloseOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClassNextFn, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OmitChainMethodDeep, OnFinishState, PromiseWithError, Registry, Segment, SetOptional, ThrowableError, Value };
package/dist/index.mjs CHANGED
@@ -12,6 +12,13 @@ function splitInHalf(arr) {
12
12
  return [arr.slice(0, half), arr.slice(half)];
13
13
  }
14
14
 
15
+ function readAsBuffer(source) {
16
+ if (typeof source.bytes === "function") {
17
+ return source.bytes();
18
+ }
19
+ return source.arrayBuffer();
20
+ }
21
+
15
22
  function once(fn) {
16
23
  let cached;
17
24
  return () => {
@@ -120,7 +127,7 @@ function isAsyncIteratorObject(maybe) {
120
127
  if (!maybe || typeof maybe !== "object") {
121
128
  return false;
122
129
  }
123
- return Symbol.asyncIterator in maybe && typeof maybe[Symbol.asyncIterator] === "function";
130
+ return "next" in maybe && typeof maybe.next === "function" && Symbol.asyncIterator in maybe && typeof maybe[Symbol.asyncIterator] === "function";
124
131
  }
125
132
  const fallbackAsyncDisposeSymbol = Symbol.for("asyncDispose");
126
133
  const asyncDisposeSymbol = Symbol.asyncDispose ?? fallbackAsyncDisposeSymbol;
@@ -442,6 +449,33 @@ const NullProtoObj = /* @__PURE__ */ (() => {
442
449
  return e;
443
450
  })();
444
451
 
452
+ function streamToAsyncIteratorClass(stream) {
453
+ const reader = stream.getReader();
454
+ return new AsyncIteratorClass(
455
+ async () => {
456
+ return reader.read();
457
+ },
458
+ async () => {
459
+ await reader.cancel();
460
+ }
461
+ );
462
+ }
463
+ function asyncIteratorToStream(iterator) {
464
+ return new ReadableStream({
465
+ async pull(controller) {
466
+ const { done, value } = await iterator.next();
467
+ if (done) {
468
+ controller.close();
469
+ } else {
470
+ controller.enqueue(value);
471
+ }
472
+ },
473
+ async cancel() {
474
+ await iterator.return?.();
475
+ }
476
+ });
477
+ }
478
+
445
479
  function value(value2, ...args) {
446
480
  if (typeof value2 === "function") {
447
481
  return value2(...args);
@@ -449,4 +483,4 @@ function value(value2, ...args) {
449
483
  return value2;
450
484
  }
451
485
 
452
- export { AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, SequentialIdGenerator, clone, defer, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, replicateAsyncIterator, resolveMaybeOptionalOptions, sequential, splitInHalf, stringifyJSON, toArray, value };
486
+ export { AsyncIdQueue, AsyncIteratorClass, EventPublisher, NullProtoObj, SequentialIdGenerator, asyncIteratorToStream, clone, defer, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isPropertyKey, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, readAsBuffer, replicateAsyncIterator, resolveMaybeOptionalOptions, sequential, splitInHalf, streamToAsyncIteratorClass, stringifyJSON, toArray, 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.e710b76",
4
+ "version": "0.0.0-next.e788265",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -30,7 +30,7 @@
30
30
  "devDependencies": {
31
31
  "arktype": "2.1.20",
32
32
  "valibot": "^1.1.0",
33
- "zod": "^3.25.67"
33
+ "zod": "^4.0.5"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "unbuild",