@orpc/server 0.0.0-next.fc23c8d → 0.0.0-next.fc2dc8f

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 (65) hide show
  1. package/README.md +11 -6
  2. package/dist/adapters/aws-lambda/index.d.mts +9 -8
  3. package/dist/adapters/aws-lambda/index.d.ts +9 -8
  4. package/dist/adapters/aws-lambda/index.mjs +6 -5
  5. package/dist/adapters/bun-ws/index.d.mts +14 -13
  6. package/dist/adapters/bun-ws/index.d.ts +14 -13
  7. package/dist/adapters/bun-ws/index.mjs +17 -16
  8. package/dist/adapters/crossws/index.d.mts +10 -7
  9. package/dist/adapters/crossws/index.d.ts +10 -7
  10. package/dist/adapters/crossws/index.mjs +9 -10
  11. package/dist/adapters/fastify/index.d.mts +53 -0
  12. package/dist/adapters/fastify/index.d.ts +53 -0
  13. package/dist/adapters/fastify/index.mjs +54 -0
  14. package/dist/adapters/fetch/index.d.mts +57 -11
  15. package/dist/adapters/fetch/index.d.ts +57 -11
  16. package/dist/adapters/fetch/index.mjs +74 -4
  17. package/dist/adapters/message-port/index.d.mts +42 -13
  18. package/dist/adapters/message-port/index.d.ts +42 -13
  19. package/dist/adapters/message-port/index.mjs +32 -18
  20. package/dist/adapters/node/index.d.mts +34 -12
  21. package/dist/adapters/node/index.d.ts +34 -12
  22. package/dist/adapters/node/index.mjs +70 -13
  23. package/dist/adapters/standard/index.d.mts +8 -13
  24. package/dist/adapters/standard/index.d.ts +8 -13
  25. package/dist/adapters/standard/index.mjs +3 -2
  26. package/dist/adapters/standard-peer/index.d.mts +18 -0
  27. package/dist/adapters/standard-peer/index.d.ts +18 -0
  28. package/dist/adapters/standard-peer/index.mjs +7 -0
  29. package/dist/adapters/websocket/index.d.mts +20 -15
  30. package/dist/adapters/websocket/index.d.ts +20 -15
  31. package/dist/adapters/websocket/index.mjs +13 -15
  32. package/dist/adapters/ws/index.d.mts +13 -10
  33. package/dist/adapters/ws/index.d.ts +13 -10
  34. package/dist/adapters/ws/index.mjs +13 -15
  35. package/dist/helpers/index.d.mts +149 -0
  36. package/dist/helpers/index.d.ts +149 -0
  37. package/dist/helpers/index.mjs +198 -0
  38. package/dist/hibernation/index.d.mts +13 -13
  39. package/dist/hibernation/index.d.ts +13 -13
  40. package/dist/hibernation/index.mjs +8 -8
  41. package/dist/index.d.mts +105 -136
  42. package/dist/index.d.ts +105 -136
  43. package/dist/index.mjs +37 -33
  44. package/dist/plugins/index.d.mts +58 -10
  45. package/dist/plugins/index.d.ts +58 -10
  46. package/dist/plugins/index.mjs +134 -59
  47. package/dist/shared/{server.-ACo36I0.d.ts → server.7cEtMB30.d.ts} +3 -3
  48. package/dist/shared/server.B8gYOD5g.d.mts +12 -0
  49. package/dist/shared/{server.Dq8xr7PQ.d.mts → server.BqadksTP.d.mts} +3 -3
  50. package/dist/shared/{server.CB8Snncu.mjs → server.Bxx6tqNe.mjs} +74 -41
  51. package/dist/shared/server.C8_sRzQB.d.mts +42 -0
  52. package/dist/shared/server.ChUyt5-i.d.mts +32 -0
  53. package/dist/shared/server.ChyoA9XY.d.ts +42 -0
  54. package/dist/shared/{server.DLJzqnSX.mjs → server.Ds4HPpvH.mjs} +114 -73
  55. package/dist/shared/server.EfTOZ2Q7.d.ts +12 -0
  56. package/dist/shared/{server.BW-nUGgA.mjs → server.TEVCLCFC.mjs} +3 -0
  57. package/dist/shared/server.UVMTOWrk.mjs +26 -0
  58. package/dist/shared/{server.DD2C4ujN.d.mts → server.qKsRrdxW.d.mts} +14 -13
  59. package/dist/shared/{server.DD2C4ujN.d.ts → server.qKsRrdxW.d.ts} +14 -13
  60. package/dist/shared/server.yoEB3Fx4.d.ts +32 -0
  61. package/package.json +34 -13
  62. package/dist/shared/server.BPAWobQg.d.ts +0 -12
  63. package/dist/shared/server.Bd52nNaH.d.mts +0 -12
  64. package/dist/shared/server.BliFSTnG.d.mts +0 -10
  65. package/dist/shared/server.IG2MjhrD.d.ts +0 -10
@@ -1,6 +1,7 @@
1
- import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
2
- import { value, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
3
- import { fallbackORPCErrorStatus, ORPCError } from '@orpc/client';
1
+ import { isContractProcedure, validateORPCError, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
2
+ import { resolveMaybeOptionalOptions, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@orpc/shared';
3
+ import { ORPCError, mapEventIterator } from '@orpc/client';
4
+ import { HibernationEventIterator } from '@orpc/standard-server';
4
5
 
5
6
  const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
6
7
  function lazy(loader, meta = {}) {
@@ -71,14 +72,15 @@ function createORPCErrorConstructorMap(errors) {
71
72
  if (typeof code !== "string") {
72
73
  return Reflect.get(target, code);
73
74
  }
74
- const item = (...[options]) => {
75
+ const item = (...rest) => {
76
+ const options = resolveMaybeOptionalOptions(rest);
75
77
  const config = errors[code];
76
78
  return new ORPCError(code, {
77
79
  defined: Boolean(config),
78
80
  status: config?.status,
79
- message: options?.message ?? config?.message,
80
- data: options?.data,
81
- cause: options?.cause
81
+ message: options.message ?? config?.message,
82
+ data: options.data,
83
+ cause: options.cause
82
84
  });
83
85
  };
84
86
  return item;
@@ -86,54 +88,64 @@ function createORPCErrorConstructorMap(errors) {
86
88
  });
87
89
  return proxy;
88
90
  }
89
- async function validateORPCError(map, error) {
90
- const { code, status, message, data, cause, defined } = error;
91
- const config = map?.[error.code];
92
- if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
93
- return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
94
- }
95
- if (!config.data) {
96
- return defined ? error : new ORPCError(code, { defined: true, status, message, data, cause });
97
- }
98
- const validated = await config.data["~standard"].validate(error.data);
99
- if (validated.issues) {
100
- return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
101
- }
102
- return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
103
- }
104
91
 
105
92
  function middlewareOutputFn(output) {
106
93
  return { output, context: {} };
107
94
  }
108
95
 
109
- function createProcedureClient(lazyableProcedure, ...[options]) {
96
+ function createProcedureClient(lazyableProcedure, ...rest) {
97
+ const options = resolveMaybeOptionalOptions(rest);
110
98
  return async (...[input, callerOptions]) => {
111
- const path = options?.path ?? [];
99
+ const path = toArray(options.path);
112
100
  const { default: procedure } = await unlazy(lazyableProcedure);
113
101
  const clientContext = callerOptions?.context ?? {};
114
- const context = await value(options?.context ?? {}, clientContext);
102
+ const context = await value(options.context ?? {}, clientContext);
115
103
  const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
104
+ const validateError = async (e) => {
105
+ if (e instanceof ORPCError) {
106
+ return await validateORPCError(procedure["~orpc"].errorMap, e);
107
+ }
108
+ return e;
109
+ };
116
110
  try {
117
- return await intercept(
118
- options?.interceptors ?? [],
119
- {
120
- context,
121
- input,
122
- // input only optional when it undefinable so we can safely cast it
123
- errors,
124
- path,
125
- procedure,
126
- signal: callerOptions?.signal,
127
- lastEventId: callerOptions?.lastEventId
128
- },
129
- (interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
111
+ const output = await runWithSpan(
112
+ { name: "call_procedure", signal: callerOptions?.signal },
113
+ (span) => {
114
+ span?.setAttribute("procedure.path", [...path]);
115
+ return intercept(
116
+ toArray(options.interceptors),
117
+ {
118
+ context,
119
+ input,
120
+ // input only optional when it undefinable so we can safely cast it
121
+ errors,
122
+ path,
123
+ procedure,
124
+ signal: callerOptions?.signal,
125
+ lastEventId: callerOptions?.lastEventId
126
+ },
127
+ (interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
128
+ );
129
+ }
130
130
  );
131
- } catch (e) {
132
- if (!(e instanceof ORPCError)) {
133
- throw e;
131
+ if (isAsyncIteratorObject(output)) {
132
+ if (output instanceof HibernationEventIterator) {
133
+ return output;
134
+ }
135
+ return overlayProxy(output, mapEventIterator(
136
+ asyncIteratorWithSpan(
137
+ { name: "consume_event_iterator_output", signal: callerOptions?.signal },
138
+ output
139
+ ),
140
+ {
141
+ value: (v) => v,
142
+ error: (e) => validateError(e)
143
+ }
144
+ ));
134
145
  }
135
- const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
136
- throw validated;
146
+ return output;
147
+ } catch (e) {
148
+ throw await validateError(e);
137
149
  }
138
150
  };
139
151
  }
@@ -142,31 +154,49 @@ async function validateInput(procedure, input) {
142
154
  if (!schema) {
143
155
  return input;
144
156
  }
145
- const result = await schema["~standard"].validate(input);
146
- if (result.issues) {
147
- throw new ORPCError("BAD_REQUEST", {
148
- message: "Input validation failed",
149
- data: {
150
- issues: result.issues
151
- },
152
- cause: new ValidationError({ message: "Input validation failed", issues: result.issues })
153
- });
154
- }
155
- return result.value;
157
+ return runWithSpan(
158
+ { name: "validate_input" },
159
+ async () => {
160
+ const result = await schema["~standard"].validate(input);
161
+ if (result.issues) {
162
+ throw new ORPCError("BAD_REQUEST", {
163
+ message: "Input validation failed",
164
+ data: {
165
+ issues: result.issues
166
+ },
167
+ cause: new ValidationError({
168
+ message: "Input validation failed",
169
+ issues: result.issues,
170
+ data: input
171
+ })
172
+ });
173
+ }
174
+ return result.value;
175
+ }
176
+ );
156
177
  }
157
178
  async function validateOutput(procedure, output) {
158
179
  const schema = procedure["~orpc"].outputSchema;
159
180
  if (!schema) {
160
181
  return output;
161
182
  }
162
- const result = await schema["~standard"].validate(output);
163
- if (result.issues) {
164
- throw new ORPCError("INTERNAL_SERVER_ERROR", {
165
- message: "Output validation failed",
166
- cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
167
- });
168
- }
169
- return result.value;
183
+ return runWithSpan(
184
+ { name: "validate_output" },
185
+ async () => {
186
+ const result = await schema["~standard"].validate(output);
187
+ if (result.issues) {
188
+ throw new ORPCError("INTERNAL_SERVER_ERROR", {
189
+ message: "Output validation failed",
190
+ cause: new ValidationError({
191
+ message: "Output validation failed",
192
+ issues: result.issues,
193
+ data: output
194
+ })
195
+ });
196
+ }
197
+ return result.value;
198
+ }
199
+ );
170
200
  }
171
201
  async function executeProcedureInternal(procedure, options) {
172
202
  const middlewares = procedure["~orpc"].middlewares;
@@ -178,17 +208,28 @@ async function executeProcedureInternal(procedure, options) {
178
208
  currentInput = await validateInput(procedure, currentInput);
179
209
  }
180
210
  const mid = middlewares[index];
181
- const output = mid ? (await mid({
182
- ...options,
183
- context,
184
- next: async (...[nextOptions]) => {
185
- const nextContext = nextOptions?.context ?? {};
186
- return {
187
- output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
188
- context: nextContext
189
- };
211
+ const output = mid ? await runWithSpan(
212
+ { name: `middleware.${mid.name}`, signal: options.signal },
213
+ async (span) => {
214
+ span?.setAttribute("middleware.index", index);
215
+ span?.setAttribute("middleware.name", mid.name);
216
+ const result = await mid({
217
+ ...options,
218
+ context,
219
+ next: async (...[nextOptions]) => {
220
+ const nextContext = nextOptions?.context ?? {};
221
+ return {
222
+ output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
223
+ context: nextContext
224
+ };
225
+ }
226
+ }, currentInput, middlewareOutputFn);
227
+ return result.output;
190
228
  }
191
- }, currentInput, middlewareOutputFn)).output : await procedure["~orpc"].handler({ ...options, context, input: currentInput });
229
+ ) : await runWithSpan(
230
+ { name: "handler", signal: options.signal },
231
+ () => procedure["~orpc"].handler({ ...options, context, input: currentInput })
232
+ );
192
233
  if (index === outputValidationIndex) {
193
234
  return await validateOutput(procedure, output);
194
235
  }
@@ -365,4 +406,4 @@ function call(procedure, input, ...rest) {
365
406
  return createProcedureClient(procedure, options)(input, options);
366
407
  }
367
408
 
368
- export { LAZY_SYMBOL as L, Procedure as P, createContractedProcedure as a, addMiddleware as b, createProcedureClient as c, isLazy as d, enhanceRouter as e, createAssertedLazyProcedure as f, getRouter as g, createORPCErrorConstructorMap as h, isProcedure as i, getLazyMeta as j, middlewareOutputFn as k, lazy as l, mergeCurrentContext as m, isStartWithMiddlewares as n, mergeMiddlewares as o, call as p, getHiddenRouterContract as q, createAccessibleLazyRouter as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, validateORPCError as v, resolveContractProcedures as w, unlazyRouter as x };
409
+ export { LAZY_SYMBOL as L, Procedure as P, createContractedProcedure as a, addMiddleware as b, createProcedureClient as c, isLazy as d, enhanceRouter as e, createAssertedLazyProcedure as f, getRouter as g, createORPCErrorConstructorMap as h, isProcedure as i, getLazyMeta as j, middlewareOutputFn as k, lazy as l, mergeCurrentContext as m, isStartWithMiddlewares as n, mergeMiddlewares as o, call as p, getHiddenRouterContract as q, createAccessibleLazyRouter as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, resolveContractProcedures as v, unlazyRouter as w };
@@ -0,0 +1,12 @@
1
+ import { C as Context } from './server.qKsRrdxW.js';
2
+ import { b as StandardHandleOptions } from './server.7cEtMB30.js';
3
+
4
+ type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
+ context?: T;
6
+ } : {
7
+ context: T;
8
+ });
9
+ declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
10
+
11
+ export { resolveFriendlyStandardHandleOptions as r };
12
+ export type { FriendlyStandardHandleOptions as F };
@@ -3,6 +3,9 @@ import { ORPCError, fallbackContractConfig } from '@orpc/contract';
3
3
  const STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT_SYMBOL = Symbol("STRICT_GET_METHOD_PLUGIN_IS_GET_METHOD_CONTEXT");
4
4
  class StrictGetMethodPlugin {
5
5
  error;
6
+ /**
7
+ * make sure execute before batch plugin to get real method
8
+ */
6
9
  order = 7e6;
7
10
  constructor(options = {}) {
8
11
  this.error = options.error ?? new ORPCError("METHOD_NOT_SUPPORTED");
@@ -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 };
@@ -13,7 +13,6 @@ type ORPCErrorConstructorMap<T extends ErrorMap> = {
13
13
  [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
14
14
  };
15
15
  declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
16
- declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
17
16
 
18
17
  declare const LAZY_SYMBOL: unique symbol;
19
18
  interface LazyMeta {
@@ -29,7 +28,9 @@ interface Lazy<T> {
29
28
  }
30
29
  type Lazyable<T> = T | Lazy<T>;
31
30
  /**
32
- * Create a lazy thing.
31
+ * Creates a lazy-loaded item.
32
+ *
33
+ * @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazy(...)` instead.
33
34
  */
34
35
  declare function lazy<T>(loader: () => Promise<{
35
36
  default: T;
@@ -62,7 +63,7 @@ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends
62
63
  /**
63
64
  * This class represents a procedure.
64
65
  *
65
- * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
66
+ * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
66
67
  */
67
68
  declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
68
69
  /**
@@ -101,7 +102,7 @@ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstruct
101
102
  /**
102
103
  * A function that represents a middleware.
103
104
  *
104
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
105
+ * @see {@link https://orpc.dev/docs/middleware Middleware Docs}
105
106
  */
106
107
  interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
107
108
  (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
@@ -136,15 +137,15 @@ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema
136
137
  /**
137
138
  * Create Server-side client from a procedure.
138
139
  *
139
- * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
140
+ * @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs}
140
141
  */
141
- declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
142
+ declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
142
143
 
143
144
  /**
144
145
  * Represents a router, which defines a hierarchical structure of procedures.
145
146
  *
146
147
  * @info A procedure is a router too.
147
- * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
148
+ * @see {@link https://orpc.dev/docs/contract-first/define-contract#contract-router Contract Router Docs}
148
149
  */
149
150
  type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
150
151
  [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
@@ -155,7 +156,7 @@ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infe
155
156
  * Infer all initial context of the router.
156
157
  *
157
158
  * @info A procedure is a router too.
158
- * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
159
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
159
160
  */
160
161
  type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
161
162
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
@@ -164,7 +165,7 @@ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer
164
165
  * Infer all current context of the router.
165
166
  *
166
167
  * @info A procedure is a router too.
167
- * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
168
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
168
169
  */
169
170
  type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
170
171
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
@@ -173,7 +174,7 @@ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any,
173
174
  * Infer all router inputs
174
175
  *
175
176
  * @info A procedure is a router too.
176
- * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
177
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
177
178
  */
178
179
  type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
179
180
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
@@ -182,11 +183,11 @@ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infe
182
183
  * Infer all router outputs
183
184
  *
184
185
  * @info A procedure is a router too.
185
- * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
186
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
186
187
  */
187
188
  type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
188
189
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
189
190
  };
190
191
 
191
- export { isProcedure as E, createProcedureClient as G, Procedure as P, createORPCErrorConstructorMap as l, mergeCurrentContext as m, LAZY_SYMBOL as n, lazy as p, isLazy as q, getLazyMeta as r, unlazy as u, validateORPCError as v, middlewareOutputFn as z };
192
- export type { AnyMiddleware as A, ProcedureHandlerOptions as B, Context as C, ProcedureDef as D, ProcedureClientInterceptorOptions as F, InferRouterInitialContexts as H, InferRouterInitialContext as I, InferRouterCurrentContexts as J, InferRouterInputs as K, Lazyable as L, Middleware as M, InferRouterOutputs as N, ORPCErrorConstructorMap as O, Router as R, MergedInitialContext as a, MergedCurrentContext as b, MapInputMiddleware as c, CreateProcedureClientOptions as d, ProcedureClient as e, AnyRouter as f, Lazy as g, AnyProcedure as h, ProcedureHandler as i, ORPCErrorConstructorMapItemOptions as j, ORPCErrorConstructorMapItem as k, LazyMeta as o, MiddlewareResult as s, MiddlewareNextFnOptions as t, MiddlewareNextFn as w, MiddlewareOutputFn as x, MiddlewareOptions as y };
192
+ export { isProcedure as E, createProcedureClient as F, Procedure as P, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, lazy as q, isLazy as r, getLazyMeta as s, unlazy as u, middlewareOutputFn as z };
193
+ export type { AnyProcedure as A, ProcedureHandlerOptions as B, Context as C, ProcedureDef as D, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L, MergedInitialContext as M, ORPCErrorConstructorMap as O, Router as R, AnyMiddleware as a, AnyRouter as b, Lazy as c, ProcedureClientInterceptorOptions as d, Middleware as e, MergedCurrentContext as f, MapInputMiddleware as g, CreateProcedureClientOptions as h, ProcedureClient as i, ProcedureHandler as j, ORPCErrorConstructorMapItemOptions as k, ORPCErrorConstructorMapItem as l, LazyMeta as p, MiddlewareResult as t, MiddlewareNextFnOptions as v, MiddlewareNextFn as w, MiddlewareOutputFn as x, MiddlewareOptions as y };
@@ -13,7 +13,6 @@ type ORPCErrorConstructorMap<T extends ErrorMap> = {
13
13
  [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
14
14
  };
15
15
  declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
16
- declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
17
16
 
18
17
  declare const LAZY_SYMBOL: unique symbol;
19
18
  interface LazyMeta {
@@ -29,7 +28,9 @@ interface Lazy<T> {
29
28
  }
30
29
  type Lazyable<T> = T | Lazy<T>;
31
30
  /**
32
- * Create a lazy thing.
31
+ * Creates a lazy-loaded item.
32
+ *
33
+ * @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazy(...)` instead.
33
34
  */
34
35
  declare function lazy<T>(loader: () => Promise<{
35
36
  default: T;
@@ -62,7 +63,7 @@ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends
62
63
  /**
63
64
  * This class represents a procedure.
64
65
  *
65
- * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
66
+ * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
66
67
  */
67
68
  declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
68
69
  /**
@@ -101,7 +102,7 @@ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstruct
101
102
  /**
102
103
  * A function that represents a middleware.
103
104
  *
104
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
105
+ * @see {@link https://orpc.dev/docs/middleware Middleware Docs}
105
106
  */
106
107
  interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
107
108
  (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
@@ -136,15 +137,15 @@ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema
136
137
  /**
137
138
  * Create Server-side client from a procedure.
138
139
  *
139
- * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
140
+ * @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs}
140
141
  */
141
- declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
142
+ declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
142
143
 
143
144
  /**
144
145
  * Represents a router, which defines a hierarchical structure of procedures.
145
146
  *
146
147
  * @info A procedure is a router too.
147
- * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
148
+ * @see {@link https://orpc.dev/docs/contract-first/define-contract#contract-router Contract Router Docs}
148
149
  */
149
150
  type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
150
151
  [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
@@ -155,7 +156,7 @@ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infe
155
156
  * Infer all initial context of the router.
156
157
  *
157
158
  * @info A procedure is a router too.
158
- * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
159
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
159
160
  */
160
161
  type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
161
162
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
@@ -164,7 +165,7 @@ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer
164
165
  * Infer all current context of the router.
165
166
  *
166
167
  * @info A procedure is a router too.
167
- * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
168
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
168
169
  */
169
170
  type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
170
171
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
@@ -173,7 +174,7 @@ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any,
173
174
  * Infer all router inputs
174
175
  *
175
176
  * @info A procedure is a router too.
176
- * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
177
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
177
178
  */
178
179
  type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
179
180
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
@@ -182,11 +183,11 @@ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infe
182
183
  * Infer all router outputs
183
184
  *
184
185
  * @info A procedure is a router too.
185
- * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
186
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
186
187
  */
187
188
  type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
188
189
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
189
190
  };
190
191
 
191
- export { isProcedure as E, createProcedureClient as G, Procedure as P, createORPCErrorConstructorMap as l, mergeCurrentContext as m, LAZY_SYMBOL as n, lazy as p, isLazy as q, getLazyMeta as r, unlazy as u, validateORPCError as v, middlewareOutputFn as z };
192
- export type { AnyMiddleware as A, ProcedureHandlerOptions as B, Context as C, ProcedureDef as D, ProcedureClientInterceptorOptions as F, InferRouterInitialContexts as H, InferRouterInitialContext as I, InferRouterCurrentContexts as J, InferRouterInputs as K, Lazyable as L, Middleware as M, InferRouterOutputs as N, ORPCErrorConstructorMap as O, Router as R, MergedInitialContext as a, MergedCurrentContext as b, MapInputMiddleware as c, CreateProcedureClientOptions as d, ProcedureClient as e, AnyRouter as f, Lazy as g, AnyProcedure as h, ProcedureHandler as i, ORPCErrorConstructorMapItemOptions as j, ORPCErrorConstructorMapItem as k, LazyMeta as o, MiddlewareResult as s, MiddlewareNextFnOptions as t, MiddlewareNextFn as w, MiddlewareOutputFn as x, MiddlewareOptions as y };
192
+ export { isProcedure as E, createProcedureClient as F, Procedure as P, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, lazy as q, isLazy as r, getLazyMeta as s, unlazy as u, middlewareOutputFn as z };
193
+ export type { AnyProcedure as A, ProcedureHandlerOptions as B, Context as C, ProcedureDef as D, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L, MergedInitialContext as M, ORPCErrorConstructorMap as O, Router as R, AnyMiddleware as a, AnyRouter as b, Lazy as c, ProcedureClientInterceptorOptions as d, Middleware as e, MergedCurrentContext as f, MapInputMiddleware as g, CreateProcedureClientOptions as h, ProcedureClient as i, ProcedureHandler as j, ORPCErrorConstructorMapItemOptions as k, ORPCErrorConstructorMapItem as l, LazyMeta as p, MiddlewareResult as t, MiddlewareNextFnOptions as v, MiddlewareNextFn as w, MiddlewareOutputFn as x, MiddlewareOptions as y };
@@ -0,0 +1,32 @@
1
+ import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
+ import { b as AnyRouter, C as Context, R as Router } from './server.qKsRrdxW.js';
3
+ import { i as StandardMatcher, h as StandardMatchResult, e as StandardHandlerOptions, f as StandardHandler } from './server.7cEtMB30.js';
4
+ import { HTTPPath } from '@orpc/client';
5
+ import { Value } from '@orpc/shared';
6
+ import { T as TraverseContractProcedureCallbackOptions } from './server.ChyoA9XY.js';
7
+
8
+ interface StandardRPCMatcherOptions {
9
+ /**
10
+ * Filter procedures. Return `false` to exclude a procedure from matching.
11
+ *
12
+ * @default true
13
+ */
14
+ filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
15
+ }
16
+ declare class StandardRPCMatcher implements StandardMatcher {
17
+ private readonly filter;
18
+ private readonly tree;
19
+ private pendingRouters;
20
+ constructor(options?: StandardRPCMatcherOptions);
21
+ init(router: AnyRouter, path?: readonly string[]): void;
22
+ match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
23
+ }
24
+
25
+ interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions, StandardRPCMatcherOptions {
26
+ }
27
+ declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
28
+ constructor(router: Router<any, T>, options?: StandardRPCHandlerOptions<T>);
29
+ }
30
+
31
+ export { StandardRPCHandler as a, StandardRPCMatcher as c };
32
+ export type { StandardRPCHandlerOptions as S, StandardRPCMatcherOptions as b };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.0.0-next.fc23c8d",
4
+ "version": "0.0.0-next.fc2dc8f",
5
5
  "license": "MIT",
6
- "homepage": "https://orpc.unnoq.com",
6
+ "homepage": "https://orpc.dev",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/unnoq/orpc.git",
@@ -19,6 +19,11 @@
19
19
  "import": "./dist/index.mjs",
20
20
  "default": "./dist/index.mjs"
21
21
  },
22
+ "./helpers": {
23
+ "types": "./dist/helpers/index.d.mts",
24
+ "import": "./dist/helpers/index.mjs",
25
+ "default": "./dist/helpers/index.mjs"
26
+ },
22
27
  "./plugins": {
23
28
  "types": "./dist/plugins/index.d.mts",
24
29
  "import": "./dist/plugins/index.mjs",
@@ -34,6 +39,11 @@
34
39
  "import": "./dist/adapters/standard/index.mjs",
35
40
  "default": "./dist/adapters/standard/index.mjs"
36
41
  },
42
+ "./standard-peer": {
43
+ "types": "./dist/adapters/standard-peer/index.d.mts",
44
+ "import": "./dist/adapters/standard-peer/index.mjs",
45
+ "default": "./dist/adapters/standard-peer/index.mjs"
46
+ },
37
47
  "./fetch": {
38
48
  "types": "./dist/adapters/fetch/index.d.mts",
39
49
  "import": "./dist/adapters/fetch/index.mjs",
@@ -44,6 +54,11 @@
44
54
  "import": "./dist/adapters/node/index.mjs",
45
55
  "default": "./dist/adapters/node/index.mjs"
46
56
  },
57
+ "./fastify": {
58
+ "types": "./dist/adapters/fastify/index.d.mts",
59
+ "import": "./dist/adapters/fastify/index.mjs",
60
+ "default": "./dist/adapters/fastify/index.mjs"
61
+ },
47
62
  "./aws-lambda": {
48
63
  "types": "./dist/adapters/aws-lambda/index.d.mts",
49
64
  "import": "./dist/adapters/aws-lambda/index.mjs",
@@ -91,21 +106,27 @@
91
106
  }
92
107
  },
93
108
  "dependencies": {
94
- "@orpc/contract": "0.0.0-next.fc23c8d",
95
- "@orpc/client": "0.0.0-next.fc23c8d",
96
- "@orpc/shared": "0.0.0-next.fc23c8d",
97
- "@orpc/standard-server-aws-lambda": "0.0.0-next.fc23c8d",
98
- "@orpc/standard-server-node": "0.0.0-next.fc23c8d",
99
- "@orpc/standard-server": "0.0.0-next.fc23c8d",
100
- "@orpc/standard-server-peer": "0.0.0-next.fc23c8d",
101
- "@orpc/standard-server-fetch": "0.0.0-next.fc23c8d"
109
+ "cookie": "^1.1.1",
110
+ "@orpc/client": "0.0.0-next.fc2dc8f",
111
+ "@orpc/contract": "0.0.0-next.fc2dc8f",
112
+ "@orpc/shared": "0.0.0-next.fc2dc8f",
113
+ "@orpc/interop": "0.0.0-next.fc2dc8f",
114
+ "@orpc/standard-server": "0.0.0-next.fc2dc8f",
115
+ "@orpc/standard-server-fastify": "0.0.0-next.fc2dc8f",
116
+ "@orpc/standard-server-node": "0.0.0-next.fc2dc8f",
117
+ "@orpc/standard-server-fetch": "0.0.0-next.fc2dc8f",
118
+ "@orpc/standard-server-peer": "0.0.0-next.fc2dc8f",
119
+ "@orpc/standard-server-aws-lambda": "0.0.0-next.fc2dc8f"
102
120
  },
103
121
  "devDependencies": {
122
+ "@tanstack/router-core": "^1.144.0",
104
123
  "@types/ws": "^8.18.1",
105
124
  "crossws": "^0.4.1",
106
- "next": "^15.3.4",
107
- "supertest": "^7.1.0",
108
- "ws": "^8.18.1"
125
+ "fastify": "^5.6.2",
126
+ "next": "^16.1.1",
127
+ "supertest": "^7.1.4",
128
+ "ws": "^8.18.3",
129
+ "zod": "^4.2.1"
109
130
  },
110
131
  "scripts": {
111
132
  "build": "unbuild",
@@ -1,12 +0,0 @@
1
- import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
- import { C as Context, R as Router } from './server.DD2C4ujN.js';
3
- import { b as StandardHandlerOptions, i as StandardHandler } from './server.-ACo36I0.js';
4
-
5
- interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
- }
7
- declare class StandardRPCHandler<T extends Context> extends StandardHandler<T> {
8
- constructor(router: Router<any, T>, options?: StandardRPCHandlerOptions<T>);
9
- }
10
-
11
- export { StandardRPCHandler as a };
12
- export type { StandardRPCHandlerOptions as S };