@orpc/server 2.0.0-beta.43 → 2.0.0-beta.45

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 (39) hide show
  1. package/README.md +56 -57
  2. package/dist/adapters/aws-lambda/index.mjs +2 -2
  3. package/dist/adapters/crossws/index.mjs +2 -2
  4. package/dist/adapters/fastify/index.mjs +2 -2
  5. package/dist/adapters/fetch/index.d.mts +2 -2
  6. package/dist/adapters/fetch/index.d.ts +2 -2
  7. package/dist/adapters/fetch/index.mjs +2 -2
  8. package/dist/adapters/message-port/index.d.mts +1 -1
  9. package/dist/adapters/message-port/index.d.ts +1 -1
  10. package/dist/adapters/message-port/index.mjs +2 -2
  11. package/dist/adapters/node/index.d.mts +1 -1
  12. package/dist/adapters/node/index.d.ts +1 -1
  13. package/dist/adapters/node/index.mjs +2 -2
  14. package/dist/adapters/standard/index.d.mts +10 -8
  15. package/dist/adapters/standard/index.d.ts +10 -8
  16. package/dist/adapters/standard/index.mjs +2 -2
  17. package/dist/adapters/websocket/index.mjs +2 -2
  18. package/dist/helpers/index.d.mts +2 -1
  19. package/dist/helpers/index.d.ts +2 -1
  20. package/dist/helpers/index.mjs +3 -9
  21. package/dist/index.d.mts +14 -7
  22. package/dist/index.d.ts +14 -7
  23. package/dist/index.mjs +2 -2
  24. package/dist/plugins/index.d.mts +64 -55
  25. package/dist/plugins/index.d.ts +64 -55
  26. package/dist/plugins/index.mjs +232 -146
  27. package/dist/shared/{server.BllfVJLm.d.mts → server.B4hFgqPr.d.mts} +2 -2
  28. package/dist/shared/{server.BEdOJs6S.d.mts → server.BWhT-63L.d.mts} +5 -5
  29. package/dist/shared/{server.BEdOJs6S.d.ts → server.BWhT-63L.d.ts} +5 -5
  30. package/dist/shared/{server.CVO0hWyj.d.mts → server.BYNQ06wN.d.ts} +5 -5
  31. package/dist/shared/{server.BgvqVW_v.mjs → server.BcxD3fmU.mjs} +15 -3
  32. package/dist/shared/{server.COfbQ0D8.d.ts → server.CI0qiBzm.d.ts} +2 -2
  33. package/dist/shared/{server.DFEuNUt4.d.ts → server.CO_upro1.d.ts} +3 -3
  34. package/dist/shared/{server.DZeVx8K9.d.ts → server.DcDZdSrg.d.ts} +1 -1
  35. package/dist/shared/{server.UG_xdTub.d.mts → server.DgcwQ-Wr.d.mts} +3 -3
  36. package/dist/shared/{server.B1ecixZJ.mjs → server.Kbq-C85k.mjs} +7 -20
  37. package/dist/shared/{server.DJNkZPfD.d.ts → server.TVSii8T9.d.mts} +5 -5
  38. package/dist/shared/{server.DD1roZl9.d.mts → server.TjEHK8V3.d.mts} +1 -1
  39. package/package.json +15 -15
@@ -1,10 +1,10 @@
1
1
  import { Value, Promisable } from '@orpc/shared';
2
2
  import { StandardLazyRequest } from '@standard-server/core';
3
- import { C as Context } from './server.BEdOJs6S.mjs';
4
- import { a as StandardHandlerHandleOptions } from './server.CVO0hWyj.mjs';
3
+ import { C as Context } from './server.BWhT-63L.mjs';
4
+ import { a as StandardHandlerHandleOptions } from './server.TVSii8T9.mjs';
5
5
 
6
6
  type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (object extends T ? {
7
- context?: Value<Promisable<T>, [request: StandardLazyRequest]>;
7
+ context?: Value<Promisable<T>, [request: StandardLazyRequest]> | undefined;
8
8
  } : {
9
9
  context: Value<Promisable<T>, [request: StandardLazyRequest]>;
10
10
  });
@@ -2,7 +2,7 @@ import { ORPCError, toORPCError, RPCSerializer, COMMON_ERROR_STATUS_MAP } from '
2
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
3
  import { flattenStandardHeader, parseStandardUrl, ErrorEvent } from '@standard-server/core';
4
4
  import { c as createProcedureClient, u as unlazy, P as Procedure } from './server.FEqy7Hrj.mjs';
5
- import { w as walkProcedureContractsSync, g as getRouter, c as createContractProcedure, D as DEFAULT_SUCCESS_STATUS, a as DEFAULT_ERROR_STATUS } from './server.BgvqVW_v.mjs';
5
+ import { w as walkProcedureContractsSync, r as resolveContractProcedure, D as DEFAULT_SUCCESS_STATUS, a as DEFAULT_ERROR_STATUS } from './server.BcxD3fmU.mjs';
6
6
 
7
7
  class CompositeStandardHandlerPlugin {
8
8
  name = "~composite";
@@ -191,6 +191,8 @@ class RPCMatcher {
191
191
  rootRouter;
192
192
  tree = /* @__PURE__ */ new Map();
193
193
  pendingLazyRouters = /* @__PURE__ */ new Map();
194
+ /** segment count of the deepest pending key, never lowered so it stays an upper bound */
195
+ maxPendingLazyRouterDepth = 0;
194
196
  constructor(router, options = {}) {
195
197
  this.filter = options.filter ?? true;
196
198
  const allowMethods = options.allowMethods ?? RPC_DEFAULT_ALLOW_METHODS;
@@ -216,6 +218,7 @@ class RPCMatcher {
216
218
  }, path);
217
219
  for (const result of lazyResults) {
218
220
  this.pendingLazyRouters.set(pathToHttpPath(result.path), result);
221
+ this.maxPendingLazyRouterDepth = Math.max(this.maxPendingLazyRouterDepth, result.path.length);
219
222
  }
220
223
  }
221
224
  async match(method, pathname, prefix) {
@@ -270,22 +273,12 @@ class RPCMatcher {
270
273
  return;
271
274
  }
272
275
  let slashIndex = 0;
273
- while (slashIndex !== -1) {
274
- const nextSlashIndex = pathname.indexOf("/", slashIndex + 1);
275
- const httpPathPrefix = nextSlashIndex === -1 ? pathname : pathname.slice(0, nextSlashIndex);
276
- if (this.pendingLazyRouters.has(httpPathPrefix)) {
277
- return this.loadPendingLazyRouters(pathname, slashIndex);
278
- }
279
- slashIndex = nextSlashIndex;
280
- }
281
- }
282
- async loadPendingLazyRouters(pathname, slashIndex) {
283
- while (slashIndex !== -1) {
276
+ for (let depth = 1; slashIndex !== -1 && depth <= this.maxPendingLazyRouterDepth; depth++) {
284
277
  const nextSlashIndex = pathname.indexOf("/", slashIndex + 1);
285
278
  const httpPathPrefix = nextSlashIndex === -1 ? pathname : pathname.slice(0, nextSlashIndex);
286
279
  const pending = this.pendingLazyRouters.get(httpPathPrefix);
287
280
  if (pending !== void 0) {
288
- await this.loadPendingLazyRouter(httpPathPrefix, pending);
281
+ return this.loadPendingLazyRouter(httpPathPrefix, pending).then(() => this.resolvePendingLazyRouters(pathname));
289
282
  }
290
283
  slashIndex = nextSlashIndex;
291
284
  }
@@ -305,13 +298,7 @@ class RPCMatcher {
305
298
  this.pendingLazyRouters.delete(httpPathPrefix);
306
299
  }
307
300
  async resolveProcedure(entry) {
308
- const { default: maybeProcedure } = await unlazy(getRouter(this.rootRouter, entry.path));
309
- if (!(maybeProcedure instanceof Procedure)) {
310
- throw new TypeError(
311
- `[Contract-First] Missing or invalid implementation for procedure at path: "${entry.path.join(".")}". Ensure the procedure is correctly implemented and matches its contract.`
312
- );
313
- }
314
- entry.procedure = createContractProcedure(maybeProcedure, entry.contract);
301
+ entry.procedure = await resolveContractProcedure(this.rootRouter, entry.contract, entry.path);
315
302
  return entry.procedure;
316
303
  }
317
304
  }
@@ -1,7 +1,7 @@
1
1
  import { AnyORPCError } from '@orpc/client';
2
2
  import { OrderablePlugin, Value, Promisable, Interceptor } from '@orpc/shared';
3
3
  import { StandardLazyRequest, StandardResponse } from '@standard-server/core';
4
- import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.BEdOJs6S.js';
4
+ import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.BWhT-63L.mjs';
5
5
  import { Schema, ErrorMap } from '@orpc/contract';
6
6
 
7
7
  interface StandardHandlerPlugin<T extends Context> extends OrderablePlugin {
@@ -73,19 +73,19 @@ interface StandardHandlerOptions<TContext extends Context> {
73
73
  * - batch plugins - separate one request into multiple and call multiple next
74
74
  * - openapi spec plugin - to intercept a request and early response
75
75
  */
76
- routingInterceptors?: StandardHandlerRoutingInterceptor<TContext>[];
76
+ routingInterceptors?: StandardHandlerRoutingInterceptor<TContext>[] | undefined;
77
77
  /**
78
78
  * interceptor run after routing and before error handler,
79
79
  * useful for error handling, logging, metrics, etc.
80
80
  */
81
- interceptors?: StandardHandlerInterceptor<TContext>[];
81
+ interceptors?: StandardHandlerInterceptor<TContext>[] | undefined;
82
82
  /**
83
83
  *
84
84
  * ClientInterceptor equivalent with createRouterClient.interceptors / createProcedure.interceptors
85
85
  * useful for error handling, logging, metrics, etc. (not counting encoding/decoding)
86
86
  */
87
- clientInterceptors?: ProcedureClientInterceptor<TContext, Schema<unknown>, ErrorMap>[];
88
- plugins?: StandardHandlerPlugin<TContext>[];
87
+ clientInterceptors?: ProcedureClientInterceptor<TContext, Schema<unknown>, ErrorMap>[] | undefined;
88
+ plugins?: StandardHandlerPlugin<TContext>[] | undefined;
89
89
  }
90
90
  declare class StandardHandler<T extends Context> {
91
91
  private readonly codec;
@@ -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.BEdOJs6S.mjs';
2
+ import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.BWhT-63L.mjs';
3
3
 
4
4
  type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any> | {
5
5
  [k: string]: Lazyable<Router<TInitialContext>>;
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.43",
4
+ "version": "2.0.0-beta.45",
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,23 +117,23 @@
117
117
  }
118
118
  },
119
119
  "dependencies": {
120
- "@orpc/client": "2.0.0-beta.43",
121
- "@orpc/contract": "2.0.0-beta.43",
122
- "@orpc/shared": "2.0.0-beta.43",
123
- "@standard-server/aws-lambda": "~0.10.2",
124
- "@standard-server/core": "~0.10.2",
125
- "@standard-server/fastify": "~0.10.2",
126
- "@standard-server/fetch": "~0.10.2",
127
- "@standard-server/node": "~0.10.2",
128
- "@standard-server/peer": "~0.10.2",
120
+ "@orpc/client": "2.0.0-beta.45",
121
+ "@orpc/contract": "2.0.0-beta.45",
122
+ "@orpc/shared": "2.0.0-beta.45",
123
+ "@standard-server/aws-lambda": "~0.11.0",
124
+ "@standard-server/core": "~0.11.0",
125
+ "@standard-server/fastify": "~0.11.0",
126
+ "@standard-server/fetch": "~0.11.0",
127
+ "@standard-server/node": "~0.11.0",
128
+ "@standard-server/peer": "~0.11.0",
129
129
  "cookie": "^2.0.1"
130
130
  },
131
131
  "devDependencies": {
132
- "crossws": "^0.4.6",
133
- "fastify": "^5.12.1",
134
- "supertest": "^7.2.2",
135
- "ws": "^8.21.3",
136
- "zod": "^4.5.4"
132
+ "crossws": "^0.4.15",
133
+ "fastify": "^5.12.7",
134
+ "supertest": "^7.3.1",
135
+ "ws": "^8.22.0",
136
+ "zod": "^4.6.7"
137
137
  },
138
138
  "scripts": {
139
139
  "type:check": "tsc -b"