@orpc/server 0.0.0-next.f56d2b3 → 0.0.0-next.fd0ca3d

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 (55) hide show
  1. package/dist/chunk-47YYO5JS.js +32 -0
  2. package/dist/chunk-77FU7QSO.js +181 -0
  3. package/dist/{chunk-KK4SDLC7.js → chunk-MHVECKBC.js} +132 -31
  4. package/dist/chunk-WQNNSBXW.js +120 -0
  5. package/dist/fetch.js +6 -11
  6. package/dist/hono.js +17 -13
  7. package/dist/index.js +29 -7
  8. package/dist/next.js +5 -10
  9. package/dist/node.js +18 -74
  10. package/dist/plugins.js +11 -0
  11. package/dist/src/adapters/fetch/index.d.ts +1 -4
  12. package/dist/src/adapters/fetch/rpc-handler.d.ts +11 -0
  13. package/dist/src/adapters/fetch/types.d.ts +3 -10
  14. package/dist/src/adapters/hono/middleware.d.ts +5 -5
  15. package/dist/src/adapters/next/serve.d.ts +5 -5
  16. package/dist/src/adapters/node/index.d.ts +1 -3
  17. package/dist/src/adapters/node/rpc-handler.d.ts +11 -0
  18. package/dist/src/adapters/node/types.d.ts +14 -14
  19. package/dist/src/adapters/standard/handler.d.ts +53 -0
  20. package/dist/src/adapters/standard/index.d.ts +6 -0
  21. package/dist/src/adapters/standard/rpc-codec.d.ts +16 -0
  22. package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
  23. package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
  24. package/dist/src/adapters/standard/types.d.ts +21 -0
  25. package/dist/src/builder-variants.d.ts +2 -1
  26. package/dist/src/builder.d.ts +2 -1
  27. package/dist/src/context.d.ts +0 -1
  28. package/dist/src/error.d.ts +12 -0
  29. package/dist/src/implementer-procedure.d.ts +7 -4
  30. package/dist/src/implementer-variants.d.ts +7 -5
  31. package/dist/src/implementer.d.ts +8 -6
  32. package/dist/src/index.d.ts +5 -1
  33. package/dist/src/middleware-decorated.d.ts +2 -1
  34. package/dist/src/middleware.d.ts +5 -4
  35. package/dist/src/plugins/base.d.ts +11 -0
  36. package/dist/src/plugins/cors.d.ts +19 -0
  37. package/dist/src/plugins/index.d.ts +4 -0
  38. package/dist/src/plugins/response-headers.d.ts +10 -0
  39. package/dist/src/procedure-client.d.ts +21 -8
  40. package/dist/src/procedure-decorated.d.ts +7 -4
  41. package/dist/src/procedure-utils.d.ts +5 -3
  42. package/dist/src/procedure.d.ts +5 -3
  43. package/dist/src/router-client.d.ts +7 -17
  44. package/dist/src/router.d.ts +1 -0
  45. package/dist/src/utils.d.ts +24 -0
  46. package/dist/standard.js +13 -0
  47. package/package.json +20 -3
  48. package/dist/chunk-ESTRJAOX.js +0 -299
  49. package/dist/chunk-WUOGVGWG.js +0 -1
  50. package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
  51. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
  52. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
  53. package/dist/src/adapters/fetch/super-json.d.ts +0 -12
  54. package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
  55. package/dist/src/adapters/node/request-listener.d.ts +0 -28
package/dist/index.js CHANGED
@@ -3,10 +3,14 @@ import {
3
3
  Procedure,
4
4
  adaptRouter,
5
5
  addMiddleware,
6
+ convertPathToHttpPath,
6
7
  createAccessibleLazyRouter,
8
+ createContractedProcedure,
7
9
  createLazyProcedureFormAnyLazy,
8
10
  createProcedureClient,
9
11
  deepSetLazyRouterPrefix,
12
+ eachAllContractProcedure,
13
+ eachContractProcedure,
10
14
  flatLazy,
11
15
  getLazyRouterPrefix,
12
16
  getRouterChild,
@@ -17,7 +21,7 @@ import {
17
21
  middlewareOutputFn,
18
22
  setRouterContract,
19
23
  unlazy
20
- } from "./chunk-KK4SDLC7.js";
24
+ } from "./chunk-MHVECKBC.js";
21
25
 
22
26
  // src/builder.ts
23
27
  import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
@@ -46,10 +50,14 @@ function decorateMiddleware(middleware) {
46
50
  decorated.concat = (concatMiddleware, mapInput) => {
47
51
  const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
48
52
  const concatted = decorateMiddleware((options, input, output, ...rest) => {
49
- const next = async (...[nextOptions]) => {
50
- return mapped({ ...options, context: { ...nextOptions?.context, ...options.context } }, input, output, ...rest);
51
- };
52
- 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);
53
61
  return merged;
54
62
  });
55
63
  return concatted;
@@ -353,7 +361,10 @@ function createRouterClient(router, ...rest) {
353
361
  }
354
362
 
355
363
  // src/index.ts
356
- 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";
366
+ import { getEventMeta, withEventMeta } from "@orpc/server-standard";
367
+ import { onError, onFinish, onStart, onSuccess } from "@orpc/shared";
357
368
  export {
358
369
  Builder,
359
370
  DecoratedProcedure,
@@ -363,14 +374,20 @@ export {
363
374
  ValidationError,
364
375
  adaptRouter,
365
376
  call,
377
+ convertPathToHttpPath,
366
378
  createAccessibleLazyRouter,
379
+ createContractedProcedure,
367
380
  createLazyProcedureFormAnyLazy,
368
381
  createProcedureClient,
369
382
  createRouterClient,
370
383
  decorateMiddleware,
371
384
  deepSetLazyRouterPrefix,
385
+ eachAllContractProcedure,
386
+ eachContractProcedure,
387
+ eventIterator,
372
388
  fallbackConfig,
373
389
  flatLazy,
390
+ getEventMeta,
374
391
  getLazyRouterPrefix,
375
392
  getRouterChild,
376
393
  getRouterContract,
@@ -382,10 +399,15 @@ export {
382
399
  lazy,
383
400
  mergeContext,
384
401
  middlewareOutputFn,
402
+ onError,
403
+ onFinish,
404
+ onStart,
405
+ onSuccess,
385
406
  os,
386
407
  safe,
387
408
  setRouterContract,
388
409
  type,
389
- unlazy
410
+ unlazy,
411
+ withEventMeta
390
412
  };
391
413
  //# sourceMappingURL=index.js.map
package/dist/next.js CHANGED
@@ -1,11 +1,9 @@
1
- import "./chunk-WUOGVGWG.js";
2
1
  import {
3
- ORPCPayloadCodec,
4
- ORPCProcedureMatcher,
5
- RPCHandler,
6
- super_json_exports
7
- } from "./chunk-ESTRJAOX.js";
8
- import "./chunk-KK4SDLC7.js";
2
+ RPCHandler
3
+ } from "./chunk-47YYO5JS.js";
4
+ import "./chunk-77FU7QSO.js";
5
+ import "./chunk-MHVECKBC.js";
6
+ import "./chunk-WQNNSBXW.js";
9
7
 
10
8
  // src/adapters/next/serve.ts
11
9
  import { value } from "@orpc/shared";
@@ -27,10 +25,7 @@ function serve(handler, ...[options]) {
27
25
  };
28
26
  }
29
27
  export {
30
- ORPCPayloadCodec,
31
- ORPCProcedureMatcher,
32
28
  RPCHandler,
33
- super_json_exports as SuperJSON,
34
29
  serve
35
30
  };
36
31
  //# sourceMappingURL=next.js.map
package/dist/node.js CHANGED
@@ -1,87 +1,31 @@
1
1
  import {
2
- RPCHandler
3
- } from "./chunk-ESTRJAOX.js";
4
- import "./chunk-KK4SDLC7.js";
2
+ RPCCodec,
3
+ RPCMatcher,
4
+ StandardHandler
5
+ } from "./chunk-77FU7QSO.js";
6
+ import "./chunk-MHVECKBC.js";
7
+ import "./chunk-WQNNSBXW.js";
5
8
 
6
- // src/adapters/node/request-listener.ts
7
- function createRequest(req, res) {
8
- const controller = new AbortController();
9
- res.on("close", () => {
10
- controller.abort();
11
- });
12
- const method = req.method ?? "GET";
13
- const headers = createHeaders(req);
14
- const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
15
- const host = headers.get("Host") ?? "localhost";
16
- const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
17
- const init = { method, headers, signal: controller.signal };
18
- if (method !== "GET" && method !== "HEAD") {
19
- init.body = new ReadableStream({
20
- start(controller2) {
21
- req.on("data", (chunk) => {
22
- controller2.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
23
- });
24
- req.on("end", () => {
25
- controller2.close();
26
- });
27
- }
28
- });
29
- init.duplex = "half";
30
- }
31
- return new Request(url, init);
32
- }
33
- function createHeaders(req) {
34
- const headers = new Headers();
35
- const rawHeaders = req.rawHeaders;
36
- for (let i = 0; i < rawHeaders.length; i += 2) {
37
- headers.append(rawHeaders[i], rawHeaders[i + 1]);
38
- }
39
- return headers;
40
- }
41
- async function sendResponse(res, response) {
42
- const headers = {};
43
- for (const [key, value] of response.headers) {
44
- if (key in headers) {
45
- if (Array.isArray(headers[key])) {
46
- headers[key].push(value);
47
- } else {
48
- headers[key] = [headers[key], value];
49
- }
50
- } else {
51
- headers[key] = value;
52
- }
53
- }
54
- res.writeHead(response.status, headers);
55
- if (response.body != null && res.req.method !== "HEAD") {
56
- for await (const chunk of response.body) {
57
- res.write(chunk);
58
- }
59
- }
60
- res.end();
61
- }
62
-
63
- // src/adapters/node/orpc-handler.ts
64
- var RPCHandler2 = class {
65
- orpcFetchHandler;
9
+ // src/adapters/node/rpc-handler.ts
10
+ import { sendStandardResponse, toStandardRequest } from "@orpc/server-standard-node";
11
+ var RPCHandler = class {
12
+ standardHandler;
66
13
  constructor(router, options) {
67
- this.orpcFetchHandler = new RPCHandler(router, options);
14
+ const codec = options?.codec ?? new RPCCodec();
15
+ const matcher = options?.matcher ?? new RPCMatcher();
16
+ this.standardHandler = new StandardHandler(router, matcher, codec, options);
68
17
  }
69
18
  async handle(req, res, ...rest) {
70
- const request = createRequest(req, res);
71
- const result = await this.orpcFetchHandler.handle(request, ...rest);
72
- if (result.matched === false) {
19
+ const standardRequest = toStandardRequest(req, res);
20
+ const result = await this.standardHandler.handle(standardRequest, ...rest);
21
+ if (!result.matched) {
73
22
  return { matched: false };
74
23
  }
75
- const context = rest[0]?.context ?? {};
76
- await rest[0]?.beforeSend?.(result.response, context);
77
- await sendResponse(res, result.response);
24
+ await sendStandardResponse(res, result.response);
78
25
  return { matched: true };
79
26
  }
80
27
  };
81
28
  export {
82
- RPCHandler2 as RPCHandler,
83
- createHeaders,
84
- createRequest,
85
- sendResponse
29
+ RPCHandler
86
30
  };
87
31
  //# sourceMappingURL=node.js.map
@@ -0,0 +1,11 @@
1
+ import {
2
+ CORSPlugin,
3
+ CompositePlugin,
4
+ ResponseHeadersPlugin
5
+ } from "./chunk-WQNNSBXW.js";
6
+ export {
7
+ CORSPlugin,
8
+ CompositePlugin,
9
+ ResponseHeadersPlugin
10
+ };
11
+ //# sourceMappingURL=plugins.js.map
@@ -1,6 +1,3 @@
1
- export * from './orpc-handler';
2
- export * from './orpc-payload-codec';
3
- export * from './orpc-procedure-matcher';
4
- export * as SuperJSON from './super-json';
1
+ export * from './rpc-handler';
5
2
  export * from './types';
6
3
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
+ import type { Context } from '../../context';
3
+ import type { Router } from '../../router';
4
+ import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
5
+ import type { FetchHandler, FetchHandleResult } from './types';
6
+ export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
7
+ private readonly standardHandler;
8
+ constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
9
+ handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
10
+ }
11
+ //# sourceMappingURL=rpc-handler.d.ts.map
@@ -1,13 +1,6 @@
1
- import type { HTTPPath } from '@orpc/contract';
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
2
  import type { Context } from '../../context';
3
- export type FetchHandleOptions<T extends Context> = {
4
- prefix?: HTTPPath;
5
- } & (Record<never, never> extends T ? {
6
- context?: T;
7
- } : {
8
- context: T;
9
- });
10
- export type FetchHandleRest<T extends Context> = [options: FetchHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
3
+ import type { StandardHandleOptions } from '../standard';
11
4
  export type FetchHandleResult = {
12
5
  matched: true;
13
6
  response: Response;
@@ -16,6 +9,6 @@ export type FetchHandleResult = {
16
9
  response: undefined;
17
10
  };
18
11
  export interface FetchHandler<T extends Context> {
19
- handle(request: Request, ...rest: FetchHandleRest<T>): Promise<FetchHandleResult>;
12
+ handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
20
13
  }
21
14
  //# sourceMappingURL=types.d.ts.map
@@ -1,12 +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
- import type { FetchHandleOptions, FetchHandler } from '../fetch';
4
- import { type Value } from '@orpc/shared';
5
- export type CreateMiddlewareOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
4
+ import type { FetchHandler } from '../fetch';
5
+ import type { StandardHandleOptions } from '../standard';
6
+ export type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
7
  context?: Value<T, [HonoContext]>;
7
8
  } : {
8
9
  context: Value<T, [HonoContext]>;
9
10
  });
10
- export type CreateMiddlewareRest<T extends Context> = [options: CreateMiddlewareOptions<T>] | (Record<never, never> extends T ? [] : never);
11
- 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;
12
12
  //# sourceMappingURL=middleware.d.ts.map
@@ -1,13 +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
- import type { FetchHandleOptions, FetchHandler } from '../fetch';
4
- import { type Value } from '@orpc/shared';
5
- export type ServeOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
4
+ import type { FetchHandler } from '../fetch';
5
+ import type { StandardHandleOptions } from '../standard';
6
+ export type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
7
  context?: Value<T, [NextRequest]>;
7
8
  } : {
8
9
  context: Value<T, [NextRequest]>;
9
10
  });
10
- export type ServeRest<T extends Context> = [options: ServeOptions<T>] | (Record<never, never> extends T ? [] : never);
11
11
  export interface ServeResult {
12
12
  GET(req: NextRequest): Promise<Response>;
13
13
  POST(req: NextRequest): Promise<Response>;
@@ -15,5 +15,5 @@ export interface ServeResult {
15
15
  PATCH(req: NextRequest): Promise<Response>;
16
16
  DELETE(req: NextRequest): Promise<Response>;
17
17
  }
18
- 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;
19
19
  //# sourceMappingURL=serve.d.ts.map
@@ -1,5 +1,3 @@
1
- export * from './orpc-handler';
2
- export * from './orpc-handler';
3
- export * from './request-listener';
1
+ export * from './rpc-handler';
4
2
  export * from './types';
5
3
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
2
+ import type { Context } from '../../context';
3
+ import type { Router } from '../../router';
4
+ import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
5
+ import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from './types';
6
+ export declare class RPCHandler<T extends Context> implements NodeHttpHandler<T> {
7
+ private readonly standardHandler;
8
+ constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
9
+ handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
10
+ }
11
+ //# sourceMappingURL=rpc-handler.d.ts.map
@@ -1,22 +1,22 @@
1
- import type { HTTPPath } from '@orpc/contract';
2
- import type { Promisable } from '@orpc/shared';
1
+ import type { MaybeOptionalOptions } from '@orpc/shared';
3
2
  import type { IncomingMessage, ServerResponse } from 'node:http';
3
+ import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
4
4
  import type { Context } from '../../context';
5
- export type RequestHandleOptions<T extends Context> = {
6
- prefix?: HTTPPath;
7
- beforeSend?(response: Response, context: T): Promisable<void>;
8
- } & (Record<never, never> extends T ? {
9
- context?: T;
10
- } : {
11
- context: T;
12
- });
13
- export type RequestHandleRest<T extends Context> = [options: RequestHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
14
- export type RequestHandleResult = {
5
+ import type { StandardHandleOptions } from '../standard';
6
+ export type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
7
+ /**
8
+ * Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
9
+ * This is useful for `express.js` middleware.
10
+ */
11
+ originalUrl?: string;
12
+ };
13
+ export type NodeHttpResponse = ServerResponse | Http2ServerResponse;
14
+ export type NodeHttpHandleResult = {
15
15
  matched: true;
16
16
  } | {
17
17
  matched: false;
18
18
  };
19
- export interface RequestHandler<T extends Context> {
20
- handle(req: IncomingMessage, res: ServerResponse, ...rest: RequestHandleRest<T>): Promise<RequestHandleResult>;
19
+ export interface NodeHttpHandler<T extends Context> {
20
+ handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
21
21
  }
22
22
  //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,53 @@
1
+ import type { ErrorFromErrorMap, HTTPPath, Meta, Schema, SchemaOutput } from '@orpc/contract';
2
+ import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
3
+ import type { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
4
+ import type { Context } from '../../context';
5
+ import type { Plugin } from '../../plugins';
6
+ import type { ProcedureClientInterceptorOptions } from '../../procedure-client';
7
+ import type { Router } from '../../router';
8
+ import type { StandardCodec, StandardMatcher } from './types';
9
+ export type StandardHandleOptions<T extends Context> = {
10
+ prefix?: HTTPPath;
11
+ } & (Record<never, never> extends T ? {
12
+ context?: T;
13
+ } : {
14
+ context: T;
15
+ });
16
+ export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
17
+ context: T;
18
+ };
19
+ export type StandardHandleResult = {
20
+ matched: true;
21
+ response: StandardResponse;
22
+ } | {
23
+ matched: false;
24
+ response: undefined;
25
+ };
26
+ export type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
27
+ request: StandardRequest;
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>>>[];
44
+ }
45
+ export declare class StandardHandler<T extends Context> {
46
+ private readonly matcher;
47
+ private readonly codec;
48
+ private readonly options;
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>;
52
+ }
53
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1,6 @@
1
+ export * from './handler';
2
+ export * from './rpc-codec';
3
+ export * from './rpc-handler';
4
+ export * from './rpc-matcher';
5
+ export * from './types';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,16 @@
1
+ import type { ORPCError } from '@orpc/client';
2
+ import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
3
+ import type { AnyProcedure } from '../../procedure';
4
+ import type { StandardCodec, StandardParams } from './types';
5
+ import { RPCSerializer } from '@orpc/client/rpc';
6
+ export interface StandardCodecOptions {
7
+ serializer?: RPCSerializer;
8
+ }
9
+ export declare class RPCCodec implements StandardCodec {
10
+ private readonly serializer;
11
+ constructor(options?: StandardCodecOptions);
12
+ decode(request: StandardRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
13
+ encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
14
+ encodeError(error: ORPCError<any, any>): StandardResponse;
15
+ }
16
+ //# sourceMappingURL=rpc-codec.d.ts.map
@@ -0,0 +1,8 @@
1
+ import type { Context } from '../../context';
2
+ import type { StandardHandlerOptions } from './handler';
3
+ import type { StandardCodec, StandardMatcher } from './types';
4
+ export interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T> {
5
+ matcher?: StandardMatcher;
6
+ codec?: StandardCodec;
7
+ }
8
+ //# sourceMappingURL=rpc-handler.d.ts.map
@@ -0,0 +1,10 @@
1
+ import type { HTTPPath } from '@orpc/contract';
2
+ import type { StandardMatcher, StandardMatchResult } from './types';
3
+ import { type AnyRouter } from '../../router';
4
+ export declare class RPCMatcher implements StandardMatcher {
5
+ private readonly tree;
6
+ private pendingRouters;
7
+ init(router: AnyRouter, path?: string[]): void;
8
+ match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
9
+ }
10
+ //# sourceMappingURL=rpc-matcher.d.ts.map
@@ -0,0 +1,21 @@
1
+ import type { ORPCError } from '@orpc/client';
2
+ import type { HTTPPath } from '@orpc/contract';
3
+ import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
4
+ import type { AnyProcedure } from '../../procedure';
5
+ import type { AnyRouter } from '../../router';
6
+ export type StandardParams = Record<string, string>;
7
+ export type StandardMatchResult = {
8
+ path: string[];
9
+ procedure: AnyProcedure;
10
+ params?: StandardParams;
11
+ } | undefined;
12
+ export interface StandardMatcher {
13
+ init(router: AnyRouter): void;
14
+ match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
15
+ }
16
+ export interface StandardCodec {
17
+ encode(output: unknown, procedure: AnyProcedure): StandardResponse;
18
+ encodeError(error: ORPCError<any, any>): StandardResponse;
19
+ decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
20
+ }
21
+ //# sourceMappingURL=types.d.ts.map
@@ -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,16 +1,18 @@
1
- import type { AnyContractRouter, ContractProcedure, ContractRouter, ContractRouterToErrorMap, 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';
6
7
  import type { AdaptedRouter, Router } from './router';
7
- export type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : TContract extends ContractRouter<infer UMeta> ? {
8
- use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, UMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
8
+ export interface RouterImplementerWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
9
+ use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
9
10
  router<U extends Router<TCurrentContext, TContract>>(router: U): AdaptedRouter<U, TInitialContext, Record<never, never>>;
10
11
  lazy<U extends Router<TInitialContext, TContract>>(loader: () => Promise<{
11
12
  default: U;
12
13
  }>): AdaptedRouter<FlattenLazy<U>, TInitialContext, Record<never, never>>;
13
- } & {
14
+ }
15
+ export type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementerWithMiddlewares<TContract, TInitialContext, TCurrentContext> & {
14
16
  [K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
15
- } : never);
17
+ });
16
18
  //# sourceMappingURL=implementer-variants.d.ts.map