@orpc/server 2.0.0-beta.3 → 2.0.0-beta.31

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 (56) hide show
  1. package/README.md +71 -101
  2. package/dist/adapters/aws-lambda/index.d.mts +93 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +93 -0
  4. package/dist/adapters/aws-lambda/index.mjs +66 -0
  5. package/dist/adapters/crossws/index.d.mts +17 -8
  6. package/dist/adapters/crossws/index.d.ts +17 -8
  7. package/dist/adapters/crossws/index.mjs +10 -7
  8. package/dist/adapters/fastify/index.d.mts +85 -0
  9. package/dist/adapters/fastify/index.d.ts +85 -0
  10. package/dist/adapters/fastify/index.mjs +66 -0
  11. package/dist/adapters/fetch/index.d.mts +16 -67
  12. package/dist/adapters/fetch/index.d.ts +16 -67
  13. package/dist/adapters/fetch/index.mjs +8 -144
  14. package/dist/adapters/message-port/index.d.mts +19 -16
  15. package/dist/adapters/message-port/index.d.ts +19 -16
  16. package/dist/adapters/message-port/index.mjs +28 -32
  17. package/dist/adapters/node/index.d.mts +15 -49
  18. package/dist/adapters/node/index.d.ts +15 -49
  19. package/dist/adapters/node/index.mjs +9 -120
  20. package/dist/adapters/standard/index.d.mts +6 -6
  21. package/dist/adapters/standard/index.d.ts +6 -6
  22. package/dist/adapters/standard/index.mjs +3 -3
  23. package/dist/adapters/standard-peer/index.d.mts +2 -2
  24. package/dist/adapters/standard-peer/index.d.ts +2 -2
  25. package/dist/adapters/websocket/index.d.mts +42 -26
  26. package/dist/adapters/websocket/index.d.ts +42 -26
  27. package/dist/adapters/websocket/index.mjs +33 -25
  28. package/dist/extensions/callable.d.mts +2 -2
  29. package/dist/extensions/callable.d.ts +2 -2
  30. package/dist/extensions/callable.mjs +2 -2
  31. package/dist/helpers/index.d.mts +23 -6
  32. package/dist/helpers/index.d.ts +23 -6
  33. package/dist/helpers/index.mjs +13 -5
  34. package/dist/index.d.mts +311 -16
  35. package/dist/index.d.ts +311 -16
  36. package/dist/index.mjs +126 -34
  37. package/dist/plugins/index.d.mts +241 -32
  38. package/dist/plugins/index.d.ts +241 -32
  39. package/dist/plugins/index.mjs +479 -15
  40. package/dist/shared/server.BhHrioCw.d.ts +34 -0
  41. package/dist/shared/{server.T9F3bzZx.d.ts → server.C2n16pp0.d.ts} +34 -9
  42. package/dist/shared/server.Cd4Z1hpV.mjs +69 -0
  43. package/dist/shared/{server.CrlKQucM.mjs → server.CkButhNT.mjs} +21 -38
  44. package/dist/shared/{server.B_U9y00a.d.mts → server.CkNnZ5F-.d.mts} +34 -9
  45. package/dist/shared/{server.BL22TloH.d.mts → server.CwrYlF72.d.mts} +31 -41
  46. package/dist/shared/{server.BL22TloH.d.ts → server.CwrYlF72.d.ts} +31 -41
  47. package/dist/shared/server.D0Ipbmdv.d.mts +34 -0
  48. package/dist/shared/{server.BwHnWUuN.mjs → server.Dh77P3ii.mjs} +17 -10
  49. package/dist/shared/{server.Pa0F03f_.d.ts → server.Dm0os-OP.d.mts} +24 -12
  50. package/dist/shared/{server.GDpX6Df8.mjs → server.DpUGXBi2.mjs} +84 -51
  51. package/dist/shared/{server.EOHJ3NJr.d.ts → server.DrN1Pj1-.d.ts} +3 -3
  52. package/dist/shared/{server.BsNNjG5J.d.mts → server.DtfwuV6U.d.ts} +24 -12
  53. package/dist/shared/{server.BB_Ik9Ph.d.mts → server.JbCIPL4P.d.mts} +3 -3
  54. package/dist/shared/{server.CjOb6ItT.mjs → server.eCTV8Vpp.mjs} +1 -1
  55. package/package.json +46 -12
  56. package/dist/shared/server.D_QauotT.mjs +0 -30
@@ -1,6 +1,6 @@
1
- import { c as createProcedureClient, P as Procedure, L as Lazy, u as unlazy } from './server.CrlKQucM.mjs';
1
+ import { c as createProcedureClient, P as Procedure, L as Lazy, u as unlazy } from './server.CkButhNT.mjs';
2
2
  import { resolveMetaPlugins, mergeErrorMap, ProcedureContract } from '@orpc/contract';
3
- import { getOrBind, isTypescriptObject } from '@orpc/shared';
3
+ import { omit, isTypescriptObject } from '@orpc/shared';
4
4
 
5
5
  const DEFAULT_SUCCESS_STATUS = 200;
6
6
  const DEFAULT_ERROR_STATUS = 500;
@@ -44,7 +44,7 @@ function withHiddenRouterContract(router, contract) {
44
44
  if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
45
45
  return contract;
46
46
  }
47
- return getOrBind(target, key);
47
+ return Reflect.get(target, key);
48
48
  }
49
49
  });
50
50
  }
@@ -77,6 +77,7 @@ function augmentRouter(router, options) {
77
77
  router["~orpc"].metaPlugins
78
78
  );
79
79
  const enhanced2 = new Procedure({
80
+ ...omit(options, ["middlewares", "errorMap", "meta", "metaPlugins"]),
80
81
  ...router["~orpc"],
81
82
  meta,
82
83
  metaPlugins,
@@ -111,6 +112,7 @@ function augmentImplementedRouter(router, options) {
111
112
  }
112
113
  if (router instanceof Procedure) {
113
114
  const enhanced2 = new Procedure({
115
+ ...omit(options, ["middlewares"]),
114
116
  ...router["~orpc"],
115
117
  orderedMiddlewares: [
116
118
  ...options.middlewares.map((middleware) => ({ middleware, inputSchemasLengthAtUse: 0, outputSchemasLengthAtUse: 0 })),
@@ -159,27 +161,32 @@ function getRouter(router, path) {
159
161
  return current;
160
162
  }
161
163
  function walkProcedureContractsSync(router, callback, path = []) {
164
+ const lazyResults = [];
165
+ walkProcedureContractsSyncInternal(router, callback, path.slice(), lazyResults);
166
+ return lazyResults;
167
+ }
168
+ function walkProcedureContractsSyncInternal(router, callback, path, lazyResults) {
162
169
  const hiddenContract = getHiddenRouterContract(router);
163
170
  if (hiddenContract !== void 0) {
164
171
  router = hiddenContract;
165
172
  }
166
173
  if (router instanceof ProcedureContract) {
167
- callback(router, path);
168
- return [];
174
+ callback(router, path.slice());
175
+ return;
169
176
  }
170
177
  if (!isTypescriptObject(router)) {
171
- return [];
178
+ return;
172
179
  }
173
- const lazyResults = [];
174
180
  for (const key in router) {
175
181
  const value = router[key];
182
+ path.push(key);
176
183
  if (value instanceof Lazy) {
177
- lazyResults.push({ router: value, path: [...path, key] });
184
+ lazyResults.push({ router: value, path: path.slice() });
178
185
  } else {
179
- lazyResults.push(...walkProcedureContractsSync(value, callback, [...path, key]));
186
+ walkProcedureContractsSyncInternal(value, callback, path, lazyResults);
180
187
  }
188
+ path.pop();
181
189
  }
182
- return lazyResults;
183
190
  }
184
191
  async function walkProcedureContractsAsync(router, callback, path = []) {
185
192
  const hiddenContract = getHiddenRouterContract(router);
@@ -1,5 +1,5 @@
1
1
  import { RouterContract, ProcedureContract, ORPCErrorFromErrorMap, ThrowableError, InferSchemaInput, InferSchemaOutput } from '@orpc/contract';
2
- import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.BL22TloH.js';
2
+ import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.CwrYlF72.mjs';
3
3
 
4
4
  type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any, any> | {
5
5
  [k: string]: Lazyable<Router<TInitialContext>>;
@@ -12,8 +12,10 @@ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer $>
12
12
  /**
13
13
  * Infer all initial context of the router.
14
14
  *
15
- * @info A procedure is a router too.
16
- * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
15
+ * @remarks
16
+ * **Note**: A procedure is a router too.
17
+ *
18
+ * @see {@link https://orpc.dev/docs/router#infer-router-initial-contexts | Router - Infer Router Initial Contexts}
17
19
  */
18
20
  type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
19
21
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
@@ -21,41 +23,51 @@ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer
21
23
  /**
22
24
  * Infer all current context of the router.
23
25
  *
24
- * @info A procedure is a router too.
25
- * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
26
+ * @remarks
27
+ * **Note**: A procedure is a router too.
28
+ *
29
+ * @see {@link https://orpc.dev/docs/router#infer-router-final-contexts | Router - Infer Router Final Contexts}
26
30
  */
27
31
  type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, any, any, any> ? MergedContext<UInitialContext, UInjectedContext> : {
28
32
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterFinalContexts<U> : never;
29
33
  };
30
34
  /**
31
- * Infer all router inputs
35
+ * Infer all router inputs.
36
+ *
37
+ * @remarks
38
+ * **Note**: A procedure is a router too.
32
39
  *
33
- * @info A procedure is a router too.
34
- * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
40
+ * @see {@link https://orpc.dev/docs/router#infer-router-inputs | Router - Infer Router Inputs}
35
41
  */
36
42
  type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
37
43
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
38
44
  };
39
45
  /**
40
- * Infer all router outputs
46
+ * Infer all router outputs.
41
47
  *
42
- * @info A procedure is a router too.
43
- * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
48
+ * @remarks
49
+ * **Note**: A procedure is a router too.
50
+ *
51
+ * @see {@link https://orpc.dev/docs/router#infer-router-outputs | Router - Infer Router Outputs}
44
52
  */
45
53
  type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
46
54
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
47
55
  };
48
56
  /**
49
57
  * Infer the union of throwable errors for entire router.
58
+ *
59
+ * @see {@link https://orpc.dev/docs/router#infer-router-error | Router - Infer Router Error}
50
60
  */
51
61
  type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap, infer UReturnedError> ? ORPCErrorFromErrorMap<UErrorMap> | UReturnedError | ThrowableError : {
52
62
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterError<U> : never;
53
63
  }[keyof T];
54
64
  /**
55
65
  * Infer throwable errors for each procedure, preserving the router shape.
66
+ *
67
+ * @see {@link https://orpc.dev/docs/router#infer-router-errors | Router - Infer Router Errors}
56
68
  */
57
69
  type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap, infer UReturnedError> ? ORPCErrorFromErrorMap<UErrorMap> | UReturnedError | ThrowableError : {
58
70
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterErrors<U> : never;
59
71
  };
60
72
 
61
- export type { AnyRouter as A, ContractedRouter as C, InferRouterInitialContext as I, Router as R, InferRouterError as a, InferRouterErrors as b, InferRouterFinalContexts as c, InferRouterInitialContexts as d, InferRouterInputs as e, InferRouterOutputs as f };
73
+ export type { AnyRouter as A, ContractedRouter as C, InferRouterInitialContext as I, Router as R, InferRouterFinalContexts as a, InferRouterError as b, InferRouterErrors as c, InferRouterInitialContexts as d, InferRouterInputs as e, InferRouterOutputs as f };
@@ -1,8 +1,8 @@
1
1
  import { ORPCError, toORPCError, RPCSerializer, COMMON_ERROR_STATUS_MAP } from '@orpc/client';
2
- import { sortPlugins, getOpenTelemetryConfig, runWithSpan, toArray, matchesHttpPathPrefix, intercept, ORPC_NAME, isAsyncIteratorObject, override, traceAsyncIterator, recordSpanError, pathToHttpPath, normalizeHttpPath, value, parseEmptyableJSON } from '@orpc/shared';
2
+ import { sortPlugins, getOpenTelemetryConfig, runWithSpan, toArray, matchesHttpPathPrefix, intercept, ORPC_NAME, isAsyncIteratorObject, override, traceAsyncIterator, recordSpanError, pathToHttpPath, normalizeHttpPath, value, parseEmptyableJSON, getOwn } from '@orpc/shared';
3
3
  import { flattenStandardHeader, parseStandardUrl } from '@standardserver/core';
4
- import { c as createProcedureClient, u as unlazy, P as Procedure } from './server.CrlKQucM.mjs';
5
- import { w as walkProcedureContractsSync, g as getRouter, c as createContractProcedure, D as DEFAULT_SUCCESS_STATUS, a as DEFAULT_ERROR_STATUS } from './server.BwHnWUuN.mjs';
4
+ import { c as createProcedureClient, u as unlazy, P as Procedure } from './server.CkButhNT.mjs';
5
+ import { w as walkProcedureContractsSync, g as getRouter, c as createContractProcedure, D as DEFAULT_SUCCESS_STATUS, a as DEFAULT_ERROR_STATUS } from './server.Dh77P3ii.mjs';
6
6
 
7
7
  class CompositeStandardHandlerPlugin {
8
8
  name = "~composite";
@@ -64,7 +64,7 @@ class StandardHandler {
64
64
  let input = await runWithSpan("decode_input", decodeInput2);
65
65
  step = void 0;
66
66
  if (isAsyncIteratorObject(input)) {
67
- input = override(input, traceAsyncIterator("consume_event_iterator_input", input));
67
+ input = override(input, traceAsyncIterator("consume_async_iterator_object_input", input));
68
68
  }
69
69
  const client = createProcedureClient(procedure2, {
70
70
  context: context3,
@@ -121,13 +121,22 @@ class OtelHandlerPlugin {
121
121
  }
122
122
  }
123
123
 
124
+ const RPC_DEFAULT_ALLOW_METHODS = ["POST", "PUT", "PATCH", "DELETE"];
124
125
  class RPCMatcher {
125
126
  filter;
127
+ allowMethodsSet;
128
+ allowMethodsFn;
126
129
  rootRouter;
127
130
  tree = /* @__PURE__ */ new Map();
128
- pendingLazyRouters = [];
131
+ pendingLazyRouters = /* @__PURE__ */ new Map();
129
132
  constructor(router, options = {}) {
130
133
  this.filter = options.filter ?? true;
134
+ const allowMethods = options.allowMethods ?? RPC_DEFAULT_ALLOW_METHODS;
135
+ if (typeof allowMethods !== "function") {
136
+ this.allowMethodsSet = new Set(allowMethods);
137
+ } else {
138
+ this.allowMethodsFn = allowMethods;
139
+ }
131
140
  this.rootRouter = router;
132
141
  this.index(router);
133
142
  }
@@ -136,28 +145,21 @@ class RPCMatcher {
136
145
  if (!value(this.filter, procedure, procedurePath)) {
137
146
  return;
138
147
  }
139
- const httpPath = pathToHttpPath(procedurePath);
140
- if (procedure instanceof Procedure) {
141
- this.tree.set(httpPath, {
142
- path: procedurePath,
143
- contract: procedure,
144
- procedure
145
- });
146
- } else {
147
- this.tree.set(httpPath, {
148
- path: procedurePath,
149
- contract: procedure
150
- });
151
- }
148
+ this.tree.set(pathToHttpPath(procedurePath), {
149
+ path: procedurePath,
150
+ contract: procedure,
151
+ // contract-first entries have no implementation yet, resolveProcedure fills it in on demand
152
+ procedure: procedure instanceof Procedure ? procedure : void 0
153
+ });
152
154
  }, path);
153
- this.pendingLazyRouters.push(
154
- ...lazyResults.map((result) => ({
155
- ...result,
156
- httpPathPrefix: pathToHttpPath(result.path)
157
- }))
158
- );
155
+ for (const result of lazyResults) {
156
+ this.pendingLazyRouters.set(pathToHttpPath(result.path), result);
157
+ }
159
158
  }
160
- async match(_method, pathname, prefix) {
159
+ async match(method, pathname, prefix) {
160
+ if (this.allowMethodsSet && !this.allowMethodsSet.has(method)) {
161
+ return void 0;
162
+ }
161
163
  if (pathname.length > 1 && pathname.endsWith("/")) {
162
164
  pathname = pathname.slice(0, -1);
163
165
  }
@@ -176,40 +178,71 @@ class RPCMatcher {
176
178
  return void 0;
177
179
  }
178
180
  }
179
- const result = await this.matchPathname(pathname);
180
- if (!result && pathname.includes("%")) {
181
- return this.matchPathname(normalizeHttpPath(pathname));
181
+ const loading = this.resolvePendingLazyRouters(pathname);
182
+ if (loading !== void 0) {
183
+ await loading;
182
184
  }
183
- return result;
184
- }
185
- async matchPathname(pathname) {
186
- await this.resolvePendingLazyRouters(pathname);
187
- const entry = this.tree.get(pathname);
188
- if (!entry) {
185
+ let entry = this.tree.get(pathname);
186
+ if (entry === void 0 && pathname.includes("%")) {
187
+ const normalizedPathname = normalizeHttpPath(pathname);
188
+ const normalizedLoading = this.resolvePendingLazyRouters(normalizedPathname);
189
+ if (normalizedLoading !== void 0) {
190
+ await normalizedLoading;
191
+ }
192
+ entry = this.tree.get(normalizedPathname);
193
+ }
194
+ if (entry === void 0) {
195
+ return void 0;
196
+ }
197
+ const procedure = entry.procedure ?? await this.resolveProcedure(entry);
198
+ if (this.allowMethodsFn && !this.allowMethodsFn(method, procedure, entry.path)) {
189
199
  return void 0;
190
200
  }
191
- const procedure = await this.resolveProcedure(entry);
192
- return { path: entry.path, procedure };
201
+ return {
202
+ path: entry.path,
203
+ procedure
204
+ };
193
205
  }
194
- async resolvePendingLazyRouters(pathname) {
195
- if (!this.pendingLazyRouters.length) {
206
+ resolvePendingLazyRouters(pathname) {
207
+ if (this.pendingLazyRouters.size === 0) {
196
208
  return;
197
209
  }
198
- const stillPending = [];
199
- for (const pending of this.pendingLazyRouters) {
200
- if (pathname.startsWith(pending.httpPathPrefix)) {
201
- const { default: router } = await unlazy(pending.router);
202
- this.index(router, pending.path);
203
- } else {
204
- stillPending.push(pending);
210
+ let slashIndex = 0;
211
+ while (slashIndex !== -1) {
212
+ const nextSlashIndex = pathname.indexOf("/", slashIndex + 1);
213
+ const httpPathPrefix = nextSlashIndex === -1 ? pathname : pathname.slice(0, nextSlashIndex);
214
+ if (this.pendingLazyRouters.has(httpPathPrefix)) {
215
+ return this.loadPendingLazyRouters(pathname, slashIndex);
205
216
  }
217
+ slashIndex = nextSlashIndex;
206
218
  }
207
- this.pendingLazyRouters = stillPending;
208
219
  }
209
- async resolveProcedure(entry) {
210
- if (entry.procedure) {
211
- return entry.procedure;
220
+ async loadPendingLazyRouters(pathname, slashIndex) {
221
+ while (slashIndex !== -1) {
222
+ const nextSlashIndex = pathname.indexOf("/", slashIndex + 1);
223
+ const httpPathPrefix = nextSlashIndex === -1 ? pathname : pathname.slice(0, nextSlashIndex);
224
+ const pending = this.pendingLazyRouters.get(httpPathPrefix);
225
+ if (pending !== void 0) {
226
+ await this.loadPendingLazyRouter(httpPathPrefix, pending);
227
+ }
228
+ slashIndex = nextSlashIndex;
212
229
  }
230
+ }
231
+ loadPendingLazyRouter(httpPathPrefix, pending) {
232
+ if (pending.loading === void 0) {
233
+ pending.loading = this.indexPendingLazyRouter(httpPathPrefix, pending).catch((error) => {
234
+ pending.loading = void 0;
235
+ throw error;
236
+ });
237
+ }
238
+ return pending.loading;
239
+ }
240
+ async indexPendingLazyRouter(httpPathPrefix, pending) {
241
+ const { default: router } = await unlazy(pending.router);
242
+ this.index(router, pending.path);
243
+ this.pendingLazyRouters.delete(httpPathPrefix);
244
+ }
245
+ async resolveProcedure(entry) {
213
246
  const { default: maybeProcedure } = await unlazy(getRouter(this.rootRouter, entry.path));
214
247
  if (!(maybeProcedure instanceof Procedure)) {
215
248
  throw new TypeError(
@@ -259,7 +292,7 @@ class RPCHandlerCodec {
259
292
  };
260
293
  }
261
294
  encodeError(error, _procedure, _path, _options) {
262
- const status = this.errorStatusMap[error.code] ?? DEFAULT_ERROR_STATUS;
295
+ const status = getOwn(this.errorStatusMap, error.code) ?? DEFAULT_ERROR_STATUS;
263
296
  return {
264
297
  headers: {},
265
298
  status,
@@ -268,4 +301,4 @@ class RPCHandlerCodec {
268
301
  }
269
302
  }
270
303
 
271
- export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, RPCHandlerCodec as R, StandardHandler as S, RPCMatcher as a };
304
+ export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, RPCHandlerCodec as R, StandardHandler as S, RPCMatcher as a, RPC_DEFAULT_ALLOW_METHODS as b };
@@ -1,7 +1,7 @@
1
1
  import { AnyORPCError } from '@orpc/client';
2
2
  import { OrderablePlugin, Interceptor, Promisable } from '@orpc/shared';
3
3
  import { StandardLazyRequest, StandardResponse } from '@standardserver/core';
4
- import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.BL22TloH.js';
4
+ import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.CwrYlF72.js';
5
5
  import { Schema, ErrorMap } from '@orpc/contract';
6
6
 
7
7
  interface StandardHandlerPlugin<T extends Context> extends OrderablePlugin {
@@ -100,5 +100,5 @@ interface StandardHandlerCodec<T extends Context> {
100
100
  encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
101
101
  }
102
102
 
103
- export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, StandardHandler as S };
104
- export type { StandardHandlerOptions as a, StandardHandlerHandleOptions as b, StandardHandlerCodec as c, StandardHandlerCodecResolvedProcedure as d, StandardHandlerPlugin as e, StandardHandlerRoutingInterceptorOptions as f, StandardHandlerHandleResult as g, StandardHandlerInterceptor as h, StandardHandlerInterceptorOptions as i, StandardHandlerRoutingInterceptor as j };
103
+ export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, 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 };
@@ -1,5 +1,5 @@
1
1
  import { RouterContract, ProcedureContract, ORPCErrorFromErrorMap, ThrowableError, InferSchemaInput, InferSchemaOutput } from '@orpc/contract';
2
- import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.BL22TloH.mjs';
2
+ import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.CwrYlF72.js';
3
3
 
4
4
  type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any, any> | {
5
5
  [k: string]: Lazyable<Router<TInitialContext>>;
@@ -12,8 +12,10 @@ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer $>
12
12
  /**
13
13
  * Infer all initial context of the router.
14
14
  *
15
- * @info A procedure is a router too.
16
- * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
15
+ * @remarks
16
+ * **Note**: A procedure is a router too.
17
+ *
18
+ * @see {@link https://orpc.dev/docs/router#infer-router-initial-contexts | Router - Infer Router Initial Contexts}
17
19
  */
18
20
  type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
19
21
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
@@ -21,41 +23,51 @@ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer
21
23
  /**
22
24
  * Infer all current context of the router.
23
25
  *
24
- * @info A procedure is a router too.
25
- * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
26
+ * @remarks
27
+ * **Note**: A procedure is a router too.
28
+ *
29
+ * @see {@link https://orpc.dev/docs/router#infer-router-final-contexts | Router - Infer Router Final Contexts}
26
30
  */
27
31
  type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, any, any, any> ? MergedContext<UInitialContext, UInjectedContext> : {
28
32
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterFinalContexts<U> : never;
29
33
  };
30
34
  /**
31
- * Infer all router inputs
35
+ * Infer all router inputs.
36
+ *
37
+ * @remarks
38
+ * **Note**: A procedure is a router too.
32
39
  *
33
- * @info A procedure is a router too.
34
- * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
40
+ * @see {@link https://orpc.dev/docs/router#infer-router-inputs | Router - Infer Router Inputs}
35
41
  */
36
42
  type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
37
43
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
38
44
  };
39
45
  /**
40
- * Infer all router outputs
46
+ * Infer all router outputs.
41
47
  *
42
- * @info A procedure is a router too.
43
- * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
48
+ * @remarks
49
+ * **Note**: A procedure is a router too.
50
+ *
51
+ * @see {@link https://orpc.dev/docs/router#infer-router-outputs | Router - Infer Router Outputs}
44
52
  */
45
53
  type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
46
54
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
47
55
  };
48
56
  /**
49
57
  * Infer the union of throwable errors for entire router.
58
+ *
59
+ * @see {@link https://orpc.dev/docs/router#infer-router-error | Router - Infer Router Error}
50
60
  */
51
61
  type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap, infer UReturnedError> ? ORPCErrorFromErrorMap<UErrorMap> | UReturnedError | ThrowableError : {
52
62
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterError<U> : never;
53
63
  }[keyof T];
54
64
  /**
55
65
  * Infer throwable errors for each procedure, preserving the router shape.
66
+ *
67
+ * @see {@link https://orpc.dev/docs/router#infer-router-errors | Router - Infer Router Errors}
56
68
  */
57
69
  type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap, infer UReturnedError> ? ORPCErrorFromErrorMap<UErrorMap> | UReturnedError | ThrowableError : {
58
70
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterErrors<U> : never;
59
71
  };
60
72
 
61
- export type { AnyRouter as A, ContractedRouter as C, InferRouterInitialContext as I, Router as R, InferRouterError as a, InferRouterErrors as b, InferRouterFinalContexts as c, InferRouterInitialContexts as d, InferRouterInputs as e, InferRouterOutputs as f };
73
+ export type { AnyRouter as A, ContractedRouter as C, InferRouterInitialContext as I, Router as R, InferRouterFinalContexts as a, InferRouterError as b, InferRouterErrors as c, InferRouterInitialContexts as d, InferRouterInputs as e, InferRouterOutputs as f };
@@ -1,7 +1,7 @@
1
1
  import { AnyORPCError } from '@orpc/client';
2
2
  import { OrderablePlugin, Interceptor, Promisable } from '@orpc/shared';
3
3
  import { StandardLazyRequest, StandardResponse } from '@standardserver/core';
4
- import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.BL22TloH.mjs';
4
+ import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.CwrYlF72.mjs';
5
5
  import { Schema, ErrorMap } from '@orpc/contract';
6
6
 
7
7
  interface StandardHandlerPlugin<T extends Context> extends OrderablePlugin {
@@ -100,5 +100,5 @@ interface StandardHandlerCodec<T extends Context> {
100
100
  encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
101
101
  }
102
102
 
103
- export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, StandardHandler as S };
104
- export type { StandardHandlerOptions as a, StandardHandlerHandleOptions as b, StandardHandlerCodec as c, StandardHandlerCodecResolvedProcedure as d, StandardHandlerPlugin as e, StandardHandlerRoutingInterceptorOptions as f, StandardHandlerHandleResult as g, StandardHandlerInterceptor as h, StandardHandlerInterceptorOptions as i, StandardHandlerRoutingInterceptor as j };
103
+ export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, 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 };
@@ -1,5 +1,5 @@
1
1
  import { resolveMetaPlugins, mergeErrorMap, getHiddenMetaPlugins } from '@orpc/contract';
2
- import { P as Procedure } from './server.CrlKQucM.mjs';
2
+ import { P as Procedure } from './server.CkButhNT.mjs';
3
3
 
4
4
  class DecoratedProcedure extends Procedure {
5
5
  meta(...plugins) {
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.3",
4
+ "version": "2.0.0-beta.31",
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",
5
6
  "license": "MIT",
7
+ "funding": [
8
+ "https://github.com/sponsors/dinwwwh",
9
+ "https://opencollective.com/middleapi"
10
+ ],
6
11
  "homepage": "https://orpc.dev",
7
12
  "repository": {
8
13
  "type": "git",
@@ -10,7 +15,20 @@
10
15
  "directory": "packages/server"
11
16
  },
12
17
  "keywords": [
13
- "orpc"
18
+ "orpc",
19
+ "rpc",
20
+ "api",
21
+ "typescript",
22
+ "typesafe",
23
+ "server",
24
+ "openapi",
25
+ "middleware",
26
+ "nodejs",
27
+ "bun",
28
+ "deno",
29
+ "fastify",
30
+ "websocket",
31
+ "aws-lambda"
14
32
  ],
15
33
  "sideEffects": [
16
34
  "./dist/extensions/callable.mjs"
@@ -52,6 +70,16 @@
52
70
  "import": "./dist/adapters/node/index.mjs",
53
71
  "default": "./dist/adapters/node/index.mjs"
54
72
  },
73
+ "./aws-lambda": {
74
+ "types": "./dist/adapters/aws-lambda/index.d.mts",
75
+ "import": "./dist/adapters/aws-lambda/index.mjs",
76
+ "default": "./dist/adapters/aws-lambda/index.mjs"
77
+ },
78
+ "./fastify": {
79
+ "types": "./dist/adapters/fastify/index.d.mts",
80
+ "import": "./dist/adapters/fastify/index.mjs",
81
+ "default": "./dist/adapters/fastify/index.mjs"
82
+ },
55
83
  "./websocket": {
56
84
  "types": "./dist/adapters/websocket/index.d.mts",
57
85
  "import": "./dist/adapters/websocket/index.mjs",
@@ -77,26 +105,32 @@
77
105
  "dist"
78
106
  ],
79
107
  "peerDependencies": {
80
- "crossws": ">=0.3.4"
108
+ "crossws": ">=0.3.4",
109
+ "fastify": ">=5.6.1"
81
110
  },
82
111
  "peerDependenciesMeta": {
83
112
  "crossws": {
84
113
  "optional": true
114
+ },
115
+ "fastify": {
116
+ "optional": true
85
117
  }
86
118
  },
87
119
  "dependencies": {
88
- "@standardserver/core": "^0.0.25",
89
- "@standardserver/fetch": "^0.0.25",
90
- "@standardserver/node": "^0.0.25",
91
- "@standardserver/peer": "^0.0.25",
92
- "cookie": "^1.1.1",
93
- "@orpc/contract": "2.0.0-beta.3",
94
- "@orpc/interop": "2.0.0-beta.3",
95
- "@orpc/shared": "2.0.0-beta.3",
96
- "@orpc/client": "2.0.0-beta.3"
120
+ "@standardserver/aws-lambda": "^0.8.0",
121
+ "@standardserver/core": "^0.8.0",
122
+ "@standardserver/fastify": "^0.8.0",
123
+ "@standardserver/fetch": "^0.8.0",
124
+ "@standardserver/node": "^0.8.0",
125
+ "@standardserver/peer": "^0.8.0",
126
+ "cookie": "^2.0.1",
127
+ "@orpc/contract": "2.0.0-beta.31",
128
+ "@orpc/client": "2.0.0-beta.31",
129
+ "@orpc/shared": "2.0.0-beta.31"
97
130
  },
98
131
  "devDependencies": {
99
132
  "crossws": "^0.4.6",
133
+ "fastify": "^5.12.1",
100
134
  "supertest": "^7.2.2",
101
135
  "zod": "^4.4.3"
102
136
  },
@@ -1,30 +0,0 @@
1
- import { ORPCError } from '@orpc/client';
2
- import { toArray } from '@orpc/shared';
3
- import { flattenStandardHeader } from '@standardserver/core';
4
-
5
- class CSRFGuardHandlerPlugin {
6
- name = "~csrf-guard";
7
- init(options) {
8
- const interceptor = async (interceptorOptions) => {
9
- const mode = flattenStandardHeader(
10
- interceptorOptions.request.headers["sec-fetch-mode"]
11
- )?.toLowerCase();
12
- if (mode === void 0) {
13
- return interceptorOptions.next();
14
- }
15
- if (mode === "cors" || mode === "same-origin") {
16
- return interceptorOptions.next();
17
- }
18
- throw new ORPCError("FORBIDDEN", {
19
- message: "Request blocked by CSRF protection."
20
- });
21
- };
22
- return {
23
- ...options,
24
- // appended last so user's interceptors can catch ORPCError
25
- interceptors: [...toArray(options.interceptors), interceptor]
26
- };
27
- }
28
- }
29
-
30
- export { CSRFGuardHandlerPlugin as C };