@orpc/server 0.0.0-next.ed05c40 → 0.0.0-next.ed87680

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 (58) hide show
  1. package/README.md +4 -2
  2. package/dist/adapters/aws-lambda/index.d.mts +5 -5
  3. package/dist/adapters/aws-lambda/index.d.ts +5 -5
  4. package/dist/adapters/aws-lambda/index.mjs +2 -2
  5. package/dist/adapters/bun-ws/index.d.mts +5 -5
  6. package/dist/adapters/bun-ws/index.d.ts +5 -5
  7. package/dist/adapters/bun-ws/index.mjs +10 -10
  8. package/dist/adapters/crossws/index.d.mts +5 -5
  9. package/dist/adapters/crossws/index.d.ts +5 -5
  10. package/dist/adapters/crossws/index.mjs +5 -7
  11. package/dist/adapters/fetch/index.d.mts +54 -9
  12. package/dist/adapters/fetch/index.d.ts +54 -9
  13. package/dist/adapters/fetch/index.mjs +73 -3
  14. package/dist/adapters/message-port/index.d.mts +5 -5
  15. package/dist/adapters/message-port/index.d.ts +5 -5
  16. package/dist/adapters/message-port/index.mjs +5 -7
  17. package/dist/adapters/node/index.d.mts +30 -9
  18. package/dist/adapters/node/index.d.ts +30 -9
  19. package/dist/adapters/node/index.mjs +68 -12
  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 +2 -2
  23. package/dist/adapters/standard-peer/index.d.mts +9 -5
  24. package/dist/adapters/standard-peer/index.d.ts +9 -5
  25. package/dist/adapters/standard-peer/index.mjs +1 -1
  26. package/dist/adapters/websocket/index.d.mts +5 -5
  27. package/dist/adapters/websocket/index.d.ts +5 -5
  28. package/dist/adapters/websocket/index.mjs +5 -7
  29. package/dist/adapters/ws/index.d.mts +5 -5
  30. package/dist/adapters/ws/index.d.ts +5 -5
  31. package/dist/adapters/ws/index.mjs +5 -7
  32. package/dist/helpers/index.d.mts +5 -1
  33. package/dist/helpers/index.d.ts +5 -1
  34. package/dist/helpers/index.mjs +7 -1
  35. package/dist/hibernation/index.d.mts +11 -11
  36. package/dist/hibernation/index.d.ts +11 -11
  37. package/dist/hibernation/index.mjs +8 -8
  38. package/dist/index.d.mts +6 -6
  39. package/dist/index.d.ts +6 -6
  40. package/dist/index.mjs +5 -5
  41. package/dist/plugins/index.d.mts +2 -2
  42. package/dist/plugins/index.d.ts +2 -2
  43. package/dist/plugins/index.mjs +65 -56
  44. package/dist/shared/{server.CYNGeoCm.d.mts → server.B4BGqy3Y.d.mts} +2 -3
  45. package/dist/shared/{server.CYNGeoCm.d.ts → server.B4BGqy3Y.d.ts} +2 -3
  46. package/dist/shared/{server.D0H-iaY3.d.ts → server.COL12UTb.d.ts} +3 -3
  47. package/dist/shared/{server.BEFBl-Cb.d.mts → server.CVKCo60T.d.mts} +2 -2
  48. package/dist/shared/{server.NeumLVdS.mjs → server.CaqDCZX1.mjs} +105 -66
  49. package/dist/shared/{server.jMTkVNIb.d.ts → server.Cb6yD7DZ.d.ts} +1 -1
  50. package/dist/shared/{server.BU4WI18A.d.mts → server.Ck-gOLzq.d.mts} +3 -3
  51. package/dist/shared/{server.gqRxT-yN.d.mts → server.DBCUJijK.d.mts} +1 -1
  52. package/dist/shared/{server.B7b2w3_i.d.ts → server.DNtJ-p60.d.ts} +2 -2
  53. package/dist/shared/{server.Bmh5xd4n.d.ts → server.DPIFWpxG.d.ts} +1 -1
  54. package/dist/shared/{server.DhJj-1X9.d.mts → server.DzV1hr3z.d.mts} +1 -1
  55. package/dist/shared/server.UVMTOWrk.mjs +26 -0
  56. package/dist/shared/{server.CIL9uKTN.mjs → server.vzZSq5UM.mjs} +64 -39
  57. package/package.json +12 -11
  58. package/dist/shared/server.C6Q5sqYw.mjs +0 -20
@@ -1,5 +1,5 @@
1
1
  import { ErrorMap, EnhanceRouteOptions, MergedErrorMap, AnyContractRouter, AnyContractProcedure } from '@orpc/contract';
2
- import { a as AnyMiddleware, L as Lazyable, b as AnyRouter, C as Context, c as Lazy, A as AnyProcedure, P as Procedure, M as MergedInitialContext } from './server.CYNGeoCm.js';
2
+ import { a as AnyMiddleware, L as Lazyable, b as AnyRouter, C as Context, c as Lazy, A as AnyProcedure, P as Procedure, M as MergedInitialContext } from './server.B4BGqy3Y.js';
3
3
 
4
4
  declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
5
5
  type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : T extends AnyProcedure | undefined ? Lazy<T> : Lazy<T> & {
@@ -1,9 +1,9 @@
1
1
  import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
- import { b as AnyRouter, C as Context, R as Router } from './server.CYNGeoCm.mjs';
3
- import { i as StandardMatcher, h as StandardMatchResult, e as StandardHandlerOptions, f as StandardHandler } from './server.gqRxT-yN.mjs';
2
+ import { b as AnyRouter, C as Context, R as Router } from './server.B4BGqy3Y.mjs';
3
+ import { i as StandardMatcher, h as StandardMatchResult, e as StandardHandlerOptions, f as StandardHandler } from './server.DBCUJijK.mjs';
4
4
  import { HTTPPath } from '@orpc/client';
5
5
  import { Value } from '@orpc/shared';
6
- import { T as TraverseContractProcedureCallbackOptions } from './server.DhJj-1X9.mjs';
6
+ import { T as TraverseContractProcedureCallbackOptions } from './server.DzV1hr3z.mjs';
7
7
 
8
8
  interface StandardRPCMatcherOptions {
9
9
  /**
@@ -2,7 +2,7 @@ import { HTTPPath, ORPCError } from '@orpc/client';
2
2
  import { Meta } from '@orpc/contract';
3
3
  import { Interceptor } from '@orpc/shared';
4
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
- import { C as Context, R as Router, b as AnyRouter, A as AnyProcedure, d as ProcedureClientInterceptorOptions } from './server.CYNGeoCm.mjs';
5
+ import { C as Context, R as Router, b as AnyRouter, A as AnyProcedure, d as ProcedureClientInterceptorOptions } from './server.B4BGqy3Y.mjs';
6
6
 
7
7
  interface StandardHandlerPlugin<T extends Context> {
8
8
  order?: number;
@@ -1,5 +1,5 @@
1
- import { C as Context } from './server.CYNGeoCm.js';
2
- import { b as StandardHandleOptions } from './server.Bmh5xd4n.js';
1
+ import { C as Context } from './server.B4BGqy3Y.js';
2
+ import { b as StandardHandleOptions } from './server.DPIFWpxG.js';
3
3
 
4
4
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
5
  context?: T;
@@ -2,7 +2,7 @@ import { HTTPPath, ORPCError } from '@orpc/client';
2
2
  import { Meta } from '@orpc/contract';
3
3
  import { Interceptor } from '@orpc/shared';
4
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
- import { C as Context, R as Router, b as AnyRouter, A as AnyProcedure, d as ProcedureClientInterceptorOptions } from './server.CYNGeoCm.js';
5
+ import { C as Context, R as Router, b as AnyRouter, A as AnyProcedure, d as ProcedureClientInterceptorOptions } from './server.B4BGqy3Y.js';
6
6
 
7
7
  interface StandardHandlerPlugin<T extends Context> {
8
8
  order?: number;
@@ -1,5 +1,5 @@
1
1
  import { ErrorMap, EnhanceRouteOptions, MergedErrorMap, AnyContractRouter, AnyContractProcedure } from '@orpc/contract';
2
- import { a as AnyMiddleware, L as Lazyable, b as AnyRouter, C as Context, c as Lazy, A as AnyProcedure, P as Procedure, M as MergedInitialContext } from './server.CYNGeoCm.mjs';
2
+ import { a as AnyMiddleware, L as Lazyable, b as AnyRouter, C as Context, c as Lazy, A as AnyProcedure, P as Procedure, M as MergedInitialContext } from './server.B4BGqy3Y.mjs';
3
3
 
4
4
  declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
5
5
  type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : T extends AnyProcedure | undefined ? Lazy<T> : Lazy<T> & {
@@ -0,0 +1,26 @@
1
+ import '@orpc/client';
2
+ import '@orpc/shared';
3
+ import '@orpc/standard-server';
4
+ import '@orpc/contract';
5
+ import '@orpc/client/standard';
6
+ import { r as resolveFriendlyStandardHandleOptions } from './server.DZ5BIITo.mjs';
7
+
8
+ async function handleStandardServerPeerMessage(handler, peer, message, options) {
9
+ const [id, request] = await peer.message(message);
10
+ if (!request) {
11
+ return;
12
+ }
13
+ const handle = createServerPeerHandleRequestFn(handler, options);
14
+ await peer.response(id, await handle(request));
15
+ }
16
+ function createServerPeerHandleRequestFn(handler, options) {
17
+ return async (request) => {
18
+ const { response } = await handler.handle(
19
+ { ...request, body: () => Promise.resolve(request.body) },
20
+ resolveFriendlyStandardHandleOptions(options)
21
+ );
22
+ return response ?? { status: 404, headers: {}, body: "No procedure matched" };
23
+ };
24
+ }
25
+
26
+ export { createServerPeerHandleRequestFn as c, handleStandardServerPeerMessage as h };
@@ -1,8 +1,8 @@
1
1
  import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
2
2
  import { ORPCError, toORPCError } from '@orpc/client';
3
- import { toArray, intercept, parseEmptyableJSON, NullProtoObj, value } from '@orpc/shared';
3
+ import { toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, parseEmptyableJSON, NullProtoObj, value } from '@orpc/shared';
4
4
  import { flattenHeader } from '@orpc/standard-server';
5
- import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.NeumLVdS.mjs';
5
+ import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.CaqDCZX1.mjs';
6
6
 
7
7
  class CompositeStandardHandlerPlugin {
8
8
  plugins;
@@ -39,49 +39,74 @@ class StandardHandler {
39
39
  this.rootInterceptors,
40
40
  { ...options, request, prefix },
41
41
  async (interceptorOptions) => {
42
- let isDecoding = false;
43
- try {
44
- return await intercept(
45
- this.interceptors,
46
- interceptorOptions,
47
- async ({ request: request2, context, prefix: prefix2 }) => {
48
- const method = request2.method;
49
- const url = request2.url;
50
- const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
51
- const match = await this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`);
52
- if (!match) {
53
- return { matched: false, response: void 0 };
42
+ return runWithSpan(
43
+ { name: `${request.method} ${request.url.pathname}` },
44
+ async (span) => {
45
+ let step;
46
+ try {
47
+ return await intercept(
48
+ this.interceptors,
49
+ interceptorOptions,
50
+ async ({ request: request2, context, prefix: prefix2 }) => {
51
+ const method = request2.method;
52
+ const url = request2.url;
53
+ const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
54
+ const match = await runWithSpan(
55
+ { name: "find_procedure" },
56
+ () => this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`)
57
+ );
58
+ if (!match) {
59
+ return { matched: false, response: void 0 };
60
+ }
61
+ span?.updateName(`${ORPC_NAME}.${match.path.join("/")}`);
62
+ span?.setAttribute("rpc.system", ORPC_NAME);
63
+ span?.setAttribute("rpc.method", match.path.join("."));
64
+ step = "decode_input";
65
+ let input = await runWithSpan(
66
+ { name: "decode_input" },
67
+ () => this.codec.decode(request2, match.params, match.procedure)
68
+ );
69
+ step = void 0;
70
+ if (isAsyncIteratorObject(input)) {
71
+ input = asyncIteratorWithSpan(
72
+ { name: "consume_event_iterator_input", signal: request2.signal },
73
+ input
74
+ );
75
+ }
76
+ const client = createProcedureClient(match.procedure, {
77
+ context,
78
+ path: match.path,
79
+ interceptors: this.clientInterceptors
80
+ });
81
+ step = "call_procedure";
82
+ const output = await client(input, {
83
+ signal: request2.signal,
84
+ lastEventId: flattenHeader(request2.headers["last-event-id"])
85
+ });
86
+ step = void 0;
87
+ const response = this.codec.encode(output, match.procedure);
88
+ return {
89
+ matched: true,
90
+ response
91
+ };
92
+ }
93
+ );
94
+ } catch (e) {
95
+ if (step !== "call_procedure") {
96
+ setSpanError(span, e);
54
97
  }
55
- const client = createProcedureClient(match.procedure, {
56
- context,
57
- path: match.path,
58
- interceptors: this.clientInterceptors
59
- });
60
- isDecoding = true;
61
- const input = await this.codec.decode(request2, match.params, match.procedure);
62
- isDecoding = false;
63
- const output = await client(input, {
64
- signal: request2.signal,
65
- lastEventId: flattenHeader(request2.headers["last-event-id"])
66
- });
67
- const response = this.codec.encode(output, match.procedure);
98
+ const error = step === "decode_input" && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
99
+ message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
100
+ cause: e
101
+ }) : toORPCError(e);
102
+ const response = this.codec.encodeError(error);
68
103
  return {
69
104
  matched: true,
70
105
  response
71
106
  };
72
107
  }
73
- );
74
- } catch (e) {
75
- const error = isDecoding && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
76
- message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
77
- cause: e
78
- }) : toORPCError(e);
79
- const response = this.codec.encodeError(error);
80
- return {
81
- matched: true,
82
- response
83
- };
84
- }
108
+ }
109
+ );
85
110
  }
86
111
  );
87
112
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.0.0-next.ed05c40",
4
+ "version": "0.0.0-next.ed87680",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -102,20 +102,21 @@
102
102
  },
103
103
  "dependencies": {
104
104
  "cookie": "^1.0.2",
105
- "@orpc/client": "0.0.0-next.ed05c40",
106
- "@orpc/contract": "0.0.0-next.ed05c40",
107
- "@orpc/shared": "0.0.0-next.ed05c40",
108
- "@orpc/standard-server": "0.0.0-next.ed05c40",
109
- "@orpc/standard-server-aws-lambda": "0.0.0-next.ed05c40",
110
- "@orpc/standard-server-peer": "0.0.0-next.ed05c40",
111
- "@orpc/standard-server-fetch": "0.0.0-next.ed05c40",
112
- "@orpc/standard-server-node": "0.0.0-next.ed05c40"
105
+ "@orpc/client": "0.0.0-next.ed87680",
106
+ "@orpc/interop": "0.0.0-next.ed87680",
107
+ "@orpc/standard-server-aws-lambda": "0.0.0-next.ed87680",
108
+ "@orpc/standard-server": "0.0.0-next.ed87680",
109
+ "@orpc/contract": "0.0.0-next.ed87680",
110
+ "@orpc/shared": "0.0.0-next.ed87680",
111
+ "@orpc/standard-server-fetch": "0.0.0-next.ed87680",
112
+ "@orpc/standard-server-node": "0.0.0-next.ed87680",
113
+ "@orpc/standard-server-peer": "0.0.0-next.ed87680"
113
114
  },
114
115
  "devDependencies": {
115
116
  "@types/ws": "^8.18.1",
116
117
  "crossws": "^0.4.1",
117
- "next": "^15.4.1",
118
- "supertest": "^7.1.3",
118
+ "next": "^15.5.2",
119
+ "supertest": "^7.1.4",
119
120
  "ws": "^8.18.3"
120
121
  },
121
122
  "scripts": {
@@ -1,20 +0,0 @@
1
- import '@orpc/client';
2
- import '@orpc/shared';
3
- import '@orpc/standard-server';
4
- import '@orpc/contract';
5
- import '@orpc/client/standard';
6
- import { r as resolveFriendlyStandardHandleOptions } from './server.DZ5BIITo.mjs';
7
-
8
- async function handleStandardServerPeerMessage(handler, peer, message, options) {
9
- const [id, request] = await peer.message(message);
10
- if (!request) {
11
- return;
12
- }
13
- const { response } = await handler.handle(
14
- { ...request, body: () => Promise.resolve(request.body) },
15
- resolveFriendlyStandardHandleOptions(options)
16
- );
17
- await peer.response(id, response ?? { status: 404, headers: {}, body: "No procedure matched" });
18
- }
19
-
20
- export { handleStandardServerPeerMessage as h };