@orpc/server 1.14.9 → 1.14.11
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 +52 -98
- package/dist/adapters/crossws/index.d.mts +45 -21
- package/dist/adapters/crossws/index.d.ts +45 -21
- package/dist/adapters/crossws/index.mjs +40 -18
- package/dist/adapters/fetch/index.d.mts +64 -96
- package/dist/adapters/fetch/index.d.ts +64 -96
- package/dist/adapters/fetch/index.mjs +34 -139
- package/dist/adapters/message-port/index.d.mts +49 -34
- package/dist/adapters/message-port/index.d.ts +49 -34
- package/dist/adapters/message-port/index.mjs +68 -37
- package/dist/adapters/node/index.d.mts +63 -71
- package/dist/adapters/node/index.d.ts +63 -71
- package/dist/adapters/node/index.mjs +36 -113
- package/dist/adapters/standard/index.d.mts +16 -18
- package/dist/adapters/standard/index.d.ts +16 -18
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/standard-peer/index.d.mts +12 -14
- package/dist/adapters/standard-peer/index.d.ts +12 -14
- package/dist/adapters/standard-peer/index.mjs +2 -21
- package/dist/adapters/websocket/index.d.mts +53 -38
- package/dist/adapters/websocket/index.d.ts +53 -38
- package/dist/adapters/websocket/index.mjs +59 -42
- package/dist/extensions/callable.d.mts +10 -0
- package/dist/extensions/callable.d.ts +10 -0
- package/dist/extensions/callable.mjs +11 -0
- package/dist/helpers/index.d.mts +4 -4
- package/dist/helpers/index.d.ts +4 -4
- package/dist/helpers/index.mjs +13 -5
- package/dist/index.d.mts +166 -770
- package/dist/index.d.ts +166 -770
- package/dist/index.mjs +306 -399
- package/dist/plugins/index.d.mts +214 -121
- package/dist/plugins/index.d.ts +214 -121
- package/dist/plugins/index.mjs +576 -214
- package/dist/shared/server.15O7oC1p.d.mts +61 -0
- package/dist/shared/server.B4BnEWWm.d.mts +67 -0
- package/dist/shared/server.BhsVw7m7.d.ts +104 -0
- package/dist/shared/server.BoiFpNT7.mjs +224 -0
- package/dist/shared/server.COPVXhDG.mjs +271 -0
- package/dist/shared/server.CX4vUnDk.mjs +11 -0
- package/dist/shared/server.CcR4kgje.d.mts +206 -0
- package/dist/shared/server.CcR4kgje.d.ts +206 -0
- package/dist/shared/server.CnN50DHH.d.ts +67 -0
- package/dist/shared/server.DBs0rrf9.mjs +41 -0
- package/dist/shared/server.DDFizwfU.d.mts +104 -0
- package/dist/shared/server.D_QauotT.mjs +30 -0
- package/dist/shared/server.DofEOwf-.mjs +237 -0
- package/dist/shared/{server.DZ5BIITo.mjs → server.W91HSRkE.mjs} +2 -2
- package/dist/shared/server.m3szVJGU.d.ts +61 -0
- package/package.json +26 -56
- package/dist/adapters/aws-lambda/index.d.mts +0 -46
- package/dist/adapters/aws-lambda/index.d.ts +0 -46
- package/dist/adapters/aws-lambda/index.mjs +0 -40
- package/dist/adapters/bun-ws/index.d.mts +0 -36
- package/dist/adapters/bun-ws/index.d.ts +0 -36
- package/dist/adapters/bun-ws/index.mjs +0 -47
- package/dist/adapters/fastify/index.d.mts +0 -53
- package/dist/adapters/fastify/index.d.ts +0 -53
- package/dist/adapters/fastify/index.mjs +0 -52
- package/dist/adapters/ws/index.d.mts +0 -31
- package/dist/adapters/ws/index.d.ts +0 -31
- package/dist/adapters/ws/index.mjs +0 -41
- package/dist/hibernation/index.d.mts +0 -44
- package/dist/hibernation/index.d.ts +0 -44
- package/dist/hibernation/index.mjs +0 -65
- package/dist/shared/server.7cEtMB30.d.ts +0 -74
- package/dist/shared/server.B8gYOD5g.d.mts +0 -12
- package/dist/shared/server.BqadksTP.d.mts +0 -74
- package/dist/shared/server.C8_sRzQB.d.mts +0 -42
- package/dist/shared/server.ChUyt5-i.d.mts +0 -32
- package/dist/shared/server.ChyoA9XY.d.ts +0 -42
- package/dist/shared/server.DEBcqOjg.mjs +0 -418
- package/dist/shared/server.EfTOZ2Q7.d.ts +0 -12
- package/dist/shared/server.TEVCLCFC.mjs +0 -39
- package/dist/shared/server.ZxHCEN1h.mjs +0 -226
- package/dist/shared/server.qKsRrdxW.d.mts +0 -193
- package/dist/shared/server.qKsRrdxW.d.ts +0 -193
- package/dist/shared/server.yoEB3Fx4.d.ts +0 -32
|
@@ -1,56 +1,71 @@
|
|
|
1
|
-
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { Arrayable, MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
|
|
3
|
+
import { C as Context } from '../../shared/server.CcR4kgje.mjs';
|
|
4
|
+
import { S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DDFizwfU.mjs';
|
|
5
|
+
import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.mjs';
|
|
6
|
+
import { R as Router } from '../../shared/server.15O7oC1p.mjs';
|
|
7
|
+
import { R as RPCHandlerCodecOptions } from '../../shared/server.B4BnEWWm.mjs';
|
|
6
8
|
import '@orpc/client';
|
|
7
9
|
import '@orpc/contract';
|
|
8
|
-
import '@
|
|
9
|
-
import '../../shared/server.B8gYOD5g.mjs';
|
|
10
|
-
import '@orpc/standard-server';
|
|
11
|
-
import '@orpc/client/standard';
|
|
12
|
-
import '../../shared/server.C8_sRzQB.mjs';
|
|
10
|
+
import '@standardserver/core';
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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> {
|
|
20
|
+
/**
|
|
21
|
+
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
22
|
+
*/
|
|
23
|
+
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
18
24
|
/**
|
|
19
|
-
*
|
|
25
|
+
* Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
26
|
+
*/
|
|
27
|
+
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
28
|
+
}
|
|
29
|
+
declare class WebSocketHandler<T extends Context> {
|
|
30
|
+
private readonly handler;
|
|
31
|
+
private readonly peers;
|
|
32
|
+
private readonly encodePeerMessageOptions;
|
|
33
|
+
private readonly decodePeerMessageOptions;
|
|
34
|
+
constructor(handler: StandardHandler<T>, options?: NoInfer<WebSocketHandlerOptions<T>>);
|
|
35
|
+
/**
|
|
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.
|
|
20
40
|
*
|
|
21
|
-
*
|
|
41
|
+
* To avoid async Blob reads, configure `ws.binaryType` to return binary data
|
|
42
|
+
* directly (for example, `arraybuffer`).
|
|
22
43
|
*
|
|
23
|
-
* @
|
|
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`).
|
|
24
46
|
*/
|
|
25
|
-
|
|
47
|
+
message(ws: WebSocketLike, data: Arrayable<string | ArrayBuffer | Pick<Uint8Array<ArrayBuffer>, 'buffer' | 'byteOffset' | 'byteLength'>>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): Promise<{
|
|
48
|
+
matched: boolean;
|
|
49
|
+
}>;
|
|
26
50
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @warning Avoid calling this directly if `.upgrade()` is used.
|
|
51
|
+
* Cleans up peer state for a closed WebSocket.
|
|
30
52
|
*
|
|
31
|
-
* @param ws The WebSocket instance
|
|
32
|
-
* @param data The message payload, usually place in `event.data`
|
|
53
|
+
* @param ws The same WebSocket instance passed to `.message()`.
|
|
33
54
|
*/
|
|
34
|
-
|
|
55
|
+
close(ws: WebSocketLike): Promise<void>;
|
|
35
56
|
/**
|
|
36
|
-
*
|
|
57
|
+
* Attaches message and close event listeners to a WebSocket.
|
|
37
58
|
*
|
|
38
|
-
*
|
|
59
|
+
* Prefer this over calling `.message()` and `.close()` manually.
|
|
39
60
|
*/
|
|
40
|
-
|
|
61
|
+
upgrade(ws: Pick<WebSocket, 'send' | 'addEventListener' | 'removeEventListener'>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
|
|
41
62
|
}
|
|
42
63
|
|
|
43
|
-
interface RPCHandlerOptions<T extends Context> extends
|
|
64
|
+
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebSocketHandlerOptions<T> {
|
|
44
65
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
* @see {@link https://orpc.dev/docs/rpc-handler RPC Handler Docs}
|
|
49
|
-
* @see {@link https://orpc.dev/docs/adapters/websocket Websocket Adapter Docs}
|
|
50
|
-
*/
|
|
51
|
-
declare class RPCHandler<T extends Context> extends WebsocketHandler<T> {
|
|
52
|
-
constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
66
|
+
declare class RPCHandler<T extends Context> extends WebSocketHandler<T> {
|
|
67
|
+
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
53
68
|
}
|
|
54
69
|
|
|
55
|
-
export { RPCHandler,
|
|
56
|
-
export type {
|
|
70
|
+
export { RPCHandler, WebSocketHandler };
|
|
71
|
+
export type { RPCHandlerOptions, WebSocketHandlerOptions, WebSocketLike };
|
|
@@ -1,56 +1,71 @@
|
|
|
1
|
-
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { Arrayable, MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
|
|
3
|
+
import { C as Context } from '../../shared/server.CcR4kgje.js';
|
|
4
|
+
import { S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.BhsVw7m7.js';
|
|
5
|
+
import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.js';
|
|
6
|
+
import { R as Router } from '../../shared/server.m3szVJGU.js';
|
|
7
|
+
import { R as RPCHandlerCodecOptions } from '../../shared/server.CnN50DHH.js';
|
|
6
8
|
import '@orpc/client';
|
|
7
9
|
import '@orpc/contract';
|
|
8
|
-
import '@
|
|
9
|
-
import '../../shared/server.EfTOZ2Q7.js';
|
|
10
|
-
import '@orpc/standard-server';
|
|
11
|
-
import '@orpc/client/standard';
|
|
12
|
-
import '../../shared/server.ChyoA9XY.js';
|
|
10
|
+
import '@standardserver/core';
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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> {
|
|
20
|
+
/**
|
|
21
|
+
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
22
|
+
*/
|
|
23
|
+
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
18
24
|
/**
|
|
19
|
-
*
|
|
25
|
+
* Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
26
|
+
*/
|
|
27
|
+
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
28
|
+
}
|
|
29
|
+
declare class WebSocketHandler<T extends Context> {
|
|
30
|
+
private readonly handler;
|
|
31
|
+
private readonly peers;
|
|
32
|
+
private readonly encodePeerMessageOptions;
|
|
33
|
+
private readonly decodePeerMessageOptions;
|
|
34
|
+
constructor(handler: StandardHandler<T>, options?: NoInfer<WebSocketHandlerOptions<T>>);
|
|
35
|
+
/**
|
|
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.
|
|
20
40
|
*
|
|
21
|
-
*
|
|
41
|
+
* To avoid async Blob reads, configure `ws.binaryType` to return binary data
|
|
42
|
+
* directly (for example, `arraybuffer`).
|
|
22
43
|
*
|
|
23
|
-
* @
|
|
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`).
|
|
24
46
|
*/
|
|
25
|
-
|
|
47
|
+
message(ws: WebSocketLike, data: Arrayable<string | ArrayBuffer | Pick<Uint8Array<ArrayBuffer>, 'buffer' | 'byteOffset' | 'byteLength'>>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): Promise<{
|
|
48
|
+
matched: boolean;
|
|
49
|
+
}>;
|
|
26
50
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @warning Avoid calling this directly if `.upgrade()` is used.
|
|
51
|
+
* Cleans up peer state for a closed WebSocket.
|
|
30
52
|
*
|
|
31
|
-
* @param ws The WebSocket instance
|
|
32
|
-
* @param data The message payload, usually place in `event.data`
|
|
53
|
+
* @param ws The same WebSocket instance passed to `.message()`.
|
|
33
54
|
*/
|
|
34
|
-
|
|
55
|
+
close(ws: WebSocketLike): Promise<void>;
|
|
35
56
|
/**
|
|
36
|
-
*
|
|
57
|
+
* Attaches message and close event listeners to a WebSocket.
|
|
37
58
|
*
|
|
38
|
-
*
|
|
59
|
+
* Prefer this over calling `.message()` and `.close()` manually.
|
|
39
60
|
*/
|
|
40
|
-
|
|
61
|
+
upgrade(ws: Pick<WebSocket, 'send' | 'addEventListener' | 'removeEventListener'>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
|
|
41
62
|
}
|
|
42
63
|
|
|
43
|
-
interface RPCHandlerOptions<T extends Context> extends
|
|
64
|
+
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebSocketHandlerOptions<T> {
|
|
44
65
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
* @see {@link https://orpc.dev/docs/rpc-handler RPC Handler Docs}
|
|
49
|
-
* @see {@link https://orpc.dev/docs/adapters/websocket Websocket Adapter Docs}
|
|
50
|
-
*/
|
|
51
|
-
declare class RPCHandler<T extends Context> extends WebsocketHandler<T> {
|
|
52
|
-
constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
66
|
+
declare class RPCHandler<T extends Context> extends WebSocketHandler<T> {
|
|
67
|
+
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
53
68
|
}
|
|
54
69
|
|
|
55
|
-
export { RPCHandler,
|
|
56
|
-
export type {
|
|
70
|
+
export { RPCHandler, WebSocketHandler };
|
|
71
|
+
export type { RPCHandlerOptions, WebSocketHandlerOptions, WebSocketLike };
|
|
@@ -1,67 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ServerPeer } from '@
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import '../../shared/server.DZ5BIITo.mjs';
|
|
6
|
-
import '@orpc/client/standard';
|
|
1
|
+
import { toStringOrBytes, resolveMaybeOptionalOptions, sequential, loadBytes } from '@orpc/shared';
|
|
2
|
+
import { ServerPeer, encodePeerMessage, decodePeerMessage, isClientPeerSendMessage } from '@standardserver/peer';
|
|
3
|
+
import { c as createStandardPeerRequestHandler } from '../../shared/server.CX4vUnDk.mjs';
|
|
4
|
+
import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.COPVXhDG.mjs';
|
|
7
5
|
import '@orpc/client';
|
|
8
|
-
import '@
|
|
9
|
-
import '../../shared/server.
|
|
6
|
+
import '@standardserver/core';
|
|
7
|
+
import '../../shared/server.DofEOwf-.mjs';
|
|
10
8
|
import '@orpc/contract';
|
|
9
|
+
import '../../shared/server.BoiFpNT7.mjs';
|
|
11
10
|
|
|
12
|
-
class
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this
|
|
11
|
+
class WebSocketHandler {
|
|
12
|
+
constructor(handler, options = {}) {
|
|
13
|
+
this.handler = handler;
|
|
14
|
+
this.encodePeerMessageOptions = options.encodePeerMessage;
|
|
15
|
+
this.decodePeerMessageOptions = options.decodePeerMessage;
|
|
17
16
|
}
|
|
17
|
+
peers = /* @__PURE__ */ new WeakMap();
|
|
18
|
+
encodePeerMessageOptions;
|
|
19
|
+
decodePeerMessageOptions;
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
21
|
+
* Handles a single WebSocket message.
|
|
20
22
|
*
|
|
21
|
-
*
|
|
23
|
+
* Message order matters. Call this immediately after receiving a message,
|
|
24
|
+
* before any other async work, to preserve ordering.
|
|
22
25
|
*
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
upgrade(ws, ...rest) {
|
|
26
|
-
ws.addEventListener("message", (event) => this.message(ws, event.data, ...rest));
|
|
27
|
-
ws.addEventListener("close", () => this.close(ws));
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Handles a single message received from a WebSocket.
|
|
31
|
-
*
|
|
32
|
-
* @warning Avoid calling this directly if `.upgrade()` is used.
|
|
26
|
+
* To avoid async Blob reads, configure `ws.binaryType` to return binary data
|
|
27
|
+
* directly (for example, `arraybuffer`).
|
|
33
28
|
*
|
|
34
|
-
* @param ws The WebSocket instance
|
|
35
|
-
* @param data The message
|
|
29
|
+
* @param ws The WebSocket instance. Use the same instance for all messages.
|
|
30
|
+
* @param data The received message. Binary data should already be loaded (not a `Blob`).
|
|
36
31
|
*/
|
|
37
32
|
async message(ws, data, ...rest) {
|
|
38
|
-
let peer = this
|
|
33
|
+
let peer = this.peers.get(ws);
|
|
39
34
|
if (!peer) {
|
|
40
|
-
this
|
|
35
|
+
this.peers.set(ws, peer = new ServerPeer(async (message) => {
|
|
36
|
+
const encoded2 = await encodePeerMessage(message, this.encodePeerMessageOptions);
|
|
37
|
+
await ws.send(encoded2);
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
const encoded = toStringOrBytes(data);
|
|
41
|
+
const result = decodePeerMessage(encoded, this.decodePeerMessageOptions);
|
|
42
|
+
if (result.matched && isClientPeerSendMessage(result.message)) {
|
|
43
|
+
await peer.message(
|
|
44
|
+
result.message,
|
|
45
|
+
createStandardPeerRequestHandler(this.handler, resolveMaybeOptionalOptions(rest))
|
|
46
|
+
);
|
|
41
47
|
}
|
|
42
|
-
|
|
43
|
-
await peer.message(
|
|
44
|
-
message,
|
|
45
|
-
createServerPeerHandleRequestFn(this.#handler, resolveMaybeOptionalOptions(rest))
|
|
46
|
-
);
|
|
48
|
+
return result;
|
|
47
49
|
}
|
|
48
50
|
/**
|
|
49
|
-
*
|
|
51
|
+
* Cleans up peer state for a closed WebSocket.
|
|
50
52
|
*
|
|
51
|
-
* @
|
|
53
|
+
* @param ws The same WebSocket instance passed to `.message()`.
|
|
52
54
|
*/
|
|
53
|
-
close(ws) {
|
|
54
|
-
const peer = this
|
|
55
|
+
async close(ws) {
|
|
56
|
+
const peer = this.peers.get(ws);
|
|
55
57
|
if (peer) {
|
|
56
|
-
|
|
58
|
+
this.peers.delete(ws);
|
|
59
|
+
await peer.close();
|
|
57
60
|
}
|
|
58
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Attaches message and close event listeners to a WebSocket.
|
|
64
|
+
*
|
|
65
|
+
* Prefer this over calling `.message()` and `.close()` manually.
|
|
66
|
+
*/
|
|
67
|
+
upgrade(ws, ...rest) {
|
|
68
|
+
ws.addEventListener("message", sequential(async (event) => {
|
|
69
|
+
const data = event.data instanceof Blob ? await loadBytes(event.data) : event.data;
|
|
70
|
+
this.message(ws, data, ...rest);
|
|
71
|
+
}));
|
|
72
|
+
ws.addEventListener("close", () => this.close(ws));
|
|
73
|
+
}
|
|
59
74
|
}
|
|
60
75
|
|
|
61
|
-
class RPCHandler extends
|
|
76
|
+
class RPCHandler extends WebSocketHandler {
|
|
62
77
|
constructor(router, options = {}) {
|
|
63
|
-
|
|
78
|
+
const codec = new RPCHandlerCodec(router, options);
|
|
79
|
+
const handler = new StandardHandler(codec, options);
|
|
80
|
+
super(handler, options);
|
|
64
81
|
}
|
|
65
82
|
}
|
|
66
83
|
|
|
67
|
-
export { RPCHandler,
|
|
84
|
+
export { RPCHandler, WebSocketHandler };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AnyORPCError, ClientContext } from '@orpc/client';
|
|
2
|
+
import { AnySchema, ErrorMap } from '@orpc/contract';
|
|
3
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
4
|
+
import { C as Context, P as ProcedureClientOptions, a as Procedure, b as ProcedureClient } from '../shared/server.CcR4kgje.mjs';
|
|
5
|
+
|
|
6
|
+
declare module "../index" {
|
|
7
|
+
interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> {
|
|
8
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TReturnedError, TClientContext>>): Procedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AnyORPCError, ClientContext } from '@orpc/client';
|
|
2
|
+
import { AnySchema, ErrorMap } from '@orpc/contract';
|
|
3
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
4
|
+
import { C as Context, P as ProcedureClientOptions, a as Procedure, b as ProcedureClient } from '../shared/server.CcR4kgje.js';
|
|
5
|
+
|
|
6
|
+
declare module "../index" {
|
|
7
|
+
interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> {
|
|
8
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TReturnedError, TClientContext>>): Procedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { c as createProcedureClient } from '../shared/server.DofEOwf-.mjs';
|
|
2
|
+
import { D as DecoratedProcedure } from '../shared/server.DBs0rrf9.mjs';
|
|
3
|
+
import '@orpc/client';
|
|
4
|
+
import '@orpc/contract';
|
|
5
|
+
import '@orpc/shared';
|
|
6
|
+
|
|
7
|
+
DecoratedProcedure.prototype.callable = function callable(...rest) {
|
|
8
|
+
const callable2 = createProcedureClient(this, ...rest);
|
|
9
|
+
callable2["~orpc"] = this["~orpc"];
|
|
10
|
+
return callable2;
|
|
11
|
+
};
|
package/dist/helpers/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParseOptions, SetCookie, StringifyOptions } from 'cookie';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Encodes a Uint8Array to base64url format
|
|
@@ -25,9 +25,9 @@ declare function encodeBase64url(data: Uint8Array): string;
|
|
|
25
25
|
* expect(new TextDecoder().decode(decoded)).toEqual(text)
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
declare function decodeBase64url(base64url: string | undefined | null): Uint8Array | undefined;
|
|
28
|
+
declare function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefined;
|
|
29
29
|
|
|
30
|
-
interface SetCookieOptions extends
|
|
30
|
+
interface SetCookieOptions extends Omit<SetCookie, 'name' | 'value'>, StringifyOptions {
|
|
31
31
|
/**
|
|
32
32
|
* Specifies the value for the [`Path` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.4).
|
|
33
33
|
*
|
|
@@ -46,7 +46,7 @@ interface SetCookieOptions extends SerializeOptions {
|
|
|
46
46
|
*
|
|
47
47
|
* setCookie(headers, 'sessionId', 'abc123', { httpOnly: true, maxAge: 3600 })
|
|
48
48
|
*
|
|
49
|
-
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123;
|
|
49
|
+
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123; Max-Age=3600; Path=/; HttpOnly')
|
|
50
50
|
* ```
|
|
51
51
|
*
|
|
52
52
|
*/
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParseOptions, SetCookie, StringifyOptions } from 'cookie';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Encodes a Uint8Array to base64url format
|
|
@@ -25,9 +25,9 @@ declare function encodeBase64url(data: Uint8Array): string;
|
|
|
25
25
|
* expect(new TextDecoder().decode(decoded)).toEqual(text)
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
declare function decodeBase64url(base64url: string | undefined | null): Uint8Array | undefined;
|
|
28
|
+
declare function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefined;
|
|
29
29
|
|
|
30
|
-
interface SetCookieOptions extends
|
|
30
|
+
interface SetCookieOptions extends Omit<SetCookie, 'name' | 'value'>, StringifyOptions {
|
|
31
31
|
/**
|
|
32
32
|
* Specifies the value for the [`Path` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.4).
|
|
33
33
|
*
|
|
@@ -46,7 +46,7 @@ interface SetCookieOptions extends SerializeOptions {
|
|
|
46
46
|
*
|
|
47
47
|
* setCookie(headers, 'sessionId', 'abc123', { httpOnly: true, maxAge: 3600 })
|
|
48
48
|
*
|
|
49
|
-
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123;
|
|
49
|
+
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123; Max-Age=3600; Path=/; HttpOnly')
|
|
50
50
|
* ```
|
|
51
51
|
*
|
|
52
52
|
*/
|
package/dist/helpers/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseCookie, stringifySetCookie } from 'cookie';
|
|
2
2
|
|
|
3
3
|
function encodeBase64url(data) {
|
|
4
4
|
const chunkSize = 8192;
|
|
@@ -34,10 +34,17 @@ function setCookie(headers, name, value, options = {}) {
|
|
|
34
34
|
if (headers === void 0) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
const cookieString =
|
|
37
|
+
const cookieString = stringifySetCookie({
|
|
38
|
+
// Force path to '/' by default so the cookie is available across the
|
|
39
|
+
// entire app, not just under the directory of the request that set it
|
|
40
|
+
// (which is what browsers do per RFC 6265 §5.1.4 when Path is omitted).
|
|
38
41
|
path: "/",
|
|
39
|
-
...options
|
|
40
|
-
|
|
42
|
+
...options,
|
|
43
|
+
name,
|
|
44
|
+
// prioritize
|
|
45
|
+
value
|
|
46
|
+
// prioritize
|
|
47
|
+
}, options);
|
|
41
48
|
headers.append("Set-Cookie", cookieString);
|
|
42
49
|
}
|
|
43
50
|
function getCookie(headers, name, options = {}) {
|
|
@@ -48,12 +55,13 @@ function getCookie(headers, name, options = {}) {
|
|
|
48
55
|
if (cookieHeader === null) {
|
|
49
56
|
return void 0;
|
|
50
57
|
}
|
|
51
|
-
return
|
|
58
|
+
return parseCookie(cookieHeader, options)[name];
|
|
52
59
|
}
|
|
53
60
|
function deleteCookie(headers, name, options = {}) {
|
|
54
61
|
return setCookie(headers, name, "", {
|
|
55
62
|
...options,
|
|
56
63
|
maxAge: 0
|
|
64
|
+
// prioritize
|
|
57
65
|
});
|
|
58
66
|
}
|
|
59
67
|
|