@orpc/client 1.10.0 → 1.10.2

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.Bi0qwEze.mjs';
3
+ import { C as CompositeStandardLinkPlugin, c as StandardRPCLink } from '../../shared/client.CSbKRiux.mjs';
4
4
  import '@orpc/standard-server';
5
- import '../../shared/client.DLfp86aF.mjs';
5
+ import '../../shared/client.CcxIdvpr.mjs';
6
6
 
7
7
  class CompositeLinkFetchPlugin extends CompositeStandardLinkPlugin {
8
8
  initRuntimeAdapter(options) {
@@ -1,8 +1,9 @@
1
+ import { Value, Promisable } from '@orpc/shared';
1
2
  import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { DecodedRequestMessage } from '@orpc/standard-server-peer';
2
4
  import { b as ClientContext, c as ClientOptions } from '../../shared/client.BH1AYT_p.mjs';
3
5
  import { f as StandardLinkClient } from '../../shared/client.CPgZaUox.mjs';
4
6
  import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.D8lMmWVC.mjs';
5
- import '@orpc/shared';
6
7
 
7
8
  /**
8
9
  * The message port used by electron in main process
@@ -11,7 +12,7 @@ interface MessagePortMainLike {
11
12
  on: <T extends string>(event: T, callback: (event?: {
12
13
  data: any;
13
14
  }) => void) => void;
14
- postMessage: (data: any) => void;
15
+ postMessage: (data: any, transfer?: any[]) => void;
15
16
  }
16
17
  /**
17
18
  * The message port used by browser extension
@@ -29,13 +30,33 @@ type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'
29
30
  /**
30
31
  * Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
31
32
  */
32
- type SupportedMessagePortData = string | ArrayBufferLike | Uint8Array;
33
- declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData): void;
33
+ type SupportedMessagePortData = any;
34
+ declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void;
34
35
  declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
35
36
  declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
36
37
 
37
38
  interface LinkMessagePortClientOptions {
38
39
  port: SupportedMessagePort;
40
+ /**
41
+ * By default, oRPC serializes request/response messages to string/binary data before sending over message port.
42
+ * If needed, you can define the this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
43
+ * such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
44
+ *
45
+ * @remarks
46
+ * - return null | undefined to disable this feature
47
+ *
48
+ * @warning Make sure your message port supports `transfer` before using this feature.
49
+ * @example
50
+ * ```ts
51
+ * experimental_transfer: (message, port) => {
52
+ * const transfer = deepFindTransferableObjects(message) // implement your own logic
53
+ * return transfer.length ? transfer : null // only enable when needed
54
+ * }
55
+ * ```
56
+ *
57
+ * @see {@link https://orpc.unnoq.com/docs/adapters/message-port#transfer Message Port Transfer Docs}
58
+ */
59
+ experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]>;
39
60
  }
40
61
  declare class LinkMessagePortClient<T extends ClientContext> implements StandardLinkClient<T> {
41
62
  private readonly peer;
@@ -1,8 +1,9 @@
1
+ import { Value, Promisable } from '@orpc/shared';
1
2
  import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { DecodedRequestMessage } from '@orpc/standard-server-peer';
2
4
  import { b as ClientContext, c as ClientOptions } from '../../shared/client.BH1AYT_p.js';
3
5
  import { f as StandardLinkClient } from '../../shared/client.De8SW4Kw.js';
4
6
  import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BxV-mzeR.js';
5
- import '@orpc/shared';
6
7
 
7
8
  /**
8
9
  * The message port used by electron in main process
@@ -11,7 +12,7 @@ interface MessagePortMainLike {
11
12
  on: <T extends string>(event: T, callback: (event?: {
12
13
  data: any;
13
14
  }) => void) => void;
14
- postMessage: (data: any) => void;
15
+ postMessage: (data: any, transfer?: any[]) => void;
15
16
  }
16
17
  /**
17
18
  * The message port used by browser extension
@@ -29,13 +30,33 @@ type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'
29
30
  /**
30
31
  * Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
31
32
  */
32
- type SupportedMessagePortData = string | ArrayBufferLike | Uint8Array;
33
- declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData): void;
33
+ type SupportedMessagePortData = any;
34
+ declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void;
34
35
  declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
35
36
  declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
36
37
 
37
38
  interface LinkMessagePortClientOptions {
38
39
  port: SupportedMessagePort;
40
+ /**
41
+ * By default, oRPC serializes request/response messages to string/binary data before sending over message port.
42
+ * If needed, you can define the this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
43
+ * such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
44
+ *
45
+ * @remarks
46
+ * - return null | undefined to disable this feature
47
+ *
48
+ * @warning Make sure your message port supports `transfer` before using this feature.
49
+ * @example
50
+ * ```ts
51
+ * experimental_transfer: (message, port) => {
52
+ * const transfer = deepFindTransferableObjects(message) // implement your own logic
53
+ * return transfer.length ? transfer : null // only enable when needed
54
+ * }
55
+ * ```
56
+ *
57
+ * @see {@link https://orpc.unnoq.com/docs/adapters/message-port#transfer Message Port Transfer Docs}
58
+ */
59
+ experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]>;
39
60
  }
40
61
  declare class LinkMessagePortClient<T extends ClientContext> implements StandardLinkClient<T> {
41
62
  private readonly peer;
@@ -1,12 +1,16 @@
1
- import { ClientPeer } from '@orpc/standard-server-peer';
2
- import '@orpc/shared';
3
- import { c as StandardRPCLink } from '../../shared/client.Bi0qwEze.mjs';
1
+ import { value, isObject } from '@orpc/shared';
2
+ import { experimental_ClientPeerWithoutCodec, serializeRequestMessage, encodeRequestMessage, deserializeResponseMessage, decodeResponseMessage } from '@orpc/standard-server-peer';
3
+ import { c as StandardRPCLink } from '../../shared/client.CSbKRiux.mjs';
4
4
  import '@orpc/standard-server';
5
- import '../../shared/client.DLfp86aF.mjs';
5
+ import '../../shared/client.CcxIdvpr.mjs';
6
6
  import '@orpc/standard-server-fetch';
7
7
 
8
- function postMessagePortMessage(port, data) {
9
- port.postMessage(data);
8
+ function postMessagePortMessage(port, data, transfer) {
9
+ if (transfer) {
10
+ port.postMessage(data, transfer);
11
+ } else {
12
+ port.postMessage(data);
13
+ }
10
14
  }
11
15
  function onMessagePortMessage(port, callback) {
12
16
  if ("addEventListener" in port) {
@@ -46,11 +50,21 @@ function onMessagePortClose(port, callback) {
46
50
  class LinkMessagePortClient {
47
51
  peer;
48
52
  constructor(options) {
49
- this.peer = new ClientPeer((message) => {
50
- return postMessagePortMessage(options.port, message);
53
+ this.peer = new experimental_ClientPeerWithoutCodec(async (message) => {
54
+ const [id, type, payload] = message;
55
+ const transfer = await value(options.experimental_transfer, message, options.port);
56
+ if (transfer) {
57
+ postMessagePortMessage(options.port, serializeRequestMessage(id, type, payload), transfer);
58
+ } else {
59
+ postMessagePortMessage(options.port, await encodeRequestMessage(id, type, payload));
60
+ }
51
61
  });
52
62
  onMessagePortMessage(options.port, async (message) => {
53
- await this.peer.message(message);
63
+ if (isObject(message)) {
64
+ await this.peer.message(deserializeResponseMessage(message));
65
+ } else {
66
+ await this.peer.message(await decodeResponseMessage(message));
67
+ }
54
68
  });
55
69
  onMessagePortClose(options.port, () => {
56
70
  this.peer.close();
@@ -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.Bi0qwEze.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.CSbKRiux.mjs';
2
2
  import '@orpc/shared';
3
3
  import '@orpc/standard-server';
4
- import '../../shared/client.DLfp86aF.mjs';
4
+ import '../../shared/client.CcxIdvpr.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.Bi0qwEze.mjs';
3
+ import { c as StandardRPCLink } from '../../shared/client.CSbKRiux.mjs';
4
4
  import '@orpc/standard-server';
5
- import '../../shared/client.DLfp86aF.mjs';
5
+ import '../../shared/client.CcxIdvpr.mjs';
6
6
  import '@orpc/standard-server-fetch';
7
7
 
8
8
  const WEBSOCKET_CONNECTING = 0;
package/dist/index.d.mts CHANGED
@@ -207,7 +207,7 @@ type SafeClient<T extends NestedClient<any>> = T extends Client<infer UContext,
207
207
  declare function createSafeClient<T extends NestedClient<any>>(client: T): SafeClient<T>;
208
208
 
209
209
  declare const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
210
- declare const ORPC_CLIENT_PACKAGE_VERSION = "1.10.0";
210
+ declare const ORPC_CLIENT_PACKAGE_VERSION = "1.10.2";
211
211
 
212
212
  /**
213
213
  * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
package/dist/index.d.ts CHANGED
@@ -207,7 +207,7 @@ type SafeClient<T extends NestedClient<any>> = T extends Client<infer UContext,
207
207
  declare function createSafeClient<T extends NestedClient<any>>(client: T): SafeClient<T>;
208
208
 
209
209
  declare const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
210
- declare const ORPC_CLIENT_PACKAGE_VERSION = "1.10.0";
210
+ declare const ORPC_CLIENT_PACKAGE_VERSION = "1.10.2";
211
211
 
212
212
  /**
213
213
  * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
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, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
3
- import { i as isDefinedError } from './shared/client.DLfp86aF.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.DLfp86aF.mjs';
3
+ import { i as isDefinedError } from './shared/client.CcxIdvpr.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.CcxIdvpr.mjs';
5
5
  export { ErrorEvent } from '@orpc/standard-server';
6
6
 
7
7
  async function safe(promise) {
@@ -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.DLfp86aF.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.CcxIdvpr.mjs';
4
4
  import { toStandardHeaders as toStandardHeaders$1 } from '@orpc/standard-server-fetch';
5
5
 
6
6
  class CompositeStandardLinkPlugin {
@@ -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.10.0";
5
+ const ORPC_CLIENT_PACKAGE_VERSION = "1.10.2";
6
6
 
7
7
  const COMMON_ORPC_ERROR_DEFS = {
8
8
  BAD_REQUEST: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
3
  "type": "module",
4
- "version": "1.10.0",
4
+ "version": "1.10.2",
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-fetch": "1.10.0",
53
- "@orpc/standard-server": "1.10.0",
54
- "@orpc/shared": "1.10.0",
55
- "@orpc/standard-server-peer": "1.10.0"
52
+ "@orpc/shared": "1.10.2",
53
+ "@orpc/standard-server": "1.10.2",
54
+ "@orpc/standard-server-fetch": "1.10.2",
55
+ "@orpc/standard-server-peer": "1.10.2"
56
56
  },
57
57
  "devDependencies": {
58
58
  "zod": "^4.1.12"