@orpc/server 2.0.0-beta.22 → 2.0.0-beta.24
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 +4 -1
- package/dist/adapters/aws-lambda/index.d.mts +104 -0
- package/dist/adapters/aws-lambda/index.d.ts +104 -0
- package/dist/adapters/aws-lambda/index.mjs +73 -0
- package/dist/adapters/crossws/index.d.mts +10 -4
- package/dist/adapters/crossws/index.d.ts +10 -4
- package/dist/adapters/crossws/index.mjs +3 -3
- package/dist/adapters/fastify/index.d.mts +96 -0
- package/dist/adapters/fastify/index.d.ts +96 -0
- package/dist/adapters/fastify/index.mjs +73 -0
- package/dist/adapters/fetch/index.d.mts +13 -5
- package/dist/adapters/fetch/index.d.ts +13 -5
- package/dist/adapters/fetch/index.mjs +5 -4
- package/dist/adapters/message-port/index.d.mts +12 -7
- package/dist/adapters/message-port/index.d.ts +12 -7
- package/dist/adapters/message-port/index.mjs +3 -3
- package/dist/adapters/node/index.d.mts +12 -5
- package/dist/adapters/node/index.d.ts +12 -5
- package/dist/adapters/node/index.mjs +6 -4
- package/dist/adapters/standard/index.d.mts +5 -5
- package/dist/adapters/standard/index.d.ts +5 -5
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/adapters/standard-peer/index.d.mts +2 -2
- package/dist/adapters/standard-peer/index.d.ts +2 -2
- package/dist/adapters/websocket/index.d.mts +10 -4
- package/dist/adapters/websocket/index.d.ts +10 -4
- package/dist/adapters/websocket/index.mjs +3 -3
- package/dist/extensions/callable.d.mts +2 -2
- package/dist/extensions/callable.d.ts +2 -2
- package/dist/extensions/callable.mjs +2 -2
- package/dist/helpers/index.d.mts +20 -3
- package/dist/helpers/index.d.ts +20 -3
- package/dist/index.d.mts +39 -7
- package/dist/index.d.ts +39 -7
- package/dist/index.mjs +23 -18
- package/dist/plugins/index.d.mts +49 -40
- package/dist/plugins/index.d.ts +49 -40
- package/dist/plugins/index.mjs +10 -67
- package/dist/shared/{server.DofEOwf-.mjs → server.7T18Khvf.mjs} +6 -32
- package/dist/shared/{server.DBs0rrf9.mjs → server.B2pXdfpL.mjs} +1 -1
- package/dist/shared/{server.DG9aQpJK.d.ts → server.BUvC0G_8.d.ts} +3 -3
- package/dist/shared/server.BhHrioCw.d.ts +34 -0
- package/dist/shared/server.Cd4Z1hpV.mjs +69 -0
- package/dist/shared/{server.CcR4kgje.d.ts → server.CwrYlF72.d.mts} +10 -42
- package/dist/shared/{server.CcR4kgje.d.mts → server.CwrYlF72.d.ts} +10 -42
- package/dist/shared/server.D0Ipbmdv.d.mts +34 -0
- package/dist/shared/{server.A8J9H8OE.mjs → server.DEGjTAPW.mjs} +2 -2
- package/dist/shared/{server.D4cnq66J.mjs → server.DgunZU0v.mjs} +3 -3
- package/dist/shared/{server.m3szVJGU.d.ts → server.Dm0os-OP.d.mts} +24 -12
- package/dist/shared/{server.BhsVw7m7.d.ts → server.DrN1Pj1-.d.ts} +3 -3
- package/dist/shared/{server.15O7oC1p.d.mts → server.DtfwuV6U.d.ts} +24 -12
- package/dist/shared/{server.DDFizwfU.d.mts → server.JbCIPL4P.d.mts} +3 -3
- package/dist/shared/{server.omY4cUs0.d.mts → server.zySQaS-n.d.mts} +3 -3
- package/package.json +26 -9
package/README.md
CHANGED
|
@@ -44,6 +44,7 @@ You can read the documentation [here](https://orpc.dev).
|
|
|
44
44
|
|
|
45
45
|
- [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher): Pub/Sub with memory, Redis, and Upstash adapters.
|
|
46
46
|
- [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit): Rate limiting with memory, Redis, and Upstash adapters.
|
|
47
|
+
- [@orpc/hibernation](https://www.npmjs.com/package/@orpc/hibernation): Leverage Hibernation APIs like [Cloudflare's Hibernation WebSocket](https://developers.cloudflare.com/durable-objects/best-practices/websockets/#durable-objects-hibernation-websocket-api).
|
|
47
48
|
- [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema): Smart coercion for OpenAPI requests.
|
|
48
49
|
|
|
49
50
|
**Framework & ecosystem integrations**
|
|
@@ -114,6 +115,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
114
115
|
</tr>
|
|
115
116
|
<tr>
|
|
116
117
|
<td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="139" alt="shota"/><br />shota</a></td>
|
|
118
|
+
<td align="center"><a href="https://github.com/ellis-driscoll?ref=orpc" target="_blank" rel="noopener" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&v=4" width="139" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
|
|
117
119
|
</tr>
|
|
118
120
|
</table>
|
|
119
121
|
|
|
@@ -139,8 +141,9 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
139
141
|
<td align="center"><a href="https://github.com/mr-kelly?ref=orpc" target="_blank" rel="noopener" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&v=4" width="119" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
|
|
140
142
|
</tr>
|
|
141
143
|
<tr>
|
|
144
|
+
<td align="center"><a href="https://github.com/guyariely?ref=orpc" target="_blank" rel="noopener" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&v=4" width="119" alt="Guy Ariely"/><br />Guy Ariely</a></td>
|
|
142
145
|
<td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="119" alt="Alex"/><br />Alex</a></td>
|
|
143
|
-
<td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=
|
|
146
|
+
<td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&v=4" width="119" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
|
|
144
147
|
</tr>
|
|
145
148
|
</table>
|
|
146
149
|
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { SendStandardResponseOptions, AnyAPIGatewayProxyEvent, HttpResponseStream } from '@standardserver/aws-lambda';
|
|
3
|
+
import { C as Context } from '../../shared/server.CwrYlF72.mjs';
|
|
4
|
+
import { S as StandardHandlerPlugin, b as StandardHandler, c as StandardHandlerHandleOptions, a as StandardHandlerOptions } from '../../shared/server.JbCIPL4P.mjs';
|
|
5
|
+
import { FriendlyStandardHandlerHandleOptions } from '../standard/index.mjs';
|
|
6
|
+
import { R as Router } from '../../shared/server.Dm0os-OP.mjs';
|
|
7
|
+
import { R as RPCHandlerCodecOptions } from '../../shared/server.zySQaS-n.mjs';
|
|
8
|
+
import '@orpc/client';
|
|
9
|
+
import '@orpc/contract';
|
|
10
|
+
import '@standardserver/core';
|
|
11
|
+
|
|
12
|
+
interface AwsLambdaHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
|
13
|
+
/**
|
|
14
|
+
* Initializes the plugin and returns new AWS Lambda handler options.
|
|
15
|
+
* Called once per plugin instance during composition.
|
|
16
|
+
*
|
|
17
|
+
* This method allows plugins to wrap, extend, or transform AWS Lambda handler options
|
|
18
|
+
* such as interceptors, or other configuration.
|
|
19
|
+
*
|
|
20
|
+
* @param options - The current handler options from previous plugins or base configuration
|
|
21
|
+
* @returns Transformed handler options with plugin's modifications applied
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* initAwsLambdaHandlerOptions(options) {
|
|
26
|
+
* return {
|
|
27
|
+
* ...options,
|
|
28
|
+
* awsLambdaInterceptors: [...(options.awsLambdaInterceptors || []), myInterceptor]
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
initAwsLambdaHandlerOptions?(options: AwsLambdaHandlerOptions<T>): AwsLambdaHandlerOptions<T>;
|
|
34
|
+
}
|
|
35
|
+
declare class CompositeAwsLambdaHandlerPlugin<T extends Context> implements AwsLambdaHandlerPlugin<T> {
|
|
36
|
+
readonly name = "~composite/aws-lambda";
|
|
37
|
+
protected readonly plugins: AwsLambdaHandlerPlugin<T>[];
|
|
38
|
+
constructor(plugins?: AwsLambdaHandlerPlugin<T>[]);
|
|
39
|
+
initAwsLambdaHandlerOptions(options: AwsLambdaHandlerOptions<T>): AwsLambdaHandlerOptions<T>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type AwsLambdaHandlerHandleResult = {
|
|
43
|
+
matched: true;
|
|
44
|
+
} | {
|
|
45
|
+
matched: false;
|
|
46
|
+
};
|
|
47
|
+
interface AwsLambdaHandlerAwsLambdaInterceptorOptions<T extends Context> extends StandardHandlerHandleOptions<T> {
|
|
48
|
+
event: AnyAPIGatewayProxyEvent;
|
|
49
|
+
responseStream: HttpResponseStream;
|
|
50
|
+
sendStandardResponseOptions: SendStandardResponseOptions | undefined;
|
|
51
|
+
}
|
|
52
|
+
type AwsLambdaHandlerAwsLambdaInterceptor<T extends Context> = Interceptor<AwsLambdaHandlerAwsLambdaInterceptorOptions<T>, Promise<AwsLambdaHandlerHandleResult>>;
|
|
53
|
+
interface AwsLambdaHandlerOptions<T extends Context> {
|
|
54
|
+
/**
|
|
55
|
+
* Custom options for `sendStandardResponse`, used to send a `Standard Response`
|
|
56
|
+
*/
|
|
57
|
+
sendStandardResponse?: SendStandardResponseOptions | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Interceptors that run before the mapping between the Standard API and AWS Lambda API,
|
|
60
|
+
* useful for extending the AWS Lambda event/response stream before handling, ...
|
|
61
|
+
*/
|
|
62
|
+
awsLambdaInterceptors?: AwsLambdaHandlerAwsLambdaInterceptor<T>[] | undefined;
|
|
63
|
+
plugins?: AwsLambdaHandlerPlugin<T>[] | undefined;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Requires the AWS Lambda Node.js runtime with response streaming enabled,
|
|
67
|
+
* handlers should be wrapped with `awslambda.streamifyResponse`.
|
|
68
|
+
*/
|
|
69
|
+
declare class AwsLambdaHandler<T extends Context> {
|
|
70
|
+
private readonly standardHandler;
|
|
71
|
+
private readonly sendStandardResponseOptions;
|
|
72
|
+
private readonly awsLambdaInterceptors;
|
|
73
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<AwsLambdaHandlerOptions<T>>);
|
|
74
|
+
handle(event: AnyAPIGatewayProxyEvent, responseStream: HttpResponseStream, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<AwsLambdaHandlerHandleResult>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
interface RPCHandlerOptions<T extends Context> extends AwsLambdaHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
|
|
78
|
+
/**
|
|
79
|
+
* Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
|
|
80
|
+
*/
|
|
81
|
+
csrfGuardPlugin?: {
|
|
82
|
+
/**
|
|
83
|
+
* If `false`, this plugin is disabled.
|
|
84
|
+
*
|
|
85
|
+
* @default true
|
|
86
|
+
*/
|
|
87
|
+
enabled?: boolean;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Serves an oRPC router over the RPC protocol on AWS Lambda,
|
|
92
|
+
* behind API Gateway or Lambda Function URLs.
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* **Warning**: Requires the Lambda Node.js runtime with response streaming enabled, so handlers must be wrapped with `awslambda.streamifyResponse`.
|
|
96
|
+
*
|
|
97
|
+
* @see {@link https://orpc.dev/docs/adapters/aws-lambda | AWS Lambda Adapter}
|
|
98
|
+
*/
|
|
99
|
+
declare class RPCHandler<T extends Context> extends AwsLambdaHandler<T> {
|
|
100
|
+
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { AwsLambdaHandler, CompositeAwsLambdaHandlerPlugin, RPCHandler };
|
|
104
|
+
export type { AwsLambdaHandlerAwsLambdaInterceptor, AwsLambdaHandlerAwsLambdaInterceptorOptions, AwsLambdaHandlerHandleResult, AwsLambdaHandlerOptions, AwsLambdaHandlerPlugin, RPCHandlerOptions };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { SendStandardResponseOptions, AnyAPIGatewayProxyEvent, HttpResponseStream } from '@standardserver/aws-lambda';
|
|
3
|
+
import { C as Context } from '../../shared/server.CwrYlF72.js';
|
|
4
|
+
import { S as StandardHandlerPlugin, b as StandardHandler, c as StandardHandlerHandleOptions, a as StandardHandlerOptions } from '../../shared/server.DrN1Pj1-.js';
|
|
5
|
+
import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
|
|
6
|
+
import { R as Router } from '../../shared/server.DtfwuV6U.js';
|
|
7
|
+
import { R as RPCHandlerCodecOptions } from '../../shared/server.BUvC0G_8.js';
|
|
8
|
+
import '@orpc/client';
|
|
9
|
+
import '@orpc/contract';
|
|
10
|
+
import '@standardserver/core';
|
|
11
|
+
|
|
12
|
+
interface AwsLambdaHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
|
13
|
+
/**
|
|
14
|
+
* Initializes the plugin and returns new AWS Lambda handler options.
|
|
15
|
+
* Called once per plugin instance during composition.
|
|
16
|
+
*
|
|
17
|
+
* This method allows plugins to wrap, extend, or transform AWS Lambda handler options
|
|
18
|
+
* such as interceptors, or other configuration.
|
|
19
|
+
*
|
|
20
|
+
* @param options - The current handler options from previous plugins or base configuration
|
|
21
|
+
* @returns Transformed handler options with plugin's modifications applied
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* initAwsLambdaHandlerOptions(options) {
|
|
26
|
+
* return {
|
|
27
|
+
* ...options,
|
|
28
|
+
* awsLambdaInterceptors: [...(options.awsLambdaInterceptors || []), myInterceptor]
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
initAwsLambdaHandlerOptions?(options: AwsLambdaHandlerOptions<T>): AwsLambdaHandlerOptions<T>;
|
|
34
|
+
}
|
|
35
|
+
declare class CompositeAwsLambdaHandlerPlugin<T extends Context> implements AwsLambdaHandlerPlugin<T> {
|
|
36
|
+
readonly name = "~composite/aws-lambda";
|
|
37
|
+
protected readonly plugins: AwsLambdaHandlerPlugin<T>[];
|
|
38
|
+
constructor(plugins?: AwsLambdaHandlerPlugin<T>[]);
|
|
39
|
+
initAwsLambdaHandlerOptions(options: AwsLambdaHandlerOptions<T>): AwsLambdaHandlerOptions<T>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type AwsLambdaHandlerHandleResult = {
|
|
43
|
+
matched: true;
|
|
44
|
+
} | {
|
|
45
|
+
matched: false;
|
|
46
|
+
};
|
|
47
|
+
interface AwsLambdaHandlerAwsLambdaInterceptorOptions<T extends Context> extends StandardHandlerHandleOptions<T> {
|
|
48
|
+
event: AnyAPIGatewayProxyEvent;
|
|
49
|
+
responseStream: HttpResponseStream;
|
|
50
|
+
sendStandardResponseOptions: SendStandardResponseOptions | undefined;
|
|
51
|
+
}
|
|
52
|
+
type AwsLambdaHandlerAwsLambdaInterceptor<T extends Context> = Interceptor<AwsLambdaHandlerAwsLambdaInterceptorOptions<T>, Promise<AwsLambdaHandlerHandleResult>>;
|
|
53
|
+
interface AwsLambdaHandlerOptions<T extends Context> {
|
|
54
|
+
/**
|
|
55
|
+
* Custom options for `sendStandardResponse`, used to send a `Standard Response`
|
|
56
|
+
*/
|
|
57
|
+
sendStandardResponse?: SendStandardResponseOptions | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Interceptors that run before the mapping between the Standard API and AWS Lambda API,
|
|
60
|
+
* useful for extending the AWS Lambda event/response stream before handling, ...
|
|
61
|
+
*/
|
|
62
|
+
awsLambdaInterceptors?: AwsLambdaHandlerAwsLambdaInterceptor<T>[] | undefined;
|
|
63
|
+
plugins?: AwsLambdaHandlerPlugin<T>[] | undefined;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Requires the AWS Lambda Node.js runtime with response streaming enabled,
|
|
67
|
+
* handlers should be wrapped with `awslambda.streamifyResponse`.
|
|
68
|
+
*/
|
|
69
|
+
declare class AwsLambdaHandler<T extends Context> {
|
|
70
|
+
private readonly standardHandler;
|
|
71
|
+
private readonly sendStandardResponseOptions;
|
|
72
|
+
private readonly awsLambdaInterceptors;
|
|
73
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<AwsLambdaHandlerOptions<T>>);
|
|
74
|
+
handle(event: AnyAPIGatewayProxyEvent, responseStream: HttpResponseStream, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<AwsLambdaHandlerHandleResult>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
interface RPCHandlerOptions<T extends Context> extends AwsLambdaHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
|
|
78
|
+
/**
|
|
79
|
+
* Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
|
|
80
|
+
*/
|
|
81
|
+
csrfGuardPlugin?: {
|
|
82
|
+
/**
|
|
83
|
+
* If `false`, this plugin is disabled.
|
|
84
|
+
*
|
|
85
|
+
* @default true
|
|
86
|
+
*/
|
|
87
|
+
enabled?: boolean;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Serves an oRPC router over the RPC protocol on AWS Lambda,
|
|
92
|
+
* behind API Gateway or Lambda Function URLs.
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* **Warning**: Requires the Lambda Node.js runtime with response streaming enabled, so handlers must be wrapped with `awslambda.streamifyResponse`.
|
|
96
|
+
*
|
|
97
|
+
* @see {@link https://orpc.dev/docs/adapters/aws-lambda | AWS Lambda Adapter}
|
|
98
|
+
*/
|
|
99
|
+
declare class RPCHandler<T extends Context> extends AwsLambdaHandler<T> {
|
|
100
|
+
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { AwsLambdaHandler, CompositeAwsLambdaHandlerPlugin, RPCHandler };
|
|
104
|
+
export type { AwsLambdaHandlerAwsLambdaInterceptor, AwsLambdaHandlerAwsLambdaInterceptorOptions, AwsLambdaHandlerHandleResult, AwsLambdaHandlerOptions, AwsLambdaHandlerPlugin, RPCHandlerOptions };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { sortPlugins, intercept, resolveMaybeOptionalOptions, toArray } from '@orpc/shared';
|
|
2
|
+
import { toStandardLazyRequest, sendStandardResponse } from '@standardserver/aws-lambda';
|
|
3
|
+
import { r as resolveFriendlyStandardHandlerHandleOptions } from '../../shared/server.W91HSRkE.mjs';
|
|
4
|
+
import { C as CSRFGuardHandlerPlugin } from '../../shared/server.D_QauotT.mjs';
|
|
5
|
+
import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DEGjTAPW.mjs';
|
|
6
|
+
import '@orpc/client';
|
|
7
|
+
import '@standardserver/core';
|
|
8
|
+
import '../../shared/server.7T18Khvf.mjs';
|
|
9
|
+
import '@orpc/contract';
|
|
10
|
+
import '../../shared/server.DgunZU0v.mjs';
|
|
11
|
+
|
|
12
|
+
class CompositeAwsLambdaHandlerPlugin {
|
|
13
|
+
name = "~composite/aws-lambda";
|
|
14
|
+
plugins;
|
|
15
|
+
constructor(plugins = []) {
|
|
16
|
+
this.plugins = sortPlugins(plugins);
|
|
17
|
+
}
|
|
18
|
+
initAwsLambdaHandlerOptions(options) {
|
|
19
|
+
for (const plugin of this.plugins) {
|
|
20
|
+
if (plugin.initAwsLambdaHandlerOptions) {
|
|
21
|
+
options = plugin.initAwsLambdaHandlerOptions(options);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return options;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
class AwsLambdaHandler {
|
|
29
|
+
constructor(standardHandler, options = {}) {
|
|
30
|
+
this.standardHandler = standardHandler;
|
|
31
|
+
options = new CompositeAwsLambdaHandlerPlugin(options.plugins).initAwsLambdaHandlerOptions(options);
|
|
32
|
+
this.awsLambdaInterceptors = options.awsLambdaInterceptors;
|
|
33
|
+
this.sendStandardResponseOptions = options.sendStandardResponse;
|
|
34
|
+
}
|
|
35
|
+
sendStandardResponseOptions;
|
|
36
|
+
awsLambdaInterceptors;
|
|
37
|
+
async handle(event, responseStream, ...rest) {
|
|
38
|
+
return intercept(
|
|
39
|
+
this.awsLambdaInterceptors,
|
|
40
|
+
{
|
|
41
|
+
...resolveFriendlyStandardHandlerHandleOptions(resolveMaybeOptionalOptions(rest)),
|
|
42
|
+
event,
|
|
43
|
+
responseStream,
|
|
44
|
+
sendStandardResponseOptions: this.sendStandardResponseOptions
|
|
45
|
+
},
|
|
46
|
+
async ({ event: event2, responseStream: responseStream2, sendStandardResponseOptions, ...options }) => {
|
|
47
|
+
const standardRequest = toStandardLazyRequest(event2, responseStream2);
|
|
48
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
|
49
|
+
if (!result.matched) {
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
await sendStandardResponse(responseStream2, result.response, sendStandardResponseOptions);
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class RPCHandler extends AwsLambdaHandler {
|
|
60
|
+
constructor(router, options = {}) {
|
|
61
|
+
if (options.csrfGuardPlugin?.enabled !== false) {
|
|
62
|
+
options = {
|
|
63
|
+
...options,
|
|
64
|
+
plugins: [...toArray(options.plugins), new CSRFGuardHandlerPlugin()]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const codec = new RPCHandlerCodec(router, options);
|
|
68
|
+
const handler = new StandardHandler(codec, options);
|
|
69
|
+
super(handler, options);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { AwsLambdaHandler, CompositeAwsLambdaHandlerPlugin, RPCHandler };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
2
|
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
|
|
3
3
|
import { Message, Peer } from 'crossws';
|
|
4
|
-
import { C as Context } from '../../shared/server.
|
|
5
|
-
import {
|
|
4
|
+
import { C as Context } from '../../shared/server.CwrYlF72.mjs';
|
|
5
|
+
import { b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.JbCIPL4P.mjs';
|
|
6
6
|
import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.mjs';
|
|
7
|
-
import { R as Router } from '../../shared/server.
|
|
8
|
-
import { R as RPCHandlerCodecOptions } from '../../shared/server.
|
|
7
|
+
import { R as Router } from '../../shared/server.Dm0os-OP.mjs';
|
|
8
|
+
import { R as RPCHandlerCodecOptions } from '../../shared/server.zySQaS-n.mjs';
|
|
9
9
|
import '@orpc/client';
|
|
10
10
|
import '@orpc/contract';
|
|
11
11
|
import '@standardserver/core';
|
|
@@ -49,6 +49,12 @@ declare class experimental_CrosswsHandler<T extends Context> {
|
|
|
49
49
|
|
|
50
50
|
interface experimental_RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, experimental_CrosswsHandlerOptions<T> {
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Serves an oRPC router over the RPC protocol on a WebSocket connection
|
|
54
|
+
* managed by [crossws](https://github.com/h3js/crossws).
|
|
55
|
+
*
|
|
56
|
+
* @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
|
|
57
|
+
*/
|
|
52
58
|
declare class experimental_RPCHandler<T extends Context> extends experimental_CrosswsHandler<T> {
|
|
53
59
|
constructor(router: Router<T>, options?: NoInfer<experimental_RPCHandlerOptions<T>>);
|
|
54
60
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
2
|
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
|
|
3
3
|
import { Message, Peer } from 'crossws';
|
|
4
|
-
import { C as Context } from '../../shared/server.
|
|
5
|
-
import {
|
|
4
|
+
import { C as Context } from '../../shared/server.CwrYlF72.js';
|
|
5
|
+
import { b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DrN1Pj1-.js';
|
|
6
6
|
import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.js';
|
|
7
|
-
import { R as Router } from '../../shared/server.
|
|
8
|
-
import { R as RPCHandlerCodecOptions } from '../../shared/server.
|
|
7
|
+
import { R as Router } from '../../shared/server.DtfwuV6U.js';
|
|
8
|
+
import { R as RPCHandlerCodecOptions } from '../../shared/server.BUvC0G_8.js';
|
|
9
9
|
import '@orpc/client';
|
|
10
10
|
import '@orpc/contract';
|
|
11
11
|
import '@standardserver/core';
|
|
@@ -49,6 +49,12 @@ declare class experimental_CrosswsHandler<T extends Context> {
|
|
|
49
49
|
|
|
50
50
|
interface experimental_RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, experimental_CrosswsHandlerOptions<T> {
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Serves an oRPC router over the RPC protocol on a WebSocket connection
|
|
54
|
+
* managed by [crossws](https://github.com/h3js/crossws).
|
|
55
|
+
*
|
|
56
|
+
* @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
|
|
57
|
+
*/
|
|
52
58
|
declare class experimental_RPCHandler<T extends Context> extends experimental_CrosswsHandler<T> {
|
|
53
59
|
constructor(router: Router<T>, options?: NoInfer<experimental_RPCHandlerOptions<T>>);
|
|
54
60
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
|
2
2
|
import { ServerPeer, encodePeerMessage, decodePeerMessage, isClientPeerSendMessage } from '@standardserver/peer';
|
|
3
3
|
import { c as createStandardPeerRequestHandler } from '../../shared/server.CX4vUnDk.mjs';
|
|
4
|
-
import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.
|
|
4
|
+
import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DEGjTAPW.mjs';
|
|
5
5
|
import '@orpc/client';
|
|
6
6
|
import '@standardserver/core';
|
|
7
|
-
import '../../shared/server.
|
|
7
|
+
import '../../shared/server.7T18Khvf.mjs';
|
|
8
8
|
import '@orpc/contract';
|
|
9
|
-
import '../../shared/server.
|
|
9
|
+
import '../../shared/server.DgunZU0v.mjs';
|
|
10
10
|
|
|
11
11
|
class experimental_CrosswsHandler {
|
|
12
12
|
constructor(handler, options = {}) {
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { SendStandardResponseOptions, AnyFastifyRequest, AnyFastifyReply } from '@standardserver/fastify';
|
|
3
|
+
import { C as Context } from '../../shared/server.CwrYlF72.mjs';
|
|
4
|
+
import { S as StandardHandlerPlugin, c as StandardHandlerHandleOptions, b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.JbCIPL4P.mjs';
|
|
5
|
+
import { FriendlyStandardHandlerHandleOptions } from '../standard/index.mjs';
|
|
6
|
+
import { R as Router } from '../../shared/server.Dm0os-OP.mjs';
|
|
7
|
+
import { R as RPCHandlerCodecOptions } from '../../shared/server.zySQaS-n.mjs';
|
|
8
|
+
import '@orpc/client';
|
|
9
|
+
import '@orpc/contract';
|
|
10
|
+
import '@standardserver/core';
|
|
11
|
+
|
|
12
|
+
interface FastifyHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
|
13
|
+
/**
|
|
14
|
+
* Initializes the plugin and returns new Fastify handler options.
|
|
15
|
+
* Called once per plugin instance during composition.
|
|
16
|
+
*
|
|
17
|
+
* This method allows plugins to wrap, extend, or transform Fastify handler options
|
|
18
|
+
* such as interceptors, or other configuration.
|
|
19
|
+
*
|
|
20
|
+
* @param options - The current handler options from previous plugins or base configuration
|
|
21
|
+
* @returns Transformed handler options with plugin's modifications applied
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* initFastifyHandlerOptions(options) {
|
|
26
|
+
* return {
|
|
27
|
+
* ...options,
|
|
28
|
+
* fastifyInterceptors: [...(options.fastifyInterceptors || []), myInterceptor]
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
initFastifyHandlerOptions?(options: FastifyHandlerOptions<T>): FastifyHandlerOptions<T>;
|
|
34
|
+
}
|
|
35
|
+
declare class CompositeFastifyHandlerPlugin<T extends Context> implements FastifyHandlerPlugin<T> {
|
|
36
|
+
readonly name = "~composite/fastify";
|
|
37
|
+
protected readonly plugins: FastifyHandlerPlugin<T>[];
|
|
38
|
+
constructor(plugins?: FastifyHandlerPlugin<T>[]);
|
|
39
|
+
initFastifyHandlerOptions(options: FastifyHandlerOptions<T>): FastifyHandlerOptions<T>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type FastifyHandlerHandleResult = {
|
|
43
|
+
matched: true;
|
|
44
|
+
} | {
|
|
45
|
+
matched: false;
|
|
46
|
+
};
|
|
47
|
+
interface FastifyHandlerFastifyInterceptorOptions<T extends Context> extends StandardHandlerHandleOptions<T> {
|
|
48
|
+
request: AnyFastifyRequest;
|
|
49
|
+
reply: AnyFastifyReply;
|
|
50
|
+
sendStandardResponseOptions: SendStandardResponseOptions | undefined;
|
|
51
|
+
}
|
|
52
|
+
type FastifyHandlerFastifyInterceptor<T extends Context> = Interceptor<FastifyHandlerFastifyInterceptorOptions<T>, Promise<FastifyHandlerHandleResult>>;
|
|
53
|
+
interface FastifyHandlerOptions<T extends Context> {
|
|
54
|
+
/**
|
|
55
|
+
* Custom options for `sendStandardResponse`, used to send a `Standard Response`
|
|
56
|
+
*/
|
|
57
|
+
sendStandardResponse?: SendStandardResponseOptions | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Interceptors that run before the mapping between the Standard API and Fastify API,
|
|
60
|
+
* useful for extending the Fastify request/reply before handling, ...
|
|
61
|
+
*/
|
|
62
|
+
fastifyInterceptors?: FastifyHandlerFastifyInterceptor<T>[] | undefined;
|
|
63
|
+
plugins?: FastifyHandlerPlugin<T>[] | undefined;
|
|
64
|
+
}
|
|
65
|
+
declare class FastifyHandler<T extends Context> {
|
|
66
|
+
private readonly standardHandler;
|
|
67
|
+
private readonly sendStandardResponseOptions;
|
|
68
|
+
private readonly fastifyInterceptors;
|
|
69
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FastifyHandlerOptions<T>>);
|
|
70
|
+
handle(request: AnyFastifyRequest, reply: AnyFastifyReply, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<FastifyHandlerHandleResult>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface RPCHandlerOptions<T extends Context> extends FastifyHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
|
|
74
|
+
/**
|
|
75
|
+
* Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
|
|
76
|
+
*/
|
|
77
|
+
csrfGuardPlugin?: {
|
|
78
|
+
/**
|
|
79
|
+
* If `false`, this plugin is disabled.
|
|
80
|
+
*
|
|
81
|
+
* @default true
|
|
82
|
+
*/
|
|
83
|
+
enabled?: boolean;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Serves an oRPC router over the RPC protocol inside a Fastify server.
|
|
88
|
+
*
|
|
89
|
+
* @see {@link https://orpc.dev/docs/adapters/fastify | Fastify Adapter}
|
|
90
|
+
*/
|
|
91
|
+
declare class RPCHandler<T extends Context> extends FastifyHandler<T> {
|
|
92
|
+
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { CompositeFastifyHandlerPlugin, FastifyHandler, RPCHandler };
|
|
96
|
+
export type { FastifyHandlerFastifyInterceptor, FastifyHandlerFastifyInterceptorOptions, FastifyHandlerHandleResult, FastifyHandlerOptions, FastifyHandlerPlugin, RPCHandlerOptions };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { SendStandardResponseOptions, AnyFastifyRequest, AnyFastifyReply } from '@standardserver/fastify';
|
|
3
|
+
import { C as Context } from '../../shared/server.CwrYlF72.js';
|
|
4
|
+
import { S as StandardHandlerPlugin, c as StandardHandlerHandleOptions, b as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DrN1Pj1-.js';
|
|
5
|
+
import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
|
|
6
|
+
import { R as Router } from '../../shared/server.DtfwuV6U.js';
|
|
7
|
+
import { R as RPCHandlerCodecOptions } from '../../shared/server.BUvC0G_8.js';
|
|
8
|
+
import '@orpc/client';
|
|
9
|
+
import '@orpc/contract';
|
|
10
|
+
import '@standardserver/core';
|
|
11
|
+
|
|
12
|
+
interface FastifyHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
|
13
|
+
/**
|
|
14
|
+
* Initializes the plugin and returns new Fastify handler options.
|
|
15
|
+
* Called once per plugin instance during composition.
|
|
16
|
+
*
|
|
17
|
+
* This method allows plugins to wrap, extend, or transform Fastify handler options
|
|
18
|
+
* such as interceptors, or other configuration.
|
|
19
|
+
*
|
|
20
|
+
* @param options - The current handler options from previous plugins or base configuration
|
|
21
|
+
* @returns Transformed handler options with plugin's modifications applied
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* initFastifyHandlerOptions(options) {
|
|
26
|
+
* return {
|
|
27
|
+
* ...options,
|
|
28
|
+
* fastifyInterceptors: [...(options.fastifyInterceptors || []), myInterceptor]
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
initFastifyHandlerOptions?(options: FastifyHandlerOptions<T>): FastifyHandlerOptions<T>;
|
|
34
|
+
}
|
|
35
|
+
declare class CompositeFastifyHandlerPlugin<T extends Context> implements FastifyHandlerPlugin<T> {
|
|
36
|
+
readonly name = "~composite/fastify";
|
|
37
|
+
protected readonly plugins: FastifyHandlerPlugin<T>[];
|
|
38
|
+
constructor(plugins?: FastifyHandlerPlugin<T>[]);
|
|
39
|
+
initFastifyHandlerOptions(options: FastifyHandlerOptions<T>): FastifyHandlerOptions<T>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type FastifyHandlerHandleResult = {
|
|
43
|
+
matched: true;
|
|
44
|
+
} | {
|
|
45
|
+
matched: false;
|
|
46
|
+
};
|
|
47
|
+
interface FastifyHandlerFastifyInterceptorOptions<T extends Context> extends StandardHandlerHandleOptions<T> {
|
|
48
|
+
request: AnyFastifyRequest;
|
|
49
|
+
reply: AnyFastifyReply;
|
|
50
|
+
sendStandardResponseOptions: SendStandardResponseOptions | undefined;
|
|
51
|
+
}
|
|
52
|
+
type FastifyHandlerFastifyInterceptor<T extends Context> = Interceptor<FastifyHandlerFastifyInterceptorOptions<T>, Promise<FastifyHandlerHandleResult>>;
|
|
53
|
+
interface FastifyHandlerOptions<T extends Context> {
|
|
54
|
+
/**
|
|
55
|
+
* Custom options for `sendStandardResponse`, used to send a `Standard Response`
|
|
56
|
+
*/
|
|
57
|
+
sendStandardResponse?: SendStandardResponseOptions | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Interceptors that run before the mapping between the Standard API and Fastify API,
|
|
60
|
+
* useful for extending the Fastify request/reply before handling, ...
|
|
61
|
+
*/
|
|
62
|
+
fastifyInterceptors?: FastifyHandlerFastifyInterceptor<T>[] | undefined;
|
|
63
|
+
plugins?: FastifyHandlerPlugin<T>[] | undefined;
|
|
64
|
+
}
|
|
65
|
+
declare class FastifyHandler<T extends Context> {
|
|
66
|
+
private readonly standardHandler;
|
|
67
|
+
private readonly sendStandardResponseOptions;
|
|
68
|
+
private readonly fastifyInterceptors;
|
|
69
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FastifyHandlerOptions<T>>);
|
|
70
|
+
handle(request: AnyFastifyRequest, reply: AnyFastifyReply, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<FastifyHandlerHandleResult>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface RPCHandlerOptions<T extends Context> extends FastifyHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
|
|
74
|
+
/**
|
|
75
|
+
* Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
|
|
76
|
+
*/
|
|
77
|
+
csrfGuardPlugin?: {
|
|
78
|
+
/**
|
|
79
|
+
* If `false`, this plugin is disabled.
|
|
80
|
+
*
|
|
81
|
+
* @default true
|
|
82
|
+
*/
|
|
83
|
+
enabled?: boolean;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Serves an oRPC router over the RPC protocol inside a Fastify server.
|
|
88
|
+
*
|
|
89
|
+
* @see {@link https://orpc.dev/docs/adapters/fastify | Fastify Adapter}
|
|
90
|
+
*/
|
|
91
|
+
declare class RPCHandler<T extends Context> extends FastifyHandler<T> {
|
|
92
|
+
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { CompositeFastifyHandlerPlugin, FastifyHandler, RPCHandler };
|
|
96
|
+
export type { FastifyHandlerFastifyInterceptor, FastifyHandlerFastifyInterceptorOptions, FastifyHandlerHandleResult, FastifyHandlerOptions, FastifyHandlerPlugin, RPCHandlerOptions };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { sortPlugins, intercept, resolveMaybeOptionalOptions, toArray } from '@orpc/shared';
|
|
2
|
+
import { toStandardLazyRequest, sendStandardResponse } from '@standardserver/fastify';
|
|
3
|
+
import { r as resolveFriendlyStandardHandlerHandleOptions } from '../../shared/server.W91HSRkE.mjs';
|
|
4
|
+
import { C as CSRFGuardHandlerPlugin } from '../../shared/server.D_QauotT.mjs';
|
|
5
|
+
import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.DEGjTAPW.mjs';
|
|
6
|
+
import '@orpc/client';
|
|
7
|
+
import '@standardserver/core';
|
|
8
|
+
import '../../shared/server.7T18Khvf.mjs';
|
|
9
|
+
import '@orpc/contract';
|
|
10
|
+
import '../../shared/server.DgunZU0v.mjs';
|
|
11
|
+
|
|
12
|
+
class CompositeFastifyHandlerPlugin {
|
|
13
|
+
name = "~composite/fastify";
|
|
14
|
+
plugins;
|
|
15
|
+
constructor(plugins = []) {
|
|
16
|
+
this.plugins = sortPlugins(plugins);
|
|
17
|
+
}
|
|
18
|
+
initFastifyHandlerOptions(options) {
|
|
19
|
+
for (const plugin of this.plugins) {
|
|
20
|
+
if (plugin.initFastifyHandlerOptions) {
|
|
21
|
+
options = plugin.initFastifyHandlerOptions(options);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return options;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
class FastifyHandler {
|
|
29
|
+
constructor(standardHandler, options = {}) {
|
|
30
|
+
this.standardHandler = standardHandler;
|
|
31
|
+
options = new CompositeFastifyHandlerPlugin(options.plugins).initFastifyHandlerOptions(options);
|
|
32
|
+
this.fastifyInterceptors = options.fastifyInterceptors;
|
|
33
|
+
this.sendStandardResponseOptions = options.sendStandardResponse;
|
|
34
|
+
}
|
|
35
|
+
sendStandardResponseOptions;
|
|
36
|
+
fastifyInterceptors;
|
|
37
|
+
async handle(request, reply, ...rest) {
|
|
38
|
+
return intercept(
|
|
39
|
+
this.fastifyInterceptors,
|
|
40
|
+
{
|
|
41
|
+
...resolveFriendlyStandardHandlerHandleOptions(resolveMaybeOptionalOptions(rest)),
|
|
42
|
+
request,
|
|
43
|
+
reply,
|
|
44
|
+
sendStandardResponseOptions: this.sendStandardResponseOptions
|
|
45
|
+
},
|
|
46
|
+
async ({ request: request2, reply: reply2, sendStandardResponseOptions, ...options }) => {
|
|
47
|
+
const standardRequest = toStandardLazyRequest(request2, reply2);
|
|
48
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
|
49
|
+
if (!result.matched) {
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
await sendStandardResponse(reply2, result.response, sendStandardResponseOptions);
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class RPCHandler extends FastifyHandler {
|
|
60
|
+
constructor(router, options = {}) {
|
|
61
|
+
if (options.csrfGuardPlugin?.enabled !== false) {
|
|
62
|
+
options = {
|
|
63
|
+
...options,
|
|
64
|
+
plugins: [...toArray(options.plugins), new CSRFGuardHandlerPlugin()]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const codec = new RPCHandlerCodec(router, options);
|
|
68
|
+
const handler = new StandardHandler(codec, options);
|
|
69
|
+
super(handler, options);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { CompositeFastifyHandlerPlugin, FastifyHandler, RPCHandler };
|