@orpc/standard-server-peer 0.0.0-next.fc23c8d → 0.0.0-next.fc2dc8f
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/README.md +9 -4
- package/dist/index.d.mts +148 -33
- package/dist/index.d.ts +148 -33
- package/dist/index.mjs +423 -205
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<image align="center" src="https://orpc.
|
|
2
|
+
<image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" />
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<h1></h1>
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
18
|
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
19
|
</a>
|
|
20
|
+
<a href="https://deepwiki.com/unnoq/orpc">
|
|
21
|
+
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
|
|
22
|
+
</a>
|
|
20
23
|
</div>
|
|
21
24
|
|
|
22
25
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
@@ -30,7 +33,8 @@
|
|
|
30
33
|
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
34
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
35
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
-
-
|
|
36
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
37
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
34
38
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
39
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
40
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
@@ -38,11 +42,10 @@
|
|
|
38
42
|
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
43
|
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
44
|
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
-
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
42
45
|
|
|
43
46
|
## Documentation
|
|
44
47
|
|
|
45
|
-
You can find the full documentation [here](https://orpc.
|
|
48
|
+
You can find the full documentation [here](https://orpc.dev).
|
|
46
49
|
|
|
47
50
|
## Packages
|
|
48
51
|
|
|
@@ -50,9 +53,11 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
50
53
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
51
54
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
52
55
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
56
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
|
53
57
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
54
58
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
55
59
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
60
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
56
61
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
57
62
|
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
58
63
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
|
-
import { Promisable, AsyncIdQueueCloseOptions as AsyncIdQueueCloseOptions$1, AsyncIteratorClassCleanupFn, AsyncIteratorClass } from '@orpc/shared';
|
|
2
|
-
import { StandardRequest, StandardResponse,
|
|
1
|
+
import { Promisable, AsyncIdQueueCloseOptions as AsyncIdQueueCloseOptions$1, SetSpanErrorOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClass } from '@orpc/shared';
|
|
2
|
+
import { StandardRequest, EventMeta, StandardResponse, StandardBody, StandardHeaders } from '@orpc/standard-server';
|
|
3
3
|
|
|
4
|
-
type EncodedMessage = string | ArrayBufferLike;
|
|
4
|
+
type EncodedMessage = string | ArrayBufferLike | Uint8Array;
|
|
5
5
|
interface EncodedMessageSendFn {
|
|
6
6
|
(message: EncodedMessage): Promisable<void>;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
interface ClientPeerCloseOptions extends AsyncIdQueueCloseOptions$1 {
|
|
10
|
-
/**
|
|
11
|
-
* Should abort or not?
|
|
12
|
-
*
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
abort?: boolean;
|
|
16
|
-
}
|
|
17
|
-
declare class ClientPeer {
|
|
18
|
-
private readonly idGenerator;
|
|
19
|
-
private readonly responseQueue;
|
|
20
|
-
private readonly serverEventIteratorQueue;
|
|
21
|
-
private readonly serverControllers;
|
|
22
|
-
private readonly send;
|
|
23
|
-
constructor(send: EncodedMessageSendFn);
|
|
24
|
-
get length(): number;
|
|
25
|
-
open(id: string): AbortController;
|
|
26
|
-
request(request: StandardRequest): Promise<StandardResponse>;
|
|
27
|
-
message(raw: EncodedMessage): Promise<void>;
|
|
28
|
-
close(options?: AsyncIdQueueCloseOptions$1): void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
9
|
declare enum MessageType {
|
|
32
10
|
REQUEST = 1,
|
|
33
11
|
RESPONSE = 2,
|
|
@@ -50,16 +28,116 @@ interface ResponseMessageMap {
|
|
|
50
28
|
[MessageType.EVENT_ITERATOR]: EventIteratorPayload;
|
|
51
29
|
[MessageType.ABORT_SIGNAL]: void;
|
|
52
30
|
}
|
|
31
|
+
interface BaseMessageFormat<P = unknown> {
|
|
32
|
+
/**
|
|
33
|
+
* Client-guaranteed unique identifier
|
|
34
|
+
*/
|
|
35
|
+
i: string;
|
|
36
|
+
/**
|
|
37
|
+
* @default REQUEST | RESPONSE
|
|
38
|
+
*/
|
|
39
|
+
t?: MessageType;
|
|
40
|
+
p: P;
|
|
41
|
+
}
|
|
42
|
+
interface SerializedEventIteratorPayload {
|
|
43
|
+
e: EventIteratorEvent;
|
|
44
|
+
d: unknown;
|
|
45
|
+
m?: EventMeta;
|
|
46
|
+
}
|
|
47
|
+
interface SerializedRequestPayload {
|
|
48
|
+
/**
|
|
49
|
+
* The url of the request
|
|
50
|
+
*
|
|
51
|
+
* might be relative path if origin is `http://orpc`
|
|
52
|
+
*/
|
|
53
|
+
u: string;
|
|
54
|
+
b: StandardBody;
|
|
55
|
+
/**
|
|
56
|
+
* @default {}
|
|
57
|
+
*/
|
|
58
|
+
h?: StandardHeaders;
|
|
59
|
+
/**
|
|
60
|
+
* @default POST
|
|
61
|
+
*/
|
|
62
|
+
m?: string;
|
|
63
|
+
}
|
|
64
|
+
interface SerializedResponsePayload {
|
|
65
|
+
/**
|
|
66
|
+
* @default 200
|
|
67
|
+
*/
|
|
68
|
+
s?: number;
|
|
69
|
+
/**
|
|
70
|
+
* @default {}
|
|
71
|
+
*/
|
|
72
|
+
h?: StandardHeaders;
|
|
73
|
+
b: StandardBody;
|
|
74
|
+
}
|
|
53
75
|
type DecodedMessageUnion<TMap extends RequestMessageMap | ResponseMessageMap> = {
|
|
54
76
|
[K in keyof TMap]: [id: string, type: K, payload: TMap[K]];
|
|
55
77
|
}[keyof TMap];
|
|
56
78
|
type DecodedRequestMessage = DecodedMessageUnion<RequestMessageMap>;
|
|
57
79
|
type DecodedResponseMessage = DecodedMessageUnion<ResponseMessageMap>;
|
|
80
|
+
/**
|
|
81
|
+
* New serialization functions without Blob handling
|
|
82
|
+
*/
|
|
83
|
+
declare function serializeRequestMessage<T extends keyof RequestMessageMap>(id: string, type: T, payload: RequestMessageMap[T]): BaseMessageFormat;
|
|
84
|
+
declare function deserializeRequestMessage(message: BaseMessageFormat): DecodedRequestMessage;
|
|
85
|
+
declare function serializeResponseMessage<T extends keyof ResponseMessageMap>(id: string, type: T, payload: ResponseMessageMap[T]): BaseMessageFormat;
|
|
86
|
+
declare function deserializeResponseMessage(message: BaseMessageFormat): DecodedResponseMessage;
|
|
87
|
+
/**
|
|
88
|
+
* Original encode/decode functions now using the new serialize/deserialize functions
|
|
89
|
+
*/
|
|
58
90
|
declare function encodeRequestMessage<T extends keyof RequestMessageMap>(id: string, type: T, payload: RequestMessageMap[T]): Promise<EncodedMessage>;
|
|
59
91
|
declare function decodeRequestMessage(raw: EncodedMessage): Promise<DecodedRequestMessage>;
|
|
60
92
|
declare function encodeResponseMessage<T extends keyof ResponseMessageMap>(id: string, type: T, payload: ResponseMessageMap[T]): Promise<EncodedMessage>;
|
|
61
93
|
declare function decodeResponseMessage(raw: EncodedMessage): Promise<DecodedResponseMessage>;
|
|
62
|
-
|
|
94
|
+
|
|
95
|
+
interface experimental_RequestMessageSendFn {
|
|
96
|
+
(message: DecodedRequestMessage): Promisable<void>;
|
|
97
|
+
}
|
|
98
|
+
interface ClientPeerCloseOptions extends AsyncIdQueueCloseOptions$1 {
|
|
99
|
+
/**
|
|
100
|
+
* Should abort or not?
|
|
101
|
+
*
|
|
102
|
+
* @default true
|
|
103
|
+
*/
|
|
104
|
+
abort?: boolean;
|
|
105
|
+
}
|
|
106
|
+
declare class ClientPeer {
|
|
107
|
+
private readonly peer;
|
|
108
|
+
constructor(send: EncodedMessageSendFn);
|
|
109
|
+
get length(): number;
|
|
110
|
+
open(id: string): AbortController;
|
|
111
|
+
request(request: StandardRequest): Promise<StandardResponse>;
|
|
112
|
+
message(raw: EncodedMessage): Promise<void>;
|
|
113
|
+
close(options?: AsyncIdQueueCloseOptions$1): void;
|
|
114
|
+
}
|
|
115
|
+
declare class experimental_ClientPeerWithoutCodec {
|
|
116
|
+
private readonly idGenerator;
|
|
117
|
+
/**
|
|
118
|
+
* Queue of responses sent from server, awaiting consumption
|
|
119
|
+
*/
|
|
120
|
+
private readonly responseQueue;
|
|
121
|
+
/**
|
|
122
|
+
* Queue of event iterator messages sent from server, awaiting consumption
|
|
123
|
+
*/
|
|
124
|
+
private readonly serverEventIteratorQueue;
|
|
125
|
+
/**
|
|
126
|
+
* Controllers used to signal that the client should stop sending event iterator messages
|
|
127
|
+
*/
|
|
128
|
+
private readonly serverControllers;
|
|
129
|
+
/**
|
|
130
|
+
* Cleanup functions invoked when the request/response is closed
|
|
131
|
+
*/
|
|
132
|
+
private readonly cleanupFns;
|
|
133
|
+
private readonly send;
|
|
134
|
+
constructor(send: experimental_RequestMessageSendFn);
|
|
135
|
+
get length(): number;
|
|
136
|
+
open(id: string): AbortController;
|
|
137
|
+
request(request: StandardRequest): Promise<StandardResponse>;
|
|
138
|
+
message([id, type, payload]: DecodedResponseMessage): Promise<void>;
|
|
139
|
+
close(options?: AsyncIdQueueCloseOptions$1): void;
|
|
140
|
+
}
|
|
63
141
|
|
|
64
142
|
interface AsyncIdQueueCloseOptions {
|
|
65
143
|
id?: string;
|
|
@@ -67,9 +145,11 @@ interface AsyncIdQueueCloseOptions {
|
|
|
67
145
|
}
|
|
68
146
|
declare class AsyncIdQueue<T> {
|
|
69
147
|
private readonly openIds;
|
|
70
|
-
private readonly
|
|
71
|
-
private readonly
|
|
148
|
+
private readonly queues;
|
|
149
|
+
private readonly waiters;
|
|
72
150
|
get length(): number;
|
|
151
|
+
get waiterIds(): string[];
|
|
152
|
+
hasBufferedItems(id: string): boolean;
|
|
73
153
|
open(id: string): void;
|
|
74
154
|
isOpen(id: string): boolean;
|
|
75
155
|
push(id: string, item: T): void;
|
|
@@ -78,9 +158,17 @@ declare class AsyncIdQueue<T> {
|
|
|
78
158
|
assertOpen(id: string): void;
|
|
79
159
|
}
|
|
80
160
|
|
|
81
|
-
|
|
161
|
+
interface ToEventIteratorOptions extends SetSpanErrorOptions {
|
|
162
|
+
}
|
|
163
|
+
declare function toEventIterator(queue: AsyncIdQueue<EventIteratorPayload>, id: string, cleanup: AsyncIteratorClassCleanupFn, options?: ToEventIteratorOptions): AsyncIteratorClass<unknown>;
|
|
82
164
|
declare function resolveEventIterator(iterator: AsyncIterator<any>, callback: (payload: EventIteratorPayload) => Promise<'next' | 'abort'>): Promise<void>;
|
|
83
165
|
|
|
166
|
+
interface experimental_ResponseMessageSendFn {
|
|
167
|
+
(message: DecodedResponseMessage): Promisable<void>;
|
|
168
|
+
}
|
|
169
|
+
interface ServerPeerHandleRequestFn {
|
|
170
|
+
(request: StandardRequest): Promise<StandardResponse>;
|
|
171
|
+
}
|
|
84
172
|
interface ServerPeerCloseOptions extends AsyncIdQueueCloseOptions$1 {
|
|
85
173
|
/**
|
|
86
174
|
* Should abort or not?
|
|
@@ -90,16 +178,43 @@ interface ServerPeerCloseOptions extends AsyncIdQueueCloseOptions$1 {
|
|
|
90
178
|
abort?: boolean;
|
|
91
179
|
}
|
|
92
180
|
declare class ServerPeer {
|
|
181
|
+
private readonly peer;
|
|
182
|
+
constructor(send: EncodedMessageSendFn);
|
|
183
|
+
get length(): number;
|
|
184
|
+
open(id: string): AbortController;
|
|
185
|
+
/**
|
|
186
|
+
* @todo This method will return Promise<void> in the next major version.
|
|
187
|
+
*/
|
|
188
|
+
message(raw: EncodedMessage, handleRequest?: ServerPeerHandleRequestFn): Promise<[id: string, StandardRequest | undefined]>;
|
|
189
|
+
/**
|
|
190
|
+
* @deprecated Please pass the `handleRequest` (second arg) function to the `message` method instead.
|
|
191
|
+
*/
|
|
192
|
+
response(id: string, response: StandardResponse): Promise<void>;
|
|
193
|
+
close({ abort, ...options }?: ServerPeerCloseOptions): void;
|
|
194
|
+
}
|
|
195
|
+
declare class experimental_ServerPeerWithoutCodec {
|
|
196
|
+
/**
|
|
197
|
+
* Queue of event iterator messages sent from client, awaiting consumption
|
|
198
|
+
*/
|
|
93
199
|
private readonly clientEventIteratorQueue;
|
|
200
|
+
/**
|
|
201
|
+
* Map of active client request controllers, should be synced to request signal
|
|
202
|
+
*/
|
|
94
203
|
private readonly clientControllers;
|
|
95
204
|
private readonly send;
|
|
96
|
-
constructor(send:
|
|
205
|
+
constructor(send: experimental_ResponseMessageSendFn);
|
|
97
206
|
get length(): number;
|
|
98
207
|
open(id: string): AbortController;
|
|
99
|
-
|
|
208
|
+
/**
|
|
209
|
+
* @todo This method will return Promise<void> in the next major version.
|
|
210
|
+
*/
|
|
211
|
+
message([id, type, payload]: DecodedRequestMessage, handleRequest?: ServerPeerHandleRequestFn): Promise<[id: string, StandardRequest | undefined]>;
|
|
212
|
+
/**
|
|
213
|
+
* @deprecated Please pass the `handleRequest` (second arg) function to the `message` method instead.
|
|
214
|
+
*/
|
|
100
215
|
response(id: string, response: StandardResponse): Promise<void>;
|
|
101
216
|
close({ abort, ...options }?: ServerPeerCloseOptions): void;
|
|
102
217
|
}
|
|
103
218
|
|
|
104
|
-
export { ClientPeer, MessageType, ServerPeer, decodeRequestMessage, decodeResponseMessage, encodeRequestMessage, encodeResponseMessage,
|
|
105
|
-
export type { ClientPeerCloseOptions, DecodedRequestMessage, DecodedResponseMessage, EncodedMessage, EncodedMessageSendFn, EventIteratorEvent, EventIteratorPayload, RequestMessageMap, ResponseMessageMap, ServerPeerCloseOptions };
|
|
219
|
+
export { ClientPeer, MessageType, ServerPeer, decodeRequestMessage, decodeResponseMessage, deserializeRequestMessage, deserializeResponseMessage, encodeRequestMessage, encodeResponseMessage, experimental_ClientPeerWithoutCodec, experimental_ServerPeerWithoutCodec, resolveEventIterator, serializeRequestMessage, serializeResponseMessage, toEventIterator };
|
|
220
|
+
export type { BaseMessageFormat, ClientPeerCloseOptions, DecodedMessageUnion, DecodedRequestMessage, DecodedResponseMessage, EncodedMessage, EncodedMessageSendFn, EventIteratorEvent, EventIteratorPayload, RequestMessageMap, ResponseMessageMap, SerializedEventIteratorPayload, SerializedRequestPayload, SerializedResponsePayload, ServerPeerCloseOptions, ServerPeerHandleRequestFn, ToEventIteratorOptions, experimental_RequestMessageSendFn, experimental_ResponseMessageSendFn };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
|
-
import { Promisable, AsyncIdQueueCloseOptions as AsyncIdQueueCloseOptions$1, AsyncIteratorClassCleanupFn, AsyncIteratorClass } from '@orpc/shared';
|
|
2
|
-
import { StandardRequest, StandardResponse,
|
|
1
|
+
import { Promisable, AsyncIdQueueCloseOptions as AsyncIdQueueCloseOptions$1, SetSpanErrorOptions, AsyncIteratorClassCleanupFn, AsyncIteratorClass } from '@orpc/shared';
|
|
2
|
+
import { StandardRequest, EventMeta, StandardResponse, StandardBody, StandardHeaders } from '@orpc/standard-server';
|
|
3
3
|
|
|
4
|
-
type EncodedMessage = string | ArrayBufferLike;
|
|
4
|
+
type EncodedMessage = string | ArrayBufferLike | Uint8Array;
|
|
5
5
|
interface EncodedMessageSendFn {
|
|
6
6
|
(message: EncodedMessage): Promisable<void>;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
interface ClientPeerCloseOptions extends AsyncIdQueueCloseOptions$1 {
|
|
10
|
-
/**
|
|
11
|
-
* Should abort or not?
|
|
12
|
-
*
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
abort?: boolean;
|
|
16
|
-
}
|
|
17
|
-
declare class ClientPeer {
|
|
18
|
-
private readonly idGenerator;
|
|
19
|
-
private readonly responseQueue;
|
|
20
|
-
private readonly serverEventIteratorQueue;
|
|
21
|
-
private readonly serverControllers;
|
|
22
|
-
private readonly send;
|
|
23
|
-
constructor(send: EncodedMessageSendFn);
|
|
24
|
-
get length(): number;
|
|
25
|
-
open(id: string): AbortController;
|
|
26
|
-
request(request: StandardRequest): Promise<StandardResponse>;
|
|
27
|
-
message(raw: EncodedMessage): Promise<void>;
|
|
28
|
-
close(options?: AsyncIdQueueCloseOptions$1): void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
9
|
declare enum MessageType {
|
|
32
10
|
REQUEST = 1,
|
|
33
11
|
RESPONSE = 2,
|
|
@@ -50,16 +28,116 @@ interface ResponseMessageMap {
|
|
|
50
28
|
[MessageType.EVENT_ITERATOR]: EventIteratorPayload;
|
|
51
29
|
[MessageType.ABORT_SIGNAL]: void;
|
|
52
30
|
}
|
|
31
|
+
interface BaseMessageFormat<P = unknown> {
|
|
32
|
+
/**
|
|
33
|
+
* Client-guaranteed unique identifier
|
|
34
|
+
*/
|
|
35
|
+
i: string;
|
|
36
|
+
/**
|
|
37
|
+
* @default REQUEST | RESPONSE
|
|
38
|
+
*/
|
|
39
|
+
t?: MessageType;
|
|
40
|
+
p: P;
|
|
41
|
+
}
|
|
42
|
+
interface SerializedEventIteratorPayload {
|
|
43
|
+
e: EventIteratorEvent;
|
|
44
|
+
d: unknown;
|
|
45
|
+
m?: EventMeta;
|
|
46
|
+
}
|
|
47
|
+
interface SerializedRequestPayload {
|
|
48
|
+
/**
|
|
49
|
+
* The url of the request
|
|
50
|
+
*
|
|
51
|
+
* might be relative path if origin is `http://orpc`
|
|
52
|
+
*/
|
|
53
|
+
u: string;
|
|
54
|
+
b: StandardBody;
|
|
55
|
+
/**
|
|
56
|
+
* @default {}
|
|
57
|
+
*/
|
|
58
|
+
h?: StandardHeaders;
|
|
59
|
+
/**
|
|
60
|
+
* @default POST
|
|
61
|
+
*/
|
|
62
|
+
m?: string;
|
|
63
|
+
}
|
|
64
|
+
interface SerializedResponsePayload {
|
|
65
|
+
/**
|
|
66
|
+
* @default 200
|
|
67
|
+
*/
|
|
68
|
+
s?: number;
|
|
69
|
+
/**
|
|
70
|
+
* @default {}
|
|
71
|
+
*/
|
|
72
|
+
h?: StandardHeaders;
|
|
73
|
+
b: StandardBody;
|
|
74
|
+
}
|
|
53
75
|
type DecodedMessageUnion<TMap extends RequestMessageMap | ResponseMessageMap> = {
|
|
54
76
|
[K in keyof TMap]: [id: string, type: K, payload: TMap[K]];
|
|
55
77
|
}[keyof TMap];
|
|
56
78
|
type DecodedRequestMessage = DecodedMessageUnion<RequestMessageMap>;
|
|
57
79
|
type DecodedResponseMessage = DecodedMessageUnion<ResponseMessageMap>;
|
|
80
|
+
/**
|
|
81
|
+
* New serialization functions without Blob handling
|
|
82
|
+
*/
|
|
83
|
+
declare function serializeRequestMessage<T extends keyof RequestMessageMap>(id: string, type: T, payload: RequestMessageMap[T]): BaseMessageFormat;
|
|
84
|
+
declare function deserializeRequestMessage(message: BaseMessageFormat): DecodedRequestMessage;
|
|
85
|
+
declare function serializeResponseMessage<T extends keyof ResponseMessageMap>(id: string, type: T, payload: ResponseMessageMap[T]): BaseMessageFormat;
|
|
86
|
+
declare function deserializeResponseMessage(message: BaseMessageFormat): DecodedResponseMessage;
|
|
87
|
+
/**
|
|
88
|
+
* Original encode/decode functions now using the new serialize/deserialize functions
|
|
89
|
+
*/
|
|
58
90
|
declare function encodeRequestMessage<T extends keyof RequestMessageMap>(id: string, type: T, payload: RequestMessageMap[T]): Promise<EncodedMessage>;
|
|
59
91
|
declare function decodeRequestMessage(raw: EncodedMessage): Promise<DecodedRequestMessage>;
|
|
60
92
|
declare function encodeResponseMessage<T extends keyof ResponseMessageMap>(id: string, type: T, payload: ResponseMessageMap[T]): Promise<EncodedMessage>;
|
|
61
93
|
declare function decodeResponseMessage(raw: EncodedMessage): Promise<DecodedResponseMessage>;
|
|
62
|
-
|
|
94
|
+
|
|
95
|
+
interface experimental_RequestMessageSendFn {
|
|
96
|
+
(message: DecodedRequestMessage): Promisable<void>;
|
|
97
|
+
}
|
|
98
|
+
interface ClientPeerCloseOptions extends AsyncIdQueueCloseOptions$1 {
|
|
99
|
+
/**
|
|
100
|
+
* Should abort or not?
|
|
101
|
+
*
|
|
102
|
+
* @default true
|
|
103
|
+
*/
|
|
104
|
+
abort?: boolean;
|
|
105
|
+
}
|
|
106
|
+
declare class ClientPeer {
|
|
107
|
+
private readonly peer;
|
|
108
|
+
constructor(send: EncodedMessageSendFn);
|
|
109
|
+
get length(): number;
|
|
110
|
+
open(id: string): AbortController;
|
|
111
|
+
request(request: StandardRequest): Promise<StandardResponse>;
|
|
112
|
+
message(raw: EncodedMessage): Promise<void>;
|
|
113
|
+
close(options?: AsyncIdQueueCloseOptions$1): void;
|
|
114
|
+
}
|
|
115
|
+
declare class experimental_ClientPeerWithoutCodec {
|
|
116
|
+
private readonly idGenerator;
|
|
117
|
+
/**
|
|
118
|
+
* Queue of responses sent from server, awaiting consumption
|
|
119
|
+
*/
|
|
120
|
+
private readonly responseQueue;
|
|
121
|
+
/**
|
|
122
|
+
* Queue of event iterator messages sent from server, awaiting consumption
|
|
123
|
+
*/
|
|
124
|
+
private readonly serverEventIteratorQueue;
|
|
125
|
+
/**
|
|
126
|
+
* Controllers used to signal that the client should stop sending event iterator messages
|
|
127
|
+
*/
|
|
128
|
+
private readonly serverControllers;
|
|
129
|
+
/**
|
|
130
|
+
* Cleanup functions invoked when the request/response is closed
|
|
131
|
+
*/
|
|
132
|
+
private readonly cleanupFns;
|
|
133
|
+
private readonly send;
|
|
134
|
+
constructor(send: experimental_RequestMessageSendFn);
|
|
135
|
+
get length(): number;
|
|
136
|
+
open(id: string): AbortController;
|
|
137
|
+
request(request: StandardRequest): Promise<StandardResponse>;
|
|
138
|
+
message([id, type, payload]: DecodedResponseMessage): Promise<void>;
|
|
139
|
+
close(options?: AsyncIdQueueCloseOptions$1): void;
|
|
140
|
+
}
|
|
63
141
|
|
|
64
142
|
interface AsyncIdQueueCloseOptions {
|
|
65
143
|
id?: string;
|
|
@@ -67,9 +145,11 @@ interface AsyncIdQueueCloseOptions {
|
|
|
67
145
|
}
|
|
68
146
|
declare class AsyncIdQueue<T> {
|
|
69
147
|
private readonly openIds;
|
|
70
|
-
private readonly
|
|
71
|
-
private readonly
|
|
148
|
+
private readonly queues;
|
|
149
|
+
private readonly waiters;
|
|
72
150
|
get length(): number;
|
|
151
|
+
get waiterIds(): string[];
|
|
152
|
+
hasBufferedItems(id: string): boolean;
|
|
73
153
|
open(id: string): void;
|
|
74
154
|
isOpen(id: string): boolean;
|
|
75
155
|
push(id: string, item: T): void;
|
|
@@ -78,9 +158,17 @@ declare class AsyncIdQueue<T> {
|
|
|
78
158
|
assertOpen(id: string): void;
|
|
79
159
|
}
|
|
80
160
|
|
|
81
|
-
|
|
161
|
+
interface ToEventIteratorOptions extends SetSpanErrorOptions {
|
|
162
|
+
}
|
|
163
|
+
declare function toEventIterator(queue: AsyncIdQueue<EventIteratorPayload>, id: string, cleanup: AsyncIteratorClassCleanupFn, options?: ToEventIteratorOptions): AsyncIteratorClass<unknown>;
|
|
82
164
|
declare function resolveEventIterator(iterator: AsyncIterator<any>, callback: (payload: EventIteratorPayload) => Promise<'next' | 'abort'>): Promise<void>;
|
|
83
165
|
|
|
166
|
+
interface experimental_ResponseMessageSendFn {
|
|
167
|
+
(message: DecodedResponseMessage): Promisable<void>;
|
|
168
|
+
}
|
|
169
|
+
interface ServerPeerHandleRequestFn {
|
|
170
|
+
(request: StandardRequest): Promise<StandardResponse>;
|
|
171
|
+
}
|
|
84
172
|
interface ServerPeerCloseOptions extends AsyncIdQueueCloseOptions$1 {
|
|
85
173
|
/**
|
|
86
174
|
* Should abort or not?
|
|
@@ -90,16 +178,43 @@ interface ServerPeerCloseOptions extends AsyncIdQueueCloseOptions$1 {
|
|
|
90
178
|
abort?: boolean;
|
|
91
179
|
}
|
|
92
180
|
declare class ServerPeer {
|
|
181
|
+
private readonly peer;
|
|
182
|
+
constructor(send: EncodedMessageSendFn);
|
|
183
|
+
get length(): number;
|
|
184
|
+
open(id: string): AbortController;
|
|
185
|
+
/**
|
|
186
|
+
* @todo This method will return Promise<void> in the next major version.
|
|
187
|
+
*/
|
|
188
|
+
message(raw: EncodedMessage, handleRequest?: ServerPeerHandleRequestFn): Promise<[id: string, StandardRequest | undefined]>;
|
|
189
|
+
/**
|
|
190
|
+
* @deprecated Please pass the `handleRequest` (second arg) function to the `message` method instead.
|
|
191
|
+
*/
|
|
192
|
+
response(id: string, response: StandardResponse): Promise<void>;
|
|
193
|
+
close({ abort, ...options }?: ServerPeerCloseOptions): void;
|
|
194
|
+
}
|
|
195
|
+
declare class experimental_ServerPeerWithoutCodec {
|
|
196
|
+
/**
|
|
197
|
+
* Queue of event iterator messages sent from client, awaiting consumption
|
|
198
|
+
*/
|
|
93
199
|
private readonly clientEventIteratorQueue;
|
|
200
|
+
/**
|
|
201
|
+
* Map of active client request controllers, should be synced to request signal
|
|
202
|
+
*/
|
|
94
203
|
private readonly clientControllers;
|
|
95
204
|
private readonly send;
|
|
96
|
-
constructor(send:
|
|
205
|
+
constructor(send: experimental_ResponseMessageSendFn);
|
|
97
206
|
get length(): number;
|
|
98
207
|
open(id: string): AbortController;
|
|
99
|
-
|
|
208
|
+
/**
|
|
209
|
+
* @todo This method will return Promise<void> in the next major version.
|
|
210
|
+
*/
|
|
211
|
+
message([id, type, payload]: DecodedRequestMessage, handleRequest?: ServerPeerHandleRequestFn): Promise<[id: string, StandardRequest | undefined]>;
|
|
212
|
+
/**
|
|
213
|
+
* @deprecated Please pass the `handleRequest` (second arg) function to the `message` method instead.
|
|
214
|
+
*/
|
|
100
215
|
response(id: string, response: StandardResponse): Promise<void>;
|
|
101
216
|
close({ abort, ...options }?: ServerPeerCloseOptions): void;
|
|
102
217
|
}
|
|
103
218
|
|
|
104
|
-
export { ClientPeer, MessageType, ServerPeer, decodeRequestMessage, decodeResponseMessage, encodeRequestMessage, encodeResponseMessage,
|
|
105
|
-
export type { ClientPeerCloseOptions, DecodedRequestMessage, DecodedResponseMessage, EncodedMessage, EncodedMessageSendFn, EventIteratorEvent, EventIteratorPayload, RequestMessageMap, ResponseMessageMap, ServerPeerCloseOptions };
|
|
219
|
+
export { ClientPeer, MessageType, ServerPeer, decodeRequestMessage, decodeResponseMessage, deserializeRequestMessage, deserializeResponseMessage, encodeRequestMessage, encodeResponseMessage, experimental_ClientPeerWithoutCodec, experimental_ServerPeerWithoutCodec, resolveEventIterator, serializeRequestMessage, serializeResponseMessage, toEventIterator };
|
|
220
|
+
export type { BaseMessageFormat, ClientPeerCloseOptions, DecodedMessageUnion, DecodedRequestMessage, DecodedResponseMessage, EncodedMessage, EncodedMessageSendFn, EventIteratorEvent, EventIteratorPayload, RequestMessageMap, ResponseMessageMap, SerializedEventIteratorPayload, SerializedRequestPayload, SerializedResponsePayload, ServerPeerCloseOptions, ServerPeerHandleRequestFn, ToEventIteratorOptions, experimental_RequestMessageSendFn, experimental_ResponseMessageSendFn };
|