@orpc/server 2.0.0-beta.49 → 2.0.0-beta.50
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/dist/adapters/aws-lambda/handler.d.ts +17 -15
- package/dist/adapters/aws-lambda/handler.js +23 -23
- package/dist/adapters/aws-lambda/index.d.ts +4 -16
- package/dist/adapters/aws-lambda/index.js +2 -2
- package/dist/adapters/aws-lambda/rpc-handler.d.ts +9 -9
- package/dist/adapters/aws-lambda/rpc-handler.js +20 -17
- package/dist/adapters/crossws/handler.d.ts +44 -42
- package/dist/adapters/crossws/handler.js +53 -60
- package/dist/adapters/crossws/index.d.ts +3 -2
- package/dist/adapters/crossws/index.js +2 -2
- package/dist/adapters/crossws/rpc-handler.d.ts +10 -10
- package/dist/adapters/crossws/rpc-handler.js +17 -14
- package/dist/adapters/fastify/handler.d.ts +17 -15
- package/dist/adapters/fastify/handler.js +20 -20
- package/dist/adapters/fastify/index.d.ts +3 -2
- package/dist/adapters/fastify/index.js +2 -2
- package/dist/adapters/fastify/rpc-handler.d.ts +9 -9
- package/dist/adapters/fastify/rpc-handler.js +16 -13
- package/dist/adapters/fetch/handler.d.ts +19 -17
- package/dist/adapters/fetch/handler.js +22 -22
- package/dist/adapters/fetch/index.d.ts +4 -7
- package/dist/adapters/fetch/index.js +3 -7
- package/dist/adapters/fetch/rpc-handler.d.ts +9 -9
- package/dist/adapters/fetch/rpc-handler.js +18 -15
- package/dist/adapters/message-port/handler.d.ts +58 -60
- package/dist/adapters/message-port/handler.js +72 -86
- package/dist/adapters/message-port/index.d.ts +3 -2
- package/dist/adapters/message-port/index.js +2 -2
- package/dist/adapters/message-port/rpc-handler.d.ts +9 -9
- package/dist/adapters/message-port/rpc-handler.js +17 -14
- package/dist/adapters/node/handler.d.ts +17 -15
- package/dist/adapters/node/handler.js +20 -20
- package/dist/adapters/node/index.d.ts +4 -7
- package/dist/adapters/node/index.js +3 -7
- package/dist/adapters/node/rpc-handler.d.ts +9 -9
- package/dist/adapters/node/rpc-handler.js +17 -14
- package/dist/adapters/standard/codec.d.ts +13 -13
- package/dist/adapters/standard/handler.d.ts +49 -49
- package/dist/adapters/standard/handler.js +205 -205
- package/dist/adapters/standard/index.d.ts +7 -6
- package/dist/adapters/standard/index.js +4 -5
- package/dist/adapters/standard/plugin.d.ts +25 -31
- package/dist/adapters/standard/plugin.js +14 -16
- package/dist/adapters/standard/rpc-handler-codec.d.ts +39 -43
- package/dist/adapters/standard/rpc-handler-codec.js +50 -51
- package/dist/adapters/standard/rpc-matcher.d.ts +40 -40
- package/dist/adapters/standard/rpc-matcher.js +103 -149
- package/dist/adapters/standard/utils.d.ts +8 -8
- package/dist/adapters/standard/utils.js +7 -5
- package/dist/adapters/standard-peer/index.d.ts +2 -1
- package/dist/adapters/standard-peer/index.js +1 -1
- package/dist/adapters/standard-peer/utils.d.ts +6 -4
- package/dist/adapters/standard-peer/utils.js +12 -6
- package/dist/adapters/websocket/handler.d.ts +52 -50
- package/dist/adapters/websocket/handler.js +75 -85
- package/dist/adapters/websocket/index.d.ts +3 -2
- package/dist/adapters/websocket/index.js +2 -2
- package/dist/adapters/websocket/rpc-handler.d.ts +9 -9
- package/dist/adapters/websocket/rpc-handler.js +17 -14
- package/dist/builder-variants.d.ts +195 -195
- package/dist/builder.d.ts +103 -104
- package/dist/builder.js +198 -224
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +4 -2
- package/dist/context.d.ts +3 -3
- package/dist/extensions/callable.d.ts +11 -11
- package/dist/extensions/callable.js +6 -5
- package/dist/helpers/base64url.d.ts +1 -1
- package/dist/helpers/base64url.js +44 -49
- package/dist/helpers/cookie.d.ts +10 -11
- package/dist/helpers/cookie.js +56 -63
- package/dist/helpers/encryption.d.ts +1 -1
- package/dist/helpers/encryption.js +80 -70
- package/dist/helpers/index.d.ts +5 -4
- package/dist/helpers/index.js +4 -4
- package/dist/helpers/signing.d.ts +1 -1
- package/dist/helpers/signing.js +72 -82
- package/dist/implementer-procedure.d.ts +12 -13
- package/dist/implementer-procedure.js +37 -44
- package/dist/implementer-router.d.ts +30 -36
- package/dist/implementer-router.js +92 -111
- package/dist/implementer.d.ts +8 -8
- package/dist/implementer.js +28 -35
- package/dist/index.d.ts +22 -61
- package/dist/index.js +16 -48
- package/dist/lazy.d.ts +14 -14
- package/dist/lazy.js +19 -30
- package/dist/middleware-decorated.d.ts +8 -9
- package/dist/middleware-decorated.js +66 -70
- package/dist/middleware.d.ts +34 -34
- package/dist/plugins/batch.d.ts +75 -75
- package/dist/plugins/batch.js +345 -379
- package/dist/plugins/cors.d.ts +60 -64
- package/dist/plugins/cors.js +118 -111
- package/dist/plugins/get-method-csrf-protection.d.ts +8 -6
- package/dist/plugins/get-method-csrf-protection.js +47 -63
- package/dist/plugins/head-method.d.ts +11 -9
- package/dist/plugins/head-method.js +97 -94
- package/dist/plugins/index.d.ts +15 -39
- package/dist/plugins/index.js +14 -29
- package/dist/plugins/method-override.d.ts +30 -28
- package/dist/plugins/method-override.js +53 -49
- package/dist/plugins/request-compression.d.ts +11 -9
- package/dist/plugins/request-compression.js +52 -79
- package/dist/plugins/request-headers.d.ts +10 -8
- package/dist/plugins/request-headers.js +27 -29
- package/dist/plugins/request-limit.d.ts +21 -19
- package/dist/plugins/request-limit.js +60 -67
- package/dist/plugins/response-compression.d.ts +42 -39
- package/dist/plugins/response-compression.js +150 -202
- package/dist/plugins/response-headers.d.ts +15 -13
- package/dist/plugins/response-headers.js +43 -46
- package/dist/plugins/rethrow.d.ts +25 -23
- package/dist/plugins/rethrow.js +46 -58
- package/dist/plugins/signal-sync.d.ts +7 -5
- package/dist/plugins/signal-sync.js +71 -86
- package/dist/plugins/timeout.d.ts +29 -27
- package/dist/plugins/timeout.js +61 -58
- package/dist/procedure-client.d.ts +14 -15
- package/dist/procedure-client.js +149 -166
- package/dist/procedure-decorated.d.ts +9 -9
- package/dist/procedure-decorated.js +36 -44
- package/dist/procedure-utils.d.ts +10 -30
- package/dist/procedure-utils.js +39 -40
- package/dist/procedure.d.ts +60 -60
- package/dist/procedure.js +18 -24
- package/dist/router-client.d.ts +9 -11
- package/dist/router-client.js +33 -41
- package/dist/router-hidden.js +10 -12
- package/dist/router-utils.d.ts +13 -30
- package/dist/router-utils.js +146 -191
- package/dist/router.d.ts +12 -26
- package/package.json +10 -10
- package/dist/adapters/standard/codec.js +0 -1
- package/dist/builder-variants.js +0 -1
- package/dist/context.js +0 -1
- package/dist/middleware.js +0 -1
- package/dist/router-hidden.d.ts +0 -5
- package/dist/router.js +0 -1
|
@@ -1,205 +1,205 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
1
|
+
import { createProcedureClient } from "../../procedure-client.js";
|
|
2
|
+
import { CompositeStandardHandlerPlugin } from "./plugin.js";
|
|
3
|
+
import { ORPC_NAME, getTracer, intercept, isAsyncIteratorObject, matchesHttpPathPrefix, override, recordSpanError, runWithSpan, toArray, toTracingException, traceAsyncIterator, traceReadableStream, value, wrapAsyncIterator, wrapReadableStream } from "@orpc/shared";
|
|
4
|
+
import { ORPCError, toORPCError } from "@orpc/client";
|
|
5
|
+
import { EventStreamErrorEvent, flattenStandardHeader, parseStandardUrl } from "@standard-server/core";
|
|
6
|
+
// src/adapters/standard/handler.ts
|
|
7
|
+
var StandardHandler = class {
|
|
8
|
+
codec;
|
|
9
|
+
routingInterceptors;
|
|
10
|
+
interceptors;
|
|
11
|
+
clientInterceptors;
|
|
12
|
+
constructor(codec, options) {
|
|
13
|
+
this.codec = codec;
|
|
14
|
+
options = new CompositeStandardHandlerPlugin([...toArray(options.plugins), new TracingHandlerPlugin()]).init(options);
|
|
15
|
+
this.routingInterceptors = options.routingInterceptors;
|
|
16
|
+
this.interceptors = options.interceptors;
|
|
17
|
+
this.clientInterceptors = options.clientInterceptors;
|
|
18
|
+
}
|
|
19
|
+
async handle(request, options) {
|
|
20
|
+
const { prefix } = options;
|
|
21
|
+
if (prefix && !matchesHttpPathPrefix(request.url, prefix)) return {
|
|
22
|
+
matched: false,
|
|
23
|
+
response: void 0
|
|
24
|
+
};
|
|
25
|
+
const context = await value(options.context, request);
|
|
26
|
+
return intercept(this.routingInterceptors, {
|
|
27
|
+
context,
|
|
28
|
+
prefix,
|
|
29
|
+
request
|
|
30
|
+
}, async ({ context, prefix, request }) => {
|
|
31
|
+
const span = getTracer()?.getActiveSpan();
|
|
32
|
+
let step;
|
|
33
|
+
const matchedOrNot = await runWithSpan("find_procedure", () => this.codec.resolveProcedure(request, {
|
|
34
|
+
context,
|
|
35
|
+
prefix
|
|
36
|
+
}));
|
|
37
|
+
if (!matchedOrNot) {
|
|
38
|
+
/**
|
|
39
|
+
* [Semantic conventions for HTTP spans](https://opentelemetry.io/docs/specs/semconv/http/http-spans/)
|
|
40
|
+
*/
|
|
41
|
+
span?.updateName(`${ORPC_NAME}_no_match`);
|
|
42
|
+
span?.setAttribute("http.request.method", request.method);
|
|
43
|
+
span?.setAttribute("url.path", request.url);
|
|
44
|
+
return { matched: false };
|
|
45
|
+
}
|
|
46
|
+
const { path, procedure, decodeInput } = matchedOrNot;
|
|
47
|
+
/**
|
|
48
|
+
* [Semantic conventions for RPC spans](https://opentelemetry.io/docs/specs/semconv/rpc/rpc-spans/)
|
|
49
|
+
*/
|
|
50
|
+
span?.updateName(`${ORPC_NAME}.${path.join("/")}`);
|
|
51
|
+
span?.setAttribute("rpc.system", ORPC_NAME);
|
|
52
|
+
span?.setAttribute("rpc.method", path.join("."));
|
|
53
|
+
try {
|
|
54
|
+
return {
|
|
55
|
+
matched: true,
|
|
56
|
+
response: await intercept(this.interceptors, {
|
|
57
|
+
context,
|
|
58
|
+
prefix,
|
|
59
|
+
request,
|
|
60
|
+
path,
|
|
61
|
+
procedure,
|
|
62
|
+
decodeInput
|
|
63
|
+
}, async ({ context, prefix, request, path, procedure, decodeInput }) => {
|
|
64
|
+
step = "decode_input";
|
|
65
|
+
let input = await runWithSpan("decode_input", decodeInput);
|
|
66
|
+
step = void 0;
|
|
67
|
+
if (getTracer() && isAsyncIteratorObject(input))
|
|
68
|
+
/**
|
|
69
|
+
* @warning
|
|
70
|
+
* Remember use `override` for AsyncIteratorObject to remain other special properties
|
|
71
|
+
*/
|
|
72
|
+
input = override(input, traceAsyncIterator("consume_async_iterator_object_input", input));
|
|
73
|
+
else if (getTracer() && input instanceof ReadableStream)
|
|
74
|
+
/**
|
|
75
|
+
* @warning
|
|
76
|
+
* Remember use `override` for ReadableStream to remain other special properties
|
|
77
|
+
*/
|
|
78
|
+
input = override(input, traceReadableStream("consume_octet_stream_input", input));
|
|
79
|
+
const client = createProcedureClient(procedure, {
|
|
80
|
+
context,
|
|
81
|
+
path,
|
|
82
|
+
interceptors: this.clientInterceptors
|
|
83
|
+
});
|
|
84
|
+
/**
|
|
85
|
+
* No need to use `runWithSpan` here, because the client already has its own span.
|
|
86
|
+
*/
|
|
87
|
+
step = "call_procedure";
|
|
88
|
+
const output = await client(input, {
|
|
89
|
+
signal: request.signal,
|
|
90
|
+
lastEventId: flattenStandardHeader(request.headers["last-event-id"])
|
|
91
|
+
});
|
|
92
|
+
step = void 0;
|
|
93
|
+
return await this.codec.encodeOutput(output, procedure, path, {
|
|
94
|
+
context,
|
|
95
|
+
prefix
|
|
96
|
+
});
|
|
97
|
+
})
|
|
98
|
+
};
|
|
99
|
+
} catch (e) {
|
|
100
|
+
/**
|
|
101
|
+
* Only errors that happen outside of the `call_procedure` step should be set as an error.
|
|
102
|
+
* Because a business logic error should not be considered as a protocol-level error.
|
|
103
|
+
*/
|
|
104
|
+
if (step !== "call_procedure") recordSpanError(span, e);
|
|
105
|
+
const error = step === "decode_input" && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
|
|
106
|
+
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
|
107
|
+
cause: e
|
|
108
|
+
}) : toORPCError(e);
|
|
109
|
+
return {
|
|
110
|
+
matched: true,
|
|
111
|
+
response: await this.codec.encodeError(error, procedure, path, {
|
|
112
|
+
context,
|
|
113
|
+
prefix
|
|
114
|
+
})
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var TracingHandlerPlugin = class {
|
|
121
|
+
name = "~tracing";
|
|
122
|
+
init(options) {
|
|
123
|
+
return {
|
|
124
|
+
...options,
|
|
125
|
+
routingInterceptors: [async ({ next, request }) => {
|
|
126
|
+
const tracer = getTracer();
|
|
127
|
+
if (!tracer) return next();
|
|
128
|
+
const parent = tracer.extract?.(request.headers);
|
|
129
|
+
/**
|
|
130
|
+
* The search part is excluded because span names should have low cardinality.
|
|
131
|
+
* The name is replaced with the procedure path once the request is routed.
|
|
132
|
+
*/
|
|
133
|
+
const [pathname] = parseStandardUrl(request.url);
|
|
134
|
+
return tracer.startActiveSpan(`${request.method} ${pathname}`, parent, async (span) => {
|
|
135
|
+
try {
|
|
136
|
+
const result = await next();
|
|
137
|
+
if (!result.matched) {
|
|
138
|
+
span.end();
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
const body = result.response.body;
|
|
142
|
+
if (isAsyncIteratorObject(body)) return {
|
|
143
|
+
...result,
|
|
144
|
+
response: {
|
|
145
|
+
...result.response,
|
|
146
|
+
/**
|
|
147
|
+
* @remarks
|
|
148
|
+
* **Warning**: Remember use `override` for remaining special properties
|
|
149
|
+
*/
|
|
150
|
+
body: override(body, wrapAsyncIterator(body, {
|
|
151
|
+
runWith: (fn) => tracer.withActiveSpan(span, fn),
|
|
152
|
+
onError(error) {
|
|
153
|
+
/**
|
|
154
|
+
* Errors here are internal (interceptor/framework) failures,
|
|
155
|
+
* except `EventStreamErrorEvent`: a business error the protocol delivers
|
|
156
|
+
* inside the event stream, already logged by the client interceptor.
|
|
157
|
+
*/
|
|
158
|
+
if (!(error instanceof EventStreamErrorEvent)) span.recordException("error", toTracingException(error));
|
|
159
|
+
},
|
|
160
|
+
onFinish() {
|
|
161
|
+
span.end();
|
|
162
|
+
}
|
|
163
|
+
}))
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
if (body instanceof ReadableStream) return {
|
|
167
|
+
...result,
|
|
168
|
+
response: {
|
|
169
|
+
...result.response,
|
|
170
|
+
/**
|
|
171
|
+
* @remarks
|
|
172
|
+
* **Warning**: Remember use `override` for remaining special properties
|
|
173
|
+
*/
|
|
174
|
+
body: override(body, wrapReadableStream(body, {
|
|
175
|
+
runWith: (fn) => tracer.withActiveSpan(span, fn),
|
|
176
|
+
onError(error) {
|
|
177
|
+
/**
|
|
178
|
+
* Any error here is internal (interceptor/framework), not business logic.
|
|
179
|
+
* Indicates unexpected handler failure.
|
|
180
|
+
*/
|
|
181
|
+
span.recordException("error", toTracingException(error));
|
|
182
|
+
},
|
|
183
|
+
onFinish() {
|
|
184
|
+
span.end();
|
|
185
|
+
}
|
|
186
|
+
}))
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
span.end();
|
|
190
|
+
return result;
|
|
191
|
+
} catch (e) {
|
|
192
|
+
/**
|
|
193
|
+
* Any error here is internal (interceptor/framework), not business logic.
|
|
194
|
+
* Always recorded as an error, even when it is an abort error.
|
|
195
|
+
*/
|
|
196
|
+
span.recordException("error", toTracingException(e));
|
|
197
|
+
span.end();
|
|
198
|
+
throw e;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}, ...toArray(options.routingInterceptors)]
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
export { StandardHandler };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { StandardHandlerCodec, StandardHandlerCodecResolvedProcedure } from "./codec.js";
|
|
2
|
+
import { ResolvedStandardHandlerHandleOptions, StandardHandler, StandardHandlerHandleOptions, StandardHandlerHandleResult, StandardHandlerInterceptor, StandardHandlerInterceptorOptions, StandardHandlerOptions, StandardHandlerRoutingInterceptor, StandardHandlerRoutingInterceptorOptions } from "./handler.js";
|
|
3
|
+
import { StandardHandlerPlugin } from "./plugin.js";
|
|
4
|
+
import { RPCHandlerCodec, RPCHandlerCodecOptions } from "./rpc-handler-codec.js";
|
|
5
|
+
import { RPCMatcher, RPCMatcherOptions, RPC_DEFAULT_ALLOW_METHODS } from "./rpc-matcher.js";
|
|
6
|
+
import { FriendlyStandardHandlerHandleOptions, resolveFriendlyStandardHandlerHandleOptions } from "./utils.js";
|
|
7
|
+
export { FriendlyStandardHandlerHandleOptions, RPCHandlerCodec, RPCHandlerCodecOptions, RPCMatcher, RPCMatcherOptions, RPC_DEFAULT_ALLOW_METHODS, ResolvedStandardHandlerHandleOptions, StandardHandler, StandardHandlerCodec, StandardHandlerCodecResolvedProcedure, StandardHandlerHandleOptions, StandardHandlerHandleResult, StandardHandlerInterceptor, StandardHandlerInterceptorOptions, StandardHandlerOptions, type StandardHandlerPlugin, StandardHandlerRoutingInterceptor, StandardHandlerRoutingInterceptorOptions, resolveFriendlyStandardHandlerHandleOptions };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export * from './utils.js';
|
|
1
|
+
export { StandardHandler } from "./handler.js";
|
|
2
|
+
export { RPCHandlerCodec } from "./rpc-handler-codec.js";
|
|
3
|
+
export { RPCMatcher, RPC_DEFAULT_ALLOW_METHODS } from "./rpc-matcher.js";
|
|
4
|
+
export { resolveFriendlyStandardHandlerHandleOptions } from "./utils.js";
|
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { Context } from "../../context.js";
|
|
2
|
+
import { StandardHandlerOptions } from "./handler.js";
|
|
3
|
+
import { OrderablePlugin } from "@orpc/shared";
|
|
4
4
|
export interface StandardHandlerPlugin<T extends Context> extends OrderablePlugin {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
export declare class CompositeStandardHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
28
|
-
readonly name = "~composite";
|
|
29
|
-
protected readonly plugins: StandardHandlerPlugin<T>[];
|
|
30
|
-
constructor(plugins?: StandardHandlerPlugin<T>[]);
|
|
31
|
-
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
32
|
-
}
|
|
5
|
+
/**
|
|
6
|
+
* Initializes the plugin and returns new handler options.
|
|
7
|
+
* Called once per plugin instance during composition.
|
|
8
|
+
*
|
|
9
|
+
* This method allows plugins to wrap, extend, or transform handler options
|
|
10
|
+
* such as interceptors, or configuration.
|
|
11
|
+
*
|
|
12
|
+
* @param options - The current handler options from previous plugins or base configuration
|
|
13
|
+
* @returns Transformed handler options with plugin's modifications applied
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* init(options) {
|
|
18
|
+
* return {
|
|
19
|
+
* ...options,
|
|
20
|
+
* interceptors: [...(options.interceptors || []), myInterceptor]
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
init?(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
26
|
+
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { sortPlugins } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
import { sortPlugins } from "@orpc/shared";
|
|
2
|
+
// src/adapters/standard/plugin.ts
|
|
3
|
+
var CompositeStandardHandlerPlugin = class {
|
|
4
|
+
name = "~composite";
|
|
5
|
+
plugins;
|
|
6
|
+
constructor(plugins = []) {
|
|
7
|
+
this.plugins = sortPlugins(plugins);
|
|
8
|
+
}
|
|
9
|
+
init(options) {
|
|
10
|
+
for (const plugin of this.plugins) if (plugin.init) options = plugin.init(options);
|
|
11
|
+
return options;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export { CompositeStandardHandlerPlugin };
|
|
@@ -1,46 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
1
|
+
import { Context } from "../../context.js";
|
|
2
|
+
import { AnyProcedure } from "../../procedure.js";
|
|
3
|
+
import { ResolvedStandardHandlerHandleOptions } from "./handler.js";
|
|
4
|
+
import { StandardHandlerCodec, StandardHandlerCodecResolvedProcedure } from "./codec.js";
|
|
5
|
+
import { AnyRouter } from "../../router.js";
|
|
6
|
+
import "./index.js";
|
|
7
|
+
import { RPCMatcherOptions } from "./rpc-matcher.js";
|
|
8
|
+
import { Promisable, Public, Value } from "@orpc/shared";
|
|
9
|
+
import { AnyORPCError, RPCSerializer } from "@orpc/client";
|
|
10
|
+
import { StandardLazyRequest, StandardResponse } from "@standard-server/core";
|
|
10
11
|
export interface RPCHandlerCodecOptions<T extends Context> extends RPCMatcherOptions {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* Codes missing from the map fall back to `DEFAULT_ERROR_STATUS` (400).
|
|
32
|
-
*
|
|
33
|
-
* @default COMMON_ERROR_STATUS_MAP
|
|
34
|
-
*/
|
|
35
|
-
errorStatusMap?: Record<string, number> | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Override the default RPC serializer.
|
|
14
|
+
*/
|
|
15
|
+
serializer?: Public<RPCSerializer> | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Resolve HTTP status for encoded successful outputs.
|
|
18
|
+
*
|
|
19
|
+
* Value should be in the `2xx` range and must be less than `400`.
|
|
20
|
+
*
|
|
21
|
+
* @default DEFAULT_SUCCESS_STATUS (200)
|
|
22
|
+
*/
|
|
23
|
+
outputStatus?: Value<number, [output: unknown, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>]> | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Mapping ORPCError Code -> HTTP Status Code
|
|
26
|
+
* The status code should be in the `4xx` or `5xx` range (must be greater than or equal to `400`).
|
|
27
|
+
* Codes missing from the map fall back to `DEFAULT_ERROR_STATUS` (400).
|
|
28
|
+
*
|
|
29
|
+
* @default COMMON_ERROR_STATUS_MAP
|
|
30
|
+
*/
|
|
31
|
+
errorStatusMap?: Record<string, number> | undefined;
|
|
36
32
|
}
|
|
37
33
|
export declare class RPCHandlerCodec<T extends Context> implements StandardHandlerCodec<T> {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
34
|
+
private readonly matcher;
|
|
35
|
+
private readonly serializer;
|
|
36
|
+
private readonly errorStatusMap;
|
|
37
|
+
private readonly outputStatus;
|
|
38
|
+
constructor(router: AnyRouter, options?: RPCHandlerCodecOptions<T>);
|
|
39
|
+
resolveProcedure(request: StandardLazyRequest, options: ResolvedStandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
40
|
+
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
41
|
+
encodeError(error: AnyORPCError, _procedure: AnyProcedure, _path: string[], _options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
42
|
+
}
|