@orpc/server 0.0.0-next.ccd4e42 → 0.0.0-next.d0e429d

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 (50) hide show
  1. package/README.md +118 -0
  2. package/dist/chunk-AJXRPY6I.js +32 -0
  3. package/dist/{chunk-NOA3GBJQ.js → chunk-MHVECKBC.js} +64 -23
  4. package/dist/chunk-NTHCS5CK.js +182 -0
  5. package/dist/chunk-TXHKQO7N.js +120 -0
  6. package/dist/fetch.js +6 -13
  7. package/dist/hono.js +18 -16
  8. package/dist/index.js +16 -7
  9. package/dist/next.js +6 -13
  10. package/dist/node.js +9 -151
  11. package/dist/plugins.js +11 -0
  12. package/dist/src/adapters/fetch/index.d.ts +0 -1
  13. package/dist/src/adapters/fetch/rpc-handler.d.ts +4 -2
  14. package/dist/src/adapters/fetch/types.d.ts +4 -2
  15. package/dist/src/adapters/hono/middleware.d.ts +2 -3
  16. package/dist/src/adapters/next/serve.d.ts +2 -3
  17. package/dist/src/adapters/node/index.d.ts +0 -1
  18. package/dist/src/adapters/node/rpc-handler.d.ts +4 -2
  19. package/dist/src/adapters/node/types.d.ts +4 -2
  20. package/dist/src/adapters/standard/handler.d.ts +30 -10
  21. package/dist/src/adapters/standard/index.d.ts +0 -1
  22. package/dist/src/adapters/standard/rpc-codec.d.ts +4 -3
  23. package/dist/src/adapters/standard/types.d.ts +3 -26
  24. package/dist/src/builder-variants.d.ts +2 -1
  25. package/dist/src/builder.d.ts +2 -1
  26. package/dist/src/context.d.ts +0 -1
  27. package/dist/src/error.d.ts +12 -0
  28. package/dist/src/implementer-procedure.d.ts +7 -4
  29. package/dist/src/implementer-variants.d.ts +2 -1
  30. package/dist/src/implementer.d.ts +2 -1
  31. package/dist/src/index.d.ts +3 -1
  32. package/dist/src/middleware-decorated.d.ts +2 -1
  33. package/dist/src/middleware.d.ts +5 -4
  34. package/dist/src/plugins/base.d.ts +11 -0
  35. package/dist/src/plugins/cors.d.ts +19 -0
  36. package/dist/src/plugins/index.d.ts +4 -0
  37. package/dist/src/plugins/response-headers.d.ts +10 -0
  38. package/dist/src/procedure-client.d.ts +21 -8
  39. package/dist/src/procedure-decorated.d.ts +7 -4
  40. package/dist/src/procedure-utils.d.ts +5 -3
  41. package/dist/src/procedure.d.ts +5 -3
  42. package/dist/src/router-client.d.ts +7 -17
  43. package/dist/src/router.d.ts +1 -0
  44. package/dist/standard.js +5 -8
  45. package/package.json +12 -4
  46. package/dist/chunk-6RSW63UJ.js +0 -136
  47. package/dist/chunk-JHLUGXCM.js +0 -294
  48. package/dist/src/adapters/fetch/utils.d.ts +0 -6
  49. package/dist/src/adapters/node/utils.d.ts +0 -5
  50. package/dist/src/adapters/standard/rpc-serializer.d.ts +0 -16
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  middlewareOutputFn,
22
22
  setRouterContract,
23
23
  unlazy
24
- } from "./chunk-NOA3GBJQ.js";
24
+ } from "./chunk-MHVECKBC.js";
25
25
 
26
26
  // src/builder.ts
27
27
  import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
@@ -50,10 +50,14 @@ function decorateMiddleware(middleware) {
50
50
  decorated.concat = (concatMiddleware, mapInput) => {
51
51
  const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
52
52
  const concatted = decorateMiddleware((options, input, output, ...rest) => {
53
- const next = async (...[nextOptions]) => {
54
- return mapped({ ...options, context: { ...nextOptions?.context, ...options.context } }, input, output, ...rest);
55
- };
56
- const merged = middleware({ ...options, next }, input, output, ...rest);
53
+ const merged = middleware({
54
+ ...options,
55
+ next: (...[nextOptions1]) => mapped({
56
+ ...options,
57
+ context: { ...options.context, ...nextOptions1?.context },
58
+ next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
59
+ }, input, output, ...rest)
60
+ }, input, output, ...rest);
57
61
  return merged;
58
62
  });
59
63
  return concatted;
@@ -357,8 +361,10 @@ function createRouterClient(router, ...rest) {
357
361
  }
358
362
 
359
363
  // src/index.ts
360
- import { isDefinedError, ORPCError, safe, type, ValidationError } from "@orpc/contract";
364
+ import { isDefinedError, ORPCError, safe } from "@orpc/client";
365
+ import { eventIterator, type, ValidationError } from "@orpc/contract";
361
366
  import { onError, onFinish, onStart, onSuccess } from "@orpc/shared";
367
+ import { getEventMeta, withEventMeta } from "@orpc/standard-server";
362
368
  export {
363
369
  Builder,
364
370
  DecoratedProcedure,
@@ -378,8 +384,10 @@ export {
378
384
  deepSetLazyRouterPrefix,
379
385
  eachAllContractProcedure,
380
386
  eachContractProcedure,
387
+ eventIterator,
381
388
  fallbackConfig,
382
389
  flatLazy,
390
+ getEventMeta,
383
391
  getLazyRouterPrefix,
384
392
  getRouterChild,
385
393
  getRouterContract,
@@ -399,6 +407,7 @@ export {
399
407
  safe,
400
408
  setRouterContract,
401
409
  type,
402
- unlazy
410
+ unlazy,
411
+ withEventMeta
403
412
  };
404
413
  //# sourceMappingURL=index.js.map
package/dist/next.js CHANGED
@@ -1,12 +1,9 @@
1
1
  import {
2
- RPCHandler,
3
- fetchReToStandardBody,
4
- fetchRequestToStandardRequest,
5
- standardBodyToFetchBody,
6
- standardResponseToFetchResponse
7
- } from "./chunk-6RSW63UJ.js";
8
- import "./chunk-JHLUGXCM.js";
9
- import "./chunk-NOA3GBJQ.js";
2
+ RPCHandler
3
+ } from "./chunk-AJXRPY6I.js";
4
+ import "./chunk-NTHCS5CK.js";
5
+ import "./chunk-MHVECKBC.js";
6
+ import "./chunk-TXHKQO7N.js";
10
7
 
11
8
  // src/adapters/next/serve.ts
12
9
  import { value } from "@orpc/shared";
@@ -29,10 +26,6 @@ function serve(handler, ...[options]) {
29
26
  }
30
27
  export {
31
28
  RPCHandler,
32
- fetchReToStandardBody,
33
- fetchRequestToStandardRequest,
34
- serve,
35
- standardBodyToFetchBody,
36
- standardResponseToFetchResponse
29
+ serve
37
30
  };
38
31
  //# sourceMappingURL=next.js.map
package/dist/node.js CHANGED
@@ -2,152 +2,12 @@ import {
2
2
  RPCCodec,
3
3
  RPCMatcher,
4
4
  StandardHandler
5
- } from "./chunk-JHLUGXCM.js";
6
- import "./chunk-NOA3GBJQ.js";
7
-
8
- // src/adapters/node/utils.ts
9
- import { Buffer, File } from "node:buffer";
10
- import { Readable } from "node:stream";
11
- import { once } from "@orpc/shared";
12
- import cd from "content-disposition";
13
- function nodeHttpToStandardRequest(req, res) {
14
- const method = req.method ?? "GET";
15
- const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
16
- const host = req.headers.host ?? "localhost";
17
- const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
18
- return {
19
- raw: { request: req, response: res },
20
- method,
21
- url,
22
- headers: req.headers,
23
- body: once(() => {
24
- return nodeHttpRequestToStandardBody(req);
25
- }),
26
- get signal() {
27
- const signal = nodeHttpResponseToAbortSignal(res);
28
- Object.defineProperty(this, "signal", { value: signal, writable: true });
29
- return signal;
30
- },
31
- set signal(value) {
32
- Object.defineProperty(this, "signal", { value, writable: true });
33
- }
34
- };
35
- }
36
- function nodeHttpResponseSendStandardResponse(res, standardResponse) {
37
- return new Promise((resolve, reject) => {
38
- res.on("error", reject);
39
- res.on("finish", resolve);
40
- if (standardResponse.body === void 0) {
41
- res.writeHead(standardResponse.status, standardResponse.headers);
42
- res.end();
43
- }
44
- if (standardResponse.body instanceof Blob) {
45
- const resHeaders = {
46
- ...standardResponse.headers,
47
- "content-type": standardResponse.body.type,
48
- "content-length": standardResponse.body.size.toString()
49
- };
50
- if (!standardResponse.headers["content-disposition"] && standardResponse.body instanceof Blob) {
51
- resHeaders["content-disposition"] = cd(standardResponse.body instanceof File ? standardResponse.body.name : "blob");
52
- }
53
- res.writeHead(standardResponse.status, resHeaders);
54
- Readable.fromWeb(
55
- standardResponse.body.stream()
56
- // Conflict between types=node and lib=dom so we need to cast it
57
- ).pipe(res);
58
- return;
59
- }
60
- if (standardResponse.body instanceof FormData) {
61
- const response = new Response(standardResponse.body);
62
- res.writeHead(standardResponse.status, {
63
- ...standardResponse.headers,
64
- "content-type": response.headers.get("content-type")
65
- });
66
- Readable.fromWeb(
67
- response.body
68
- // Conflict between types=node and lib=dom so we need to cast it
69
- ).pipe(res);
70
- return;
71
- }
72
- if (standardResponse.body instanceof URLSearchParams) {
73
- res.writeHead(standardResponse.status, {
74
- ...standardResponse.headers,
75
- "content-type": "application/x-www-form-urlencoded"
76
- });
77
- const string2 = standardResponse.body.toString();
78
- res.end(string2);
79
- return;
80
- }
81
- res.writeHead(standardResponse.status, {
82
- ...standardResponse.headers,
83
- "content-type": "application/json"
84
- });
85
- const string = JSON.stringify(standardResponse.body);
86
- res.end(string);
87
- });
88
- }
89
- async function nodeHttpRequestToStandardBody(req) {
90
- const method = req.method ?? "GET";
91
- if (method === "GET" || method === "HEAD") {
92
- return void 0;
93
- }
94
- const contentDisposition = req.headers["content-disposition"];
95
- const fileName = contentDisposition ? cd.parse(contentDisposition).parameters.filename : void 0;
96
- const contentType = req.headers["content-type"];
97
- if (fileName) {
98
- return await streamToFile(req, fileName, contentType || "application/octet-stream");
99
- }
100
- if (!contentType || contentType.startsWith("application/json")) {
101
- const text = await streamToString(req);
102
- if (!text) {
103
- return void 0;
104
- }
105
- return JSON.parse(text);
106
- }
107
- if (contentType.startsWith("multipart/form-data")) {
108
- return await streamToFormData(req, contentType);
109
- }
110
- if (contentType.startsWith("application/x-www-form-urlencoded")) {
111
- const text = await streamToString(req);
112
- return new URLSearchParams(text);
113
- }
114
- if (contentType.startsWith("text/")) {
115
- return await streamToString(req);
116
- }
117
- return streamToFile(req, "blob", contentType);
118
- }
119
- function streamToFormData(stream, contentType) {
120
- const response = new Response(stream, {
121
- // Conflict between types=node and lib=dom so we need to cast it
122
- headers: {
123
- "content-type": contentType
124
- }
125
- });
126
- return response.formData();
127
- }
128
- async function streamToString(stream) {
129
- let string = "";
130
- for await (const chunk of stream) {
131
- string += chunk.toString();
132
- }
133
- return string;
134
- }
135
- async function streamToFile(stream, fileName, contentType) {
136
- const chunks = [];
137
- for await (const chunk of stream) {
138
- chunks.push(chunk);
139
- }
140
- return new File([Buffer.concat(chunks)], fileName, { type: contentType });
141
- }
142
- function nodeHttpResponseToAbortSignal(res) {
143
- const controller = new AbortController();
144
- res.on("close", () => {
145
- controller.abort();
146
- });
147
- return controller.signal;
148
- }
5
+ } from "./chunk-NTHCS5CK.js";
6
+ import "./chunk-MHVECKBC.js";
7
+ import "./chunk-TXHKQO7N.js";
149
8
 
150
9
  // src/adapters/node/rpc-handler.ts
10
+ import { sendStandardResponse, toStandardRequest } from "@orpc/standard-server-node";
151
11
  var RPCHandler = class {
152
12
  standardHandler;
153
13
  constructor(router, options) {
@@ -155,19 +15,17 @@ var RPCHandler = class {
155
15
  const matcher = options?.matcher ?? new RPCMatcher();
156
16
  this.standardHandler = new StandardHandler(router, matcher, codec, options);
157
17
  }
158
- async handle(req, res, ...rest) {
159
- const standardRequest = nodeHttpToStandardRequest(req, res);
160
- const result = await this.standardHandler.handle(standardRequest, ...rest);
18
+ async handle(req, res, ...[options]) {
19
+ const standardRequest = toStandardRequest(req, res);
20
+ const result = await this.standardHandler.handle(standardRequest, options);
161
21
  if (!result.matched) {
162
22
  return { matched: false };
163
23
  }
164
- await nodeHttpResponseSendStandardResponse(res, result.response);
24
+ await sendStandardResponse(res, result.response, options);
165
25
  return { matched: true };
166
26
  }
167
27
  };
168
28
  export {
169
- RPCHandler,
170
- nodeHttpResponseSendStandardResponse,
171
- nodeHttpToStandardRequest
29
+ RPCHandler
172
30
  };
173
31
  //# sourceMappingURL=node.js.map
@@ -0,0 +1,11 @@
1
+ import {
2
+ CORSPlugin,
3
+ CompositePlugin,
4
+ ResponseHeadersPlugin
5
+ } from "./chunk-TXHKQO7N.js";
6
+ export {
7
+ CORSPlugin,
8
+ CompositePlugin,
9
+ ResponseHeadersPlugin
10
+ };
11
+ //# sourceMappingURL=plugins.js.map
@@ -1,4 +1,3 @@
1
1
  export * from './rpc-handler';
2
2
  export * from './types';
3
- export * from './utils';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,10 +1,12 @@
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
+ import type { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
1
3
  import type { Context } from '../../context';
2
4
  import type { Router } from '../../router';
3
- import type { RPCHandlerOptions, StandardHandleRest } from '../standard';
5
+ import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
4
6
  import type { FetchHandler, FetchHandleResult } from './types';
5
7
  export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
6
8
  private readonly standardHandler;
7
9
  constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
8
- handle(request: Request, ...rest: StandardHandleRest<T>): Promise<FetchHandleResult>;
10
+ handle(request: Request, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
9
11
  }
10
12
  //# sourceMappingURL=rpc-handler.d.ts.map
@@ -1,5 +1,7 @@
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
+ import type { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
1
3
  import type { Context } from '../../context';
2
- import type { StandardHandleRest } from '../standard';
4
+ import type { StandardHandleOptions } from '../standard';
3
5
  export type FetchHandleResult = {
4
6
  matched: true;
5
7
  response: Response;
@@ -8,6 +10,6 @@ export type FetchHandleResult = {
8
10
  response: undefined;
9
11
  };
10
12
  export interface FetchHandler<T extends Context> {
11
- handle(request: Request, ...rest: StandardHandleRest<T>): Promise<FetchHandleResult>;
13
+ handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
12
14
  }
13
15
  //# sourceMappingURL=types.d.ts.map
@@ -1,13 +1,12 @@
1
+ import type { MaybeOptionalOptions, Value } from '@orpc/shared';
1
2
  import type { Context as HonoContext, MiddlewareHandler } from 'hono';
2
3
  import type { Context } from '../../context';
3
4
  import type { FetchHandler } from '../fetch';
4
5
  import type { StandardHandleOptions } from '../standard';
5
- import { type Value } from '@orpc/shared';
6
6
  export type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
7
7
  context?: Value<T, [HonoContext]>;
8
8
  } : {
9
9
  context: Value<T, [HonoContext]>;
10
10
  });
11
- export type CreateMiddlewareRest<T extends Context> = [options: CreateMiddlewareOptions<T>] | (Record<never, never> extends T ? [] : never);
12
- export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: CreateMiddlewareRest<T>): MiddlewareHandler;
11
+ export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
13
12
  //# sourceMappingURL=middleware.d.ts.map
@@ -1,14 +1,13 @@
1
+ import type { MaybeOptionalOptions, Value } from '@orpc/shared';
1
2
  import type { NextRequest } from 'next/server';
2
3
  import type { Context } from '../../context';
3
4
  import type { FetchHandler } from '../fetch';
4
5
  import type { StandardHandleOptions } from '../standard';
5
- import { type Value } from '@orpc/shared';
6
6
  export type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
7
7
  context?: Value<T, [NextRequest]>;
8
8
  } : {
9
9
  context: Value<T, [NextRequest]>;
10
10
  });
11
- export type ServeRest<T extends Context> = [options: ServeOptions<T>] | (Record<never, never> extends T ? [] : never);
12
11
  export interface ServeResult {
13
12
  GET(req: NextRequest): Promise<Response>;
14
13
  POST(req: NextRequest): Promise<Response>;
@@ -16,5 +15,5 @@ export interface ServeResult {
16
15
  PATCH(req: NextRequest): Promise<Response>;
17
16
  DELETE(req: NextRequest): Promise<Response>;
18
17
  }
19
- export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: ServeRest<T>): ServeResult;
18
+ export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
20
19
  //# sourceMappingURL=serve.d.ts.map
@@ -1,4 +1,3 @@
1
1
  export * from './rpc-handler';
2
2
  export * from './types';
3
- export * from './utils';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,10 +1,12 @@
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
+ import type { SendStandardResponseOptions } from '@orpc/standard-server-node';
1
3
  import type { Context } from '../../context';
2
4
  import type { Router } from '../../router';
3
- import type { RPCHandlerOptions, StandardHandleRest } from '../standard';
5
+ import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
4
6
  import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from './types';
5
7
  export declare class RPCHandler<T extends Context> implements NodeHttpHandler<T> {
6
8
  private readonly standardHandler;
7
9
  constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
8
- handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: StandardHandleRest<T>): Promise<NodeHttpHandleResult>;
10
+ handle(req: NodeHttpRequest, res: NodeHttpResponse, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
9
11
  }
10
12
  //# sourceMappingURL=rpc-handler.d.ts.map
@@ -1,7 +1,9 @@
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
+ import type { SendStandardResponseOptions } from '@orpc/standard-server-node';
1
3
  import type { IncomingMessage, ServerResponse } from 'node:http';
2
4
  import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
3
5
  import type { Context } from '../../context';
4
- import type { StandardHandleRest } from '../standard';
6
+ import type { StandardHandleOptions } from '../standard';
5
7
  export type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
6
8
  /**
7
9
  * Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
@@ -16,6 +18,6 @@ export type NodeHttpHandleResult = {
16
18
  matched: false;
17
19
  };
18
20
  export interface NodeHttpHandler<T extends Context> {
19
- handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: StandardHandleRest<T>): Promise<NodeHttpHandleResult>;
21
+ handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
20
22
  }
21
23
  //# sourceMappingURL=types.d.ts.map
@@ -1,8 +1,11 @@
1
- import type { HTTPPath } from '@orpc/contract';
2
- import type { Interceptable } from '@orpc/shared';
1
+ import type { ErrorFromErrorMap, HTTPPath, Meta, Schema, SchemaOutput } from '@orpc/contract';
2
+ import type { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
3
+ import type { StandardRequest, StandardResponse } from '@orpc/standard-server';
3
4
  import type { Context } from '../../context';
5
+ import type { Plugin } from '../../plugins';
6
+ import type { ProcedureClientInterceptorOptions } from '../../procedure-client';
4
7
  import type { Router } from '../../router';
5
- import type { StandardCodec, StandardMatcher, StandardRequest, StandardResponse } from './types';
8
+ import type { StandardCodec, StandardMatcher } from './types';
6
9
  export type StandardHandleOptions<T extends Context> = {
7
10
  prefix?: HTTPPath;
8
11
  } & (Record<never, never> extends T ? {
@@ -10,7 +13,9 @@ export type StandardHandleOptions<T extends Context> = {
10
13
  } : {
11
14
  context: T;
12
15
  });
13
- export type StandardHandleRest<T extends Context> = [options: StandardHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
16
+ export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
17
+ context: T;
18
+ };
14
19
  export type StandardHandleResult = {
15
20
  matched: true;
16
21
  response: StandardResponse;
@@ -18,16 +23,31 @@ export type StandardHandleResult = {
18
23
  matched: false;
19
24
  response: undefined;
20
25
  };
21
- export interface StandardHandlerOptions<TContext extends Context> extends Interceptable<{
22
- context: TContext;
26
+ export type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
23
27
  request: StandardRequest;
24
- }, StandardHandleResult, unknown> {
28
+ };
29
+ export interface StandardHandlerOptions<TContext extends Context> {
30
+ plugins?: Plugin<TContext>[];
31
+ /**
32
+ * Interceptors at the request level, helpful when you want catch errors
33
+ */
34
+ interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
35
+ /**
36
+ * Interceptors at the root level, helpful when you want override the request/response
37
+ */
38
+ rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
39
+ /**
40
+ *
41
+ * Interceptors for procedure client.
42
+ */
43
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Schema, Record<never, never>, Meta>, SchemaOutput<Schema, unknown>, ErrorFromErrorMap<Record<never, never>>>[];
25
44
  }
26
- export declare class StandardHandler<TContext extends Context> {
45
+ export declare class StandardHandler<T extends Context> {
27
46
  private readonly matcher;
28
47
  private readonly codec;
29
48
  private readonly options;
30
- constructor(router: Router<TContext, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<TContext>>);
31
- handle(request: StandardRequest, ...[options]: StandardHandleRest<TContext>): Promise<StandardHandleResult>;
49
+ private readonly plugin;
50
+ constructor(router: Router<T, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<T>>);
51
+ handle(request: StandardRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
32
52
  }
33
53
  //# sourceMappingURL=handler.d.ts.map
@@ -2,6 +2,5 @@ export * from './handler';
2
2
  export * from './rpc-codec';
3
3
  export * from './rpc-handler';
4
4
  export * from './rpc-matcher';
5
- export * from './rpc-serializer';
6
5
  export * from './types';
7
6
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,8 @@
1
- import type { ORPCError } from '@orpc/contract';
1
+ import type { ORPCError } from '@orpc/client';
2
+ import type { StandardRequest, StandardResponse } from '@orpc/standard-server';
2
3
  import type { AnyProcedure } from '../../procedure';
3
- import type { StandardCodec, StandardParams, StandardRequest, StandardResponse } from './types';
4
- import { RPCSerializer } from './rpc-serializer';
4
+ import type { StandardCodec, StandardParams } from './types';
5
+ import { RPCSerializer } from '@orpc/client/rpc';
5
6
  export interface StandardCodecOptions {
6
7
  serializer?: RPCSerializer;
7
8
  }
@@ -1,31 +1,8 @@
1
- import type { AbortSignal, HTTPPath, ORPCError } from '@orpc/contract';
2
- import type { JsonValue } from '@orpc/shared';
1
+ import type { ORPCError } from '@orpc/client';
2
+ import type { HTTPPath } from '@orpc/contract';
3
+ import type { StandardRequest, StandardResponse } from '@orpc/standard-server';
3
4
  import type { AnyProcedure } from '../../procedure';
4
5
  import type { AnyRouter } from '../../router';
5
- export interface StandardHeaders {
6
- [key: string]: string | string[] | undefined;
7
- }
8
- export type StandardBody = undefined | JsonValue | Blob | URLSearchParams | FormData;
9
- export interface StandardRequest {
10
- /**
11
- * Can be { request: Request } or { request: IncomingMessage, response: ServerResponse } based on the adapter.
12
- */
13
- raw: Record<string, unknown>;
14
- method: string;
15
- url: URL;
16
- headers: StandardHeaders;
17
- /**
18
- * The body has been parsed base on the content-type header.
19
- * This method can safely call multiple times (cached).
20
- */
21
- body(): Promise<StandardBody>;
22
- signal?: AbortSignal;
23
- }
24
- export interface StandardResponse {
25
- status: number;
26
- headers: StandardHeaders;
27
- body: StandardBody;
28
- }
29
6
  export type StandardParams = Record<string, string>;
30
7
  export type StandardMatchResult = {
31
8
  path: string[];
@@ -1,6 +1,7 @@
1
- import type { ContractRouter, ErrorMap, HTTPPath, MergedErrorMap, Meta, ORPCErrorConstructorMap, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
1
+ import type { ContractRouter, ErrorMap, HTTPPath, MergedErrorMap, Meta, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
2
  import type { BuilderDef } from './builder';
3
3
  import type { ConflictContextGuard, Context, MergedContext } from './context';
4
+ import type { ORPCErrorConstructorMap } from './error';
4
5
  import type { FlattenLazy } from './lazy-utils';
5
6
  import type { MapInputMiddleware, Middleware } from './middleware';
6
7
  import type { ProcedureHandler } from './procedure';
@@ -1,6 +1,7 @@
1
- import type { ContractProcedureDef, ContractRouter, ErrorMap, HTTPPath, MergedErrorMap, Meta, ORPCErrorConstructorMap, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
1
+ import type { ContractProcedureDef, ContractRouter, ErrorMap, HTTPPath, MergedErrorMap, Meta, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
2
  import type { BuilderWithMiddlewares, ProcedureBuilder, ProcedureBuilderWithInput, ProcedureBuilderWithOutput, RouterBuilder } from './builder-variants';
3
3
  import type { ConflictContextGuard, Context, MergedContext } from './context';
4
+ import type { ORPCErrorConstructorMap } from './error';
4
5
  import type { FlattenLazy } from './lazy-utils';
5
6
  import type { AnyMiddleware, MapInputMiddleware, Middleware } from './middleware';
6
7
  import type { DecoratedMiddleware } from './middleware-decorated';
@@ -1,6 +1,5 @@
1
1
  import type { IsNever } from '@orpc/shared';
2
2
  export type Context = Record<string, any>;
3
- export type TypeInitialContext<T extends Context> = (type: T) => unknown;
4
3
  export type MergedContext<T extends Context, U extends Context> = T & U;
5
4
  export declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
6
5
  export type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
@@ -0,0 +1,12 @@
1
+ import type { ORPCErrorCode, ORPCErrorOptions } from '@orpc/client';
2
+ import type { ErrorMap, ErrorMapItem, SchemaInput } from '@orpc/contract';
3
+ import type { MaybeOptionalOptions } from '@orpc/shared';
4
+ import { ORPCError } from '@orpc/client';
5
+ export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
6
+ export type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
7
+ export type ORPCErrorConstructorMap<T extends ErrorMap> = {
8
+ [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, SchemaInput<UInputSchema>> : never : never;
9
+ };
10
+ export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
11
+ export declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
12
+ //# sourceMappingURL=error.d.ts.map
@@ -1,9 +1,12 @@
1
- import type { ClientRest, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
1
+ import type { ClientContext, ClientRest } from '@orpc/client';
2
+ import type { ErrorMap, Meta, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
3
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
4
  import type { BuilderDef } from './builder';
3
5
  import type { ConflictContextGuard, Context, MergedContext } from './context';
6
+ import type { ORPCErrorConstructorMap } from './error';
4
7
  import type { MapInputMiddleware, Middleware } from './middleware';
5
8
  import type { Procedure, ProcedureHandler } from './procedure';
6
- import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
9
+ import type { CreateProcedureClientOptions, ProcedureClient } from './procedure-client';
7
10
  import type { DecoratedProcedure } from './procedure-decorated';
8
11
  /**
9
12
  * Like `DecoratedProcedure`, but removed all method that can change the contract.
@@ -13,11 +16,11 @@ export interface ImplementedProcedure<TInitialContext extends Context, TCurrentC
13
16
  /**
14
17
  * Make this procedure callable (works like a function while still being a procedure).
15
18
  */
16
- callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
19
+ callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
17
20
  /**
18
21
  * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
19
22
  */
20
- actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
23
+ actionable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
21
24
  }
22
25
  /**
23
26
  * Like `ProcedureBuilderWithoutHandler`, but removed all method that can change the contract.
@@ -1,5 +1,6 @@
1
- import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta, ORPCErrorConstructorMap } from '@orpc/contract';
1
+ import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta } from '@orpc/contract';
2
2
  import type { ConflictContextGuard, Context, MergedContext } from './context';
3
+ import type { ORPCErrorConstructorMap } from './error';
3
4
  import type { ProcedureImplementer } from './implementer-procedure';
4
5
  import type { FlattenLazy } from './lazy-utils';
5
6
  import type { Middleware } from './middleware';
@@ -1,5 +1,6 @@
1
- import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta, ORPCErrorConstructorMap } from '@orpc/contract';
1
+ import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta } from '@orpc/contract';
2
2
  import type { ConflictContextGuard, Context, MergedContext } from './context';
3
+ import type { ORPCErrorConstructorMap } from './error';
3
4
  import type { ProcedureImplementer } from './implementer-procedure';
4
5
  import type { ImplementerInternalWithMiddlewares } from './implementer-variants';
5
6
  import type { AnyMiddleware, Middleware } from './middleware';
@@ -18,6 +18,8 @@ export * from './router';
18
18
  export * from './router-accessible-lazy';
19
19
  export * from './router-client';
20
20
  export * from './utils';
21
- export { isDefinedError, ORPCError, safe, type, ValidationError } from '@orpc/contract';
21
+ export { isDefinedError, ORPCError, safe } from '@orpc/client';
22
+ export { eventIterator, type, ValidationError } from '@orpc/contract';
22
23
  export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
24
+ export { getEventMeta, withEventMeta } from '@orpc/standard-server';
23
25
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,6 @@
1
- import type { Meta, ORPCErrorConstructorMap } from '@orpc/contract';
1
+ import type { Meta } from '@orpc/contract';
2
2
  import type { Context, MergedContext } from './context';
3
+ import type { ORPCErrorConstructorMap } from './error';
3
4
  import type { MapInputMiddleware, Middleware } from './middleware';
4
5
  export interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta> {
5
6
  concat<UOutContext extends Context, UInput>(middleware: Middleware<TInContext & TOutContext, UOutContext, UInput & TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<TInContext, MergedContext<TOutContext, UOutContext>, UInput & TInput, TOutput, TErrorConstructorMap, TMeta>;