@orpc/server 0.0.0-next.dd4e882 → 0.0.0-next.dda04c5
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 +5 -7
- package/dist/adapters/aws-lambda/index.mjs +3 -3
- package/dist/adapters/bun-ws/index.mjs +5 -10
- package/dist/adapters/crossws/index.mjs +5 -10
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/message-port/index.mjs +6 -6
- package/dist/adapters/node/index.mjs +3 -3
- package/dist/adapters/standard/index.mjs +2 -2
- package/dist/adapters/websocket/index.d.mts +26 -2
- package/dist/adapters/websocket/index.d.ts +26 -2
- package/dist/adapters/websocket/index.mjs +47 -16
- package/dist/adapters/ws/index.mjs +5 -4
- package/dist/hibernation/index.d.mts +44 -0
- package/dist/hibernation/index.d.ts +44 -0
- package/dist/hibernation/index.mjs +65 -0
- package/dist/index.d.mts +14 -9
- package/dist/index.d.ts +14 -9
- package/dist/index.mjs +18 -5
- package/dist/plugins/index.mjs +9 -3
- package/dist/shared/{server.CHvOkcM3.mjs → server.CB8Snncu.mjs} +1 -1
- package/dist/shared/{server.DG7Tamti.mjs → server.DLJzqnSX.mjs} +3 -2
- package/dist/shared/{server.BVwwTHyO.mjs → server.DZ5BIITo.mjs} +1 -1
- package/package.json +16 -11
package/README.md
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
31
31
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
32
32
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
33
|
-
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
|
33
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
|
34
34
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
35
35
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
36
36
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
@@ -49,14 +49,12 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
49
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
50
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
51
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
52
|
-
- [@orpc/
|
52
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
53
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
53
54
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
54
|
-
- [@orpc/
|
55
|
-
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
56
|
-
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
57
|
-
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
55
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
58
56
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
59
|
-
- [@orpc/
|
57
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
60
58
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
61
59
|
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
62
60
|
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
2
2
|
import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-aws-lambda';
|
3
|
-
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
3
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
4
4
|
import '@orpc/standard-server';
|
5
5
|
import '@orpc/standard-server/batch';
|
6
6
|
import '@orpc/client';
|
7
7
|
import { S as StrictGetMethodPlugin } from '../../shared/server.BW-nUGgA.mjs';
|
8
8
|
import '@orpc/contract';
|
9
|
-
import { b as StandardRPCHandler } from '../../shared/server.
|
9
|
+
import { b as StandardRPCHandler } from '../../shared/server.CB8Snncu.mjs';
|
10
10
|
import '@orpc/client/standard';
|
11
|
-
import '../../shared/server.
|
11
|
+
import '../../shared/server.DLJzqnSX.mjs';
|
12
12
|
|
13
13
|
class AwsLambdaHandler {
|
14
14
|
constructor(standardHandler, options = {}) {
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
2
2
|
import { ServerPeer } from '@orpc/standard-server-peer';
|
3
|
-
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
3
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
4
4
|
import '@orpc/client';
|
5
5
|
import '@orpc/standard-server';
|
6
6
|
import '@orpc/contract';
|
7
|
-
import { b as StandardRPCHandler } from '../../shared/server.
|
7
|
+
import { b as StandardRPCHandler } from '../../shared/server.CB8Snncu.mjs';
|
8
8
|
import '@orpc/client/standard';
|
9
|
-
import '../../shared/server.
|
9
|
+
import '../../shared/server.DLJzqnSX.mjs';
|
10
10
|
|
11
11
|
class experimental_BunWsHandler {
|
12
12
|
constructor(standardHandler) {
|
@@ -16,13 +16,8 @@ class experimental_BunWsHandler {
|
|
16
16
|
async message(ws, message, ...rest) {
|
17
17
|
let peer = this.peers.get(ws);
|
18
18
|
if (!peer) {
|
19
|
-
this.peers.set(ws, peer = new ServerPeer(
|
20
|
-
|
21
|
-
const buffer = await raw.arrayBuffer();
|
22
|
-
ws.send(buffer);
|
23
|
-
} else {
|
24
|
-
ws.send(raw);
|
25
|
-
}
|
19
|
+
this.peers.set(ws, peer = new ServerPeer((message2) => {
|
20
|
+
ws.send(message2);
|
26
21
|
}));
|
27
22
|
}
|
28
23
|
const [id, request] = await peer.message(typeof message === "string" ? message : message.buffer);
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
2
2
|
import { ServerPeer } from '@orpc/standard-server-peer';
|
3
|
-
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
3
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
4
4
|
import '@orpc/client';
|
5
5
|
import '@orpc/standard-server';
|
6
6
|
import '@orpc/contract';
|
7
|
-
import { b as StandardRPCHandler } from '../../shared/server.
|
7
|
+
import { b as StandardRPCHandler } from '../../shared/server.CB8Snncu.mjs';
|
8
8
|
import '@orpc/client/standard';
|
9
|
-
import '../../shared/server.
|
9
|
+
import '../../shared/server.DLJzqnSX.mjs';
|
10
10
|
|
11
11
|
class experimental_CrosswsHandler {
|
12
12
|
constructor(standardHandler) {
|
@@ -16,13 +16,8 @@ class experimental_CrosswsHandler {
|
|
16
16
|
async message(ws, message, ...rest) {
|
17
17
|
let peer = this.peers.get(ws);
|
18
18
|
if (!peer) {
|
19
|
-
this.peers.set(ws, peer = new ServerPeer(
|
20
|
-
|
21
|
-
const buffer = await raw.arrayBuffer();
|
22
|
-
ws.send(buffer);
|
23
|
-
} else {
|
24
|
-
ws.send(raw);
|
25
|
-
}
|
19
|
+
this.peers.set(ws, peer = new ServerPeer((message2) => {
|
20
|
+
ws.send(message2);
|
26
21
|
}));
|
27
22
|
}
|
28
23
|
const [id, request] = await peer.message(typeof message.rawData === "string" ? message.rawData : message.uint8Array());
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import { ORPCError } from '@orpc/client';
|
2
2
|
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
3
3
|
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
4
|
-
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
4
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
5
5
|
import '@orpc/standard-server';
|
6
6
|
import '@orpc/contract';
|
7
|
-
import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.
|
7
|
+
import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.CB8Snncu.mjs';
|
8
8
|
import '@orpc/client/standard';
|
9
9
|
import '@orpc/standard-server/batch';
|
10
10
|
import { S as StrictGetMethodPlugin } from '../../shared/server.BW-nUGgA.mjs';
|
11
|
-
import '../../shared/server.
|
11
|
+
import '../../shared/server.DLJzqnSX.mjs';
|
12
12
|
|
13
13
|
class BodyLimitPlugin {
|
14
14
|
maxBodySize;
|
@@ -1,21 +1,21 @@
|
|
1
|
-
import { onMessagePortMessage, onMessagePortClose } from '@orpc/client/message-port';
|
1
|
+
import { postMessagePortMessage, onMessagePortMessage, onMessagePortClose } from '@orpc/client/message-port';
|
2
2
|
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
3
3
|
import { ServerPeer } from '@orpc/standard-server-peer';
|
4
|
-
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
4
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
5
5
|
import '@orpc/client';
|
6
6
|
import '@orpc/standard-server';
|
7
7
|
import '@orpc/contract';
|
8
|
-
import { b as StandardRPCHandler } from '../../shared/server.
|
8
|
+
import { b as StandardRPCHandler } from '../../shared/server.CB8Snncu.mjs';
|
9
9
|
import '@orpc/client/standard';
|
10
|
-
import '../../shared/server.
|
10
|
+
import '../../shared/server.DLJzqnSX.mjs';
|
11
11
|
|
12
12
|
class experimental_MessagePortHandler {
|
13
13
|
constructor(standardHandler) {
|
14
14
|
this.standardHandler = standardHandler;
|
15
15
|
}
|
16
16
|
upgrade(port, ...rest) {
|
17
|
-
const peer = new ServerPeer(
|
18
|
-
|
17
|
+
const peer = new ServerPeer((message) => {
|
18
|
+
return postMessagePortMessage(port, message);
|
19
19
|
});
|
20
20
|
onMessagePortMessage(port, async (message) => {
|
21
21
|
const [id, request] = await peer.message(message);
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import { ORPCError } from '@orpc/client';
|
2
2
|
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
3
3
|
import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-node';
|
4
|
-
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
4
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
5
5
|
import '@orpc/standard-server';
|
6
6
|
import '@orpc/contract';
|
7
|
-
import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.
|
7
|
+
import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.CB8Snncu.mjs';
|
8
8
|
import '@orpc/client/standard';
|
9
9
|
import '@orpc/standard-server/batch';
|
10
10
|
import { S as StrictGetMethodPlugin } from '../../shared/server.BW-nUGgA.mjs';
|
11
|
-
import '../../shared/server.
|
11
|
+
import '../../shared/server.DLJzqnSX.mjs';
|
12
12
|
|
13
13
|
class BodyLimitPlugin {
|
14
14
|
maxBodySize;
|
@@ -1,7 +1,7 @@
|
|
1
|
-
export { C as CompositeStandardHandlerPlugin, S as StandardHandler, a as StandardRPCCodec, b as StandardRPCHandler, c as StandardRPCMatcher } from '../../shared/server.
|
1
|
+
export { C as CompositeStandardHandlerPlugin, S as StandardHandler, a as StandardRPCCodec, b as StandardRPCHandler, c as StandardRPCMatcher } from '../../shared/server.CB8Snncu.mjs';
|
2
2
|
import '@orpc/client/standard';
|
3
3
|
import '@orpc/client';
|
4
4
|
import '@orpc/shared';
|
5
5
|
import '@orpc/standard-server';
|
6
|
-
import '../../shared/server.
|
6
|
+
import '../../shared/server.DLJzqnSX.mjs';
|
7
7
|
import '@orpc/contract';
|
@@ -8,10 +8,33 @@ import '@orpc/contract';
|
|
8
8
|
import '@orpc/standard-server';
|
9
9
|
import '@orpc/client/standard';
|
10
10
|
|
11
|
+
type experimental_MinimalWebsocket = Pick<WebSocket, 'addEventListener' | 'send'>;
|
11
12
|
declare class experimental_WebsocketHandler<T extends Context> {
|
12
|
-
private
|
13
|
+
#private;
|
13
14
|
constructor(standardHandler: StandardHandler<T>);
|
14
|
-
|
15
|
+
/**
|
16
|
+
* Upgrades a WebSocket to enable handling
|
17
|
+
*
|
18
|
+
* This attaches the necessary 'message' and 'close' listeners to the WebSocket
|
19
|
+
*
|
20
|
+
* @warning Do not use this method if you're using `.message()` or `.close()`
|
21
|
+
*/
|
22
|
+
upgrade(ws: experimental_MinimalWebsocket, ...rest: MaybeOptionalOptions<Omit<FriendlyStandardHandleOptions<T>, 'prefix'>>): void;
|
23
|
+
/**
|
24
|
+
* Handles a single message received from a WebSocket.
|
25
|
+
*
|
26
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
27
|
+
*
|
28
|
+
* @param ws The WebSocket instance
|
29
|
+
* @param data The message payload, usually place in `event.data`
|
30
|
+
*/
|
31
|
+
message(ws: experimental_MinimalWebsocket, data: string | ArrayBuffer | Blob, ...rest: MaybeOptionalOptions<Omit<FriendlyStandardHandleOptions<T>, 'prefix'>>): Promise<void>;
|
32
|
+
/**
|
33
|
+
* Closes the WebSocket peer and cleans up.
|
34
|
+
*
|
35
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
36
|
+
*/
|
37
|
+
close(ws: experimental_MinimalWebsocket): void;
|
15
38
|
}
|
16
39
|
|
17
40
|
/**
|
@@ -25,3 +48,4 @@ declare class experimental_RPCHandler<T extends Context> extends experimental_We
|
|
25
48
|
}
|
26
49
|
|
27
50
|
export { experimental_RPCHandler, experimental_WebsocketHandler };
|
51
|
+
export type { experimental_MinimalWebsocket };
|
@@ -8,10 +8,33 @@ import '@orpc/contract';
|
|
8
8
|
import '@orpc/standard-server';
|
9
9
|
import '@orpc/client/standard';
|
10
10
|
|
11
|
+
type experimental_MinimalWebsocket = Pick<WebSocket, 'addEventListener' | 'send'>;
|
11
12
|
declare class experimental_WebsocketHandler<T extends Context> {
|
12
|
-
private
|
13
|
+
#private;
|
13
14
|
constructor(standardHandler: StandardHandler<T>);
|
14
|
-
|
15
|
+
/**
|
16
|
+
* Upgrades a WebSocket to enable handling
|
17
|
+
*
|
18
|
+
* This attaches the necessary 'message' and 'close' listeners to the WebSocket
|
19
|
+
*
|
20
|
+
* @warning Do not use this method if you're using `.message()` or `.close()`
|
21
|
+
*/
|
22
|
+
upgrade(ws: experimental_MinimalWebsocket, ...rest: MaybeOptionalOptions<Omit<FriendlyStandardHandleOptions<T>, 'prefix'>>): void;
|
23
|
+
/**
|
24
|
+
* Handles a single message received from a WebSocket.
|
25
|
+
*
|
26
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
27
|
+
*
|
28
|
+
* @param ws The WebSocket instance
|
29
|
+
* @param data The message payload, usually place in `event.data`
|
30
|
+
*/
|
31
|
+
message(ws: experimental_MinimalWebsocket, data: string | ArrayBuffer | Blob, ...rest: MaybeOptionalOptions<Omit<FriendlyStandardHandleOptions<T>, 'prefix'>>): Promise<void>;
|
32
|
+
/**
|
33
|
+
* Closes the WebSocket peer and cleans up.
|
34
|
+
*
|
35
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
36
|
+
*/
|
37
|
+
close(ws: experimental_MinimalWebsocket): void;
|
15
38
|
}
|
16
39
|
|
17
40
|
/**
|
@@ -25,3 +48,4 @@ declare class experimental_RPCHandler<T extends Context> extends experimental_We
|
|
25
48
|
}
|
26
49
|
|
27
50
|
export { experimental_RPCHandler, experimental_WebsocketHandler };
|
51
|
+
export type { experimental_MinimalWebsocket };
|
@@ -1,31 +1,62 @@
|
|
1
1
|
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
2
2
|
import { ServerPeer } from '@orpc/standard-server-peer';
|
3
|
-
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
3
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
4
4
|
import '@orpc/client';
|
5
5
|
import '@orpc/standard-server';
|
6
6
|
import '@orpc/contract';
|
7
|
-
import { b as StandardRPCHandler } from '../../shared/server.
|
7
|
+
import { b as StandardRPCHandler } from '../../shared/server.CB8Snncu.mjs';
|
8
8
|
import '@orpc/client/standard';
|
9
|
-
import '../../shared/server.
|
9
|
+
import '../../shared/server.DLJzqnSX.mjs';
|
10
10
|
|
11
11
|
class experimental_WebsocketHandler {
|
12
|
+
#peers = /* @__PURE__ */ new WeakMap();
|
13
|
+
#handler;
|
12
14
|
constructor(standardHandler) {
|
13
|
-
this
|
15
|
+
this.#handler = standardHandler;
|
14
16
|
}
|
17
|
+
/**
|
18
|
+
* Upgrades a WebSocket to enable handling
|
19
|
+
*
|
20
|
+
* This attaches the necessary 'message' and 'close' listeners to the WebSocket
|
21
|
+
*
|
22
|
+
* @warning Do not use this method if you're using `.message()` or `.close()`
|
23
|
+
*/
|
15
24
|
upgrade(ws, ...rest) {
|
16
|
-
|
17
|
-
ws.addEventListener("
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
ws.addEventListener("message", (event) => this.message(ws, event.data, ...rest));
|
26
|
+
ws.addEventListener("close", () => this.close(ws));
|
27
|
+
}
|
28
|
+
/**
|
29
|
+
* Handles a single message received from a WebSocket.
|
30
|
+
*
|
31
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
32
|
+
*
|
33
|
+
* @param ws The WebSocket instance
|
34
|
+
* @param data The message payload, usually place in `event.data`
|
35
|
+
*/
|
36
|
+
async message(ws, data, ...rest) {
|
37
|
+
let peer = this.#peers.get(ws);
|
38
|
+
if (!peer) {
|
39
|
+
this.#peers.set(ws, peer = new ServerPeer(ws.send.bind(ws)));
|
40
|
+
}
|
41
|
+
const message = data instanceof Blob ? await data.arrayBuffer() : data;
|
42
|
+
const [id, request] = await peer.message(message);
|
43
|
+
if (!request) {
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
const options = resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest));
|
47
|
+
const { response } = await this.#handler.handle({ ...request, body: () => Promise.resolve(request.body) }, options);
|
48
|
+
await peer.response(id, response ?? { status: 404, headers: {}, body: "No procedure matched" });
|
49
|
+
}
|
50
|
+
/**
|
51
|
+
* Closes the WebSocket peer and cleans up.
|
52
|
+
*
|
53
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
54
|
+
*/
|
55
|
+
close(ws) {
|
56
|
+
const peer = this.#peers.get(ws);
|
57
|
+
if (peer) {
|
27
58
|
peer.close();
|
28
|
-
}
|
59
|
+
}
|
29
60
|
}
|
30
61
|
}
|
31
62
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
2
2
|
import { ServerPeer } from '@orpc/standard-server-peer';
|
3
|
-
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
3
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
4
4
|
import '@orpc/client';
|
5
5
|
import '@orpc/standard-server';
|
6
6
|
import '@orpc/contract';
|
7
|
-
import { b as StandardRPCHandler } from '../../shared/server.
|
7
|
+
import { b as StandardRPCHandler } from '../../shared/server.CB8Snncu.mjs';
|
8
8
|
import '@orpc/client/standard';
|
9
|
-
import '../../shared/server.
|
9
|
+
import '../../shared/server.DLJzqnSX.mjs';
|
10
10
|
|
11
11
|
class experimental_WsHandler {
|
12
12
|
constructor(standardHandler) {
|
@@ -15,7 +15,8 @@ class experimental_WsHandler {
|
|
15
15
|
async upgrade(ws, ...rest) {
|
16
16
|
const peer = new ServerPeer(ws.send.bind(ws));
|
17
17
|
ws.addEventListener("message", async (event) => {
|
18
|
-
const
|
18
|
+
const message = Array.isArray(event.data) ? await new Blob(event.data).arrayBuffer() : event.data;
|
19
|
+
const [id, request] = await peer.message(message);
|
19
20
|
if (!request) {
|
20
21
|
return;
|
21
22
|
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.Dq8xr7PQ.mjs';
|
3
|
+
import { experimental_HibernationEventIterator } from '@orpc/standard-server';
|
4
|
+
export { experimental_HibernationEventIterator, experimental_HibernationEventIteratorCallback } from '@orpc/standard-server';
|
5
|
+
import { C as Context, R as Router } from '../shared/server.DD2C4ujN.mjs';
|
6
|
+
import '@orpc/client';
|
7
|
+
import '@orpc/contract';
|
8
|
+
import '@orpc/shared';
|
9
|
+
|
10
|
+
interface experimental_EncodeHibernationRPCEventOptions extends StandardRPCJsonSerializerOptions {
|
11
|
+
/**
|
12
|
+
* The type of event, each type corresponds a different operation
|
13
|
+
*
|
14
|
+
* - 'message' = 'yield'
|
15
|
+
* - 'error' = 'throw'
|
16
|
+
* - 'done' = 'return'
|
17
|
+
*
|
18
|
+
* @default 'message'
|
19
|
+
*/
|
20
|
+
event?: 'message' | 'error' | 'done';
|
21
|
+
}
|
22
|
+
/**
|
23
|
+
* Encodes a Hibernation RPC Event
|
24
|
+
*
|
25
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/hibernation Hibernation Plugin}
|
26
|
+
*/
|
27
|
+
declare function experimental_encodeHibernationRPCEvent(id: string, payload: unknown, options?: experimental_EncodeHibernationRPCEventOptions): string;
|
28
|
+
|
29
|
+
interface experimental_HibernationPluginContext {
|
30
|
+
iterator?: experimental_HibernationEventIterator<any>;
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* Enable Hibernation APIs
|
34
|
+
*
|
35
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/hibernation Hibernation Plugin}
|
36
|
+
*/
|
37
|
+
declare class experimental_HibernationPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
38
|
+
readonly CONTEXT_SYMBOL: symbol;
|
39
|
+
order: number;
|
40
|
+
init(options: StandardHandlerOptions<T>, _router: Router<any, T>): void;
|
41
|
+
}
|
42
|
+
|
43
|
+
export { experimental_HibernationPlugin, experimental_encodeHibernationRPCEvent };
|
44
|
+
export type { experimental_EncodeHibernationRPCEventOptions, experimental_HibernationPluginContext };
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.-ACo36I0.js';
|
3
|
+
import { experimental_HibernationEventIterator } from '@orpc/standard-server';
|
4
|
+
export { experimental_HibernationEventIterator, experimental_HibernationEventIteratorCallback } from '@orpc/standard-server';
|
5
|
+
import { C as Context, R as Router } from '../shared/server.DD2C4ujN.js';
|
6
|
+
import '@orpc/client';
|
7
|
+
import '@orpc/contract';
|
8
|
+
import '@orpc/shared';
|
9
|
+
|
10
|
+
interface experimental_EncodeHibernationRPCEventOptions extends StandardRPCJsonSerializerOptions {
|
11
|
+
/**
|
12
|
+
* The type of event, each type corresponds a different operation
|
13
|
+
*
|
14
|
+
* - 'message' = 'yield'
|
15
|
+
* - 'error' = 'throw'
|
16
|
+
* - 'done' = 'return'
|
17
|
+
*
|
18
|
+
* @default 'message'
|
19
|
+
*/
|
20
|
+
event?: 'message' | 'error' | 'done';
|
21
|
+
}
|
22
|
+
/**
|
23
|
+
* Encodes a Hibernation RPC Event
|
24
|
+
*
|
25
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/hibernation Hibernation Plugin}
|
26
|
+
*/
|
27
|
+
declare function experimental_encodeHibernationRPCEvent(id: string, payload: unknown, options?: experimental_EncodeHibernationRPCEventOptions): string;
|
28
|
+
|
29
|
+
interface experimental_HibernationPluginContext {
|
30
|
+
iterator?: experimental_HibernationEventIterator<any>;
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* Enable Hibernation APIs
|
34
|
+
*
|
35
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/hibernation Hibernation Plugin}
|
36
|
+
*/
|
37
|
+
declare class experimental_HibernationPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
38
|
+
readonly CONTEXT_SYMBOL: symbol;
|
39
|
+
order: number;
|
40
|
+
init(options: StandardHandlerOptions<T>, _router: Router<any, T>): void;
|
41
|
+
}
|
42
|
+
|
43
|
+
export { experimental_HibernationPlugin, experimental_encodeHibernationRPCEvent };
|
44
|
+
export type { experimental_EncodeHibernationRPCEventOptions, experimental_HibernationPluginContext };
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import { toORPCError } from '@orpc/client';
|
2
|
+
import { StandardRPCJsonSerializer } from '@orpc/client/standard';
|
3
|
+
import { stringifyJSON } from '@orpc/shared';
|
4
|
+
import { getEventMeta, experimental_HibernationEventIterator } from '@orpc/standard-server';
|
5
|
+
export { experimental_HibernationEventIterator } from '@orpc/standard-server';
|
6
|
+
import { MessageType } from '@orpc/standard-server-peer';
|
7
|
+
|
8
|
+
function experimental_encodeHibernationRPCEvent(id, payload, options = {}) {
|
9
|
+
const { event = "message", ...rest } = options;
|
10
|
+
const serializer = new StandardRPCJsonSerializer(rest);
|
11
|
+
const data = event === "error" ? toORPCError(payload).toJSON() : payload;
|
12
|
+
const [json, meta] = serializer.serialize(data);
|
13
|
+
return stringifyJSON({
|
14
|
+
i: id,
|
15
|
+
t: MessageType.EVENT_ITERATOR,
|
16
|
+
p: {
|
17
|
+
e: event,
|
18
|
+
d: { json, meta: meta.length > 0 ? meta : void 0 },
|
19
|
+
m: getEventMeta(payload)
|
20
|
+
}
|
21
|
+
});
|
22
|
+
}
|
23
|
+
|
24
|
+
class experimental_HibernationPlugin {
|
25
|
+
CONTEXT_SYMBOL = Symbol("ORPC_HIBERNATION_CONTEXT");
|
26
|
+
order = 2e6;
|
27
|
+
// make sure execute after the batch plugin
|
28
|
+
init(options, _router) {
|
29
|
+
options.interceptors ??= [];
|
30
|
+
options.clientInterceptors ??= [];
|
31
|
+
options.interceptors.unshift(async (options2) => {
|
32
|
+
const hibernationContext = {};
|
33
|
+
const result = await options2.next({
|
34
|
+
...options2,
|
35
|
+
context: {
|
36
|
+
[this.CONTEXT_SYMBOL]: hibernationContext,
|
37
|
+
...options2.context
|
38
|
+
}
|
39
|
+
});
|
40
|
+
if (!result.matched || !hibernationContext.iterator) {
|
41
|
+
return result;
|
42
|
+
}
|
43
|
+
return {
|
44
|
+
...result,
|
45
|
+
response: {
|
46
|
+
...result.response,
|
47
|
+
body: hibernationContext.iterator
|
48
|
+
}
|
49
|
+
};
|
50
|
+
});
|
51
|
+
options.clientInterceptors.unshift(async (options2) => {
|
52
|
+
const hibernationContext = options2.context[this.CONTEXT_SYMBOL];
|
53
|
+
if (!hibernationContext) {
|
54
|
+
throw new TypeError("[HibernationPlugin] Hibernation context has been corrupted or modified by another plugin or interceptor");
|
55
|
+
}
|
56
|
+
const output = await options2.next();
|
57
|
+
if (output instanceof experimental_HibernationEventIterator) {
|
58
|
+
hibernationContext.iterator = output;
|
59
|
+
}
|
60
|
+
return output;
|
61
|
+
});
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
export { experimental_HibernationPlugin, experimental_encodeHibernationRPCEvent };
|
package/dist/index.d.mts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, ClientPromiseResult } from '@orpc/client';
|
1
|
+
import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, HTTPMethod, ClientOptions, ClientPromiseResult } from '@orpc/client';
|
2
2
|
export { ClientContext, HTTPMethod, HTTPPath, ORPCError, isDefinedError, safe } from '@orpc/client';
|
3
3
|
import { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, ErrorFromErrorMap, Meta, MergedErrorMap, Route, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, Schema, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta } from '@orpc/contract';
|
4
4
|
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type } from '@orpc/contract';
|
@@ -510,7 +510,7 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
|
|
510
510
|
/**
|
511
511
|
* Sets or overrides the config.
|
512
512
|
*
|
513
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
513
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side#middlewares-order Middlewares Order Docs}
|
514
514
|
* @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
515
515
|
*/
|
516
516
|
$config(config: BuilderConfig): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
@@ -730,9 +730,9 @@ interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitial
|
|
730
730
|
default: U;
|
731
731
|
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
732
732
|
}
|
733
|
-
type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> =
|
733
|
+
type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementerWithMiddlewares<TContract, TInitialContext, TCurrentContext> & {
|
734
734
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
|
735
|
-
}
|
735
|
+
};
|
736
736
|
|
737
737
|
interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
738
738
|
/**
|
@@ -768,9 +768,9 @@ interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends
|
|
768
768
|
default: U;
|
769
769
|
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
770
770
|
}
|
771
|
-
type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> =
|
771
|
+
type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementer<TContract, TInitialContext, TCurrentContext> & {
|
772
772
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
|
773
|
-
}
|
773
|
+
};
|
774
774
|
declare function implementerInternal<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: T, config: BuilderConfig, middlewares: AnyMiddleware[]): ImplementerInternal<T, TInitialContext, TCurrentContext>;
|
775
775
|
type Implementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = {
|
776
776
|
/**
|
@@ -782,13 +782,18 @@ type Implementer<TContract extends AnyContractRouter, TInitialContext extends Co
|
|
782
782
|
/**
|
783
783
|
* Sets or overrides the config.
|
784
784
|
*
|
785
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
785
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side#middlewares-order Middlewares Order Docs}
|
786
786
|
* @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
787
787
|
*/
|
788
788
|
$config(config: BuilderConfig): Implementer<TContract, TInitialContext, TCurrentContext>;
|
789
789
|
} & ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
|
790
790
|
declare function implement<T extends AnyContractRouter, TContext extends Context = Record<never, never>>(contract: T, config?: BuilderConfig): Implementer<T, TContext, TContext>;
|
791
791
|
|
792
|
+
/**
|
793
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the router.
|
794
|
+
*/
|
795
|
+
declare function inferRPCMethodFromRouter(router: AnyRouter): (options: unknown, path: readonly string[]) => Promise<Exclude<HTTPMethod, 'HEAD'>>;
|
796
|
+
|
792
797
|
declare function isStartWithMiddlewares(middlewares: readonly AnyMiddleware[], compare: readonly AnyMiddleware[]): boolean;
|
793
798
|
declare function mergeMiddlewares(first: readonly AnyMiddleware[], second: readonly AnyMiddleware[], options: {
|
794
799
|
dedupeLeading: boolean;
|
@@ -810,7 +815,7 @@ declare function createContractedProcedure(procedure: AnyProcedure, contract: An
|
|
810
815
|
* ```
|
811
816
|
*
|
812
817
|
*/
|
813
|
-
declare function call<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, input: InferSchemaInput<TInputSchema>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never
|
818
|
+
declare function call<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, input: InferSchemaInput<TInputSchema>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never>> & Omit<ClientOptions<Record<never, never>>, 'context'>>): ClientPromiseResult<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
814
819
|
|
815
820
|
type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
816
821
|
[K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never;
|
@@ -825,5 +830,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
|
|
825
830
|
declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
|
826
831
|
declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
|
827
832
|
|
828
|
-
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createActionableClient, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
|
833
|
+
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createActionableClient, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getHiddenRouterContract, getRouter, implement, implementerInternal, inferRPCMethodFromRouter, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
|
829
834
|
export type { AccessibleLazyRouter, ActionableClient, ActionableClientRest, ActionableClientResult, ActionableError, BuilderConfig, BuilderDef, BuilderWithMiddlewares, Config, ContractProcedureCallbackOptions, DecoratedMiddleware, EnhanceRouterOptions, EnhancedRouter, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, LazyTraverseContractProceduresOptions, ProcedureActionableClient, ProcedureBuilder, ProcedureBuilderWithInput, ProcedureBuilderWithInputOutput, ProcedureBuilderWithOutput, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, TraverseContractProceduresOptions, UnactionableError, UnlaziedRouter };
|
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, ClientPromiseResult } from '@orpc/client';
|
1
|
+
import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, HTTPMethod, ClientOptions, ClientPromiseResult } from '@orpc/client';
|
2
2
|
export { ClientContext, HTTPMethod, HTTPPath, ORPCError, isDefinedError, safe } from '@orpc/client';
|
3
3
|
import { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, ErrorFromErrorMap, Meta, MergedErrorMap, Route, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, Schema, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta } from '@orpc/contract';
|
4
4
|
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type } from '@orpc/contract';
|
@@ -510,7 +510,7 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
|
|
510
510
|
/**
|
511
511
|
* Sets or overrides the config.
|
512
512
|
*
|
513
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
513
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side#middlewares-order Middlewares Order Docs}
|
514
514
|
* @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
515
515
|
*/
|
516
516
|
$config(config: BuilderConfig): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
@@ -730,9 +730,9 @@ interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitial
|
|
730
730
|
default: U;
|
731
731
|
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
732
732
|
}
|
733
|
-
type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> =
|
733
|
+
type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementerWithMiddlewares<TContract, TInitialContext, TCurrentContext> & {
|
734
734
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
|
735
|
-
}
|
735
|
+
};
|
736
736
|
|
737
737
|
interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
738
738
|
/**
|
@@ -768,9 +768,9 @@ interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends
|
|
768
768
|
default: U;
|
769
769
|
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
770
770
|
}
|
771
|
-
type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> =
|
771
|
+
type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementer<TContract, TInitialContext, TCurrentContext> & {
|
772
772
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
|
773
|
-
}
|
773
|
+
};
|
774
774
|
declare function implementerInternal<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: T, config: BuilderConfig, middlewares: AnyMiddleware[]): ImplementerInternal<T, TInitialContext, TCurrentContext>;
|
775
775
|
type Implementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = {
|
776
776
|
/**
|
@@ -782,13 +782,18 @@ type Implementer<TContract extends AnyContractRouter, TInitialContext extends Co
|
|
782
782
|
/**
|
783
783
|
* Sets or overrides the config.
|
784
784
|
*
|
785
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
785
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side#middlewares-order Middlewares Order Docs}
|
786
786
|
* @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
787
787
|
*/
|
788
788
|
$config(config: BuilderConfig): Implementer<TContract, TInitialContext, TCurrentContext>;
|
789
789
|
} & ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
|
790
790
|
declare function implement<T extends AnyContractRouter, TContext extends Context = Record<never, never>>(contract: T, config?: BuilderConfig): Implementer<T, TContext, TContext>;
|
791
791
|
|
792
|
+
/**
|
793
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the router.
|
794
|
+
*/
|
795
|
+
declare function inferRPCMethodFromRouter(router: AnyRouter): (options: unknown, path: readonly string[]) => Promise<Exclude<HTTPMethod, 'HEAD'>>;
|
796
|
+
|
792
797
|
declare function isStartWithMiddlewares(middlewares: readonly AnyMiddleware[], compare: readonly AnyMiddleware[]): boolean;
|
793
798
|
declare function mergeMiddlewares(first: readonly AnyMiddleware[], second: readonly AnyMiddleware[], options: {
|
794
799
|
dedupeLeading: boolean;
|
@@ -810,7 +815,7 @@ declare function createContractedProcedure(procedure: AnyProcedure, contract: An
|
|
810
815
|
* ```
|
811
816
|
*
|
812
817
|
*/
|
813
|
-
declare function call<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, input: InferSchemaInput<TInputSchema>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never
|
818
|
+
declare function call<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, input: InferSchemaInput<TInputSchema>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never>> & Omit<ClientOptions<Record<never, never>>, 'context'>>): ClientPromiseResult<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
814
819
|
|
815
820
|
type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
816
821
|
[K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never;
|
@@ -825,5 +830,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
|
|
825
830
|
declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
|
826
831
|
declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
|
827
832
|
|
828
|
-
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createActionableClient, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
|
833
|
+
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createActionableClient, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getHiddenRouterContract, getRouter, implement, implementerInternal, inferRPCMethodFromRouter, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
|
829
834
|
export type { AccessibleLazyRouter, ActionableClient, ActionableClientRest, ActionableClientResult, ActionableError, BuilderConfig, BuilderDef, BuilderWithMiddlewares, Config, ContractProcedureCallbackOptions, DecoratedMiddleware, EnhanceRouterOptions, EnhancedRouter, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, LazyTraverseContractProceduresOptions, ProcedureActionableClient, ProcedureBuilder, ProcedureBuilderWithInput, ProcedureBuilderWithInputOutput, ProcedureBuilderWithOutput, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, TraverseContractProceduresOptions, UnactionableError, UnlaziedRouter };
|
package/dist/index.mjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
|
1
|
+
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter, fallbackContractConfig } from '@orpc/contract';
|
2
2
|
export { ValidationError, eventIterator, type } from '@orpc/contract';
|
3
|
-
import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure
|
4
|
-
export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, w as resolveContractProcedures, t as traverseContractProcedures,
|
3
|
+
import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, u as unlazy, g as getRouter, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure } from './shared/server.DLJzqnSX.mjs';
|
4
|
+
export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, w as resolveContractProcedures, t as traverseContractProcedures, x as unlazyRouter, v as validateORPCError } from './shared/server.DLJzqnSX.mjs';
|
5
5
|
import { toORPCError } from '@orpc/client';
|
6
6
|
export { ORPCError, isDefinedError, safe } from '@orpc/client';
|
7
7
|
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
@@ -151,7 +151,7 @@ class Builder {
|
|
151
151
|
/**
|
152
152
|
* Sets or overrides the config.
|
153
153
|
*
|
154
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
154
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side#middlewares-order Middlewares Order Docs}
|
155
155
|
* @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
156
156
|
*/
|
157
157
|
$config(config) {
|
@@ -448,6 +448,19 @@ function implement(contract, config = {}) {
|
|
448
448
|
return impl;
|
449
449
|
}
|
450
450
|
|
451
|
+
function inferRPCMethodFromRouter(router) {
|
452
|
+
return async (_, path) => {
|
453
|
+
const { default: procedure } = await unlazy(getRouter(router, path));
|
454
|
+
if (!isProcedure(procedure)) {
|
455
|
+
throw new Error(
|
456
|
+
`[inferRPCMethodFromRouter] No valid procedure found at path "${path.join(".")}". This may happen when the router is not properly configured.`
|
457
|
+
);
|
458
|
+
}
|
459
|
+
const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
|
460
|
+
return method === "HEAD" ? "GET" : method;
|
461
|
+
};
|
462
|
+
}
|
463
|
+
|
451
464
|
function createRouterClient(router, ...rest) {
|
452
465
|
if (isProcedure(router)) {
|
453
466
|
const caller = createProcedureClient(router, resolveMaybeOptionalOptions(rest));
|
@@ -472,4 +485,4 @@ function createRouterClient(router, ...rest) {
|
|
472
485
|
return recursive;
|
473
486
|
}
|
474
487
|
|
475
|
-
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
|
488
|
+
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, inferRPCMethodFromRouter, isLazy, isProcedure, lazy, os, setHiddenRouterContract, unlazy };
|
package/dist/plugins/index.mjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { value, isAsyncIteratorObject } from '@orpc/shared';
|
1
|
+
import { value, isAsyncIteratorObject, clone } from '@orpc/shared';
|
2
2
|
import { flattenHeader } from '@orpc/standard-server';
|
3
3
|
import { parseBatchRequest, toBatchResponse } from '@orpc/standard-server/batch';
|
4
4
|
import { ORPCError } from '@orpc/client';
|
@@ -192,7 +192,7 @@ class ResponseHeadersPlugin {
|
|
192
192
|
if (!result.matched) {
|
193
193
|
return result;
|
194
194
|
}
|
195
|
-
const responseHeaders = result.response.headers;
|
195
|
+
const responseHeaders = clone(result.response.headers);
|
196
196
|
for (const [key, value] of resHeaders) {
|
197
197
|
if (Array.isArray(responseHeaders[key])) {
|
198
198
|
responseHeaders[key].push(value);
|
@@ -202,7 +202,13 @@ class ResponseHeadersPlugin {
|
|
202
202
|
responseHeaders[key] = value;
|
203
203
|
}
|
204
204
|
}
|
205
|
-
return
|
205
|
+
return {
|
206
|
+
...result,
|
207
|
+
response: {
|
208
|
+
...result.response,
|
209
|
+
headers: responseHeaders
|
210
|
+
}
|
211
|
+
};
|
206
212
|
});
|
207
213
|
}
|
208
214
|
}
|
@@ -2,7 +2,7 @@ import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@o
|
|
2
2
|
import { ORPCError, toORPCError } from '@orpc/client';
|
3
3
|
import { toArray, intercept, parseEmptyableJSON, NullProtoObj } from '@orpc/shared';
|
4
4
|
import { flattenHeader } from '@orpc/standard-server';
|
5
|
-
import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.
|
5
|
+
import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.DLJzqnSX.mjs';
|
6
6
|
|
7
7
|
class CompositeStandardHandlerPlugin {
|
8
8
|
plugins;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
|
2
|
+
import { value, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
2
3
|
import { fallbackORPCErrorStatus, ORPCError } from '@orpc/client';
|
3
|
-
import { value, intercept } from '@orpc/shared';
|
4
4
|
|
5
5
|
const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
|
6
6
|
function lazy(loader, meta = {}) {
|
@@ -361,7 +361,8 @@ function createContractedProcedure(procedure, contract) {
|
|
361
361
|
});
|
362
362
|
}
|
363
363
|
function call(procedure, input, ...rest) {
|
364
|
-
|
364
|
+
const options = resolveMaybeOptionalOptions(rest);
|
365
|
+
return createProcedureClient(procedure, options)(input, options);
|
365
366
|
}
|
366
367
|
|
367
368
|
export { LAZY_SYMBOL as L, Procedure as P, createContractedProcedure as a, addMiddleware as b, createProcedureClient as c, isLazy as d, enhanceRouter as e, createAssertedLazyProcedure as f, getRouter as g, createORPCErrorConstructorMap as h, isProcedure as i, getLazyMeta as j, middlewareOutputFn as k, lazy as l, mergeCurrentContext as m, isStartWithMiddlewares as n, mergeMiddlewares as o, call as p, getHiddenRouterContract as q, createAccessibleLazyRouter as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, validateORPCError as v, resolveContractProcedures as w, unlazyRouter as x };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.dda04c5",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -24,6 +24,11 @@
|
|
24
24
|
"import": "./dist/plugins/index.mjs",
|
25
25
|
"default": "./dist/plugins/index.mjs"
|
26
26
|
},
|
27
|
+
"./hibernation": {
|
28
|
+
"types": "./dist/hibernation/index.d.mts",
|
29
|
+
"import": "./dist/hibernation/index.mjs",
|
30
|
+
"default": "./dist/hibernation/index.mjs"
|
31
|
+
},
|
27
32
|
"./standard": {
|
28
33
|
"types": "./dist/adapters/standard/index.d.mts",
|
29
34
|
"import": "./dist/adapters/standard/index.mjs",
|
@@ -86,21 +91,21 @@
|
|
86
91
|
}
|
87
92
|
},
|
88
93
|
"dependencies": {
|
89
|
-
"@orpc/client": "0.0.0-next.
|
90
|
-
"@orpc/contract": "0.0.0-next.
|
91
|
-
"@orpc/
|
92
|
-
"@orpc/
|
93
|
-
"@orpc/standard-server
|
94
|
-
"@orpc/standard-server-
|
95
|
-
"@orpc/standard-server-
|
96
|
-
"@orpc/standard-server-
|
94
|
+
"@orpc/client": "0.0.0-next.dda04c5",
|
95
|
+
"@orpc/contract": "0.0.0-next.dda04c5",
|
96
|
+
"@orpc/shared": "0.0.0-next.dda04c5",
|
97
|
+
"@orpc/standard-server-aws-lambda": "0.0.0-next.dda04c5",
|
98
|
+
"@orpc/standard-server": "0.0.0-next.dda04c5",
|
99
|
+
"@orpc/standard-server-fetch": "0.0.0-next.dda04c5",
|
100
|
+
"@orpc/standard-server-peer": "0.0.0-next.dda04c5",
|
101
|
+
"@orpc/standard-server-node": "0.0.0-next.dda04c5"
|
97
102
|
},
|
98
103
|
"devDependencies": {
|
99
104
|
"@types/ws": "^8.18.1",
|
100
105
|
"crossws": "^0.4.1",
|
101
|
-
"next": "^15.3.
|
106
|
+
"next": "^15.3.4",
|
102
107
|
"supertest": "^7.1.0",
|
103
|
-
"ws": "^8.18.
|
108
|
+
"ws": "^8.18.3"
|
104
109
|
},
|
105
110
|
"scripts": {
|
106
111
|
"build": "unbuild",
|