@orpc/server 2.0.0-beta.4 → 2.0.0-beta.40
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 +97 -94
- package/dist/adapters/aws-lambda/index.d.mts +50 -0
- package/dist/adapters/aws-lambda/index.d.ts +50 -0
- package/dist/adapters/aws-lambda/index.mjs +39 -0
- package/dist/adapters/crossws/index.d.mts +21 -12
- package/dist/adapters/crossws/index.d.ts +21 -12
- package/dist/adapters/crossws/index.mjs +14 -10
- package/dist/adapters/fastify/index.d.mts +42 -0
- package/dist/adapters/fastify/index.d.ts +42 -0
- package/dist/adapters/fastify/index.mjs +39 -0
- package/dist/adapters/fetch/index.d.mts +21 -114
- package/dist/adapters/fetch/index.d.ts +21 -114
- package/dist/adapters/fetch/index.mjs +20 -182
- package/dist/adapters/message-port/index.d.mts +23 -20
- package/dist/adapters/message-port/index.d.ts +23 -20
- package/dist/adapters/message-port/index.mjs +31 -34
- package/dist/adapters/node/index.d.mts +19 -96
- package/dist/adapters/node/index.d.ts +19 -96
- package/dist/adapters/node/index.mjs +19 -157
- package/dist/adapters/standard/index.d.mts +91 -17
- package/dist/adapters/standard/index.d.ts +91 -17
- package/dist/adapters/standard/index.mjs +4 -4
- package/dist/adapters/standard-peer/index.d.mts +6 -11
- package/dist/adapters/standard-peer/index.d.ts +6 -11
- package/dist/adapters/standard-peer/index.mjs +10 -2
- package/dist/adapters/websocket/index.d.mts +45 -29
- package/dist/adapters/websocket/index.d.ts +45 -29
- package/dist/adapters/websocket/index.mjs +37 -28
- package/dist/extensions/callable.d.mts +5 -5
- package/dist/extensions/callable.d.ts +5 -5
- package/dist/extensions/callable.mjs +2 -2
- package/dist/helpers/index.d.mts +23 -6
- package/dist/helpers/index.d.ts +23 -6
- package/dist/helpers/index.mjs +13 -5
- package/dist/index.d.mts +332 -37
- package/dist/index.d.ts +332 -37
- package/dist/index.mjs +131 -49
- package/dist/plugins/index.d.mts +243 -31
- package/dist/plugins/index.d.ts +243 -31
- package/dist/plugins/index.mjs +527 -30
- package/dist/shared/server.1ExWFMze.mjs +69 -0
- package/dist/shared/{server.CjOb6ItT.mjs → server.24nXyhbl.mjs} +1 -1
- package/dist/shared/{server.DBANIheG.d.ts → server.B5K1CViq.d.mts} +24 -13
- package/dist/shared/{server.BsNNjG5J.d.mts → server.BpmUhems.d.mts} +32 -20
- package/dist/shared/{server.BL22TloH.d.mts → server.BsujoJoF.d.mts} +38 -59
- package/dist/shared/{server.BL22TloH.d.ts → server.BsujoJoF.d.ts} +38 -59
- package/dist/shared/{server.BwHnWUuN.mjs → server.BynNaBBA.mjs} +24 -19
- package/dist/shared/{server.GDpX6Df8.mjs → server.C0lFtoHU.mjs} +162 -68
- package/dist/shared/server.C7xllBNN.d.mts +34 -0
- package/dist/shared/server.CFqSIFnT.d.mts +14 -0
- package/dist/shared/{server.Pa0F03f_.d.ts → server.CRwPbhLO.d.ts} +32 -20
- package/dist/shared/{server.DJIkub_t.d.mts → server.Cxranw-8.d.ts} +24 -13
- package/dist/shared/server.D0dr-F8u.d.ts +34 -0
- package/dist/shared/{server.CrlKQucM.mjs → server.Djb_ebJT.mjs} +25 -53
- package/dist/shared/server.RRVK1xTV.d.ts +14 -0
- package/package.json +47 -14
- package/dist/shared/server.CX4vUnDk.mjs +0 -11
- package/dist/shared/server.Cj5lgPuG.d.mts +0 -66
- package/dist/shared/server.D_QauotT.mjs +0 -30
- package/dist/shared/server.d_2NS3g5.d.ts +0 -66
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { Arrayable, MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standard-server/peer';
|
|
3
|
+
import { Context } from '../../index.mjs';
|
|
4
|
+
import { StandardHandler, StandardHandlerOptions } from '../standard/index.mjs';
|
|
5
|
+
import { FriendlyStandardHandlerHandleOptions } from '../standard/index.mjs';
|
|
6
|
+
import { Router } from '../../index.mjs';
|
|
7
|
+
import { RPCHandlerCodecOptions } from '../standard/index.mjs';
|
|
8
8
|
import '@orpc/client';
|
|
9
9
|
import '@orpc/contract';
|
|
10
|
-
import '@
|
|
10
|
+
import '@standard-server/core';
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Supports standard WebSocket instances, Bun ServerWebSocket, "ws" ServerWebSocket,
|
|
14
|
+
* Cloudflare WebSocket Hibernation, and similar implementations.
|
|
15
|
+
*/
|
|
16
|
+
type WebSocketLike = {
|
|
17
|
+
send: (data: string | Uint8Array<ArrayBuffer>) => unknown;
|
|
18
|
+
};
|
|
19
|
+
interface WebSocketHandlerOptions<_T extends Context> {
|
|
14
20
|
/**
|
|
15
21
|
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
16
22
|
*/
|
|
@@ -20,42 +26,52 @@ interface WebsocketHandlerOptions<_T extends Context> {
|
|
|
20
26
|
*/
|
|
21
27
|
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
22
28
|
}
|
|
23
|
-
declare class
|
|
29
|
+
declare class WebSocketHandler<T extends Context> {
|
|
24
30
|
private readonly handler;
|
|
25
31
|
private readonly peers;
|
|
26
32
|
private readonly encodePeerMessageOptions;
|
|
27
33
|
private readonly decodePeerMessageOptions;
|
|
28
|
-
constructor(handler: StandardHandler<T>, options?: NoInfer<
|
|
34
|
+
constructor(handler: StandardHandler<T>, options?: NoInfer<WebSocketHandlerOptions<T>>);
|
|
29
35
|
/**
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* Handles a single message received from a WebSocket.
|
|
36
|
+
* Handles a single WebSocket message.
|
|
37
|
+
*
|
|
38
|
+
* Message order matters. Call this immediately after receiving a message,
|
|
39
|
+
* before any other async work, to preserve ordering.
|
|
35
40
|
*
|
|
36
|
-
*
|
|
41
|
+
* To avoid async Blob reads, configure `ws.binaryType` to return binary data
|
|
42
|
+
* directly (for example, `arraybuffer`).
|
|
37
43
|
*
|
|
38
|
-
* @param ws The WebSocket instance
|
|
39
|
-
* @param data The message data
|
|
44
|
+
* @param ws The WebSocket instance. Use the same instance for all messages.
|
|
45
|
+
* @param data The received message. Binary data should already be loaded (not a `Blob`).
|
|
40
46
|
*/
|
|
41
|
-
message(ws:
|
|
47
|
+
message(ws: WebSocketLike, data: Arrayable<string | ArrayBuffer | Pick<Uint8Array<ArrayBuffer>, 'buffer' | 'byteOffset' | 'byteLength'>>, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<{
|
|
42
48
|
matched: boolean;
|
|
43
49
|
}>;
|
|
44
50
|
/**
|
|
45
|
-
*
|
|
51
|
+
* Cleans up peer state for a closed WebSocket.
|
|
46
52
|
*
|
|
47
|
-
* @
|
|
53
|
+
* @param ws The same WebSocket instance passed to `.message()`.
|
|
54
|
+
*/
|
|
55
|
+
close(ws: WebSocketLike): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Attaches message and close event listeners to a WebSocket.
|
|
48
58
|
*
|
|
49
|
-
*
|
|
59
|
+
* Prefer this over calling `.message()` and `.close()` manually.
|
|
50
60
|
*/
|
|
51
|
-
|
|
61
|
+
upgrade(ws: Pick<WebSocket, 'send' | 'addEventListener' | 'removeEventListener'>, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): void;
|
|
52
62
|
}
|
|
53
63
|
|
|
54
|
-
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>,
|
|
64
|
+
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebSocketHandlerOptions<T> {
|
|
55
65
|
}
|
|
56
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Serves an oRPC router over the RPC protocol on a standard WebSocket
|
|
68
|
+
* connection (Deno, Bun, Cloudflare Durable Objects, and more).
|
|
69
|
+
*
|
|
70
|
+
* @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
|
|
71
|
+
*/
|
|
72
|
+
declare class RPCHandler<T extends Context> extends WebSocketHandler<T> {
|
|
57
73
|
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
58
74
|
}
|
|
59
75
|
|
|
60
|
-
export { RPCHandler,
|
|
61
|
-
export type { RPCHandlerOptions,
|
|
76
|
+
export { RPCHandler, WebSocketHandler };
|
|
77
|
+
export type { RPCHandlerOptions, WebSocketHandlerOptions, WebSocketLike };
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { Arrayable, MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standard-server/peer';
|
|
3
|
+
import { Context } from '../../index.js';
|
|
4
|
+
import { StandardHandler, StandardHandlerOptions } from '../standard/index.js';
|
|
5
|
+
import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
|
|
6
|
+
import { Router } from '../../index.js';
|
|
7
|
+
import { RPCHandlerCodecOptions } from '../standard/index.js';
|
|
8
8
|
import '@orpc/client';
|
|
9
9
|
import '@orpc/contract';
|
|
10
|
-
import '@
|
|
10
|
+
import '@standard-server/core';
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Supports standard WebSocket instances, Bun ServerWebSocket, "ws" ServerWebSocket,
|
|
14
|
+
* Cloudflare WebSocket Hibernation, and similar implementations.
|
|
15
|
+
*/
|
|
16
|
+
type WebSocketLike = {
|
|
17
|
+
send: (data: string | Uint8Array<ArrayBuffer>) => unknown;
|
|
18
|
+
};
|
|
19
|
+
interface WebSocketHandlerOptions<_T extends Context> {
|
|
14
20
|
/**
|
|
15
21
|
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
16
22
|
*/
|
|
@@ -20,42 +26,52 @@ interface WebsocketHandlerOptions<_T extends Context> {
|
|
|
20
26
|
*/
|
|
21
27
|
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
22
28
|
}
|
|
23
|
-
declare class
|
|
29
|
+
declare class WebSocketHandler<T extends Context> {
|
|
24
30
|
private readonly handler;
|
|
25
31
|
private readonly peers;
|
|
26
32
|
private readonly encodePeerMessageOptions;
|
|
27
33
|
private readonly decodePeerMessageOptions;
|
|
28
|
-
constructor(handler: StandardHandler<T>, options?: NoInfer<
|
|
34
|
+
constructor(handler: StandardHandler<T>, options?: NoInfer<WebSocketHandlerOptions<T>>);
|
|
29
35
|
/**
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* Handles a single message received from a WebSocket.
|
|
36
|
+
* Handles a single WebSocket message.
|
|
37
|
+
*
|
|
38
|
+
* Message order matters. Call this immediately after receiving a message,
|
|
39
|
+
* before any other async work, to preserve ordering.
|
|
35
40
|
*
|
|
36
|
-
*
|
|
41
|
+
* To avoid async Blob reads, configure `ws.binaryType` to return binary data
|
|
42
|
+
* directly (for example, `arraybuffer`).
|
|
37
43
|
*
|
|
38
|
-
* @param ws The WebSocket instance
|
|
39
|
-
* @param data The message data
|
|
44
|
+
* @param ws The WebSocket instance. Use the same instance for all messages.
|
|
45
|
+
* @param data The received message. Binary data should already be loaded (not a `Blob`).
|
|
40
46
|
*/
|
|
41
|
-
message(ws:
|
|
47
|
+
message(ws: WebSocketLike, data: Arrayable<string | ArrayBuffer | Pick<Uint8Array<ArrayBuffer>, 'buffer' | 'byteOffset' | 'byteLength'>>, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<{
|
|
42
48
|
matched: boolean;
|
|
43
49
|
}>;
|
|
44
50
|
/**
|
|
45
|
-
*
|
|
51
|
+
* Cleans up peer state for a closed WebSocket.
|
|
46
52
|
*
|
|
47
|
-
* @
|
|
53
|
+
* @param ws The same WebSocket instance passed to `.message()`.
|
|
54
|
+
*/
|
|
55
|
+
close(ws: WebSocketLike): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Attaches message and close event listeners to a WebSocket.
|
|
48
58
|
*
|
|
49
|
-
*
|
|
59
|
+
* Prefer this over calling `.message()` and `.close()` manually.
|
|
50
60
|
*/
|
|
51
|
-
|
|
61
|
+
upgrade(ws: Pick<WebSocket, 'send' | 'addEventListener' | 'removeEventListener'>, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): void;
|
|
52
62
|
}
|
|
53
63
|
|
|
54
|
-
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>,
|
|
64
|
+
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebSocketHandlerOptions<T> {
|
|
55
65
|
}
|
|
56
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Serves an oRPC router over the RPC protocol on a standard WebSocket
|
|
68
|
+
* connection (Deno, Bun, Cloudflare Durable Objects, and more).
|
|
69
|
+
*
|
|
70
|
+
* @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
|
|
71
|
+
*/
|
|
72
|
+
declare class RPCHandler<T extends Context> extends WebSocketHandler<T> {
|
|
57
73
|
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
58
74
|
}
|
|
59
75
|
|
|
60
|
-
export { RPCHandler,
|
|
61
|
-
export type { RPCHandlerOptions,
|
|
76
|
+
export { RPCHandler, WebSocketHandler };
|
|
77
|
+
export type { RPCHandlerOptions, WebSocketHandlerOptions, WebSocketLike };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { toStringOrBytes, resolveMaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import { ServerPeer, encodePeerMessage, decodePeerMessage, isClientPeerSendMessage } from '@
|
|
3
|
-
import {
|
|
4
|
-
import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.
|
|
1
|
+
import { toStringOrBytes, resolveMaybeOptionalOptions, sequential, loadBytes } from '@orpc/shared';
|
|
2
|
+
import { ServerPeer, encodePeerMessage, decodePeerMessage, isClientPeerSendMessage } from '@standard-server/peer';
|
|
3
|
+
import { createStandardPeerRequestHandler } from '../standard-peer/index.mjs';
|
|
4
|
+
import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.C0lFtoHU.mjs';
|
|
5
|
+
import '../../shared/server.W91HSRkE.mjs';
|
|
5
6
|
import '@orpc/client';
|
|
6
|
-
import '@
|
|
7
|
-
import '../../shared/server.
|
|
7
|
+
import '@standard-server/core';
|
|
8
|
+
import '../../shared/server.Djb_ebJT.mjs';
|
|
8
9
|
import '@orpc/contract';
|
|
9
|
-
import '../../shared/server.
|
|
10
|
+
import '../../shared/server.BynNaBBA.mjs';
|
|
10
11
|
|
|
11
|
-
class
|
|
12
|
+
class WebSocketHandler {
|
|
12
13
|
constructor(handler, options = {}) {
|
|
13
14
|
this.handler = handler;
|
|
14
15
|
this.encodePeerMessageOptions = options.encodePeerMessage;
|
|
@@ -18,28 +19,26 @@ class WebsocketHandler {
|
|
|
18
19
|
encodePeerMessageOptions;
|
|
19
20
|
decodePeerMessageOptions;
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
ws.addEventListener("close", () => this.close(ws));
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Handles a single message received from a WebSocket.
|
|
22
|
+
* Handles a single WebSocket message.
|
|
23
|
+
*
|
|
24
|
+
* Message order matters. Call this immediately after receiving a message,
|
|
25
|
+
* before any other async work, to preserve ordering.
|
|
29
26
|
*
|
|
30
|
-
*
|
|
27
|
+
* To avoid async Blob reads, configure `ws.binaryType` to return binary data
|
|
28
|
+
* directly (for example, `arraybuffer`).
|
|
31
29
|
*
|
|
32
|
-
* @param ws The WebSocket instance
|
|
33
|
-
* @param data The message data
|
|
30
|
+
* @param ws The WebSocket instance. Use the same instance for all messages.
|
|
31
|
+
* @param data The received message. Binary data should already be loaded (not a `Blob`).
|
|
34
32
|
*/
|
|
35
33
|
async message(ws, data, ...rest) {
|
|
36
34
|
let peer = this.peers.get(ws);
|
|
37
35
|
if (!peer) {
|
|
38
36
|
this.peers.set(ws, peer = new ServerPeer(async (message) => {
|
|
39
|
-
|
|
37
|
+
const encoded2 = await encodePeerMessage(message, this.encodePeerMessageOptions);
|
|
38
|
+
await ws.send(encoded2);
|
|
40
39
|
}));
|
|
41
40
|
}
|
|
42
|
-
const encoded =
|
|
41
|
+
const encoded = toStringOrBytes(data);
|
|
43
42
|
const result = decodePeerMessage(encoded, this.decodePeerMessageOptions);
|
|
44
43
|
if (result.matched && isClientPeerSendMessage(result.message)) {
|
|
45
44
|
await peer.message(
|
|
@@ -50,22 +49,32 @@ class WebsocketHandler {
|
|
|
50
49
|
return result;
|
|
51
50
|
}
|
|
52
51
|
/**
|
|
53
|
-
*
|
|
52
|
+
* Cleans up peer state for a closed WebSocket.
|
|
54
53
|
*
|
|
55
|
-
* @
|
|
56
|
-
*
|
|
57
|
-
* @param ws The WebSocket instance to clean up, must be the same instance used in `.message()` calls to properly clean up
|
|
54
|
+
* @param ws The same WebSocket instance passed to `.message()`.
|
|
58
55
|
*/
|
|
59
56
|
async close(ws) {
|
|
60
57
|
const peer = this.peers.get(ws);
|
|
61
58
|
if (peer) {
|
|
62
|
-
await peer.close();
|
|
63
59
|
this.peers.delete(ws);
|
|
60
|
+
await peer.close();
|
|
64
61
|
}
|
|
65
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Attaches message and close event listeners to a WebSocket.
|
|
65
|
+
*
|
|
66
|
+
* Prefer this over calling `.message()` and `.close()` manually.
|
|
67
|
+
*/
|
|
68
|
+
upgrade(ws, ...rest) {
|
|
69
|
+
ws.addEventListener("message", sequential(async (event) => {
|
|
70
|
+
const data = event.data instanceof Blob ? await loadBytes(event.data) : event.data;
|
|
71
|
+
this.message(ws, data, ...rest);
|
|
72
|
+
}));
|
|
73
|
+
ws.addEventListener("close", () => this.close(ws));
|
|
74
|
+
}
|
|
66
75
|
}
|
|
67
76
|
|
|
68
|
-
class RPCHandler extends
|
|
77
|
+
class RPCHandler extends WebSocketHandler {
|
|
69
78
|
constructor(router, options = {}) {
|
|
70
79
|
const codec = new RPCHandlerCodec(router, options);
|
|
71
80
|
const handler = new StandardHandler(codec, options);
|
|
@@ -73,4 +82,4 @@ class RPCHandler extends WebsocketHandler {
|
|
|
73
82
|
}
|
|
74
83
|
}
|
|
75
84
|
|
|
76
|
-
export { RPCHandler,
|
|
85
|
+
export { RPCHandler, WebSocketHandler };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClientContext } from '@orpc/client';
|
|
2
2
|
import { AnySchema, ErrorMap } from '@orpc/contract';
|
|
3
3
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
4
|
-
import {
|
|
4
|
+
import { Context, ProcedureClientOptions, Procedure, ProcedureClient } from '../index.mjs';
|
|
5
5
|
|
|
6
|
-
declare module
|
|
7
|
-
interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap
|
|
8
|
-
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap,
|
|
6
|
+
declare module '@orpc/server' {
|
|
7
|
+
interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
8
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TClientContext>>): Procedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClientContext } from '@orpc/client';
|
|
2
2
|
import { AnySchema, ErrorMap } from '@orpc/contract';
|
|
3
3
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
4
|
-
import {
|
|
4
|
+
import { Context, ProcedureClientOptions, Procedure, ProcedureClient } from '../index.js';
|
|
5
5
|
|
|
6
|
-
declare module
|
|
7
|
-
interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap
|
|
8
|
-
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap,
|
|
6
|
+
declare module '@orpc/server' {
|
|
7
|
+
interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
8
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TClientContext>>): Procedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as createProcedureClient } from '../shared/server.
|
|
2
|
-
import { D as DecoratedProcedure } from '../shared/server.
|
|
1
|
+
import { c as createProcedureClient } from '../shared/server.Djb_ebJT.mjs';
|
|
2
|
+
import { D as DecoratedProcedure } from '../shared/server.24nXyhbl.mjs';
|
|
3
3
|
import '@orpc/client';
|
|
4
4
|
import '@orpc/contract';
|
|
5
5
|
import '@orpc/shared';
|
package/dist/helpers/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParseOptions,
|
|
1
|
+
import { ParseOptions, SetCookie, StringifyOptions } from 'cookie';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Encodes a Uint8Array to base64url format
|
|
@@ -11,6 +11,8 @@ import { ParseOptions, SerializeOptions } from 'cookie';
|
|
|
11
11
|
* const decoded = decodeBase64url(encoded)
|
|
12
12
|
* expect(new TextDecoder().decode(decoded)).toEqual(text)
|
|
13
13
|
* ```
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://orpc.dev/docs/helpers/base64url | Base64Url Helpers}
|
|
14
16
|
*/
|
|
15
17
|
declare function encodeBase64url(data: Uint8Array): string;
|
|
16
18
|
/**
|
|
@@ -24,10 +26,12 @@ declare function encodeBase64url(data: Uint8Array): string;
|
|
|
24
26
|
* const decoded = decodeBase64url(encoded)
|
|
25
27
|
* expect(new TextDecoder().decode(decoded)).toEqual(text)
|
|
26
28
|
* ```
|
|
29
|
+
*
|
|
30
|
+
* @see {@link https://orpc.dev/docs/helpers/base64url | Base64Url Helpers}
|
|
27
31
|
*/
|
|
28
32
|
declare function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefined;
|
|
29
33
|
|
|
30
|
-
interface SetCookieOptions extends
|
|
34
|
+
interface SetCookieOptions extends Omit<SetCookie, 'name' | 'value'>, StringifyOptions {
|
|
31
35
|
/**
|
|
32
36
|
* Specifies the value for the [`Path` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.4).
|
|
33
37
|
*
|
|
@@ -36,7 +40,7 @@ interface SetCookieOptions extends SerializeOptions {
|
|
|
36
40
|
path?: string;
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
|
-
* Sets a cookie in the response headers
|
|
43
|
+
* Sets a cookie in the response headers.
|
|
40
44
|
*
|
|
41
45
|
* Does nothing if `headers` is `undefined`.
|
|
42
46
|
*
|
|
@@ -46,9 +50,10 @@ interface SetCookieOptions extends SerializeOptions {
|
|
|
46
50
|
*
|
|
47
51
|
* setCookie(headers, 'sessionId', 'abc123', { httpOnly: true, maxAge: 3600 })
|
|
48
52
|
*
|
|
49
|
-
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123;
|
|
53
|
+
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123; Max-Age=3600; Path=/; HttpOnly')
|
|
50
54
|
* ```
|
|
51
55
|
*
|
|
56
|
+
* @see {@link https://orpc.dev/docs/helpers/cookie | Cookie Helpers}
|
|
52
57
|
*/
|
|
53
58
|
declare function setCookie(headers: Headers | undefined, name: string, value: string, options?: SetCookieOptions): void;
|
|
54
59
|
interface GetCookieOptions extends ParseOptions {
|
|
@@ -66,10 +71,14 @@ interface GetCookieOptions extends ParseOptions {
|
|
|
66
71
|
*
|
|
67
72
|
* expect(sessionId).toEqual('abc123')
|
|
68
73
|
* ```
|
|
74
|
+
*
|
|
75
|
+
* @see {@link https://orpc.dev/docs/helpers/cookie | Cookie Helpers}
|
|
69
76
|
*/
|
|
70
77
|
declare function getCookie(headers: Headers | undefined, name: string, options?: GetCookieOptions): string | undefined;
|
|
71
78
|
/**
|
|
72
79
|
* Deletes a cookie by marking it expired.
|
|
80
|
+
*
|
|
81
|
+
* @see {@link https://orpc.dev/docs/helpers/cookie | Cookie Helpers}
|
|
73
82
|
*/
|
|
74
83
|
declare function deleteCookie(headers: Headers | undefined, name: string, options?: Omit<SetCookieOptions, 'maxAge'>): void;
|
|
75
84
|
|
|
@@ -83,6 +92,8 @@ declare function deleteCookie(headers: Headers | undefined, name: string, option
|
|
|
83
92
|
* const decrypted = await decrypt(encrypted, "test-secret-key")
|
|
84
93
|
* expect(decrypted).toBe("Hello, World!")
|
|
85
94
|
* ```
|
|
95
|
+
*
|
|
96
|
+
* @see {@link https://orpc.dev/docs/helpers/encryption | Encryption Helpers}
|
|
86
97
|
*/
|
|
87
98
|
declare function encrypt(value: string, secret: string): Promise<string>;
|
|
88
99
|
/**
|
|
@@ -95,6 +106,8 @@ declare function encrypt(value: string, secret: string): Promise<string>;
|
|
|
95
106
|
* const decrypted = await decrypt(encrypted, "test-secret-key")
|
|
96
107
|
* expect(decrypted).toBe("Hello, World!")
|
|
97
108
|
* ```
|
|
109
|
+
*
|
|
110
|
+
* @see {@link https://orpc.dev/docs/helpers/encryption | Encryption Helpers}
|
|
98
111
|
*/
|
|
99
112
|
declare function decrypt(encrypted: string | undefined | null, secret: string): Promise<string | undefined>;
|
|
100
113
|
|
|
@@ -105,12 +118,13 @@ declare function decrypt(encrypted: string | undefined | null, secret: string):
|
|
|
105
118
|
* the integrity and authenticity of the data. The signature is appended to
|
|
106
119
|
* the original value, separated by a dot, using base64url encoding (no padding).
|
|
107
120
|
*
|
|
108
|
-
*
|
|
109
121
|
* @example
|
|
110
122
|
* ```ts
|
|
111
123
|
* const signedValue = await sign("user123", "my-secret-key")
|
|
112
124
|
* expect(signedValue).toEqual("user123.oneQsU0r5dvwQFHFEjjV1uOI_IR3gZfkYHij3TRauVA")
|
|
113
125
|
* ```
|
|
126
|
+
*
|
|
127
|
+
* @see {@link https://orpc.dev/docs/helpers/signing | Signing Helpers}
|
|
114
128
|
*/
|
|
115
129
|
declare function sign(value: string, secret: string): Promise<string>;
|
|
116
130
|
/**
|
|
@@ -120,13 +134,14 @@ declare function sign(value: string, secret: string): Promise<string>;
|
|
|
120
134
|
* secret key. If the signature is valid, it returns the original value. If the
|
|
121
135
|
* signature is invalid or the format is incorrect, it returns undefined.
|
|
122
136
|
*
|
|
123
|
-
*
|
|
124
137
|
* @example
|
|
125
138
|
* ```ts
|
|
126
139
|
* const signedValue = "user123.oneQsU0r5dvwQFHFEjjV1uOI_IR3gZfkYHij3TRauVA"
|
|
127
140
|
* const originalValue = await unsign(signedValue, "my-secret-key")
|
|
128
141
|
* expect(originalValue).toEqual("user123")
|
|
129
142
|
* ```
|
|
143
|
+
*
|
|
144
|
+
* @see {@link https://orpc.dev/docs/helpers/signing | Signing Helpers}
|
|
130
145
|
*/
|
|
131
146
|
declare function unsign(signedValue: string | undefined | null, secret: string): Promise<string | undefined>;
|
|
132
147
|
/**
|
|
@@ -142,6 +157,8 @@ declare function unsign(signedValue: string | undefined | null, secret: string):
|
|
|
142
157
|
* const value = getSignedValue(signedValue)
|
|
143
158
|
* expect(value).toEqual("user123")
|
|
144
159
|
* ```
|
|
160
|
+
*
|
|
161
|
+
* @see {@link https://orpc.dev/docs/helpers/signing | Signing Helpers}
|
|
145
162
|
*/
|
|
146
163
|
declare function getSignedValue(signedValue: string | undefined | null): string | undefined;
|
|
147
164
|
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParseOptions,
|
|
1
|
+
import { ParseOptions, SetCookie, StringifyOptions } from 'cookie';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Encodes a Uint8Array to base64url format
|
|
@@ -11,6 +11,8 @@ import { ParseOptions, SerializeOptions } from 'cookie';
|
|
|
11
11
|
* const decoded = decodeBase64url(encoded)
|
|
12
12
|
* expect(new TextDecoder().decode(decoded)).toEqual(text)
|
|
13
13
|
* ```
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://orpc.dev/docs/helpers/base64url | Base64Url Helpers}
|
|
14
16
|
*/
|
|
15
17
|
declare function encodeBase64url(data: Uint8Array): string;
|
|
16
18
|
/**
|
|
@@ -24,10 +26,12 @@ declare function encodeBase64url(data: Uint8Array): string;
|
|
|
24
26
|
* const decoded = decodeBase64url(encoded)
|
|
25
27
|
* expect(new TextDecoder().decode(decoded)).toEqual(text)
|
|
26
28
|
* ```
|
|
29
|
+
*
|
|
30
|
+
* @see {@link https://orpc.dev/docs/helpers/base64url | Base64Url Helpers}
|
|
27
31
|
*/
|
|
28
32
|
declare function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefined;
|
|
29
33
|
|
|
30
|
-
interface SetCookieOptions extends
|
|
34
|
+
interface SetCookieOptions extends Omit<SetCookie, 'name' | 'value'>, StringifyOptions {
|
|
31
35
|
/**
|
|
32
36
|
* Specifies the value for the [`Path` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.4).
|
|
33
37
|
*
|
|
@@ -36,7 +40,7 @@ interface SetCookieOptions extends SerializeOptions {
|
|
|
36
40
|
path?: string;
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
|
-
* Sets a cookie in the response headers
|
|
43
|
+
* Sets a cookie in the response headers.
|
|
40
44
|
*
|
|
41
45
|
* Does nothing if `headers` is `undefined`.
|
|
42
46
|
*
|
|
@@ -46,9 +50,10 @@ interface SetCookieOptions extends SerializeOptions {
|
|
|
46
50
|
*
|
|
47
51
|
* setCookie(headers, 'sessionId', 'abc123', { httpOnly: true, maxAge: 3600 })
|
|
48
52
|
*
|
|
49
|
-
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123;
|
|
53
|
+
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123; Max-Age=3600; Path=/; HttpOnly')
|
|
50
54
|
* ```
|
|
51
55
|
*
|
|
56
|
+
* @see {@link https://orpc.dev/docs/helpers/cookie | Cookie Helpers}
|
|
52
57
|
*/
|
|
53
58
|
declare function setCookie(headers: Headers | undefined, name: string, value: string, options?: SetCookieOptions): void;
|
|
54
59
|
interface GetCookieOptions extends ParseOptions {
|
|
@@ -66,10 +71,14 @@ interface GetCookieOptions extends ParseOptions {
|
|
|
66
71
|
*
|
|
67
72
|
* expect(sessionId).toEqual('abc123')
|
|
68
73
|
* ```
|
|
74
|
+
*
|
|
75
|
+
* @see {@link https://orpc.dev/docs/helpers/cookie | Cookie Helpers}
|
|
69
76
|
*/
|
|
70
77
|
declare function getCookie(headers: Headers | undefined, name: string, options?: GetCookieOptions): string | undefined;
|
|
71
78
|
/**
|
|
72
79
|
* Deletes a cookie by marking it expired.
|
|
80
|
+
*
|
|
81
|
+
* @see {@link https://orpc.dev/docs/helpers/cookie | Cookie Helpers}
|
|
73
82
|
*/
|
|
74
83
|
declare function deleteCookie(headers: Headers | undefined, name: string, options?: Omit<SetCookieOptions, 'maxAge'>): void;
|
|
75
84
|
|
|
@@ -83,6 +92,8 @@ declare function deleteCookie(headers: Headers | undefined, name: string, option
|
|
|
83
92
|
* const decrypted = await decrypt(encrypted, "test-secret-key")
|
|
84
93
|
* expect(decrypted).toBe("Hello, World!")
|
|
85
94
|
* ```
|
|
95
|
+
*
|
|
96
|
+
* @see {@link https://orpc.dev/docs/helpers/encryption | Encryption Helpers}
|
|
86
97
|
*/
|
|
87
98
|
declare function encrypt(value: string, secret: string): Promise<string>;
|
|
88
99
|
/**
|
|
@@ -95,6 +106,8 @@ declare function encrypt(value: string, secret: string): Promise<string>;
|
|
|
95
106
|
* const decrypted = await decrypt(encrypted, "test-secret-key")
|
|
96
107
|
* expect(decrypted).toBe("Hello, World!")
|
|
97
108
|
* ```
|
|
109
|
+
*
|
|
110
|
+
* @see {@link https://orpc.dev/docs/helpers/encryption | Encryption Helpers}
|
|
98
111
|
*/
|
|
99
112
|
declare function decrypt(encrypted: string | undefined | null, secret: string): Promise<string | undefined>;
|
|
100
113
|
|
|
@@ -105,12 +118,13 @@ declare function decrypt(encrypted: string | undefined | null, secret: string):
|
|
|
105
118
|
* the integrity and authenticity of the data. The signature is appended to
|
|
106
119
|
* the original value, separated by a dot, using base64url encoding (no padding).
|
|
107
120
|
*
|
|
108
|
-
*
|
|
109
121
|
* @example
|
|
110
122
|
* ```ts
|
|
111
123
|
* const signedValue = await sign("user123", "my-secret-key")
|
|
112
124
|
* expect(signedValue).toEqual("user123.oneQsU0r5dvwQFHFEjjV1uOI_IR3gZfkYHij3TRauVA")
|
|
113
125
|
* ```
|
|
126
|
+
*
|
|
127
|
+
* @see {@link https://orpc.dev/docs/helpers/signing | Signing Helpers}
|
|
114
128
|
*/
|
|
115
129
|
declare function sign(value: string, secret: string): Promise<string>;
|
|
116
130
|
/**
|
|
@@ -120,13 +134,14 @@ declare function sign(value: string, secret: string): Promise<string>;
|
|
|
120
134
|
* secret key. If the signature is valid, it returns the original value. If the
|
|
121
135
|
* signature is invalid or the format is incorrect, it returns undefined.
|
|
122
136
|
*
|
|
123
|
-
*
|
|
124
137
|
* @example
|
|
125
138
|
* ```ts
|
|
126
139
|
* const signedValue = "user123.oneQsU0r5dvwQFHFEjjV1uOI_IR3gZfkYHij3TRauVA"
|
|
127
140
|
* const originalValue = await unsign(signedValue, "my-secret-key")
|
|
128
141
|
* expect(originalValue).toEqual("user123")
|
|
129
142
|
* ```
|
|
143
|
+
*
|
|
144
|
+
* @see {@link https://orpc.dev/docs/helpers/signing | Signing Helpers}
|
|
130
145
|
*/
|
|
131
146
|
declare function unsign(signedValue: string | undefined | null, secret: string): Promise<string | undefined>;
|
|
132
147
|
/**
|
|
@@ -142,6 +157,8 @@ declare function unsign(signedValue: string | undefined | null, secret: string):
|
|
|
142
157
|
* const value = getSignedValue(signedValue)
|
|
143
158
|
* expect(value).toEqual("user123")
|
|
144
159
|
* ```
|
|
160
|
+
*
|
|
161
|
+
* @see {@link https://orpc.dev/docs/helpers/signing | Signing Helpers}
|
|
145
162
|
*/
|
|
146
163
|
declare function getSignedValue(signedValue: string | undefined | null): string | undefined;
|
|
147
164
|
|