@orpc/server 2.0.0-beta.35 → 2.0.0-beta.37

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 (43) hide show
  1. package/README.md +29 -20
  2. package/dist/adapters/aws-lambda/index.d.mts +6 -49
  3. package/dist/adapters/aws-lambda/index.d.ts +6 -49
  4. package/dist/adapters/aws-lambda/index.mjs +13 -40
  5. package/dist/adapters/crossws/index.d.mts +2 -2
  6. package/dist/adapters/crossws/index.d.ts +2 -2
  7. package/dist/adapters/crossws/index.mjs +4 -3
  8. package/dist/adapters/fastify/index.d.mts +6 -49
  9. package/dist/adapters/fastify/index.d.ts +6 -49
  10. package/dist/adapters/fastify/index.mjs +13 -40
  11. package/dist/adapters/fetch/index.d.mts +7 -49
  12. package/dist/adapters/fetch/index.d.ts +7 -49
  13. package/dist/adapters/fetch/index.mjs +15 -41
  14. package/dist/adapters/message-port/index.d.mts +3 -3
  15. package/dist/adapters/message-port/index.d.ts +3 -3
  16. package/dist/adapters/message-port/index.mjs +4 -3
  17. package/dist/adapters/node/index.d.mts +7 -50
  18. package/dist/adapters/node/index.d.ts +7 -50
  19. package/dist/adapters/node/index.mjs +13 -40
  20. package/dist/adapters/standard/index.d.mts +91 -17
  21. package/dist/adapters/standard/index.d.ts +91 -17
  22. package/dist/adapters/standard/index.mjs +2 -2
  23. package/dist/adapters/standard-peer/index.d.mts +4 -9
  24. package/dist/adapters/standard-peer/index.d.ts +4 -9
  25. package/dist/adapters/standard-peer/index.mjs +10 -2
  26. package/dist/adapters/websocket/index.d.mts +3 -3
  27. package/dist/adapters/websocket/index.d.ts +3 -3
  28. package/dist/adapters/websocket/index.mjs +4 -3
  29. package/dist/index.mjs +4 -6
  30. package/dist/plugins/index.d.mts +1 -1
  31. package/dist/plugins/index.d.ts +1 -1
  32. package/dist/shared/{server.R0uHWfBo.d.mts → server.B5K1CViq.d.mts} +20 -9
  33. package/dist/shared/{server.BYnwk7Xz.mjs → server.BynNaBBA.mjs} +7 -9
  34. package/dist/shared/{server.sNWd6DAG.mjs → server.C0lFtoHU.mjs} +72 -11
  35. package/dist/shared/{server.CAiLRqPf.d.mts → server.C7xllBNN.d.mts} +1 -1
  36. package/dist/shared/server.CFqSIFnT.d.mts +14 -0
  37. package/dist/shared/{server.DEeCcNd6.d.ts → server.Cxranw-8.d.ts} +20 -9
  38. package/dist/shared/{server.b2-J4t6T.d.ts → server.D0dr-F8u.d.ts} +1 -1
  39. package/dist/shared/server.RRVK1xTV.d.ts +14 -0
  40. package/package.json +10 -10
  41. package/dist/shared/server.BGMO5dst.d.ts +0 -91
  42. package/dist/shared/server.CX4vUnDk.mjs +0 -11
  43. package/dist/shared/server.DcHlvZFK.d.mts +0 -91
@@ -1,8 +1,8 @@
1
1
  import { ORPCError, toORPCError, RPCSerializer, COMMON_ERROR_STATUS_MAP } from '@orpc/client';
2
- import { sortPlugins, toArray, matchesHttpPathPrefix, intercept, getTracer, runWithSpan, ORPC_NAME, isAsyncIteratorObject, override, traceAsyncIterator, traceReadableStream, recordSpanError, pathToHttpPath, normalizeHttpPath, value, parseEmptyableJSON, getOwn } from '@orpc/shared';
3
- import { flattenStandardHeader, parseStandardUrl } from '@standard-server/core';
2
+ import { sortPlugins, toArray, matchesHttpPathPrefix, value, intercept, getTracer, runWithSpan, ORPC_NAME, isAsyncIteratorObject, override, traceAsyncIterator, traceReadableStream, recordSpanError, wrapAsyncIterator, toTracingException, wrapReadableStream, pathToHttpPath, normalizeHttpPath, parseEmptyableJSON, getOwn } from '@orpc/shared';
3
+ import { flattenStandardHeader, parseStandardUrl, ErrorEvent } from '@standard-server/core';
4
4
  import { c as createProcedureClient, u as unlazy, P as Procedure } from './server.Djb_ebJT.mjs';
5
- import { w as walkProcedureContractsSync, g as getRouter, c as createContractProcedure, D as DEFAULT_SUCCESS_STATUS, a as DEFAULT_ERROR_STATUS } from './server.BYnwk7Xz.mjs';
5
+ import { w as walkProcedureContractsSync, g as getRouter, c as createContractProcedure, D as DEFAULT_SUCCESS_STATUS, a as DEFAULT_ERROR_STATUS } from './server.BynNaBBA.mjs';
6
6
 
7
7
  class CompositeStandardHandlerPlugin {
8
8
  name = "~composite";
@@ -24,8 +24,8 @@ class StandardHandler {
24
24
  constructor(codec, options) {
25
25
  this.codec = codec;
26
26
  options = new CompositeStandardHandlerPlugin([
27
- new TracingHandlerPlugin(),
28
- ...toArray(options.plugins)
27
+ ...toArray(options.plugins),
28
+ new TracingHandlerPlugin()
29
29
  ]).init(options);
30
30
  this.routingInterceptors = options.routingInterceptors;
31
31
  this.interceptors = options.interceptors;
@@ -34,10 +34,12 @@ class StandardHandler {
34
34
  routingInterceptors;
35
35
  interceptors;
36
36
  clientInterceptors;
37
- async handle(request, { context, prefix }) {
37
+ async handle(request, options) {
38
+ const { prefix } = options;
38
39
  if (prefix && !matchesHttpPathPrefix(request.url, prefix)) {
39
40
  return { matched: false, response: void 0 };
40
41
  }
42
+ const context = await value(options.context, request);
41
43
  return intercept(
42
44
  this.routingInterceptors,
43
45
  { context, prefix, request },
@@ -108,12 +110,71 @@ class TracingHandlerPlugin {
108
110
  // Should be placed before user-provided interceptors to help them access the current active span.
109
111
  async ({ next, request }) => {
110
112
  const tracer = getTracer();
111
- const parent = tracer?.extract?.(request.headers);
113
+ if (!tracer) {
114
+ return next();
115
+ }
116
+ const parent = tracer.extract?.(request.headers);
112
117
  const [pathname] = parseStandardUrl(request.url);
113
- return runWithSpan(
114
- { name: `${request.method} ${pathname}`, parent },
115
- () => next()
116
- );
118
+ return tracer.startActiveSpan(`${request.method} ${pathname}`, parent, async (span) => {
119
+ try {
120
+ const result = await next();
121
+ if (!result.matched) {
122
+ span.end();
123
+ return result;
124
+ }
125
+ const body = result.response.body;
126
+ if (isAsyncIteratorObject(body)) {
127
+ return {
128
+ ...result,
129
+ response: {
130
+ ...result.response,
131
+ /**
132
+ * @remarks
133
+ * **Warning**: Remember use `override` for remaining special properties
134
+ */
135
+ body: override(body, wrapAsyncIterator(body, {
136
+ runWith: (fn) => tracer.withActiveSpan(span, fn),
137
+ onError(error) {
138
+ if (!(error instanceof ErrorEvent)) {
139
+ span.recordException("error", toTracingException(error));
140
+ }
141
+ },
142
+ onFinish() {
143
+ span.end();
144
+ }
145
+ }))
146
+ }
147
+ };
148
+ }
149
+ if (body instanceof ReadableStream) {
150
+ return {
151
+ ...result,
152
+ response: {
153
+ ...result.response,
154
+ /**
155
+ * @remarks
156
+ * **Warning**: Remember use `override` for remaining special properties
157
+ */
158
+ body: override(body, wrapReadableStream(body, {
159
+ runWith: (fn) => tracer.withActiveSpan(span, fn),
160
+ onError(error) {
161
+ span.recordException("error", toTracingException(error));
162
+ },
163
+ onFinish() {
164
+ span.end();
165
+ }
166
+ }))
167
+ }
168
+ };
169
+ }
170
+ span.end();
171
+ return result;
172
+ } catch (e) {
173
+ span.recordException("error", toTracingException(e));
174
+ span.end();
175
+ throw e;
176
+ }
177
+ });
117
178
  },
118
179
  ...toArray(options.routingInterceptors)
119
180
  ]
@@ -1,5 +1,5 @@
1
1
  import { C as Context } from './server.BsujoJoF.mjs';
2
- import { S as StandardHandlerPlugin, a as StandardHandlerOptions } from './server.R0uHWfBo.mjs';
2
+ import { b as StandardHandlerPlugin, c as StandardHandlerOptions } from './server.B5K1CViq.mjs';
3
3
 
4
4
  interface RequestLimitHandlerPluginOptions {
5
5
  /**
@@ -0,0 +1,14 @@
1
+ import { Value, Promisable } from '@orpc/shared';
2
+ import { StandardLazyRequest } from '@standard-server/core';
3
+ import { C as Context } from './server.BsujoJoF.mjs';
4
+ import { a as StandardHandlerHandleOptions } from './server.B5K1CViq.mjs';
5
+
6
+ type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (object extends T ? {
7
+ context?: Value<Promisable<T>, [request: StandardLazyRequest]>;
8
+ } : {
9
+ context: Value<Promisable<T>, [request: StandardLazyRequest]>;
10
+ });
11
+ declare function resolveFriendlyStandardHandlerHandleOptions<T extends Context>(options: FriendlyStandardHandlerHandleOptions<T>): StandardHandlerHandleOptions<T>;
12
+
13
+ export { resolveFriendlyStandardHandlerHandleOptions as r };
14
+ export type { FriendlyStandardHandlerHandleOptions as F };
@@ -1,5 +1,5 @@
1
1
  import { AnyORPCError } from '@orpc/client';
2
- import { OrderablePlugin, Interceptor, Promisable } from '@orpc/shared';
2
+ import { OrderablePlugin, Value, Promisable, Interceptor } from '@orpc/shared';
3
3
  import { StandardLazyRequest, StandardResponse } from '@standard-server/core';
4
4
  import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.BsujoJoF.js';
5
5
  import { Schema, ErrorMap } from '@orpc/contract';
@@ -36,6 +36,17 @@ declare class CompositeStandardHandlerPlugin<T extends Context> implements Stand
36
36
 
37
37
  interface StandardHandlerHandleOptions<T extends Context> {
38
38
  prefix?: `/${string}` | undefined;
39
+ /**
40
+ * The initial context, or a function (sync or async) that receives the request and returns it.
41
+ * The function only runs once the request passes the prefix check.
42
+ */
43
+ context: Value<Promisable<T>, [request: StandardLazyRequest]>;
44
+ }
45
+ /**
46
+ * `StandardHandlerHandleOptions` after the context has been resolved,
47
+ * this is what interceptors and codecs receive.
48
+ */
49
+ interface ResolvedStandardHandlerHandleOptions<T extends Context> extends Omit<StandardHandlerHandleOptions<T>, 'context'> {
39
50
  context: T;
40
51
  }
41
52
  type StandardHandlerHandleResult = {
@@ -45,11 +56,11 @@ type StandardHandlerHandleResult = {
45
56
  matched: false;
46
57
  response?: undefined;
47
58
  };
48
- interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandlerCodecResolvedProcedure, StandardHandlerHandleOptions<T> {
59
+ interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandlerCodecResolvedProcedure, ResolvedStandardHandlerHandleOptions<T> {
49
60
  request: StandardLazyRequest;
50
61
  }
51
62
  type StandardHandlerInterceptor<T extends Context> = Interceptor<StandardHandlerInterceptorOptions<T>, Promise<StandardResponse>>;
52
- interface StandardHandlerRoutingInterceptorOptions<T extends Context> extends StandardHandlerHandleOptions<T> {
63
+ interface StandardHandlerRoutingInterceptorOptions<T extends Context> extends ResolvedStandardHandlerHandleOptions<T> {
53
64
  request: StandardLazyRequest;
54
65
  }
55
66
  type StandardHandlerRoutingInterceptor<T extends Context> = Interceptor<StandardHandlerRoutingInterceptorOptions<T>, Promise<StandardHandlerHandleResult>>;
@@ -82,7 +93,7 @@ declare class StandardHandler<T extends Context> {
82
93
  private readonly interceptors;
83
94
  private readonly clientInterceptors;
84
95
  constructor(codec: StandardHandlerCodec<T>, options: StandardHandlerOptions<T>);
85
- handle(request: StandardLazyRequest, { context, prefix }: StandardHandlerHandleOptions<T>): Promise<StandardHandlerHandleResult>;
96
+ handle(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerHandleResult>;
86
97
  }
87
98
  declare class TracingHandlerPlugin implements StandardHandlerPlugin<any> {
88
99
  name: string;
@@ -95,10 +106,10 @@ interface StandardHandlerCodecResolvedProcedure {
95
106
  decodeInput: () => Promise<unknown>;
96
107
  }
97
108
  interface StandardHandlerCodec<T extends Context> {
98
- resolveProcedure(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promisable<StandardHandlerCodecResolvedProcedure | undefined>;
99
- encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
100
- encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
109
+ resolveProcedure(request: StandardLazyRequest, options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardHandlerCodecResolvedProcedure | undefined>;
110
+ encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
111
+ encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
101
112
  }
102
113
 
103
- export { CompositeStandardHandlerPlugin as C, TracingHandlerPlugin as T, StandardHandler as b };
104
- export type { StandardHandlerPlugin as S, StandardHandlerOptions as a, StandardHandlerHandleOptions as c, StandardHandlerCodec as d, StandardHandlerCodecResolvedProcedure as e, StandardHandlerRoutingInterceptorOptions as f, StandardHandlerInterceptorOptions as g, StandardHandlerHandleResult as h, StandardHandlerInterceptor as i, StandardHandlerRoutingInterceptor as j };
114
+ export { CompositeStandardHandlerPlugin as C, StandardHandler as S, TracingHandlerPlugin as T };
115
+ export type { ResolvedStandardHandlerHandleOptions as R, StandardHandlerHandleOptions as a, StandardHandlerPlugin as b, StandardHandlerOptions as c, StandardHandlerRoutingInterceptorOptions as d, StandardHandlerInterceptorOptions as e, StandardHandlerCodec as f, StandardHandlerCodecResolvedProcedure as g, StandardHandlerHandleResult as h, StandardHandlerInterceptor as i, StandardHandlerRoutingInterceptor as j };
@@ -1,5 +1,5 @@
1
1
  import { C as Context } from './server.BsujoJoF.js';
2
- import { S as StandardHandlerPlugin, a as StandardHandlerOptions } from './server.DEeCcNd6.js';
2
+ import { b as StandardHandlerPlugin, c as StandardHandlerOptions } from './server.Cxranw-8.js';
3
3
 
4
4
  interface RequestLimitHandlerPluginOptions {
5
5
  /**
@@ -0,0 +1,14 @@
1
+ import { Value, Promisable } from '@orpc/shared';
2
+ import { StandardLazyRequest } from '@standard-server/core';
3
+ import { C as Context } from './server.BsujoJoF.js';
4
+ import { a as StandardHandlerHandleOptions } from './server.Cxranw-8.js';
5
+
6
+ type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (object extends T ? {
7
+ context?: Value<Promisable<T>, [request: StandardLazyRequest]>;
8
+ } : {
9
+ context: Value<Promisable<T>, [request: StandardLazyRequest]>;
10
+ });
11
+ declare function resolveFriendlyStandardHandlerHandleOptions<T extends Context>(options: FriendlyStandardHandlerHandleOptions<T>): StandardHandlerHandleOptions<T>;
12
+
13
+ export { resolveFriendlyStandardHandlerHandleOptions as r };
14
+ export type { FriendlyStandardHandlerHandleOptions as F };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.35",
4
+ "version": "2.0.0-beta.37",
5
5
  "description": "Build typesafe APIs with oRPC: RPC and OpenAPI support, middleware, and adapters for Node.js, Bun, Deno, Fetch, Fastify, WebSocket, AWS Lambda, and more",
6
6
  "license": "MIT",
7
7
  "funding": [
@@ -117,15 +117,15 @@
117
117
  }
118
118
  },
119
119
  "dependencies": {
120
- "@orpc/client": "2.0.0-beta.35",
121
- "@orpc/contract": "2.0.0-beta.35",
122
- "@orpc/shared": "2.0.0-beta.35",
123
- "@standard-server/aws-lambda": "~0.9.0",
124
- "@standard-server/core": "~0.9.0",
125
- "@standard-server/fastify": "~0.9.0",
126
- "@standard-server/fetch": "~0.9.0",
127
- "@standard-server/node": "~0.9.0",
128
- "@standard-server/peer": "~0.9.0",
120
+ "@orpc/client": "2.0.0-beta.37",
121
+ "@orpc/contract": "2.0.0-beta.37",
122
+ "@orpc/shared": "2.0.0-beta.37",
123
+ "@standard-server/aws-lambda": "~0.9.2",
124
+ "@standard-server/core": "~0.9.2",
125
+ "@standard-server/fastify": "~0.9.2",
126
+ "@standard-server/fetch": "~0.9.2",
127
+ "@standard-server/node": "~0.9.2",
128
+ "@standard-server/peer": "~0.9.2",
129
129
  "cookie": "^2.0.1"
130
130
  },
131
131
  "devDependencies": {
@@ -1,91 +0,0 @@
1
- import { RPCSerializer, AnyORPCError } from '@orpc/client';
2
- import { Value, Public, Promisable } from '@orpc/shared';
3
- import { StandardMethod, StandardLazyRequest, StandardResponse } from '@standard-server/core';
4
- import { A as AnyProcedure, C as Context } from './server.BsujoJoF.js';
5
- import { A as AnyRouter } from './server.CRwPbhLO.js';
6
- import { AnyProcedureContract } from '@orpc/contract';
7
- import { c as StandardHandlerHandleOptions, d as StandardHandlerCodec, e as StandardHandlerCodecResolvedProcedure } from './server.DEeCcNd6.js';
8
-
9
- /**
10
- * Methods that can invoke procedures by default. Browsers cannot trigger them
11
- * cross-site without a CORS preflight or an HTML form, unlike `GET`, which a plain
12
- * `<a>` click or redirect can trigger with `SameSite=Lax` cookies attached. Other
13
- * methods (`HEAD`, `OPTIONS`, `QUERY`, ...) have safe semantics that should not
14
- * invoke a procedure that can modify data.
15
- *
16
- * @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
17
- */
18
- declare const RPC_DEFAULT_ALLOW_METHODS: readonly StandardMethod[];
19
- interface RPCMatcherOptions {
20
- /**
21
- * Filter which procedures are exposed for matching. Return `false` to exclude.
22
- *
23
- * @default true
24
- */
25
- filter?: Value<boolean, [procedure: AnyProcedureContract | AnyProcedure, path: string[]]>;
26
- /**
27
- * Restricts which HTTP methods can invoke procedures, either with a list of allowed
28
- * methods or decided per request via a function. Requests using a disallowed method
29
- * are treated as unmatched. `GET` is excluded by default because it is exposed to
30
- * Cross-Site Request Forgery (CSRF) attacks.
31
- *
32
- * @default RPC_DEFAULT_ALLOW_METHODS (['POST', 'PUT', 'PATCH', 'DELETE'])
33
- * @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
34
- */
35
- allowMethods?: readonly StandardMethod[] | ((method: StandardMethod, procedure: AnyProcedure, path: string[]) => boolean);
36
- }
37
- declare class RPCMatcher {
38
- private readonly filter;
39
- private readonly allowMethodsSet;
40
- private readonly allowMethodsFn;
41
- private readonly rootRouter;
42
- private readonly tree;
43
- private readonly pendingLazyRouters;
44
- constructor(router: AnyRouter, options?: RPCMatcherOptions);
45
- private index;
46
- match(method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
47
- path: string[];
48
- procedure: AnyProcedure;
49
- } | undefined>;
50
- private resolvePendingLazyRouters;
51
- private loadPendingLazyRouters;
52
- private loadPendingLazyRouter;
53
- private indexPendingLazyRouter;
54
- private resolveProcedure;
55
- }
56
-
57
- interface RPCHandlerCodecOptions<T extends Context> extends RPCMatcherOptions {
58
- /**
59
- * Override the default RPC serializer.
60
- */
61
- serializer?: Public<RPCSerializer>;
62
- /**
63
- * Resolve HTTP status for encoded successful outputs.
64
- *
65
- * Value should be in the `2xx` range and must be less than `400`.
66
- * Return `undefined` or `null` to fallback to default
67
- *
68
- * @default DEFAULT_SUCCESS_STATUS (200)
69
- */
70
- outputStatus?: Value<number | undefined | null, [output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>]>;
71
- /**
72
- * Mapping ORPCError Code -> HTTP Status Code
73
- * The status code should be in the `4xx` or `5xx` range (must be greater than or equal to `400`).
74
- *
75
- * @default COMMON_ERROR_STATUS_MAP
76
- */
77
- errorStatusMap?: Record<string, number> | undefined;
78
- }
79
- declare class RPCHandlerCodec<T extends Context> implements StandardHandlerCodec<T> {
80
- private readonly matcher;
81
- private readonly serializer;
82
- private readonly errorStatusMap;
83
- private readonly outputStatus;
84
- constructor(router: AnyRouter, options?: RPCHandlerCodecOptions<T>);
85
- resolveProcedure(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
86
- encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
87
- encodeError(error: AnyORPCError, _procedure: AnyProcedure, _path: string[], _options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
88
- }
89
-
90
- export { RPCHandlerCodec as a, RPCMatcher as b, RPC_DEFAULT_ALLOW_METHODS as d };
91
- export type { RPCHandlerCodecOptions as R, RPCMatcherOptions as c };
@@ -1,11 +0,0 @@
1
- import { value } from '@orpc/shared';
2
-
3
- function createStandardPeerRequestHandler(handler, options) {
4
- return async (request) => {
5
- const context = await value(options.context ?? {}, request);
6
- const { response } = await handler.handle(request, { ...options, context });
7
- return response ?? { status: 404, headers: {}, body: "No procedure matched" };
8
- };
9
- }
10
-
11
- export { createStandardPeerRequestHandler as c };
@@ -1,91 +0,0 @@
1
- import { RPCSerializer, AnyORPCError } from '@orpc/client';
2
- import { Value, Public, Promisable } from '@orpc/shared';
3
- import { StandardMethod, StandardLazyRequest, StandardResponse } from '@standard-server/core';
4
- import { A as AnyProcedure, C as Context } from './server.BsujoJoF.mjs';
5
- import { A as AnyRouter } from './server.BpmUhems.mjs';
6
- import { AnyProcedureContract } from '@orpc/contract';
7
- import { c as StandardHandlerHandleOptions, d as StandardHandlerCodec, e as StandardHandlerCodecResolvedProcedure } from './server.R0uHWfBo.mjs';
8
-
9
- /**
10
- * Methods that can invoke procedures by default. Browsers cannot trigger them
11
- * cross-site without a CORS preflight or an HTML form, unlike `GET`, which a plain
12
- * `<a>` click or redirect can trigger with `SameSite=Lax` cookies attached. Other
13
- * methods (`HEAD`, `OPTIONS`, `QUERY`, ...) have safe semantics that should not
14
- * invoke a procedure that can modify data.
15
- *
16
- * @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
17
- */
18
- declare const RPC_DEFAULT_ALLOW_METHODS: readonly StandardMethod[];
19
- interface RPCMatcherOptions {
20
- /**
21
- * Filter which procedures are exposed for matching. Return `false` to exclude.
22
- *
23
- * @default true
24
- */
25
- filter?: Value<boolean, [procedure: AnyProcedureContract | AnyProcedure, path: string[]]>;
26
- /**
27
- * Restricts which HTTP methods can invoke procedures, either with a list of allowed
28
- * methods or decided per request via a function. Requests using a disallowed method
29
- * are treated as unmatched. `GET` is excluded by default because it is exposed to
30
- * Cross-Site Request Forgery (CSRF) attacks.
31
- *
32
- * @default RPC_DEFAULT_ALLOW_METHODS (['POST', 'PUT', 'PATCH', 'DELETE'])
33
- * @see {@link https://orpc.dev/docs/rpc/handler#supported-http-methods | RPC Handler - Supported HTTP Methods}
34
- */
35
- allowMethods?: readonly StandardMethod[] | ((method: StandardMethod, procedure: AnyProcedure, path: string[]) => boolean);
36
- }
37
- declare class RPCMatcher {
38
- private readonly filter;
39
- private readonly allowMethodsSet;
40
- private readonly allowMethodsFn;
41
- private readonly rootRouter;
42
- private readonly tree;
43
- private readonly pendingLazyRouters;
44
- constructor(router: AnyRouter, options?: RPCMatcherOptions);
45
- private index;
46
- match(method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
47
- path: string[];
48
- procedure: AnyProcedure;
49
- } | undefined>;
50
- private resolvePendingLazyRouters;
51
- private loadPendingLazyRouters;
52
- private loadPendingLazyRouter;
53
- private indexPendingLazyRouter;
54
- private resolveProcedure;
55
- }
56
-
57
- interface RPCHandlerCodecOptions<T extends Context> extends RPCMatcherOptions {
58
- /**
59
- * Override the default RPC serializer.
60
- */
61
- serializer?: Public<RPCSerializer>;
62
- /**
63
- * Resolve HTTP status for encoded successful outputs.
64
- *
65
- * Value should be in the `2xx` range and must be less than `400`.
66
- * Return `undefined` or `null` to fallback to default
67
- *
68
- * @default DEFAULT_SUCCESS_STATUS (200)
69
- */
70
- outputStatus?: Value<number | undefined | null, [output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>]>;
71
- /**
72
- * Mapping ORPCError Code -> HTTP Status Code
73
- * The status code should be in the `4xx` or `5xx` range (must be greater than or equal to `400`).
74
- *
75
- * @default COMMON_ERROR_STATUS_MAP
76
- */
77
- errorStatusMap?: Record<string, number> | undefined;
78
- }
79
- declare class RPCHandlerCodec<T extends Context> implements StandardHandlerCodec<T> {
80
- private readonly matcher;
81
- private readonly serializer;
82
- private readonly errorStatusMap;
83
- private readonly outputStatus;
84
- constructor(router: AnyRouter, options?: RPCHandlerCodecOptions<T>);
85
- resolveProcedure(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
86
- encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
87
- encodeError(error: AnyORPCError, _procedure: AnyProcedure, _path: string[], _options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
88
- }
89
-
90
- export { RPCHandlerCodec as a, RPCMatcher as b, RPC_DEFAULT_ALLOW_METHODS as d };
91
- export type { RPCHandlerCodecOptions as R, RPCMatcherOptions as c };