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