@orpc/client 1.8.7 → 1.8.8

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.
@@ -1,8 +1,8 @@
1
1
  import { toArray, intercept } from '@orpc/shared';
2
2
  import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
3
- import { C as CompositeStandardLinkPlugin, c as StandardRPCLink } from '../../shared/client.CH3WAlBG.mjs';
3
+ import { C as CompositeStandardLinkPlugin, c as StandardRPCLink } from '../../shared/client.DQ_4a8B5.mjs';
4
4
  import '@orpc/standard-server';
5
- import '../../shared/client.DO4HriUw.mjs';
5
+ import '../../shared/client.BTW8ue0g.mjs';
6
6
 
7
7
  class CompositeLinkFetchPlugin extends CompositeStandardLinkPlugin {
8
8
  initRuntimeAdapter(options) {
@@ -1,8 +1,8 @@
1
1
  import { ClientPeer } from '@orpc/standard-server-peer';
2
2
  import '@orpc/shared';
3
- import { c as StandardRPCLink } from '../../shared/client.CH3WAlBG.mjs';
3
+ import { c as StandardRPCLink } from '../../shared/client.DQ_4a8B5.mjs';
4
4
  import '@orpc/standard-server';
5
- import '../../shared/client.DO4HriUw.mjs';
5
+ import '../../shared/client.BTW8ue0g.mjs';
6
6
  import '@orpc/standard-server-fetch';
7
7
 
8
8
  function postMessagePortMessage(port, data) {
@@ -1,5 +1,5 @@
1
- export { C as CompositeStandardLinkPlugin, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLink, d as StandardRPCLinkCodec, e as StandardRPCSerializer, g as getMalformedResponseErrorCode, t as toHttpPath, f as toStandardHeaders } from '../../shared/client.CH3WAlBG.mjs';
1
+ export { C as CompositeStandardLinkPlugin, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLink, d as StandardRPCLinkCodec, e as StandardRPCSerializer, g as getMalformedResponseErrorCode, t as toHttpPath, f as toStandardHeaders } from '../../shared/client.DQ_4a8B5.mjs';
2
2
  import '@orpc/shared';
3
3
  import '@orpc/standard-server';
4
- import '../../shared/client.DO4HriUw.mjs';
4
+ import '../../shared/client.BTW8ue0g.mjs';
5
5
  import '@orpc/standard-server-fetch';
@@ -1,8 +1,8 @@
1
1
  import { readAsBuffer } from '@orpc/shared';
2
2
  import { ClientPeer } from '@orpc/standard-server-peer';
3
- import { c as StandardRPCLink } from '../../shared/client.CH3WAlBG.mjs';
3
+ import { c as StandardRPCLink } from '../../shared/client.DQ_4a8B5.mjs';
4
4
  import '@orpc/standard-server';
5
- import '../../shared/client.DO4HriUw.mjs';
5
+ import '../../shared/client.BTW8ue0g.mjs';
6
6
  import '@orpc/standard-server-fetch';
7
7
 
8
8
  const WEBSOCKET_CONNECTING = 0;
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientPromiseResult, b as ClientContext, F as FriendlyClientOptions, c as ClientOptions, d as Client, e as ClientRest } from './shared/client.BOYsZIRq.mjs';
2
2
  export { f as HTTPMethod, H as HTTPPath } from './shared/client.BOYsZIRq.mjs';
3
- import { MaybeOptionalOptions, ThrowableError, Promisable, AsyncIteratorClass } from '@orpc/shared';
3
+ import { MaybeOptionalOptions, ThrowableError, OnFinishState, Promisable, AsyncIteratorClass } from '@orpc/shared';
4
4
  export { AsyncIteratorClass, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
5
5
  export { ErrorEvent } from '@orpc/standard-server';
6
6
 
@@ -160,6 +160,35 @@ type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false
160
160
  */
161
161
  declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
162
162
  declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
163
+ interface ConsumeEventIteratorOptions<T, TReturn, TError> {
164
+ /**
165
+ * Called on each event
166
+ */
167
+ onEvent: (event: T) => void;
168
+ /**
169
+ * Called once error happens
170
+ */
171
+ onError?: (error: TError) => void;
172
+ /**
173
+ * Called once event iterator is done
174
+ *
175
+ * @info If iterator is canceled, `undefined` can be passed on success
176
+ */
177
+ onSuccess?: (value: TReturn | undefined) => void;
178
+ /**
179
+ * Called once after onError or onSuccess
180
+ *
181
+ * @info If iterator is canceled, `undefined` can be passed on success
182
+ */
183
+ onFinish?: (state: OnFinishState<TReturn | undefined, TError>) => void;
184
+ }
185
+ /**
186
+ * Consumes an event iterator with lifecycle callbacks
187
+ *
188
+ * @warning If no `onError` or `onFinish` is provided, unhandled rejections will be thrown
189
+ * @return unsubscribe callback
190
+ */
191
+ declare function consumeEventIterator<T, TReturn, TError = ThrowableError>(iterator: AsyncIterator<T, TReturn> | ClientPromiseResult<AsyncIterator<T, TReturn>, TError>, options: ConsumeEventIteratorOptions<T, TReturn, TError>): () => Promise<void>;
163
192
 
164
193
  type SafeClient<T extends NestedClient<any>> = T extends Client<infer UContext, infer UInput, infer UOutput, infer UError> ? (...rest: ClientRest<UContext, UInput>) => Promise<SafeResult<UOutput, UError>> : {
165
194
  [K in keyof T]: T[K] extends NestedClient<any> ? SafeClient<T[K]> : never;
@@ -178,7 +207,7 @@ type SafeClient<T extends NestedClient<any>> = T extends Client<infer UContext,
178
207
  declare function createSafeClient<T extends NestedClient<any>>(client: T): SafeClient<T>;
179
208
 
180
209
  declare const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
181
- declare const ORPC_CLIENT_PACKAGE_VERSION = "1.8.7";
210
+ declare const ORPC_CLIENT_PACKAGE_VERSION = "1.8.8";
182
211
 
183
212
  /**
184
213
  * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
@@ -197,5 +226,5 @@ declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TRetur
197
226
  error: (error: unknown) => Promise<unknown>;
198
227
  }): AsyncIteratorClass<TMap, TMap, TNext>;
199
228
 
200
- export { COMMON_ORPC_ERROR_DEFS, Client, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, ORPC_CLIENT_PACKAGE_NAME, ORPC_CLIENT_PACKAGE_VERSION, createORPCClient, createORPCErrorFromJson, createSafeClient, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorJson, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
201
- export type { CommonORPCErrorCode, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, SafeClient, SafeResult, createORPCClientOptions };
229
+ export { COMMON_ORPC_ERROR_DEFS, Client, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, ORPC_CLIENT_PACKAGE_NAME, ORPC_CLIENT_PACKAGE_VERSION, consumeEventIterator, createORPCClient, createORPCErrorFromJson, createSafeClient, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorJson, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
230
+ export type { CommonORPCErrorCode, ConsumeEventIteratorOptions, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, SafeClient, SafeResult, createORPCClientOptions };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientPromiseResult, b as ClientContext, F as FriendlyClientOptions, c as ClientOptions, d as Client, e as ClientRest } from './shared/client.BOYsZIRq.js';
2
2
  export { f as HTTPMethod, H as HTTPPath } from './shared/client.BOYsZIRq.js';
3
- import { MaybeOptionalOptions, ThrowableError, Promisable, AsyncIteratorClass } from '@orpc/shared';
3
+ import { MaybeOptionalOptions, ThrowableError, OnFinishState, Promisable, AsyncIteratorClass } from '@orpc/shared';
4
4
  export { AsyncIteratorClass, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
5
5
  export { ErrorEvent } from '@orpc/standard-server';
6
6
 
@@ -160,6 +160,35 @@ type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false
160
160
  */
161
161
  declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
162
162
  declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
163
+ interface ConsumeEventIteratorOptions<T, TReturn, TError> {
164
+ /**
165
+ * Called on each event
166
+ */
167
+ onEvent: (event: T) => void;
168
+ /**
169
+ * Called once error happens
170
+ */
171
+ onError?: (error: TError) => void;
172
+ /**
173
+ * Called once event iterator is done
174
+ *
175
+ * @info If iterator is canceled, `undefined` can be passed on success
176
+ */
177
+ onSuccess?: (value: TReturn | undefined) => void;
178
+ /**
179
+ * Called once after onError or onSuccess
180
+ *
181
+ * @info If iterator is canceled, `undefined` can be passed on success
182
+ */
183
+ onFinish?: (state: OnFinishState<TReturn | undefined, TError>) => void;
184
+ }
185
+ /**
186
+ * Consumes an event iterator with lifecycle callbacks
187
+ *
188
+ * @warning If no `onError` or `onFinish` is provided, unhandled rejections will be thrown
189
+ * @return unsubscribe callback
190
+ */
191
+ declare function consumeEventIterator<T, TReturn, TError = ThrowableError>(iterator: AsyncIterator<T, TReturn> | ClientPromiseResult<AsyncIterator<T, TReturn>, TError>, options: ConsumeEventIteratorOptions<T, TReturn, TError>): () => Promise<void>;
163
192
 
164
193
  type SafeClient<T extends NestedClient<any>> = T extends Client<infer UContext, infer UInput, infer UOutput, infer UError> ? (...rest: ClientRest<UContext, UInput>) => Promise<SafeResult<UOutput, UError>> : {
165
194
  [K in keyof T]: T[K] extends NestedClient<any> ? SafeClient<T[K]> : never;
@@ -178,7 +207,7 @@ type SafeClient<T extends NestedClient<any>> = T extends Client<infer UContext,
178
207
  declare function createSafeClient<T extends NestedClient<any>>(client: T): SafeClient<T>;
179
208
 
180
209
  declare const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
181
- declare const ORPC_CLIENT_PACKAGE_VERSION = "1.8.7";
210
+ declare const ORPC_CLIENT_PACKAGE_VERSION = "1.8.8";
182
211
 
183
212
  /**
184
213
  * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
@@ -197,5 +226,5 @@ declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TRetur
197
226
  error: (error: unknown) => Promise<unknown>;
198
227
  }): AsyncIteratorClass<TMap, TMap, TNext>;
199
228
 
200
- export { COMMON_ORPC_ERROR_DEFS, Client, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, ORPC_CLIENT_PACKAGE_NAME, ORPC_CLIENT_PACKAGE_VERSION, createORPCClient, createORPCErrorFromJson, createSafeClient, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorJson, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
201
- export type { CommonORPCErrorCode, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, SafeClient, SafeResult, createORPCClientOptions };
229
+ export { COMMON_ORPC_ERROR_DEFS, Client, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, ORPC_CLIENT_PACKAGE_NAME, ORPC_CLIENT_PACKAGE_VERSION, consumeEventIterator, createORPCClient, createORPCErrorFromJson, createSafeClient, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorJson, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
230
+ export type { CommonORPCErrorCode, ConsumeEventIteratorOptions, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, SafeClient, SafeResult, createORPCClientOptions };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { preventNativeAwait, isTypescriptObject } from '@orpc/shared';
2
2
  export { AsyncIteratorClass, EventPublisher, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
3
- import { i as isDefinedError } from './shared/client.DO4HriUw.mjs';
4
- export { C as COMMON_ORPC_ERROR_DEFS, c as ORPCError, O as ORPC_CLIENT_PACKAGE_NAME, a as ORPC_CLIENT_PACKAGE_VERSION, g as createORPCErrorFromJson, b as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, e as isORPCErrorJson, d as isORPCErrorStatus, m as mapEventIterator, t as toORPCError } from './shared/client.DO4HriUw.mjs';
3
+ import { i as isDefinedError } from './shared/client.BTW8ue0g.mjs';
4
+ export { C as COMMON_ORPC_ERROR_DEFS, c as ORPCError, O as ORPC_CLIENT_PACKAGE_NAME, a as ORPC_CLIENT_PACKAGE_VERSION, g as createORPCErrorFromJson, b as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, e as isORPCErrorJson, d as isORPCErrorStatus, m as mapEventIterator, t as toORPCError } from './shared/client.BTW8ue0g.mjs';
5
5
  export { ErrorEvent } from '@orpc/standard-server';
6
6
 
7
7
  async function safe(promise) {
@@ -32,6 +32,35 @@ function resolveFriendlyClientOptions(options) {
32
32
  // Context only optional if all fields are optional
33
33
  };
34
34
  }
35
+ function consumeEventIterator(iterator, options) {
36
+ void (async () => {
37
+ let onFinishState;
38
+ try {
39
+ const resolvedIterator = await iterator;
40
+ while (true) {
41
+ const { done, value } = await resolvedIterator.next();
42
+ if (done) {
43
+ const realValue = value;
44
+ onFinishState = [null, realValue, true];
45
+ options.onSuccess?.(realValue);
46
+ break;
47
+ }
48
+ options.onEvent(value);
49
+ }
50
+ } catch (error) {
51
+ onFinishState = [error, void 0, false];
52
+ if (!options.onError && !options.onFinish) {
53
+ throw error;
54
+ }
55
+ options.onError?.(error);
56
+ } finally {
57
+ options.onFinish?.(onFinishState);
58
+ }
59
+ })();
60
+ return async () => {
61
+ await (await iterator)?.return?.();
62
+ };
63
+ }
35
64
 
36
65
  function createORPCClient(link, options = {}) {
37
66
  const path = options.path ?? [];
@@ -79,4 +108,4 @@ class DynamicLink {
79
108
  }
80
109
  }
81
110
 
82
- export { DynamicLink, createORPCClient, createSafeClient, isDefinedError, resolveFriendlyClientOptions, safe };
111
+ export { DynamicLink, consumeEventIterator, createORPCClient, createSafeClient, isDefinedError, resolveFriendlyClientOptions, safe };
@@ -2,7 +2,7 @@ import { resolveMaybeOptionalOptions, getConstructor, isObject, AsyncIteratorCla
2
2
  import { getEventMeta, withEventMeta } from '@orpc/standard-server';
3
3
 
4
4
  const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
5
- const ORPC_CLIENT_PACKAGE_VERSION = "1.8.7";
5
+ const ORPC_CLIENT_PACKAGE_VERSION = "1.8.8";
6
6
 
7
7
  const COMMON_ORPC_ERROR_DEFS = {
8
8
  BAD_REQUEST: {
@@ -1,6 +1,6 @@
1
1
  import { toArray, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, intercept, getGlobalOtelConfig, isObject, value, stringifyJSON } from '@orpc/shared';
2
2
  import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
3
- import { C as COMMON_ORPC_ERROR_DEFS, d as isORPCErrorStatus, e as isORPCErrorJson, g as createORPCErrorFromJson, c as ORPCError, m as mapEventIterator, t as toORPCError } from './client.DO4HriUw.mjs';
3
+ import { C as COMMON_ORPC_ERROR_DEFS, d as isORPCErrorStatus, e as isORPCErrorJson, g as createORPCErrorFromJson, c as ORPCError, m as mapEventIterator, t as toORPCError } from './client.BTW8ue0g.mjs';
4
4
  import { toStandardHeaders as toStandardHeaders$1 } from '@orpc/standard-server-fetch';
5
5
 
6
6
  class CompositeStandardLinkPlugin {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
3
  "type": "module",
4
- "version": "1.8.7",
4
+ "version": "1.8.8",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -49,10 +49,10 @@
49
49
  "dist"
50
50
  ],
51
51
  "dependencies": {
52
- "@orpc/standard-server": "1.8.7",
53
- "@orpc/standard-server-fetch": "1.8.7",
54
- "@orpc/shared": "1.8.7",
55
- "@orpc/standard-server-peer": "1.8.7"
52
+ "@orpc/shared": "1.8.8",
53
+ "@orpc/standard-server-fetch": "1.8.8",
54
+ "@orpc/standard-server": "1.8.8",
55
+ "@orpc/standard-server-peer": "1.8.8"
56
56
  },
57
57
  "devDependencies": {
58
58
  "zod": "^4.1.5"