@orpc/client 2.0.0-beta.5 → 2.0.0-beta.51

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.
Files changed (94) hide show
  1. package/README.md +139 -102
  2. package/dist/adapters/fetch/index.d.ts +3 -65
  3. package/dist/adapters/fetch/index.js +2 -0
  4. package/dist/adapters/fetch/rpc-link.d.ts +14 -0
  5. package/dist/adapters/fetch/rpc-link.js +17 -0
  6. package/dist/adapters/fetch/transport.d.ts +32 -0
  7. package/dist/adapters/fetch/transport.js +51 -0
  8. package/dist/adapters/message-port/index.d.ts +4 -75
  9. package/dist/adapters/message-port/index.js +3 -0
  10. package/dist/adapters/message-port/message-port.d.ts +29 -0
  11. package/dist/adapters/message-port/message-port.js +38 -0
  12. package/dist/adapters/message-port/rpc-link.d.ts +15 -0
  13. package/dist/adapters/message-port/rpc-link.js +18 -0
  14. package/dist/adapters/message-port/transport.d.ts +35 -0
  15. package/dist/adapters/message-port/transport.js +38 -0
  16. package/dist/adapters/standard/codec.d.ts +14 -0
  17. package/dist/adapters/standard/index.d.ts +6 -61
  18. package/dist/adapters/standard/index.js +2 -0
  19. package/dist/adapters/standard/link.d.ts +40 -0
  20. package/dist/adapters/standard/link.js +101 -0
  21. package/dist/adapters/standard/plugin.d.ts +26 -0
  22. package/dist/adapters/standard/plugin.js +14 -0
  23. package/dist/adapters/standard/rpc-link-codec.d.ts +56 -0
  24. package/dist/adapters/standard/rpc-link-codec.js +100 -0
  25. package/dist/adapters/standard/transport.d.ts +14 -0
  26. package/dist/adapters/websocket/index.d.ts +3 -121
  27. package/dist/adapters/websocket/index.js +2 -0
  28. package/dist/adapters/websocket/rpc-link.d.ts +14 -0
  29. package/dist/adapters/websocket/rpc-link.js +17 -0
  30. package/dist/adapters/websocket/transport.d.ts +116 -0
  31. package/dist/adapters/websocket/transport.js +105 -0
  32. package/dist/async-iterator-object.d.ts +2 -0
  33. package/dist/async-iterator-object.js +28 -0
  34. package/dist/client-safe.d.ts +17 -0
  35. package/dist/client-safe.js +31 -0
  36. package/dist/client.d.ts +39 -0
  37. package/dist/client.js +37 -0
  38. package/dist/consts.d.ts +10 -0
  39. package/dist/consts.js +20 -0
  40. package/dist/dynamic-link.d.ts +13 -0
  41. package/dist/dynamic-link.js +17 -0
  42. package/dist/error-utils.d.ts +20 -0
  43. package/dist/error-utils.js +54 -0
  44. package/dist/error.d.ts +141 -0
  45. package/dist/error.js +166 -0
  46. package/dist/index.d.ts +14 -155
  47. package/dist/index.js +12 -0
  48. package/dist/plugins/batch.d.ts +152 -0
  49. package/dist/plugins/batch.js +330 -0
  50. package/dist/plugins/cookie-jar.d.ts +85 -0
  51. package/dist/plugins/cookie-jar.js +231 -0
  52. package/dist/plugins/dedupe.d.ts +60 -0
  53. package/dist/plugins/dedupe.js +183 -0
  54. package/dist/plugins/index.d.ts +9 -242
  55. package/dist/plugins/index.js +8 -0
  56. package/dist/plugins/request-compression.d.ts +47 -0
  57. package/dist/plugins/request-compression.js +132 -0
  58. package/dist/plugins/response-compression.d.ts +31 -0
  59. package/dist/plugins/response-compression.js +67 -0
  60. package/dist/plugins/retry-after.d.ts +43 -0
  61. package/dist/plugins/retry-after.js +63 -0
  62. package/dist/plugins/retry.d.ts +84 -0
  63. package/dist/plugins/retry.js +121 -0
  64. package/dist/plugins/timeout.d.ts +27 -0
  65. package/dist/plugins/timeout.js +42 -0
  66. package/dist/rpc-json-serializer.d.ts +99 -0
  67. package/dist/rpc-json-serializer.js +347 -0
  68. package/dist/rpc-serializer.d.ts +31 -0
  69. package/dist/rpc-serializer.js +102 -0
  70. package/dist/types.d.ts +91 -0
  71. package/dist/utils.d.ts +36 -0
  72. package/dist/utils.js +67 -0
  73. package/package.json +47 -35
  74. package/dist/adapters/fetch/index.d.mts +0 -65
  75. package/dist/adapters/fetch/index.mjs +0 -68
  76. package/dist/adapters/message-port/index.d.mts +0 -75
  77. package/dist/adapters/message-port/index.mjs +0 -91
  78. package/dist/adapters/standard/index.d.mts +0 -61
  79. package/dist/adapters/standard/index.mjs +0 -6
  80. package/dist/adapters/websocket/index.d.mts +0 -121
  81. package/dist/adapters/websocket/index.mjs +0 -110
  82. package/dist/index.d.mts +0 -155
  83. package/dist/index.mjs +0 -154
  84. package/dist/plugins/index.d.mts +0 -242
  85. package/dist/plugins/index.mjs +0 -574
  86. package/dist/shared/client.8ug8I-zu.d.mts +0 -167
  87. package/dist/shared/client.8ug8I-zu.d.ts +0 -167
  88. package/dist/shared/client.BdItY5DT.d.mts +0 -111
  89. package/dist/shared/client.BdItY5DT.d.ts +0 -111
  90. package/dist/shared/client.CPF3hX6O.d.ts +0 -96
  91. package/dist/shared/client.Cby_-GGh.d.mts +0 -96
  92. package/dist/shared/client.DMXKFDyV.mjs +0 -343
  93. package/dist/shared/client.DXhchJ84.mjs +0 -174
  94. package/dist/shared/client.Dnfj8jnT.mjs +0 -92
package/package.json CHANGED
@@ -1,65 +1,77 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
- "type": "module",
4
- "version": "2.0.0-beta.5",
5
- "license": "MIT",
3
+ "version": "2.0.0-beta.51",
4
+ "description": "Consume oRPC and OpenAPI APIs with end-to-end type safety over HTTP, WebSocket, or message ports",
5
+ "keywords": [
6
+ "api",
7
+ "client",
8
+ "fetch",
9
+ "openapi",
10
+ "orpc",
11
+ "rpc",
12
+ "typesafe",
13
+ "typescript",
14
+ "websocket"
15
+ ],
6
16
  "homepage": "https://orpc.dev",
17
+ "license": "MIT",
7
18
  "repository": {
8
19
  "type": "git",
9
20
  "url": "git+https://github.com/middleapi/orpc.git",
10
21
  "directory": "packages/client"
11
22
  },
12
- "keywords": [
13
- "orpc"
23
+ "funding": [
24
+ "https://github.com/sponsors/dinwwwh",
25
+ "https://opencollective.com/middleapi"
14
26
  ],
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "type": "module",
15
31
  "sideEffects": false,
16
32
  "exports": {
17
33
  "./package.json": "./package.json",
18
34
  ".": {
19
- "types": "./dist/index.d.mts",
20
- "import": "./dist/index.mjs",
21
- "default": "./dist/index.mjs"
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.js",
37
+ "default": "./dist/index.js"
22
38
  },
23
39
  "./plugins": {
24
- "types": "./dist/plugins/index.d.mts",
25
- "import": "./dist/plugins/index.mjs",
26
- "default": "./dist/plugins/index.mjs"
40
+ "types": "./dist/plugins/index.d.ts",
41
+ "import": "./dist/plugins/index.js",
42
+ "default": "./dist/plugins/index.js"
27
43
  },
28
44
  "./standard": {
29
- "types": "./dist/adapters/standard/index.d.mts",
30
- "import": "./dist/adapters/standard/index.mjs",
31
- "default": "./dist/adapters/standard/index.mjs"
45
+ "types": "./dist/adapters/standard/index.d.ts",
46
+ "import": "./dist/adapters/standard/index.js",
47
+ "default": "./dist/adapters/standard/index.js"
32
48
  },
33
49
  "./fetch": {
34
- "types": "./dist/adapters/fetch/index.d.mts",
35
- "import": "./dist/adapters/fetch/index.mjs",
36
- "default": "./dist/adapters/fetch/index.mjs"
50
+ "types": "./dist/adapters/fetch/index.d.ts",
51
+ "import": "./dist/adapters/fetch/index.js",
52
+ "default": "./dist/adapters/fetch/index.js"
37
53
  },
38
54
  "./websocket": {
39
- "types": "./dist/adapters/websocket/index.d.mts",
40
- "import": "./dist/adapters/websocket/index.mjs",
41
- "default": "./dist/adapters/websocket/index.mjs"
55
+ "types": "./dist/adapters/websocket/index.d.ts",
56
+ "import": "./dist/adapters/websocket/index.js",
57
+ "default": "./dist/adapters/websocket/index.js"
42
58
  },
43
59
  "./message-port": {
44
- "types": "./dist/adapters/message-port/index.d.mts",
45
- "import": "./dist/adapters/message-port/index.mjs",
46
- "default": "./dist/adapters/message-port/index.mjs"
60
+ "types": "./dist/adapters/message-port/index.d.ts",
61
+ "import": "./dist/adapters/message-port/index.js",
62
+ "default": "./dist/adapters/message-port/index.js"
47
63
  }
48
64
  },
49
- "files": [
50
- "dist"
51
- ],
52
65
  "dependencies": {
53
- "@standardserver/core": "^0.0.25",
54
- "@standardserver/fetch": "^0.0.25",
55
- "@standardserver/peer": "^0.0.25",
56
- "@orpc/shared": "2.0.0-beta.5"
66
+ "@orpc/shared": "2.0.0-beta.51",
67
+ "@standard-server/core": "~0.16.0",
68
+ "@standard-server/fetch": "~0.16.0",
69
+ "@standard-server/peer": "~0.16.0"
57
70
  },
58
71
  "devDependencies": {
59
- "zod": "^4.4.3"
72
+ "@types/ws": "^8.18.2",
73
+ "ws": "^8.22.1",
74
+ "zod": "^4.6.7"
60
75
  },
61
- "scripts": {
62
- "build": "unbuild",
63
- "type:check": "tsc -b"
64
- }
76
+ "scripts": {}
65
77
  }
@@ -1,65 +0,0 @@
1
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
2
- import { Value, Promisable, Interceptor } from '@orpc/shared';
3
- import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
4
- import { ToFetchBodyOptions } from '@standardserver/fetch';
5
- import { S as StandardLinkTransport, c as StandardLinkPlugin, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.Cby_-GGh.mjs';
6
- import { RPCLinkCodecOptions } from '../standard/index.mjs';
7
- import '../../shared/client.BdItY5DT.mjs';
8
-
9
- interface FetchLinkTransportFetchInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
10
- path: string[];
11
- url: string;
12
- init: RequestInit;
13
- }
14
- type FetchLinkTransportFetchInterceptor<T extends ClientContext> = Interceptor<FetchLinkTransportFetchInterceptorOptions<T>, Promise<Response>>;
15
- interface FetchLinkTransportOptions<T extends ClientContext> {
16
- /**
17
- * The origin to prepend to all request URLs, useful for CORS requests.
18
- *
19
- * @example 'https://api.example.com'
20
- * @example 'http://localhost:3000'
21
- */
22
- origin?: Value<Promisable<`https://${string}` | `http://${string}` | ({} & string) | undefined>, [options: ClientOptions<T>, path: string[]]>;
23
- /**
24
- * Options for how to convert the Standard Request to a Fetch Request, like event iterator options, etc.
25
- */
26
- toFetchRequest?: undefined | ToFetchBodyOptions;
27
- /**
28
- * Override the default fetch implementation.
29
- *
30
- * @default globalThis.fetch.bind(globalThis)
31
- */
32
- fetch?(url: string, init: RequestInit, options: ClientOptions<T>, path: string[]): Promise<Response>;
33
- /**
34
- * Interceptors that execute before the actual fetch call, useful for modifying the fetch parameters, adding logging, etc.
35
- */
36
- fetchInterceptors?: FetchLinkTransportFetchInterceptor<T>[];
37
- plugins?: FetchLinkTransportPlugin<T>[];
38
- }
39
- declare class FetchLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
40
- private readonly origin;
41
- private readonly fetch;
42
- private readonly toFetchRequestOptions;
43
- private readonly fetchInterceptors;
44
- constructor(options: FetchLinkTransportOptions<T>);
45
- send(standardRequest: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>;
46
- }
47
-
48
- interface FetchLinkTransportPlugin<T extends ClientContext> extends StandardLinkPlugin<T> {
49
- initFetchLinkTransportOptions?(options: FetchLinkTransportOptions<T>): FetchLinkTransportOptions<T>;
50
- }
51
- declare class CompositeFetchLinkTransportPlugin<T extends ClientContext> implements FetchLinkTransportPlugin<T> {
52
- protected readonly plugins: FetchLinkTransportPlugin<T>[];
53
- name: string;
54
- constructor(plugins?: FetchLinkTransportPlugin<T>[]);
55
- initFetchLinkTransportOptions(options: FetchLinkTransportOptions<T>): FetchLinkTransportOptions<T>;
56
- }
57
-
58
- interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardLinkOptions<T>, 'plugins'>, FetchLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
59
- }
60
- declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
61
- constructor(options: RPCLinkOptions<T>);
62
- }
63
-
64
- export { CompositeFetchLinkTransportPlugin, FetchLinkTransport, RPCLink };
65
- export type { FetchLinkTransportFetchInterceptor, FetchLinkTransportFetchInterceptorOptions, FetchLinkTransportOptions, FetchLinkTransportPlugin, RPCLinkOptions };
@@ -1,68 +0,0 @@
1
- import { sortPlugins, value, intercept } from '@orpc/shared';
2
- import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from '@standardserver/fetch';
3
- import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.DXhchJ84.mjs';
4
- import '@standardserver/core';
5
- import '../../shared/client.Dnfj8jnT.mjs';
6
- import '../../shared/client.DMXKFDyV.mjs';
7
-
8
- class CompositeFetchLinkTransportPlugin {
9
- constructor(plugins = []) {
10
- this.plugins = plugins;
11
- this.plugins = sortPlugins(plugins);
12
- }
13
- name = "~composite/fetch-link-transport";
14
- initFetchLinkTransportOptions(options) {
15
- for (const plugin of this.plugins) {
16
- if (plugin.initFetchLinkTransportOptions) {
17
- options = plugin.initFetchLinkTransportOptions(options);
18
- }
19
- }
20
- return options;
21
- }
22
- }
23
-
24
- class FetchLinkTransport {
25
- origin;
26
- fetch;
27
- toFetchRequestOptions;
28
- fetchInterceptors;
29
- constructor(options) {
30
- options = new CompositeFetchLinkTransportPlugin(options.plugins).initFetchLinkTransportOptions(options);
31
- this.origin = options.origin;
32
- this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
33
- this.toFetchRequestOptions = options.toFetchRequest;
34
- this.fetchInterceptors = options.fetchInterceptors;
35
- }
36
- async send(standardRequest, path, options) {
37
- let origin = await value(this.origin, options, path);
38
- if (origin?.endsWith("/")) {
39
- origin = origin.slice(0, -1);
40
- }
41
- const url = `${origin ?? ""}${standardRequest.url}`;
42
- const [body, standardHeaders] = toFetchBody(standardRequest.body, standardRequest.headers, this.toFetchRequestOptions);
43
- const init = {
44
- body,
45
- headers: toFetchHeaders(standardHeaders),
46
- method: standardRequest.method,
47
- signal: options.signal,
48
- redirect: "manual"
49
- };
50
- const response = await intercept(
51
- this.fetchInterceptors,
52
- { ...options, url, path, init },
53
- ({ url: url2, path: path2, init: init2, ...options2 }) => this.fetch(url2, init2, options2, path2)
54
- );
55
- const standardResponse = toStandardLazyResponse(response);
56
- return standardResponse;
57
- }
58
- }
59
-
60
- class RPCLink extends StandardLink {
61
- constructor(options) {
62
- const codec = new RPCLinkCodec(options);
63
- const transport = new FetchLinkTransport(options);
64
- super(codec, transport, options);
65
- }
66
- }
67
-
68
- export { CompositeFetchLinkTransportPlugin, FetchLinkTransport, RPCLink };
@@ -1,75 +0,0 @@
1
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
2
- import { Value, Promisable } from '@orpc/shared';
3
- import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
4
- import { ClientPeer, EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
5
- import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.Cby_-GGh.mjs';
6
- import { RPCLinkCodecOptions } from '../standard/index.mjs';
7
- import '../../shared/client.BdItY5DT.mjs';
8
-
9
- /**
10
- * The message port used by electron in main process
11
- */
12
- interface MessagePortMainLike {
13
- on: <T extends string>(event: T, callback: (event?: {
14
- data: any;
15
- }) => void) => void;
16
- postMessage: (data: any, transfer?: any[]) => void;
17
- }
18
- /**
19
- * The message port used by browser extension
20
- */
21
- interface BrowserPortLike {
22
- onMessage: {
23
- addListener: (callback: (data: any) => void) => void;
24
- };
25
- onDisconnect: {
26
- addListener: (callback: () => void) => void;
27
- };
28
- postMessage: (data: any) => void;
29
- }
30
- type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'> | MessagePortMainLike | BrowserPortLike;
31
- /**
32
- * Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
33
- */
34
- type SupportedMessagePortData = any;
35
- declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void;
36
- declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
37
- declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
38
-
39
- type DecodedRequestMessage = ConstructorParameters<typeof ClientPeer>[0] extends (message: infer TMessage) => unknown ? TMessage : never;
40
- interface MessagePortLinkTransportOptions<_T extends ClientContext> {
41
- port: SupportedMessagePort;
42
- /**
43
- * By default, oRPC serializes request/response messages to string/binary data before sending over message port.
44
- * If needed, define this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
45
- * such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
46
- *
47
- * @remarks
48
- * - return null | undefined to disable this feature
49
- *
50
- * @warning Make sure your message port supports `transfer` before using this feature.
51
- */
52
- experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]>;
53
- /**
54
- * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
55
- */
56
- encodePeerMessage?: EncodePeerMessageOptions | undefined;
57
- /**
58
- * Options for decoding peer messages, such as `prefix` for distinguishing messages on the same channel.
59
- */
60
- decodePeerMessage?: DecodePeerMessageOptions | undefined;
61
- }
62
- declare class MessagePortLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
63
- private readonly peer;
64
- constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions }: MessagePortLinkTransportOptions<T>);
65
- send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
66
- }
67
-
68
- interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, MessagePortLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
69
- }
70
- declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
71
- constructor(options: RPCLinkOptions<T>);
72
- }
73
-
74
- export { MessagePortLinkTransport, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
75
- export type { BrowserPortLike, MessagePortLinkTransportOptions, MessagePortMainLike, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData };
@@ -1,91 +0,0 @@
1
- import { value, isPlainObject, toStringOrBytes } from '@orpc/shared';
2
- import { ClientPeer, encodePeerMessage, decodePeerMessage, isServerPeerSendMessage } from '@standardserver/peer';
3
- import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.DXhchJ84.mjs';
4
- import '@standardserver/core';
5
- import '@standardserver/fetch';
6
- import '../../shared/client.Dnfj8jnT.mjs';
7
- import '../../shared/client.DMXKFDyV.mjs';
8
-
9
- function postMessagePortMessage(port, data, transfer) {
10
- if (transfer) {
11
- port.postMessage(data, transfer);
12
- } else {
13
- port.postMessage(data);
14
- }
15
- }
16
- function onMessagePortMessage(port, callback) {
17
- if ("addEventListener" in port) {
18
- port.addEventListener("message", (event) => {
19
- callback(event.data);
20
- });
21
- } else if ("on" in port) {
22
- port.on("message", (event) => {
23
- callback(event?.data);
24
- });
25
- } else if ("onMessage" in port) {
26
- port.onMessage.addListener((data) => {
27
- callback(data);
28
- });
29
- } else {
30
- throw new Error("Cannot find a addEventListener/on/onMessage method on the port");
31
- }
32
- }
33
- function onMessagePortClose(port, callback) {
34
- if ("addEventListener" in port) {
35
- port.addEventListener("close", () => {
36
- callback();
37
- });
38
- } else if ("on" in port) {
39
- port.on("close", () => {
40
- callback();
41
- });
42
- } else if ("onDisconnect" in port) {
43
- port.onDisconnect.addListener(() => {
44
- callback();
45
- });
46
- } else {
47
- throw new Error("Cannot find a addEventListener/on/onDisconnect method on the port");
48
- }
49
- }
50
-
51
- class MessagePortLinkTransport {
52
- peer;
53
- constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions }) {
54
- this.peer = new ClientPeer(async (message) => {
55
- const transfer = await value(experimental_transfer, message, port);
56
- if (transfer) {
57
- postMessagePortMessage(port, message, transfer);
58
- } else {
59
- postMessagePortMessage(port, await encodePeerMessage(message, encodePeerMessageOptions));
60
- }
61
- });
62
- onMessagePortMessage(port, async (message) => {
63
- if (isPlainObject(message)) {
64
- await this.peer.message(message);
65
- return;
66
- }
67
- const encodedMessage = await toStringOrBytes(message);
68
- const result = decodePeerMessage(encodedMessage, decodePeerMessageOptions);
69
- if (result.matched && isServerPeerSendMessage(result.message)) {
70
- await this.peer.message(result.message);
71
- }
72
- });
73
- onMessagePortClose(port, () => {
74
- this.peer.close();
75
- });
76
- }
77
- async send(standardRequest, _path, _options) {
78
- const standardResponse = await this.peer.request(standardRequest);
79
- return standardResponse;
80
- }
81
- }
82
-
83
- class RPCLink extends StandardLink {
84
- constructor(options) {
85
- const codec = new RPCLinkCodec(options);
86
- const transport = new MessagePortLinkTransport(options);
87
- super(codec, transport, options);
88
- }
89
- }
90
-
91
- export { MessagePortLinkTransport, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
@@ -1,61 +0,0 @@
1
- import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.Cby_-GGh.mjs';
2
- export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.Cby_-GGh.mjs';
3
- import { Value, Promisable } from '@orpc/shared';
4
- import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core';
5
- export { StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl } from '@standardserver/core';
6
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
7
- import { e as RPCSerializer } from '../../shared/client.BdItY5DT.mjs';
8
-
9
- interface RPCLinkCodecOptions<T extends ClientContext> {
10
- /**
11
- * Base url for all requests (without origin). Should match with handler's prefix.
12
- *
13
- * @example '/rpc?base=1'
14
- *
15
- * @default '/'
16
- */
17
- url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]>;
18
- /**
19
- * The maximum length of the URL.
20
- *
21
- * If the URL exceeds this length, the codec should use the `fallbackMethod` to send the request with the payload in the body instead of the URL.
22
- *
23
- * @default 2083
24
- */
25
- maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: string[], input: unknown]>;
26
- /**
27
- * The method used to make the request.
28
- *
29
- * @default 'POST'
30
- */
31
- method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
32
- /**
33
- * The method to use when the payload cannot safely pass to the server with method return from method function.
34
- * GET is not allowed, it's very dangerous.
35
- *
36
- * @default 'POST'
37
- */
38
- fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
39
- /**
40
- * Inject headers to the request.
41
- */
42
- headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]>;
43
- /**
44
- * Override the default RPC serializer.
45
- */
46
- serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
47
- }
48
- declare class RPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
49
- private readonly baseUrl;
50
- private readonly maxUrlLength;
51
- private readonly fallbackMethod;
52
- private readonly expectedMethod;
53
- private readonly headers;
54
- private readonly serializer;
55
- constructor(options: RPCLinkCodecOptions<T>);
56
- encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
57
- decodeResponse(response: StandardLazyResponse): Promise<StandardLinkCodecDecodedResponse>;
58
- }
59
-
60
- export { RPCLinkCodec, StandardLinkCodec, StandardLinkCodecDecodedResponse };
61
- export type { RPCLinkCodecOptions };
@@ -1,6 +0,0 @@
1
- export { C as CompositeStandardLinkPlugin, R as RPCLinkCodec, S as StandardLink } from '../../shared/client.DXhchJ84.mjs';
2
- import '@orpc/shared';
3
- import '@standardserver/core';
4
- import '@standardserver/fetch';
5
- import '../../shared/client.Dnfj8jnT.mjs';
6
- import '../../shared/client.DMXKFDyV.mjs';
@@ -1,121 +0,0 @@
1
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
2
- import { Promisable } from '@orpc/shared';
3
- import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
4
- import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
5
- import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.Cby_-GGh.mjs';
6
- import { RPCLinkCodecOptions } from '../standard/index.mjs';
7
- import '../../shared/client.BdItY5DT.mjs';
8
-
9
- type WebSocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>;
10
- interface WebsocketLinkTransportAttemptInfo {
11
- /**
12
- * Total number of connection attempts for this transport's lifetime.
13
- * Starts at 1 on the first attempt, increments on every subsequent
14
- * attempt, and never resets.
15
- */
16
- totalAttempt: number;
17
- /**
18
- * Attempt number within the current (re)connect cycle.
19
- * Starts at 1, increments on each consecutive failure, and resets to 1
20
- * once a connection succeeds. Use this for backoff calculations.
21
- */
22
- attempt: number;
23
- }
24
- interface WebsocketLinkTransportReconnectOptions {
25
- /**
26
- * Whether to automatically reconnect when the connection is lost.
27
- *
28
- * @default false
29
- */
30
- enabled: boolean;
31
- /**
32
- * Delay before a (re)connect attempt, in milliseconds.
33
- *
34
- * @default info => info.attempt === 1 ? 0 : 2_000
35
- */
36
- delay?: undefined | ((info: WebsocketLinkTransportAttemptInfo) => number);
37
- /**
38
- * Maximum number of consecutive failed attempts before giving up.
39
- * When exceeded, `getConnectedPeer` throws instead of retrying.
40
- * Should greater than 1
41
- *
42
- * @default Infinity
43
- */
44
- maxAttempt?: undefined | number;
45
- /**
46
- * Whether to proactively reconnect right after the socket closes,
47
- * rather than waiting for the next call to trigger reconnection.
48
- * Reduces latency for the next request.
49
- *
50
- * @default { enabled: false }
51
- */
52
- onClose?: undefined | {
53
- /**
54
- * Whether to proactively reconnect right after the socket closes,
55
- * rather than waiting for the next call to trigger reconnection.
56
- * Reduces latency for the next request.
57
- *
58
- * @default false
59
- */
60
- enabled: boolean;
61
- /**
62
- * Delay before reconnecting after the socket closes, in milliseconds.
63
- *
64
- * @default 0
65
- */
66
- delay?: number;
67
- };
68
- }
69
- interface WebsocketLinkTransportOptions<_T extends ClientContext> {
70
- /**
71
- * Returns a WebSocket instance for peer communication.
72
- * Can be async for lazy resolution.
73
- */
74
- connect: (info: WebsocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
75
- /**
76
- * Whether to connect immediately on initialization, instead of waiting
77
- * for the first call. Reduces latency for the first request.
78
- *
79
- * @default false
80
- */
81
- connectOnInit?: undefined | boolean;
82
- /**
83
- * Reconnection behavior when the connection is lost.
84
- *
85
- * @default { enabled: false }
86
- */
87
- reconnect?: undefined | WebsocketLinkTransportReconnectOptions;
88
- /**
89
- * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
90
- */
91
- encodePeerMessage?: EncodePeerMessageOptions | undefined;
92
- /**
93
- * Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
94
- */
95
- decodePeerMessage?: DecodePeerMessageOptions | undefined;
96
- }
97
- declare class WebsocketLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
98
- private readonly connect;
99
- private readonly reconnectEnabled;
100
- private readonly reconnectDelay;
101
- private readonly reconnectMaxAttempt;
102
- private readonly reconnectOnCloseEnabled;
103
- private readonly reconnectOnCloseDelay;
104
- private readonly encodePeerMessageOptions;
105
- private readonly decodePeerMessageOptions;
106
- constructor(options: WebsocketLinkTransportOptions<T>);
107
- send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
108
- private totalAttempt;
109
- private attempt;
110
- private current;
111
- private getConnectedPeer;
112
- }
113
-
114
- interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, WebsocketLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
115
- }
116
- declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
117
- constructor(options: RPCLinkOptions<T>);
118
- }
119
-
120
- export { RPCLink, WebsocketLinkTransport };
121
- export type { RPCLinkOptions, WebSocketLike, WebsocketLinkTransportAttemptInfo, WebsocketLinkTransportOptions, WebsocketLinkTransportReconnectOptions };